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