From ea0e6d960eca06a4682db72e7914de8010b4f05d Mon Sep 17 00:00:00 2001 From: "Luo, Heng" Date: Fri, 23 Oct 2020 09:26:11 +0800 Subject: [PATCH] MdeModulePkg/XhciDxe: Error handle for USB slot initialization failure REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3007 Currently UsbDevContext is not cleaned up if USB slot initialization is failed, the wrong context data will affect next USB devices and the USB devices can not be enumerated. Need to disable slot if USB slot initialization is failed. Below test cases are passed on UpXtreme: a. USB 3.0 thumb drives can be recognized in UEFI shell b. SUT can boot to Puppylinux from USB3.0 mass storage, the storage can be recognized in linux c. Plug in a USB keyboard (hot plug) and enumeration is OK in UEFI shell and linux d. Plug in a USB mouse(hot plug) and enumeration is OK in linux. Cc: Ray Ni Cc: Hao A Wu Signed-off-by: Heng Luo Tested-by: Jon Hunter Reviewed-by: Jon Hunter Reviewed-by: Hao A Wu --- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index c0c374fc47..eed342bdb8 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -2,7 +2,8 @@ XHCI transfer scheduling routines. -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -2245,6 +2246,9 @@ XhcInitializeDeviceSlot ( DeviceAddress = (UINT8) ((DEVICE_CONTEXT *) OutputContext)->Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assigned successfully\n", DeviceAddress)); Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress; + } else { + DEBUG ((DEBUG_INFO, " Address %d assigned unsuccessfully\n")); + XhcDisableSlotCmd (Xhc, SlotId); } return Status; @@ -2455,7 +2459,11 @@ XhcInitializeDeviceSlot64 ( DeviceAddress = (UINT8) ((DEVICE_CONTEXT_64 *) OutputContext)->Slot.DeviceAddress; DEBUG ((EFI_D_INFO, " Address %d assigned successfully\n", DeviceAddress)); Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress; + } else { + DEBUG ((DEBUG_INFO, " Address %d assigned unsuccessfully\n")); + XhcDisableSlotCmd64 (Xhc, SlotId); } + return Status; }