]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Usb Hub Request Support In PEI Phase\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | \r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include "UsbPeim.h"\r | |
11 | #include "HubPeim.h"\r | |
12 | #include "PeiUsbLib.h"\r | |
13 | \r | |
14 | /**\r | |
15 | Get a given hub port status.\r | |
16 | \r | |
17 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
18 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
19 | @param Port Usb hub port number (starting from 1).\r | |
20 | @param PortStatus Current Hub port status and change status.\r | |
21 | \r | |
22 | @retval EFI_SUCCESS Port status is obtained successfully.\r | |
23 | @retval EFI_DEVICE_ERROR Cannot get the port status due to a hardware error.\r | |
24 | @retval Others Other failure occurs.\r | |
25 | \r | |
26 | **/\r | |
27 | EFI_STATUS\r | |
28 | PeiHubGetPortStatus (\r | |
29 | IN EFI_PEI_SERVICES **PeiServices,\r | |
30 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
31 | IN UINT8 Port,\r | |
32 | OUT UINT32 *PortStatus\r | |
33 | )\r | |
34 | {\r | |
35 | EFI_USB_DEVICE_REQUEST DeviceRequest;\r | |
36 | \r | |
37 | ZeroMem (&DeviceRequest, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
38 | \r | |
39 | //\r | |
40 | // Fill Device request packet\r | |
41 | //\r | |
42 | DeviceRequest.RequestType = USB_HUB_GET_PORT_STATUS_REQ_TYPE;\r | |
43 | DeviceRequest.Request = USB_HUB_GET_PORT_STATUS;\r | |
44 | DeviceRequest.Index = Port;\r | |
45 | DeviceRequest.Length = (UINT16)sizeof (UINT32);\r | |
46 | \r | |
47 | return UsbIoPpi->UsbControlTransfer (\r | |
48 | PeiServices,\r | |
49 | UsbIoPpi,\r | |
50 | &DeviceRequest,\r | |
51 | EfiUsbDataIn,\r | |
52 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
53 | PortStatus,\r | |
54 | sizeof (UINT32)\r | |
55 | );\r | |
56 | }\r | |
57 | \r | |
58 | /**\r | |
59 | Set specified feature to a given hub port.\r | |
60 | \r | |
61 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
62 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
63 | @param Port Usb hub port number (starting from 1).\r | |
64 | @param Value New feature value.\r | |
65 | \r | |
66 | @retval EFI_SUCCESS Port feature is set successfully.\r | |
67 | @retval EFI_DEVICE_ERROR Cannot set the port feature due to a hardware error.\r | |
68 | @retval Others Other failure occurs.\r | |
69 | \r | |
70 | **/\r | |
71 | EFI_STATUS\r | |
72 | PeiHubSetPortFeature (\r | |
73 | IN EFI_PEI_SERVICES **PeiServices,\r | |
74 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
75 | IN UINT8 Port,\r | |
76 | IN UINT8 Value\r | |
77 | )\r | |
78 | {\r | |
79 | EFI_USB_DEVICE_REQUEST DeviceRequest;\r | |
80 | \r | |
81 | ZeroMem (&DeviceRequest, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
82 | \r | |
83 | //\r | |
84 | // Fill Device request packet\r | |
85 | //\r | |
86 | DeviceRequest.RequestType = USB_HUB_SET_PORT_FEATURE_REQ_TYPE;\r | |
87 | DeviceRequest.Request = USB_HUB_SET_PORT_FEATURE;\r | |
88 | DeviceRequest.Value = Value;\r | |
89 | DeviceRequest.Index = Port;\r | |
90 | \r | |
91 | return UsbIoPpi->UsbControlTransfer (\r | |
92 | PeiServices,\r | |
93 | UsbIoPpi,\r | |
94 | &DeviceRequest,\r | |
95 | EfiUsbNoData,\r | |
96 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
97 | NULL,\r | |
98 | 0\r | |
99 | );\r | |
100 | }\r | |
101 | \r | |
102 | /**\r | |
103 | Clear specified feature on a given hub port.\r | |
104 | \r | |
105 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
106 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
107 | @param Port Usb hub port number (starting from 1).\r | |
108 | @param Value Feature value that will be cleared from the hub port.\r | |
109 | \r | |
110 | @retval EFI_SUCCESS Port feature is cleared successfully.\r | |
111 | @retval EFI_DEVICE_ERROR Cannot clear the port feature due to a hardware error.\r | |
112 | @retval Others Other failure occurs.\r | |
113 | \r | |
114 | **/\r | |
115 | EFI_STATUS\r | |
116 | PeiHubClearPortFeature (\r | |
117 | IN EFI_PEI_SERVICES **PeiServices,\r | |
118 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
119 | IN UINT8 Port,\r | |
120 | IN UINT8 Value\r | |
121 | )\r | |
122 | {\r | |
123 | EFI_USB_DEVICE_REQUEST DeviceRequest;\r | |
124 | \r | |
125 | ZeroMem (&DeviceRequest, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
126 | \r | |
127 | //\r | |
128 | // Fill Device request packet\r | |
129 | //\r | |
130 | DeviceRequest.RequestType = USB_HUB_CLEAR_FEATURE_PORT_REQ_TYPE;\r | |
131 | DeviceRequest.Request = USB_HUB_CLEAR_FEATURE_PORT;\r | |
132 | DeviceRequest.Value = Value;\r | |
133 | DeviceRequest.Index = Port;\r | |
134 | \r | |
135 | return UsbIoPpi->UsbControlTransfer (\r | |
136 | PeiServices,\r | |
137 | UsbIoPpi,\r | |
138 | &DeviceRequest,\r | |
139 | EfiUsbNoData,\r | |
140 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
141 | NULL,\r | |
142 | 0\r | |
143 | );\r | |
144 | }\r | |
145 | \r | |
146 | /**\r | |
147 | Get a given hub status.\r | |
148 | \r | |
149 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
150 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
151 | @param HubStatus Current Hub status and change status.\r | |
152 | \r | |
153 | @retval EFI_SUCCESS Hub status is obtained successfully.\r | |
154 | @retval EFI_DEVICE_ERROR Cannot get the hub status due to a hardware error.\r | |
155 | @retval Others Other failure occurs.\r | |
156 | \r | |
157 | **/\r | |
158 | EFI_STATUS\r | |
159 | PeiHubGetHubStatus (\r | |
160 | IN EFI_PEI_SERVICES **PeiServices,\r | |
161 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
162 | OUT UINT32 *HubStatus\r | |
163 | )\r | |
164 | {\r | |
165 | EFI_USB_DEVICE_REQUEST DeviceRequest;\r | |
166 | \r | |
167 | ZeroMem (&DeviceRequest, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
168 | \r | |
169 | //\r | |
170 | // Fill Device request packet\r | |
171 | //\r | |
172 | DeviceRequest.RequestType = USB_HUB_GET_HUB_STATUS_REQ_TYPE;\r | |
173 | DeviceRequest.Request = USB_HUB_GET_HUB_STATUS;\r | |
174 | DeviceRequest.Length = (UINT16)sizeof (UINT32);\r | |
175 | \r | |
176 | return UsbIoPpi->UsbControlTransfer (\r | |
177 | PeiServices,\r | |
178 | UsbIoPpi,\r | |
179 | &DeviceRequest,\r | |
180 | EfiUsbDataIn,\r | |
181 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
182 | HubStatus,\r | |
183 | sizeof (UINT32)\r | |
184 | );\r | |
185 | }\r | |
186 | \r | |
187 | /**\r | |
188 | Clear specified feature on a given hub.\r | |
189 | \r | |
190 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
191 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
192 | @param Value Feature value that will be cleared from the hub port.\r | |
193 | \r | |
194 | @retval EFI_SUCCESS Hub feature is cleared successfully.\r | |
195 | @retval EFI_DEVICE_ERROR Cannot clear the hub feature due to a hardware error.\r | |
196 | @retval Others Other failure occurs.\r | |
197 | \r | |
198 | **/\r | |
199 | EFI_STATUS\r | |
200 | PeiHubClearHubFeature (\r | |
201 | IN EFI_PEI_SERVICES **PeiServices,\r | |
202 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
203 | IN UINT8 Value\r | |
204 | )\r | |
205 | {\r | |
206 | EFI_USB_DEVICE_REQUEST DeviceRequest;\r | |
207 | \r | |
208 | ZeroMem (&DeviceRequest, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
209 | \r | |
210 | //\r | |
211 | // Fill Device request packet\r | |
212 | //\r | |
213 | DeviceRequest.RequestType = USB_HUB_CLEAR_FEATURE_REQ_TYPE;\r | |
214 | DeviceRequest.Request = USB_HUB_CLEAR_FEATURE;\r | |
215 | DeviceRequest.Value = Value;\r | |
216 | \r | |
217 | return UsbIoPpi->UsbControlTransfer (\r | |
218 | PeiServices,\r | |
219 | UsbIoPpi,\r | |
220 | &DeviceRequest,\r | |
221 | EfiUsbNoData,\r | |
222 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
223 | NULL,\r | |
224 | 0\r | |
225 | );\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | Get a given (SuperSpeed) hub descriptor.\r | |
230 | \r | |
231 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
232 | @param PeiUsbDevice Indicates the hub controller device.\r | |
233 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
234 | @param DescriptorSize The length of Hub Descriptor buffer.\r | |
235 | @param HubDescriptor Caller allocated buffer to store the hub descriptor if\r | |
236 | successfully returned.\r | |
237 | \r | |
238 | @retval EFI_SUCCESS Hub descriptor is obtained successfully.\r | |
239 | @retval EFI_DEVICE_ERROR Cannot get the hub descriptor due to a hardware error.\r | |
240 | @retval Others Other failure occurs.\r | |
241 | \r | |
242 | **/\r | |
243 | EFI_STATUS\r | |
244 | PeiGetHubDescriptor (\r | |
245 | IN EFI_PEI_SERVICES **PeiServices,\r | |
246 | IN PEI_USB_DEVICE *PeiUsbDevice,\r | |
247 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
248 | IN UINTN DescriptorSize,\r | |
249 | OUT EFI_USB_HUB_DESCRIPTOR *HubDescriptor\r | |
250 | )\r | |
251 | {\r | |
252 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
253 | UINT8 DescType;\r | |
254 | \r | |
255 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
256 | \r | |
257 | DescType = (PeiUsbDevice->DeviceSpeed == EFI_USB_SPEED_SUPER) ?\r | |
258 | USB_DT_SUPERSPEED_HUB :\r | |
259 | USB_DT_HUB;\r | |
260 | \r | |
261 | //\r | |
262 | // Fill Device request packet\r | |
263 | //\r | |
264 | DevReq.RequestType = USB_RT_HUB | 0x80;\r | |
265 | DevReq.Request = USB_HUB_GET_DESCRIPTOR;\r | |
266 | DevReq.Value = (UINT16)(DescType << 8);\r | |
267 | DevReq.Length = (UINT16)DescriptorSize;\r | |
268 | \r | |
269 | return UsbIoPpi->UsbControlTransfer (\r | |
270 | PeiServices,\r | |
271 | UsbIoPpi,\r | |
272 | &DevReq,\r | |
273 | EfiUsbDataIn,\r | |
274 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
275 | HubDescriptor,\r | |
276 | (UINT16)DescriptorSize\r | |
277 | );\r | |
278 | }\r | |
279 | \r | |
280 | /**\r | |
281 | Read the whole usb hub descriptor. It is necessary\r | |
282 | to do it in two steps because hub descriptor is of\r | |
283 | variable length.\r | |
284 | \r | |
285 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
286 | @param PeiUsbDevice Indicates the hub controller device.\r | |
287 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
288 | @param HubDescriptor Caller allocated buffer to store the hub descriptor if\r | |
289 | successfully returned.\r | |
290 | \r | |
291 | @retval EFI_SUCCESS Hub descriptor is obtained successfully.\r | |
292 | @retval EFI_DEVICE_ERROR Cannot get the hub descriptor due to a hardware error.\r | |
293 | @retval Others Other failure occurs.\r | |
294 | \r | |
295 | **/\r | |
296 | EFI_STATUS\r | |
297 | PeiUsbHubReadDesc (\r | |
298 | IN EFI_PEI_SERVICES **PeiServices,\r | |
299 | IN PEI_USB_DEVICE *PeiUsbDevice,\r | |
300 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
301 | OUT EFI_USB_HUB_DESCRIPTOR *HubDescriptor\r | |
302 | )\r | |
303 | {\r | |
304 | EFI_STATUS Status;\r | |
305 | \r | |
306 | //\r | |
307 | // First get the hub descriptor length\r | |
308 | //\r | |
309 | Status = PeiGetHubDescriptor (PeiServices, PeiUsbDevice, UsbIoPpi, 2, HubDescriptor);\r | |
310 | \r | |
311 | if (EFI_ERROR (Status)) {\r | |
312 | return Status;\r | |
313 | }\r | |
314 | \r | |
315 | //\r | |
316 | // Get the whole hub descriptor\r | |
317 | //\r | |
318 | return PeiGetHubDescriptor (PeiServices, PeiUsbDevice, UsbIoPpi, HubDescriptor->Length, HubDescriptor);\r | |
319 | }\r | |
320 | \r | |
321 | /**\r | |
322 | USB hub control transfer to set the hub depth.\r | |
323 | \r | |
324 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
325 | @param PeiUsbDevice Indicates the hub controller device.\r | |
326 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
327 | \r | |
328 | @retval EFI_SUCCESS Depth of the hub is set.\r | |
329 | @retval Others Failed to set the depth.\r | |
330 | \r | |
331 | **/\r | |
332 | EFI_STATUS\r | |
333 | PeiUsbHubCtrlSetHubDepth (\r | |
334 | IN EFI_PEI_SERVICES **PeiServices,\r | |
335 | IN PEI_USB_DEVICE *PeiUsbDevice,\r | |
336 | IN PEI_USB_IO_PPI *UsbIoPpi\r | |
337 | )\r | |
338 | {\r | |
339 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
340 | \r | |
341 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
342 | \r | |
343 | //\r | |
344 | // Fill Device request packet\r | |
345 | //\r | |
346 | DevReq.RequestType = USB_RT_HUB;\r | |
347 | DevReq.Request = USB_HUB_REQ_SET_DEPTH;\r | |
348 | DevReq.Value = PeiUsbDevice->Tier;\r | |
349 | DevReq.Length = 0;\r | |
350 | \r | |
351 | return UsbIoPpi->UsbControlTransfer (\r | |
352 | PeiServices,\r | |
353 | UsbIoPpi,\r | |
354 | &DevReq,\r | |
355 | EfiUsbNoData,\r | |
356 | PcdGet32 (PcdUsbTransferTimeoutValue),\r | |
357 | NULL,\r | |
358 | 0\r | |
359 | );\r | |
360 | }\r | |
361 | \r | |
362 | /**\r | |
363 | Configure a given hub.\r | |
364 | \r | |
365 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
366 | @param PeiUsbDevice Indicating the hub controller device that will be configured\r | |
367 | \r | |
368 | @retval EFI_SUCCESS Hub configuration is done successfully.\r | |
369 | @retval EFI_DEVICE_ERROR Cannot configure the hub due to a hardware error.\r | |
370 | \r | |
371 | **/\r | |
372 | EFI_STATUS\r | |
373 | PeiDoHubConfig (\r | |
374 | IN EFI_PEI_SERVICES **PeiServices,\r | |
375 | IN PEI_USB_DEVICE *PeiUsbDevice\r | |
376 | )\r | |
377 | {\r | |
378 | UINT8 HubDescBuffer[256];\r | |
379 | EFI_USB_HUB_DESCRIPTOR *HubDescriptor;\r | |
380 | EFI_STATUS Status;\r | |
381 | EFI_USB_HUB_STATUS HubStatus;\r | |
382 | UINTN Index;\r | |
383 | PEI_USB_IO_PPI *UsbIoPpi;\r | |
384 | \r | |
385 | UsbIoPpi = &PeiUsbDevice->UsbIoPpi;\r | |
386 | \r | |
387 | //\r | |
388 | // The length field of descriptor is UINT8 type, so the buffer\r | |
389 | // with 256 bytes is enough to hold the descriptor data.\r | |
390 | //\r | |
391 | HubDescriptor = (EFI_USB_HUB_DESCRIPTOR *)HubDescBuffer;\r | |
392 | \r | |
393 | //\r | |
394 | // Get the hub descriptor\r | |
395 | //\r | |
396 | Status = PeiUsbHubReadDesc (\r | |
397 | PeiServices,\r | |
398 | PeiUsbDevice,\r | |
399 | UsbIoPpi,\r | |
400 | HubDescriptor\r | |
401 | );\r | |
402 | if (EFI_ERROR (Status)) {\r | |
403 | return EFI_DEVICE_ERROR;\r | |
404 | }\r | |
405 | \r | |
406 | PeiUsbDevice->DownStreamPortNo = HubDescriptor->NbrPorts;\r | |
407 | \r | |
408 | if (PeiUsbDevice->DeviceSpeed == EFI_USB_SPEED_SUPER) {\r | |
409 | DEBUG ((DEBUG_INFO, "PeiDoHubConfig: Set Hub Depth as 0x%x\n", PeiUsbDevice->Tier));\r | |
410 | PeiUsbHubCtrlSetHubDepth (\r | |
411 | PeiServices,\r | |
412 | PeiUsbDevice,\r | |
413 | UsbIoPpi\r | |
414 | );\r | |
415 | } else {\r | |
416 | //\r | |
417 | // Power all the hub ports\r | |
418 | //\r | |
419 | for (Index = 0; Index < PeiUsbDevice->DownStreamPortNo; Index++) {\r | |
420 | Status = PeiHubSetPortFeature (\r | |
421 | PeiServices,\r | |
422 | UsbIoPpi,\r | |
423 | (UINT8)(Index + 1),\r | |
424 | EfiUsbPortPower\r | |
425 | );\r | |
426 | if (EFI_ERROR (Status)) {\r | |
427 | DEBUG ((DEBUG_ERROR, "PeiDoHubConfig: PeiHubSetPortFeature EfiUsbPortPower failed %x\n", Index));\r | |
428 | continue;\r | |
429 | }\r | |
430 | }\r | |
431 | \r | |
432 | DEBUG ((DEBUG_INFO, "PeiDoHubConfig: HubDescriptor.PwrOn2PwrGood: 0x%x\n", HubDescriptor->PwrOn2PwrGood));\r | |
433 | if (HubDescriptor->PwrOn2PwrGood > 0) {\r | |
434 | MicroSecondDelay (HubDescriptor->PwrOn2PwrGood * USB_SET_PORT_POWER_STALL);\r | |
435 | }\r | |
436 | \r | |
437 | //\r | |
438 | // Clear Hub Status Change\r | |
439 | //\r | |
440 | Status = PeiHubGetHubStatus (\r | |
441 | PeiServices,\r | |
442 | UsbIoPpi,\r | |
443 | (UINT32 *)&HubStatus\r | |
444 | );\r | |
445 | if (EFI_ERROR (Status)) {\r | |
446 | return EFI_DEVICE_ERROR;\r | |
447 | } else {\r | |
448 | //\r | |
449 | // Hub power supply change happens\r | |
450 | //\r | |
451 | if ((HubStatus.HubChangeStatus & HUB_CHANGE_LOCAL_POWER) != 0) {\r | |
452 | PeiHubClearHubFeature (\r | |
453 | PeiServices,\r | |
454 | UsbIoPpi,\r | |
455 | C_HUB_LOCAL_POWER\r | |
456 | );\r | |
457 | }\r | |
458 | \r | |
459 | //\r | |
460 | // Hub change overcurrent happens\r | |
461 | //\r | |
462 | if ((HubStatus.HubChangeStatus & HUB_CHANGE_OVERCURRENT) != 0) {\r | |
463 | PeiHubClearHubFeature (\r | |
464 | PeiServices,\r | |
465 | UsbIoPpi,\r | |
466 | C_HUB_OVER_CURRENT\r | |
467 | );\r | |
468 | }\r | |
469 | }\r | |
470 | }\r | |
471 | \r | |
472 | return EFI_SUCCESS;\r | |
473 | }\r | |
474 | \r | |
475 | /**\r | |
476 | Send reset signal over the given root hub port.\r | |
477 | \r | |
478 | @param PeiServices General-purpose services that are available to every PEIM.\r | |
479 | @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r | |
480 | @param PortNum Usb hub port number (starting from 1).\r | |
481 | \r | |
482 | **/\r | |
483 | VOID\r | |
484 | PeiResetHubPort (\r | |
485 | IN EFI_PEI_SERVICES **PeiServices,\r | |
486 | IN PEI_USB_IO_PPI *UsbIoPpi,\r | |
487 | IN UINT8 PortNum\r | |
488 | )\r | |
489 | {\r | |
490 | EFI_STATUS Status;\r | |
491 | UINTN Index;\r | |
492 | EFI_USB_PORT_STATUS HubPortStatus;\r | |
493 | \r | |
494 | MicroSecondDelay (100 * 1000);\r | |
495 | \r | |
496 | //\r | |
497 | // reset root port\r | |
498 | //\r | |
499 | PeiHubSetPortFeature (\r | |
500 | PeiServices,\r | |
501 | UsbIoPpi,\r | |
502 | PortNum,\r | |
503 | EfiUsbPortReset\r | |
504 | );\r | |
505 | \r | |
506 | //\r | |
507 | // Drive the reset signal for worst 20ms. Check USB 2.0 Spec\r | |
508 | // section 7.1.7.5 for timing requirements.\r | |
509 | //\r | |
510 | MicroSecondDelay (USB_SET_PORT_RESET_STALL);\r | |
511 | \r | |
512 | //\r | |
513 | // Check USB_PORT_STAT_C_RESET bit to see if the resetting state is done.\r | |
514 | //\r | |
515 | ZeroMem (&HubPortStatus, sizeof (EFI_USB_PORT_STATUS));\r | |
516 | \r | |
517 | for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {\r | |
518 | Status = PeiHubGetPortStatus (\r | |
519 | PeiServices,\r | |
520 | UsbIoPpi,\r | |
521 | PortNum,\r | |
522 | (UINT32 *)&HubPortStatus\r | |
523 | );\r | |
524 | \r | |
525 | if (EFI_ERROR (Status)) {\r | |
526 | return;\r | |
527 | }\r | |
528 | \r | |
529 | if (USB_BIT_IS_SET (HubPortStatus.PortChangeStatus, USB_PORT_STAT_C_RESET)) {\r | |
530 | break;\r | |
531 | }\r | |
532 | \r | |
533 | MicroSecondDelay (USB_WAIT_PORT_STS_CHANGE_STALL);\r | |
534 | }\r | |
535 | \r | |
536 | if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {\r | |
537 | DEBUG ((DEBUG_ERROR, "PeiResetHubPort: reset not finished in time on port %d\n", PortNum));\r | |
538 | return;\r | |
539 | }\r | |
540 | \r | |
541 | //\r | |
542 | // clear reset change root port\r | |
543 | //\r | |
544 | PeiHubClearPortFeature (\r | |
545 | PeiServices,\r | |
546 | UsbIoPpi,\r | |
547 | PortNum,\r | |
548 | EfiUsbPortResetChange\r | |
549 | );\r | |
550 | \r | |
551 | MicroSecondDelay (1 * 1000);\r | |
552 | \r | |
553 | PeiHubClearPortFeature (\r | |
554 | PeiServices,\r | |
555 | UsbIoPpi,\r | |
556 | PortNum,\r | |
557 | EfiUsbPortConnectChange\r | |
558 | );\r | |
559 | \r | |
560 | //\r | |
561 | // Set port enable\r | |
562 | //\r | |
563 | PeiHubSetPortFeature (\r | |
564 | PeiServices,\r | |
565 | UsbIoPpi,\r | |
566 | PortNum,\r | |
567 | EfiUsbPortEnable\r | |
568 | );\r | |
569 | \r | |
570 | //\r | |
571 | // Clear any change status\r | |
572 | //\r | |
573 | \r | |
574 | PeiHubClearPortFeature (\r | |
575 | PeiServices,\r | |
576 | UsbIoPpi,\r | |
577 | PortNum,\r | |
578 | EfiUsbPortEnableChange\r | |
579 | );\r | |
580 | \r | |
581 | MicroSecondDelay (10 * 1000);\r | |
582 | \r | |
583 | return;\r | |
584 | }\r |