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
;
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 //-----------------------------------------------------------------------------------------
179 // Description: returns the DMA object which can be used to allocate memory from the common buffer
181 virtual NTSTATUS
GetDMA(OUT
struct IDMAMemoryManager
**OutDMAMemoryManager
) = 0;
184 //-----------------------------------------------------------------------------------------
188 // Description: this function resets the controller
189 // Returns STATUS_SUCCESS when the controller was successfully reset
191 virtual NTSTATUS
ResetController() = 0;
193 //-----------------------------------------------------------------------------------------
197 // Description: this functions starts controller allowing interrupts for device connects/removal, and execution of
198 // Periodic and Asynchronous Schedules.
201 virtual NTSTATUS
StartController() = 0;
203 //-----------------------------------------------------------------------------------------
207 // Description: this functions stops controller disabling interrupts for device connects/removal, and execution of
208 // Periodic and Asynchronous Schedules.
211 virtual NTSTATUS
StopController() = 0;
213 //-----------------------------------------------------------------------------------------
217 // Description: this functions resets the port on the controller
220 virtual NTSTATUS
ResetPort(ULONG PortNumber
) = 0;
222 //-----------------------------------------------------------------------------------------
226 // Description: this functions return status and change state of port
228 virtual NTSTATUS
GetPortStatus(ULONG PortId
, OUT USHORT
*PortStatus
, OUT USHORT
*PortChange
) = 0;
230 //-----------------------------------------------------------------------------------------
234 // Description: Clears Status of Port, for example Connection, Enable and Reset
236 virtual NTSTATUS
ClearPortStatus(ULONG PortId
, ULONG Status
) = 0;
238 //-----------------------------------------------------------------------------------------
242 // Description: this functions Sets Feature on Port, for example Enable, Power and Reset
244 virtual NTSTATUS
SetPortFeature(ULONG PortId
, ULONG Feature
) = 0;
246 //-----------------------------------------------------------------------------------------
248 // SetAsyncListRegister
250 // Description: this functions sets the register to a address that is the physical address of a QueueHead.
251 // This is the location at which the controller will start executing the Asynchronous Schedule.
253 // FIXME: This is only available for USB 2.0
254 virtual VOID
SetAsyncListRegister(ULONG PhysicalAddress
) = 0;
256 //-----------------------------------------------------------------------------------------
258 // SetPeriodicListRegister
260 // Description: this functions sets the register to a address that is the physical address of a ???.
261 // This is the location at which the controller will start executing the Periodic Schedule.
263 virtual VOID
SetPeriodicListRegister(ULONG PhysicalAddress
) = 0;
265 //-----------------------------------------------------------------------------------------
267 // GetAsyncListRegister
269 // Description: Returns the memory address used in the Asynchronous Register
271 virtual struct _QUEUE_HEAD
* GetAsyncListQueueHead() = 0;
273 //-----------------------------------------------------------------------------------------
275 // GetPeriodicListRegister
277 // Description: Returns the the memory address used in the Periodic Register
279 virtual ULONG
GetPeriodicListRegister() = 0;
281 //-----------------------------------------------------------------------------------------
283 // SetStatusChangeEndpointCallBack
285 // Description: Used to callback to the hub controller when SCE detected
287 virtual VOID
SetStatusChangeEndpointCallBack(PVOID CallBack
,PVOID Context
) = 0;
289 //-----------------------------------------------------------------------------------------
293 // Description: acquires the device lock
295 virtual KIRQL
AcquireDeviceLock(void) = 0;
297 //-----------------------------------------------------------------------------------------
301 // Description: releases the device lock
303 virtual void ReleaseDeviceLock(KIRQL OldLevel
) = 0;
306 virtual void SetCommandRegister(struct _EHCI_USBCMD_CONTENT
*UsbCmd
) = 0;
309 virtual void GetCommandRegister(struct _EHCI_USBCMD_CONTENT
*UsbCmd
) = 0;
315 typedef IUSBHardwareDevice
*PUSBHARDWAREDEVICE
;
318 //=========================================================================================
320 // class IDMAMemoryManager
322 // Description: This class provides access to the dma buffer. It provides methods to
323 // allocate and free from the dma buffer
326 DECLARE_INTERFACE_(IDMAMemoryManager
, IUnknown
)
328 DEFINE_ABSTRACT_UNKNOWN()
330 //-----------------------------------------------------------------------------------------
334 // Description: initializes the memory manager
336 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Device
,
338 IN ULONG DmaBufferSize
,
339 IN PVOID VirtualBase
,
340 IN PHYSICAL_ADDRESS PhysicalAddress
,
341 IN ULONG DefaultBlockSize
) = 0;
343 //-----------------------------------------------------------------------------------------
347 // Description: allocates block of memory from allocator
349 virtual NTSTATUS
Allocate(IN ULONG Size
,
350 OUT PVOID
*OutVirtualBase
,
351 OUT PPHYSICAL_ADDRESS OutPhysicalAddress
) = 0;
354 //-----------------------------------------------------------------------------------------
358 // Description: releases memory block
360 virtual NTSTATUS
Release(IN PVOID VirtualBase
,
365 typedef IDMAMemoryManager
*PDMAMEMORYMANAGER
;
368 //=========================================================================================
372 // Description: This class is used to issue request to usb controller. The class is
373 // initialized using InitializeXXX methods. You also need to call SetEndpoint to define the endpoint
374 // In addition you can call SetCompletionDetails if you need to wait for the end of
375 // the request or want to complete an irp. You call AddUSBRequest to add the request to the queue.
376 // Once the request is completed the CompletionCallback is invoked. The CompletionCallback
377 // will take care of any completion details which have been set. If the request is cancelled, the
378 // CancelCallback routine is invoked.
382 struct _USB_ENDPOINT
;
384 DECLARE_INTERFACE_(IUSBRequest
, IUnknown
)
386 DEFINE_ABSTRACT_UNKNOWN()
388 //-----------------------------------------------------------------------------------------
390 // InitializeWithSetupPacket
392 // Description: initializes the request packet with an setup packet
393 // If there is a TransferBuffer, the TransferBufferLength contains the length of the buffer
396 virtual NTSTATUS
InitializeWithSetupPacket(IN PDMAMEMORYMANAGER DmaManager
,
397 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
398 IN UCHAR DeviceAddress
,
399 IN OPTIONAL
struct _USB_ENDPOINT
*EndpointDescriptor
,
400 IN OUT ULONG TransferBufferLength
,
401 IN OUT PMDL TransferBuffer
) = 0;
403 //-----------------------------------------------------------------------------------------
407 // Description: initializes the request with an IRP
408 // The irp contains an URB block which contains all necessary information
410 virtual NTSTATUS
InitializeWithIrp(IN PDMAMEMORYMANAGER DmaManager
,
411 IN OUT PIRP Irp
) = 0;
413 //-----------------------------------------------------------------------------------------
415 // CompletionCallback
417 // Description: called when request has been completed. It is called when
418 // IUSBQueue completes a queue head
420 virtual VOID
CompletionCallback(IN NTSTATUS NtStatusCode
,
421 IN ULONG UrbStatusCode
,
422 IN
struct _QUEUE_HEAD
*QueueHead
) = 0;
424 //-----------------------------------------------------------------------------------------
428 // Description: called when the queue head is cancelled
430 virtual VOID
CancelCallback(IN NTSTATUS NtStatusCode
,
431 IN
struct _QUEUE_HEAD
*QueueHead
) = 0;
433 //-----------------------------------------------------------------------------------------
437 // Description: returns an initialized queue head which contains all transfer descriptors
439 virtual NTSTATUS
GetQueueHead(struct _QUEUE_HEAD
** OutHead
) = 0;
441 //-----------------------------------------------------------------------------------------
445 // Description: returns true when the request has been completed
446 // Should be called after the CompletionCallback has been invoked
447 // This function is called by IUSBQueue after queue head has been completed
448 // If the function returns true, IUSBQueue will then call ShouldReleaseRequestAfterCompletion
449 // If that function returns also true, it calls Release() to delete the IUSBRequest
451 virtual BOOLEAN
IsRequestComplete() = 0;
453 //-----------------------------------------------------------------------------------------
457 // Description: returns the type of the request: control, bulk, iso, interrupt
459 virtual ULONG
GetTransferType() = 0;
461 //-----------------------------------------------------------------------------------------
465 // Description: returns the status code of the result
466 // Note: this function will block the caller untill the request has been completed
468 virtual VOID
GetResultStatus(OUT OPTIONAL NTSTATUS
* NtStatusCode
,
469 OUT OPTIONAL PULONG UrbStatusCode
) = 0;
471 //-----------------------------------------------------------------------------------------
473 // IsRequestInitialized
475 // Description: returns true when the request has been successfully initialized using InitializeXXX methods
477 virtual BOOLEAN
IsRequestInitialized() = 0;
479 //-----------------------------------------------------------------------------------------
481 // ShouldReleaseRequestAfterCompletion
483 // Description: this function gets called when the request returns
484 // IUSBQueue will then call Release() on the object to release all associated memory
485 // This function will typically return true when the request has been initialized with an irp
486 // If the request was initialized with an setup packet, it will return false
488 virtual BOOLEAN
ShouldReleaseRequestAfterCompletion() = 0;
490 //----------------------------------------------------------------------------------------
494 // Description: frees the queue head with the associated transfer descriptors
496 virtual VOID
FreeQueueHead(struct _QUEUE_HEAD
* QueueHead
) = 0;
498 //---------------------------------------------------------------------------------------
502 // Description: this function returns the transfer buffer mdl and length
503 // Used by IUSBQueue for mapping buffer contents with DMA
505 virtual VOID
GetTransferBuffer(OUT PMDL
* OutMDL
,
506 OUT PULONG TransferLength
) = 0;
508 //--------------------------------------------------------------------------------------
510 // IsQueueHeadComplete
512 // Description: returns true when the queue head which was passed as a parameter has been completed
514 virtual BOOLEAN
IsQueueHeadComplete(struct _QUEUE_HEAD
* QueueHead
) = 0;
518 typedef IUSBRequest
*PUSBREQUEST
;
520 //=========================================================================================
524 // Description: This class manages pending requests
527 DECLARE_INTERFACE_(IUSBQueue
, IUnknown
)
529 DEFINE_ABSTRACT_UNKNOWN()
531 //-----------------------------------------------------------------------------------------
535 // Description: initializes the object
537 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Hardware
,
538 IN PDMA_ADAPTER AdapterObject
,
539 IN PDMAMEMORYMANAGER MemManager
,
540 IN OPTIONAL PKSPIN_LOCK Lock
) = 0;
542 //-----------------------------------------------------------------------------------------
544 // GetPendingRequestCount
546 // Description: returns the number of pending requests true from IsRequestComplete
548 virtual ULONG
GetPendingRequestCount() = 0;
550 //-----------------------------------------------------------------------------------------
554 // Description: adds an usb request to the queue.
555 // Returns status success when successful
557 virtual NTSTATUS
AddUSBRequest(IUSBRequest
* Request
) = 0;
558 virtual NTSTATUS
AddUSBRequest(PURB Urb
) = 0;
559 //-----------------------------------------------------------------------------------------
563 // Description: cancels all requests
565 virtual NTSTATUS
CancelRequests() = 0;
567 //-----------------------------------------------------------------------------------------
571 // Description: creates an usb request
573 virtual NTSTATUS
CreateUSBRequest(IUSBRequest
**OutRequest
) = 0;
575 //--------------------------------------------------------------------------------------
579 // Description: callback when the periodic / asynchronous queue has been completed / queue head been completed
581 virtual VOID
InterruptCallback(IN NTSTATUS Status
, OUT PULONG ShouldRingDoorBell
) = 0;
583 //--------------------------------------------------------------------------------------
585 // CompleteAsyncRequests
587 // Description: once a request has been completed it is moved to pending queue. Since a queue head should only be freed
588 // after a door bell ring, this needs some synchronization.
589 // This function gets called by IUSBHardware after it the Interrupt on Async Advance bit has been set
591 virtual VOID
CompleteAsyncRequests() = 0;
593 //-----------------------------------------------------------------------------------------
597 // Description: aborts all pending requsts of an device
599 virtual NTSTATUS
AbortDevicePipe(UCHAR DeviceAddress
, IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
) = 0;
603 typedef IUSBQueue
*PUSBQUEUE
;
605 //=========================================================================================
607 // class IHubController
609 // Description: This class implements a hub controller
612 DECLARE_INTERFACE_(IHubController
, IUnknown
)
614 DEFINE_ABSTRACT_UNKNOWN()
616 //----------------------------------------------------------------------------------------
620 // Description: Initializes the hub controller
622 virtual NTSTATUS
Initialize(IN PDRIVER_OBJECT DriverObject
,
623 IN PHCDCONTROLLER Controller
,
624 IN PUSBHARDWAREDEVICE Device
,
625 IN BOOLEAN IsRootHubDevice
,
626 IN ULONG DeviceAddress
) = 0;
628 //----------------------------------------------------------------------------------------
630 // GetHubControllerDeviceObject
632 // Description: Returns the hub controller device object
634 virtual NTSTATUS
GetHubControllerDeviceObject(PDEVICE_OBJECT
* HubDeviceObject
) = 0;
636 //----------------------------------------------------------------------------------------
638 // GetHubControllerSymbolicLink
640 // Description: Returns the symbolic link of the root hub
642 virtual NTSTATUS
GetHubControllerSymbolicLink(ULONG BufferLength
, PVOID Buffer
, PULONG RequiredLength
) = 0;
647 typedef IHubController
*PHUBCONTROLLER
;
649 //=========================================================================================
651 // class IDispatchIrp
653 // Description: This class is used to handle irp dispatch requests
656 DECLARE_INTERFACE_(IDispatchIrp
, IUnknown
)
658 DEFINE_ABSTRACT_UNKNOWN()
660 //-----------------------------------------------------------------------------------------
664 // Description: This function handles all pnp requests
666 virtual NTSTATUS
HandlePnp(IN PDEVICE_OBJECT DeviceObject
,
667 IN OUT PIRP Irp
) = 0;
669 //-----------------------------------------------------------------------------------------
673 // Description: This function handles all power pnp requests
675 virtual NTSTATUS
HandlePower(IN PDEVICE_OBJECT DeviceObject
,
676 IN OUT PIRP Irp
) = 0;
678 //-----------------------------------------------------------------------------------------
680 // HandleDeviceControl
682 // Description: handles device io control requests
684 virtual NTSTATUS
HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
685 IN OUT PIRP Irp
) = 0;
688 typedef IDispatchIrp
*PDISPATCHIRP
;
690 //=========================================================================================
694 // Description: This class is used to abstract details of a usb device
697 DECLARE_INTERFACE_(IUSBDevice
, IUnknown
)
699 DEFINE_ABSTRACT_UNKNOWN()
701 //----------------------------------------------------------------------------------------
705 // Description: Initializes the usb device
707 virtual NTSTATUS
Initialize(IN PHUBCONTROLLER HubController
,
708 IN PUSBHARDWAREDEVICE Device
,
711 IN ULONG PortStatus
) = 0;
713 //-----------------------------------------------------------------------------------------
717 // Description: returns true when device is a hub
719 virtual BOOLEAN
IsHub() = 0;
721 //-----------------------------------------------------------------------------------------
725 // Description: gets the parent device of the this device
727 virtual NTSTATUS
GetParent(PVOID
* Parent
) = 0;
729 //-----------------------------------------------------------------------------------------
733 // Description: gets the device address of the this device
735 virtual UCHAR
GetDeviceAddress() = 0;
738 //-----------------------------------------------------------------------------------------
742 // Description: gets the port to which this device is connected
744 virtual ULONG
GetPort() = 0;
746 //-----------------------------------------------------------------------------------------
750 // Description: gets the speed of the device
752 virtual USB_DEVICE_SPEED
GetSpeed() = 0;
754 //-----------------------------------------------------------------------------------------
758 // Description: gets the type of the device, either 1.1 or 2.0 device
760 virtual USB_DEVICE_TYPE
GetType() = 0;
762 //-----------------------------------------------------------------------------------------
766 // Description: gets the device state
768 virtual ULONG
GetState() = 0;
770 //-----------------------------------------------------------------------------------------
772 // SetDeviceHandleData
774 // Description: sets device handle data
776 virtual void SetDeviceHandleData(PVOID Data
) = 0;
778 //-----------------------------------------------------------------------------------------
782 // Description: sets device handle data
784 virtual NTSTATUS
SetDeviceAddress(UCHAR DeviceAddress
) = 0;
786 //-----------------------------------------------------------------------------------------
788 // GetDeviceDescriptor
790 // Description: sets device handle data
792 virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
) = 0;
794 //-----------------------------------------------------------------------------------------
796 // GetConfigurationValue
798 // Description: gets current selected configuration index
800 virtual UCHAR
GetConfigurationValue() = 0;
802 //-----------------------------------------------------------------------------------------
806 // Description: submits an irp containing an urb
808 virtual NTSTATUS
SubmitIrp(PIRP Irp
) = 0;
810 //-----------------------------------------------------------------------------------------
812 // GetConfigurationDescriptors
814 // Description: returns one or more configuration descriptors
816 virtual VOID
GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer
,
817 IN ULONG BufferLength
,
818 OUT PULONG OutBufferLength
) = 0;
820 //-----------------------------------------------------------------------------------------
822 // Description: returns length of configuration descriptors
824 virtual ULONG
GetConfigurationDescriptorsLength() = 0;
826 //-----------------------------------------------------------------------------------------
830 // Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
832 virtual NTSTATUS
SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
833 IN OUT ULONG BufferLength
,
834 OUT PVOID Buffer
) = 0;
836 //-----------------------------------------------------------------------------------------
838 // SelectConfiguration
840 // Description: selects a configuration
842 virtual NTSTATUS
SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
,
843 IN PUSBD_INTERFACE_INFORMATION Interface
,
844 OUT USBD_CONFIGURATION_HANDLE
*ConfigurationHandle
) = 0;
846 //-----------------------------------------------------------------------------------------
848 // SelectConfiguration
850 // Description: selects a interface of an configuration
852 virtual NTSTATUS
SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle
,
853 IN OUT PUSBD_INTERFACE_INFORMATION Interface
) = 0;
855 //-----------------------------------------------------------------------------------------
859 // Description: aborts all pending requsts
861 virtual NTSTATUS
AbortPipe(IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
) = 0;
865 typedef IUSBDevice
*PUSBDEVICE
;