]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Enable SATA Controller PCI mem space
authorSami Mujawar <sami.mujawar@arm.com>
Tue, 19 Jun 2018 11:58:14 +0000 (19:58 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 21 Jun 2018 01:08:19 +0000 (09:08 +0800)
The SATA controller driver crashes while accessing the
PCI memory [AHCI Base Registers (ABAR)], as the PCI memory
space is not enabled.

Enable the PCI memory space access to prevent the SATA
Controller driver from crashing.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h

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
index f7db3b832a14c0c8314518cfdf4198c7a4e8ef25..db2e2195993162d23e2d07186360dce6d552f940 100644 (file)
@@ -2,6 +2,7 @@
   Header file for Sata Controller driver.\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
@@ -104,6 +105,17 @@ typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA {
   //\r
   EFI_IDENTIFY_DATA                 *IdentifyData;\r
   BOOLEAN                           *IdentifyValid;\r
+\r
+  //\r
+  // Track the state so that the PCI attributes that were modified\r
+  // can be restored to the original value later.\r
+  //\r
+  BOOLEAN                           PciAttributesChanged;\r
+\r
+  //\r
+  // Copy of the original PCI Attributes\r
+  //\r
+  UINT64                            OriginalPciAttributes;\r
 } EFI_SATA_CONTROLLER_PRIVATE_DATA;\r
 \r
 #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)\r