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