|
|
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: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
24: *
25: * IOATAHDDrive.h
26: *
27: * HISTORY
28: * Aug 27, 1999 jliu - Ported from AppleATADrive.
29: */
30:
31: #ifndef _IOATAHDDRIVE_H
32: #define _IOATAHDDRIVE_H
33:
34: #include <IOKit/IOTypes.h>
35: #include <IOKit/ata/IOATA.h>
36: #include <IOKit/IOInterruptEventSource.h>
37: #include <IOKit/IOWorkLoop.h>
38: #include <IOKit/IOLocks.h>
39: #include <IOKit/storage/IOHDTypes.h>
40:
41: class IOSyncer;
42:
43: // ATA parameters.
44: //
45: #define kIOATASectorSize 512
46: #define kIOATAMaxBlocksPerXfer 256
47:
48: // ATA commands.
49: //
50: enum {
51: kIOATACommandReadPIO = 0x20,
52: kIOATACommandWritePIO = 0x30,
53: kIOATACommandReadDMA = 0xc8,
54: kIOATACommandWriteDMA = 0xca,
55: kIOATACommandSetFeatures = 0xef,
56: };
57:
58: // ==========================================================================
59: // IOATAClientData - This structure is stored on the IOATACommand's
60: // driver private area.
61: // ==========================================================================
62:
63: struct IOATAClientData {
64: IOATACommand * command; // back pointer to command object.
65: IOMemoryDescriptor * buffer; // memory descriptor.
66: union {
67: struct {
68: IOService * target; // completion target.
69: gdCompletionFunction action; // completion action.
70: void * param; // completion param.
71: } async;
72: IOSyncer * syncLock; // lock for synchronous operation.
73: } completion;
74: bool isSync; // synchronous command.
75: SInt32 maxRetries; // max retry attempts (0 is no retry).
76: ATAReturnCode returnCode; // operation return code.
77: queue_chain_t link; // queue linkage.
78: };
79:
80: // Get driver private data (IOATAClientData) from an IOATACommand object.
81: //
82: #define ATA_CLIENT_DATA(x) ((IOATAClientData *)(x->getClientData()))
83:
84: // ==========================================================================
85: // IOATACommandQueue
86: // ==========================================================================
87:
88: class IOATACommandQueue : public OSObject
89: {
90: OSDeclareDefaultStructors(IOATACommandQueue)
91:
92: protected:
93: queue_head_t _queue;
94: IORecursiveLock * _cmdLock;
95: IOSimpleLock * _qLock;
96: bool _enabled;
97:
98: virtual void free();
99:
100: public:
101: static IOATACommandQueue * commmandQueue();
102: virtual bool init();
103:
104: void executeCommands();
105: bool enqueueCommand(IOATACommand * cmd);
106: void setEnabled(bool enable);
107: };
108:
109: // ==========================================================================
110: // IOATAHDDrive
111: // ==========================================================================
112:
113: class IOATAHDDrive : public IOService
114: {
115: OSDeclareDefaultStructors(IOATAHDDrive)
116:
117: protected:
118: IOATADevice * _ataDevice;
119: IOWorkLoop * _workloop;
120: IOInterruptEventSource * _evSource;
121: UInt _unit;
122:
123: ATATimingProtocol _timingProtocol;
124: ATAProtocol _ataProtocol;
125: UInt8 _ataReadCmd;
126: UInt8 _ataWriteCmd;
127:
128: IOATACommandQueue * _retryQueue;
129:
130: char _revision[9];
131: char _model[41];
132:
133: //-----------------------------------------------------------------------
134: // Default timeout interval for async and sync commands.
135:
136: static const UInt ATADefaultTimeout = 30000; // 30 seconds
137:
138: //-----------------------------------------------------------------------
139: // Default retry count for async and sync commands.
140:
141: static const UInt ATADefaultRetries = 4;
142:
143: //-----------------------------------------------------------------------
144: // Release all allocated resource before calling super::free().
145:
146: virtual void free();
147:
148: //-----------------------------------------------------------------------
149: // Set the ATA device timings.
150:
151: virtual bool selectTimingProtocol(ATATimingProtocol protocol =
152: ataMaxTimings);
153:
154: //-----------------------------------------------------------------------
155: // Selects the Command protocol to use (e.g. ataProtocolPIO,
156: // ataProtocolDMA).
157:
158: virtual void selectCommandProtocol(bool useDMA);
159:
160: //-----------------------------------------------------------------------
161: // Setup an ATATaskFile from the parameters given, and write the taskfile
162: // to the ATATaskfile structure pointer provided.
163:
164: virtual void setupReadWriteTaskFile(ATATaskfile * taskfile,
165: ATAProtocol protocol,
166: UInt8 command,
167: UInt32 block,
168: UInt32 nblks);
169:
170: //-----------------------------------------------------------------------
171: // Allocate and return an IOATACommand that is initialized to perform
172: // a read/write operation.
173:
174: virtual IOATACommand * ataCommandReadWrite(IOMemoryDescriptor * buffer,
175: UInt32 block,
176: UInt32 nblks);
177:
178: //-----------------------------------------------------------------------
179: // Allocate and return a ATA Set Features command.
180:
181: virtual IOATACommand * ataCommandSetFeatures(UInt8 features,
182: UInt8 SectorCount,
183: UInt8 SectorNumber,
184: UInt8 CylinderLow,
185: UInt8 CyclinderHigh);
186:
187: //-----------------------------------------------------------------------
188: // This method is responsible for calling the client's completion routine
189: // for an async command.
190:
191: virtual void completionCallback(IOService * target,
192: gdCompletionFunction action,
193: void * param,
194: UInt32 bytes,
195: IOReturn status);
196:
197: //-----------------------------------------------------------------------
198: // This routine is called by our provider when a command processing has
199: // completed.
200:
201: virtual void completionHandler(IOService * device,
202: IOATACommand * cmd,
203: void * refcon);
204:
205: //-----------------------------------------------------------------------
206: // Issue a synchronous ATA command.
207:
208: virtual ATAReturnCode syncExecute(
209: IOATACommand * cmd,
210: UInt32 timeout = ATADefaultTimeout,
211: UInt retries = ATADefaultRetries);
212:
213: //-----------------------------------------------------------------------
214: // Issue an asynchronous ATA command.
215:
216: virtual ATAReturnCode asyncExecute(
217: IOATACommand * cmd,
218: IOService * target,
219: gdCompletionFunction action,
220: void * param,
221: UInt32 timeout = ATADefaultTimeout,
222: UInt retries = ATADefaultRetries);
223:
224: //-----------------------------------------------------------------------
225: // Add a command to the retry/sync queue.
226:
227: virtual bool enqueueCommand(IOATACommand * cmd);
228:
229: //-----------------------------------------------------------------------
230: // Dequeues commands from the queue and executes them.
231:
232: virtual void dequeueCommands(IOInterruptEventSource * source,
233: int count);
234:
235: //-----------------------------------------------------------------------
236: // Allocate an IOATACommand object.
237:
238: virtual IOATACommand * allocateCommand();
239:
240: //-----------------------------------------------------------------------
241: // Inspect the ATA device.
242:
243: virtual void inspectDevice(IOService * provider);
244:
245: //-----------------------------------------------------------------------
246: // Returns an IOATAHDDriveNub instance.
247:
248: virtual IOService * instantiateNub();
249:
250: //-----------------------------------------------------------------------
251: // Calls instantiateNub() then initialize, attach, and register the
252: // drive nub.
253:
254: virtual bool createNub(IOService * provider);
255:
256: public:
257: /*
258: * Overrides from IOService.
259: */
260: virtual bool init(OSDictionary * properties);
261: virtual IOService * probe(IOService * provider, SInt32 * score);
262: virtual bool start(IOService * provider);
263:
264: //-----------------------------------------------------------------------
265: // Report the type of ATA device (ATA vs. ATAPI).
266:
267: virtual ATADeviceType reportATADeviceType() const;
268:
269: //-----------------------------------------------------------------------
270: // Handles read/write requests.
271:
272: virtual IOReturn doAsyncReadWrite(IOMemoryDescriptor * buffer,
273: UInt32 block,
274: UInt32 nblks,
275: gdCompletionFunction action,
276: IOService * target,
277: void * param);
278:
279: //-----------------------------------------------------------------------
280: // Eject the media in the drive.
281:
282: virtual IOReturn doEjectMedia();
283:
284: //-----------------------------------------------------------------------
285: // Format the media in the drive.
286:
287: virtual IOReturn doFormatMedia(UInt64 byteCapacity);
288:
289: //-----------------------------------------------------------------------
290: // Returns disk capacity in bytes.
291:
292: virtual UInt32 doGetFormatCapacities(UInt64 * capacities,
293: UInt32 capacitiesMaxCount) const;
294:
295: //-----------------------------------------------------------------------
296: // Lock the media and prevent a user-initiated eject.
297:
298: virtual IOReturn doLockUnlockMedia(bool doLock);
299:
300: //-----------------------------------------------------------------------
301: // Flush the write-cache to the physical media.
302:
303: virtual IOReturn doSynchronizeCache();
304:
305: //-----------------------------------------------------------------------
306: // Start/stop the drive.
307:
308: virtual IOReturn doStart();
309: virtual IOReturn doStop();
310:
311: //-----------------------------------------------------------------------
312: // Return device identification strings
313:
314: virtual char * getAdditionalDeviceInfoString();
315: virtual char * getProductString();
316: virtual char * getRevisionString();
317: virtual char * getVendorString();
318:
319: //-----------------------------------------------------------------------
320: // Report the device block size in bytes.
321:
322: virtual IOReturn reportBlockSize(UInt64 * blockSize);
323:
324: //-----------------------------------------------------------------------
325: // Report whether the media in the ATA device is ejectable.
326:
327: virtual IOReturn reportEjectability(bool * isEjectable);
328:
329: //-----------------------------------------------------------------------
330: // Report whether the media can be locked.
331:
332: virtual IOReturn reportLockability(bool * isLockable);
333:
334: //-----------------------------------------------------------------------
335: // Report the polling requirements for a removable media.
336:
337: virtual IOReturn reportPollRequirements(bool * pollRequired,
338: bool * pollIsExpensive);
339:
340: //-----------------------------------------------------------------------
341: // Report the max number of bytes transferred for an ATA read command.
342:
343: virtual IOReturn reportMaxReadTransfer(UInt64 blocksize,
344: UInt64 * max);
345:
346: //-----------------------------------------------------------------------
347: // Report the max number of bytes transferred for an ATA write command.
348:
349: virtual IOReturn reportMaxWriteTransfer(UInt64 blocksize,
350: UInt64 * max);
351:
352: //-----------------------------------------------------------------------
353: // Returns the maximum addressable sector number.
354:
355: virtual IOReturn reportMaxValidBlock(UInt64 * maxBlock);
356:
357: //-----------------------------------------------------------------------
358: // Report whether the media is currently present, and whether a media
359: // change has been registered since the last reporting.
360:
361: virtual IOReturn reportMediaState(bool * mediaPresent,
362: bool * changed);
363:
364: //-----------------------------------------------------------------------
365: // Report whether the media is removable.
366:
367: virtual IOReturn reportRemovability(bool * isRemovable);
368:
369: //-----------------------------------------------------------------------
370: // Report if the media is write-protected.
371:
372: virtual IOReturn reportWriteProtection(bool * isWriteProtected);
373:
374: //-----------------------------------------------------------------------
375: // Handles messages (notifications) from our provider.
376:
377: virtual IOReturn message(UInt32 type, IOService * provider,
378: void * argument);
379:
380: //-----------------------------------------------------------------------
381: // Perform translation from ATAReturnCode to IOReturn codes.
382:
383: virtual IOReturn getIOReturn(ATAResults * result);
384: virtual IOReturn getIOReturn(ATAReturnCode code);
385:
386: //-----------------------------------------------------------------------
387: // Returns the device type.
388:
389: virtual const char * getDeviceTypeName();
390: };
391:
392: #endif /* !_IOATAHDDRIVE_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.