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