]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
1) remove wrong global variable usage because it will bring data corrupt if there...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index c3a9c734b88a8b42efe9ab48f53e73d065dc50db..63480f62a9a5257f01afc32b9362de7ee36ec6cb 100644 (file)
@@ -45,8 +45,6 @@ EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding = {
   NULL\r
 };\r
 \r
-UINT16 mMaxUsbDeviceNum = USB_MAX_DEVICES;\r
-\r
 /**\r
   USB_IO function to execute a control transfer. This\r
   function will execute the USB transfer. If transfer\r
@@ -112,7 +110,7 @@ UsbIoControlTransfer (
     // Clear TT buffer when CTRL/BULK split transaction failes\r
     // Clear the TRANSLATOR TT buffer, not parent's buffer\r
     //\r
-    ASSERT (Dev->Translator.TranslatorHubAddress < mMaxUsbDeviceNum);\r
+    ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);\r
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -285,7 +283,7 @@ UsbIoBulkTransfer (
     // Clear TT buffer when CTRL/BULK split transaction failes.\r
     // Clear the TRANSLATOR TT buffer, not parent's buffer\r
     //\r
-    ASSERT (Dev->Translator.TranslatorHubAddress < mMaxUsbDeviceNum);\r
+    ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);\r
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -913,8 +911,9 @@ UsbBusBuildProtocol (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  UsbBus->Signature   = USB_BUS_SIGNATURE;\r
-  UsbBus->HostHandle  = Controller;\r
+  UsbBus->Signature  = USB_BUS_SIGNATURE;\r
+  UsbBus->HostHandle = Controller;\r
+  UsbBus->MaxDevices = USB_MAX_DEVICES;\r
 \r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
@@ -966,12 +965,12 @@ UsbBusBuildProtocol (
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
+    //\r
+    // The EFI_USB2_HC_PROTOCOL is produced for XHCI support.\r
+    // Then its max supported devices are 256. Otherwise it's 128.\r
+    //\r
     if (UsbBus->Usb2Hc->MajorRevision == 0x3) {\r
-      //\r
-      // The EFI_USB2_HC_PROTOCOL is produced for XHCI support.\r
-      // Then its max supported devices are 256.\r
-      //\r
-      mMaxUsbDeviceNum = 256;\r
+      UsbBus->MaxDevices = 256;\r
     }\r
   }\r
 \r
@@ -1444,7 +1443,8 @@ UsbBusControllerDriverStop (
 \r
   mUsbRootHubApi.Release (RootIf);\r
 \r
-  for (Index = 1; Index < mMaxUsbDeviceNum; Index++) {\r
+  ASSERT (Bus->MaxDevices <= 256);\r
+  for (Index = 1; Index < Bus->MaxDevices; Index++) {\r
     if (Bus->Devices[Index] != NULL) {\r
       UsbRemoveDevice (Bus->Devices[Index]);\r
     }\r