Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/i386/include/IOKit/usb/IOUSBMassStorageClass.h

Source at commit 1146 created 12 years 11 months ago.
By azimutz, Sync with trunk (r1145). Add nVidia dev id's, 0DF4 for "GeForce GT 450M" (issue 99) and 1251 for "GeForce GTX 560M" (thanks to oSxFr33k for testing).
1/*
2 * Copyright (c) 1998-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25#ifndef _IOKIT_IOUSBMASSSTORAGECLASS_H
26#define _IOKIT_IOUSBMASSSTORAGECLASS_H
27
28// Headers for general IOKit definitions
29#include <IOKit/IOLib.h>
30#include <IOKit/IOService.h>
31#include <IOKit/IOMemoryDescriptor.h>
32#include <IOKit/IOMessage.h>
33
34// Headers for USB specific definitions
35#include <IOKit/usb/IOUSBInterface.h>
36#include <IOKit/usb/IOUSBPipe.h>
37#include <IOKit/usb/USBSpec.h>
38#include <IOKit/usb/USB.h>
39
40// Headers for SCSI Protocol support definitions
41#include <IOKit/scsi/IOSCSIProtocolServices.h>
42
43// BSD includes
44#include <sys/sysctl.h>
45
46#define UNUSED(x) ((void)x)
47
48
49#pragma mark -
50#pragma mark Vendor Specific Device Support
51#define kIOUSBMassStorageCharacteristics"USB Mass Storage Characteristics"
52#define kIOUSBMassStoragePreferredSubclass"Preferred Subclass"
53#define kIOUSBMassStoragePreferredProtocol"Preferred Protocol"
54#define kIOUSBMassStorageResetOnResume"Reset On Resume"
55#define kIOUSBMassStorageUseStandardUSBReset"Use Standard USB Reset"
56#define kIOUSBKnownCSWTagIssues"Known CSW Tag Issues"
57#define kIOUSBMassStorageMaxLogicalUnitNumber"Max Logical Unit Number"
58#define kIOPropertyIOUnitKey"IOUnit"
59#define kIOUSBMassStorageDoNotMatch"Do Not Match MSC"
60#define kIOUSBMassStorageDoNotOperate"Do Not Operate"
61#define kIOUSBMassStorageEnableSuspendResumePM"Enable Port Suspend-Resume PM"
62
63enum
64{
65kUSBDAddressLength = 10
66};
67
68#pragma mark -
69#pragma mark CBI Protocol Strutures
70// Structure for the global PB's
71struct CBIRequestBlock
72{
73SCSITaskIdentifierrequest;
74IOUSBDevRequestcbiDevRequest;
75SCSICommandDescriptorBlockcbiCDB;
76IOUSBCompletioncbiCompletion;
77UInt32currentState;
78IOMemoryDescriptor *cbiPhaseDesc;
79UInt8cbiGetStatusBuffer[2];// 2 bytes as specified in the USB spec
80};
81
82typedef struct CBIRequestBlockCBIRequestBlock;
83
84#pragma mark -
85#pragma mark Bulk Only Protocol Structures
86
87struct StorageBulkOnlyCBW
88{
89UInt32cbwSignature;
90UInt32cbwTag;
91UInt32cbwTransferLength;
92UInt8cbwFlags;
93UInt8cbwLUN;// Bits 0-3: LUN, 4-7: Reserved
94UInt8cbwCDBLength;// Bits 0-4: CDB Length, 5-7: Reserved
95UInt8cbwCDB[16];
96};
97
98typedef struct StorageBulkOnlyCBWStorageBulkOnlyCBW;
99
100structStorageBulkOnlyCSW
101{
102UInt32cswSignature;
103UInt32cswTag;
104UInt32cswDataResidue;
105UInt8cswStatus;
106};
107
108typedef struct StorageBulkOnlyCSWStorageBulkOnlyCSW;
109
110structBulkOnlyRequestBlock
111{
112SCSITaskIdentifierrequest;
113IOUSBCompletionboCompletion;
114UInt32currentState;
115StorageBulkOnlyCBWboCBW;
116StorageBulkOnlyCSWboCSW;
117IOMemoryDescriptor *boPhaseDesc;
118UInt8boGetStatusBuffer[2];// 2 bytes as specified in the USB spec
119};
120
121typedef struct BulkOnlyRequestBlockBulkOnlyRequestBlock;
122
123
124#pragma mark -
125#pragma mark IOUSBMassStorageClass definition
126
127class IOUSBMassStorageClass : public IOSCSIProtocolServices
128{
129 OSDeclareDefaultStructors(IOUSBMassStorageClass)
130
131private:
132// ---- Member variables used by all protocols ----
133// The interface object that provides the driver with access to the
134// USB so that it may talk to its device.
135 IOUSBInterface *fInterface;
136
137// The pipe objects that the driver uses to transport data through a
138// pipe to the appropriate endpoint.
139 IOUSBPipe *fBulkInPipe;
140 IOUSBPipe *fBulkOutPipe;
141 IOUSBPipe *fInterruptPipe;
142IOUSBDevRequestfUSBDeviceRequest;
143UInt8fPreferredSubclass;
144UInt8fPreferredProtocol;
145
146 // The maximum Logical Unit Number. This is the highest valid LUN
147 // that the USB device supports, so if the device only supports one
148 // LUN, such as CBI and CB, this number will be zero.
149 UInt8fMaxLogicalUnitNumber;
150
151// ---- Member variables used by CBI protocol ----
152boolfCBICommandStructInUse;
153
154CBIRequestBlockfCBICommandRequestBlock;
155
156// ---- Member variables used by Bulk Only protocol ----
157 // Command tag, this driver just uses a sequential counter that is
158 // incremented for each CBW that is sent to the device.
159 UInt32 fBulkOnlyCommandTag;
160
161boolfBulkOnlyCommandStructInUse;
162
163 // Dedicated CBW and CSW IOMemoryDescriptors are listed in the ExpansionData struct.
164
165 // The Request block that contains all the necessary data for
166 // transporting a Bulk Only request across the USB.
167 BulkOnlyRequestBlockfBulkOnlyCommandRequestBlock;
168
169protected:
170 // Reserve space for future expansion.
171 struct ExpansionData
172{
173boolfResetInProgress;
174OSSet *fClients;
175IOUSBPipe *fPotentiallyStalledPipe;
176boolfUseUSBResetNotBOReset;
177boolfAbortCurrentSCSITaskInProgress;
178IOMemoryDescriptor *fCBIMemoryDescriptor;
179IOMemoryDescriptor *fBulkOnlyCBWMemoryDescriptor;
180IOMemoryDescriptor *fBulkOnlyCSWMemoryDescriptor;
181 bool fDeviceAttached;
182bool fWaitingForReconfigurationMessage;
183boolfTerminating;
184 bool fKnownCSWTagMismatchIssues;
185 bool fPortSuspendResumeForPMEnabled;
186 bool fPortIsSuspended;
187boolfRequiresResetOnResume;
188boolfAutonomousSpinDownWorkAround;
189UInt8fConsecutiveResetCount;
190boolfClearStallInProgress;/* OBSOLETE */
191boolfTerminationDeferred;
192};
193 ExpansionData *reserved;
194
195#define fResetInProgressreserved->fResetInProgress
196#define fClientsreserved->fClients
197#define fPotentiallyStalledPipereserved->fPotentiallyStalledPipe
198 #define fUseUSBResetNotBOResetreserved->fUseUSBResetNotBOReset
199#define fAbortCurrentSCSITaskInProgressreserved->fAbortCurrentSCSITaskInProgress
200#define fCBIMemoryDescriptor reserved->fCBIMemoryDescriptor
201#definefBulkOnlyCBWMemoryDescriptorreserved->fBulkOnlyCBWMemoryDescriptor
202#definefBulkOnlyCSWMemoryDescriptorreserved->fBulkOnlyCSWMemoryDescriptor
203 #define fDeviceAttached reserved->fDeviceAttached
204#define fWaitingForReconfigurationMessagereserved->fWaitingForReconfigurationMessage
205#define fTerminatingreserved->fTerminating
206 #define fKnownCSWTagMismatchIssues reserved->fKnownCSWTagMismatchIssues
207 #define fPortSuspendResumeForPMEnabled reserved->fPortSuspendResumeForPMEnabled
208 #define fPortIsSuspended reserved->fPortIsSuspended
209#define fRequiresResetOnResumereserved->fRequiresResetOnResume
210#define fAutonomousSpinDownWorkAroundreserved->fAutonomousSpinDownWorkAround
211#define fConsecutiveResetCountreserved->fConsecutiveResetCount
212#define fClearStallInProgressreserved->fClearStallInProgress
213#define fTerminationDeferredreserved->fTerminationDeferred
214
215// Enumerated constants used to control various aspects of this
216// driver.
217
218// Enumerations for Mass Storage Class Subclass types
219enum
220{
221kUSBStorageRBCSubclass = 1,
222kUSBStorageSFF8020iSubclass = 2,
223kUSBStorageQIC157Subclass= 3,
224kUSBStorageUFISubclass= 4,
225kUSBStorageSFF8070iSubclass= 5,
226kUSBStorageSCSITransparentSubclass= 6
227};
228
229// The supported USB Mass Storage Class transport protocols.
230enum
231{
232kProtocolControlBulkInterrupt= 0x00,
233kProtocolControlBulk= 0x01,
234kProtocolBulkOnly= 0x50
235};
236
237// ------- Protocol support functions ------------
238// The SendSCSICommand function will take a SCSITask Object and transport
239// it across the physical wire(s) to the device
240virtual bool SendSCSICommand(
241SCSITaskIdentifier request,
242SCSIServiceResponse *serviceResponse,
243SCSITaskStatus*taskStatus );
244
245// The AbortSCSICommand function will abort the indicated SCSITask object,
246// if it is possible and the SCSITask has not already completed.
247 virtual SCSIServiceResponse AbortSCSICommand( SCSITaskIdentifier abortTask );
248
249virtual boolIsProtocolServiceSupported(
250SCSIProtocolFeature feature,
251void * serviceValue );
252
253virtual boolHandleProtocolServiceFeature(
254SCSIProtocolFeature feature,
255void * serviceValue );
256
257// Methods for retrieving and setting the object for the Interface
258IOUSBInterface *GetInterfaceReference( void );
259voidSetInterfaceReference( IOUSBInterface * newInterface );
260
261UInt8GetInterfaceSubclass( void );
262UInt8GetInterfaceProtocol( void );
263
264// Methods for retrieving an object for a Pipe.
265IOUSBPipe *GetControlPipe( void );
266IOUSBPipe *GetBulkInPipe( void );
267IOUSBPipe *GetBulkOutPipe( void );
268IOUSBPipe *GetInterruptPipe( void );
269
270// Methods for getting and setting the maximum LUN of a device.
271UInt8GetMaxLogicalUnitNumber( void ) const;
272voidSetMaxLogicalUnitNumber( UInt8 maxLUN );
273
274virtual void CompleteSCSICommand(
275SCSITaskIdentifier request,
276IOReturn status );
277
278virtualboolBeginProvidedServices( void );
279virtualboolEndProvidedServices( void );
280
281// The Protocol specific helper methods for SendSCSICommand
282virtual IOReturnSendSCSICommandForCBIProtocol(
283 SCSITaskIdentifier request );
284
285virtual IOReturnSendSCSICommandForBulkOnlyProtocol(
286SCSITaskIdentifier request );
287
288// The Protocol specific helper methods for AbortSCSICommand
289virtual IOReturnAbortSCSICommandForCBIProtocol(
290SCSITaskIdentifier abortTask );
291
292virtual IOReturnAbortSCSICommandForBulkOnlyProtocol(
293SCSITaskIdentifier abortTask );
294
295// Helper methods for performing general USB device requests
296virtual IOReturnClearFeatureEndpointStall(
297IOUSBPipe *thePipe,
298IOUSBCompletion*completion );
299virtual IOReturn GetStatusEndpointStatus(
300IOUSBPipe *thePipe,
301void *endpointStatus,
302IOUSBCompletion*completion );
303
304 /* All CBI transport related methods.
305 */
306// All definitions and structures for the CBI Protocol
307enum
308{
309 kUSBStorageAutoStatusSize= 2// Per the USB CBI Protocol
310 };
311
312 // Methods for accessing Bulk Only specific member variables.
313CBIRequestBlock *GetCBIRequestBlock( void );
314
315void ReleaseCBIRequestBlock(
316CBIRequestBlock *cbiRequestBlock );
317
318// Methods used for CBI/CB command transportation.
319static voidCBIProtocolUSBCompletionAction(
320void *target,
321 void *parameter,
322 IOReturnstatus,
323 UInt32bufferSizeRemaining);
324
325IOReturnCBIProtocolTransferData(
326CBIRequestBlock *cbiRequestBlock,
327UInt32nextExecutionState );
328
329IOReturnCBIProtocolReadInterrupt(
330CBIRequestBlock *cbiRequestBlock,
331UInt32nextExecutionState );
332
333IOReturnCBIGetStatusEndpointStatus(
334IOUSBPipe *targetPipe,
335CBIRequestBlock *cbiRequestBlock,
336UInt32nextExecutionState );
337
338IOReturnCBIClearFeatureEndpointStall(
339IOUSBPipe *targetPipe,
340CBIRequestBlock *cbiRequestBlock,
341UInt32nextExecutionState );
342
343void CBIProtocolCommandCompletion(
344CBIRequestBlock *cbiRequestBlock,
345 IOReturnresultingStatus,
346 UInt32bufferSizeRemaining );
347
348 /* All Bulk Only transport related methods, structures and enums.
349 */
350 // All Bulk Only specific structures and enums.
351
352// All definitions and structures for the Bulk Only Protocol
353// Command Block Wrapper (CBW)
354enum
355{
356// CBW general struture definitions
357kCommandBlockWrapperSignature= OSSwapHostToBigConstInt32 ( 'USBC' ),
358kByteCountOfCBW= 31,
359
360// CBW LUN related definitions
361kCBWLUNMask= 0x0F,
362
363kCBWFlagsDataOut= 0x00,
364kCBWFlagsDataIn= 0x80
365};
366
367// All definitions and structures for the Bulk Only Protocol
368// Command Status Wrapper (CSW)
369enum
370{
371// CSW general struture definitions
372kCommandStatusWrapperSignature= OSSwapHostToBigConstInt32 ( 'USBS' ),
373kByteCountOfCSW= 13,
374
375// CSW status definitions
376kCSWCommandPassedError = 0x00,// No error occurred
377kCSWCommandFailedError= 0x01,/* An error occurred (probably a
378 * bad command or parameter ) */
379kCSWPhaseError= 0x02/* A transfer was performed in
380 * the wrong sequence */
381};
382
383 // Methods for accessing Bulk Only specific member variables.
384BulkOnlyRequestBlock *GetBulkOnlyRequestBlock( void );
385
386void ReleaseBulkOnlyRequestBlock(
387BulkOnlyRequestBlock * boRequestBlock );
388
389UInt32GetNextBulkOnlyCommandTag( void );
390
391// Methods for Bulk Only specific utility commands
392IOReturnBulkDeviceResetDevice(
393BulkOnlyRequestBlock *boRequestBlock,
394UInt32nextExecutionState );
395
396// Methods used for Bulk Only command transportation.
397IOReturnBulkOnlySendCBWPacket(
398BulkOnlyRequestBlock *boRequestBlock,
399UInt32nextExecutionState );
400
401IOReturnBulkOnlyTransferData(
402BulkOnlyRequestBlock *boRequestBlock,
403UInt32nextExecutionState );
404
405IOReturnBulkOnlyReceiveCSWPacket(
406BulkOnlyRequestBlock *boRequestBlock,
407UInt32nextExecutionState );
408
409voidBulkOnlyExecuteCommandCompletion (
410BulkOnlyRequestBlock *boRequestBlock,
411 IOReturnresultingStatus,
412 UInt32bufferSizeRemaining );
413
414static voidBulkOnlyUSBCompletionAction (
415 void *target,
416 void *parameter,
417 IOReturnstatus,
418 UInt32bufferSizeRemaining );
419
420public:
421
422 boolinit( OSDictionary * propTable );
423 virtual boolstart( IOService * provider );
424 virtual void stop( IOService * provider );
425virtual voidfree( void );
426virtualIOReturnmessage( UInt32 type, IOService * provider, void * argument = 0 );
427
428virtual bool willTerminate( IOService * provider,
429 IOOptionBits options );
430
431virtual bool didTerminate(IOService * provider,
432 IOOptionBits options,
433bool *defer );
434
435virtual boolhandleOpen( IOService *client,
436IOOptionBitsoptions,
437void *arg );
438
439virtual voidhandleClose( IOService *client,
440 IOOptionBitsoptions );
441
442virtual boolhandleIsOpen( const IOService * client ) const;
443
444virtual IOReturnHandlePowerOn( void );
445
446protected:
447
448static IOReturnsWaitForReset( void * refcon );
449IOReturnGatedWaitForReset( void );
450
451static IOReturnsWaitForTaskAbort( void * refcon );/* OBSOLETE */
452IOReturnGatedWaitForTaskAbort( void );/* OBSOLETE */
453
454static voidsResetDevice( void * refcon );
455
456static voidsAbortCurrentSCSITask( void * refcon );/* OBSOLETE */
457
458 OSMetaClassDeclareReservedUsed( IOUSBMassStorageClass, 1 );
459virtual IOReturnStartDeviceRecovery( void );/* OBSOLETE */
460
461 OSMetaClassDeclareReservedUsed( IOUSBMassStorageClass, 2 );
462virtual voidFinishDeviceRecovery( IOReturnstatus );/* OBSOLETE */
463
464static voidDeviceRecoveryCompletionAction(
465 void *target,
466 void *parameter,
467 IOReturnstatus,
468 UInt32bufferSizeRemaining );/* OBSOLETE */
469
470 void ResetDeviceNow( bool waitForReset );
471
472void AbortCurrentSCSITask( void );
473
474bool IsPhysicalInterconnectLocationInternal ( void );
475
476IOReturn SuspendPort ( bool suspend );
477
478private:
479
480voidClearPipeStall ( void );
481
482IOReturnAcceptSCSITask ( SCSITaskIdentifier scsiTask, bool * pAccepted );
483
484voidCheckDeferredTermination ( void );
485
486voidGatedCompleteSCSICommand ( SCSITaskIdentifier request, SCSIServiceResponse * serviceResponse, SCSITaskStatus * taskStatus );
487
488// Space reserved for future expansion.
489 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 3 );
490 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 4 );
491 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 5 );
492 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 6 );
493 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 7 );
494 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 8 );
495 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 9 );
496 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 10 );
497 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 11 );
498 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 12 );
499 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 13 );
500 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 14 );
501 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 15 );
502 OSMetaClassDeclareReservedUnused( IOUSBMassStorageClass, 16 );
503
504};
505
506
507#endif _IOKIT_IOUSBMASSSTORAGECLASS_H
508

Archive Download this file

Revision: 1146