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
= 20 * 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.
114 // The USB Specification 2.0, section 11.24.1 recommends a value of
115 // 50 milliseconds. We use a value of 100 milliseconds to work
116 // around slower hubs and devices.
118 USB_GENERAL_DEVICE_REQUEST_TIMEOUT
= 100,
121 // Send clear feature request timeout, set by experience
123 USB_CLEAR_FEATURE_REQUEST_TIMEOUT
= 10
124 }USB_BUS_TIMEOUT_EXPERIENCE_VALUE
;
127 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
128 // to protect shared data structures.
130 #define USB_BUS_TPL TPL_NOTIFY
132 #define USB_INTERFACE_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'I')
133 #define USB_BUS_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'B')
135 #define USB_BIT(a) ((UINTN)(1 << (a)))
136 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
138 #define EFI_USB_BUS_PROTOCOL_GUID \
139 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
141 #define USB_INTERFACE_FROM_USBIO(a) \
142 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
144 #define USB_BUS_FROM_THIS(a) \
145 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
148 // Used to locate USB_BUS
150 typedef struct _EFI_USB_BUS_PROTOCOL
{
152 } EFI_USB_BUS_PROTOCOL
;
156 // Stands for the real USB device. Each device may
157 // has several seperately working interfaces.
163 // Configuration information
170 // The device's descriptors and its configuration
172 USB_DEVICE_DESC
*DevDesc
;
173 USB_CONFIG_DESC
*ActiveConfig
;
175 UINT16 LangId
[USB_MAX_LANG_ID
];
178 UINT8 NumOfInterface
;
179 USB_INTERFACE
*Interfaces
[USB_MAX_INTERFACE
];
182 // Parent child relationship
184 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator
;
187 USB_INTERFACE
*ParentIf
;
188 UINT8 ParentPort
; // Start at 0
192 // Stands for different functions of USB device
194 struct _USB_INTERFACE
{
197 USB_INTERFACE_DESC
*IfDesc
;
198 USB_INTERFACE_SETTING
*IfSetting
;
201 // Handles and protocols
204 EFI_USB_IO_PROTOCOL UsbIo
;
205 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
209 // Hub device special data
217 // Data used only by normal hub devices
219 USB_ENDPOINT_DESC
*HubEp
;
223 // Data used only by root hub to hand over device to
224 // companion UHCI driver if low/full speed devices are
225 // connected to EHCI.
231 // Stands for the current USB Bus
235 EFI_USB_BUS_PROTOCOL BusId
;
238 // Managed USB host controller
240 EFI_HANDLE HostHandle
;
241 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
242 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
243 EFI_USB_HC_PROTOCOL
*UsbHc
;
246 // An array of device that is on the bus. Devices[0] is
247 // for root hub. Device with address i is at Devices[i].
249 USB_DEVICE
*Devices
[USB_MAX_DEVICES
];
252 // USB Bus driver need to control the recursive connect policy of the bus, only those wanted
253 // usb child device will be recursively connected.
255 // WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,
256 // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is
257 // DEVICE_PATH_LIST_ITEM
259 LIST_ENTRY WantedUsbIoDPList
;
268 USB_HUB_GET_PORT_STATUS GetPortStatus
;
269 USB_HUB_CLEAR_PORT_CHANGE ClearPortChange
;
270 USB_HUB_SET_PORT_FEATURE SetPortFeature
;
271 USB_HUB_CLEAR_PORT_FEATURE ClearPortFeature
;
272 USB_HUB_RESET_PORT ResetPort
;
273 USB_HUB_RELEASE Release
;
276 #define USB_US_LAND_ID 0x0409
278 #define DEVICE_PATH_LIST_ITEM_SIGNATURE SIGNATURE_32('d','p','l','i')
279 typedef struct _DEVICE_PATH_LIST_ITEM
{
282 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
283 } DEVICE_PATH_LIST_ITEM
;
286 USB_CLASS_DEVICE_PATH UsbClass
;
287 EFI_DEVICE_PATH_PROTOCOL End
;
288 } USB_CLASS_FORMAT_DEVICE_PATH
;
291 Free a DEVICE_PATH_LIST_ITEM list.
293 @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer.
295 @retval EFI_INVALID_PARAMETER If parameters are invalid, return this value.
296 @retval EFI_SUCCESS If free operation is successful, return this value.
301 UsbBusFreeUsbDPList (
302 IN LIST_ENTRY
*UsbIoDPList
306 Store a wanted usb child device info (its Usb part of device path) which is indicated by
307 RemainingDevicePath in a Usb bus which is indicated by UsbBusId.
309 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
310 @param RemainingDevicePath The remaining device patch.
312 @retval EFI_SUCCESS Add operation is successful.
313 @retval EFI_INVALID_PARAMETER The parameters are invalid.
318 UsbBusAddWantedUsbIoDP (
319 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
,
320 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
324 Check whether a usb child device is the wanted device in a bus.
326 @param Bus The Usb bus's private data pointer.
327 @param UsbIf The usb child device inferface.
329 @retval True If a usb child device is the wanted device in a bus.
330 @retval False If a usb child device is *NOT* the wanted device in a bus.
335 UsbBusIsWantedUsbIO (
337 IN USB_INTERFACE
*UsbIf
341 Recursively connnect every wanted usb child device to ensure they all fully connected.
342 Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device.
344 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
346 @retval EFI_SUCCESS Connect is done successfully.
347 @retval EFI_INVALID_PARAMETER The parameter is invalid.
352 UsbBusRecursivelyConnectWantedUsbIo (
353 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
357 USB_IO function to execute a control transfer. This
358 function will execute the USB transfer. If transfer
359 successes, it will sync the internal state of USB bus
362 @param This The USB_IO instance
363 @param Request The control transfer request
364 @param Direction Direction for data stage
365 @param Timeout The time to wait before timeout
366 @param Data The buffer holding the data
367 @param DataLength Then length of the data
368 @param UsbStatus USB result
370 @retval EFI_INVALID_PARAMETER The parameters are invalid
371 @retval EFI_SUCCESS The control transfer succeded.
372 @retval Others Failed to execute the transfer
377 UsbIoControlTransfer (
378 IN EFI_USB_IO_PROTOCOL
*This
,
379 IN EFI_USB_DEVICE_REQUEST
*Request
,
380 IN EFI_USB_DATA_DIRECTION Direction
,
382 IN OUT VOID
*Data
, OPTIONAL
383 IN UINTN DataLength
, OPTIONAL
384 OUT UINT32
*UsbStatus
388 Execute a bulk transfer to the device endpoint.
390 @param This The USB IO instance.
391 @param Endpoint The device endpoint.
392 @param Data The data to transfer.
393 @param DataLength The length of the data to transfer.
394 @param Timeout Time to wait before timeout.
395 @param UsbStatus The result of USB transfer.
397 @retval EFI_SUCCESS The bulk transfer is OK.
398 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
399 @retval Others Failed to execute transfer, reason returned in
406 IN EFI_USB_IO_PROTOCOL
*This
,
409 IN OUT UINTN
*DataLength
,
411 OUT UINT32
*UsbStatus
415 Execute a synchronous interrupt transfer.
417 @param This The USB IO instance.
418 @param Endpoint The device endpoint.
419 @param Data The data to transfer.
420 @param DataLength The length of the data to transfer.
421 @param Timeout Time to wait before timeout.
422 @param UsbStatus The result of USB transfer.
424 @retval EFI_SUCCESS The synchronous interrupt transfer is OK.
425 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
426 @retval Others Failed to execute transfer, reason returned in
432 UsbIoSyncInterruptTransfer (
433 IN EFI_USB_IO_PROTOCOL
*This
,
436 IN OUT UINTN
*DataLength
,
438 OUT UINT32
*UsbStatus
442 Queue a new asynchronous interrupt transfer, or remove the old
443 request if (IsNewTransfer == FALSE).
445 @param This The USB_IO instance.
446 @param Endpoint The device endpoint.
447 @param IsNewTransfer Whether this is a new request, if it's old, remove
449 @param PollInterval The interval to poll the transfer result, (in ms).
450 @param DataLength The length of perodic data transfer.
451 @param Callback The function to call periodicaly when transfer is
453 @param Context The context to the callback.
455 @retval EFI_SUCCESS New transfer is queued or old request is removed.
456 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
457 @retval Others Failed to queue the new request or remove the old
463 UsbIoAsyncInterruptTransfer (
464 IN EFI_USB_IO_PROTOCOL
*This
,
466 IN BOOLEAN IsNewTransfer
,
467 IN UINTN PollInterval
, OPTIONAL
468 IN UINTN DataLength
, OPTIONAL
469 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback
, OPTIONAL
470 IN VOID
*Context OPTIONAL
474 Execute a synchronous isochronous transfer.
476 @param This The USB IO instance.
477 @param DeviceEndpoint The device endpoint.
478 @param Data The data to transfer.
479 @param DataLength The length of the data to transfer.
480 @param UsbStatus The result of USB transfer.
482 @retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
487 UsbIoIsochronousTransfer (
488 IN EFI_USB_IO_PROTOCOL
*This
,
489 IN UINT8 DeviceEndpoint
,
496 Queue an asynchronous isochronous transfer.
498 @param This The USB_IO instance.
499 @param DeviceEndpoint The device endpoint.
500 @param Data The data to transfer.
501 @param DataLength The length of perodic data transfer.
502 @param IsochronousCallBack The function to call periodicaly when transfer is
504 @param Context The context to the callback.
506 @retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
511 UsbIoAsyncIsochronousTransfer (
512 IN EFI_USB_IO_PROTOCOL
*This
,
513 IN UINT8 DeviceEndpoint
,
516 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
517 IN VOID
*Context OPTIONAL
521 Retrieve the device descriptor of the device.
523 @param This The USB IO instance.
524 @param Descriptor The variable to receive the device descriptor.
526 @retval EFI_SUCCESS The device descriptor is returned.
527 @retval EFI_INVALID_PARAMETER The parameter is invalid.
532 UsbIoGetDeviceDescriptor (
533 IN EFI_USB_IO_PROTOCOL
*This
,
534 OUT EFI_USB_DEVICE_DESCRIPTOR
*Descriptor
538 Return the configuration descriptor of the current active configuration.
540 @param This The USB IO instance.
541 @param Descriptor The USB configuration descriptor.
543 @retval EFI_SUCCESS The active configuration descriptor is returned.
544 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
545 @retval EFI_NOT_FOUND Currently no active configuration is selected.
550 UsbIoGetActiveConfigDescriptor (
551 IN EFI_USB_IO_PROTOCOL
*This
,
552 OUT EFI_USB_CONFIG_DESCRIPTOR
*Descriptor
556 Retrieve the active interface setting descriptor for this USB IO instance.
558 @param This The USB IO instance.
559 @param Descriptor The variable to receive active interface setting.
561 @retval EFI_SUCCESS The active interface setting is returned.
562 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
567 UsbIoGetInterfaceDescriptor (
568 IN EFI_USB_IO_PROTOCOL
*This
,
569 OUT EFI_USB_INTERFACE_DESCRIPTOR
*Descriptor
573 Retrieve the endpoint descriptor from this interface setting.
575 @param This The USB IO instance.
576 @param Index The index (start from zero) of the endpoint to
578 @param Descriptor The variable to receive the descriptor.
580 @retval EFI_SUCCESS The endpoint descriptor is returned.
581 @retval EFI_INVALID_PARAMETER Some parameter is invalid.
586 UsbIoGetEndpointDescriptor (
587 IN EFI_USB_IO_PROTOCOL
*This
,
589 OUT EFI_USB_ENDPOINT_DESCRIPTOR
*Descriptor
593 Retrieve the supported language ID table from the device.
595 @param This The USB IO instance.
596 @param LangIDTable The table to return the language IDs.
597 @param TableSize The number of supported languanges.
599 @retval EFI_SUCCESS The language ID is return.
604 UsbIoGetSupportedLanguages (
605 IN EFI_USB_IO_PROTOCOL
*This
,
606 OUT UINT16
**LangIDTable
,
607 OUT UINT16
*TableSize
611 Retrieve an indexed string in the language of LangID.
613 @param This The USB IO instance.
614 @param LangID The language ID of the string to retrieve.
615 @param StringIndex The index of the string.
616 @param String The variable to receive the string.
618 @retval EFI_SUCCESS The string is returned.
619 @retval EFI_NOT_FOUND No such string existed.
624 UsbIoGetStringDescriptor (
625 IN EFI_USB_IO_PROTOCOL
*This
,
627 IN UINT8 StringIndex
,
632 Reset the device, then if that succeeds, reconfigure the
633 device with its address and current active configuration.
635 @param This The USB IO instance.
637 @retval EFI_SUCCESS The device is reset and configured.
638 @retval Others Failed to reset the device.
644 IN EFI_USB_IO_PROTOCOL
*This
648 Install Usb Bus Protocol on host controller, and start the Usb bus.
650 @param This The USB bus driver binding instance.
651 @param Controller The controller to check.
652 @param RemainingDevicePath The remaining device patch.
654 @retval EFI_SUCCESS The controller is controlled by the usb bus.
655 @retval EFI_ALREADY_STARTED The controller is already controlled by the usb bus.
656 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
661 UsbBusBuildProtocol (
662 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
663 IN EFI_HANDLE Controller
,
664 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
668 The USB bus driver entry pointer.
670 @param ImageHandle The driver image handle.
671 @param SystemTable The system table.
673 @return EFI_SUCCESS The component name protocol is installed.
674 @return Others Failed to init the usb driver.
679 UsbBusDriverEntryPoint (
680 IN EFI_HANDLE ImageHandle
,
681 IN EFI_SYSTEM_TABLE
*SystemTable
685 Check whether USB bus driver support this device.
687 @param This The USB bus driver binding protocol.
688 @param Controller The controller handle to check.
689 @param RemainingDevicePath The remaining device path.
691 @retval EFI_SUCCESS The bus supports this controller.
692 @retval EFI_UNSUPPORTED This device isn't supported.
697 UsbBusControllerDriverSupported (
698 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
699 IN EFI_HANDLE Controller
,
700 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
704 Start to process the controller.
706 @param This The USB bus driver binding instance.
707 @param Controller The controller to check.
708 @param RemainingDevicePath The remaining device patch.
710 @retval EFI_SUCCESS The controller is controlled by the usb bus.
711 @retval EFI_ALREADY_STARTED The controller is already controlled by the usb
713 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
718 UsbBusControllerDriverStart (
719 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
720 IN EFI_HANDLE Controller
,
721 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
725 Stop handle the controller by this USB bus driver.
727 @param This The USB bus driver binding protocol.
728 @param Controller The controller to release.
729 @param NumberOfChildren The child of USB bus that opened controller
731 @param ChildHandleBuffer The array of child handle.
733 @retval EFI_SUCCESS The controller or children are stopped.
734 @retval EFI_DEVICE_ERROR Failed to stop the driver.
739 UsbBusControllerDriverStop (
740 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
741 IN EFI_HANDLE Controller
,
742 IN UINTN NumberOfChildren
,
743 IN EFI_HANDLE
*ChildHandleBuffer
746 extern EFI_USB_IO_PROTOCOL mUsbIoProtocol
;
747 extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding
;
748 extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName
;
749 extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2
;