5 //---------------------------------------------------------------------------
8 // --------------------------------------------------------------------
9 // | IRootHCDController |
10 // | IHCDController Intel USB Universal Host Controller - 3A37 |
11 // | IHCDController - Intel USB Universal HostController - 3A38 |
12 // | IHCDController - Intel USB Universal HostController - 3A38 |
13 // |------------------------------------------------------------------|
16 // IHCDController Intel USB Universal Host Controller - 3A37
20 // IUSBQueue <- interacts with -> IUSBRequest
23 // Each IHCDController creates an IUSBHardwareDevice class upon initialization. The
24 // IUSBHardwardeDevice class is used to abstract usb controller specifics. The IHubController
25 // manages all attached devices and handles hub control ioctl requests.
27 // Each IUSBHardwareDevice has one IDMAMemoryManager and one IUSBQueue. The IDMAMemoryManager
28 // is used to handle dma memory allocations. The IUSBQueue manages requests which are send to the
29 // usb hardware. See IUSBRequest class for details.
33 //=========================================================================================
35 // class IRootHCDController
37 // Description: This class serves as the root host controller. The host controller mantains
38 // a list of registered controllers and provides support functions for the host controllers
40 struct IHCDController
;
42 DECLARE_INTERFACE_(IRootHCDController
, IUnknown
)
44 DEFINE_ABSTRACT_UNKNOWN()
46 //-----------------------------------------------------------------------------------------
50 // Description: This function initializes the root host controller. It allocates the resources
51 // required to manage the registered controllers
53 virtual NTSTATUS
Initialize() = 0;
55 //-----------------------------------------------------------------------------------------
59 // Description: this function registers a host controller with the root host controller
61 virtual NTSTATUS
RegisterHCD(struct IHCDController
* Controller
) = 0;
63 //-----------------------------------------------------------------------------------------
67 // Description: this function unregistes a host controller
69 virtual NTSTATUS
UnregisterHCD(struct IHCDController
* Controller
) = 0;
71 //-----------------------------------------------------------------------------------------
75 // Description: returns the number of host controllers registered
77 virtual ULONG
GetControllerCount() = 0;
81 typedef IRootHCDController
*PROOTHDCCONTROLLER
;
83 //=========================================================================================
85 // class IHCDController
87 // Description: This class is used to manage a single USB host controller
90 DECLARE_INTERFACE_(IHCDController
, IUnknown
)
92 DEFINE_ABSTRACT_UNKNOWN()
94 //-----------------------------------------------------------------------------------------
98 // Description: This function initializes the IHCDController implementation.
99 // It creates an IUSBHardwareDevice object and initializes it. It also registeres itself with
100 // the IRootHCDController
102 virtual NTSTATUS
Initialize(IN PROOTHDCCONTROLLER RootHCDController
,
103 IN PDRIVER_OBJECT DriverObject
,
104 IN PDEVICE_OBJECT PhysicalDeviceObject
) = 0;
108 typedef IHCDController
*PHCDCONTROLLER
;
110 struct _OHCI_ENDPOINT_DESCRIPTOR
;
111 //=========================================================================================
113 // class IUSBHardwareDevice
115 // Description: This class provides access to the usb hardware controller
118 struct IDMAMemoryManager
;
121 DECLARE_INTERFACE_(IUSBHardwareDevice
, IUnknown
)
123 DEFINE_ABSTRACT_UNKNOWN()
125 //-----------------------------------------------------------------------------------------
129 // Description: Initializes the usb device controller
131 virtual NTSTATUS
Initialize(PDRIVER_OBJECT DriverObject
,
132 PDEVICE_OBJECT FunctionalDeviceObject
,
133 PDEVICE_OBJECT PhysicalDeviceObject
,
134 PDEVICE_OBJECT LowerDeviceObject
) = 0;
136 //-----------------------------------------------------------------------------------------
140 // Description: handles pnp start request from device. It registeres the interrupt,
141 // sets up the ports and prepares the device. It then starts the controller
143 virtual NTSTATUS
PnpStart(PCM_RESOURCE_LIST RawResources
,
144 PCM_RESOURCE_LIST TranslatedResources
) = 0;
146 //-----------------------------------------------------------------------------------------
150 // Description: handles pnp stop request from device. It unregisteres the interrupt, releases ports and dma object.
152 virtual NTSTATUS
PnpStop(void) = 0;
154 //-----------------------------------------------------------------------------------------
158 // Description: returns the device details such as vendor id, device id, number of ports and speed
160 virtual NTSTATUS
GetDeviceDetails(OUT OPTIONAL PUSHORT VendorId
,
161 OUT OPTIONAL PUSHORT DeviceId
,
162 OUT OPTIONAL PULONG NumberOfPorts
,
163 OUT OPTIONAL PULONG Speed
) = 0;
165 //-----------------------------------------------------------------------------------------
169 // Description: returns interface to internal IUSBQueue
170 // Interface is reference counted, you need to call release method when you are done with it
171 // Do not call Initialize on IUSBQueue, the object is already initialized
173 virtual NTSTATUS
GetUSBQueue(OUT
struct IUSBQueue
**OutUsbQueue
) = 0;
175 //-----------------------------------------------------------------------------------------
177 // GetBulkHeadEndpointDescriptor
179 // Description: returns the bulk head endpoint descriptor
181 virtual NTSTATUS
GetBulkHeadEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
183 //-----------------------------------------------------------------------------------------
185 // GetControlHeadEndpointDescriptor
187 // Description: returns the control head endpoint descriptor
189 virtual NTSTATUS
GetControlHeadEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
191 //-----------------------------------------------------------------------------------------
193 // HeadEndpointDescriptorModified
195 // Description: notifies the hardware that an endpoint descriptor was added to head endpoint descriptor
197 virtual VOID
HeadEndpointDescriptorModified(ULONG HeadType
) = 0;
202 //-----------------------------------------------------------------------------------------
206 // Description: returns the DMA object which can be used to allocate memory from the common buffer
208 virtual NTSTATUS
GetDMA(OUT
struct IDMAMemoryManager
**OutDMAMemoryManager
) = 0;
211 //-----------------------------------------------------------------------------------------
215 // Description: this function resets the controller
216 // Returns STATUS_SUCCESS when the controller was successfully reset
218 virtual NTSTATUS
ResetController() = 0;
220 //-----------------------------------------------------------------------------------------
224 // Description: this functions starts controller allowing interrupts for device connects/removal, and execution of
225 // Periodic and Asynchronous Schedules.
228 virtual NTSTATUS
StartController() = 0;
230 //-----------------------------------------------------------------------------------------
234 // Description: this functions stops controller disabling interrupts for device connects/removal, and execution of
235 // Periodic and Asynchronous Schedules.
238 virtual NTSTATUS
StopController() = 0;
240 //-----------------------------------------------------------------------------------------
244 // Description: this functions resets the port on the controller
247 virtual NTSTATUS
ResetPort(ULONG PortNumber
) = 0;
249 //-----------------------------------------------------------------------------------------
253 // Description: this functions return status and change state of port
255 virtual NTSTATUS
GetPortStatus(ULONG PortId
, OUT USHORT
*PortStatus
, OUT USHORT
*PortChange
) = 0;
257 //-----------------------------------------------------------------------------------------
261 // Description: Clears Status of Port, for example Connection, Enable and Reset
263 virtual NTSTATUS
ClearPortStatus(ULONG PortId
, ULONG Status
) = 0;
265 //-----------------------------------------------------------------------------------------
269 // Description: this functions Sets Feature on Port, for example Enable, Power and Reset
271 virtual NTSTATUS
SetPortFeature(ULONG PortId
, ULONG Feature
) = 0;
273 //-----------------------------------------------------------------------------------------
275 // SetStatusChangeEndpointCallBack
277 // Description: Used to callback to the hub controller when SCE detected
279 virtual VOID
SetStatusChangeEndpointCallBack(PVOID CallBack
,PVOID Context
) = 0;
281 //-----------------------------------------------------------------------------------------
285 // Description: acquires the device lock
287 virtual KIRQL
AcquireDeviceLock(void) = 0;
289 //-----------------------------------------------------------------------------------------
293 // Description: releases the device lock
295 virtual void ReleaseDeviceLock(KIRQL OldLevel
) = 0;
298 typedef IUSBHardwareDevice
*PUSBHARDWAREDEVICE
;
301 //=========================================================================================
303 // class IDMAMemoryManager
305 // Description: This class provides access to the dma buffer. It provides methods to
306 // allocate and free from the dma buffer
309 DECLARE_INTERFACE_(IDMAMemoryManager
, IUnknown
)
311 DEFINE_ABSTRACT_UNKNOWN()
313 //-----------------------------------------------------------------------------------------
317 // Description: initializes the memory manager
319 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Device
,
321 IN ULONG DmaBufferSize
,
322 IN PVOID VirtualBase
,
323 IN PHYSICAL_ADDRESS PhysicalAddress
,
324 IN ULONG DefaultBlockSize
) = 0;
326 //-----------------------------------------------------------------------------------------
330 // Description: allocates block of memory from allocator
332 virtual NTSTATUS
Allocate(IN ULONG Size
,
333 OUT PVOID
*OutVirtualBase
,
334 OUT PPHYSICAL_ADDRESS OutPhysicalAddress
) = 0;
337 //-----------------------------------------------------------------------------------------
341 // Description: releases memory block
343 virtual NTSTATUS
Release(IN PVOID VirtualBase
,
348 typedef IDMAMemoryManager
*PDMAMEMORYMANAGER
;
351 //=========================================================================================
355 // Description: This class is used to issue request to usb controller. The class is
356 // initialized using InitializeXXX methods. You also need to call SetEndpoint to define the endpoint
357 // In addition you can call SetCompletionDetails if you need to wait for the end of
358 // the request or want to complete an irp. You call AddUSBRequest to add the request to the queue.
359 // Once the request is completed the CompletionCallback is invoked. The CompletionCallback
360 // will take care of any completion details which have been set. If the request is cancelled, the
361 // CancelCallback routine is invoked.
364 DECLARE_INTERFACE_(IUSBRequest
, IUnknown
)
366 DEFINE_ABSTRACT_UNKNOWN()
368 //-----------------------------------------------------------------------------------------
370 // InitializeWithSetupPacket
372 // Description: initializes the request packet with an setup packet
373 // If there is a TransferBuffer, the TransferBufferLength contains the length of the buffer
376 virtual NTSTATUS
InitializeWithSetupPacket(IN PDMAMEMORYMANAGER DmaManager
,
377 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
378 IN UCHAR DeviceAddress
,
379 IN OPTIONAL PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
,
380 IN OUT ULONG TransferBufferLength
,
381 IN OUT PMDL TransferBuffer
) = 0;
383 //-----------------------------------------------------------------------------------------
387 // Description: initializes the request with an IRP
388 // The irp contains an URB block which contains all necessary information
390 virtual NTSTATUS
InitializeWithIrp(IN PDMAMEMORYMANAGER DmaManager
,
391 IN OUT PIRP Irp
) = 0;
393 //-----------------------------------------------------------------------------------------
397 // Description: returns true when the request has been completed
398 // Should be called after the CompletionCallback has been invoked
399 // This function is called by IUSBQueue after queue head has been completed
400 // If the function returns true, IUSBQueue will then call ShouldReleaseRequestAfterCompletion
401 // If that function returns also true, it calls Release() to delete the IUSBRequest
403 virtual BOOLEAN
IsRequestComplete() = 0;
405 //-----------------------------------------------------------------------------------------
409 // Description: returns the type of the request: control, bulk, iso, interrupt
411 virtual ULONG
GetTransferType() = 0;
413 //-----------------------------------------------------------------------------------------
415 // GetEndpointDescriptor
417 // Description: returns the general transfer descriptor
419 virtual NTSTATUS
GetEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
421 //-----------------------------------------------------------------------------------------
425 // Description: returns the status code of the result
426 // Note: this function will block the caller untill the request has been completed
428 virtual VOID
GetResultStatus(OUT OPTIONAL NTSTATUS
* NtStatusCode
,
429 OUT OPTIONAL PULONG UrbStatusCode
) = 0;
431 //-----------------------------------------------------------------------------------------
433 // IsRequestInitialized
435 // Description: returns true when the request has been successfully initialized using InitializeXXX methods
437 virtual BOOLEAN
IsRequestInitialized() = 0;
439 //-----------------------------------------------------------------------------------------
441 // CompletionCallback
443 // Description: notifies request that the endpoint descriptor is complete
445 virtual VOID
CompletionCallback(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
447 //-----------------------------------------------------------------------------------------
449 // FreeEndpointDescriptor
451 // Description: frees the associated endpoint descriptor and its general descriptors
453 virtual VOID
FreeEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
457 typedef IUSBRequest
*PUSBREQUEST
;
459 //=========================================================================================
463 // Description: This class manages pending requests
466 DECLARE_INTERFACE_(IUSBQueue
, IUnknown
)
468 DEFINE_ABSTRACT_UNKNOWN()
470 //-----------------------------------------------------------------------------------------
474 // Description: initializes the object
476 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Hardware
,
477 IN PDMA_ADAPTER AdapterObject
,
478 IN PDMAMEMORYMANAGER MemManager
,
479 IN OPTIONAL PKSPIN_LOCK Lock
) = 0;
481 //-----------------------------------------------------------------------------------------
483 // GetPendingRequestCount
485 // Description: returns the number of pending requests true from IsRequestComplete
487 virtual ULONG
GetPendingRequestCount() = 0;
489 //-----------------------------------------------------------------------------------------
493 // Description: adds an usb request to the queue.
494 // Returns status success when successful
496 virtual NTSTATUS
AddUSBRequest(IUSBRequest
* Request
) = 0;
498 //-----------------------------------------------------------------------------------------
502 // Description: cancels all requests
504 virtual NTSTATUS
CancelRequests() = 0;
506 //-----------------------------------------------------------------------------------------
510 // Description: creates an usb request
512 virtual NTSTATUS
CreateUSBRequest(IUSBRequest
**OutRequest
) = 0;
514 //-----------------------------------------------------------------------------------------
516 // TransferDescriptorCompletionCallback
518 // Description: notifies the queue that a transfer was completed
520 virtual VOID
TransferDescriptorCompletionCallback(ULONG TransferDescriptorLogicalAddress
) = 0;
524 typedef IUSBQueue
*PUSBQUEUE
;
526 //=========================================================================================
528 // class IHubController
530 // Description: This class implements a hub controller
533 DECLARE_INTERFACE_(IHubController
, IUnknown
)
535 DEFINE_ABSTRACT_UNKNOWN()
537 //----------------------------------------------------------------------------------------
541 // Description: Initializes the hub controller
543 virtual NTSTATUS
Initialize(IN PDRIVER_OBJECT DriverObject
,
544 IN PHCDCONTROLLER Controller
,
545 IN PUSBHARDWAREDEVICE Device
,
546 IN BOOLEAN IsRootHubDevice
,
547 IN ULONG DeviceAddress
) = 0;
549 //----------------------------------------------------------------------------------------
551 // GetHubControllerDeviceObject
553 // Description: Returns the hub controller device object
555 virtual NTSTATUS
GetHubControllerDeviceObject(PDEVICE_OBJECT
* HubDeviceObject
) = 0;
557 //----------------------------------------------------------------------------------------
559 // GetHubControllerSymbolicLink
561 // Description: Returns the symbolic link of the root hub
563 virtual NTSTATUS
GetHubControllerSymbolicLink(ULONG BufferLength
, PVOID Buffer
, PULONG RequiredLength
) = 0;
568 typedef IHubController
*PHUBCONTROLLER
;
570 //=========================================================================================
572 // class IDispatchIrp
574 // Description: This class is used to handle irp dispatch requests
577 DECLARE_INTERFACE_(IDispatchIrp
, IUnknown
)
579 DEFINE_ABSTRACT_UNKNOWN()
581 //-----------------------------------------------------------------------------------------
585 // Description: This function handles all pnp requests
587 virtual NTSTATUS
HandlePnp(IN PDEVICE_OBJECT DeviceObject
,
588 IN OUT PIRP Irp
) = 0;
590 //-----------------------------------------------------------------------------------------
594 // Description: This function handles all power pnp requests
596 virtual NTSTATUS
HandlePower(IN PDEVICE_OBJECT DeviceObject
,
597 IN OUT PIRP Irp
) = 0;
599 //-----------------------------------------------------------------------------------------
601 // HandleDeviceControl
603 // Description: handles device io control requests
605 virtual NTSTATUS
HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
606 IN OUT PIRP Irp
) = 0;
609 typedef IDispatchIrp
*PDISPATCHIRP
;
611 //=========================================================================================
615 // Description: This class is used to abstract details of a usb device
618 DECLARE_INTERFACE_(IUSBDevice
, IUnknown
)
620 DEFINE_ABSTRACT_UNKNOWN()
622 //----------------------------------------------------------------------------------------
626 // Description: Initializes the usb device
628 virtual NTSTATUS
Initialize(IN PHUBCONTROLLER HubController
,
629 IN PUSBHARDWAREDEVICE Device
,
632 IN ULONG PortStatus
) = 0;
634 //-----------------------------------------------------------------------------------------
638 // Description: returns true when device is a hub
640 virtual BOOLEAN
IsHub() = 0;
642 //-----------------------------------------------------------------------------------------
646 // Description: gets the parent device of the this device
648 virtual NTSTATUS
GetParent(PVOID
* Parent
) = 0;
650 //-----------------------------------------------------------------------------------------
654 // Description: gets the device address of the this device
656 virtual UCHAR
GetDeviceAddress() = 0;
659 //-----------------------------------------------------------------------------------------
663 // Description: gets the port to which this device is connected
665 virtual ULONG
GetPort() = 0;
667 //-----------------------------------------------------------------------------------------
671 // Description: gets the speed of the device
673 virtual USB_DEVICE_SPEED
GetSpeed() = 0;
675 //-----------------------------------------------------------------------------------------
679 // Description: gets the type of the device, either 1.1 or 2.0 device
681 virtual USB_DEVICE_TYPE
GetType() = 0;
683 //-----------------------------------------------------------------------------------------
687 // Description: gets the device state
689 virtual ULONG
GetState() = 0;
691 //-----------------------------------------------------------------------------------------
693 // SetDeviceHandleData
695 // Description: sets device handle data
697 virtual void SetDeviceHandleData(PVOID Data
) = 0;
699 //-----------------------------------------------------------------------------------------
703 // Description: sets device handle data
705 virtual NTSTATUS
SetDeviceAddress(UCHAR DeviceAddress
) = 0;
707 //-----------------------------------------------------------------------------------------
709 // GetDeviceDescriptor
711 // Description: sets device handle data
713 virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
) = 0;
715 //-----------------------------------------------------------------------------------------
717 // GetConfigurationValue
719 // Description: gets current selected configuration index
721 virtual UCHAR
GetConfigurationValue() = 0;
723 //-----------------------------------------------------------------------------------------
727 // Description: submits an irp containing an urb
729 virtual NTSTATUS
SubmitIrp(PIRP Irp
) = 0;
731 //-----------------------------------------------------------------------------------------
733 // GetConfigurationDescriptors
735 // Description: returns one or more configuration descriptors
737 virtual VOID
GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer
,
738 IN ULONG BufferLength
,
739 OUT PULONG OutBufferLength
) = 0;
741 //-----------------------------------------------------------------------------------------
743 // Description: returns length of configuration descriptors
745 virtual ULONG
GetConfigurationDescriptorsLength() = 0;
747 //-----------------------------------------------------------------------------------------
751 // Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
753 virtual NTSTATUS
SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
754 IN OUT ULONG BufferLength
,
755 OUT PVOID Buffer
) = 0;
757 //-----------------------------------------------------------------------------------------
759 // SelectConfiguration
761 // Description: selects a configuration
763 virtual NTSTATUS
SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
,
764 IN PUSBD_INTERFACE_INFORMATION Interface
,
765 OUT USBD_CONFIGURATION_HANDLE
*ConfigurationHandle
) = 0;
767 //-----------------------------------------------------------------------------------------
769 // SelectConfiguration
771 // Description: selects a interface of an configuration
773 virtual NTSTATUS
SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle
,
774 IN OUT PUSBD_INTERFACE_INFORMATION Interface
) = 0;
777 typedef IUSBDevice
*PUSBDEVICE
;