]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index 35da41b3e39eab379ee04067e40e7bc0cb3e75a3..30bf43cb36070951d19beb107825e358bcb7c8c3 100644 (file)
@@ -2,7 +2,7 @@
 \r
     Usb Bus Driver Binding and Bus IO Protocol.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -15,11 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "UsbBus.h"\r
 \r
-//\r
-// USB_BUS_PROTOCOL is only used to locate USB_BUS\r
-//\r
-EFI_GUID  mUsbBusProtocolGuid = EFI_USB_BUS_PROTOCOL_GUID;\r
-\r
 EFI_USB_IO_PROTOCOL mUsbIoProtocol = {\r
   UsbIoControlTransfer,\r
   UsbIoBulkTransfer,\r
@@ -45,7 +40,6 @@ EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding = {
   NULL\r
 };\r
 \r
-\r
 /**\r
   USB_IO function to execute a control transfer. This\r
   function will execute the USB transfer. If transfer\r
@@ -111,7 +105,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 < USB_MAX_DEVICES);\r
+    ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);\r
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -284,7 +278,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 < USB_MAX_DEVICES);\r
+    ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);\r
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -817,7 +811,6 @@ UsbIoPortReset (
   USB_INTERFACE           *UsbIf;\r
   USB_INTERFACE           *HubIf;\r
   USB_DEVICE              *Dev;\r
-  UINT8                   Address;\r
   EFI_TPL                 OldTpl;\r
   EFI_STATUS              Status;\r
 \r
@@ -842,27 +835,26 @@ UsbIoPortReset (
   }\r
 \r
   //\r
-  // Reset the device to its current address. The device now has a\r
-  // address of ZERO, so need to set Dev->Address to zero first for\r
-  // host to communicate with the device\r
+  // Reset the device to its current address. The device now has an address\r
+  // of ZERO after port reset, so need to set Dev->Address to the device again for\r
+  // host to communicate with it.\r
   //\r
-  Address       = Dev->Address;\r
-  Dev->Address  = 0;\r
-  Status        = UsbSetAddress (Dev, Address);\r
+  Status  = UsbSetAddress (Dev, Dev->Address);\r
 \r
   gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);\r
   \r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // It may fail due to device disconnection or other reasons.\r
+    //\r
     DEBUG (( EFI_D_ERROR, "UsbIoPortReset: failed to set address for device %d - %r\n",\r
-                Address, Status));\r
+                Dev->Address, Status));\r
 \r
     goto ON_EXIT;\r
   }\r
 \r
-  Dev->Address  = Address;\r
+  DEBUG (( EFI_D_INFO, "UsbIoPortReset: device is now ADDRESSED at %d\n", Dev->Address));\r
 \r
-  DEBUG (( EFI_D_INFO, "UsbIoPortReset: device is now ADDRESSED at %d\n", Address));\r
-  \r
   //\r
   // Reset the current active configure, after this device\r
   // is in CONFIGURED state.\r
@@ -872,7 +864,7 @@ UsbIoPortReset (
 \r
     if (EFI_ERROR (Status)) {\r
       DEBUG (( EFI_D_ERROR, "UsbIoPortReset: failed to set configure for device %d - %r\n",\r
-                  Address, Status));\r
+                  Dev->Address, Status));\r
     }\r
   }\r
 \r
@@ -914,8 +906,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,6 +959,16 @@ UsbBusBuildProtocol (
     goto CLOSE_HC;\r
   }\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
+      UsbBus->MaxDevices = 256;\r
+    }\r
+  }\r
+\r
   UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
   UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
 \r
@@ -974,7 +977,7 @@ UsbBusBuildProtocol (
   //\r
   Status = gBS->InstallProtocolInterface (\r
                   &Controller,\r
-                  &mUsbBusProtocolGuid,\r
+                  &gEfiCallerIdGuid,\r
                   EFI_NATIVE_INTERFACE,\r
                   &UsbBus->BusId\r
                   );\r
@@ -1011,6 +1014,7 @@ UsbBusBuildProtocol (
   RootHub->Bus            = UsbBus;\r
   RootHub->NumOfInterface = 1;\r
   RootHub->Interfaces[0]  = RootIf;\r
+  RootHub->Tier           = 0;\r
   RootIf->Signature       = USB_INTERFACE_SIGNATURE;\r
   RootIf->Device          = RootHub;\r
   RootIf->DevicePath      = UsbBus->DevicePath;\r
@@ -1036,7 +1040,7 @@ FREE_ROOTHUB:
   }\r
 \r
 UNINSTALL_USBBUS:\r
-  gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &UsbBus->BusId);\r
+  gBS->UninstallProtocolInterface (Controller, &gEfiCallerIdGuid, &UsbBus->BusId);\r
 \r
 CLOSE_HC:\r
   if (UsbBus->Usb2Hc != NULL) {\r
@@ -1268,7 +1272,7 @@ UsbBusControllerDriverStart (
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
-                  &mUsbBusProtocolGuid,\r
+                  &gEfiCallerIdGuid,\r
                   (VOID **) &UsbBusId,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
@@ -1279,6 +1283,7 @@ UsbBusControllerDriverStart (
     //\r
     // If first start, build the bus execute environment and install bus protocol\r
     //\r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_IO_BUS_USB | EFI_P_PC_ENABLE));\r
     Status = UsbBusBuildProtocol (This, Controller, RemainingDevicePath);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1288,7 +1293,7 @@ UsbBusControllerDriverStart (
     //\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
-                    &mUsbBusProtocolGuid,\r
+                    &gEfiCallerIdGuid,\r
                     (VOID **) &UsbBusId,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
@@ -1407,7 +1412,7 @@ UsbBusControllerDriverStop (
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
-                  &mUsbBusProtocolGuid,\r
+                  &gEfiCallerIdGuid,\r
                   (VOID **) &BusId,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
@@ -1433,7 +1438,8 @@ UsbBusControllerDriverStop (
 \r
   mUsbRootHubApi.Release (RootIf);\r
 \r
-  for (Index = 1; Index < USB_MAX_DEVICES; 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
@@ -1449,7 +1455,7 @@ UsbBusControllerDriverStop (
   //\r
   // Uninstall the bus identifier and close USB_HC/USB2_HC protocols\r
   //\r
-  gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &Bus->BusId);\r
+  gBS->UninstallProtocolInterface (Controller, &gEfiCallerIdGuid, &Bus->BusId);\r
 \r
   if (Bus->Usb2Hc != NULL) {\r
     gBS->CloseProtocol (\r