forked from apple-oss-distributions/IOUSBMassStorageClass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOUSBMassStorageUFISubclass.h
355 lines (290 loc) · 12 KB
/
IOUSBMassStorageUFISubclass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
* Copyright (c) 1998-2015 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _IOKIT_IOUSBMASSSTORAGEUFISUBCLASS_H
#define _IOKIT_IOUSBMASSSTORAGEUFISUBCLASS_H
// This class' header file
#include <IOKit/usb/IOUSBMassStorageClass.h>
#include <IOKit/scsi/IOSCSIPrimaryCommandsDevice.h>
#pragma mark -
#pragma mark IOUSBMassStorageUFIDevice declaration
class IOUSBMassStorageUFIDevice : public IOSCSIPrimaryCommandsDevice
{
OSDeclareDefaultStructors(IOUSBMassStorageUFIDevice)
private:
static void AsyncReadWriteComplete( SCSITaskIdentifier completedTask );
protected:
// Reserve space for future expansion.
struct IOUSBMassStorageUFIDeviceExpansionData
{
};
IOUSBMassStorageUFIDeviceExpansionData *fIOUSBMassStorageUFIDeviceReserved;
// ---- Medium Characteristics ----
bool fMediumPresent;
// The byte count of each physical block on the medium.
UInt32 fMediumBlockSize;
// The total number of blocks of fMediumBlockSize on the medium.
UInt32 fMediumBlockCount;
// Whether the installed medium is protected from writes
bool fMediumIsWriteProtected;
// Polling thread variables
thread_call_t fPollingThread;
UInt32 fPollingMode;
enum
{
kPollingMode_Suspended = 0,
kPollingMode_NewMedia = 1,
kPollingMode_MediaRemoval = 2
};
// ---- Methods for controlling the current state of device support ----
virtual bool InitializeDeviceSupport( void ) APPLE_KEXT_OVERRIDE;
virtual void StartDeviceSupport ( void ) APPLE_KEXT_OVERRIDE;
virtual void SuspendDeviceSupport( void ) APPLE_KEXT_OVERRIDE;
virtual void ResumeDeviceSupport( void ) APPLE_KEXT_OVERRIDE;
virtual void StopDeviceSupport ( void ) APPLE_KEXT_OVERRIDE;
virtual void TerminateDeviceSupport( void ) APPLE_KEXT_OVERRIDE;
// ---- Methods used for misc ----
virtual bool ClearNotReadyStatus( void ) APPLE_KEXT_OVERRIDE;
virtual void CreateStorageServiceNub( void );
virtual bool DetermineDeviceCharacteristics( void );
// ---- Methods used for controlling the polling thread ----
virtual void ProcessPoll( void );
virtual void EnablePolling( void );
virtual void DisablePolling( void );
// ---- Main and support methods for polling for new Media ----
virtual void PollForNewMedia( void );
virtual bool DetermineMediaPresence( void );
virtual bool DetermineMediumCapacity(
UInt64 * blockSize,
UInt64 * blockCount );
virtual bool DetermineMediumWriteProtectState( void );
// ---- Main and support methods for polling for Media removal ----
virtual void PollForMediaRemoval( void );
// ---- Methods used for power managment ----
virtual UInt32 GetInitialPowerState ( void ) APPLE_KEXT_OVERRIDE;
virtual void InitializePowerManagement ( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual void HandlePowerChange ( void ) APPLE_KEXT_OVERRIDE;
virtual void HandleCheckPowerState ( void ) APPLE_KEXT_OVERRIDE;
virtual void TicklePowerManager ( void ) APPLE_KEXT_OVERRIDE;
virtual UInt32 GetNumberOfPowerStateTransitions ( void ) APPLE_KEXT_OVERRIDE;
// ---- Methods used for handling medium characteristics ----
virtual void SetMediumCharacteristics(
UInt32 blockSize,
UInt32 blockCount );
virtual void ResetMediumCharacteristics( void );
virtual IOReturn IssueRead(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount );
virtual IOReturn IssueRead(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount,
void * clientData );
virtual IOReturn IssueWrite(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount );
virtual IOReturn IssueWrite(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount,
void * clientData );
public:
static void sProcessPoll( void * pdtDriver, void * refCon );
// Interface to the UFI Storage Services Driver
// ---- Methods for controlling the device ----
virtual IOReturn SyncReadWrite(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount,
UInt64 blockSize );
virtual IOReturn AsyncReadWrite(
IOMemoryDescriptor * buffer,
UInt64 startBlock,
UInt64 blockCount,
UInt64 blockSize,
void * clientData );
// ---- Methods for controlling medium state ----
virtual IOReturn EjectTheMedium( void );
// ---- Methods for controlling media format ----
virtual IOReturn FormatMedium(
UInt64 blockCount,
UInt64 blockSize );
virtual UInt32 GetFormatCapacities(
UInt64 * capacities,
UInt32 capacitiesMaxCount ) const;
// ---- Query methods to report device characteristics ----
// Report the maximum number of blocks that the device can handle per
// read or write. A value of 0 (zero) indicates there is no limit aside
// from the size of the method's return parameter.
virtual UInt64 ReportDeviceMaxBlocksReadTransfer( void );
virtual UInt64 ReportDeviceMaxBlocksWriteTransfer( void );
// ---- Query methods to report installed medium characteristics ----
virtual UInt64 ReportMediumBlockSize( void );
virtual UInt64 ReportMediumTotalBlockCount( void );
virtual bool ReportMediumWriteProtection( void );
// Methods for getting device information strings
virtual char * GetVendorString( void ) APPLE_KEXT_OVERRIDE;
virtual char * GetProductString( void ) APPLE_KEXT_OVERRIDE;
virtual char * GetRevisionString( void ) APPLE_KEXT_OVERRIDE;
OSDictionary * GetProtocolCharacteristicsDictionary ( void );
OSDictionary * GetDeviceCharacteristicsDictionary ( void );
protected:
// Utility methods used by all SCSI Command Set objects
// isParameterValid methods are used to validate that the parameter passed into
// the command methods are of the correct value.
// Validate Parameter used for 1 bit to 1 byte paramaters
bool IsParameterValid(
SCSICmdField1Byte param,
SCSICmdField1Byte mask );
// Validate Parameter used for 9 bit to 2 byte paramaters
bool IsParameterValid(
SCSICmdField2Byte param,
SCSICmdField2Byte mask );
// Validate Parameter used for 17 bit to 4 byte paramaters
bool IsParameterValid(
SCSICmdField4Byte param,
SCSICmdField4Byte mask );
// UFI Required Commands
virtual bool FORMAT_UNIT(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
IOByteCount defectListSize,
SCSICmdField1Byte TRACK_NUMBER,
SCSICmdField2Byte INTERLEAVE );
virtual bool INQUIRY(
SCSITaskIdentifier request,
IOMemoryDescriptor *dataBuffer,
SCSICmdField1Byte PAGE_OR_OPERATION_CODE,
SCSICmdField1Byte ALLOCATION_LENGTH );
virtual bool MODE_SELECT_10(
SCSITaskIdentifier request,
IOMemoryDescriptor *dataBuffer,
SCSICmdField1Bit PF,
SCSICmdField1Bit SP,
SCSICmdField2Byte PARAMETER_LIST_LENGTH );
virtual bool MODE_SENSE_10(
SCSITaskIdentifier request,
IOMemoryDescriptor *dataBuffer,
SCSICmdField1Bit DBD,
SCSICmdField2Bit PC,
SCSICmdField6Bit PAGE_CODE,
SCSICmdField2Byte PARAMETER_LIST_LENGTH );
virtual bool PREVENT_ALLOW_MEDIUM_REMOVAL(
SCSITaskIdentifier request,
SCSICmdField1Bit PREVENT );
virtual bool READ_10(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
UInt32 blockSize,
SCSICmdField1Bit DPO,
SCSICmdField1Bit FUA,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField2Byte TRANSFER_LENGTH );
virtual bool READ_12(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
UInt32 blockSize,
SCSICmdField1Bit DPO,
SCSICmdField1Bit FUA,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField4Byte TRANSFER_LENGTH );
virtual bool READ_CAPACITY(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField1Bit PMI );
virtual bool READ_FORMAT_CAPACITIES(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
SCSICmdField2Byte ALLOCATION_LENGTH );
virtual bool REQUEST_SENSE(
SCSITaskIdentifier request,
IOMemoryDescriptor *dataBuffer,
SCSICmdField1Byte ALLOCATION_LENGTH );
virtual bool REZERO_UNIT(
SCSITaskIdentifier request );
virtual bool SEEK(
SCSITaskIdentifier request,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS );
virtual bool SEND_DIAGNOSTICS(
SCSITaskIdentifier request,
SCSICmdField1Bit PF,
SCSICmdField1Bit SELF_TEST,
SCSICmdField1Bit DEF_OFL,
SCSICmdField1Bit UNIT_OFL );
virtual bool START_STOP_UNIT(
SCSITaskIdentifier request,
SCSICmdField1Bit IMMED,
SCSICmdField1Bit LOEJ,
SCSICmdField1Bit START );
virtual bool TEST_UNIT_READY(
SCSITaskIdentifier request );
virtual bool VERIFY(
SCSITaskIdentifier request,
SCSICmdField1Bit DPO,
SCSICmdField1Bit BYTCHK,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField2Byte VERIFICATION_LENGTH );
virtual bool WRITE_10(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
UInt32 blockSize,
SCSICmdField1Bit DPO,
SCSICmdField1Bit FUA,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField2Byte TRANSFER_LENGTH );
virtual bool WRITE_12(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
UInt32 blockSize,
SCSICmdField1Bit DPO,
SCSICmdField1Bit EBP,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField4Byte TRANSFER_LENGTH );
virtual bool WRITE_AND_VERIFY(
SCSITaskIdentifier request,
IOMemoryDescriptor * dataBuffer,
UInt32 blockSize,
SCSICmdField1Bit DPO,
SCSICmdField1Bit BYTCHK,
SCSICmdField1Bit RELADR,
SCSICmdField4Byte LOGICAL_BLOCK_ADDRESS,
SCSICmdField2Byte TRANSFER_LENGTH );
};
#pragma mark -
#pragma mark IOUSBMassStorageUFISubclass declaration
class IOUSBMassStorageUFISubclass : public IOUSBMassStorageClass
{
OSDeclareDefaultStructors(IOUSBMassStorageUFISubclass)
protected:
virtual bool BeginProvidedServices( void ) APPLE_KEXT_OVERRIDE;
virtual bool EndProvidedServices( void ) APPLE_KEXT_OVERRIDE;
};
#endif //_IOKIT_IOUSBMASSSTORAGEUFISUBCLASS_H