]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
Save original PCI attributes in start() function and restore it in Stop() for those...
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / Ehci.c
index 07a690edce0788237587137a6e9853cdbd29c3b6..32ae6b6cdcfd040f2ef004ab95c55beaf0577535 100644 (file)
@@ -133,7 +133,7 @@ EhcReset (
         goto ON_EXIT;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Clean up the asynchronous transfers, currently only\r
     // interrupt supports asynchronous operation.\r
@@ -262,9 +262,9 @@ EhcSetState (
 \r
     //\r
     // Software must not write a one to this field unless the host controller\r
-    // is in the Halted state. Doing so will yield undefined results. \r
+    // is in the Halted state. Doing so will yield undefined results.\r
     // refers to Spec[EHCI1.0-2.3.1]\r
-    // \r
+    //\r
     if (!EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_HALT)) {\r
       Status = EFI_DEVICE_ERROR;\r
       break;\r
@@ -454,7 +454,7 @@ EhcSetRootHubPortFeature (
         break;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Set one to PortReset bit must also set zero to PortEnable bit\r
     //\r
@@ -1395,7 +1395,8 @@ ON_EXIT:
 /**\r
   Create and initialize a USB2_HC_DEV\r
 \r
-  @param  PciIo                The PciIo on this device\r
+  @param  PciIo                  The PciIo on this device\r
+  @param  OriginalPciAttributes  Original PCI attributes\r
 \r
   @return The allocated and initialized USB2_HC_DEV structure\r
   @return if created, otherwise NULL.\r
@@ -1404,7 +1405,8 @@ ON_EXIT:
 STATIC\r
 USB2_HC_DEV *\r
 EhcCreateUsb2Hc (\r
-  IN EFI_PCI_IO_PROTOCOL  *PciIo\r
+  IN EFI_PCI_IO_PROTOCOL  *PciIo,\r
+  IN UINT64               OriginalPciAttributes\r
   )\r
 {\r
   USB2_HC_DEV             *Ehc;\r
@@ -1437,7 +1439,8 @@ EhcCreateUsb2Hc (
   Ehc->Usb2Hc.MajorRevision             = 0x1;\r
   Ehc->Usb2Hc.MinorRevision             = 0x1;\r
 \r
-  Ehc->PciIo = PciIo;\r
+  Ehc->PciIo                 = PciIo;\r
+  Ehc->OriginalPciAttributes = OriginalPciAttributes;\r
 \r
   InitializeListHead (&Ehc->AsyncIntTransfers);\r
 \r
@@ -1491,6 +1494,8 @@ EhcDriverBindingStart (
   EFI_STATUS              Status;\r
   USB2_HC_DEV             *Ehc;\r
   EFI_PCI_IO_PROTOCOL     *PciIo;\r
+  UINT64                  Supports;\r
+  UINT64                  OriginalPciAttributes;\r
 \r
   //\r
   // Open the PciIo Protocol, then enable the USB host controller\r
@@ -1509,13 +1514,36 @@ EhcDriverBindingStart (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  //\r
+  // Save original PCI attributes\r
+  //\r
   Status = PciIo->Attributes (\r
                     PciIo,\r
-                    EfiPciIoAttributeOperationEnable,\r
-                    EFI_PCI_DEVICE_ENABLE,\r
-                    NULL\r
+                    EfiPciIoAttributeOperationGet,\r
+                    0,\r
+                    &OriginalPciAttributes\r
                     );\r
 \r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationSupported,\r
+                    0,\r
+                    &Supports\r
+                    );\r
+  if (!EFI_ERROR (Status)) {\r
+    Supports &= EFI_PCI_DEVICE_ENABLE;\r
+    Status = PciIo->Attributes (\r
+                      PciIo,\r
+                      EfiPciIoAttributeOperationEnable,\r
+                      Supports,\r
+                      NULL\r
+                      );\r
+  }\r
+\r
   if (EFI_ERROR (Status)) {\r
     EHC_ERROR (("EhcDriverBindingStart: failed to enable controller\n"));\r
     goto CLOSE_PCIIO;\r
@@ -1524,7 +1552,7 @@ EhcDriverBindingStart (
   //\r
   // Create then install USB2_HC_PROTOCOL\r
   //\r
-  Ehc = EhcCreateUsb2Hc (PciIo);\r
+  Ehc = EhcCreateUsb2Hc (PciIo, OriginalPciAttributes);\r
 \r
   if (Ehc == NULL) {\r
     EHC_ERROR (("EhcDriverBindingStart: failed to create USB2_HC\n"));\r
@@ -1606,6 +1634,16 @@ FREE_POOL:
   gBS->FreePool (Ehc);\r
 \r
 CLOSE_PCIIO:\r
+  //\r
+  // Restore original PCI attributes\r
+  //\r
+  PciIo->Attributes (\r
+                  PciIo,\r
+                  EfiPciIoAttributeOperationSet,\r
+                  OriginalPciAttributes,\r
+                  NULL\r
+                  );\r
+\r
   gBS->CloseProtocol (\r
          Controller,\r
          &gEfiPciIoProtocolGuid,\r
@@ -1693,14 +1731,14 @@ EhcDriverBindingStop (
   }\r
 \r
   //\r
-  // Disable the USB Host Controller\r
+  // Restore original PCI attributes\r
   //\r
   PciIo->Attributes (\r
-           PciIo,\r
-           EfiPciIoAttributeOperationDisable,\r
-           EFI_PCI_DEVICE_ENABLE,\r
-           NULL\r
-           );\r
+                  PciIo,\r
+                  EfiPciIoAttributeOperationSet,\r
+                  Ehc->OriginalPciAttributes,\r
+                  NULL\r
+                  );\r
 \r
   gBS->CloseProtocol (\r
          Controller,\r
@@ -1709,8 +1747,9 @@ EhcDriverBindingStop (
          Controller\r
          );\r
 \r
-  gBS->FreePool (Ehc);\r
-  return Status;\r
+  FreePool (Ehc);\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL\r