|
|
1.1 root 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: * AppleATA.cpp
25: *
26: */
27:
28: #include "AppleATA.h"
29:
30: #undef super
31: #define super IOATAController
32:
33: OSDefineMetaClass( AppleATA, IOATAController );
34: OSDefineAbstractStructors( AppleATA, IOATAController );
35:
36: #if 0
37: static UInt32 dropInt=0;
38: #endif
39:
40: /*
41: *
42: *
43: */
44: bool AppleATA::executeCommand( IOATACommand *cmd )
45: {
46:
47: cmd->getDeviceQueue()->enqueueCommand( true, (void *)0, cmd, (void *)0, (void *)0 );
48:
49: return true;
50: }
51:
52:
53: /*
54: *
55: *
56: */
57: bool AppleATA::abortCommand( IOATACommand * /* cmd */ )
58: {
59: return false;
60: }
61:
62:
63: /*
64: *
65: *
66: */
67: bool AppleATA::resetBus()
68: {
69: bool rc;
70:
71: disableControllerInterrupts();
72: rc = super::resetBus();
73: enableControllerInterrupts();
74:
75: return rc;
76: }
77:
78: /*
79: *
80: *
81: */
82: IOCommandQueueAction AppleATA::provideQueueHandler( IOATADevice * )
83: {
84: IOCommandQueueAction ret = (IOCommandQueueAction) &AppleATA::commandOccurred;
85: return ret;
86: }
87:
88:
89: /*
90: *
91: *
92: */
93: void AppleATA::commandOccurred( void */*p0*/, void *p1, void */*p2*/, void */*p3*/ )
94: {
95: /* UInt32 cmdType = (UInt32) p0; unused */
96: IOATACommand *cmd = (IOATACommand *)p1;
97: IOATADevice *newDevice;
98:
99: // IOLog("ApplePPCATA::%s() - Cmd = %08x\n\r", __FUNCTION__, (int) cmd );
100:
101: disableDeviceQueue();
102:
103: xferCmd = cmd;
104:
105: newDevice = cmd->getDevice();
106: if ( currentDevice != newDevice )
107: {
108: newDeviceSelected( newDevice );
109: currentDevice = newDevice;
110: }
111:
112: switch ( cmd->getProtocol() )
113: {
114: case ataProtocolSetRegs:
115: doProtocolSetRegs( cmd );
116: break;
117:
118: case ataProtocolPIO:
119: doATAProtocolPio( cmd );
120: break;
121:
122: case ataProtocolDMA:
123: doATAProtocolDma( cmd );
124: break;
125:
126: case atapiProtocolPIO:
127: doATAPIProtocolPio( cmd );
128: break;
129:
130: case atapiProtocolDMA:
131: doATAPIProtocolDma( cmd );
132: break;
133:
134: default:
135: doProtocolNotSupported( cmd );
136: break;
137: }
138: }
139:
140:
141:
142: void AppleATA::interruptOccurred()
143: {
144: if ( !xferCmd || !xferInts )
145: {
146: UInt32 status;
147:
148: status = readATAReg( ataRegStatus );
149: IOLog( "ApplePPCATA::%s - Spurious interrupt - ATA Status = %04lx\n\r", __FUNCTION__, status );
150: return;
151: }
152:
153: #if 0
154: if ( dropInt++ > 20 )
155: {
156: UInt32 status;
157:
158: IOLog("AppleATA::%s() - Dropping interrupt\n\r", __FUNCTION__ );
159: status = readATAReg( ataRegStatus );
160: dropInt = 0;
161: xferInts = 0;
162: return;
163: }
164: #endif
165:
166: switch ( xferCmd->getProtocol() )
167: {
168: case ataProtocolPIO:
169: processATAPioInt();
170: break;
171:
172: case ataProtocolDMA:
173: processATADmaInt();
174: break;
175:
176: case atapiProtocolPIO:
177: processATAPIPioInt();
178: break;
179:
180: case atapiProtocolDMA:
181: processATAPIDmaInt();
182: break;
183:
184:
185: default:
186: ;
187: }
188: }
189:
190:
191: /*
192: *
193: *
194: */
195: bool AppleATA::doRequestSense( IOATACommand *cmd )
196: {
197: IOATACommand *reqSenseCmd;
198: IOMemoryDescriptor *senseData;
199:
200: cmd->getATAPICmd( (ATAPICmd *)NULL, &senseData, (UInt32 *)NULL );
201:
202: if ( senseData == 0 )
203: {
204: return false;
205: }
206:
207: reqSenseCmd = makeRequestSense( cmd );
208: if ( reqSenseCmd == NULL )
209: {
210: return false;
211: }
212:
213: reqSenseCmd->setCallback( this, (ATACallback)
214: &AppleATA::didRequestSense, cmd );
215:
216: xferCmdSave = xferCmd;
217: commandOccurred( (void *)0, (void *)reqSenseCmd, (void *)0, (void *)0 );
218:
219: return true;
220: }
221:
222:
223: /*
224: *
225: *
226: */
227: void AppleATA::didRequestSense( IOService *, IOATACommand *reqSenseCmd, IOATACommand *origCmd )
228: {
229: xferCmdSave = NULL;
230: completeRequestSense( origCmd, reqSenseCmd );
231: completeCmd( origCmd );
232: }
233:
234:
235: /*
236: *
237: *
238: */
239: void AppleATA::doProtocolNotSupported( IOATACommand *cmd )
240: {
241: completeCmd( cmd, ataReturnNotSupported );
242: }
243:
244:
245: /*
246: *
247: *
248: */
249: void AppleATA::completeCmd( IOATACommand *cmd, ATAReturnCode returnCode, UInt32 bytesTransferred )
250: {
251: updateCmdStatus( cmd, returnCode, bytesTransferred );
252: completeCmd( cmd );
253: }
254:
255: /*
256: *
257: *
258: */
259: void AppleATA::updateCmdStatus( IOATACommand *cmd, ATAReturnCode returnCode, UInt32 bytesTransferred )
260: {
261: UInt32 resultmask;
262: UInt32 i;
263: ATAResults result;
264:
265: bzero( &result, sizeof(result) );
266:
267: resultmask = cmd->getResultMask();
268:
269: if ( cmd->getProtocol() != ataProtocolSetRegs )
270: {
271: if ( waitForStatus( 0, ataStatusBSY, ataBusyTimeoutmS ) == false )
272: {
273: if ( returnCode == ataReturnNoError )
274: {
275: returnCode = ataReturnErrorBusy;
276: }
277: }
278: }
279:
280: for ( i=0; resultmask; i++ )
281: {
282: if ( resultmask & 1 )
283: {
284: result.ataRegs[i] = readATAReg( i );
285: }
286: resultmask >>= 1;
287: }
288:
289: result.returnCode = returnCode;
290: result.bytesTransferred = bytesTransferred;
291: cmd->setResults( &result );
292:
293: xferCmdTimer = 0;
294: }
295:
296: /*
297: *
298: *
299: */
300: void AppleATA::completeCmd( IOATACommand *cmd )
301: {
302: xferCmd = NULL;
303: xferCmdTimer = 0;
304: cmd->complete();
305: enableDeviceQueue();
306: }
307:
308:
309: /*
310: *
311: *
312: */
313: void AppleATA::newDeviceSelected( IOATADevice * )
314: {
315: }
316:
317:
318: /*
319: *
320: *
321: */
322: bool AppleATA::programDma( IOATACommand * )
323: {
324: IOLog( "AppleATA::%s - Subclass must implement\n\r", __FUNCTION__ );
325: return false;
326: }
327:
328:
329: /*
330: *
331: *
332: */
333: bool AppleATA::startDma( IOATACommand * )
334: {
335: IOLog( "AppleATA::%s - Subclass must implement\n\r", __FUNCTION__ );
336: return false;
337: }
338:
339:
340: /*
341: *
342: *
343: */
344: bool AppleATA::stopDma( IOATACommand *, UInt32 * )
345: {
346: IOLog( "AppleATA::%s - Subclass must implement\n\r", __FUNCTION__ );
347: return false;
348: }
349:
350: /*
351: *
352: *
353: */
354: bool AppleATA::waitForStatus( UInt32 statusBitsOn, UInt32 statusBitsOff, UInt32 timeoutmS )
355: {
356: mach_timespec_t endTime, tmpTime;
357: UInt32 status;
358:
359: tmpTime.tv_sec = 0;
360: tmpTime.tv_nsec = timeoutmS * 1000 * 1000;
361:
362: IOGetTime( &endTime );
363:
364: ADD_MACH_TIMESPEC( &endTime, &tmpTime);
365:
366: do
367: {
368: status = readATAReg( ataRegStatus );
369:
370: if ( (status & statusBitsOn) == statusBitsOn
371: && (status & statusBitsOff) == 0 )
372: {
373: return true;
374: }
375:
376: IOGetTime( &tmpTime );
377:
378: } while ( CMP_MACH_TIMESPEC( &endTime, &tmpTime ) > 0 );
379:
380: return false;
381: }
382:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.