|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /** ! 26: * Copyright (c) 1994-1996 NeXT Software, Inc. All rights reserved. ! 27: * Copyright 1993-1995 by Apple Computer, Inc., all rights reserved. ! 28: * Copyright 1997 Apple Computer Inc. All Rights Reserved. ! 29: * @author Martin Minow mailto:[email protected] ! 30: * @revision 1997.02.13 Initial conversion from AMDPCSCSIDriver sources. ! 31: * ! 32: * Set tabs every 4 characters. ! 33: * ! 34: * Apple96Curio.h - Hardware (chip) definitions for Apple 53c96 SCSI interface. ! 35: * Apple96SCSI is closely based on Doug Mitchell's AMD 53C974/79C974 driver ! 36: * using design concepts from Copland DR2 Curio and MESH SCSI plugins. ! 37: * ! 38: * Edit History ! 39: * 1997.02.13 MM Initial conversion from AMDPCSCSIDriver sources. ! 40: * 1997.07.18 MM Added USE_CURIO_METHODS and wrote macros for the ! 41: * one-liner methods. ! 42: */ ! 43: ! 44: #import "Apple96Curio.h" ! 45: ! 46: /* ** ** ** ! 47: * ** ** ** Warning: all macros that take arguments must safely handle ! 48: * ** ** ** side-effects. For example CURIOputByteIntoFifo(*ptr++) ! 49: * ** ** ** must increment the pointer once only. ! 50: * ** ** ** ! 51: */ ! 52: ! 53: /* ! 54: * CurioReadRegister and CurioWriteRegister actually touch the hardware ! 55: */ ! 56: #if USE_CURIO_METHODS || WRITE_CHIP_OPERATION_INTO_TIMESTAMP_LOG ! 57: extern volatile UInt8 __CurioReadRegister__( ! 58: volatile UInt8 *scsiLogicalAddress, ! 59: UInt32 index ! 60: ); ! 61: extern void __CurioWriteRegister__( ! 62: volatile UInt8 *scsiLogicalAddress, ! 63: UInt32 index, ! 64: UInt8 value ! 65: ); ! 66: ! 67: #else ! 68: #define __CurioReadRegister__(scsiLogicalAddress, index) \ ! 69: (((volatile UInt8 *) scsiLogicalAddress)[index]) ! 70: #define __CurioWriteRegister__(scsiLogicalAddress, index, value) \ ! 71: ((((volatile UInt8 *) scsiLogicalAddress)[index]) = value) ! 72: #endif /* USE_CURIO_METHODS */ ! 73: /* ! 74: * These macros implement the one-line methods. They are included inline ! 75: * if USE_CURIO_METHODS is FALSE, or provided by the method implementation ! 76: * if USE_CURIO_METHODS is TRUE. ! 77: */ ! 78: #define CurioReadRegister(index) \ ! 79: __CurioReadRegister__(gSCSILogicalAddress, (index)) ! 80: #define CurioWriteRegister(index, value) \ ! 81: __CurioWriteRegister__(gSCSILogicalAddress, (index), (value)) ! 82: #define __CURIOreadStatusRegister() (CurioReadRegister(rSTA)) ! 83: #define __CURIOreadSequenceStateRegister() (CurioReadRegister(rSQS)) ! 84: #define __CURIOreadInterruptRegister() (CurioReadRegister(rINT)) ! 85: #define __CURIOstartMSGIAction() do { \ ! 86: __CURIOnop(); \ ! 87: __CURIOstartNonDMATransfer(); \ ! 88: } while (0) ! 89: #define __CURIOnop() __CURIOsetCommandRegister(cNOP) ! 90: #define __CURIOstartNonDMATransfer() __CURIOsetCommandRegister(cIOXfer) ! 91: #define __CURIOstartDMATransfer(count) do { \ ! 92: UInt32 __count = (count); \ ! 93: __CURIOwriteRegister(rXCM, (__count >> 8) & 0xFF); \ ! 94: SynchronizeIO(); \ ! 95: __CURIOwriteRegister(rXCL, __count & 0xFF); \ ! 96: SynchronizeIO(); \ ! 97: __CURIOsetCommandRegister(cDMAXfer); \ ! 98: } while (0) ! 99: #define __CURIOtransferPad(forOutput) do { \ ! 100: __CURIOwriteRegister(rXCM, 0xFF); \ ! 101: SynchronizeIO(); \ ! 102: __CURIOwriteRegister(rXCL, 0xFF); \ ! 103: SynchronizeIO(); \ ! 104: __CURIOsetCommandRegister((forOutput) ? cDMAXferPad : cXferPad); \ ! 105: } while (0) ! 106: #define __CURIOclearTransferCountZeroBit() __CURIOsetCommandRegister(cNOP | bDMDEnBit) ! 107: #define __CURIOgetTransferCount() ( \ ! 108: ( \ ! 109: ( ((__CURIOreadRegister(rTCH) & 0xFF) << 16) \ ! 110: | ((__CURIOreadRegister(rXCM) & 0xFF) << 8) \ ! 111: | ((__CURIOreadRegister(rXCL) & 0xFF) << 0) \ ! 112: ))) ! 113: #define __CURIOsetDestinationID(target) do { \ ! 114: __CURIOwriteRegister(rSTA, target); \ ! 115: SynchronizeIO(); \ ! 116: } while (0) ! 117: #define __CURIOinitiatorCommandComplete() __CURIOsetCommandRegister(cCmdComp) ! 118: #define __CURIOenableSelectionOrReselection() __CURIOsetCommandRegister(cEnSelResel) ! 119: #define __CURIOdisconnect() __CURIOsetCommandRegister(cDisconnect) ! 120: /* ! 121: * Execute __CURIOgetFifoByte using the following sequence: ! 122: * SynchronizeIO(); ! 123: * result = __CURIOgetFifoByte(); ! 124: */ ! 125: #define __CURIOgetFifoByte() ( (UInt8) ( \ ! 126: __CURIOreadRegister(rFFO) \ ! 127: )) ! 128: #define __CURIOputByteIntoFifo(theByte) do { \ ! 129: __CURIOwriteRegister(rFFO, (theByte)); \ ! 130: SynchronizeIO(); \ ! 131: } while (0) ! 132: #define __CURIOflushFifo() do { \ ! 133: __CURIOsetCommandRegister(cFlshFFO); \ ! 134: __CURIOnop(); /* Mandatory 360 nsec delay */ \ ! 135: __CURIOnop(); \ ! 136: } while (0) ! 137: /* ! 138: * Execute __CURIOgetFifoCount using the following sequence: ! 139: * SynchronizeIO(); ! 140: * result = __CURIOgetFifoCount(); ! 141: */ ! 142: #define __CURIOgetFifoCount() ( (UInt8) ( \ ! 143: (__CURIOreadRegister(rFOS) & kFIFOCountMask) \ ! 144: )) ! 145: #define __CURIOsetSelectionTimeout(tmo) do { \ ! 146: UInt8 __selectionTimeout = (tmo); \ ! 147: gLastSelectionTimeout = __selectionTimeout; \ ! 148: __CURIOwriteRegister(rINT, __selectionTimeout); \ ! 149: SynchronizeIO(); \ ! 150: } while (0) ! 151: #define __CURIOconfigForNonDMA() do { \ ! 152: __CURIOwriteRegister(rCF3, CONFIG_FOR_NON_DMA); \ ! 153: SynchronizeIO(); \ ! 154: } while (0) ! 155: #define __CURIOconfigForDMA() do { \ ! 156: __CURIOwriteRegister(rCF3, CONFIG_FOR_DMA); \ ! 157: SynchronizeIO(); \ ! 158: } while (0) ! 159: #define __CURIOmessageAccept() do { \ ! 160: __CURIOsetCommandRegister(cMsgAcep); \ ! 161: SynchronizeIO(); \ ! 162: } while (0) ! 163: #define __CURIOmessageReject() do { \ ! 164: __CURIOputByteIntoFifo(kScsiMsgRejectMsg); \ ! 165: __CURIOsetATN(); \ ! 166: } while (0) ! 167: #define __CURIOsetATN() do { \ ! 168: __CURIOsetCommandRegister(cSetAtn); \ ! 169: SynchronizeIO(); \ ! 170: } while (0) ! 171: #define __CURIOclearATN() do { \ ! 172: __CURIOsetCommandRegister(cRstAtn); \ ! 173: SynchronizeIO(); \ ! 174: } while (0) ! 175: #define __CURIOsetSynchronousOffset(off) do { \ ! 176: UInt8 __off = (off); \ ! 177: gLastSynchronousOffset = __off; \ ! 178: __CURIOwriteRegister(rFOS, __off); \ ! 179: SynchronizeIO(); \ ! 180: } while (0) ! 181: #define __CURIOsetSynchronousPeriod(per) do { \ ! 182: UInt8 __per = (per); \ ! 183: gLastSynchronousPeriod = __per; \ ! 184: __CURIOwriteRegister(rSQS, __per); \ ! 185: SynchronizeIO(); \ ! 186: } while (0) ! 187: #define __CURIOwriteRegister(reg, val) do { \ ! 188: UInt8 __reg = (reg); \ ! 189: UInt8 __val = (val); \ ! 190: TAG("wri", (__reg << 8) | __val); \ ! 191: CurioWriteRegister(__reg, __val); \ ! 192: SynchronizeIO(); \ ! 193: } while (0) ! 194: #define __CURIOreadRegister(reg) CurioReadRegister(reg) ! 195: #define __CURIOsetCommandRegister(cmdByte) do { \ ! 196: UInt8 __cmdByte = (cmdByte); \ ! 197: ddmChip("curioSetCommandRegister byte = %x\n", __cmdByte, 2, 3, 4, 5); \ ! 198: SynchronizeIO(); /* paranoia */ \ ! 199: CurioWriteRegister(rCMD, __cmdByte); \ ! 200: SynchronizeIO(); \ ! 201: } while (0) ! 202: #define __CURIOreadCommandRegister() __CURIOreadRegister(rCMD) ! 203: #define __CURIOsetSelectTimeout(tmo, rate, factor) (( (UInt32) ( \ ! 204: (((UInt32) rate) * ((UInt32) tmo)) / (7682 * ((UInt32) factor)) \ ! 205: ))) ! 206: ! 207: ! 208: #if USE_CURIO_METHODS ! 209: /* ! 210: * Expand the one-liner macros as methods. This is useful for ! 211: * debugging as methods can be logged. ! 212: */ ! 213: #define CURIOreadStatusRegister() [self curioReadStatusRegister] ! 214: #define CURIOreadSequenceStateRegister() [self curioReadSequenceStateRegister] ! 215: #define CURIOreadInterruptRegister() [self curioReadInterruptRegister] ! 216: #define CURIOstartMSGIAction() [self curioStartMSGIAction] ! 217: #define CURIOnop() [self curioNop] ! 218: #define CURIOstartNonDMATransfer() [self curioStartNonDMATransfer] ! 219: #define CURIOstartDMATransfer(count) [self curioStartDMATransfer : (count)] ! 220: #define CURIOtransferPad(forOutput) [self curioTransferPad : (forOutput)] ! 221: #define CURIOclearTransferCountZeroBit() [self curioClearTransferCountZeroBit] ! 222: #define CURIOgetTransferCount() [self curioGetTransferCount] ! 223: #define CURIOsetDestinationID(target) [self curioSetDestinationID : (target)] ! 224: #define CURIOinitiatorCommandComplete() [self curioInitiatorCommandComplete] ! 225: #define CURIOenableSelectionOrReselection() [self curioEnableSelectionOrReselection] ! 226: #define CURIOdisconnect() [self curioDisconnect] ! 227: #define CURIOgetFifoByte() [self curioGetFifoByte] ! 228: #define CURIOputByteIntoFifo(theByte) [self curioPutByteIntoFifo : (theByte)] ! 229: #define CURIOflushFifo() [self curioFlushFifo] ! 230: #define CURIOgetFifoCount() [self curioGetFifoCount] ! 231: #define CURIOsetSelectionTimeout(tmo) [self curioSetSelectionTimeout : (tmo)] ! 232: #define CURIOconfigForNonDMA() [self curioConfigForNonDMA] ! 233: #define CURIOconfigForDMA() [self curioConfigForDMA] ! 234: #define CURIOmessageAccept() [self curioMessageAccept] ! 235: #define CURIOmessageReject() [self curioMessageReject] ! 236: #define CURIOsetATN() [self curioSetATN] ! 237: #define CURIOclearATN() [self curioClearATN] ! 238: #define CURIOsetSynchronousOffset(off) [self curioSetSynchronousOffset : (off)] ! 239: #define CURIOsetSynchronousPeriod(per) [self curioSetSynchronousPeriod : (per)] ! 240: #define CURIOwriteRegister(reg, val) [self curioWriteRegister : (reg) value : (val)] ! 241: #define CURIOreadRegister(reg) [self curioReadRegister : (reg)] ! 242: #define CURIOsetCommandRegister(cmdByte) [self curioSetCommandRegister : (cmdByte)] ! 243: #define CURIOreadCommandRegister() [self curioReadCommandRegister] ! 244: #define CURIOsetSelectTimeout(tmo, rate, factor) \ ! 245: [self curioSetSelectTimeout : (tmo) \ ! 246: curioClockMHz : (rate) \ ! 247: curioClockFactor : (factor) \ ! 248: ] ! 249: #else ! 250: /* ! 251: * Define the public CURIOxxx macros as private macros ! 252: */ ! 253: #define CURIOreadStatusRegister() __CURIOreadStatusRegister() ! 254: #define CURIOreadSequenceStateRegister() __CURIOreadSequenceStateRegister() ! 255: #define CURIOreadInterruptRegister() __CURIOreadInterruptRegister() ! 256: #define CURIOstartMSGIAction() __CURIOstartMSGIAction() ! 257: #define CURIOnop() __CURIOnop() ! 258: #define CURIOstartNonDMATransfer() __CURIOstartNonDMATransfer() ! 259: #define CURIOstartDMATransfer(count) __CURIOstartDMATransfer(count) ! 260: #define CURIOtransferPad(forOutput) __CURIOtransferPad(forOutput) ! 261: #define CURIOclearTransferCountZeroBit() __CURIOclearTransferCountZeroBit() ! 262: #define CURIOgetTransferCount() __CURIOgetTransferCount() ! 263: #define CURIOsetDestinationID(target) __CURIOsetDestinationID(target) ! 264: #define CURIOinitiatorCommandComplete() __CURIOinitiatorCommandComplete() ! 265: #define CURIOenableSelectionOrReselection() __CURIOenableSelectionOrReselection() ! 266: #define CURIOdisconnect() __CURIOdisconnect() ! 267: #define CURIOgetFifoByte() __CURIOgetFifoByte() ! 268: #define CURIOputByteIntoFifo(theByte) __CURIOputByteIntoFifo(theByte) ! 269: #define CURIOflushFifo() __CURIOflushFifo() ! 270: #define CURIOgetFifoCount() __CURIOgetFifoCount() ! 271: #define CURIOsetSelectionTimeout(tmo) __CURIOsetSelectionTimeout(tmo) ! 272: #define CURIOconfigForNonDMA() __CURIOconfigForNonDMA() ! 273: #define CURIOconfigForDMA() __CURIOconfigForDMA() ! 274: #define CURIOmessageAccept() __CURIOmessageAccept() ! 275: #define CURIOmessageReject() __CURIOmessageReject() ! 276: #define CURIOsetATN() __CURIOsetATN() ! 277: #define CURIOclearATN() __CURIOclearATN() ! 278: #define CURIOsetSynchronousOffset(off) __CURIOsetSynchronousOffset(off) ! 279: #define CURIOsetSynchronousPeriod(per) __CURIOsetSynchronousPeriod(per) ! 280: #define CURIOwriteRegister(reg, val) __CURIOwriteRegister(reg, val) ! 281: #define CURIOreadRegister(reg) __CURIOreadRegister(reg) ! 282: #define CURIOsetCommandRegister(cmdByte) __CURIOsetCommandRegister(cmdByte) ! 283: #define CURIOreadCommandRegister() __CURIOreadCommandRegister() ! 284: #define CURIOsetSelectTimeout(tmo, rate, factor) __CURIOsetSelectTimeout(tmo, rate, factor) ! 285: #endif /* USE_CURIO_METHODS */ ! 286: /* ! 287: * These "macros" always expand to method calls. This keeps the mainline ! 288: * source code looking consistent. Methods were chosen either because ! 289: * the code is messy or because it is seldom used (or both). ! 290: */ ! 291: #define CURIOquickCheckForChipInterrupt() [self curioQuickCheckForChipInterrupt] ! 292: #define CURIOinterruptPending() [self curioInterruptPending] ! 293: #define CURIOputCommandIntoFifo() [self curioPutCommandIntoFifo] ! 294: #define CURIOresetChip() [self curioResetChip] ! 295: #define CURIOresetSCSIBus() [self curioResetSCSIBus] ! 296: ! 297: @interface Apple96_SCSI(CurioPrivate) ! 298: ! 299: /* ! 300: * Private methods ! 301: */ ! 302: - (Boolean) curioQuickCheckForChipInterrupt; ! 303: - (Boolean) curioInterruptPending; ! 304: - (void) curioPutCommandIntoFifo; ! 305: - (void) curioResetChip; ! 306: - (void) curioResetSCSIBus; ! 307: ! 308: #if USE_CURIO_METHODS ! 309: - (UInt8) curioReadStatusRegister; ! 310: - (UInt8) curioReadSequenceStateRegister; ! 311: - (UInt8) curioReadInterruptRegister; ! 312: - (void) curioStartMSGIAction; ! 313: - (void) curioNop; ! 314: - (void) curioStartNonDMATransfer; ! 315: - (void) curioStartDMATransfer ! 316: : (UInt32) transferCount; ! 317: - (void) curioTransferPad ! 318: : (Boolean) forOutput; ! 319: - (void) curioClearTransferCountZeroBit; ! 320: - (UInt32) curioGetTransferCount; ! 321: - (void) curioSetDestinationID ! 322: : (UInt8) targetID; ! 323: - (void) curioInitiatorCommandComplete; ! 324: - (void) curioEnableSelectionOrReselection; ! 325: - (void) curioDisconnect; ! 326: - (UInt8) curioGetFifoByte; ! 327: - (void) curioPutByteIntoFifo ! 328: : (UInt8) value; ! 329: - (void) curioFlushFifo; ! 330: - (UInt32) curioGetFifoCount; ! 331: - (void) curioSetSelectionTimeout ! 332: : (UInt8) selectionTimeout; ! 333: - (void) curioConfigForNonDMA; ! 334: - (void) curioConfigForDMA; ! 335: - (void) curioMessageAccept; ! 336: - (void) curioMessageReject; ! 337: - (void) curioSetATN; ! 338: - (void) curioClearATN; ! 339: - (void) curioSetSynchronousOffset ! 340: : (UInt8) synchronousOffset; ! 341: - (void) curioSetSynchronousPeriod ! 342: : (UInt8) synchronousPeriod; ! 343: - (void) curioWriteRegister ! 344: : (UInt8) curioRegister ! 345: value : (UInt8) value; ! 346: - (UInt8) curioReadRegister ! 347: : (UInt8) curioRegister; ! 348: - (void) curioSetCommandRegister ! 349: : (UInt8) commandByte; ! 350: - (UInt8) curioReadCommandRegister; ! 351: - (UInt32) curioNanosecondToSyncPeriod ! 352: : (UInt8) nsecPeriod /* Desired period */ ! 353: fastSCSI : (UInt32) fastSCSI /* Control3.CR3_FAST_SCSI */ ! 354: clockRate : (UInt32) clockRate; /* in MHz */ ! 355: - (UInt32) curioSelectTimeout ! 356: : (UInt32) selectTimeoutMSec ! 357: curioClockMHz : (UInt32) chipClockRateMHz ! 358: curioClockFactor : (UInt32) chipClockFactor; ! 359: #endif /* USE_CURIO_METHODS */ ! 360: @end /* Apple96_SCSI(CurioPrivate) */ ! 361: ! 362: ! 363: ! 364: ! 365:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.