]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
MdeModulePkg: Enable SATA Controller PCI mem space
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SataControllerDxe / SataController.c
index a6d55c15571728eb3fd572003f383ba7c86635ae..87c201dabdcf14fa228c0b3577fbbead2ec9b6bd 100644 (file)
@@ -2,6 +2,7 @@
   This driver module produces IDE_CONTROLLER_INIT protocol for Sata Controllers.\r
 \r
   Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018, ARM Ltd. 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
@@ -364,6 +365,7 @@ SataControllerStart (
   EFI_SATA_CONTROLLER_PRIVATE_DATA  *Private;\r
   UINT32                            Data32;\r
   UINTN                             TotalCount;\r
+  UINT64                            Supports;\r
 \r
   DEBUG ((EFI_D_INFO, "SataControllerStart start\n"));\r
 \r
@@ -406,6 +408,52 @@ SataControllerStart (
   Private->IdeInit.CalculateMode  = IdeInitCalculateMode;\r
   Private->IdeInit.SetTiming      = IdeInitSetTiming;\r
   Private->IdeInit.EnumAll        = SATA_ENUMER_ALL;\r
+  Private->PciAttributesChanged   = FALSE;\r
+\r
+  //\r
+  // Save original PCI attributes\r
+  //\r
+  Status = PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationGet,\r
+                    0,\r
+                    &Private->OriginalPciAttributes\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+  }\r
+\r
+  DEBUG ((\r
+    EFI_D_INFO,\r
+    "Original PCI Attributes = 0x%llx\n",\r
+    Private->OriginalPciAttributes\r
+    ));\r
+\r
+  Status = PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationSupported,\r
+                    0,\r
+                    &Supports\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Supported PCI Attributes = 0x%llx\n", Supports));\r
+\r
+  Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
+  Status = PciIo->Attributes (\r
+                      PciIo,\r
+                      EfiPciIoAttributeOperationEnable,\r
+                      Supports,\r
+                      NULL\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Enabled PCI Attributes = 0x%llx\n", Supports));\r
+  Private->PciAttributesChanged = TRUE;\r
 \r
   Status = PciIo->Pci.Read (\r
                         PciIo,\r
@@ -414,7 +462,10 @@ SataControllerStart (
                         sizeof (PciData.Hdr.ClassCode),\r
                         PciData.Hdr.ClassCode\r
                         );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    ASSERT (FALSE);\r
+    goto Done;\r
+  }\r
 \r
   if (IS_PCI_IDE (&PciData)) {\r
     Private->IdeInit.ChannelCount = IDE_MAX_CHANNEL;\r
@@ -481,6 +532,17 @@ Done:
       if (Private->IdentifyValid != NULL) {\r
         FreePool (Private->IdentifyValid);\r
       }\r
+      if (Private->PciAttributesChanged) {\r
+        //\r
+        // Restore original PCI attributes\r
+        //\r
+        PciIo->Attributes (\r
+                 PciIo,\r
+                 EfiPciIoAttributeOperationSet,\r
+                 Private->OriginalPciAttributes,\r
+                 NULL\r
+                 );\r
+      }\r
       FreePool (Private);\r
     }\r
   }\r
@@ -556,6 +618,17 @@ SataControllerStop (
     if (Private->IdentifyValid != NULL) {\r
       FreePool (Private->IdentifyValid);\r
     }\r
+    if (Private->PciAttributesChanged) {\r
+      //\r
+      // Restore original PCI attributes\r
+      //\r
+      Private->PciIo->Attributes (\r
+                        Private->PciIo,\r
+                        EfiPciIoAttributeOperationSet,\r
+                        Private->OriginalPciAttributes,\r
+                        NULL\r
+                        );\r
+    }\r
     FreePool (Private);\r
   }\r
 \r