3 Usb Bus Driver Binding and Bus IO Protocol.
5 Copyright (c) 2004 - 2007, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_USB_BUS_H_
17 #define _EFI_USB_BUS_H_
22 #include <Protocol/Usb2HostController.h>
23 #include <Protocol/UsbHostController.h>
24 #include <Protocol/UsbIo.h>
25 #include <Protocol/DevicePath.h>
27 #include <Library/BaseLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/MemoryAllocationLib.h>
37 #include <IndustryStandard/Usb.h>
39 typedef struct _USB_DEVICE USB_DEVICE
;
40 typedef struct _USB_INTERFACE USB_INTERFACE
;
41 typedef struct _USB_BUS USB_BUS
;
42 typedef struct _USB_HUB_API USB_HUB_API
;
45 #include "UsbUtility.h"
48 #include "UsbEnumer.h"
52 USB_MAX_INTERFACE
= 16,
53 USB_MAX_DEVICES
= 128,
55 USB_BUS_1_MILLISECOND
= 1000,
58 // Roothub and hub's polling interval, set by experience,
59 // The unit of roothub is 100us, means 1s as interval, and
60 // the unit of hub is 1ms, means 64ms as interval.
62 USB_ROOTHUB_POLL_INTERVAL
= 1000 * 10000U,
63 USB_HUB_POLL_INTERVAL
= 64,
66 // Wait for port stable to work, refers to specification
69 USB_WAIT_PORT_STABLE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
72 // Wait for port statue reg change, set by experience
74 USB_WAIT_PORT_STS_CHANGE_STALL
= 5 * USB_BUS_1_MILLISECOND
,
77 // Wait for set device address, refers to specification
78 // [USB20-9.2.6.3, it says 2ms]
80 USB_SET_DEVICE_ADDRESS_STALL
= 20 * USB_BUS_1_MILLISECOND
,
83 // Wait for retry max packet size, set by experience
85 USB_RETRY_MAX_PACK_SIZE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
88 // Wait for hub port power-on, refers to specification
91 USB_SET_PORT_POWER_STALL
= 2 * USB_BUS_1_MILLISECOND
,
94 // Wait for port reset, refers to specification
95 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for
98 USB_SET_PORT_RESET_STALL
= 20 * USB_BUS_1_MILLISECOND
,
99 USB_SET_ROOT_PORT_RESET_STALL
= 50 * USB_BUS_1_MILLISECOND
,
102 // Wait for clear roothub port reset, set by experience
104 USB_CLR_ROOT_PORT_RESET_STALL
= 1 * USB_BUS_1_MILLISECOND
,
107 // Wait for set roothub port enable, set by experience
109 USB_SET_ROOT_PORT_ENABLE_STALL
= 20 * USB_BUS_1_MILLISECOND
,
112 // Send general device request timeout, refers to
113 // specification[USB20-11.24.1]
115 USB_GENERAL_DEVICE_REQUEST_TIMEOUT
= 50 * USB_BUS_1_MILLISECOND
,
118 // Send clear feature request timeout, set by experience
120 USB_CLEAR_FEATURE_REQUEST_TIMEOUT
= 10 * USB_BUS_1_MILLISECOND
121 }USB_BUS_TIMEOUT_EXPERIENCE_VALUE
;
124 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
125 // to protect shared data structures.
127 #define USB_BUS_TPL TPL_NOTIFY
129 #define USB_INTERFACE_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'I')
130 #define USB_BUS_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')
132 #define USB_BIT(a) ((UINTN)(1 << (a)))
133 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
135 #define EFI_USB_BUS_PROTOCOL_GUID \
136 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
138 #define USB_INTERFACE_FROM_USBIO(a) \
139 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
141 #define USB_BUS_FROM_THIS(a) \
142 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
145 // Used to locate USB_BUS
147 typedef struct _EFI_USB_BUS_PROTOCOL
{
149 } EFI_USB_BUS_PROTOCOL
;
153 // Stands for the real USB device. Each device may
154 // has several seperately working interfaces.
160 // Configuration information
167 // The device's descriptors and its configuration
169 USB_DEVICE_DESC
*DevDesc
;
170 USB_CONFIG_DESC
*ActiveConfig
;
172 UINT16 LangId
[USB_MAX_LANG_ID
];
175 UINT8 NumOfInterface
;
176 USB_INTERFACE
*Interfaces
[USB_MAX_INTERFACE
];
179 // Parent child relationship
181 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator
;
184 USB_INTERFACE
*ParentIf
;
185 UINT8 ParentPort
; // Start at 0
189 // Stands for different functions of USB device
191 struct _USB_INTERFACE
{
194 USB_INTERFACE_DESC
*IfDesc
;
195 USB_INTERFACE_SETTING
*IfSetting
;
198 // Handles and protocols
201 EFI_USB_IO_PROTOCOL UsbIo
;
202 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
206 // Hub device special data
214 // Data used only by normal hub devices
216 USB_ENDPOINT_DESC
*HubEp
;
220 // Data used only by root hub to hand over device to
221 // companion UHCI driver if low/full speed devices are
222 // connected to EHCI.
228 // Stands for the current USB Bus
232 EFI_USB_BUS_PROTOCOL BusId
;
235 // Managed USB host controller
237 EFI_HANDLE HostHandle
;
238 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
239 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
240 EFI_USB_HC_PROTOCOL
*UsbHc
;
243 // An array of device that is on the bus. Devices[0] is
244 // for root hub. Device with address i is at Devices[i].
246 USB_DEVICE
*Devices
[USB_MAX_DEVICES
];
249 // USB Bus driver need to control the recursive connect policy of the bus, only those wanted
250 // usb child device will be recursively connected.
252 // WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,
253 // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is
254 // DEVICE_PATH_LIST_ITEM
256 LIST_ENTRY WantedUsbIoDPList
;
265 USB_HUB_GET_PORT_STATUS GetPortStatus
;
266 USB_HUB_CLEAR_PORT_CHANGE ClearPortChange
;
267 USB_HUB_SET_PORT_FEATURE SetPortFeature
;
268 USB_HUB_CLEAR_PORT_FEATURE ClearPortFeature
;
269 USB_HUB_RESET_PORT ResetPort
;
270 USB_HUB_RELEASE Release
;
273 #define USB_US_LAND_ID 0x0409
275 #define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')
276 typedef struct _DEVICE_PATH_LIST_ITEM
{
279 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
280 } DEVICE_PATH_LIST_ITEM
;
283 USB_CLASS_DEVICE_PATH UsbClass
;
284 EFI_DEVICE_PATH_PROTOCOL End
;
285 } USB_CLASS_FORMAT_DEVICE_PATH
;
288 Free a DEVICE_PATH_LIST_ITEM list.
290 @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer.
292 @retval EFI_INVALID_PARAMETER If parameters are invalid, return this value.
293 @retval EFI_SUCCESS If free operation is successful, return this value.
298 UsbBusFreeUsbDPList (
299 IN LIST_ENTRY
*UsbIoDPList
303 Store a wanted usb child device info (its Usb part of device path) which is indicated by
304 RemainingDevicePath in a Usb bus which is indicated by UsbBusId.
306 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
307 @param RemainingDevicePath The remaining device patch.
309 @retval EFI_SUCCESS Add operation is successful.
310 @retval EFI_INVALID_PARAMETER The parameters are invalid.
315 UsbBusAddWantedUsbIoDP (
316 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
,
317 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
321 Check whether a usb child device is the wanted device in a bus.
323 @param Bus The Usb bus's private data pointer.
324 @param UsbIf The usb child device inferface.
326 @retval True If a usb child device is the wanted device in a bus.
327 @retval False If a usb child device is *NOT* the wanted device in a bus.
332 UsbBusIsWantedUsbIO (
334 IN USB_INTERFACE
*UsbIf
338 Recursively connnect every wanted usb child device to ensure they all fully connected.
339 Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device.
341 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
343 @retval EFI_SUCCESS Connect is done successfully.
344 @retval EFI_INVALID_PARAMETER The parameter is invalid.
349 UsbBusRecursivelyConnectWantedUsbIo (
350 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
354 USB_IO function to execute a control transfer. This
355 function will execute the USB transfer. If transfer
356 successes, it will sync the internal state of USB bus
359 @param This The USB_IO instance
360 @param Request The control transfer request
361 @param Direction Direction for data stage
362 @param Timeout The time to wait before timeout
363 @param Data The buffer holding the data
364 @param DataLength Then length of the data
365 @param UsbStatus USB result
367 @retval EFI_INVALID_PARAMETER The parameters are invalid
368 @retval EFI_SUCCESS The control transfer succeded.
369 @retval Others Failed to execute the transfer
374 UsbIoControlTransfer (
375 IN EFI_USB_IO_PROTOCOL
*This
,
376 IN EFI_USB_DEVICE_REQUEST
*Request
,
377 IN EFI_USB_DATA_DIRECTION Direction
,
379 IN OUT VOID
*Data
, OPTIONAL
380 IN UINTN DataLength
, OPTIONAL
381 OUT UINT32
*UsbStatus
385 Execute a bulk transfer to the device endpoint.
387 @param This The USB IO instance.
388 @param Endpoint The device endpoint.
389 @param Data The data to transfer.
390 @param DataLength The length of the data to transfer.
391 @param Timeout Time to wait before timeout.
392 @param UsbStatus The result of USB transfer.
394 @retval EFI_SUCCESS The bulk transfer is OK.
395 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
396 @retval Others Failed to execute transfer, reason returned in
403 IN EFI_USB_IO_PROTOCOL
*This
,
406 IN OUT UINTN
*DataLength
,
408 OUT UINT32
*UsbStatus
412 Execute a synchronous interrupt transfer.
414 @param This The USB IO instance.
415 @param Endpoint The device endpoint.
416 @param Data The data to transfer.
417 @param DataLength The length of the data to transfer.
418 @param Timeout Time to wait before timeout.
419 @param UsbStatus The result of USB transfer.
421 @retval EFI_SUCCESS The synchronous interrupt transfer is OK.
422 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
423 @retval Others Failed to execute transfer, reason returned in
429 UsbIoSyncInterruptTransfer (
430 IN EFI_USB_IO_PROTOCOL
*This
,
433 IN OUT UINTN
*DataLength
,
435 OUT UINT32
*UsbStatus
439 Queue a new asynchronous interrupt transfer, or remove the old
440 request if (IsNewTransfer == FALSE).
442 @param This The USB_IO instance.
443 @param Endpoint The device endpoint.
444 @param IsNewTransfer Whether this is a new request, if it's old, remove
446 @param PollInterval The interval to poll the transfer result, (in ms).
447 @param DataLength The length of perodic data transfer.
448 @param Callback The function to call periodicaly when transfer is
450 @param Context The context to the callback.
452 @retval EFI_SUCCESS New transfer is queued or old request is removed.
453 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
454 @retval Others Failed to queue the new request or remove the old
460 UsbIoAsyncInterruptTransfer (
461 IN EFI_USB_IO_PROTOCOL
*This
,
463 IN BOOLEAN IsNewTransfer
,
464 IN UINTN PollInterval
, OPTIONAL
465 IN UINTN DataLength
, OPTIONAL
466 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback
, OPTIONAL
467 IN VOID
*Context OPTIONAL
471 Execute a synchronous isochronous transfer.
473 @param This The USB IO instance.
474 @param DeviceEndpoint The device endpoint.
475 @param Data The data to transfer.
476 @param DataLength The length of the data to transfer.
477 @param UsbStatus The result of USB transfer.
479 @retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
484 UsbIoIsochronousTransfer (
485 IN EFI_USB_IO_PROTOCOL
*This
,
486 IN UINT8 DeviceEndpoint
,
493 Queue an asynchronous isochronous transfer.
495 @param This The USB_IO instance.
496 @param DeviceEndpoint The device endpoint.
497 @param Data The data to transfer.
498 @param DataLength The length of perodic data transfer.
499 @param IsochronousCallBack The function to call periodicaly when transfer is
501 @param Context The context to the callback.
503 @retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
508 UsbIoAsyncIsochronousTransfer (
509 IN EFI_USB_IO_PROTOCOL
*This
,
510 IN UINT8 DeviceEndpoint
,
513 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
514 IN VOID
*Context OPTIONAL
518 Retrieve the device descriptor of the device.
520 @param This The USB IO instance.
521 @param Descriptor The variable to receive the device descriptor.
523 @retval EFI_SUCCESS The device descriptor is returned.
524 @retval EFI_INVALID_PARAMETER The parameter is invalid.
529 UsbIoGetDeviceDescriptor (
530 IN EFI_USB_IO_PROTOCOL
*This
,
531 OUT EFI_USB_DEVICE_DESCRIPTOR
*Descriptor
535 Return the configuration descriptor of the current active configuration.
537 @param This The USB IO instance.
538 @param Descriptor The USB configuration descriptor.
540 @retval EFI_SUCCESS The active configuration descriptor is returned.
541 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
542 @retval EFI_NOT_FOUND Currently no active configuration is selected.
547 UsbIoGetActiveConfigDescriptor (
548 IN EFI_USB_IO_PROTOCOL
*This
,
549 OUT EFI_USB_CONFIG_DESCRIPTOR
*Descriptor
553 Retrieve the active interface setting descriptor for this USB IO instance.
555 @param This The USB IO instance.
556 @param Descriptor The variable to receive active interface setting.
558 @retval EFI_SUCCESS The active interface setting is returned.
559 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
564 UsbIoGetInterfaceDescriptor (
565 IN EFI_USB_IO_PROTOCOL
*This
,
566 OUT EFI_USB_INTERFACE_DESCRIPTOR
*Descriptor
570 Retrieve the endpoint descriptor from this interface setting.
572 @param This The USB IO instance.
573 @param Index The index (start from zero) of the endpoint to
575 @param Descriptor The variable to receive the descriptor.
577 @retval EFI_SUCCESS The endpoint descriptor is returned.
578 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
583 UsbIoGetEndpointDescriptor (
584 IN EFI_USB_IO_PROTOCOL
*This
,
586 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*Descriptor
590 Retrieve the supported language ID table from the device.
592 @param This The USB IO instance.
593 @param LangIDTable The table to return the language IDs.
594 @param TableSize The number of supported languanges.
596 @retval EFI_SUCCESS The language ID is return.
601 UsbIoGetSupportedLanguages (
602 IN EFI_USB_IO_PROTOCOL
*This
,
603 OUT UINT16
**LangIDTable
,
604 OUT UINT16
*TableSize
608 Retrieve an indexed string in the language of LangID.
610 @param This The USB IO instance.
611 @param LangID The language ID of the string to retrieve.
612 @param StringIndex The index of the string.
613 @param String The variable to receive the string.
615 @retval EFI_SUCCESS The string is returned.
616 @retval EFI_NOT_FOUND No such string existed.
621 UsbIoGetStringDescriptor (
622 IN EFI_USB_IO_PROTOCOL
*This
,
624 IN UINT8 StringIndex
,
629 Reset the device, then if that succeeds, reconfigure the
630 device with its address and current active configuration.
632 @param This The USB IO instance.
634 @retval EFI_SUCCESS The device is reset and configured.
635 @retval Others Failed to reset the device.
641 IN EFI_USB_IO_PROTOCOL
*This
645 Install Usb Bus Protocol on host controller, and start the Usb bus.
647 @param This The USB bus driver binding instance.
648 @param Controller The controller to check.
649 @param RemainingDevicePath The remaining device patch.
651 @retval EFI_SUCCESS The controller is controlled by the usb bus.
652 @retval EFI_ALREADY_STARTED The controller is already controlled by the usb bus.
653 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
658 UsbBusBuildProtocol (
659 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
660 IN EFI_HANDLE Controller
,
661 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
665 The USB bus driver entry pointer.
667 @param ImageHandle The driver image handle.
668 @param SystemTable The system table.
670 @return EFI_SUCCESS The component name protocol is installed.
671 @return Others Failed to init the usb driver.
676 UsbBusDriverEntryPoint (
677 IN EFI_HANDLE ImageHandle
,
678 IN EFI_SYSTEM_TABLE
*SystemTable
682 Check whether USB bus driver support this device.
684 @param This The USB bus driver binding protocol.
685 @param Controller The controller handle to check.
686 @param RemainingDevicePath The remaining device path.
688 @retval EFI_SUCCESS The bus supports this controller.
689 @retval EFI_UNSUPPORTED This device isn't supported.
694 UsbBusControllerDriverSupported (
695 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
696 IN EFI_HANDLE Controller
,
697 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
701 Start to process the controller.
703 @param This The USB bus driver binding instance.
704 @param Controller The controller to check.
705 @param RemainingDevicePath The remaining device patch.
707 @retval EFI_SUCCESS The controller is controlled by the usb bus.
708 @retval EFI_ALREADY_STARTED The controller is already controlled by the usb
710 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
715 UsbBusControllerDriverStart (
716 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
717 IN EFI_HANDLE Controller
,
718 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
722 Stop handle the controller by this USB bus driver.
724 @param This The USB bus driver binding protocol.
725 @param Controller The controller to release.
726 @param NumberOfChildren The child of USB bus that opened controller
728 @param ChildHandleBuffer The array of child handle.
730 @retval EFI_SUCCESS The controller or children are stopped.
731 @retval EFI_DEVICE_ERROR Failed to stop the driver.
736 UsbBusControllerDriverStop (
737 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
738 IN EFI_HANDLE Controller
,
739 IN UINTN NumberOfChildren
,
740 IN EFI_HANDLE
*ChildHandleBuffer
743 extern EFI_USB_IO_PROTOCOL mUsbIoProtocol
;
744 extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding
;
745 extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName
;
746 extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2
;