]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
MdeModulePkg/UsbBus: Fix various typos
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / UsbPeim.h
CommitLineData
4b1bf81c 1/** @file\r
2Usb Peim definition.\r
3\r
d1102dba
LG
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>\r
5\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
4b1bf81c 7\r
8**/\r
9\r
10#ifndef _PEI_USB_PEIM_H_\r
11#define _PEI_USB_PEIM_H_\r
12\r
13\r
14#include <PiPei.h>\r
15\r
16#include <Ppi/UsbHostController.h>\r
17#include <Ppi/Usb2HostController.h>\r
18#include <Ppi/UsbIo.h>\r
19\r
20#include <Library/DebugLib.h>\r
21#include <Library/PeimEntryPoint.h>\r
22#include <Library/PeiServicesLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/TimerLib.h>\r
25#include <Library/PcdLib.h>\r
26\r
27#include <IndustryStandard/Usb.h>\r
28\r
c96de1db
RN
29//\r
30// A common header for usb standard descriptor.\r
31// Each stand descriptor has a length and type.\r
32//\r
33#pragma pack(1)\r
34typedef struct {\r
35 UINT8 Len;\r
36 UINT8 Type;\r
37} USB_DESC_HEAD;\r
38#pragma pack()\r
39\r
8a718ba9 40#define MAX_INTERFACE 8\r
4b1bf81c 41#define MAX_ENDPOINT 16\r
42\r
4b1bf81c 43#define PEI_USB_DEVICE_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'D')\r
44typedef struct {\r
45 UINTN Signature;\r
46 PEI_USB_IO_PPI UsbIoPpi;\r
47 EFI_PEI_PPI_DESCRIPTOR UsbIoPpiList;\r
d987459f
SZ
48 UINT16 MaxPacketSize0;\r
49 UINT16 DataToggle;\r
4b1bf81c 50 UINT8 DeviceAddress;\r
4b1bf81c 51 UINT8 DeviceSpeed;\r
4b1bf81c 52 UINT8 IsHub;\r
53 UINT8 DownStreamPortNo;\r
4b1bf81c 54 UINTN AllocateAddress;\r
55 PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi;\r
56 PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi;\r
57 UINT8 ConfigurationData[1024];\r
58 EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;\r
59 EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;\r
8a718ba9 60 EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescList[MAX_INTERFACE];\r
4b1bf81c 61 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT];\r
8a718ba9 62 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescList[MAX_INTERFACE][MAX_ENDPOINT];\r
d987459f
SZ
63 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;\r
64 UINT8 Tier;\r
4b1bf81c 65} PEI_USB_DEVICE;\r
66\r
67#define PEI_USB_DEVICE_FROM_THIS(a) CR (a, PEI_USB_DEVICE, UsbIoPpi, PEI_USB_DEVICE_SIGNATURE)\r
68\r
d987459f
SZ
69#define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r
70\r
71#define USB_BUS_1_MILLISECOND 1000\r
72\r
73//\r
74// Wait for port reset, refers to specification\r
75// [USB20-7.1.7.5, it says 10ms for hub and 50ms for\r
76// root hub]\r
77//\r
78// According to USB2.0, Chapter 11.5.1.5 Resetting,\r
79// the worst case for TDRST is 20ms\r
80//\r
81#define USB_SET_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)\r
82#define USB_SET_ROOT_PORT_RESET_STALL (50 * USB_BUS_1_MILLISECOND)\r
83\r
84//\r
85// Wait for clear roothub port reset, set by experience\r
86//\r
87#define USB_CLR_ROOT_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)\r
88\r
89//\r
90// Wait for port statue reg change, set by experience\r
91//\r
92#define USB_WAIT_PORT_STS_CHANGE_STALL (100)\r
93\r
94//\r
d1102dba 95// Host software return timeout if port status doesn't change\r
d987459f
SZ
96// after 500ms(LOOP * STALL = 5000 * 0.1ms), set by experience\r
97//\r
98#define USB_WAIT_PORT_STS_CHANGE_LOOP 5000\r
99\r
100//\r
101// Wait for hub port power-on, refers to specification\r
102// [USB20-11.23.2]\r
103//\r
104#define USB_SET_PORT_POWER_STALL (2 * USB_BUS_1_MILLISECOND)\r
4b1bf81c 105\r
04910ceb
SZ
106//\r
107// Wait for set device address, refers to specification\r
108// [USB20-9.2.6.3, it says 2ms]\r
109//\r
110#define USB_SET_DEVICE_ADDRESS_STALL (2 * USB_BUS_1_MILLISECOND)\r
111\r
112//\r
113// Wait for get configuration descriptor, set by experience\r
114//\r
115#define USB_GET_CONFIG_DESCRIPTOR_STALL (1 * USB_BUS_1_MILLISECOND)\r
116\r
4b1bf81c 117/**\r
118 Submits control transfer to a target USB device.\r
d1102dba 119\r
4b1bf81c 120 @param PeiServices The pointer of EFI_PEI_SERVICES.\r
121 @param This The pointer of PEI_USB_IO_PPI.\r
122 @param Request USB device request to send.\r
123 @param Direction Specifies the data direction for the data stage.\r
ca243131
FT
124 @param Timeout Indicates the maximum timeout, in millisecond. If Timeout\r
125 is 0, then the caller must wait for the function to be\r
126 completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
4b1bf81c 127 @param Data Data buffer to be transmitted or received from USB device.\r
128 @param DataLength The size (in bytes) of the data buffer.\r
129\r
130 @retval EFI_SUCCESS Transfer was completed successfully.\r
131 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.\r
132 @retval EFI_INVALID_PARAMETER Some parameters are invalid.\r
133 @retval EFI_TIMEOUT Transfer failed due to timeout.\r
134 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139PeiUsbControlTransfer (\r
140 IN EFI_PEI_SERVICES **PeiServices,\r
141 IN PEI_USB_IO_PPI *This,\r
142 IN EFI_USB_DEVICE_REQUEST *Request,\r
143 IN EFI_USB_DATA_DIRECTION Direction,\r
144 IN UINT32 Timeout,\r
145 IN OUT VOID *Data, OPTIONAL\r
146 IN UINTN DataLength OPTIONAL\r
147 );\r
148\r
149/**\r
150 Submits bulk transfer to a bulk endpoint of a USB device.\r
d1102dba 151\r
4b1bf81c 152 @param PeiServices The pointer of EFI_PEI_SERVICES.\r
153 @param This The pointer of PEI_USB_IO_PPI.\r
154 @param DeviceEndpoint Endpoint number and its direction in bit 7.\r
d1102dba 155 @param Data A pointer to the buffer of data to transmit\r
4b1bf81c 156 from or receive into.\r
13a623cf 157 @param DataLength The length of the data buffer.\r
4b1bf81c 158 @param Timeout Indicates the maximum time, in millisecond, which the\r
ca243131
FT
159 transfer is allowed to complete. If Timeout is 0, then\r
160 the caller must wait for the function to be completed\r
161 until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
4b1bf81c 162\r
163 @retval EFI_SUCCESS The transfer was completed successfully.\r
164 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.\r
165 @retval EFI_INVALID_PARAMETER Parameters are invalid.\r
166 @retval EFI_TIMEOUT The transfer failed due to timeout.\r
167 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.\r
168\r
169**/\r
170EFI_STATUS\r
171EFIAPI\r
172PeiUsbBulkTransfer (\r
173 IN EFI_PEI_SERVICES **PeiServices,\r
174 IN PEI_USB_IO_PPI *This,\r
175 IN UINT8 DeviceEndpoint,\r
176 IN OUT VOID *Data,\r
177 IN OUT UINTN *DataLength,\r
178 IN UINTN Timeout\r
179 );\r
180\r
181/**\r
182 Get the usb interface descriptor.\r
183\r
184 @param PeiServices General-purpose services that are available to every PEIM.\r
185 @param This Indicates the PEI_USB_IO_PPI instance.\r
186 @param InterfaceDescriptor Request interface descriptor.\r
187\r
188\r
189 @retval EFI_SUCCESS Usb interface descriptor is obtained successfully.\r
190\r
191**/\r
192EFI_STATUS\r
193EFIAPI\r
194PeiUsbGetInterfaceDescriptor (\r
195 IN EFI_PEI_SERVICES **PeiServices,\r
196 IN PEI_USB_IO_PPI *This,\r
197 OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor\r
198 );\r
199\r
200/**\r
201 Get the usb endpoint descriptor.\r
202\r
203 @param PeiServices General-purpose services that are available to every PEIM.\r
204 @param This Indicates the PEI_USB_IO_PPI instance.\r
205 @param EndpointIndex The valid index of the specified endpoint.\r
206 @param EndpointDescriptor Request endpoint descriptor.\r
207\r
208 @retval EFI_SUCCESS Usb endpoint descriptor is obtained successfully.\r
209 @retval EFI_NOT_FOUND Usb endpoint descriptor is NOT found.\r
210\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214PeiUsbGetEndpointDescriptor (\r
215 IN EFI_PEI_SERVICES **PeiServices,\r
216 IN PEI_USB_IO_PPI *This,\r
217 IN UINT8 EndpointIndex,\r
218 OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor\r
219 );\r
220\r
221/**\r
222 Reset the port and re-configure the usb device.\r
223\r
224 @param PeiServices General-purpose services that are available to every PEIM.\r
225 @param This Indicates the PEI_USB_IO_PPI instance.\r
226\r
227 @retval EFI_SUCCESS Usb device is reset and configured successfully.\r
228 @retval Others Other failure occurs.\r
229\r
230**/\r
231EFI_STATUS\r
232EFIAPI\r
233PeiUsbPortReset (\r
234 IN EFI_PEI_SERVICES **PeiServices,\r
235 IN PEI_USB_IO_PPI *This\r
236 );\r
237\r
238/**\r
239 Send reset signal over the given root hub port.\r
d1102dba 240\r
4b1bf81c 241 @param PeiServices Describes the list of possible PEI Services.\r
242 @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.\r
243 @param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.\r
244 @param PortNum The port to be reset.\r
245 @param RetryIndex The retry times.\r
246\r
247**/\r
248VOID\r
249ResetRootPort (\r
250 IN EFI_PEI_SERVICES **PeiServices,\r
251 IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,\r
252 IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi,\r
253 IN UINT8 PortNum,\r
254 IN UINT8 RetryIndex\r
255 );\r
256\r
257#endif\r