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 OUT ULONG TransferBufferLength
,
406 IN OUT PMDL TransferBuffer
) = 0;
408 //-----------------------------------------------------------------------------------------
412 // Description: initializes the request with an IRP
413 // The irp contains an URB block which contains all necessary information
415 virtual NTSTATUS
InitializeWithIrp(IN PDMAMEMORYMANAGER DmaManager
,
416 IN OUT PIRP Irp
) = 0;
418 //-----------------------------------------------------------------------------------------
422 // Description: returns true when the request has been completed
423 // Should be called after the CompletionCallback has been invoked
424 // This function is called by IUSBQueue after queue head has been completed
425 // If the function returns true, IUSBQueue will then call ShouldReleaseRequestAfterCompletion
426 // If that function returns also true, it calls Release() to delete the IUSBRequest
428 virtual BOOLEAN
IsRequestComplete() = 0;
430 //-----------------------------------------------------------------------------------------
434 // Description: returns the type of the request: control, bulk, iso, interrupt
436 virtual ULONG
GetTransferType() = 0;
438 //-----------------------------------------------------------------------------------------
440 // GetEndpointDescriptor
442 // Description: returns the general transfer descriptor
444 virtual NTSTATUS
GetEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
446 //-----------------------------------------------------------------------------------------
450 // Description: returns the status code of the result
451 // Note: this function will block the caller untill the request has been completed
453 virtual VOID
GetResultStatus(OUT OPTIONAL NTSTATUS
* NtStatusCode
,
454 OUT OPTIONAL PULONG UrbStatusCode
) = 0;
456 //-----------------------------------------------------------------------------------------
458 // IsRequestInitialized
460 // Description: returns true when the request has been successfully initialized using InitializeXXX methods
462 virtual BOOLEAN
IsRequestInitialized() = 0;
464 //-----------------------------------------------------------------------------------------
466 // CompletionCallback
468 // Description: notifies request that the endpoint descriptor is complete
470 virtual VOID
CompletionCallback(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
472 //-----------------------------------------------------------------------------------------
474 // FreeEndpointDescriptor
476 // Description: frees the associated endpoint descriptor and its general descriptors
478 virtual VOID
FreeEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
480 //-----------------------------------------------------------------------------------------
482 // GetInterruptInterval
484 // Description: returns interval of the iso / interrupt
486 virtual UCHAR
GetInterval() = 0;
491 typedef IUSBRequest
*PUSBREQUEST
;
493 //=========================================================================================
497 // Description: This class manages pending requests
500 DECLARE_INTERFACE_(IUSBQueue
, IUnknown
)
502 DEFINE_ABSTRACT_UNKNOWN()
504 //-----------------------------------------------------------------------------------------
508 // Description: initializes the object
510 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Hardware
,
511 IN PDMA_ADAPTER AdapterObject
,
512 IN PDMAMEMORYMANAGER MemManager
,
513 IN OPTIONAL PKSPIN_LOCK Lock
) = 0;
515 //-----------------------------------------------------------------------------------------
517 // GetPendingRequestCount
519 // Description: returns the number of pending requests true from IsRequestComplete
521 virtual ULONG
GetPendingRequestCount() = 0;
523 //-----------------------------------------------------------------------------------------
527 // Description: adds an usb request to the queue.
528 // Returns status success when successful
530 virtual NTSTATUS
AddUSBRequest(IUSBRequest
* Request
) = 0;
532 //-----------------------------------------------------------------------------------------
536 // Description: cancels all requests
538 virtual NTSTATUS
CancelRequests() = 0;
540 //-----------------------------------------------------------------------------------------
544 // Description: creates an usb request
546 virtual NTSTATUS
CreateUSBRequest(IUSBRequest
**OutRequest
) = 0;
548 //-----------------------------------------------------------------------------------------
550 // TransferDescriptorCompletionCallback
552 // Description: notifies the queue that a transfer was completed
554 virtual VOID
TransferDescriptorCompletionCallback(ULONG TransferDescriptorLogicalAddress
) = 0;
558 typedef IUSBQueue
*PUSBQUEUE
;
560 //=========================================================================================
562 // class IHubController
564 // Description: This class implements a hub controller
567 DECLARE_INTERFACE_(IHubController
, IUnknown
)
569 DEFINE_ABSTRACT_UNKNOWN()
571 //----------------------------------------------------------------------------------------
575 // Description: Initializes the hub controller
577 virtual NTSTATUS
Initialize(IN PDRIVER_OBJECT DriverObject
,
578 IN PHCDCONTROLLER Controller
,
579 IN PUSBHARDWAREDEVICE Device
,
580 IN BOOLEAN IsRootHubDevice
,
581 IN ULONG DeviceAddress
) = 0;
583 //----------------------------------------------------------------------------------------
585 // GetHubControllerDeviceObject
587 // Description: Returns the hub controller device object
589 virtual NTSTATUS
GetHubControllerDeviceObject(PDEVICE_OBJECT
* HubDeviceObject
) = 0;
591 //----------------------------------------------------------------------------------------
593 // GetHubControllerSymbolicLink
595 // Description: Returns the symbolic link of the root hub
597 virtual NTSTATUS
GetHubControllerSymbolicLink(ULONG BufferLength
, PVOID Buffer
, PULONG RequiredLength
) = 0;
602 typedef IHubController
*PHUBCONTROLLER
;
604 //=========================================================================================
606 // class IDispatchIrp
608 // Description: This class is used to handle irp dispatch requests
611 DECLARE_INTERFACE_(IDispatchIrp
, IUnknown
)
613 DEFINE_ABSTRACT_UNKNOWN()
615 //-----------------------------------------------------------------------------------------
619 // Description: This function handles all pnp requests
621 virtual NTSTATUS
HandlePnp(IN PDEVICE_OBJECT DeviceObject
,
622 IN OUT PIRP Irp
) = 0;
624 //-----------------------------------------------------------------------------------------
628 // Description: This function handles all power pnp requests
630 virtual NTSTATUS
HandlePower(IN PDEVICE_OBJECT DeviceObject
,
631 IN OUT PIRP Irp
) = 0;
633 //-----------------------------------------------------------------------------------------
635 // HandleDeviceControl
637 // Description: handles device io control requests
639 virtual NTSTATUS
HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
640 IN OUT PIRP Irp
) = 0;
643 typedef IDispatchIrp
*PDISPATCHIRP
;
645 //=========================================================================================
649 // Description: This class is used to abstract details of a usb device
652 DECLARE_INTERFACE_(IUSBDevice
, IUnknown
)
654 DEFINE_ABSTRACT_UNKNOWN()
656 //----------------------------------------------------------------------------------------
660 // Description: Initializes the usb device
662 virtual NTSTATUS
Initialize(IN PHUBCONTROLLER HubController
,
663 IN PUSBHARDWAREDEVICE Device
,
666 IN ULONG PortStatus
) = 0;
668 //-----------------------------------------------------------------------------------------
672 // Description: returns true when device is a hub
674 virtual BOOLEAN
IsHub() = 0;
676 //-----------------------------------------------------------------------------------------
680 // Description: gets the parent device of the this device
682 virtual NTSTATUS
GetParent(PVOID
* Parent
) = 0;
684 //-----------------------------------------------------------------------------------------
688 // Description: gets the device address of the this device
690 virtual UCHAR
GetDeviceAddress() = 0;
693 //-----------------------------------------------------------------------------------------
697 // Description: gets the port to which this device is connected
699 virtual ULONG
GetPort() = 0;
701 //-----------------------------------------------------------------------------------------
705 // Description: gets the speed of the device
707 virtual USB_DEVICE_SPEED
GetSpeed() = 0;
709 //-----------------------------------------------------------------------------------------
713 // Description: gets the type of the device, either 1.1 or 2.0 device
715 virtual USB_DEVICE_TYPE
GetType() = 0;
717 //-----------------------------------------------------------------------------------------
721 // Description: gets the device state
723 virtual ULONG
GetState() = 0;
725 //-----------------------------------------------------------------------------------------
727 // SetDeviceHandleData
729 // Description: sets device handle data
731 virtual void SetDeviceHandleData(PVOID Data
) = 0;
733 //-----------------------------------------------------------------------------------------
737 // Description: sets device handle data
739 virtual NTSTATUS
SetDeviceAddress(UCHAR DeviceAddress
) = 0;
741 //-----------------------------------------------------------------------------------------
743 // GetDeviceDescriptor
745 // Description: sets device handle data
747 virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
) = 0;
749 //-----------------------------------------------------------------------------------------
751 // GetConfigurationValue
753 // Description: gets current selected configuration index
755 virtual UCHAR
GetConfigurationValue() = 0;
757 //-----------------------------------------------------------------------------------------
761 // Description: submits an irp containing an urb
763 virtual NTSTATUS
SubmitIrp(PIRP Irp
) = 0;
765 //-----------------------------------------------------------------------------------------
767 // GetConfigurationDescriptors
769 // Description: returns one or more configuration descriptors
771 virtual VOID
GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer
,
772 IN ULONG BufferLength
,
773 OUT PULONG OutBufferLength
) = 0;
775 //-----------------------------------------------------------------------------------------
777 // Description: returns length of configuration descriptors
779 virtual ULONG
GetConfigurationDescriptorsLength() = 0;
781 //-----------------------------------------------------------------------------------------
785 // Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
787 virtual NTSTATUS
SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
788 IN OUT ULONG BufferLength
,
789 OUT PVOID Buffer
) = 0;
791 //-----------------------------------------------------------------------------------------
793 // SelectConfiguration
795 // Description: selects a configuration
797 virtual NTSTATUS
SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
,
798 IN PUSBD_INTERFACE_INFORMATION Interface
,
799 OUT USBD_CONFIGURATION_HANDLE
*ConfigurationHandle
) = 0;
801 //-----------------------------------------------------------------------------------------
803 // SelectConfiguration
805 // Description: selects a interface of an configuration
807 virtual NTSTATUS
SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle
,
808 IN OUT PUSBD_INTERFACE_INFORMATION Interface
) = 0;
811 typedef IUSBDevice
*PUSBDEVICE
;