Chameleon

Chameleon Svn Source Tree

Root/tags/2.3/i386/include/IOKit/ata/IOATATypes.h

Source at commit 2862 created 7 years 22 days ago.
By ifabio, Tag 2.3 release, bump svn to 2.4
1/*
2 * Copyright (c) 2000-2008 Apple, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23
24#ifndef _IOATATYPES_H
25#define _IOATATYPES_H
26
27#include <IOKit/IOTypes.h>
28
29
30/*!
31
32@header IOATAtypes.h
33@discussion contains various definitions and constants for use in the IOATAFamily and clients. Header Doc is incomplete at this point, but file is heavily commented.
34
35*/
36// property strings
37#define kATADevPropertyKey "ata device type"
38#define kATATypeATAString "ata"
39#define kATATypeATAPIString "atapi"
40#define kATATypeUnknownString "unknown"
41
42#define kATAVendorPropertyKey "device model"
43#define kATARevisionPropertyKey "device revision"
44#define kATASerialNumPropertyKey "device serial"
45
46#define kATAUnitNumberKey "unit number"
47
48#define kATASocketKey "socket type"
49#define kATAInternalSocketString "internal"
50#define kATAMediaBaySocketString "media-bay"
51#define kATAPCCardSocketString "pccard"
52#define kATAInternalSATAString "serial-ata"
53#define kATASATABayString "sata-bay"
54#define kATAInternalSATA2 "serial-ata-2"
55#define kATASATA2BayString "sata-2-bay"
56#define kATAUnkownSocketString "unknown"
57
58#define kATANotifyOnChangeKey "media-notify"
59
60// allows for porting to non-memory-mapped IO systems, such as x86.
61// for such a platform, create a class and overload the assignment operators
62// so that the correct IO operation is performed and define the type for that architecture port.
63#ifdef __ppc__
64#define IOATARegPtr8 volatile UInt8*
65#define IOATARegPtr16 volatile UInt16*
66#define IOATARegPtr32 volatile UInt32*
67#define IOATARegPtr8Cast(x) ((IOATARegPtr8)(x))
68#elif defined( __i386__ ) || defined( __x86_64__ )
69#include <IOKit/ata/IOATARegI386.h>
70#else
71#error Unknown machine architecture
72#endif
73
74enum ataSocketType{
75
76kUnknownSocket= 0,
77kInternalATASocket,
78kMediaBaySocket,
79kPCCardSocket,
80kInternalSATA,
81kSATABay,
82kInternalSATA2,
83kSATA2Bay
84
85} ;
86
87
88enum ataDeviceType {
89
90kUnknownATADeviceType = 0,
91kATADeviceType,
92kATAPIDeviceType
93
94} ;
95
96// enum for bits 5 and 6 of word zero of
97// the identify packet device info data.
98// shift word-0 5-bits left, mask 0x03 and these enums apply.
99enum atapiConfig {
100
101kATAPIDRQSlow = 0x00,
102kATAPIIRQPacket = 0x01,
103kATAPIDRQFast= 0x10,
104kATAPIUnknown = 0x11
105
106};
107
108
109enum ataUnitID {
110
111kATAInvalidDeviceID= -1,
112kATADevice0DeviceID= 0,/* aka, Master. Device 0 is the correct terminology */
113kATADevice1DeviceID= 1/* aka, Slave. Device 1 is the correct terminology */
114
115} ;
116
117enum {
118
119kATADefaultSectorSize = 512
120};
121
122/* Task file definition *** Error Register *** */
123enum {
124bATABadBlock= 7,/* bit number of bad block error bit*/
125bATAUncorrectable= 6,/* bit number of uncorrectable error bit*/
126bATAMediaChanged= 5,/* bit number of media changed indicator*/
127bATAIDNotFound= 4,/* bit number of ID not found error bit*/
128bATAMediaChangeReq= 3,/* bit number of media changed request*/
129bATACommandAborted= 2,/* bit number of command abort bit*/
130bATATrack0NotFound= 1,/* bit number of track not found*/
131bATAAddressNotFound= 0,/* bit number of address mark not found*/
132mATABadBlock= 1 << bATABadBlock,/* Bad Block Detected*/
133mATAUncorrectable= 1 << bATAUncorrectable,/* Uncorrectable Data Error*/
134mATAMediaChanged= 1 << bATAMediaChanged,/* Media Changed Indicator (for removable)*/
135mATAIDNotFound= 1 << bATAIDNotFound,/* ID Not Found*/
136mATAMediaChangeReq= 1 << bATAMediaChangeReq,/* Media Change Requested (NOT IMPLEMENTED)*/
137mATACommandAborted= 1 << bATACommandAborted,/* Aborted Command*/
138mATATrack0NotFound= 1 << bATATrack0NotFound,/* Track 0 Not Found*/
139mATAAddressNotFound= 1 << bATAAddressNotFound/* Address Mark Not Found*/
140};
141
142/* Task file definition *** Features register *** */
143enum {
144bATAPIuseDMA= 0,/* bit number of useDMA bit (ATAPI)*/
145mATAPIuseDMA= 1 << bATAPIuseDMA
146};
147
148/* Task file definition *** ataTFSDH Register *** */
149enum {
150mATAHeadNumber= 0x0F,/* Head Number (bits 0-3) */
151mATASectorSize= 0xA0,/* bit 7=1; bit 5 = 01 (512 sector size) <DP4>*/
152mATADriveSelect= 0x10,/* Drive (0 = master, 1 = slave) */
153mATALBASelect= 0x40/* LBA mode bit (0 = chs, 1 = LBA)*/
154};
155
156/* Task file definition *** Status Register *** */
157enum {
158bATABusy= 7,/* bit number of BSY bit*/
159bATADriveReady= 6,/* bit number of drive ready bit*/
160bATAWriteFault= 5,/* bit number of write fault bit*/
161bATASeekComplete= 4,/* bit number of seek complete bit*/
162bATADataRequest= 3,/* bit number of data request bit*/
163bATADataCorrected= 2,/* bit number of data corrected bit*/
164bATAIndex= 1,/* bit number of index mark*/
165bATAError= 0,/* bit number of error bit*/
166mATABusy= 1 << bATABusy,/* Unit is busy*/
167mATADriveReady= 1 << bATADriveReady,/* Unit is ready*/
168mATAWriteFault= 1 << bATAWriteFault,/* Unit has a write fault condition*/
169mATASeekComplete= 1 << bATASeekComplete,/* Unit seek complete*/
170mATADataRequest= 1 << bATADataRequest,/* Unit data request*/
171mATADataCorrected= 1 << bATADataCorrected,/* Data corrected*/
172mATAIndex= 1 << bATAIndex,/* Index mark - NOT USED*/
173mATAError= 1 << bATAError/* Error condition - see error register*/
174};
175
176/* Task file definition *** Device Control Register *** */
177enum {
178bATADCROne= 3,/* bit number of always one bit*/
179bATADCRReset= 2,/* bit number of reset bit*/
180bATADCRnIntEnable= 1,/* bit number of interrupt disable*/
181mATADCROne= 1 << bATADCROne,/* always one bit*/
182mATADCRReset= 1 << bATADCRReset,/* Reset (1 = reset)*/
183mATADCRnIntEnable= 1 << bATADCRnIntEnable/* Interrupt Disable(0 = enabled)*/
184};
185
186
187/* 'ataRegMask' field of the ataRegAccess definition*/
188enum ataRegMask{
189
190bATAAltSDevCValid= 14,/* bit number of alternate status/device cntrl valid bit*/
191bATAStatusCmdValid= 7,/* bit number of status/command valid bit*/
192bATASDHValid= 6,/* bit number of ataTFSDH valid bit*/
193bATACylinderHiValid= 5,/* bit number of cylinder high valid bit*/
194bATACylinderLoValid= 4,/* bit number of cylinder low valid bit*/
195bATASectorNumValid= 3,/* bit number of sector number valid bit*/
196bATASectorCntValid= 2,/* bit number of sector count valid bit*/
197bATAErrFeaturesValid= 1,/* bit number of error/features valid bit*/
198bATADataValid= 0,/* bit number of data valid bit*/
199mATAAltSDevCValid= 1 << bATAAltSDevCValid,/* alternate status/device control valid*/
200mATAStatusCmdValid= 1 << bATAStatusCmdValid,/* status/command valid*/
201mATASDHValid= 1 << bATASDHValid,/* ataTFSDH valid*/
202mATACylinderHiValid= 1 << bATACylinderHiValid,/* cylinder high valid*/
203mATACylinderLoValid= 1 << bATACylinderLoValid,/* cylinder low valid*/
204mATASectorNumValid= 1 << bATASectorNumValid,/* sector number valid*/
205mATASectorCntValid= 1 << bATASectorCntValid,/* sector count valid*/
206mATAErrFeaturesValid= 1 << bATAErrFeaturesValid,/* error/features valid*/
207mATADataValid= 1 << bATADataValid/* data valid*/
208
209} ;
210
211
212enum ataFlags{
213bATAFlagQuiesce= 20,
214bATAFlagNoIRQ= 19,/* bit Number of no IRQ protocol flag*/
215bATAFlag48BitLBA= 18,
216bATAFlagDMAQueued= 17,
217bATAFlagOverlapped= 16,
218bATAFlagUseConfigSpeed= 15,/* bit number of use configured speed flag*/
219bATAFlagByteSwap= 14,/* bit number of byte swap flag*/
220bATAFlagIORead= 13,/* bit number of I/O read flag*/
221bATAFlagIOWrite= 12,/* bit number of I/O write flag*/
222bATAFlagTFAccessResult = 8,/* bit number of get register results on command completion.*/
223bATAFlagUseDMA= 7,/* bit number of use DMA flag*/
224bATAFlagProtocolATAPI= 5,/* bit number of ATAPI protocol*/
225bATAFlagImmediate= 1,/* bit number of immediate flag */
226bATAFlagTFAccess= 0,/* bit number of TF access */
227
228mATAFlagQuiesce= 1 << bATAFlagQuiesce,
229mATAFlagUseNoIRQ= 1 << bATAFlagNoIRQ, /* Special purpose! Avoid using! No-IRQ, polled synchronous protocol valid only for PIO commands*/
230mATAFlag48BitLBA= 1 << bATAFlag48BitLBA,/* Use 48 bit extended LBA protocol on this command. Requires support from the controller.*/
231mATAFlagDMAQueued= 1 << bATAFlagDMAQueued,/* Use tagged dma queuing protocol on this command. Requires support from the controller.*/
232mATAFlagOverlapped= 1 << bATAFlagOverlapped,/* Use overllaped protocol on this command. Requires support from the controller.*/
233mATAFlagUseConfigSpeed= 1 << bATAFlagUseConfigSpeed, /* Use the configured interface speed = true. False = use default PIO (slow) speed. valid only for PIO commands*/
234mATAFlagByteSwap= 1 << bATAFlagByteSwap,/* Swap data bytes (read - after; write - before)*/
235mATAFlagIORead= 1 << bATAFlagIORead,/* Read (in) operation*/
236mATAFlagIOWrite= 1 << bATAFlagIOWrite,/* Write (out) operation*/
237mATAFlagTFAccessResult= 1 << bATAFlagTFAccessResult, /* get contents of TaskFile registers indicated in TFMask on command completion, even if no error*/
238mATAFlagUseDMA= 1 << bATAFlagUseDMA,
239mATAFlagProtocolATAPI= 1 << bATAFlagProtocolATAPI,/* ATAPI protocol indicator*/
240mATAFlagImmediate= 1 << bATAFlagImmediate,/* Put command at head of queue */
241mATAFlagTFAccess= 1 << bATAFlagTFAccess,/* Return Taskfile on error status*/
242
243} ;
244
245/* The Function codes sent to controllers*/
246enum ataOpcode {
247
248kATANoOp = 0,
249kATAFnExecIO ,/* Execute ATA I/O */
250kATAPIFnExecIO,/* ATAPI I/O */
251kATAFnRegAccess ,/* Register Access */
252
253kATAFnQFlush ,/* I/O Queue flush requests for your unit number */
254kATAFnBusReset /* Reset ATA bus */
255
256} ;
257
258
259/* The ATA Event codes */
260/* sent when calling the device driver's event handler*/
261enum ataEventCode {
262kATANullEvent= 0x00,/* Just kidding -- nothing happened*/
263kATAOnlineEvent= 0x01,/* An ATA device has come online*/
264kATAOfflineEvent= 0x02,/* An ATA device has gone offline*/
265kATARemovedEvent= 0x03,/* An ATA device has been removed from the bus*/
266kATAResetEvent= 0x04,/* Someone gave a hard reset to the drive*/
267kATAOfflineRequest= 0x05,/* Someone requesting to offline the drive*/
268kATAEjectRequest= 0x06,/* Someone requesting to eject the drive*/
269kATAPIResetEvent= 0x07,/* Someone gave a ATAPI reset to the drive*/
270kATAReservedEvent= 0x80/* RESERVED*/
271};
272
273
274// These need to be combined with a new enumeration of the current ATA/ATAPI command set.
275// Some opcodes are of interest to ATA controllers, since they imply special protocols
276// or handling. Device Reset, Execute Device Diagnostics have subtle side effects that
277// controllers need to be aware of, so we snoop for those commands being issued.
278// the rest are here for informational purposes.
279
280// BUG make new enum for all current ATA commands.
281
282enum {
283kSOFTRESET=0x008,// ATAPI Soft Reset command
284kPACKET=0x0A0,// ATAPI Packet command
285kID_DRIVE=0x0A1// ATAPI Identify drive command
286};
287/* ATA Command Opcode definition*/
288enum {
289kATAcmdWORetry= 0x01,/* Without I/O retry option*/
290kATAcmdNOP= 0x0000,/* NOP operation - media detect*/
291kATAcmdRecal= 0x0010,/* Recalibrate command */
292kATAcmdRead= 0x0020,/* Read command */
293kATAcmdReadLong= 0x0022,/* Read Long command*/
294kATAcmdReadExtended= 0x0024,/* Read Extended (with retries)*/
295kATAcmdReadDMAExtended= 0x0025,/* Read DMA Extended (with retries)*/
296kATAcmdWrite= 0x0030,/* Write command */
297kATAcmdWriteLong= 0x0032,/* Write Long*/
298kATAcmdWriteExtended= 0x0034,/* Write Extended (with retries)*/
299kATAcmdWriteDMAExtended= 0x0035,/* Write DMA Extended (with retries)*/
300kATAcmdWriteVerify= 0x003C,/* Write verify*/
301kATAcmdReadVerify= 0x0040,/* Read Verify command */
302kATAcmdFormatTrack= 0x0050,/* Format Track command */
303kATAcmdSeek= 0x0070,/* Seek command */
304kATAcmdDiagnostic= 0x0090,/* Drive Diagnostic command */
305kATAcmdInitDrive= 0x0091,/* Init drive parameters command */
306kATAcmdReadMultiple= 0x00C4,/* Read multiple*/
307kATAcmdWriteMultiple= 0x00C5,/* Write multiple*/
308kATAcmdSetRWMultiple= 0x00C6,/* Set Multiple for Read/Write Multiple*/
309kATAcmdReadDMA= 0x00C8,/* Read DMA (with retries)*/
310kATAcmdWriteDMA= 0x00CA,/* Write DMA (with retries)*/
311kATAcmdMCAcknowledge= 0x00DB,/* Acknowledge media change - removable*/
312kATAcmdDoorLock= 0x00DE,/* Door lock*/
313kATAcmdDoorUnlock= 0x00DF,/* Door unlock*/
314kATAcmdStandbyImmed= 0x00E0,/* Standby Immediate*/
315kATAcmdIdleImmed= 0x00E1,/* Idle Immediate*/
316kATAcmdStandby= 0x00E2,/* Standby*/
317kATAcmdIdle= 0x00E3,/* Idle*/
318kATAcmdReadBuffer= 0x00E4,/* Read sector buffer command */
319kATAcmdCheckPowerMode= 0x00E5,/* Check power mode command<04/04/94>*/
320kATAcmdSleep= 0x00E6,/* Sleep*/
321kATAcmdFlushCache= 0x00E7,/* Flush Cache */
322kATAcmdWriteBuffer= 0x00E8,/* Write sector buffer command */
323kATAcmdWriteSame= 0x00E9,/* Write same data to multiple sectors*/
324kATAcmdFlushCacheExtended= 0x00EA,/* Flush Cache Extended */
325kATAcmdDriveIdentify= 0x00EC,/* Identify Drive command */
326kATAcmdMediaEject= 0x00ED,/* Media Eject*/
327kATAcmdSetFeatures= 0x00EF/* Set Features*/
328};
329
330/* Set feature command opcodes*/
331enum {
332kATAEnableWriteCache= 0x02,/*Enable write cache*/
333kATASetTransferMode= 0x03,/*Set transfer mode*/
334kATAEnableAPM= 0x05,/* Enable Advanced Power Management*/
335kATASetPIOMode= 0x08,/*PIO Flow Control Tx Mode bit*/
336kATADisableWriteCache= 0x82,/*disable write cache*/
337kATAEnableReadAhead= 0xAA/*Read look-ahead enable*/
338};
339
340// revisit the opcode enumerations.
341
342//////////////////////
343
344
345/* task file for ata */
346typedef struct ataTaskFile {
347
348UInt8 ataTFFeatures;/* <-> Error(R) or ataTFFeatures(W) register image */
349UInt8 ataTFCount;/* <-> Sector count/remaining */
350UInt8 ataTFSector;/* <-> Sector start/finish */
351UInt8 ataTFCylLo;/* <-> ataTFCylLo*/
352UInt8 ataTFCylHigh;/* <-> ataTFCylHigh */
353UInt8 ataTFSDH;/* <-> ataTFSDH register image*/
354UInt8 ataTFCommand;/* <-> Status(R) or Command(W) register image */
355
356} ataTaskFile;
357
358
359typedef struct ataRegisterImage {
360
361ataTaskFiletaskFile;
362UInt16ataDataRegister;/* <-> Data register. */
363UInt8 ataAltSDevCReg;/* <->: Alternate status(R) or Device Control(W) register image*/
364
365} ataRegisterImage ;
366
367
368typedef struct ATAPICmdPacket{
369
370UInt16 atapiPacketSize;/* Size of command packet in bytes*/
371UInt16 atapiCommandByte[8];/* The command packet itself*/
372
373}ATAPICmdPacket;
374
375
376
377// Error and result codes: TBD
378enum {
379kATAErrUnknownType = -1,
380kATANoErr = 0,
381kATAQueueEmpty = 1,
382kATAUnknownOpcode,
383kATATimeoutErr,
384kATAInvalidDevID,
385kATAErrDevBusy,
386kATAModeNotSupported,
387kATADevIntNoCmd,
388kATADeviceError,
389kATADMAErr
390};
391
392
393#endif /* !_IOATATYPES_H */
394

Archive Download this file

Revision: 2862