]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/storage/ata/IOATAPIHDDrive.h
02ac00b7a89067d7a8451e191b51a565e06f2eb1
[apple/xnu.git] / iokit / IOKit / storage / ata / IOATAPIHDDrive.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 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
24 *
25 * IOATAPIHDDrive.h - Generic ATAPI Direct-Access driver.
26 *
27 * HISTORY
28 * Sep 2, 1999 jliu - Ported from AppleATAPIDrive.
29 */
30
31 #ifndef _IOATAPIHDDRIVE_H
32 #define _IOATAPIHDDRIVE_H
33
34 #include <IOKit/IOTypes.h>
35 #include <IOKit/storage/ata/IOATAHDDrive.h>
36
37 // ATAPI (inquiry) device type.
38 //
39 enum IOATAPIDeviceType
40 {
41 kIOATAPIDeviceTypeDirectAccess = 0x00
42 };
43
44 // ATAPI packet commands.
45 //
46 enum {
47 kIOATAPICommandTestUnitReady = 0x00,
48 kIOATAPICommandFormatUnit = 0x04,
49 kIOATAPICommandStartStopUnit = 0x1b,
50 kIOATAPICommandPreventAllow = 0x1e,
51 kIOATAPICommandSynchronizeCache = 0x35,
52 kIOATAPICommandModeSelect = 0x55,
53 kIOATAPICommandModeSense = 0x5a,
54 kIOATAPICommandRead = 0xa8,
55 kIOATAPICommandWrite = 0xaa
56 };
57
58 // ATAPI feature register flags.
59 //
60 enum {
61 kIOATAPIFeaturesDMA = 0x01,
62 kIOATAPIFeaturesOverlay = 0x02,
63 };
64
65 #define kIOATAPIMaxTransfer 65534
66
67
68 //===========================================================================
69 // IOATAPIHDDrive
70 //===========================================================================
71
72 class IOATAPIHDDrive : public IOATAHDDrive
73 {
74 OSDeclareDefaultStructors(IOATAPIHDDrive)
75
76 protected:
77 char _vendor[9];
78 char _product[17];
79 bool _mediaPresent;
80 bool _isRemovable;
81 ATAProtocol _atapiProtocol;
82 bool _isLocked;
83
84 //-----------------------------------------------------------------------
85 // Selects a command protocol to use. The argument specifies whether
86 // the device supports DMA mode.
87
88 virtual bool selectCommandProtocol(bool isDMA);
89
90 //-----------------------------------------------------------------------
91 // Issues an ATAPI Start/Stop Unit command.
92
93 virtual IOReturn doStartStop(bool doStart);
94
95 //-----------------------------------------------------------------------
96 // Given the device type from the ATAPI Inquiry data, returns true if
97 // the device type is supported by this driver.
98
99 virtual bool matchATAPIDeviceType(UInt8 type, SInt32 * score);
100
101 //-----------------------------------------------------------------------
102 // Setup a ATATaskFile for an ATAPI packet command from the parameters
103 // given.
104
105 virtual void setupPacketTaskFile(ATATaskfile * taskfile,
106 ATAProtocol protocol,
107 UInt16 byteCount);
108
109 //-----------------------------------------------------------------------
110 // Create a generic ATAPI command object.
111
112 virtual IOATACommand * atapiCommand(ATACDBInfo * packetCommand,
113 IOMemoryDescriptor * transferBuffer = 0);
114
115 //-----------------------------------------------------------------------
116 // Allocates and return an IOATACommand to perform a read/write operation.
117
118 virtual IOATACommand * atapiCommandReadWrite(IOMemoryDescriptor * buffer,
119 UInt32 block,
120 UInt32 nblks);
121
122 //-----------------------------------------------------------------------
123 // ATAPI Start/Stop Unit command (1B).
124
125 virtual IOATACommand * atapiCommandStartStopUnit(bool doStart,
126 bool doLoadEject,
127 bool immediate);
128
129 //-----------------------------------------------------------------------
130 // ATAPI Format Unit command (04).
131
132 virtual IOATACommand * atapiCommandFormatUnit(
133 UInt16 interleave,
134 UInt8 flagBits,
135 UInt8 vendorBits,
136 IOMemoryDescriptor * formatData);
137
138 //-----------------------------------------------------------------------
139 // ATAPI Synchronize Cache command (35).
140
141 virtual IOATACommand * atapiCommandSynchronizeCache();
142
143 //-----------------------------------------------------------------------
144 // ATAPI Prevent/Allow medium removal command (1E).
145
146 virtual IOATACommand * atapiCommandPreventAllowRemoval(bool doLock);
147
148 //-----------------------------------------------------------------------
149 // ATAPI Test Unit Ready command (00).
150
151 virtual IOATACommand * atapiCommandTestUnitReady();
152
153 //----------------------------------------------------------------------
154 // ATAPI Mode Sense command (5a).
155
156 virtual IOATACommand * atapiCommandModeSense(
157 IOMemoryDescriptor * buffer,
158 UInt8 pageCode,
159 UInt8 pageControl);
160
161 //----------------------------------------------------------------------
162 // ATAPI Mode Select command (55).
163
164 virtual IOATACommand * atapiCommandModeSelect(
165 IOMemoryDescriptor * buffer);
166
167 //-----------------------------------------------------------------------
168 // Overrides the method in IOATAHDDrive and returns an IOATAPIHDDriveNub
169 // instance.
170
171 virtual IOService * instantiateNub();
172
173 //-----------------------------------------------------------------------
174 // Overrides the method in IOATAHDDrive. Inspect the ATAPI device.
175
176 virtual bool inspectDevice(IOATADevice * device);
177
178 //-----------------------------------------------------------------------
179 // Overrides the method in IOATAHDDrive. Add ATAPI wakeup handler.
180
181 virtual void handleActiveStateTransition( UInt32 stage,
182 IOReturn status );
183
184 public:
185 /*
186 * IOATAHDDrive overrides.
187 */
188 virtual bool init(OSDictionary * properties);
189 virtual IOService * probe(IOService * provider, SInt32 * score);
190
191 virtual ATADeviceType reportATADeviceType() const;
192
193 virtual IOReturn doAsyncReadWrite(IOMemoryDescriptor * buffer,
194 UInt32 block,
195 UInt32 nblks,
196 IOStorageCompletion completion);
197
198 virtual IOReturn doSyncReadWrite(IOMemoryDescriptor * buffer,
199 UInt32 block,
200 UInt32 nblks);
201
202 virtual IOReturn doEjectMedia();
203
204 virtual IOReturn doFormatMedia(UInt64 byteCapacity,
205 IOMemoryDescriptor * formatData = 0);
206
207 virtual IOReturn doLockUnlockMedia(bool doLock);
208
209 virtual IOReturn doSynchronizeCache();
210
211 virtual IOReturn doStart();
212 virtual IOReturn doStop();
213
214 virtual char * getVendorString();
215 virtual char * getProductString();
216 virtual char * getRevisionString();
217 virtual char * getAdditionalDeviceInfoString();
218
219 virtual IOReturn reportEjectability(bool * isEjectable);
220 virtual IOReturn reportLockability(bool * isLockable);
221 virtual IOReturn reportPollRequirements(bool * pollRequired,
222 bool * pollIsExpensive);
223
224 virtual IOReturn reportMediaState(bool * mediaPresent,
225 bool * changed);
226
227 virtual IOReturn reportRemovability(bool * isRemovable);
228
229 virtual IOReturn reportWriteProtection(bool * isWriteProtected);
230 };
231
232 #endif /* !_IOATAPIHDDRIVE_H */