Enhance the Usb bus driver to support Star with Remaining device path.
[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/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>
43
44
45 #include <IndustryStandard/Usb.h>
46
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;
51
52
53 #include "UsbUtility.h"
54 #include "UsbDesc.h"
55 #include "UsbHub.h"
56 #include "UsbEnumer.h"
57
58 enum {
59 USB_MAX_LANG_ID = 16,
60 USB_MAX_INTERFACE = 16,
61 USB_MAX_DEVICES = 128,
62
63 USB_BUS_1_MILLISECOND = 1000,
64
65 //
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.
69 //
70 USB_ROOTHUB_POLL_INTERVAL = 1000 * 10000U,
71 USB_HUB_POLL_INTERVAL = 64,
72
73 //
74 // Wait for port stable to work, refers to specification
75 // [USB20-9.1.2]
76 //
77 USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,
78
79 //
80 // Wait for port statue reg change, set by experience
81 //
82 USB_WAIT_PORT_STS_CHANGE_STALL = 5 * USB_BUS_1_MILLISECOND,
83
84 //
85 // Wait for set device address, refers to specification
86 // [USB20-9.2.6.3, it says 2ms]
87 //
88 USB_SET_DEVICE_ADDRESS_STALL = 20 * USB_BUS_1_MILLISECOND,
89
90 //
91 // Wait for retry max packet size, set by experience
92 //
93 USB_RETRY_MAX_PACK_SIZE_STALL = 100 * USB_BUS_1_MILLISECOND,
94
95 //
96 // Wait for hub port power-on, refers to specification
97 // [USB20-11.23.2]
98 //
99 USB_SET_PORT_POWER_STALL = 2 * USB_BUS_1_MILLISECOND,
100
101 //
102 // Wait for port reset, refers to specification
103 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for
104 // root hub]
105 //
106 USB_SET_PORT_RESET_STALL = 20 * USB_BUS_1_MILLISECOND,
107 USB_SET_ROOT_PORT_RESET_STALL = 50 * USB_BUS_1_MILLISECOND,
108
109 //
110 // Wait for clear roothub port reset, set by experience
111 //
112 USB_CLR_ROOT_PORT_RESET_STALL = 1 * USB_BUS_1_MILLISECOND,
113
114 //
115 // Wait for set roothub port enable, set by experience
116 //
117 USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,
118
119 //
120 // Send general device request timeout, refers to
121 // specification[USB20-11.24.1]
122 //
123 USB_GENERAL_DEVICE_REQUEST_TIMEOUT = 50 * USB_BUS_1_MILLISECOND,
124
125 //
126 // Send clear feature request timeout, set by experience
127 //
128 USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND,
129
130 //
131 // Bus raises TPL to TPL_NOTIFY to serialize all its operations
132 // to protect shared data structures.
133 //
134 USB_BUS_TPL = TPL_NOTIFY,
135
136 USB_INTERFACE_SIGNATURE = EFI_SIGNATURE_32 ('U', 'S', 'B', 'I'),
137 USB_BUS_SIGNATURE = EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')
138 };
139
140 #define USB_BIT(a) ((UINTN)(1 << (a)))
141 #define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
142
143 #define EFI_USB_BUS_PROTOCOL_GUID \
144 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}
145
146 #define USB_INTERFACE_FROM_USBIO(a) \
147 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)
148
149 #define USB_BUS_FROM_THIS(a) \
150 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)
151
152 //
153 // Used to locate USB_BUS
154 //
155 typedef struct _EFI_USB_BUS_PROTOCOL {
156 UINT64 Reserved;
157 } EFI_USB_BUS_PROTOCOL;
158
159
160 //
161 // Stands for the real USB device. Each device may
162 // has several seperately working interfaces.
163 //
164 struct _USB_DEVICE {
165 USB_BUS *Bus;
166
167 //
168 // Configuration information
169 //
170 UINT8 Speed;
171 UINT8 Address;
172 UINT8 MaxPacket0;
173
174 //
175 // The device's descriptors and its configuration
176 //
177 USB_DEVICE_DESC *DevDesc;
178 USB_CONFIG_DESC *ActiveConfig;
179
180 UINT16 LangId [USB_MAX_LANG_ID];
181 UINT16 TotalLangId;
182
183 UINT8 NumOfInterface;
184 USB_INTERFACE *Interfaces [USB_MAX_INTERFACE];
185
186 //
187 // Parent child relationship
188 //
189 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;
190
191 UINT8 ParentAddr;
192 USB_INTERFACE *ParentIf;
193 UINT8 ParentPort; // Start at 0
194 };
195
196 //
197 // Stands for different functions of USB device
198 //
199 struct _USB_INTERFACE {
200 UINTN Signature;
201 USB_DEVICE *Device;
202 USB_INTERFACE_DESC *IfDesc;
203 USB_INTERFACE_SETTING *IfSetting;
204
205 //
206 // Handles and protocols
207 //
208 EFI_HANDLE Handle;
209 EFI_USB_IO_PROTOCOL UsbIo;
210 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
211 BOOLEAN IsManaged;
212
213 //
214 // Hub device special data
215 //
216 BOOLEAN IsHub;
217 USB_HUB_API *HubApi;
218 UINT8 NumOfPort;
219 EFI_EVENT HubNotify;
220
221 //
222 // Data used only by normal hub devices
223 //
224 USB_ENDPOINT_DESC *HubEp;
225 UINT8 *ChangeMap;
226
227 //
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.
231 //
232 UINT8 MaxSpeed;
233 };
234
235 //
236 // Stands for the current USB Bus
237 //
238 struct _USB_BUS {
239 UINTN Signature;
240 EFI_USB_BUS_PROTOCOL BusId;
241
242 //
243 // Managed USB host controller
244 //
245 EFI_HANDLE HostHandle;
246 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
247 EFI_USB2_HC_PROTOCOL *Usb2Hc;
248 EFI_USB_HC_PROTOCOL *UsbHc;
249
250 //
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].
253 //
254 USB_DEVICE *Devices[USB_MAX_DEVICES];
255
256 //
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.
259 //
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
263 //
264 LIST_ENTRY WantedUsbIoDPList;
265
266 };
267
268 #define USB_US_LAND_ID 0x0409
269
270 #define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')
271 typedef struct _DEVICE_PATH_LIST_ITEM{
272 UINTN Signature;
273 LIST_ENTRY Link;
274 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
275 } DEVICE_PATH_LIST_ITEM;
276
277 typedef struct {
278 USB_CLASS_DEVICE_PATH UsbClass;
279 EFI_DEVICE_PATH_PROTOCOL End;
280 } USB_CLASS_FORMAT_DEVICE_PATH;
281
282 EFI_STATUS
283 EFIAPI
284 UsbBusFreeUsbDPList (
285 IN LIST_ENTRY *UsbIoDPList
286 );
287
288 EFI_STATUS
289 EFIAPI
290 UsbBusAddWantedUsbIoDP (
291 IN EFI_USB_BUS_PROTOCOL *UsbBusId,
292 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
293 );
294
295 BOOLEAN
296 EFIAPI
297 UsbBusIsWantedUsbIO (
298 IN USB_BUS *Bus,
299 IN USB_INTERFACE *UsbIf
300 );
301
302 EFI_STATUS
303 EFIAPI
304 UsbBusRecursivelyConnectWantedUsbIo (
305 IN EFI_USB_BUS_PROTOCOL *UsbBusId
306 );
307
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;
312
313 #endif