3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Wrapper function for usb host controller interface
30 Get the capability of the host controller
32 @param UsbBus The usb driver
33 @param MaxSpeed The maximum speed this host controller supports
34 @param NumOfPort The number of the root hub port
35 @param Is64BitCapable Whether this controller support 64 bit addressing
37 @retval EFI_SUCCESS The host controller capability is returned
38 @retval Others Failed to retrieve the host controller capability.
46 OUT UINT8
*Is64BitCapable
51 if (UsbBus
->Usb2Hc
!= NULL
) {
52 Status
= UsbBus
->Usb2Hc
->GetCapability (
60 Status
= UsbBus
->UsbHc
->GetRootHubPortNumber (UsbBus
->UsbHc
, NumOfPort
);
62 *MaxSpeed
= EFI_USB_SPEED_FULL
;
63 *Is64BitCapable
= (UINT8
) FALSE
;
71 Reset the host controller
73 @param UsbBus The usb bus driver
74 @param Attributes The reset type, only global reset is used by this driver
76 @return GC_TODO: add return values
87 if (UsbBus
->Usb2Hc
!= NULL
) {
88 Status
= UsbBus
->Usb2Hc
->Reset (UsbBus
->Usb2Hc
, Attributes
);
90 Status
= UsbBus
->UsbHc
->Reset (UsbBus
->UsbHc
, Attributes
);
98 Get the current operation state of the host controller
100 @param UsbBus The USB bus driver
101 @param State The host controller operation state
103 @retval EFI_SUCCESS The operation state is returned in State
104 @retval Others Failed to get the host controller state
110 OUT EFI_USB_HC_STATE
*State
115 if (UsbBus
->Usb2Hc
!= NULL
) {
116 Status
= UsbBus
->Usb2Hc
->GetState (UsbBus
->Usb2Hc
, State
);
118 Status
= UsbBus
->UsbHc
->GetState (UsbBus
->UsbHc
, State
);
126 Set the host controller operation state
128 @param UsbBus The USB bus driver
129 @param State The state to set
131 @retval EFI_SUCCESS The host controller is now working at State
132 @retval Others Failed to set operation state
138 IN EFI_USB_HC_STATE State
143 if (UsbBus
->Usb2Hc
!= NULL
) {
144 Status
= UsbBus
->Usb2Hc
->SetState (UsbBus
->Usb2Hc
, State
);
146 Status
= UsbBus
->UsbHc
->SetState (UsbBus
->UsbHc
, State
);
154 Get the root hub port state
156 @param UsbBus The USB bus driver
157 @param PortIndex The index of port
158 @param PortStatus The variable to save port state
160 @retval EFI_SUCCESS The root port state is returned in
161 @retval Others Failed to get the root hub port state
165 UsbHcGetRootHubPortStatus (
168 OUT EFI_USB_PORT_STATUS
*PortStatus
173 if (UsbBus
->Usb2Hc
!= NULL
) {
174 Status
= UsbBus
->Usb2Hc
->GetRootHubPortStatus (UsbBus
->Usb2Hc
, PortIndex
, PortStatus
);
176 Status
= UsbBus
->UsbHc
->GetRootHubPortStatus (UsbBus
->UsbHc
, PortIndex
, PortStatus
);
184 Set the root hub port feature
186 @param UsbBus The USB bus driver
187 @param PortIndex The port index
188 @param Feature The port feature to set
190 @retval EFI_SUCCESS The port feature is set
191 @retval Others Failed to set port feature
195 UsbHcSetRootHubPortFeature (
198 IN EFI_USB_PORT_FEATURE Feature
204 if (UsbBus
->Usb2Hc
!= NULL
) {
205 Status
= UsbBus
->Usb2Hc
->SetRootHubPortFeature (UsbBus
->Usb2Hc
, PortIndex
, Feature
);
207 Status
= UsbBus
->UsbHc
->SetRootHubPortFeature (UsbBus
->UsbHc
, PortIndex
, Feature
);
215 Clear the root hub port feature
217 @param UsbBus The USB bus driver
218 @param PortIndex The port index
219 @param Feature The port feature to clear
221 @retval EFI_SUCCESS The port feature is clear
222 @retval Others Failed to clear port feature
226 UsbHcClearRootHubPortFeature (
229 IN EFI_USB_PORT_FEATURE Feature
234 if (UsbBus
->Usb2Hc
!= NULL
) {
235 Status
= UsbBus
->Usb2Hc
->ClearRootHubPortFeature (UsbBus
->Usb2Hc
, PortIndex
, Feature
);
237 Status
= UsbBus
->UsbHc
->ClearRootHubPortFeature (UsbBus
->UsbHc
, PortIndex
, Feature
);
245 Execute a control transfer to the device
247 @param UsbBus The USB bus driver
248 @param DevAddr The device address
249 @param DevSpeed The device speed
250 @param MaxPacket Maximum packet size of endpoint 0
251 @param Request The control transfer request
252 @param Direction The direction of data stage
253 @param Data The buffer holding data
254 @param DataLength The length of the data
255 @param TimeOut Timeout (in ms) to wait until timeout
256 @param Translator The transaction translator for low/full speed device
257 @param UsbResult The result of transfer
259 @retval EFI_SUCCESS The control transfer finished without error
260 @retval Others The control transfer failed, reason returned in UsbReslt
264 UsbHcControlTransfer (
269 IN EFI_USB_DEVICE_REQUEST
*Request
,
270 IN EFI_USB_DATA_DIRECTION Direction
,
272 IN OUT UINTN
*DataLength
,
274 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
275 OUT UINT32
*UsbResult
279 BOOLEAN IsSlowDevice
;
281 if (UsbBus
->Usb2Hc
!= NULL
) {
282 Status
= UsbBus
->Usb2Hc
->ControlTransfer (
297 IsSlowDevice
= (BOOLEAN
)(EFI_USB_SPEED_LOW
== DevSpeed
);
298 Status
= UsbBus
->UsbHc
->ControlTransfer (
317 Execute a bulk transfer to the device's endpoint
319 @param UsbBus The USB bus driver
320 @param DevAddr The target device address
321 @param EpAddr The target endpoint address, with direction encoded in
323 @param DevSpeed The device's speed
324 @param MaxPacket The endpoint's max packet size
325 @param BufferNum The number of data buffer
326 @param Data Array of pointers to data buffer
327 @param DataLength The length of data buffer
328 @param DataToggle On input, the initial data toggle to use, also return
329 the next toggle on output.
330 @param TimeOut The time to wait until timeout
331 @param Translator The transaction translator for low/full speed device
332 @param UsbResult The result of USB execution
334 @retval EFI_SUCCESS The bulk transfer is finished without error
335 @retval Others Failed to execute bulk transfer, result in UsbResult
346 IN OUT VOID
*Data
[EFI_USB_MAX_BULK_BUFFER_NUM
],
347 IN OUT UINTN
*DataLength
,
348 IN OUT UINT8
*DataToggle
,
350 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
351 OUT UINT32
*UsbResult
356 if (UsbBus
->Usb2Hc
!= NULL
) {
357 Status
= UsbBus
->Usb2Hc
->BulkTransfer (
372 Status
= UsbBus
->UsbHc
->BulkTransfer (
390 Queue or cancel an asynchronous interrupt transfer
392 @param UsbBus The USB bus driver
393 @param DevAddr The target device address
394 @param EpAddr The target endpoint address, with direction encoded in
396 @param DevSpeed The device's speed
397 @param MaxPacket The endpoint's max packet size
398 @param IsNewTransfer Whether this is a new request. If not, cancel the old
400 @param DataToggle Data toggle to use on input, next toggle on output
401 @param PollingInterval The interval to poll the interrupt transfer (in ms)
402 @param DataLength The length of periodical data receive
403 @param Translator The transaction translator for low/full speed device
404 @param Callback Function to call when data is received
405 @param Context The context to the callback
407 @retval EFI_SUCCESS The asynchronous transfer is queued
408 @retval Others Failed to queue the transfer
412 UsbHcAsyncInterruptTransfer (
418 IN BOOLEAN IsNewTransfer
,
419 IN OUT UINT8
*DataToggle
,
420 IN UINTN PollingInterval
,
422 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
423 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback
,
424 IN VOID
*Context OPTIONAL
428 BOOLEAN IsSlowDevice
;
430 if (UsbBus
->Usb2Hc
!= NULL
) {
431 Status
= UsbBus
->Usb2Hc
->AsyncInterruptTransfer (
446 IsSlowDevice
= (BOOLEAN
)(EFI_USB_SPEED_LOW
== DevSpeed
);
448 Status
= UsbBus
->UsbHc
->AsyncInterruptTransfer (
468 Execute a synchronous interrupt transfer to the target endpoint
470 @param UsbBus The USB bus driver
471 @param DevAddr The target device address
472 @param EpAddr The target endpoint address, with direction encoded in
474 @param DevSpeed The device's speed
475 @param MaxPacket The endpoint's max packet size
476 @param Data Pointer to data buffer
477 @param DataLength The length of data buffer
478 @param DataToggle On input, the initial data toggle to use, also return
479 the next toggle on output.
480 @param TimeOut The time to wait until timeout
481 @param Translator The transaction translator for low/full speed device
482 @param UsbResult The result of USB execution
484 @retval EFI_SUCCESS The synchronous interrupt transfer is OK
485 @retval Others Failed to execute the synchronous interrupt transfer
489 UsbHcSyncInterruptTransfer (
496 IN OUT UINTN
*DataLength
,
497 IN OUT UINT8
*DataToggle
,
499 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
500 OUT UINT32
*UsbResult
504 BOOLEAN IsSlowDevice
;
506 if (UsbBus
->Usb2Hc
!= NULL
) {
507 Status
= UsbBus
->Usb2Hc
->SyncInterruptTransfer (
521 IsSlowDevice
= (EFI_USB_SPEED_LOW
== DevSpeed
) ? TRUE
: FALSE
;
522 Status
= UsbBus
->UsbHc
->SyncInterruptTransfer (
541 Execute a synchronous Isochronous USB transfer
543 @param UsbBus The USB bus driver
544 @param DevAddr The target device address
545 @param EpAddr The target endpoint address, with direction encoded in
547 @param DevSpeed The device's speed
548 @param MaxPacket The endpoint's max packet size
549 @param BufferNum The number of data buffer
550 @param Data Array of pointers to data buffer
551 @param DataLength The length of data buffer
552 @param Translator The transaction translator for low/full speed device
553 @param UsbResult The result of USB execution
555 @retval EFI_UNSUPPORTED The isochronous transfer isn't supported now
559 UsbHcIsochronousTransfer (
566 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
568 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
569 OUT UINT32
*UsbResult
572 return EFI_UNSUPPORTED
;
577 Queue an asynchronous isochronous transfer
579 @param UsbBus The USB bus driver
580 @param DevAddr The target device address
581 @param EpAddr The target endpoint address, with direction encoded in
583 @param DevSpeed The device's speed
584 @param MaxPacket The endpoint's max packet size
585 @param BufferNum The number of data buffer
586 @param Data Array of pointers to data buffer
587 @param DataLength The length of data buffer
588 @param Translator The transaction translator for low/full speed device
589 @param Callback The function to call when data is transferred
590 @param Context The context to the callback function
592 @retval EFI_UNSUPPORTED The asynchronous isochronous transfer isn't supported
596 UsbHcAsyncIsochronousTransfer (
603 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
605 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
606 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback
,
610 return EFI_UNSUPPORTED
;
615 Open the USB host controller protocol BY_CHILD
617 @param Bus The USB bus driver
618 @param Child The child handle
620 @return The open protocol return
624 UsbOpenHostProtoByChild (
629 EFI_USB_HC_PROTOCOL
*UsbHc
;
630 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
633 if (Bus
->Usb2Hc
!= NULL
) {
634 Status
= gBS
->OpenProtocol (
636 &gEfiUsb2HcProtocolGuid
,
638 mUsbBusDriverBinding
.DriverBindingHandle
,
640 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
644 Status
= gBS
->OpenProtocol (
646 &gEfiUsbHcProtocolGuid
,
648 mUsbBusDriverBinding
.DriverBindingHandle
,
650 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
659 Close the USB host controller protocol BY_CHILD
661 @param Bus The USB bus driver
662 @param Child The child handle
668 UsbCloseHostProtoByChild (
673 if (Bus
->Usb2Hc
!= NULL
) {
676 &gEfiUsb2HcProtocolGuid
,
677 mUsbBusDriverBinding
.DriverBindingHandle
,
684 &gEfiUsbHcProtocolGuid
,
685 mUsbBusDriverBinding
.DriverBindingHandle
,
694 return the current TPL, copied from the EDKII glue lib.
708 Tpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
709 gBS
->RestoreTPL (Tpl
);
725 USB's debug output function.
729 Format - The format parameters to the print
730 ... - The variable length parameters after format
740 VA_START (Marker
, Format
);
741 DebugVPrint (DEBUG_INFO
, Format
, Marker
);
748 USB's error output function.
750 @param Format The format parameters to the print
751 @param ... The variable length parameters after format
764 VA_START (Marker
, Format
);
765 DebugVPrint (DEBUG_ERROR
, Format
, Marker
);