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/DebugLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/UefiLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/MemoryAllocationLib.h>
44 #include <IndustryStandard/Usb.h>
46 typedef struct _USB_DEVICE USB_DEVICE
;
47 typedef struct _USB_INTERFACE USB_INTERFACE
;
48 typedef struct _USB_BUS USB_BUS
;
49 typedef struct _USB_HUB_API USB_HUB_API
;
52 #include "UsbUtility.h"
55 #include "UsbEnumer.h"
59 USB_MAX_INTERFACE
= 16,
60 USB_MAX_DEVICES
= 128,
62 USB_BUS_1_MILLISECOND
= 1000,
65 // Roothub and hub's polling interval, set by experience,
66 // The unit of roothub is 100us, means 1s as interval, and
67 // the unit of hub is 1ms, means 64ms as interval.
69 USB_ROOTHUB_POLL_INTERVAL
= 1000 * 10000U,
70 USB_HUB_POLL_INTERVAL
= 64,
73 // Wait for port stable to work, refers to specification
76 USB_WAIT_PORT_STABLE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
79 // Wait for port statue reg change, set by experience
81 USB_WAIT_PORT_STS_CHANGE_STALL
= 5 * USB_BUS_1_MILLISECOND
,
84 // Wait for set device address, refers to specification
85 // [USB20-9.2.6.3, it says 2ms]
87 USB_SET_DEVICE_ADDRESS_STALL
= 20 * USB_BUS_1_MILLISECOND
,
90 // Wait for retry max packet size, set by experience
92 USB_RETRY_MAX_PACK_SIZE_STALL
= 100 * USB_BUS_1_MILLISECOND
,
95 // Wait for hub port power-on, refers to specification
98 USB_SET_PORT_POWER_STALL
= 2 * USB_BUS_1_MILLISECOND
,
101 // Wait for port reset, refers to specification
102 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for
105 USB_SET_PORT_RESET_STALL
= 20 * USB_BUS_1_MILLISECOND
,
106 USB_SET_ROOT_PORT_RESET_STALL
= 50 * USB_BUS_1_MILLISECOND
,
109 // Wait for clear roothub port reset, set by experience
111 USB_CLR_ROOT_PORT_RESET_STALL
= 1 * USB_BUS_1_MILLISECOND
,
114 // Wait for set roothub port enable, set by experience
116 USB_SET_ROOT_PORT_ENABLE_STALL
= 20 * USB_BUS_1_MILLISECOND
,
119 // Send general device request timeout, refers to
120 // specification[USB20-11.24.1]
122 USB_GENERAL_DEVICE_REQUEST_TIMEOUT
= 50 * USB_BUS_1_MILLISECOND
,
125 // Send clear feature request timeout, set by experience
127 USB_CLEAR_FEATURE_REQUEST_TIMEOUT
= 10 * USB_BUS_1_MILLISECOND
,
130 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
131 // to protect shared data structures.
133 USB_BUS_TPL
= TPL_NOTIFY
,
135 USB_INTERFACE_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'S', 'B', 'I'),
136 USB_BUS_SIGNATURE
= EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')
139 #define USB_BIT(a) ((UINTN)(1 << (a)))
140 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
142 #define EFI_USB_BUS_PROTOCOL_GUID \
143 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
145 #define USB_INTERFACE_FROM_USBIO(a) \
146 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
148 #define USB_BUS_FROM_THIS(a) \
149 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
152 // Used to locate USB_BUS
154 typedef struct _EFI_USB_BUS_PROTOCOL
{
156 } EFI_USB_BUS_PROTOCOL
;
160 // Stands for the real USB device. Each device may
161 // has several seperately working interfaces.
167 // Configuration information
174 // The device's descriptors and its configuration
176 USB_DEVICE_DESC
*DevDesc
;
177 USB_CONFIG_DESC
*ActiveConfig
;
179 UINT16 LangId
[USB_MAX_LANG_ID
];
182 UINT8 NumOfInterface
;
183 USB_INTERFACE
*Interfaces
[USB_MAX_INTERFACE
];
186 // Parent child relationship
188 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator
;
191 USB_INTERFACE
*ParentIf
;
192 UINT8 ParentPort
; // Start at 0
196 // Stands for different functions of USB device
198 struct _USB_INTERFACE
{
201 USB_INTERFACE_DESC
*IfDesc
;
202 USB_INTERFACE_SETTING
*IfSetting
;
205 // Handles and protocols
208 EFI_USB_IO_PROTOCOL UsbIo
;
209 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
213 // Hub device special data
221 // Data used only by normal hub devices
223 USB_ENDPOINT_DESC
*HubEp
;
227 // Data used only by root hub to hand over device to
228 // companion UHCI driver if low/full speed devices are
229 // connected to EHCI.
235 // Stands for the current USB Bus
239 EFI_USB_BUS_PROTOCOL BusId
;
242 // Managed USB host controller
244 EFI_HANDLE HostHandle
;
245 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
246 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
247 EFI_USB_HC_PROTOCOL
*UsbHc
;
250 // An array of device that is on the bus. Devices[0] is
251 // for root hub. Device with address i is at Devices[i].
253 USB_DEVICE
*Devices
[USB_MAX_DEVICES
];
256 extern EFI_USB_IO_PROTOCOL mUsbIoProtocol
;
257 extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding
;
258 extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName
;
259 extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2
;