TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbBus.h
Go to the documentation of this file.
1
10#ifndef _EFI_USB_BUS_H_
11#define _EFI_USB_BUS_H_
12
13#include <Uefi.h>
14
17#include <Protocol/UsbIo.h>
18#include <Protocol/DevicePath.h>
19
20#include <Library/BaseLib.h>
21#include <Library/DebugLib.h>
25#include <Library/UefiLib.h>
29
31
32typedef struct _USB_DEVICE USB_DEVICE;
33typedef struct _USB_INTERFACE USB_INTERFACE;
34typedef struct _USB_BUS USB_BUS;
35typedef struct _USB_HUB_API USB_HUB_API;
36
37#include "UsbUtility.h"
38#include "UsbDesc.h"
39#include "UsbHub.h"
40#include "UsbEnumer.h"
41
42//
43// USB bus timeout experience values
44//
45
46#define USB_MAX_LANG_ID 16
47#define USB_MAX_INTERFACE 16
48#define USB_MAX_DEVICES 128
49
50#define USB_BUS_1_MILLISECOND 1000
51
52//
53// Roothub and hub's polling interval, set by experience,
54// The unit of roothub is 100us, means 100ms as interval, and
55// the unit of hub is 1ms, means 64ms as interval.
56//
57#define USB_ROOTHUB_POLL_INTERVAL (100 * 10000U)
58#define USB_HUB_POLL_INTERVAL 64
59
60//
61// Wait for port stable to work, refers to specification
62// [USB20-9.1.2]
63//
64#define USB_WAIT_PORT_STABLE_STALL (100 * USB_BUS_1_MILLISECOND)
65
66//
67// Wait for port statue reg change, set by experience
68//
69#define USB_WAIT_PORT_STS_CHANGE_STALL (100)
70
71//
72// Wait for set device address, refers to specification
73// [USB20-9.2.6.3, it says 2ms]
74//
75#define USB_SET_DEVICE_ADDRESS_STALL (2 * USB_BUS_1_MILLISECOND)
76
77//
78// Wait for retry max packet size, set by experience
79//
80#define USB_RETRY_MAX_PACK_SIZE_STALL (100 * USB_BUS_1_MILLISECOND)
81
82//
83// Wait for hub port power-on, refers to specification
84// [USB20-11.23.2]
85//
86#define USB_SET_PORT_POWER_STALL (2 * USB_BUS_1_MILLISECOND)
87
88//
89// Wait for port reset, refers to specification
90// [USB20-7.1.7.5, it says 10ms for hub and 50ms for
91// root hub]
92//
93// According to USB2.0, Chapter 11.5.1.5 Resetting,
94// the worst case for TDRST is 20ms
95//
96#define USB_SET_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)
97#define USB_SET_ROOT_PORT_RESET_STALL (50 * USB_BUS_1_MILLISECOND)
98
99//
100// Wait for port recovery to accept SetAddress, refers to specification
101// [USB20-7.1.7.5, it says 10 ms for TRSTRCY]
102//
103#define USB_SET_PORT_RECOVERY_STALL (10 * USB_BUS_1_MILLISECOND)
104
105//
106// Wait for clear roothub port reset, set by experience
107//
108#define USB_CLR_ROOT_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)
109
110//
111// Wait for set roothub port enable, set by experience
112//
113#define USB_SET_ROOT_PORT_ENABLE_STALL (20 * USB_BUS_1_MILLISECOND)
114
115//
116// Send general device request timeout.
117//
118// The USB Specification 2.0, section 11.24.1 recommends a value of
119// 50 milliseconds. We use a value of 500 milliseconds to work
120// around slower hubs and devices.
121//
122#define USB_GENERAL_DEVICE_REQUEST_TIMEOUT 500
123
124//
125// Send clear feature request timeout, set by experience
126//
127#define USB_CLEAR_FEATURE_REQUEST_TIMEOUT 10
128
129//
130// Bus raises TPL to TPL_NOTIFY to serialize all its operations
131// to protect shared data structures.
132//
133#define USB_BUS_TPL TPL_NOTIFY
134
135#define USB_INTERFACE_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'I')
136#define USB_BUS_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'B')
137
138#define USB_BIT(a) ((UINTN)(1 << (a)))
139#define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
140
141#define USB_INTERFACE_FROM_USBIO(a) \
142 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
143
144#define USB_BUS_FROM_THIS(a) \
145 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
146
147//
148// Used to locate USB_BUS
149// UsbBusProtocol is the private protocol.
150// gEfiCallerIdGuid will be used as its protocol guid.
151//
152typedef struct _EFI_USB_BUS_PROTOCOL {
153 UINT64 Reserved;
155
156//
157// Stands for the real USB device. Each device may
158// has several separately working interfaces.
159//
161 USB_BUS *Bus;
162
163 //
164 // Configuration information
165 //
166 UINT8 Speed;
167 UINT8 Address;
168 UINT32 MaxPacket0;
169
170 //
171 // The device's descriptors and its configuration
172 //
173 USB_DEVICE_DESC *DevDesc;
174 USB_CONFIG_DESC *ActiveConfig;
175
176 UINT16 LangId[USB_MAX_LANG_ID];
177 UINT16 TotalLangId;
178
179 UINT8 NumOfInterface;
180 USB_INTERFACE *Interfaces[USB_MAX_INTERFACE];
181
182 //
183 // Parent child relationship
184 //
186
187 UINT8 ParentAddr;
188 USB_INTERFACE *ParentIf;
189 UINT8 ParentPort; // Start at 0
190 UINT8 Tier;
191 BOOLEAN DisconnectFail;
192};
193
194//
195// Stands for different functions of USB device
196//
198 UINTN Signature;
199 USB_DEVICE *Device;
200 USB_INTERFACE_DESC *IfDesc;
201 USB_INTERFACE_SETTING *IfSetting;
202
203 //
204 // Handles and protocols
205 //
206 EFI_HANDLE Handle;
208 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
209 BOOLEAN IsManaged;
210
211 //
212 // Hub device special data
213 //
214 BOOLEAN IsHub;
215 USB_HUB_API *HubApi;
216 UINT8 NumOfPort;
217 EFI_EVENT HubNotify;
218
219 //
220 // Data used only by normal hub devices
221 //
222 USB_ENDPOINT_DESC *HubEp;
223 UINT8 *ChangeMap;
224
225 //
226 // Data used only by root hub to hand over device to
227 // companion UHCI driver if low/full speed devices are
228 // connected to EHCI.
229 //
230 UINT8 MaxSpeed;
231};
232
233//
234// Stands for the current USB Bus
235//
236struct _USB_BUS {
237 UINTN Signature;
239
240 //
241 // Managed USB host controller
242 //
243 EFI_HANDLE HostHandle;
244 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
245 EFI_USB2_HC_PROTOCOL *Usb2Hc;
246 EFI_USB_HC_PROTOCOL *UsbHc;
247
248 //
249 // Recorded the max supported usb devices.
250 // XHCI can support up to 255 devices.
251 // EHCI/UHCI/OHCI supports up to 127 devices.
252 //
253 UINT32 MaxDevices;
254 //
255 // An array of device that is on the bus. Devices[0] is
256 // for root hub. Device with address i is at Devices[i].
257 //
258 USB_DEVICE *Devices[256];
259
260 //
261 // USB Bus driver need to control the recursive connect policy of the bus, only those wanted
262 // usb child device will be recursively connected.
263 //
264 // WantedUsbIoDPList tracks the Usb child devices which user want to recursively fully connecte,
265 // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structure is
266 // DEVICE_PATH_LIST_ITEM
267 //
268 LIST_ENTRY WantedUsbIoDPList;
269};
270
271//
272// USB Hub Api
273//
275 USB_HUB_INIT Init;
276 USB_HUB_GET_PORT_STATUS GetPortStatus;
277 USB_HUB_CLEAR_PORT_CHANGE ClearPortChange;
278 USB_HUB_SET_PORT_FEATURE SetPortFeature;
279 USB_HUB_CLEAR_PORT_FEATURE ClearPortFeature;
280 USB_HUB_RESET_PORT ResetPort;
281 USB_HUB_RELEASE Release;
282};
283
284#define USB_US_LAND_ID 0x0409
285
286#define DEVICE_PATH_LIST_ITEM_SIGNATURE SIGNATURE_32('d','p','l','i')
288 UINTN Signature;
289 LIST_ENTRY Link;
290 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
292
293typedef struct {
294 USB_CLASS_DEVICE_PATH UsbClass;
297
308EFIAPI
310 IN LIST_ENTRY *UsbIoDPList
311 );
312
325EFIAPI
327 IN EFI_USB_BUS_PROTOCOL *UsbBusId,
328 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
329 );
330
341BOOLEAN
342EFIAPI
344 IN USB_BUS *Bus,
345 IN USB_INTERFACE *UsbIf
346 );
347
359EFIAPI
361 IN EFI_USB_BUS_PROTOCOL *UsbBusId
362 );
363
384EFIAPI
387 IN EFI_USB_DEVICE_REQUEST *Request,
388 IN EFI_USB_DATA_DIRECTION Direction,
389 IN UINT32 Timeout,
390 IN OUT VOID *Data OPTIONAL,
391 IN UINTN DataLength OPTIONAL,
392 OUT UINT32 *UsbStatus
393 );
394
412EFIAPI
415 IN UINT8 Endpoint,
416 IN OUT VOID *Data,
417 IN OUT UINTN *DataLength,
418 IN UINTN Timeout,
419 OUT UINT32 *UsbStatus
420 );
421
439EFIAPI
442 IN UINT8 Endpoint,
443 IN OUT VOID *Data,
444 IN OUT UINTN *DataLength,
445 IN UINTN Timeout,
446 OUT UINT32 *UsbStatus
447 );
448
470EFIAPI
473 IN UINT8 Endpoint,
474 IN BOOLEAN IsNewTransfer,
475 IN UINTN PollInterval OPTIONAL,
476 IN UINTN DataLength OPTIONAL,
477 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback OPTIONAL,
478 IN VOID *Context OPTIONAL
479 );
480
494EFIAPI
497 IN UINT8 DeviceEndpoint,
498 IN OUT VOID *Data,
499 IN UINTN DataLength,
500 OUT UINT32 *Status
501 );
502
518EFIAPI
521 IN UINT8 DeviceEndpoint,
522 IN OUT VOID *Data,
523 IN UINTN DataLength,
524 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack,
525 IN VOID *Context OPTIONAL
526 );
527
539EFIAPI
543 );
544
557EFIAPI
561 );
562
574EFIAPI
578 );
579
593EFIAPI
596 IN UINT8 Index,
598 );
599
611EFIAPI
614 OUT UINT16 **LangIDTable,
615 OUT UINT16 *TableSize
616 );
617
631EFIAPI
634 IN UINT16 LangID,
635 IN UINT8 StringIndex,
636 OUT CHAR16 **String
637 );
638
650EFIAPI
653 );
654
668EFIAPI
671 IN EFI_HANDLE Controller,
672 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
673 );
674
686EFIAPI
688 IN EFI_HANDLE ImageHandle,
689 IN EFI_SYSTEM_TABLE *SystemTable
690 );
691
704EFIAPI
707 IN EFI_HANDLE Controller,
708 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
709 );
710
725EFIAPI
728 IN EFI_HANDLE Controller,
729 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
730 );
731
746EFIAPI
749 IN EFI_HANDLE Controller,
750 IN UINTN NumberOfChildren,
751 IN EFI_HANDLE *ChildHandleBuffer
752 );
753
754extern EFI_USB_IO_PROTOCOL mUsbIoProtocol;
755extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding;
756extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName;
757extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2;
758
759#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_USB_DATA_DIRECTION
Definition: UsbIo.h:44
EFI_STATUS(EFIAPI * EFI_ASYNC_USB_TRANSFER_CALLBACK)(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Status)
Definition: UsbIo.h:80
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_STATUS EFIAPI UsbBusBuildProtocol(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbBus.c:941
EFI_STATUS EFIAPI UsbIoAsyncInterruptTransfer(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 Endpoint, IN BOOLEAN IsNewTransfer, IN UINTN PollInterval OPTIONAL, IN UINTN DataLength OPTIONAL, IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback OPTIONAL, IN VOID *Context OPTIONAL)
Definition: UsbBus.c:413
EFI_STATUS EFIAPI UsbBusAddWantedUsbIoDP(IN EFI_USB_BUS_PROTOCOL *UsbBusId, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbUtility.c:951
EFI_STATUS EFIAPI UsbIoSyncInterruptTransfer(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 Endpoint, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout, OUT UINT32 *UsbStatus)
Definition: UsbBus.c:335
EFI_STATUS EFIAPI UsbBusControllerDriverSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbBus.c:1174
EFI_STATUS EFIAPI UsbIoGetEndpointDescriptor(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 Index, OUT EFI_USB_ENDPOINT_DESCRIPTOR *Descriptor)
Definition: UsbBus.c:649
EFI_STATUS EFIAPI UsbIoIsochronousTransfer(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 DeviceEndpoint, IN OUT VOID *Data, IN UINTN DataLength, OUT UINT32 *Status)
Definition: UsbBus.c:482
EFI_STATUS EFIAPI UsbBusControllerDriverStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: UsbBus.c:1426
EFI_STATUS EFIAPI UsbIoGetActiveConfigDescriptor(IN EFI_USB_IO_PROTOCOL *This, OUT EFI_USB_CONFIG_DESCRIPTOR *Descriptor)
Definition: UsbBus.c:570
EFI_STATUS EFIAPI UsbIoGetInterfaceDescriptor(IN EFI_USB_IO_PROTOCOL *This, OUT EFI_USB_INTERFACE_DESCRIPTOR *Descriptor)
Definition: UsbBus.c:614
EFI_STATUS EFIAPI UsbIoGetSupportedLanguages(IN EFI_USB_IO_PROTOCOL *This, OUT UINT16 **LangIDTable, OUT UINT16 *TableSize)
Definition: UsbBus.c:694
EFI_STATUS EFIAPI UsbIoGetStringDescriptor(IN EFI_USB_IO_PROTOCOL *This, IN UINT16 LangID, IN UINT8 StringIndex, OUT CHAR16 **String)
Definition: UsbBus.c:730
EFI_STATUS EFIAPI UsbBusFreeUsbDPList(IN LIST_ENTRY *UsbIoDPList)
Definition: UsbUtility.c:902
BOOLEAN EFIAPI UsbBusIsWantedUsbIO(IN USB_BUS *Bus, IN USB_INTERFACE *UsbIf)
Definition: UsbUtility.c:1022
EFI_STATUS EFIAPI UsbBusDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: UsbBus.c:1146
EFI_STATUS EFIAPI UsbIoAsyncIsochronousTransfer(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 DeviceEndpoint, IN OUT VOID *Data, IN UINTN DataLength, IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, IN VOID *Context OPTIONAL)
Definition: UsbBus.c:509
EFI_STATUS EFIAPI UsbIoGetDeviceDescriptor(IN EFI_USB_IO_PROTOCOL *This, OUT EFI_USB_DEVICE_DESCRIPTOR *Descriptor)
Definition: UsbBus.c:533
EFI_STATUS EFIAPI UsbBusRecursivelyConnectWantedUsbIo(IN EFI_USB_BUS_PROTOCOL *UsbBusId)
Definition: UsbUtility.c:1134
EFI_STATUS EFIAPI UsbBusControllerDriverStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbBus.c:1315
EFI_STATUS EFIAPI UsbIoControlTransfer(IN EFI_USB_IO_PROTOCOL *This, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION Direction, IN UINT32 Timeout, IN OUT VOID *Data OPTIONAL, IN UINTN DataLength OPTIONAL, OUT UINT32 *UsbStatus)
Definition: UsbBus.c:59
EFI_STATUS EFIAPI UsbIoBulkTransfer(IN EFI_USB_IO_PROTOCOL *This, IN UINT8 Endpoint, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout, OUT UINT32 *UsbStatus)
Definition: UsbBus.c:241
EFI_STATUS EFIAPI UsbIoPortReset(IN EFI_USB_IO_PROTOCOL *This)
Definition: UsbBus.c:815