From a9292c1363437b081ea72fd8f3b2ed075e2a7ef3 Mon Sep 17 00:00:00 2001 From: erictian Date: Wed, 14 Sep 2011 12:13:03 +0000 Subject: 1) remove wrong global variable usage because it will bring data corrupt if there are multiple XHCI host controllers. 2) coding style clean up. Signed-off-by: erictian Reviewed-by: ydong10 Reviewed-by: jshi19 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12351 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 24 ++++++++++++------------ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h | 7 ++++++- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) (limited to 'MdeModulePkg/Bus/Usb/UsbBusDxe') diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c index c3a9c734b8..63480f62a9 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -45,8 +45,6 @@ EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding = { NULL }; -UINT16 mMaxUsbDeviceNum = USB_MAX_DEVICES; - /** USB_IO function to execute a control transfer. This function will execute the USB transfer. If transfer @@ -112,7 +110,7 @@ UsbIoControlTransfer ( // Clear TT buffer when CTRL/BULK split transaction failes // Clear the TRANSLATOR TT buffer, not parent's buffer // - ASSERT (Dev->Translator.TranslatorHubAddress < mMaxUsbDeviceNum); + ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices); if (Dev->Translator.TranslatorHubAddress != 0) { UsbHubCtrlClearTTBuffer ( Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress], @@ -285,7 +283,7 @@ UsbIoBulkTransfer ( // Clear TT buffer when CTRL/BULK split transaction failes. // Clear the TRANSLATOR TT buffer, not parent's buffer // - ASSERT (Dev->Translator.TranslatorHubAddress < mMaxUsbDeviceNum); + ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices); if (Dev->Translator.TranslatorHubAddress != 0) { UsbHubCtrlClearTTBuffer ( Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress], @@ -913,8 +911,9 @@ UsbBusBuildProtocol ( return EFI_OUT_OF_RESOURCES; } - UsbBus->Signature = USB_BUS_SIGNATURE; - UsbBus->HostHandle = Controller; + UsbBus->Signature = USB_BUS_SIGNATURE; + UsbBus->HostHandle = Controller; + UsbBus->MaxDevices = USB_MAX_DEVICES; Status = gBS->OpenProtocol ( Controller, @@ -966,12 +965,12 @@ UsbBusBuildProtocol ( } if (!EFI_ERROR (Status)) { + // + // The EFI_USB2_HC_PROTOCOL is produced for XHCI support. + // Then its max supported devices are 256. Otherwise it's 128. + // if (UsbBus->Usb2Hc->MajorRevision == 0x3) { - // - // The EFI_USB2_HC_PROTOCOL is produced for XHCI support. - // Then its max supported devices are 256. - // - mMaxUsbDeviceNum = 256; + UsbBus->MaxDevices = 256; } } @@ -1444,7 +1443,8 @@ UsbBusControllerDriverStop ( mUsbRootHubApi.Release (RootIf); - for (Index = 1; Index < mMaxUsbDeviceNum; Index++) { + ASSERT (Bus->MaxDevices <= 256); + for (Index = 1; Index < Bus->MaxDevices; Index++) { if (Bus->Devices[Index] != NULL) { UsbRemoveDevice (Bus->Devices[Index]); } diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h index ce041b9f79..14454da28a 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h @@ -246,6 +246,12 @@ struct _USB_BUS { EFI_USB2_HC_PROTOCOL *Usb2Hc; EFI_USB_HC_PROTOCOL *UsbHc; + // + // Recorded the max supported usb devices. + // XHCI can support up to 255 devices. + // EHCI/UHCI/OHCI supports up to 127 devices. + // + UINT32 MaxDevices; // // An array of device that is on the bus. Devices[0] is // for root hub. Device with address i is at Devices[i]. @@ -747,7 +753,6 @@ UsbBusControllerDriverStop ( IN EFI_HANDLE *ChildHandleBuffer ); -extern UINT16 mMaxUsbDeviceNum; extern EFI_USB_IO_PROTOCOL mUsbIoProtocol; extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding; extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName; diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index aacc67fef1..b7141a0ab3 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -548,7 +548,7 @@ UsbRemoveDevice ( // Remove all the devices on its downstream ports. Search from devices[1]. // Devices[0] is the root hub. // - for (Index = 1; Index < mMaxUsbDeviceNum; Index++) { + for (Index = 1; Index < Bus->MaxDevices; Index++) { Child = Bus->Devices[Index]; if ((Child == NULL) || (Child->ParentAddr != Device->Address)) { @@ -567,7 +567,7 @@ UsbRemoveDevice ( DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address)); - ASSERT (Device->Address < mMaxUsbDeviceNum); + ASSERT (Device->Address < Bus->MaxDevices); Bus->Devices[Device->Address] = NULL; UsbFreeDevice (Device); @@ -599,7 +599,7 @@ UsbFindChild ( // // Start checking from device 1, device 0 is the root hub // - for (Index = 1; Index < mMaxUsbDeviceNum; Index++) { + for (Index = 1; Index < Bus->MaxDevices; Index++) { Device = Bus->Devices[Index]; if ((Device != NULL) && (Device->ParentAddr == HubIf->Device->Address) && @@ -639,11 +639,11 @@ UsbEnumerateNewDev ( UINT8 Config; EFI_STATUS Status; - Address = mMaxUsbDeviceNum; Parent = HubIf->Device; Bus = Parent->Bus; - HubApi = HubIf->HubApi; - + HubApi = HubIf->HubApi; + Address = Bus->MaxDevices; + gBS->Stall (USB_WAIT_PORT_STABLE_STALL); // @@ -731,13 +731,14 @@ UsbEnumerateNewDev ( // status stage with default address, then switches to new address. // ADDRESS state. Address zero is reserved for root hub. // - for (Address = 1; Address < mMaxUsbDeviceNum; Address++) { + ASSERT (Bus->MaxDevices <= 256); + for (Address = 1; Address < Bus->MaxDevices; Address++) { if (Bus->Devices[Address] == NULL) { break; } } - if (Address == mMaxUsbDeviceNum) { + if (Address >= Bus->MaxDevices) { DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port)); Status = EFI_ACCESS_DENIED; @@ -808,7 +809,7 @@ UsbEnumerateNewDev ( return EFI_SUCCESS; ON_ERROR: - if (Address != mMaxUsbDeviceNum) { + if (Address != Bus->MaxDevices) { Bus->Devices[Address] = NULL; } -- cgit v1.2.3