]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ata/ata-standard/IOATAStandardDevice.h
xnu-201.42.3.tar.gz
[apple/xnu.git] / iokit / IOKit / ata / ata-standard / IOATAStandardDevice.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, 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 * IOATAStandardDevice.h
25 *
26 *
27 * Methods in this header provide information about the ATA device
28 * the device client driver is submitting the ATACommand(s) to.
29 *
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
32 * IOATACommand.h
33 */
34
35 #ifndef _IOATASTANDARDDEVICE_H
36 #define _IOATASTANDARDDEVICE_H
37
38 class IOATAStandardController;
39
40 class IOATAStandardDevice : public IOATADevice
41 {
42 OSDeclareDefaultStructors(IOATAStandardDevice)
43
44 friend class IOATAStandardCommand;
45 friend class IOATAStandardController;
46
47 /*------------------Methods provided to IOCDBDevice clients-----------------------*/
48 public:
49
50 /*
51 * Allocate a CDB Command
52 */
53 IOCDBCommand *allocCommand( IOCDBDevice *deviceType, UInt32 clientDataSize = 0 );
54
55 /*
56 * Abort all outstanding commands on this device
57 */
58 void abort();
59
60 /*
61 * Reset device (also aborts all outstanding commands)
62 */
63 void reset();
64
65 /*
66 * Obtain information about this device
67 */
68 void getInquiryData( void *inquiryBuffer,
69 UInt32 inquiryBufSize,
70 UInt32 *inquiryDataSize );
71
72 /*------------------Additional methods provided to IOATADevice clients-----------------------*/
73 public:
74 /*
75 * Allocate a ATACommand
76 */
77 IOATAStandardCommand *allocCommand( IOATAStandardDevice *deviceType, UInt32 clientDataSize = 0 );
78
79 /*
80 * Obtain information about this device
81 */
82 ATAUnit getUnit();
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();
92
93 /*
94 * Select default device timing for this device
95 */
96 bool selectTiming( ATATimingProtocol timingProtocol, bool fNotifyMsg = false );
97
98 /*
99 * Queue management commands
100 */
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 );
105
106 /*
107 *
108 */
109 IOWorkLoop *getWorkLoop() const;
110
111 /*------------------Methods private to the IOATADevice class----------------*/
112 public:
113 bool open( IOService *forClient, IOOptionBits options, void *arg );
114 void close( IOService *forClient, IOOptionBits options );
115 bool init( IOATAStandardController *forController, ATAUnit forUnit );
116 void free();
117
118 bool matchPropertyTable( OSDictionary * table );
119 IOService *matchLocation( IOService * client );
120
121 IOATACommand *allocCommand( IOATADevice *deviceType, UInt32 clientDataSize = 0 );
122
123 private:
124 void submitCommand( UInt32 cmdType, IOATAStandardCommand *ataCmd, UInt32 cmdSequenceNumber = 0 );
125 void receiveCommand( UInt32 cmdType, IOATAStandardCommand *ataCmd, UInt32 cmdSequenceNumber, void *p3 );
126
127 IOReturn probeDevice();
128 ATADeviceType probeDeviceType();
129
130 IOReturn doSpinUp();
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 );
136
137 bool getATATimings();
138
139 void selectTimingDone( IOATAStandardCommand *ataCmd );
140
141 void setupTarget();
142
143 void dispatchRequest();
144 bool dispatch( UInt32 *dispatchAction );
145
146 void abortAllCommands( ATACommandType abortCmdType );
147
148 IOATAStandardCommand *findCommandWithNexus( UInt32 tagValue );
149
150 void abortCommand( IOATAStandardCommand *ataCmd, UInt32 cmdSequenceNumber );
151 void completeCommand( IOATAStandardCommand *cmd );
152
153 void checkIdleNotify();
154
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 );
160
161 OSDictionary *createProperties();
162 bool addToRegistry( OSDictionary *propTable, OSObject *regObj, char *key, bool doRelease = true );
163 void stripBlanks( char *d, char *s, UInt32 l );
164
165 void endianConvertData( void *data, void *endianTable );
166
167 bool checkDeviceQueue( UInt32 *dispatchAction );
168 void checkNegotiate( IOATAStandardCommand *ataCmd );
169 bool checkTag( IOATAStandardCommand *ataCmd );
170 bool checkReqSense();
171 bool checkAbortQueue();
172 void checkCancelQueue();
173
174 bool allocTag( UInt32 *tagId );
175 void freeTag( UInt32 tagId );
176
177 void timer();
178
179 void resetOccurred( ATAClientMessage clientMsg = kATAClientMsgNone );
180 void resetComplete();
181
182 void rescheduleCommand( IOATAStandardCommand *ataCmd );
183
184 void suspend();
185 void resume();
186
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 );
199
200 private:
201 ATAUnit unit;
202 ATATarget *target;
203
204 IOATAStandardController *controller;
205 IOCommandGate *deviceGate;
206
207 IOService *client;
208 IORWLock * clientSem;
209
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;
215
216 ATACommandType abortCmdPending;
217
218 UInt32 reqSenseState;
219 UInt32 abortState;
220 UInt32 cancelState;
221 UInt32 negotiateState;
222
223 IOATAStandardCommand *reqSenseOrigCmd;
224
225 IOATAStandardCommand *reqSenseCmd;
226 IOATAStandardCommand *abortCmd;
227 IOATAStandardCommand *cancelCmd;
228 IOATAStandardCommand *probeCmd;
229
230 UInt32 normalQHeld;
231 UInt32 bypassQHeld;
232
233 bool idleNotifyActive;
234 CallbackFn idleNotifyCallback;
235 void *idleNotifyTarget;
236 void *idleNotifyRefcon;
237
238 bool isSuspended;
239 AbsoluteTime suspendTime;
240
241 UInt32 commandCount;
242 UInt32 commandLimit;
243 UInt32 commandLimitSave;
244
245 UInt32 maxTags;
246 UInt32 tagArraySize;
247 UInt32 *tagArray;
248
249 ATADeviceType deviceType;
250
251 UInt32 protocolsSupported;
252 UInt32 atapiPktInt;
253
254 ATAIdentify *identifyData;
255
256 ATAInquiry *inquiryData;
257 UInt32 inquiryDataSize;
258
259 ATATimingProtocol currentTiming;
260
261 UInt32 numTimings;
262 ATATiming ataTimings[kATAMaxTimings];
263
264 void *devicePrivateData;
265 };
266
267 #define kIOATAStandardDevice ((IOATAStandardDevice *)0)
268
269 #endif