2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Usb Bus Driver Binding and Bus IO Protocol
24 #ifndef _EFI_USB_BUS_H_
25 #define _EFI_USB_BUS_H_
30 #include <Protocol/Usb2HostController.h>
31 #include <Protocol/UsbHostController.h>
32 #include <Protocol/UsbIo.h>
33 #include <Protocol/DevicePath.h>
35 #include <library/BaseLib.h>
36 #include <Library/DebugLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/UefiLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/MemoryAllocationLib.h>
45 #include <IndustryStandard/Usb.h>
47 typedef struct _USB_DEVICE USB_DEVICE
;
48 typedef struct _USB_INTERFACE USB_INTERFACE
;
49 typedef struct _USB_BUS USB_BUS
;
50 typedef struct _USB_HUB_API USB_HUB_API
;
53 #include "UsbUtility.h"
56 #include "UsbEnumer.h"
60 USB_MAX_INTERFACE
= 16,
61 USB_MAX_DEVICES
= 128,
63 USB_BUS_1_MILLISECOND
= 1000,
66 // Roothub and hub's polling interval, set by experience,
67 // The unit of roothub is 100us, means 1s as interval, and
68 // the unit of hub is 1ms, means 64ms as interval.
70 USB_ROOTHUB_POLL_INTERVAL
= 1000 * 10000U,
71 USB_HUB_POLL_INTERVAL
= 64,
74 // Wait for port stable to work, refers to specification
77 USB_WAIT_PORT_STABLE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
80 // Wait for port statue reg change, set by experience
82 USB_WAIT_PORT_STS_CHANGE_STALL
= 5 * USB_BUS_1_MILLISECOND
,
85 // Wait for set device address, refers to specification
86 // [USB20-9.2.6.3, it says 2ms]
88 USB_SET_DEVICE_ADDRESS_STALL
= 20 * USB_BUS_1_MILLISECOND
,
91 // Wait for retry max packet size, set by experience
93 USB_RETRY_MAX_PACK_SIZE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
96 // Wait for hub port power-on, refers to specification
99 USB_SET_PORT_POWER_STALL
= 2 * USB_BUS_1_MILLISECOND
,
102 // Wait for port reset, refers to specification
103 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for
106 USB_SET_PORT_RESET_STALL
= 20 * USB_BUS_1_MILLISECOND
,
107 USB_SET_ROOT_PORT_RESET_STALL
= 50 * USB_BUS_1_MILLISECOND
,
110 // Wait for clear roothub port reset, set by experience
112 USB_CLR_ROOT_PORT_RESET_STALL
= 1 * USB_BUS_1_MILLISECOND
,
115 // Wait for set roothub port enable, set by experience
117 USB_SET_ROOT_PORT_ENABLE_STALL
= 20 * USB_BUS_1_MILLISECOND
,
120 // Send general device request timeout, refers to
121 // specification[USB20-11.24.1]
123 USB_GENERAL_DEVICE_REQUEST_TIMEOUT
= 50 * USB_BUS_1_MILLISECOND
,
126 // Send clear feature request timeout, set by experience
128 USB_CLEAR_FEATURE_REQUEST_TIMEOUT
= 10 * USB_BUS_1_MILLISECOND
,
131 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
132 // to protect shared data structures.
134 USB_BUS_TPL
= TPL_NOTIFY
,
136 USB_INTERFACE_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'S', 'B', 'I'),
137 USB_BUS_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')
140 #define USB_BIT(a) ((UINTN)(1 << (a)))
141 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
143 #define EFI_USB_BUS_PROTOCOL_GUID \
144 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
146 #define USB_INTERFACE_FROM_USBIO(a) \
147 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
149 #define USB_BUS_FROM_THIS(a) \
150 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
153 // Used to locate USB_BUS
155 typedef struct _EFI_USB_BUS_PROTOCOL
{
157 } EFI_USB_BUS_PROTOCOL
;
161 // Stands for the real USB device. Each device may
162 // has several seperately working interfaces.
168 // Configuration information
175 // The device's descriptors and its configuration
177 USB_DEVICE_DESC
*DevDesc
;
178 USB_CONFIG_DESC
*ActiveConfig
;
180 UINT16 LangId
[USB_MAX_LANG_ID
];
183 UINT8 NumOfInterface
;
184 USB_INTERFACE
*Interfaces
[USB_MAX_INTERFACE
];
187 // Parent child relationship
189 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator
;
192 USB_INTERFACE
*ParentIf
;
193 UINT8 ParentPort
; // Start at 0
197 // Stands for different functions of USB device
199 struct _USB_INTERFACE
{
202 USB_INTERFACE_DESC
*IfDesc
;
203 USB_INTERFACE_SETTING
*IfSetting
;
206 // Handles and protocols
209 EFI_USB_IO_PROTOCOL UsbIo
;
210 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
214 // Hub device special data
222 // Data used only by normal hub devices
224 USB_ENDPOINT_DESC
*HubEp
;
228 // Data used only by root hub to hand over device to
229 // companion UHCI driver if low/full speed devices are
230 // connected to EHCI.
236 // Stands for the current USB Bus
240 EFI_USB_BUS_PROTOCOL BusId
;
243 // Managed USB host controller
245 EFI_HANDLE HostHandle
;
246 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
247 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
248 EFI_USB_HC_PROTOCOL
*UsbHc
;
251 // An array of device that is on the bus. Devices[0] is
252 // for root hub. Device with address i is at Devices[i].
254 USB_DEVICE
*Devices
[USB_MAX_DEVICES
];
257 // USB Bus driver need to control the recursive connect policy of the bus, only those wanted
258 // usb child device will be recursively connected.
260 // WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,
261 // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is
262 // DEVICE_PATH_LIST_ITEM
264 LIST_ENTRY WantedUsbIoDPList
;
268 #define USB_US_LAND_ID 0x0409
270 #define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')
271 typedef struct _DEVICE_PATH_LIST_ITEM
{
274 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
275 } DEVICE_PATH_LIST_ITEM
;
278 USB_CLASS_DEVICE_PATH UsbClass
;
279 EFI_DEVICE_PATH_PROTOCOL End
;
280 } USB_CLASS_FORMAT_DEVICE_PATH
;
284 UsbBusFreeUsbDPList (
285 IN LIST_ENTRY
*UsbIoDPList
290 UsbBusAddWantedUsbIoDP (
291 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
,
292 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
297 UsbBusIsWantedUsbIO (
299 IN USB_INTERFACE
*UsbIf
304 UsbBusRecursivelyConnectWantedUsbIo (
305 IN EFI_USB_BUS_PROTOCOL
*UsbBusId
308 extern EFI_USB_IO_PROTOCOL mUsbIoProtocol
;
309 extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding
;
310 extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName
;
311 extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2
;