]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ata/ata-standard/IOATAStandardController.h
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / IOKit / ata / ata-standard / IOATAStandardController.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 * IOATAController.h
25 *
26 * Methods in this header list the methods an ATA controller driver must implement.
27 */
28 #ifndef _IOATASTANDARDCONTROLLER_H
29 #define _IOATASTANDARDCONTROLLER_H
30
31 #include <IOKit/IOWorkLoop.h>
32 #include <IOKit/IOCommandGate.h>
33 #include <IOKit/IOInterruptEventSource.h>
34 #include <IOKit/IOTimerEventSource.h>
35 #include <libkern/OSByteOrder.h>
36 #include <IOKit/IOMemoryCursor.h>
37
38 class IOATAStandardDevice;
39 class IOATAStandardCommand;
40 class IOATAStandardDriver;
41
42 class IOATAStandardController : public IOService
43 {
44 OSDeclareDefaultStructors(IOATAStandardController)
45
46 friend class IOATAStandardCommand;
47 friend class IOATAStandardDevice;
48 friend class IOATAStandardDriver;
49
50 /*------------------Methods provided by IOATAStandardController---------------------------------*/
51 public:
52 IOReturn reset();
53
54 protected:
55 void enableCommands();
56 void disableCommands();
57 void disableCommands( UInt32 disableTimeoutmS );
58
59 void rescheduleCommand( IOATAStandardCommand *forATACmd );
60
61 void resetStarted();
62 void resetOccurred();
63
64 IOATAStandardCommand *findCommandWithNexus( IOATAStandardDevice *forDevice, UInt32 tagValue = (UInt32)-1 );
65
66 void *getDeviceData( ATAUnit forUnit );
67
68 virtual IOWorkLoop *getWorkLoop() const;
69
70 UInt32 getCommandCount();
71 void setCommandLimit( IOATAStandardDevice *device, UInt32 commandLimit );
72
73 void suspendDevice( IOATAStandardDevice *forATADevice );
74 void resumeDevice( IOATAStandardDevice *forATADevice );
75 IOATAStandardDevice *selectDevice();
76
77 bool getTiming( ATAUnit unit, ATATimingProtocol *timingProtocol );
78
79
80 /*------------------Methods the controller subclass must implement-----------------------*/
81 protected:
82 /*
83 * Initialize controller hardware.
84 *
85 * Note: The controller driver's configure() method will be called prior to any other
86 * methods. If the controller driver returns successfully from this method it
87 * should be ready to accept any other method call listed.
88 */
89 virtual bool configure( IOService *provider, ATAControllerInfo *controllerInfo ) = 0;
90
91 /*
92 * Driver must indicate which ATA protocols it supports.
93 */
94 virtual bool getProtocolsSupported( ATAProtocol *protocolsSupported ) = 0;
95
96 /*
97 * Bus/target commands
98 *
99 */
100 virtual void executeCommand( IOATAStandardCommand *forATACmd ) = 0;
101 virtual void cancelCommand( IOATAStandardCommand *forATACmd ) = 0;
102 virtual void resetCommand( IOATAStandardCommand *forATACmd ) = 0;
103 virtual void abortCommand( IOATAStandardCommand *forATACmd ) = 0;
104
105 /*
106 * Methods to set timing for individual devices
107 */
108 virtual bool calculateTiming( UInt32 deviceNum, ATATiming *timing ) = 0;
109
110 /*------------------Optional methods the controller subclass may implement-----------------------*/
111 protected:
112 /*
113 * These methods notify the IOATAStandardController subclass, that a target or lun is about to be
114 * probed. The subclass should initialize its per-target or per-lun data when called at these
115 * methods. If the subclass (for some reason) wants to prevent probing of a target or lun, it
116 * can return false to the corresponding allocate*() call.
117 */
118 virtual bool allocateDevice( ATAUnit unit );
119 virtual void deallocateDevice( ATAUnit unit );
120
121 virtual void disableTimeoutOccurred();
122
123 /*
124 *
125 */
126 virtual void enableControllerInterrupts();
127 virtual void disableControllerInterrupts();
128
129 /*------------------Methods private to the IOATAStandardController class----------------------*/
130
131 public:
132 bool start( IOService *provider );
133 void free();
134
135 private:
136 void initQueues();
137 bool scanATABus();
138 void resetATABus();
139
140 bool createDeviceNubs();
141 bool probeDeviceNubs();
142 bool registerDeviceNubs();
143 bool initTimings();
144 bool matchNubWithPropertyTable( IOService *nub, OSDictionary *table );
145
146 bool resetBus();
147
148
149 bool initDevice( IOATAStandardDevice *device );
150 void releaseDevice( IOATAStandardDevice *device );
151
152 bool workLoopRequest( WorkLoopReqType type, UInt32 p1=0, UInt32 p2=0, UInt32 p3=0 );
153 void workLoopProcessRequest( WorkLoopRequest *workLoopReq, void *p1, void *p2, void *p3 );
154
155 void addDevice( IOATAStandardDevice *forDevice );
156 void deleteDevice( IOATAStandardDevice *forDevice );
157
158 void timer( IOTimerEventSource *);
159
160 void dispatchRequest();
161 void dispatch();
162
163 bool checkBusReset();
164
165 void completeCommand( IOATAStandardCommand *forATACmd );
166
167 bool createWorkLoop();
168 bool configureController();
169
170 IOATAStandardCommand *allocCommand( UInt32 clientDataSize );
171
172 private:
173
174 UInt32 sequenceNumber;
175
176 UInt32 commandCount;
177 UInt32 commandLimit;
178 UInt32 commandLimitSave;
179
180 UInt32 disableTimer;
181 bool commandDisable;
182
183 UInt32 busResetState;
184 IOATAStandardCommand *resetCmd;
185 UInt32 resetTimer;
186
187 IOATAStandardCommand *noDisconnectCmd;
188
189 ATAControllerInfo controllerInfo;
190 ATATarget *targets;
191
192 IOWorkLoop *workLoop;
193 IOTimerEventSource *timerEvent;
194 IOInterruptEventSource *dispatchEvent;
195 IOCommandGate *workLoopReqGate;
196
197 IOService *provider;
198 };
199
200 #endif