]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c
Save original PCI attributes in start() function and restore it in Stop() for those...
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciDxe / Uhci.c
index 00108b87e2b218afad494582bd5ca99032c84d72..82142b6a85acfd9e4e173c6b5a0dbc4e2f367714 100644 (file)
@@ -82,7 +82,7 @@ UhciReset (
   default:\r
     goto ON_INVAILD_PARAMETER;\r
   }\r
-  \r
+\r
   //\r
   // Delete all old transactions on the USB bus, then\r
   // reinitialize the frame list\r
@@ -92,13 +92,13 @@ UhciReset (
   UhciInitFrameList (Uhc);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 \r
 ON_INVAILD_PARAMETER:\r
-  \r
+\r
   gBS->RestoreTPL (OldTpl);\r
-  \r
+\r
   return EFI_INVALID_PARAMETER;\r
 }\r
 \r
@@ -213,7 +213,7 @@ UhciSetState (
         UsbCmd |= USBCMD_FGR;\r
         UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd);\r
       }\r
-      \r
+\r
       //\r
       // wait 20ms to let resume complete (20ms is specified by UHCI spec)\r
       //\r
@@ -237,7 +237,7 @@ UhciSetState (
       Status = EFI_DEVICE_ERROR;\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     //\r
     // Set Enter Global Suspend Mode bit to 1.\r
     //\r
@@ -1941,7 +1941,8 @@ ON_EXIT:
 STATIC\r
 USB_HC_DEV *\r
 UhciAllocateDev (\r
-  IN EFI_PCI_IO_PROTOCOL    *PciIo\r
+  IN EFI_PCI_IO_PROTOCOL    *PciIo,\r
+  IN UINT64                 OriginalPciAttributes\r
   )\r
 {\r
   USB_HC_DEV  *Uhc;\r
@@ -1990,8 +1991,9 @@ UhciAllocateDev (
   Uhc->Usb2Hc.MajorRevision             = 0x1;\r
   Uhc->Usb2Hc.MinorRevision             = 0x1;\r
 \r
-  Uhc->PciIo   = PciIo;\r
-  Uhc->MemPool = UsbHcInitMemPool (PciIo, TRUE, 0);\r
+  Uhc->PciIo                 = PciIo;\r
+  Uhc->OriginalPciAttributes = OriginalPciAttributes;\r
+  Uhc->MemPool               = UsbHcInitMemPool (PciIo, TRUE, 0);\r
 \r
   if (Uhc->MemPool == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -2090,12 +2092,15 @@ UhciCleanDevUp (
   UhciFreeAllAsyncReq (Uhc);\r
   UhciDestoryFrameList (Uhc);\r
 \r
+  //\r
+  // Restore original PCI attributes\r
+  //\r
   Uhc->PciIo->Attributes (\r
-                Uhc->PciIo,\r
-                EfiPciIoAttributeOperationDisable,\r
-                EFI_PCI_DEVICE_ENABLE,\r
-                NULL\r
-                );\r
+                  Uhc->PciIo,\r
+                  EfiPciIoAttributeOperationSet,\r
+                  Uhc->OriginalPciAttributes,\r
+                  NULL\r
+                  );\r
 \r
   UhciFreeDev (Uhc);\r
 }\r
@@ -2126,6 +2131,8 @@ UhciDriverBindingStart (
   EFI_STATUS          Status;\r
   EFI_PCI_IO_PROTOCOL *PciIo;\r
   USB_HC_DEV          *Uhc;\r
+  UINT64              Supports;\r
+  UINT64              OriginalPciAttributes;\r
 \r
   //\r
   // Open PCIIO, then enable the EHC device and turn off emulation\r
@@ -2144,20 +2151,43 @@ UhciDriverBindingStart (
     return Status;\r
   }\r
 \r
+  //\r
+  // Save original PCI attributes\r
+  //\r
+  Status = PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationGet,\r
+                    0,\r
+                    &OriginalPciAttributes\r
+                    );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   UhciTurnOffUsbEmulation (PciIo);\r
 \r
   Status = PciIo->Attributes (\r
                     PciIo,\r
-                    EfiPciIoAttributeOperationEnable,\r
-                    EFI_PCI_DEVICE_ENABLE,\r
-                    NULL\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
     goto CLOSE_PCIIO;\r
   }\r
 \r
-  Uhc = UhciAllocateDev (PciIo);\r
+  Uhc = UhciAllocateDev (PciIo, OriginalPciAttributes);\r
 \r
   if (Uhc == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -2232,6 +2262,16 @@ FREE_UHC:
   UhciFreeDev (Uhc);\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