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@
24 * IOATAStandardDevice.h
27 * Methods in this header provide information about the ATA device
28 * the device client driver is submitting the ATACommand(s) to.
30 * Note: ATACommand(s) are allocated and freed by methods in this class.
31 * The remaining methods to setup and submit ATACommands are defined in
35 #ifndef _IOATASTANDARDDEVICE_H
36 #define _IOATASTANDARDDEVICE_H
38 class IOATAStandardController
;
40 class IOATAStandardDevice
: public IOATADevice
42 OSDeclareDefaultStructors(IOATAStandardDevice
)
44 friend class IOATAStandardCommand
;
45 friend class IOATAStandardController
;
47 /*------------------Methods provided to IOCDBDevice clients-----------------------*/
51 * Allocate a CDB Command
53 IOCDBCommand
*allocCommand( IOCDBDevice
*deviceType
, UInt32 clientDataSize
= 0 );
56 * Abort all outstanding commands on this device
61 * Reset device (also aborts all outstanding commands)
66 * Obtain information about this device
68 void getInquiryData( void *inquiryBuffer
,
69 UInt32 inquiryBufSize
,
70 UInt32
*inquiryDataSize
);
72 /*------------------Additional methods provided to IOATADevice clients-----------------------*/
75 * Allocate a ATACommand
77 IOATAStandardCommand
*allocCommand( IOATAStandardDevice
*deviceType
, UInt32 clientDataSize
= 0 );
80 * Obtain information about this device
83 ATADeviceType
getDeviceType();
84 bool getIdentifyData( ATAIdentify
*identifyBuffer
);
85 bool getInquiryData( UInt32 inquiryBufSize
, ATAPIInquiry
*inquiryBuffer
);
86 bool getDeviceCapacity( UInt32
*blockMax
, UInt32
*blockSize
);
87 bool getProtocolsSupported( ATAProtocol
*protocolsSupported
);
88 bool getTimingsSupported( ATATimingProtocol
*timingsSupported
);
89 bool getTimingSelected( ATATimingProtocol
*timingProtocol
);
90 bool getTiming( ATATimingProtocol
*timingProtocol
, ATATiming
*timing
);
91 bool getATAPIPktInt();
94 * Select default device timing for this device
96 bool selectTiming( ATATimingProtocol timingProtocol
, bool fNotifyMsg
= false );
99 * Queue management commands
101 void holdQueue( UInt32 queueType
);
102 void releaseQueue( UInt32 queueType
);
103 void flushQueue( UInt32 queueType
, IOReturn rc
);
104 void notifyIdle( void *target
= 0, CallbackFn callback
= 0, void *refcon
= 0 );
109 IOWorkLoop
*getWorkLoop() const;
111 /*------------------Methods private to the IOATADevice class----------------*/
113 bool open( IOService
*forClient
, IOOptionBits options
, void *arg
);
114 void close( IOService
*forClient
, IOOptionBits options
);
115 bool init( IOATAStandardController
*forController
, ATAUnit forUnit
);
118 bool matchPropertyTable( OSDictionary
* table
);
119 IOService
*matchLocation( IOService
* client
);
121 IOATACommand
*allocCommand( IOATADevice
*deviceType
, UInt32 clientDataSize
= 0 );
124 void submitCommand( UInt32 cmdType
, IOATAStandardCommand
*ataCmd
, UInt32 cmdSequenceNumber
= 0 );
125 void receiveCommand( UInt32 cmdType
, IOATAStandardCommand
*ataCmd
, UInt32 cmdSequenceNumber
, void *p3
);
127 IOReturn
probeDevice();
128 ATADeviceType
probeDeviceType();
131 IOReturn
doIdentify( void **dataPtr
);
132 IOReturn
doSectorCommand( ATACommand ataCmd
, UInt32 ataLBA
, UInt32 ataCount
, void **dataPtr
);
133 IOReturn
doInquiry( void **dataPtr
);
134 IOReturn
doTestUnitReady();
135 IOReturn
doReadCapacity( void *data
);
137 bool getATATimings();
139 void selectTimingDone( IOATAStandardCommand
*ataCmd
);
143 void dispatchRequest();
144 bool dispatch( UInt32
*dispatchAction
);
146 void abortAllCommands( ATACommandType abortCmdType
);
148 IOATAStandardCommand
*findCommandWithNexus( UInt32 tagValue
);
150 void abortCommand( IOATAStandardCommand
*ataCmd
, UInt32 cmdSequenceNumber
);
151 void completeCommand( IOATAStandardCommand
*cmd
);
153 void checkIdleNotify();
155 void executeCommandDone( IOATAStandardCommand
*ataCmd
);
156 void executeReqSenseDone( IOATAStandardCommand
*ataCmd
);
157 void abortCommandDone( IOATAStandardCommand
*ataCmd
);
158 void cancelCommandDone( IOATAStandardCommand
*ataCmd
);
159 void finishCommand( IOATAStandardCommand
*ataCmd
);
161 OSDictionary
*createProperties();
162 bool addToRegistry( OSDictionary
*propTable
, OSObject
*regObj
, char *key
, bool doRelease
= true );
163 void stripBlanks( char *d
, char *s
, UInt32 l
);
165 void endianConvertData( void *data
, void *endianTable
);
167 bool checkDeviceQueue( UInt32
*dispatchAction
);
168 void checkNegotiate( IOATAStandardCommand
*ataCmd
);
169 bool checkTag( IOATAStandardCommand
*ataCmd
);
170 bool checkReqSense();
171 bool checkAbortQueue();
172 void checkCancelQueue();
174 bool allocTag( UInt32
*tagId
);
175 void freeTag( UInt32 tagId
);
179 void resetOccurred( ATAClientMessage clientMsg
= kATAClientMsgNone
);
180 void resetComplete();
182 void rescheduleCommand( IOATAStandardCommand
*ataCmd
);
187 void addCommand( queue_head_t
*list
, IOATAStandardCommand
*ataCmd
);
188 void stackCommand( queue_head_t
*list
, IOATAStandardCommand
*ataCmd
);
189 void deleteCommand( queue_head_t
*list
, IOATAStandardCommand
*ataCmd
, IOReturn rc
= kIOReturnSuccess
);
190 IOATAStandardCommand
*checkCommand( queue_head_t
*list
);
191 IOATAStandardCommand
*getCommand( queue_head_t
*list
);
192 void moveCommand( queue_head_t
*fromList
,
193 queue_head_t
*toList
,
194 IOATAStandardCommand
*ataCmd
,
195 IOReturn rc
= kIOReturnSuccess
);
196 void moveAllCommands( queue_head_t
*fromList
, queue_head_t
*toList
, IOReturn rc
= kIOReturnSuccess
);
197 bool findCommand( queue_head_t
*list
, IOATAStandardCommand
*findATACmd
);
198 void purgeAllCommands( queue_head_t
*list
, IOReturn rc
);
204 IOATAStandardController
*controller
;
205 IOCommandGate
*deviceGate
;
208 IORWLock
* clientSem
;
210 queue_head_t deviceList
;
211 queue_head_t bypassList
;
212 queue_head_t activeList
;
213 queue_head_t abortList
;
214 queue_head_t cancelList
;
216 ATACommandType abortCmdPending
;
218 UInt32 reqSenseState
;
221 UInt32 negotiateState
;
223 IOATAStandardCommand
*reqSenseOrigCmd
;
225 IOATAStandardCommand
*reqSenseCmd
;
226 IOATAStandardCommand
*abortCmd
;
227 IOATAStandardCommand
*cancelCmd
;
228 IOATAStandardCommand
*probeCmd
;
233 bool idleNotifyActive
;
234 CallbackFn idleNotifyCallback
;
235 void *idleNotifyTarget
;
236 void *idleNotifyRefcon
;
239 AbsoluteTime suspendTime
;
243 UInt32 commandLimitSave
;
249 ATADeviceType deviceType
;
251 UInt32 protocolsSupported
;
254 ATAIdentify
*identifyData
;
256 ATAInquiry
*inquiryData
;
257 UInt32 inquiryDataSize
;
259 ATATimingProtocol currentTiming
;
262 ATATiming ataTimings
[kATAMaxTimings
];
264 void *devicePrivateData
;
267 #define kIOATAStandardDevice ((IOATAStandardDevice *)0)