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 // GetIsochronousHeadEndpointDescriptor
195 // Description: returns the control head endpoint descriptor
197 virtual NTSTATUS
GetIsochronousHeadEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
200 //-----------------------------------------------------------------------------------------
202 // GetInterruptEndpointDescriptors
204 // Description: returns interrupt endpoint descriptors
206 virtual NTSTATUS
GetInterruptEndpointDescriptors(struct _OHCI_ENDPOINT_DESCRIPTOR
*** OutDescriptorArray
) = 0;
208 //-----------------------------------------------------------------------------------------
210 // HeadEndpointDescriptorModified
212 // Description: notifies the hardware that an endpoint descriptor was added to head endpoint descriptor
214 virtual VOID
HeadEndpointDescriptorModified(ULONG HeadType
) = 0;
219 //-----------------------------------------------------------------------------------------
223 // Description: returns the DMA object which can be used to allocate memory from the common buffer
225 virtual NTSTATUS
GetDMA(OUT
struct IDMAMemoryManager
**OutDMAMemoryManager
) = 0;
228 //-----------------------------------------------------------------------------------------
232 // Description: this function resets the controller
233 // Returns STATUS_SUCCESS when the controller was successfully reset
235 virtual NTSTATUS
ResetController() = 0;
237 //-----------------------------------------------------------------------------------------
241 // Description: this functions starts controller allowing interrupts for device connects/removal, and execution of
242 // Periodic and Asynchronous Schedules.
245 virtual NTSTATUS
StartController() = 0;
247 //-----------------------------------------------------------------------------------------
251 // Description: this functions stops controller disabling interrupts for device connects/removal, and execution of
252 // Periodic and Asynchronous Schedules.
255 virtual NTSTATUS
StopController() = 0;
257 //-----------------------------------------------------------------------------------------
261 // Description: this functions resets the port on the controller
264 virtual NTSTATUS
ResetPort(ULONG PortNumber
) = 0;
266 //-----------------------------------------------------------------------------------------
270 // Description: this functions return status and change state of port
272 virtual NTSTATUS
GetPortStatus(ULONG PortId
, OUT USHORT
*PortStatus
, OUT USHORT
*PortChange
) = 0;
274 //-----------------------------------------------------------------------------------------
278 // Description: Clears Status of Port, for example Connection, Enable and Reset
280 virtual NTSTATUS
ClearPortStatus(ULONG PortId
, ULONG Status
) = 0;
282 //-----------------------------------------------------------------------------------------
286 // Description: this functions Sets Feature on Port, for example Enable, Power and Reset
288 virtual NTSTATUS
SetPortFeature(ULONG PortId
, ULONG Feature
) = 0;
290 //-----------------------------------------------------------------------------------------
292 // SetStatusChangeEndpointCallBack
294 // Description: Used to callback to the hub controller when SCE detected
296 virtual VOID
SetStatusChangeEndpointCallBack(PVOID CallBack
,PVOID Context
) = 0;
298 //-----------------------------------------------------------------------------------------
302 // Description: acquires the device lock
304 virtual KIRQL
AcquireDeviceLock(void) = 0;
306 //-----------------------------------------------------------------------------------------
310 // Description: releases the device lock
312 virtual void ReleaseDeviceLock(KIRQL OldLevel
) = 0;
314 //----------------------------------------------------------------------------------------
316 // GetCurrentFrameNumber
318 // Description: returns the current frame number
320 virtual VOID
GetCurrentFrameNumber(PULONG FrameNumber
) = 0;
323 typedef IUSBHardwareDevice
*PUSBHARDWAREDEVICE
;
326 //=========================================================================================
328 // class IDMAMemoryManager
330 // Description: This class provides access to the dma buffer. It provides methods to
331 // allocate and free from the dma buffer
334 DECLARE_INTERFACE_(IDMAMemoryManager
, IUnknown
)
336 DEFINE_ABSTRACT_UNKNOWN()
338 //-----------------------------------------------------------------------------------------
342 // Description: initializes the memory manager
344 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Device
,
346 IN ULONG DmaBufferSize
,
347 IN PVOID VirtualBase
,
348 IN PHYSICAL_ADDRESS PhysicalAddress
,
349 IN ULONG DefaultBlockSize
) = 0;
351 //-----------------------------------------------------------------------------------------
355 // Description: allocates block of memory from allocator
357 virtual NTSTATUS
Allocate(IN ULONG Size
,
358 OUT PVOID
*OutVirtualBase
,
359 OUT PPHYSICAL_ADDRESS OutPhysicalAddress
) = 0;
362 //-----------------------------------------------------------------------------------------
366 // Description: releases memory block
368 virtual NTSTATUS
Release(IN PVOID VirtualBase
,
373 typedef IDMAMemoryManager
*PDMAMEMORYMANAGER
;
376 //=========================================================================================
380 // Description: This class is used to issue request to usb controller. The class is
381 // initialized using InitializeXXX methods. You also need to call SetEndpoint to define the endpoint
382 // In addition you can call SetCompletionDetails if you need to wait for the end of
383 // the request or want to complete an irp. You call AddUSBRequest to add the request to the queue.
384 // Once the request is completed the CompletionCallback is invoked. The CompletionCallback
385 // will take care of any completion details which have been set. If the request is cancelled, the
386 // CancelCallback routine is invoked.
389 DECLARE_INTERFACE_(IUSBRequest
, IUnknown
)
391 DEFINE_ABSTRACT_UNKNOWN()
393 //-----------------------------------------------------------------------------------------
395 // InitializeWithSetupPacket
397 // Description: initializes the request packet with an setup packet
398 // If there is a TransferBuffer, the TransferBufferLength contains the length of the buffer
401 virtual NTSTATUS
InitializeWithSetupPacket(IN PDMAMEMORYMANAGER DmaManager
,
402 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
403 IN UCHAR DeviceAddress
,
404 IN OPTIONAL PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
,
405 IN USB_DEVICE_SPEED DeviceSpeed
,
406 IN OUT ULONG TransferBufferLength
,
407 IN OUT PMDL TransferBuffer
) = 0;
409 //-----------------------------------------------------------------------------------------
413 // Description: initializes the request with an IRP
414 // The irp contains an URB block which contains all necessary information
415 // contains the device speed (FullSpeed / LowSpeed)
417 virtual NTSTATUS
InitializeWithIrp(IN PDMAMEMORYMANAGER DmaManager
,
419 IN USB_DEVICE_SPEED DeviceSpeed
) = 0;
421 //-----------------------------------------------------------------------------------------
425 // Description: returns true when the request has been completed
426 // Should be called after the CompletionCallback has been invoked
427 // This function is called by IUSBQueue after queue head has been completed
428 // If the function returns true, IUSBQueue will then call ShouldReleaseRequestAfterCompletion
429 // If that function returns also true, it calls Release() to delete the IUSBRequest
431 virtual BOOLEAN
IsRequestComplete() = 0;
433 //-----------------------------------------------------------------------------------------
437 // Description: returns the type of the request: control, bulk, iso, interrupt
439 virtual ULONG
GetTransferType() = 0;
441 //-----------------------------------------------------------------------------------------
443 // GetEndpointDescriptor
445 // Description: returns the general transfer descriptor
447 virtual NTSTATUS
GetEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
449 //-----------------------------------------------------------------------------------------
453 // Description: returns the status code of the result
454 // Note: this function will block the caller untill the request has been completed
456 virtual VOID
GetResultStatus(OUT OPTIONAL NTSTATUS
* NtStatusCode
,
457 OUT OPTIONAL PULONG UrbStatusCode
) = 0;
459 //-----------------------------------------------------------------------------------------
461 // IsRequestInitialized
463 // Description: returns true when the request has been successfully initialized using InitializeXXX methods
465 virtual BOOLEAN
IsRequestInitialized() = 0;
467 //-----------------------------------------------------------------------------------------
469 // CompletionCallback
471 // Description: notifies request that the endpoint descriptor is complete
473 virtual VOID
CompletionCallback(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
475 //-----------------------------------------------------------------------------------------
477 // FreeEndpointDescriptor
479 // Description: frees the associated endpoint descriptor and its general descriptors
481 virtual VOID
FreeEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
483 //-----------------------------------------------------------------------------------------
485 // GetInterruptInterval
487 // Description: returns interval of the iso / interrupt
489 virtual UCHAR
GetInterval() = 0;
494 typedef IUSBRequest
*PUSBREQUEST
;
496 //=========================================================================================
500 // Description: This class manages pending requests
503 DECLARE_INTERFACE_(IUSBQueue
, IUnknown
)
505 DEFINE_ABSTRACT_UNKNOWN()
507 //-----------------------------------------------------------------------------------------
511 // Description: initializes the object
513 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Hardware
,
514 IN PDMA_ADAPTER AdapterObject
,
515 IN PDMAMEMORYMANAGER MemManager
,
516 IN OPTIONAL PKSPIN_LOCK Lock
) = 0;
518 //-----------------------------------------------------------------------------------------
520 // GetPendingRequestCount
522 // Description: returns the number of pending requests true from IsRequestComplete
524 virtual ULONG
GetPendingRequestCount() = 0;
526 //-----------------------------------------------------------------------------------------
530 // Description: adds an usb request to the queue.
531 // Returns status success when successful
533 virtual NTSTATUS
AddUSBRequest(IUSBRequest
* Request
) = 0;
535 //-----------------------------------------------------------------------------------------
539 // Description: cancels all requests
541 virtual NTSTATUS
CancelRequests() = 0;
543 //-----------------------------------------------------------------------------------------
547 // Description: creates an usb request
549 virtual NTSTATUS
CreateUSBRequest(IUSBRequest
**OutRequest
) = 0;
551 //-----------------------------------------------------------------------------------------
553 // TransferDescriptorCompletionCallback
555 // Description: notifies the queue that a transfer was completed
557 virtual VOID
TransferDescriptorCompletionCallback(ULONG TransferDescriptorLogicalAddress
) = 0;
560 //-----------------------------------------------------------------------------------------
564 // Description: aborts all pending requsts of an device
566 virtual NTSTATUS
AbortDevicePipe(UCHAR DeviceAddress
, IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
) = 0;
569 typedef IUSBQueue
*PUSBQUEUE
;
571 //=========================================================================================
573 // class IHubController
575 // Description: This class implements a hub controller
578 DECLARE_INTERFACE_(IHubController
, IUnknown
)
580 DEFINE_ABSTRACT_UNKNOWN()
582 //----------------------------------------------------------------------------------------
586 // Description: Initializes the hub controller
588 virtual NTSTATUS
Initialize(IN PDRIVER_OBJECT DriverObject
,
589 IN PHCDCONTROLLER Controller
,
590 IN PUSBHARDWAREDEVICE Device
,
591 IN BOOLEAN IsRootHubDevice
,
592 IN ULONG DeviceAddress
) = 0;
594 //----------------------------------------------------------------------------------------
596 // GetHubControllerDeviceObject
598 // Description: Returns the hub controller device object
600 virtual NTSTATUS
GetHubControllerDeviceObject(PDEVICE_OBJECT
* HubDeviceObject
) = 0;
602 //----------------------------------------------------------------------------------------
604 // GetHubControllerSymbolicLink
606 // Description: Returns the symbolic link of the root hub
608 virtual NTSTATUS
GetHubControllerSymbolicLink(ULONG BufferLength
, PVOID Buffer
, PULONG RequiredLength
) = 0;
613 typedef IHubController
*PHUBCONTROLLER
;
615 //=========================================================================================
617 // class IDispatchIrp
619 // Description: This class is used to handle irp dispatch requests
622 DECLARE_INTERFACE_(IDispatchIrp
, IUnknown
)
624 DEFINE_ABSTRACT_UNKNOWN()
626 //-----------------------------------------------------------------------------------------
630 // Description: This function handles all pnp requests
632 virtual NTSTATUS
HandlePnp(IN PDEVICE_OBJECT DeviceObject
,
633 IN OUT PIRP Irp
) = 0;
635 //-----------------------------------------------------------------------------------------
639 // Description: This function handles all power pnp requests
641 virtual NTSTATUS
HandlePower(IN PDEVICE_OBJECT DeviceObject
,
642 IN OUT PIRP Irp
) = 0;
644 //-----------------------------------------------------------------------------------------
646 // HandleDeviceControl
648 // Description: handles device io control requests
650 virtual NTSTATUS
HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
651 IN OUT PIRP Irp
) = 0;
654 typedef IDispatchIrp
*PDISPATCHIRP
;
656 //=========================================================================================
660 // Description: This class is used to abstract details of a usb device
663 DECLARE_INTERFACE_(IUSBDevice
, IUnknown
)
665 DEFINE_ABSTRACT_UNKNOWN()
667 //----------------------------------------------------------------------------------------
671 // Description: Initializes the usb device
673 virtual NTSTATUS
Initialize(IN PHUBCONTROLLER HubController
,
674 IN PUSBHARDWAREDEVICE Device
,
677 IN ULONG PortStatus
) = 0;
679 //-----------------------------------------------------------------------------------------
683 // Description: returns true when device is a hub
685 virtual BOOLEAN
IsHub() = 0;
687 //-----------------------------------------------------------------------------------------
691 // Description: gets the parent device of the this device
693 virtual NTSTATUS
GetParent(PVOID
* Parent
) = 0;
695 //-----------------------------------------------------------------------------------------
699 // Description: gets the device address of the this device
701 virtual UCHAR
GetDeviceAddress() = 0;
704 //-----------------------------------------------------------------------------------------
708 // Description: gets the port to which this device is connected
710 virtual ULONG
GetPort() = 0;
712 //-----------------------------------------------------------------------------------------
716 // Description: gets the speed of the device
718 virtual USB_DEVICE_SPEED
GetSpeed() = 0;
720 //-----------------------------------------------------------------------------------------
724 // Description: gets the type of the device, either 1.1 or 2.0 device
726 virtual USB_DEVICE_TYPE
GetType() = 0;
728 //-----------------------------------------------------------------------------------------
732 // Description: gets the device state
734 virtual ULONG
GetState() = 0;
736 //-----------------------------------------------------------------------------------------
738 // SetDeviceHandleData
740 // Description: sets device handle data
742 virtual void SetDeviceHandleData(PVOID Data
) = 0;
744 //-----------------------------------------------------------------------------------------
748 // Description: sets device handle data
750 virtual NTSTATUS
SetDeviceAddress(UCHAR DeviceAddress
) = 0;
752 //-----------------------------------------------------------------------------------------
754 // GetDeviceDescriptor
756 // Description: sets device handle data
758 virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
) = 0;
760 //-----------------------------------------------------------------------------------------
762 // GetConfigurationValue
764 // Description: gets current selected configuration index
766 virtual UCHAR
GetConfigurationValue() = 0;
768 //-----------------------------------------------------------------------------------------
772 // Description: submits an irp containing an urb
774 virtual NTSTATUS
SubmitIrp(PIRP Irp
) = 0;
776 //-----------------------------------------------------------------------------------------
778 // GetConfigurationDescriptors
780 // Description: returns one or more configuration descriptors
782 virtual VOID
GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer
,
783 IN ULONG BufferLength
,
784 OUT PULONG OutBufferLength
) = 0;
786 //-----------------------------------------------------------------------------------------
788 // Description: returns length of configuration descriptors
790 virtual ULONG
GetConfigurationDescriptorsLength() = 0;
792 //-----------------------------------------------------------------------------------------
796 // Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
798 virtual NTSTATUS
SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
799 IN OUT ULONG BufferLength
,
800 OUT PVOID Buffer
) = 0;
802 //-----------------------------------------------------------------------------------------
804 // SelectConfiguration
806 // Description: selects a configuration
808 virtual NTSTATUS
SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
,
809 IN PUSBD_INTERFACE_INFORMATION Interface
,
810 OUT USBD_CONFIGURATION_HANDLE
*ConfigurationHandle
) = 0;
812 //-----------------------------------------------------------------------------------------
814 // SelectConfiguration
816 // Description: selects a interface of an configuration
818 virtual NTSTATUS
SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle
,
819 IN OUT PUSBD_INTERFACE_INFORMATION Interface
) = 0;
822 //-----------------------------------------------------------------------------------------
826 // Description: aborts all pending requsts
828 virtual NTSTATUS
AbortPipe(IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
) = 0;
832 typedef IUSBDevice
*PUSBDEVICE
;