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 // GetInterruptEndpointDescriptors
195 // Description: returns interrupt endpoint descriptors
197 virtual NTSTATUS
GetInterruptEndpointDescriptors(struct _OHCI_ENDPOINT_DESCRIPTOR
*** OutDescriptorArray
) = 0;
199 //-----------------------------------------------------------------------------------------
201 // HeadEndpointDescriptorModified
203 // Description: notifies the hardware that an endpoint descriptor was added to head endpoint descriptor
205 virtual VOID
HeadEndpointDescriptorModified(ULONG HeadType
) = 0;
210 //-----------------------------------------------------------------------------------------
214 // Description: returns the DMA object which can be used to allocate memory from the common buffer
216 virtual NTSTATUS
GetDMA(OUT
struct IDMAMemoryManager
**OutDMAMemoryManager
) = 0;
219 //-----------------------------------------------------------------------------------------
223 // Description: this function resets the controller
224 // Returns STATUS_SUCCESS when the controller was successfully reset
226 virtual NTSTATUS
ResetController() = 0;
228 //-----------------------------------------------------------------------------------------
232 // Description: this functions starts controller allowing interrupts for device connects/removal, and execution of
233 // Periodic and Asynchronous Schedules.
236 virtual NTSTATUS
StartController() = 0;
238 //-----------------------------------------------------------------------------------------
242 // Description: this functions stops controller disabling interrupts for device connects/removal, and execution of
243 // Periodic and Asynchronous Schedules.
246 virtual NTSTATUS
StopController() = 0;
248 //-----------------------------------------------------------------------------------------
252 // Description: this functions resets the port on the controller
255 virtual NTSTATUS
ResetPort(ULONG PortNumber
) = 0;
257 //-----------------------------------------------------------------------------------------
261 // Description: this functions return status and change state of port
263 virtual NTSTATUS
GetPortStatus(ULONG PortId
, OUT USHORT
*PortStatus
, OUT USHORT
*PortChange
) = 0;
265 //-----------------------------------------------------------------------------------------
269 // Description: Clears Status of Port, for example Connection, Enable and Reset
271 virtual NTSTATUS
ClearPortStatus(ULONG PortId
, ULONG Status
) = 0;
273 //-----------------------------------------------------------------------------------------
277 // Description: this functions Sets Feature on Port, for example Enable, Power and Reset
279 virtual NTSTATUS
SetPortFeature(ULONG PortId
, ULONG Feature
) = 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 typedef IUSBHardwareDevice
*PUSBHARDWAREDEVICE
;
309 //=========================================================================================
311 // class IDMAMemoryManager
313 // Description: This class provides access to the dma buffer. It provides methods to
314 // allocate and free from the dma buffer
317 DECLARE_INTERFACE_(IDMAMemoryManager
, IUnknown
)
319 DEFINE_ABSTRACT_UNKNOWN()
321 //-----------------------------------------------------------------------------------------
325 // Description: initializes the memory manager
327 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Device
,
329 IN ULONG DmaBufferSize
,
330 IN PVOID VirtualBase
,
331 IN PHYSICAL_ADDRESS PhysicalAddress
,
332 IN ULONG DefaultBlockSize
) = 0;
334 //-----------------------------------------------------------------------------------------
338 // Description: allocates block of memory from allocator
340 virtual NTSTATUS
Allocate(IN ULONG Size
,
341 OUT PVOID
*OutVirtualBase
,
342 OUT PPHYSICAL_ADDRESS OutPhysicalAddress
) = 0;
345 //-----------------------------------------------------------------------------------------
349 // Description: releases memory block
351 virtual NTSTATUS
Release(IN PVOID VirtualBase
,
356 typedef IDMAMemoryManager
*PDMAMEMORYMANAGER
;
359 //=========================================================================================
363 // Description: This class is used to issue request to usb controller. The class is
364 // initialized using InitializeXXX methods. You also need to call SetEndpoint to define the endpoint
365 // In addition you can call SetCompletionDetails if you need to wait for the end of
366 // the request or want to complete an irp. You call AddUSBRequest to add the request to the queue.
367 // Once the request is completed the CompletionCallback is invoked. The CompletionCallback
368 // will take care of any completion details which have been set. If the request is cancelled, the
369 // CancelCallback routine is invoked.
372 DECLARE_INTERFACE_(IUSBRequest
, IUnknown
)
374 DEFINE_ABSTRACT_UNKNOWN()
376 //-----------------------------------------------------------------------------------------
378 // InitializeWithSetupPacket
380 // Description: initializes the request packet with an setup packet
381 // If there is a TransferBuffer, the TransferBufferLength contains the length of the buffer
384 virtual NTSTATUS
InitializeWithSetupPacket(IN PDMAMEMORYMANAGER DmaManager
,
385 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
386 IN UCHAR DeviceAddress
,
387 IN OPTIONAL PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor
,
388 IN OUT ULONG TransferBufferLength
,
389 IN OUT PMDL TransferBuffer
) = 0;
391 //-----------------------------------------------------------------------------------------
395 // Description: initializes the request with an IRP
396 // The irp contains an URB block which contains all necessary information
398 virtual NTSTATUS
InitializeWithIrp(IN PDMAMEMORYMANAGER DmaManager
,
399 IN OUT PIRP Irp
) = 0;
401 //-----------------------------------------------------------------------------------------
405 // Description: returns true when the request has been completed
406 // Should be called after the CompletionCallback has been invoked
407 // This function is called by IUSBQueue after queue head has been completed
408 // If the function returns true, IUSBQueue will then call ShouldReleaseRequestAfterCompletion
409 // If that function returns also true, it calls Release() to delete the IUSBRequest
411 virtual BOOLEAN
IsRequestComplete() = 0;
413 //-----------------------------------------------------------------------------------------
417 // Description: returns the type of the request: control, bulk, iso, interrupt
419 virtual ULONG
GetTransferType() = 0;
421 //-----------------------------------------------------------------------------------------
423 // GetEndpointDescriptor
425 // Description: returns the general transfer descriptor
427 virtual NTSTATUS
GetEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
** OutDescriptor
) = 0;
429 //-----------------------------------------------------------------------------------------
433 // Description: returns the status code of the result
434 // Note: this function will block the caller untill the request has been completed
436 virtual VOID
GetResultStatus(OUT OPTIONAL NTSTATUS
* NtStatusCode
,
437 OUT OPTIONAL PULONG UrbStatusCode
) = 0;
439 //-----------------------------------------------------------------------------------------
441 // IsRequestInitialized
443 // Description: returns true when the request has been successfully initialized using InitializeXXX methods
445 virtual BOOLEAN
IsRequestInitialized() = 0;
447 //-----------------------------------------------------------------------------------------
449 // CompletionCallback
451 // Description: notifies request that the endpoint descriptor is complete
453 virtual VOID
CompletionCallback(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
455 //-----------------------------------------------------------------------------------------
457 // FreeEndpointDescriptor
459 // Description: frees the associated endpoint descriptor and its general descriptors
461 virtual VOID
FreeEndpointDescriptor(struct _OHCI_ENDPOINT_DESCRIPTOR
* OutDescriptor
) = 0;
463 //-----------------------------------------------------------------------------------------
465 // GetInterruptInterval
467 // Description: returns interval of the iso / interrupt
469 virtual UCHAR
GetInterval() = 0;
474 typedef IUSBRequest
*PUSBREQUEST
;
476 //=========================================================================================
480 // Description: This class manages pending requests
483 DECLARE_INTERFACE_(IUSBQueue
, IUnknown
)
485 DEFINE_ABSTRACT_UNKNOWN()
487 //-----------------------------------------------------------------------------------------
491 // Description: initializes the object
493 virtual NTSTATUS
Initialize(IN PUSBHARDWAREDEVICE Hardware
,
494 IN PDMA_ADAPTER AdapterObject
,
495 IN PDMAMEMORYMANAGER MemManager
,
496 IN OPTIONAL PKSPIN_LOCK Lock
) = 0;
498 //-----------------------------------------------------------------------------------------
500 // GetPendingRequestCount
502 // Description: returns the number of pending requests true from IsRequestComplete
504 virtual ULONG
GetPendingRequestCount() = 0;
506 //-----------------------------------------------------------------------------------------
510 // Description: adds an usb request to the queue.
511 // Returns status success when successful
513 virtual NTSTATUS
AddUSBRequest(IUSBRequest
* Request
) = 0;
515 //-----------------------------------------------------------------------------------------
519 // Description: cancels all requests
521 virtual NTSTATUS
CancelRequests() = 0;
523 //-----------------------------------------------------------------------------------------
527 // Description: creates an usb request
529 virtual NTSTATUS
CreateUSBRequest(IUSBRequest
**OutRequest
) = 0;
531 //-----------------------------------------------------------------------------------------
533 // TransferDescriptorCompletionCallback
535 // Description: notifies the queue that a transfer was completed
537 virtual VOID
TransferDescriptorCompletionCallback(ULONG TransferDescriptorLogicalAddress
) = 0;
541 typedef IUSBQueue
*PUSBQUEUE
;
543 //=========================================================================================
545 // class IHubController
547 // Description: This class implements a hub controller
550 DECLARE_INTERFACE_(IHubController
, IUnknown
)
552 DEFINE_ABSTRACT_UNKNOWN()
554 //----------------------------------------------------------------------------------------
558 // Description: Initializes the hub controller
560 virtual NTSTATUS
Initialize(IN PDRIVER_OBJECT DriverObject
,
561 IN PHCDCONTROLLER Controller
,
562 IN PUSBHARDWAREDEVICE Device
,
563 IN BOOLEAN IsRootHubDevice
,
564 IN ULONG DeviceAddress
) = 0;
566 //----------------------------------------------------------------------------------------
568 // GetHubControllerDeviceObject
570 // Description: Returns the hub controller device object
572 virtual NTSTATUS
GetHubControllerDeviceObject(PDEVICE_OBJECT
* HubDeviceObject
) = 0;
574 //----------------------------------------------------------------------------------------
576 // GetHubControllerSymbolicLink
578 // Description: Returns the symbolic link of the root hub
580 virtual NTSTATUS
GetHubControllerSymbolicLink(ULONG BufferLength
, PVOID Buffer
, PULONG RequiredLength
) = 0;
585 typedef IHubController
*PHUBCONTROLLER
;
587 //=========================================================================================
589 // class IDispatchIrp
591 // Description: This class is used to handle irp dispatch requests
594 DECLARE_INTERFACE_(IDispatchIrp
, IUnknown
)
596 DEFINE_ABSTRACT_UNKNOWN()
598 //-----------------------------------------------------------------------------------------
602 // Description: This function handles all pnp requests
604 virtual NTSTATUS
HandlePnp(IN PDEVICE_OBJECT DeviceObject
,
605 IN OUT PIRP Irp
) = 0;
607 //-----------------------------------------------------------------------------------------
611 // Description: This function handles all power pnp requests
613 virtual NTSTATUS
HandlePower(IN PDEVICE_OBJECT DeviceObject
,
614 IN OUT PIRP Irp
) = 0;
616 //-----------------------------------------------------------------------------------------
618 // HandleDeviceControl
620 // Description: handles device io control requests
622 virtual NTSTATUS
HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
623 IN OUT PIRP Irp
) = 0;
626 typedef IDispatchIrp
*PDISPATCHIRP
;
628 //=========================================================================================
632 // Description: This class is used to abstract details of a usb device
635 DECLARE_INTERFACE_(IUSBDevice
, IUnknown
)
637 DEFINE_ABSTRACT_UNKNOWN()
639 //----------------------------------------------------------------------------------------
643 // Description: Initializes the usb device
645 virtual NTSTATUS
Initialize(IN PHUBCONTROLLER HubController
,
646 IN PUSBHARDWAREDEVICE Device
,
649 IN ULONG PortStatus
) = 0;
651 //-----------------------------------------------------------------------------------------
655 // Description: returns true when device is a hub
657 virtual BOOLEAN
IsHub() = 0;
659 //-----------------------------------------------------------------------------------------
663 // Description: gets the parent device of the this device
665 virtual NTSTATUS
GetParent(PVOID
* Parent
) = 0;
667 //-----------------------------------------------------------------------------------------
671 // Description: gets the device address of the this device
673 virtual UCHAR
GetDeviceAddress() = 0;
676 //-----------------------------------------------------------------------------------------
680 // Description: gets the port to which this device is connected
682 virtual ULONG
GetPort() = 0;
684 //-----------------------------------------------------------------------------------------
688 // Description: gets the speed of the device
690 virtual USB_DEVICE_SPEED
GetSpeed() = 0;
692 //-----------------------------------------------------------------------------------------
696 // Description: gets the type of the device, either 1.1 or 2.0 device
698 virtual USB_DEVICE_TYPE
GetType() = 0;
700 //-----------------------------------------------------------------------------------------
704 // Description: gets the device state
706 virtual ULONG
GetState() = 0;
708 //-----------------------------------------------------------------------------------------
710 // SetDeviceHandleData
712 // Description: sets device handle data
714 virtual void SetDeviceHandleData(PVOID Data
) = 0;
716 //-----------------------------------------------------------------------------------------
720 // Description: sets device handle data
722 virtual NTSTATUS
SetDeviceAddress(UCHAR DeviceAddress
) = 0;
724 //-----------------------------------------------------------------------------------------
726 // GetDeviceDescriptor
728 // Description: sets device handle data
730 virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
) = 0;
732 //-----------------------------------------------------------------------------------------
734 // GetConfigurationValue
736 // Description: gets current selected configuration index
738 virtual UCHAR
GetConfigurationValue() = 0;
740 //-----------------------------------------------------------------------------------------
744 // Description: submits an irp containing an urb
746 virtual NTSTATUS
SubmitIrp(PIRP Irp
) = 0;
748 //-----------------------------------------------------------------------------------------
750 // GetConfigurationDescriptors
752 // Description: returns one or more configuration descriptors
754 virtual VOID
GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer
,
755 IN ULONG BufferLength
,
756 OUT PULONG OutBufferLength
) = 0;
758 //-----------------------------------------------------------------------------------------
760 // Description: returns length of configuration descriptors
762 virtual ULONG
GetConfigurationDescriptorsLength() = 0;
764 //-----------------------------------------------------------------------------------------
768 // Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
770 virtual NTSTATUS
SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket
,
771 IN OUT ULONG BufferLength
,
772 OUT PVOID Buffer
) = 0;
774 //-----------------------------------------------------------------------------------------
776 // SelectConfiguration
778 // Description: selects a configuration
780 virtual NTSTATUS
SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
,
781 IN PUSBD_INTERFACE_INFORMATION Interface
,
782 OUT USBD_CONFIGURATION_HANDLE
*ConfigurationHandle
) = 0;
784 //-----------------------------------------------------------------------------------------
786 // SelectConfiguration
788 // Description: selects a interface of an configuration
790 virtual NTSTATUS
SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle
,
791 IN OUT PUSBD_INTERFACE_INFORMATION Interface
) = 0;
794 typedef IUSBDevice
*PUSBDEVICE
;