]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index 2e5edeb0c3e985b0e162444b866c240473f904d9..90dcf61443dc29e378bb77f35a1f45880c9d9e0a 100644 (file)
@@ -2,8 +2,8 @@
 \r
     Usb Bus Driver Binding and Bus IO Protocol.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2009, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -61,7 +61,7 @@ EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding = {
   @param  UsbStatus              USB result\r
 \r
   @retval EFI_INVALID_PARAMETER  The parameters are invalid\r
-  @retval EFI_SUCCESS            The control transfer succeded.\r
+  @retval EFI_SUCCESS            The control transfer succeeded.\r
   @retval Others                 Failed to execute the transfer\r
 \r
 **/\r
@@ -111,6 +111,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
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -152,7 +153,7 @@ UsbIoControlTransfer (
   // should stop use its current UsbIo after calling this driver. The old\r
   // UsbIo will be uninstalled and new UsbIo be installed. We can't use\r
   // ReinstallProtocol since interfaces in different configuration may be\r
-  // completely irrellvant.\r
+  // completely irrelevant.\r
   //\r
   if ((Request->Request == USB_REQ_SET_CONFIG) &&\r
       (Request->RequestType == USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_STANDARD,\r
@@ -195,6 +196,7 @@ UsbIoControlTransfer (
     Status = UsbSelectSetting (UsbIf->IfDesc, (UINT8) Request->Value);\r
 \r
     if (!EFI_ERROR (Status)) {\r
+      ASSERT (UsbIf->IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING);\r
       UsbIf->IfSetting = UsbIf->IfDesc->Settings[UsbIf->IfDesc->ActiveIndex];\r
     }\r
   }\r
@@ -282,6 +284,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
     if (Dev->Translator.TranslatorHubAddress != 0) {\r
       UsbHubCtrlClearTTBuffer (\r
         Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],\r
@@ -751,6 +754,7 @@ UsbIoGetStringDescriptor (
   Status = EFI_NOT_FOUND;\r
 \r
   for (Index = 0; Index < Dev->TotalLangId; Index++) {\r
+    ASSERT (Index < USB_MAX_LANG_ID);\r
     if (Dev->LangId[Index] == LangID) {\r
       break;\r
     }\r
@@ -845,7 +849,8 @@ UsbIoPortReset (
   Address       = Dev->Address;\r
   Dev->Address  = 0;\r
   Status        = UsbSetAddress (Dev, Address);\r
-  Dev->Address  = Address;\r
+\r
+  gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);\r
   \r
   if (EFI_ERROR (Status)) {\r
     DEBUG (( EFI_D_ERROR, "UsbIoPortReset: failed to set address for device %d - %r\n",\r
@@ -854,7 +859,7 @@ UsbIoPortReset (
     goto ON_EXIT;\r
   }\r
 \r
-  gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);\r
+  Dev->Address  = Address;\r
 \r
   DEBUG (( EFI_D_INFO, "UsbIoPortReset: device is now ADDRESSED at %d\n", Address));\r
   \r
@@ -924,13 +929,13 @@ UsbBusBuildProtocol (
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to open device path %r\n", Status));\r
 \r
-    gBS->FreePool (UsbBus);\r
+    FreePool (UsbBus);\r
     return Status;\r
   }\r
 \r
   //\r
   // Get USB_HC2/USB_HC host controller protocol (EHCI/UHCI).\r
-  // This is for backward compatbility with EFI 1.x. In UEFI\r
+  // This is for backward compatibility with EFI 1.x. In UEFI\r
   // 2.x, USB_HC2 replaces USB_HC. We will open both USB_HC2\r
   // and USB_HC because EHCI driver will install both protocols\r
   // (for the same reason). If we don't consume both of them,\r
@@ -965,7 +970,7 @@ UsbBusBuildProtocol (
   UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
 \r
   //\r
-  // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
+  // Install an EFI_USB_BUS_PROTOCOL to host controller to identify it.\r
   //\r
   Status = gBS->InstallProtocolInterface (\r
                   &Controller,\r
@@ -998,7 +1003,7 @@ UsbBusBuildProtocol (
   RootIf = AllocateZeroPool (sizeof (USB_INTERFACE));\r
 \r
   if (RootIf == NULL) {\r
-    gBS->FreePool (RootHub);\r
+    FreePool (RootHub);\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto FREE_ROOTHUB;\r
   }\r
@@ -1024,10 +1029,10 @@ UsbBusBuildProtocol (
 \r
 FREE_ROOTHUB:\r
   if (RootIf != NULL) {\r
-    gBS->FreePool (RootIf);\r
+    FreePool (RootIf);\r
   }\r
   if (RootHub != NULL) {\r
-    gBS->FreePool (RootHub);\r
+    FreePool (RootHub);\r
   }\r
 \r
 UNINSTALL_USBBUS:\r
@@ -1056,7 +1061,7 @@ CLOSE_HC:
          This->DriverBindingHandle,\r
          Controller\r
          );\r
-  gBS->FreePool (UsbBus);\r
+  FreePool (UsbBus);\r
 \r
   DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to start bus driver %r\n", Status));\r
   return Status;\r
@@ -1120,42 +1125,28 @@ UsbBusControllerDriverSupported (
   // Check whether device path is valid\r
   //\r
   if (RemainingDevicePath != NULL) {\r
-    DevicePathNode.DevPath = RemainingDevicePath;\r
-\r
-    if ((DevicePathNode.DevPath->Type    != MESSAGING_DEVICE_PATH) ||\r
-        (DevicePathNode.DevPath->SubType != MSG_USB_DP &&\r
-         DevicePathNode.DevPath->SubType != MSG_USB_CLASS_DP\r
-         && DevicePathNode.DevPath->SubType != MSG_USB_WWID_DP\r
-         )) {\r
-\r
-      return EFI_UNSUPPORTED;\r
+    //\r
+    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // if yes, go on checking other conditions\r
+    //\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node,\r
+      // check its validation\r
+      //\r
+      DevicePathNode.DevPath = RemainingDevicePath;\r
+      \r
+      if ((DevicePathNode.DevPath->Type    != MESSAGING_DEVICE_PATH) ||\r
+          (DevicePathNode.DevPath->SubType != MSG_USB_DP &&\r
+           DevicePathNode.DevPath->SubType != MSG_USB_CLASS_DP\r
+           && DevicePathNode.DevPath->SubType != MSG_USB_WWID_DP\r
+           )) {\r
+      \r
+        return EFI_UNSUPPORTED;\r
+      }\r
     }\r
   }\r
 \r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &ParentDevicePath,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-\r
-  if (Status == EFI_ALREADY_STARTED) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  gBS->CloseProtocol (\r
-         Controller,\r
-         &gEfiDevicePathProtocolGuid,\r
-         This->DriverBindingHandle,\r
-         Controller\r
-         );\r
-\r
   //\r
   // Check whether USB_HC2 protocol is installed\r
   //\r
@@ -1167,45 +1158,80 @@ UsbBusControllerDriverSupported (
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-\r
   if (Status == EFI_ALREADY_STARTED) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (!EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If failed to open USB_HC2, fall back to USB_HC\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiUsbHcProtocolGuid,\r
+                    (VOID **) &UsbHc,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                    );\r
+    if (Status == EFI_ALREADY_STARTED) {\r
+      return EFI_SUCCESS;\r
+    }\r
+  \r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Close the USB_HC used to perform the supported test\r
+    //\r
     gBS->CloseProtocol (\r
           Controller,\r
-          &gEfiUsb2HcProtocolGuid,\r
+          &gEfiUsbHcProtocolGuid,\r
           This->DriverBindingHandle,\r
           Controller\r
           );\r
 \r
-    return EFI_SUCCESS;\r
-  }\r
+  } else {\r
 \r
+    //\r
+    // Close the USB_HC2 used to perform the supported test\r
+    //\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiUsb2HcProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+  }\r
\r
   //\r
-  // If failed to open USB_HC2, fall back to USB_HC\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
-                  &gEfiUsbHcProtocolGuid,\r
-                  (VOID **) &UsbHc,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-\r
   if (Status == EFI_ALREADY_STARTED) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Close protocol, don't use device path protocol in the Support() function\r
+    //\r
     gBS->CloseProtocol (\r
           Controller,\r
-          &gEfiUsbHcProtocolGuid,\r
+          &gEfiDevicePathProtocolGuid,\r
           This->DriverBindingHandle,\r
           Controller\r
           );\r
+\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   return Status;\r
@@ -1251,7 +1277,7 @@ UsbBusControllerDriverStart (
 \r
   if (EFI_ERROR (Status)) {\r
     //\r
-    // If first start, build the bus execute enviorment and install bus protocol\r
+    // If first start, build the bus execute environment and install bus protocol\r
     //\r
     Status = UsbBusBuildProtocol (This, Controller, RemainingDevicePath);\r
     if (EFI_ERROR (Status)) {\r
@@ -1279,6 +1305,16 @@ UsbBusControllerDriverStart (
     //\r
     // Save the passed in RemainingDevicePath this time\r
     //\r
+    if (RemainingDevicePath != NULL) {\r
+      if (IsDevicePathEnd (RemainingDevicePath)) {\r
+        //\r
+        // If RemainingDevicePath is the End of Device Path Node,\r
+        // skip enumerate any device and return EFI_SUCESSS\r
+        // \r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
     Status = UsbBusAddWantedUsbIoDP (UsbBusId, RemainingDevicePath);\r
     ASSERT (!EFI_ERROR (Status));\r
     //\r