]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
Refine function header comments of PalCallLib.h.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.h
CommitLineData
e237e7ae 1/** @file\r
8616fc4c 2\r
3 Usb Bus Driver Binding and Bus IO Protocol.\r
4\r
e237e7ae 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
e237e7ae 14**/\r
15\r
16#ifndef _EFI_USB_BUS_H_\r
17#define _EFI_USB_BUS_H_\r
18\r
ed7748fe 19\r
e237e7ae 20#include <PiDxe.h>\r
ed7748fe 21\r
e237e7ae 22#include <Protocol/Usb2HostController.h>\r
23#include <Protocol/UsbHostController.h>\r
24#include <Protocol/UsbIo.h>\r
25#include <Protocol/DevicePath.h>\r
ed7748fe 26\r
77442a5a 27#include <Library/BaseLib.h>\r
e237e7ae 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
8616fc4c 50typedef enum {\r
41e8ff27 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
e237e7ae 57 //\r
41e8ff27 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
e237e7ae 61 //\r
41e8ff27 62 USB_ROOTHUB_POLL_INTERVAL = 1000 * 10000U,\r
e237e7ae 63 USB_HUB_POLL_INTERVAL = 64,\r
64\r
65 //\r
41e8ff27 66 // Wait for port stable to work, refers to specification\r
67 // [USB20-9.1.2]\r
e237e7ae 68 //\r
41e8ff27 69 USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
70\r
ecb575d9 71 //\r
41e8ff27 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
e237e7ae 86\r
41e8ff27 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
ecb575d9 94 // Wait for port reset, refers to specification\r
95 // [USB20-7.1.7.5, it says 10ms for hub and 50ms for\r
41e8ff27 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
ecb575d9 108 //\r
41e8ff27 109 USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,\r
110\r
111 //\r
ecb575d9 112 // Send general device request timeout, refers to\r
41e8ff27 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
8616fc4c 120 USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND\r
121}USB_BUS_TIMEOUT_EXPERIENCE_VALUE;\r
ecb575d9 122\r
8616fc4c 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
e237e7ae 128\r
8616fc4c 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
e237e7ae 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
84b5c78e 136 {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}\r
e237e7ae 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
c52fa98c 156struct _USB_DEVICE {\r
e237e7ae 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
c52fa98c 186};\r
e237e7ae 187\r
188//\r
189// Stands for different functions of USB device\r
190//\r
c52fa98c 191struct _USB_INTERFACE {\r
e237e7ae 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
c52fa98c 225};\r
e237e7ae 226\r
227//\r
228// Stands for the current USB Bus\r
229//\r
c52fa98c 230struct _USB_BUS {\r
e237e7ae 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
ecb575d9 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
c52fa98c 258};\r
e237e7ae 259\r
ecb575d9 260#define USB_US_LAND_ID 0x0409\r
261\r
262#define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')\r
263typedef struct _DEVICE_PATH_LIST_ITEM{\r
264 UINTN Signature;\r
265 LIST_ENTRY Link;\r
266 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
267} DEVICE_PATH_LIST_ITEM;\r
268\r
269typedef struct {\r
270 USB_CLASS_DEVICE_PATH UsbClass;\r
271 EFI_DEVICE_PATH_PROTOCOL End;\r
272} USB_CLASS_FORMAT_DEVICE_PATH;\r
273\r
8616fc4c 274/**\r
275 Free a DEVICE_PATH_LIST_ITEM list.\r
276\r
277 @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer.\r
278\r
279 @retval EFI_INVALID_PARAMETER If parameters are invalid, return this value.\r
280 @retval EFI_SUCCESS If free operation is successful, return this value.\r
281\r
282**/\r
ecb575d9 283EFI_STATUS\r
284EFIAPI\r
285UsbBusFreeUsbDPList (\r
286 IN LIST_ENTRY *UsbIoDPList\r
287 );\r
288\r
8616fc4c 289/**\r
290 Store a wanted usb child device info (its Usb part of device path) which is indicated by\r
291 RemainingDevicePath in a Usb bus which is indicated by UsbBusId.\r
292\r
293 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.\r
294 @param RemainingDevicePath The remaining device patch.\r
295\r
296 @retval EFI_SUCCESS Add operation is successful.\r
297 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
298\r
299**/\r
ecb575d9 300EFI_STATUS\r
301EFIAPI\r
302UsbBusAddWantedUsbIoDP (\r
303 IN EFI_USB_BUS_PROTOCOL *UsbBusId,\r
304 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
305 );\r
306\r
8616fc4c 307/**\r
308 Check whether a usb child device is the wanted device in a bus.\r
309\r
310 @param Bus The Usb bus's private data pointer.\r
311 @param UsbIf The usb child device inferface.\r
312\r
313 @retval True If a usb child device is the wanted device in a bus.\r
314 @retval False If a usb child device is *NOT* the wanted device in a bus.\r
315\r
316**/\r
ecb575d9 317BOOLEAN\r
318EFIAPI\r
319UsbBusIsWantedUsbIO (\r
320 IN USB_BUS *Bus,\r
321 IN USB_INTERFACE *UsbIf\r
322 );\r
323\r
8616fc4c 324/**\r
325 Recursively connnect every wanted usb child device to ensure they all fully connected.\r
326 Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device.\r
327\r
328 @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.\r
329\r
330 @retval EFI_SUCCESS Connect is done successfully.\r
331 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
332\r
333**/\r
ecb575d9 334EFI_STATUS\r
335EFIAPI\r
336UsbBusRecursivelyConnectWantedUsbIo (\r
337 IN EFI_USB_BUS_PROTOCOL *UsbBusId\r
338 );\r
339\r
62b9bb55 340extern EFI_USB_IO_PROTOCOL mUsbIoProtocol;\r
341extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding;\r
342extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName;\r
343extern EFI_COMPONENT_NAME2_PROTOCOL mUsbBusComponentName2;\r
e237e7ae 344\r
345#endif\r