]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbBusDxe/usbbus.h
971e01b47ab12b4d40f93f88d83049ee953eaa20
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / usbbus.h
1 /** @file
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
7
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.
10
11 Module Name:
12
13 UsbBus.h
14
15 Abstract:
16
17 Usb Bus Driver Binding and Bus IO Protocol
18
19 Revision History
20
21
22 **/
23
24 #ifndef _EFI_USB_BUS_H_
25 #define _EFI_USB_BUS_H_
26
27
28 #include <PiDxe.h>
29
30 #include <Protocol/Usb2HostController.h>
31 #include <Protocol/UsbHostController.h>
32 #include <Protocol/UsbIo.h>
33 #include <Protocol/DevicePath.h>
34
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>
42
43
44 #include <IndustryStandard/Usb.h>
45
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;
50
51
52 #include "UsbUtility.h"
53 #include "UsbDesc.h"
54 #include "UsbHub.h"
55 #include "UsbEnumer.h"
56
57 enum {
58 USB_MAX_LANG_ID = 16,
59 USB_MAX_INTERFACE = 16,
60 USB_MAX_DEVICES = 128,
61
62 USB_BUS_1_MILLISECOND = 1000,
63
64 //
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.
68 //
69 USB_ROOTHUB_POLL_INTERVAL = 1000 * 10000U,
70 USB_HUB_POLL_INTERVAL = 64,
71
72 //
73 // Wait for port stable to work, refers to specification
74 // [USB20-9.1.2]
75 //
76 USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,
77
78 //
79 // Wait for port statue reg change, set by experience
80 //
81 USB_WAIT_PORT_STS_CHANGE_STALL = 5 * USB_BUS_1_MILLISECOND,
82
83 //
84 // Wait for set device address, refers to specification
85 // [USB20-9.2.6.3, it says 2ms]
86 //
87 USB_SET_DEVICE_ADDRESS_STALL = 20 * USB_BUS_1_MILLISECOND,
88
89 //
90 // Wait for retry max packet size, set by experience
91 //
92 USB_RETRY_MAX_PACK_SIZE_STALL = 100 * USB_BUS_1_MILLISECOND,
93
94 //
95 // Wait for hub port power-on, refers to specification
96 // [USB20-11.23.2]
97 //
98 USB_SET_PORT_POWER_STALL = 2 * USB_BUS_1_MILLISECOND,
99
100 //
101 // Wait for port reset, refers to specification
102 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for
103 // root hub]
104 //
105 USB_SET_PORT_RESET_STALL = 20 * USB_BUS_1_MILLISECOND,
106 USB_SET_ROOT_PORT_RESET_STALL = 50 * USB_BUS_1_MILLISECOND,
107
108 //
109 // Wait for clear roothub port reset, set by experience
110 //
111 USB_CLR_ROOT_PORT_RESET_STALL = 1 * USB_BUS_1_MILLISECOND,
112
113 //
114 // Wait for set roothub port enable, set by experience
115 //
116 USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,
117
118 //
119 // Send general device request timeout, refers to
120 // specification[USB20-11.24.1]
121 //
122 USB_GENERAL_DEVICE_REQUEST_TIMEOUT = 50 * USB_BUS_1_MILLISECOND,
123
124 //
125 // Send clear feature request timeout, set by experience
126 //
127 USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND,
128
129 //
130 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
131 // to protect shared data structures.
132 //
133 USB_BUS_TPL = TPL_NOTIFY,
134
135 USB_INTERFACE_SIGNATURE = EFI_SIGNATURE_32 ('U', 'S', 'B', 'I'),
136 USB_BUS_SIGNATURE = EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')
137 };
138
139 #define USB_BIT(a) ((UINTN)(1 << (a)))
140 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
141
142 #define EFI_USB_BUS_PROTOCOL_GUID \
143 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
144
145 #define USB_INTERFACE_FROM_USBIO(a) \
146 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
147
148 #define USB_BUS_FROM_THIS(a) \
149 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
150
151 //
152 // Used to locate USB_BUS
153 //
154 typedef struct _EFI_USB_BUS_PROTOCOL {
155 UINT64 Reserved;
156 } EFI_USB_BUS_PROTOCOL;
157
158
159 //
160 // Stands for the real USB device. Each device may
161 // has several seperately working interfaces.
162 //
163 struct _USB_DEVICE {
164 USB_BUS *Bus;
165
166 //
167 // Configuration information
168 //
169 UINT8 Speed;
170 UINT8 Address;
171 UINT8 MaxPacket0;
172
173 //
174 // The device's descriptors and its configuration
175 //
176 USB_DEVICE_DESC *DevDesc;
177 USB_CONFIG_DESC *ActiveConfig;
178
179 UINT16 LangId [USB_MAX_LANG_ID];
180 UINT16 TotalLangId;
181
182 UINT8 NumOfInterface;
183 USB_INTERFACE *Interfaces [USB_MAX_INTERFACE];
184
185 //
186 // Parent child relationship
187 //
188 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;
189
190 UINT8 ParentAddr;
191 USB_INTERFACE *ParentIf;
192 UINT8 ParentPort; // Start at 0
193 };
194
195 //
196 // Stands for different functions of USB device
197 //
198 struct _USB_INTERFACE {
199 UINTN Signature;
200 USB_DEVICE *Device;
201 USB_INTERFACE_DESC *IfDesc;
202 USB_INTERFACE_SETTING *IfSetting;
203
204 //
205 // Handles and protocols
206 //
207 EFI_HANDLE Handle;
208 EFI_USB_IO_PROTOCOL UsbIo;
209 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
210 BOOLEAN IsManaged;
211
212 //
213 // Hub device special data
214 //
215 BOOLEAN IsHub;
216 USB_HUB_API *HubApi;
217 UINT8 NumOfPort;
218 EFI_EVENT HubNotify;
219
220 //
221 // Data used only by normal hub devices
222 //
223 USB_ENDPOINT_DESC *HubEp;
224 UINT8 *ChangeMap;
225
226 //
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.
230 //
231 UINT8 MaxSpeed;
232 };
233
234 //
235 // Stands for the current USB Bus
236 //
237 struct _USB_BUS {
238 UINTN Signature;
239 EFI_USB_BUS_PROTOCOL BusId;
240
241 //
242 // Managed USB host controller
243 //
244 EFI_HANDLE HostHandle;
245 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
246 EFI_USB2_HC_PROTOCOL *Usb2Hc;
247 EFI_USB_HC_PROTOCOL *UsbHc;
248
249 //
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].
252 //
253 USB_DEVICE *Devices[USB_MAX_DEVICES];
254 };
255
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;
260
261 #endif