]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
edk2/MdePkg/Include/Ia32/ProcessorBind.h:
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.h
... / ...
CommitLineData
1/** @file\r
2\r
3 Usb Bus Driver Binding and Bus IO Protocol.\r
4\r
5Copyright (c) 2004 - 2007, Intel Corporation\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _EFI_USB_BUS_H_\r
17#define _EFI_USB_BUS_H_\r
18\r
19\r
20#include <PiDxe.h>\r
21\r
22#include <Protocol/Usb2HostController.h>\r
23#include <Protocol/UsbHostController.h>\r
24#include <Protocol/UsbIo.h>\r
25#include <Protocol/DevicePath.h>\r
26\r
27#include <Library/BaseLib.h>\r
28#include <Library/DebugLib.h>\r
29#include <Library/BaseMemoryLib.h>\r
30#include <Library/UefiDriverEntryPoint.h>\r
31#include <Library/UefiBootServicesTableLib.h>\r
32#include <Library/UefiLib.h>\r
33#include <Library/DevicePathLib.h>\r
34#include <Library/MemoryAllocationLib.h>\r
35\r
36\r
37#include <IndustryStandard/Usb.h>\r
38\r
39typedef struct _USB_DEVICE USB_DEVICE;\r
40typedef struct _USB_INTERFACE USB_INTERFACE;\r
41typedef struct _USB_BUS USB_BUS;\r
42typedef struct _USB_HUB_API USB_HUB_API;\r
43\r
44\r
45#include "UsbUtility.h"\r
46#include "UsbDesc.h"\r
47#include "UsbHub.h"\r
48#include "UsbEnumer.h"\r
49\r
50typedef enum {\r
51 USB_MAX_LANG_ID = 16,\r
52 USB_MAX_INTERFACE = 16,\r
53 USB_MAX_DEVICES = 128,\r
54\r
55 USB_BUS_1_MILLISECOND = 1000,\r
56\r
57 //\r
58 // Roothub and hub's polling interval, set by experience,\r
59 // The unit of roothub is 100us, means 1s as interval, and\r
60 // the unit of hub is 1ms, means 64ms as interval.\r
61 //\r
62 USB_ROOTHUB_POLL_INTERVAL = 1000 * 10000U,\r
63 USB_HUB_POLL_INTERVAL = 64,\r
64\r
65 //\r
66 // Wait for port stable to work, refers to specification\r
67 // [USB20-9.1.2]\r
68 //\r
69 USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
70\r
71 //\r
72 // Wait for port statue reg change, set by experience\r
73 //\r
74 USB_WAIT_PORT_STS_CHANGE_STALL = 5 * USB_BUS_1_MILLISECOND,\r
75\r
76 //\r
77 // Wait for set device address, refers to specification\r
78 // [USB20-9.2.6.3, it says 2ms]\r
79 //\r
80 USB_SET_DEVICE_ADDRESS_STALL = 20 * USB_BUS_1_MILLISECOND,\r
81\r
82 //\r
83 // Wait for retry max packet size, set by experience\r
84 //\r
85 USB_RETRY_MAX_PACK_SIZE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
86\r
87 //\r
88 // Wait for hub port power-on, refers to specification\r
89 // [USB20-11.23.2]\r
90 //\r
91 USB_SET_PORT_POWER_STALL = 2 * USB_BUS_1_MILLISECOND,\r
92\r
93 //\r
94 // Wait for port reset, refers to specification\r
95 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for\r
96 // root hub]\r
97 //\r
98 USB_SET_PORT_RESET_STALL = 20 * USB_BUS_1_MILLISECOND,\r
99 USB_SET_ROOT_PORT_RESET_STALL = 50 * USB_BUS_1_MILLISECOND,\r
100\r
101 //\r
102 // Wait for clear roothub port reset, set by experience\r
103 //\r
104 USB_CLR_ROOT_PORT_RESET_STALL = 1 * USB_BUS_1_MILLISECOND,\r
105\r
106 //\r
107 // Wait for set roothub port enable, set by experience\r
108 //\r
109 USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,\r
110\r
111 //\r
112 // Send general device request timeout, refers to\r
113 // specification[USB20-11.24.1]\r
114 //\r
115 USB_GENERAL_DEVICE_REQUEST_TIMEOUT = 50 * USB_BUS_1_MILLISECOND,\r
116\r
117 //\r
118 // Send clear feature request timeout, set by experience\r
119 //\r
120 USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND\r
121}USB_BUS_TIMEOUT_EXPERIENCE_VALUE;\r
122\r
123//\r
124// Bus raises TPL to TPL_NOTIFY to serialize all its operations\r
125// to protect shared data structures.\r
126//\r
127#define USB_BUS_TPL TPL_NOTIFY\r
128\r
129#define USB_INTERFACE_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'I')\r
130#define USB_BUS_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')\r
131\r
132#define USB_BIT(a) ((UINTN)(1 << (a)))\r
133#define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r
134\r
135#define EFI_USB_BUS_PROTOCOL_GUID \\r
136 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}\r
137\r
138#define USB_INTERFACE_FROM_USBIO(a) \\r
139 CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)\r
140\r
141#define USB_BUS_FROM_THIS(a) \\r
142 CR(a, USB_BUS, BusId, USB_BUS_SIGNATURE)\r
143\r
144//\r
145// Used to locate USB_BUS\r
146//\r
147typedef struct _EFI_USB_BUS_PROTOCOL {\r
148 UINT64 Reserved;\r
149} EFI_USB_BUS_PROTOCOL;\r
150\r
151\r
152//\r
153// Stands for the real USB device. Each device may\r
154// has several seperately working interfaces.\r
155//\r
156struct _USB_DEVICE {\r
157 USB_BUS *Bus;\r
158\r
159 //\r
160 // Configuration information\r
161 //\r
162 UINT8 Speed;\r
163 UINT8 Address;\r
164 UINT8 MaxPacket0;\r
165\r
166 //\r
167 // The device's descriptors and its configuration\r
168 //\r
169 USB_DEVICE_DESC *DevDesc;\r
170 USB_CONFIG_DESC *ActiveConfig;\r
171\r
172 UINT16 LangId [USB_MAX_LANG_ID];\r
173 UINT16 TotalLangId;\r
174\r
175 UINT8 NumOfInterface;\r
176 USB_INTERFACE *Interfaces [USB_MAX_INTERFACE];\r
177\r
178 //\r
179 // Parent child relationship\r
180 //\r
181 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;\r
182\r
183 UINT8 ParentAddr;\r
184 USB_INTERFACE *ParentIf;\r
185 UINT8 ParentPort; // Start at 0\r
186};\r
187\r
188//\r
189// Stands for different functions of USB device\r
190//\r
191struct _USB_INTERFACE {\r
192 UINTN Signature;\r
193 USB_DEVICE *Device;\r
194 USB_INTERFACE_DESC *IfDesc;\r
195 USB_INTERFACE_SETTING *IfSetting;\r
196\r
197 //\r
198 // Handles and protocols\r
199 //\r
200 EFI_HANDLE Handle;\r
201 EFI_USB_IO_PROTOCOL UsbIo;\r
202 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
203 BOOLEAN IsManaged;\r
204\r
205 //\r
206 // Hub device special data\r
207 //\r
208 BOOLEAN IsHub;\r
209 USB_HUB_API *HubApi;\r
210 UINT8 NumOfPort;\r
211 EFI_EVENT HubNotify;\r
212\r
213 //\r
214 // Data used only by normal hub devices\r
215 //\r
216 USB_ENDPOINT_DESC *HubEp;\r
217 UINT8 *ChangeMap;\r
218\r
219 //\r
220 // Data used only by root hub to hand over device to\r
221 // companion UHCI driver if low/full speed devices are\r
222 // connected to EHCI.\r
223 //\r
224 UINT8 MaxSpeed;\r
225};\r
226\r
227//\r
228// Stands for the current USB Bus\r
229//\r
230struct _USB_BUS {\r
231 UINTN Signature;\r
232 EFI_USB_BUS_PROTOCOL BusId;\r
233\r
234 //\r
235 // Managed USB host controller\r
236 //\r
237 EFI_HANDLE HostHandle;\r
238 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
239 EFI_USB2_HC_PROTOCOL *Usb2Hc;\r
240 EFI_USB_HC_PROTOCOL *UsbHc;\r
241\r
242 //\r
243 // An array of device that is on the bus. Devices[0] is\r
244 // for root hub. Device with address i is at Devices[i].\r
245 //\r
246 USB_DEVICE *Devices[USB_MAX_DEVICES];\r
247\r
248 //\r
249 // USB Bus driver need to control the recursive connect policy of the bus, only those wanted\r
250 // usb child device will be recursively connected.\r
251 //\r
252 // WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,\r
253 // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is\r
254 // DEVICE_PATH_LIST_ITEM\r
255 //\r
256 LIST_ENTRY WantedUsbIoDPList;\r
257\r
258};\r
259\r
260//\r
261// USB Hub Api\r
262//\r
263struct _USB_HUB_API{\r
264 USB_HUB_INIT Init;\r
265 USB_HUB_GET_PORT_STATUS GetPortStatus;\r
266 USB_HUB_CLEAR_PORT_CHANGE ClearPortChange;\r
267 USB_HUB_SET_PORT_FEATURE SetPortFeature;\r
268 USB_HUB_CLEAR_PORT_FEATURE ClearPortFeature;\r
269 USB_HUB_RESET_PORT ResetPort;\r
270 USB_HUB_RELEASE Release;\r
271};\r
272\r
273#define USB_US_LAND_ID 0x0409\r
274\r
275#define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')\r
276typedef struct _DEVICE_PATH_LIST_ITEM{\r
277 UINTN Signature;\r
278 LIST_ENTRY Link;\r
279 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
280} DEVICE_PATH_LIST_ITEM;\r
281\r
282typedef struct {\r
283 USB_CLASS_DEVICE_PATH UsbClass;\r
284 EFI_DEVICE_PATH_PROTOCOL End;\r
285} USB_CLASS_FORMAT_DEVICE_PATH;\r
286\r
287/**\r
288 Free a DEVICE_PATH_LIST_ITEM list.\r
289\r
290 @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer.\r
291\r
292 @retval EFI_INVALID_PARAMETER If parameters are invalid, return this value.\r
293 @retval EFI_SUCCESS If free operation is successful, return this value.\r
294\r
295**/\r
296EFI_STATUS\r
297EFIAPI\r
298UsbBusFreeUsbDPList (\r
299 IN LIST_ENTRY *UsbIoDPList\r
300 );\r
301\r
302/**\r
303 Store a wanted usb child device info (its Usb part of device path) which is indicated by\r
304 RemainingDevicePath in a Usb bus which is indicated by UsbBusId.\r
305\r
306 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.\r
307 @param RemainingDevicePath The remaining device patch.\r
308\r
309 @retval EFI_SUCCESS Add operation is successful.\r
310 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
311\r
312**/\r
313EFI_STATUS\r
314EFIAPI\r
315UsbBusAddWantedUsbIoDP (\r
316 IN EFI_USB_BUS_PROTOCOL *UsbBusId,\r
317 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
318 );\r
319\r
320/**\r
321 Check whether a usb child device is the wanted device in a bus.\r
322\r
323 @param Bus The Usb bus's private data pointer.\r
324 @param UsbIf The usb child device inferface.\r
325\r
326 @retval True If a usb child device is the wanted device in a bus.\r
327 @retval False If a usb child device is *NOT* the wanted device in a bus.\r
328\r
329**/\r
330BOOLEAN\r
331EFIAPI\r
332UsbBusIsWantedUsbIO (\r
333 IN USB_BUS *Bus,\r
334 IN USB_INTERFACE *UsbIf\r
335 );\r
336\r
337/**\r
338 Recursively connnect every wanted usb child device to ensure they all fully connected.\r
339 Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device.\r
340\r
341 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.\r
342\r
343 @retval EFI_SUCCESS Connect is done successfully.\r
344 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
345\r
346**/\r
347EFI_STATUS\r
348EFIAPI\r
349UsbBusRecursivelyConnectWantedUsbIo (\r
350 IN EFI_USB_BUS_PROTOCOL *UsbBusId\r
351 );\r
352\r
353extern EFI_USB_IO_PROTOCOL mUsbIoProtocol;\r
354extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding;\r
355extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName;\r
356extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2;\r
357\r
358#endif\r