public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 1/1] MdeModulePkg: UsbBusDxe: Rebuild Descriptor Table
@ 2023-07-07 17:07 brit.chesley
  2023-07-31  7:36 ` [edk2-devel] " Wu, Hao A
  0 siblings, 1 reply; 7+ messages in thread
From: brit.chesley @ 2023-07-07 17:07 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Liming Gao, Hao A Wu, Ray Ni, Abner Chang

From: Britton Chesley <Brit.Chesley@amd.com>

Fixed a bug which led to an ASSERT due to the USB device context being
maintained after a port reset, but the underlying XHCI context was
uninitialized. Specifically, Xhc->UsbDevContext is freed after a reset
and only re-allocates the default [0] enpoint transfer ring. Added build descriptor table call in UsbIoPortReset. BZ 4456

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Abner Chang <Abner.Chang@amd.com>
Signed-off-by: Britton Chesley <Brit.Chesley@amd.com>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 26 ++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index c25f3cc2f279..a5b798bd8d6c 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -821,6 +821,7 @@ UsbIoPortReset (
   EFI_TPL        OldTpl;
   EFI_STATUS     Status;
   UINT8          DevAddress;
+  UINT8          Config;
 
   OldTpl = gBS->RaiseTPL (USB_BUS_TPL);
 
@@ -882,8 +883,26 @@ UsbIoPortReset (
   // is in CONFIGURED state.
   //
   if (Dev->ActiveConfig != NULL) {
-    Status = UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationValue);
+    UsbFreeDevDesc (Dev->DevDesc);
 
+    Status = UsbRemoveConfig (Dev);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to remove configuration - %r\n", Status));
+    }
+
+    Status = UsbGetMaxPacketSize0 (Dev);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to get max packet size - %r\n", Status));
+    }
+
+    Status = UsbBuildDescTable (Dev);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to build descriptor table - %r\n", Status));
+    }
+
+    Config = Dev->DevDesc->Configs[0]->Desc.ConfigurationValue;
+
+    Status = UsbSetConfig (Dev, Config);
     if (EFI_ERROR (Status)) {
       DEBUG ((
         DEBUG_ERROR,
@@ -892,6 +911,11 @@ UsbIoPortReset (
         Status
         ));
     }
+
+    Status = UsbSelectConfig (Dev, Config);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to set configuration - %r\n", Status));
+    }
   }
 
 ON_EXIT:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-19  1:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07 17:07 [PATCH v2 1/1] MdeModulePkg: UsbBusDxe: Rebuild Descriptor Table brit.chesley
2023-07-31  7:36 ` [edk2-devel] " Wu, Hao A
2023-08-16 16:49   ` Chesley, Brit via groups.io
2024-06-18  2:50     ` Chang, Abner via groups.io
2024-06-18  5:37       ` 回复: " gaoliming via groups.io
2024-06-18  5:44         ` Chang, Abner via groups.io
2024-06-19  1:09         ` Chang, Abner via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox