2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
31 typedef struct ATAIdentify
33 UInt16 generalConfiguration
;
34 UInt16 logicalCylinders
;
38 UInt16 logicalSectorsPerTrack
;
40 char serialNumber
[20];
42 char firmwareRevision
[8];
44 UInt16 multipleModeSectors
;
51 UInt16 currentLogicalCylinders
;
52 UInt16 currentLogicalHeads
;
53 UInt16 currentLogicalSectorsPerTrack
;
54 UInt16 currentAddressableSectors
[2];
55 UInt16 currentMultipleModeSectors
;
56 UInt16 userAddressableSectors
[2];
59 UInt16 advancedPIOModes
;
60 UInt16 minDMACycleTime
;
61 UInt16 recDMACycleTime
;
62 UInt16 minPIOCycleTimeNoIORDY
;
63 UInt16 minPIOCyclcTimeIORDY
;
65 UInt16 busReleaseLatency
;
66 UInt16 serviceLatency
;
69 UInt16 reserved_10
[4];
72 UInt16 commandSetsSupported1
;
73 UInt16 commandSetsSupported2
;
74 UInt16 commandSetsSupported3
;
75 UInt16 commandSetsEnabled1
;
76 UInt16 commandSetsEnabled2
;
77 UInt16 commandSetsDefault
;
79 UInt16 securityEraseTime
;
80 UInt16 securityEnhancedEraseTime
;
81 UInt16 currentAdvPowerMgtValue
;
82 UInt16 reserved_11
[35];
83 UInt16 removableMediaSupported
;
84 UInt16 securityStatus
;
85 UInt16 reserved_12
[127];
90 typedef struct ATAPIInquiry
92 unsigned char devType
; /* 0 Device type, */
93 unsigned char devTypeMod
; /* 1 Device type modifier */
94 unsigned char version
; /* 2 ISO/ECMA/ANSI version */
95 unsigned char format
; /* 3 Response data format */
96 unsigned char length
; /* 4 Additional Length */
97 unsigned char reserved5
; /* 5 Reserved */
98 unsigned char reserved6
; /* 6 Reserved */
99 unsigned char flags
; /* 7 Capability flags */
100 unsigned char vendorName
[8]; /* 8-15 Vendor-specific */
101 unsigned char productName
[16]; /* 16-31 Product id */
102 unsigned char productRevision
[4]; /* 32-35 Product revision */
103 unsigned char vendorSpecific
[20]; /* 36-55 Vendor stuff */
104 unsigned char moreReserved
[40]; /* 56-95 Reserved */
108 * These are device type qualifiers. We need them to distinguish between "unknown"
109 * and "missing" devices.
113 kATAPIDevTypeQualifierConnected
= 0x00, /* Exists and is connected */
114 kATAPIDevTypeQualifierNotConnected
= 0x20, /* Logical unit exists */
115 kATAPIDevTypeQualifierReserved
= 0x40,
116 kATAPIDevTypeQualifierMissing
= 0x60, /* No such logical unit */
117 kATAPIDevTypeQualifierVendorSpecific
= 0x80, /* Non-standardized */
118 kATAPIDevTypeQualifierMask
= 0xE0,
123 kATAPIDevCapRelAdr
= 0x80,
124 kATAPIDevCapWBus32
= 0x40,
125 kATAPIDevCapWBus16
= 0x20,
126 kATAPIDevCapSync
= 0x10,
127 kATAPIDevCapLinked
= 0x08,
128 kATAPIDevCapCmdQue
= 0x02,
129 kATAPIDevCapSftRe
= 0x01,
132 typedef struct ATAPISenseData
134 unsigned char errorCode
; /* 0 Result validity */
135 unsigned char segmentNumber
; /* 1 Segment number */
136 unsigned char senseKey
; /* 2 Sense code, flags */
137 unsigned char info
[4]; /* 3-6 Sense-key specific */
138 unsigned char additionalSenseLength
; /* 7 Sense length info */
139 unsigned char reservedForCopy
[4]; /* 8-11 Sense-key specific */
140 unsigned char additionalSenseCode
; /* 12 What kind of error */
141 unsigned char additionalSenseQualifier
; /* 13 More error info */
142 unsigned char fruCode
; /* 14 Field replacable */
143 unsigned char senseKeySpecific
[2]; /* 15-16 Additional info */
144 unsigned char additional
[101]; /* 17-26 Additional info */
148 * The high-bit of errorCode signals whether there is a logical
149 * block. The low value signals whether there is a valid sense
153 kATAPISenseHasLBN
= 0x80, /* Logical block number set */
154 kATAPISenseInfoValid
= 0x70, /* Is sense key valid? */
155 kATAPISenseInfoMask
= 0x70, /* Mask for sense info */
156 kATAPISenseCurrentErr
= 0x70, /* Error code (byte 0 & 0x7F */
157 kATAPISenseDeferredErr
= 0x71, /* Error code (byte 0 & 0x7F */
161 * These bits may be set in the sense key
163 enum ATAPISenseKeyMasks
165 kATAPISenseKeyMask
= 0x0F,
166 kATAPISenseILI
= 0x20, /* Illegal logical Length */
167 kATAPISenseEOM
= 0x40, /* End of media */
168 kATAPISenseFileMark
= 0x80, /* End of file mark */
171 * ATA sense codes. (Returned after request sense).
175 kATAPISenseNone
= 0x00, /* No error */
176 kATAPISenseRecoveredErr
= 0x01, /* Warning */
177 kATAPISenseNotReady
= 0x02, /* Device not ready */
178 kATAPISenseMediumErr
= 0x03, /* Device medium error */
179 kATAPISenseHardwareErr
= 0x04, /* Device hardware error */
180 kATAPISenseIllegalReq
= 0x05, /* Illegal request for dev. */
181 kATAPISenseUnitAtn
= 0x06, /* Unit attention (not err) */
182 kATAPISenseDataProtect
= 0x07, /* Data protection */
183 kATAPISenseBlankCheck
= 0x08, /* Tape-specific error */
184 kATAPISenseVendorSpecific
= 0x09, /* Vendor-specific error */
185 kATAPISenseCopyAborted
= 0x0a, /* Copy request cancelled */
186 kATAPISenseAbortedCmd
= 0x0b, /* Initiator aborted cmd. */
187 kATAPISenseEqual
= 0x0c, /* Comparison equal */
188 kATAPISenseVolumeOverflow
= 0x0d, /* Write past end mark */
189 kATAPISenseMiscompare
= 0x0e, /* Comparison failed */
194 kATAPIStatusGood
= 0x00,
195 kATAPIStatusCheckCondition
= 0x02,
196 kATAPIStatusConditionMet
= 0x04,
197 kATAPIStatusBusy
= 0x08,
198 kATAPIStatusIntermediate
= 0x10,
199 kATAPIStatusIntermediateMet
= 0x0a,
200 kATAPIStatusReservationConfict
= 0x18,
201 kATAPIStatusCommandTerminated
= 0x22,
202 kATAPIStatusQueueFull
= 0x28,
208 kATAPIDevTypeDirect
= 0, /* Hard disk (not CD-ROM) */
209 kATAPIDevTypeSequential
, /* Magtape or DAT */
210 kATAPIDevTypePrinter
, /* Printer */
211 kATAPIDevTypeProcessor
, /* Attached processor */
212 kATAPIDevTypeWorm
, /* Write-once, read multiple */
213 kATAPIDevTypeCDROM
, /* CD-ROM */
214 kATAPIDevTypeScanner
, /* Scanner */
215 kATAPIDevTypeOptical
, /* Optical disk */
216 kATAPIDevTypeChanger
, /* Jukebox */
217 kATAPIDevTypeComm
, /* Communication link */
218 kATAPIDevTypeGraphicArts0A
,
219 kATAPIDevTypeGraphicArts0B
,
220 kATAPIDevTypeFirstReserved
, /* Reserved sequence start */
221 kATAPIDevTypeUnknownOrMissing
= 0x1F,
222 kATAPIDevTypeMask
= 0x1F,
227 * ATA command codes. Commands defined as ...6, ...10, ...12, are
228 * six-byte, ten-byte, and twelve-byte variants of the indicated command.
232 * These commands are supported for all devices.
236 kATAPICmdChangeDefinition
= 0x40,
237 kATAPICmdCompare
= 0x39,
238 kATAPICmdCopy
= 0x18,
239 kATAPICmdCopyAndVerify
= 0x3a,
240 kATAPICmdInquiry
= 0x12,
241 kATAPICmdLogSelect
= 0x4c,
242 kATAPICmdLogSense
= 0x4d,
243 kATAPICmdModeSelect12
= 0x55,
244 kATAPICmdModeSelect6
= 0x15,
245 kATAPICmdModeSense12
= 0x5a,
246 kATAPICmdModeSense6
= 0x1a,
247 kATAPICmdReadBuffer
= 0x3c,
248 kATAPICmdRecvDiagResult
= 0x1c,
249 kATAPICmdRequestSense
= 0x03,
250 kATAPICmdSendDiagnostic
= 0x1d,
251 kATAPICmdTestUnitReady
= 0x00,
252 kATAPICmdWriteBuffer
= 0x3b,
255 * These commands are supported by direct-access devices only.
257 kATAPICmdFormatUnit
= 0x04,
258 kATAPICmdLockUnlockCache
= 0x36,
259 kATAPICmdPrefetch
= 0x34,
260 kATAPICmdPreventAllowRemoval
= 0x1e,
261 kATAPICmdRead6
= 0x08,
262 kATAPICmdRead10
= 0x28,
263 kATAPICmdReadCapacity
= 0x25,
264 kATAPICmdReadDefectData
= 0x37,
265 kATAPICmdReadLong
= 0x3e,
266 kATAPICmdReassignBlocks
= 0x07,
267 kATAPICmdRelease
= 0x17,
268 kATAPICmdReserve
= 0x16,
269 kATAPICmdRezeroUnit
= 0x01,
270 kATAPICmdSearchDataEql
= 0x31,
271 kATAPICmdSearchDataHigh
= 0x30,
272 kATAPICmdSearchDataLow
= 0x32,
273 kATAPICmdSeek6
= 0x0b,
274 kATAPICmdSeek10
= 0x2b,
275 kATAPICmdSetLimits
= 0x33,
276 kATAPICmdStartStopUnit
= 0x1b,
277 kATAPICmdSynchronizeCache
= 0x35,
278 kATAPICmdVerify
= 0x2f,
279 kATAPICmdWrite6
= 0x0a,
280 kATAPICmdWrite10
= 0x2a,
281 kATAPICmdWriteAndVerify
= 0x2e,
282 kATAPICmdWriteLong
= 0x3f,
283 kATAPICmdWriteSame
= 0x41,
286 * These commands are supported by sequential devices.
288 kATAPICmdRewind
= 0x01,
289 kATAPICmdWriteFilemarks
= 0x10,
290 kATAPICmdSpace
= 0x11,
291 kATAPICmdLoadUnload
= 0x1B,
293 * ANSI ATA-II for CD-ROM devices.
295 kATAPICmdReadCDTableOfContents
= 0x43,
302 * ATA Register ordinals
305 kATARegFeatures
= 0x01,
306 kATARegSectorCount
= 0x02,
307 kATARegSectorNumber
= 0x03,
308 kATARegCylinderLow
= 0x04,
309 kATARegCylinderHigh
= 0x05,
310 kATARegDriveHead
= 0x06,
311 kATARegCommand
= 0x07,
314 kATARegStatus
= 0x07,
316 kATARegDeviceControl
= 0x08,
318 kATARegAltStatus
= 0x08,
321 * ATAPI Register ordinals
323 kATARegATAPIData
= 0x00,
324 kATARegATAPIFeatures
= 0x01,
325 kATARegATAPIIntReason
= 0x02,
326 kATARegATAPIByteCountLow
= 0x04,
327 kATARegATAPIByteCountHigh
= 0x05,
328 kATARegATAPIDeviceSelect
= 0x06,
329 kATARegATAPICommand
= 0x07,
331 kATARegATAPIError
= 0x01,
332 kATARegATAPIStatus
= 0x07,
334 kATARegATAPIDeviceControl
= 0x08,
336 kATARegATAPIAlternateStatus
= 0x08,
341 enum ATASectorCountQDMA
349 kATAPIIntReasonCD
= 0x01,
350 kATAPIIntReasonIO
= 0x02,
351 kATAPIIntReasonREL
= 0x04,
352 kATAPIIntReasonTagBit
= 0x08,
353 kATAPIIntReasonTagMask
= 0xf8,
361 kATACommandSetFeatures
= 0xef,
363 kATACommandIdentify
= 0xec,
365 kATACommandReadSector
= 0x20,
367 kATACommandService
= 0xa2,
369 kATACommandATAPIReset
= 0x08,
370 kATACommandATAPIPacket
= 0xa0,
371 kATACommandATAPIIdentify
= 0xa1,
376 kATAFeatureTransferMode
= 0x03,
377 kATATransferModePIODefault
= 0x00, // SectorCount settings (or'd w/Mode)
378 kATATransferModePIOwFC
= 0x08,
379 kATATransferModeDMA
= 0x20,
380 kATATransferModeUltraDMA33
= 0x40,
381 kATATransferModeMask
= 0x07,
387 kATAStatusERR
= 0x01,
388 kATAStatusIDX
= 0x02,
389 kATAStatusECC
= 0x04,
390 kATAStatusDRQ
= 0x08,
393 kATAStatusDRDY
= 0x40,
394 kATAStatusBSY
= 0x80,
396 kATAStatusSERV
= 0x10,
397 kATAStatusREL
= 0x20,
399 kATAPIStatusCHK
= 0x01,
400 kATAPIStatusDRQ
= 0x08,
401 kATAPIStatusSERV
= 0x10,
402 kATAPIStatusDMRD
= 0x20,
403 kATAPIStatusDRDY
= 0x40,
404 kATAPIStatusBSY
= 0x80,
410 kATAErrorABRT
= 0x04,
412 kATAErrorIDNF
= 0x10,
416 kATAPIErrorILI
= 0x01,
417 kATAPIErrorEOM
= 0x02,
418 kATAPIErrorABRT
= 0x04,
419 kATAPIErrorSenseKeyBit
= 0x10,
420 kATAPIErrorSenseKeyMask
= 0xf0,
423 enum ATADeviceControl
425 kATADevControlnIEN
= 0x02,
426 kATADevControlSRST
= 0x04,
431 kATASignatureSectorCount
= 0x01,
432 kATASignatureSectorNumber
= 0x01,
433 kATASignatureCylinderLow
= 0x00,
434 kATASignatureCylinderHigh
= 0x00,
436 kATAPISignatureCylinderLow
= 0x14,
437 kATAPISignatureCylinderHigh
= 0xeb,