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
353 extern EFI_USB_IO_PROTOCOL mUsbIoProtocol
;
354 extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding
;
355 extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName
;
356 extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2
;