summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2018-06-19 19:58:14 +0800
committerStar Zeng <star.zeng@intel.com>2018-06-21 09:08:19 +0800
commit24fee0528c32b240720547afdd737ca928b34e60 (patch)
tree902366e5126d733238ae6627d60f26dd990d9d6a /MdeModulePkg
parent1e0db7b11987d0ec93be7dfe26102a327860fdbd (diff)
downloadedk2-24fee0528c32b240720547afdd737ca928b34e60.tar.gz
edk2-24fee0528c32b240720547afdd737ca928b34e60.tar.bz2
edk2-24fee0528c32b240720547afdd737ca928b34e60.zip
MdeModulePkg: Enable SATA Controller PCI mem space
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>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c75
-rw-r--r--MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h12
2 files changed, 86 insertions, 1 deletions
diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
index a6d55c1557..87c201dabd 100644
--- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
+++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
@@ -2,6 +2,7 @@
This driver module produces IDE_CONTROLLER_INIT protocol for Sata Controllers.
Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -364,6 +365,7 @@ SataControllerStart (
EFI_SATA_CONTROLLER_PRIVATE_DATA *Private;
UINT32 Data32;
UINTN TotalCount;
+ UINT64 Supports;
DEBUG ((EFI_D_INFO, "SataControllerStart start\n"));
@@ -406,6 +408,52 @@ SataControllerStart (
Private->IdeInit.CalculateMode = IdeInitCalculateMode;
Private->IdeInit.SetTiming = IdeInitSetTiming;
Private->IdeInit.EnumAll = SATA_ENUMER_ALL;
+ Private->PciAttributesChanged = FALSE;
+
+ //
+ // Save original PCI attributes
+ //
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationGet,
+ 0,
+ &Private->OriginalPciAttributes
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ DEBUG ((
+ EFI_D_INFO,
+ "Original PCI Attributes = 0x%llx\n",
+ Private->OriginalPciAttributes
+ ));
+
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationSupported,
+ 0,
+ &Supports
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ DEBUG ((EFI_D_INFO, "Supported PCI Attributes = 0x%llx\n", Supports));
+
+ Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Supports,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ DEBUG ((EFI_D_INFO, "Enabled PCI Attributes = 0x%llx\n", Supports));
+ Private->PciAttributesChanged = TRUE;
Status = PciIo->Pci.Read (
PciIo,
@@ -414,7 +462,10 @@ SataControllerStart (
sizeof (PciData.Hdr.ClassCode),
PciData.Hdr.ClassCode
);
- ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ ASSERT (FALSE);
+ goto Done;
+ }
if (IS_PCI_IDE (&PciData)) {
Private->IdeInit.ChannelCount = IDE_MAX_CHANNEL;
@@ -481,6 +532,17 @@ Done:
if (Private->IdentifyValid != NULL) {
FreePool (Private->IdentifyValid);
}
+ if (Private->PciAttributesChanged) {
+ //
+ // Restore original PCI attributes
+ //
+ PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationSet,
+ Private->OriginalPciAttributes,
+ NULL
+ );
+ }
FreePool (Private);
}
}
@@ -556,6 +618,17 @@ SataControllerStop (
if (Private->IdentifyValid != NULL) {
FreePool (Private->IdentifyValid);
}
+ if (Private->PciAttributesChanged) {
+ //
+ // Restore original PCI attributes
+ //
+ Private->PciIo->Attributes (
+ Private->PciIo,
+ EfiPciIoAttributeOperationSet,
+ Private->OriginalPciAttributes,
+ NULL
+ );
+ }
FreePool (Private);
}
diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h
index f7db3b832a..db2e219599 100644
--- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h
+++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h
@@ -2,6 +2,7 @@
Header file for Sata Controller driver.
Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -104,6 +105,17 @@ typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA {
//
EFI_IDENTIFY_DATA *IdentifyData;
BOOLEAN *IdentifyValid;
+
+ //
+ // Track the state so that the PCI attributes that were modified
+ // can be restored to the original value later.
+ //
+ BOOLEAN PciAttributesChanged;
+
+ //
+ // Copy of the original PCI Attributes
+ //
+ UINT64 OriginalPciAttributes;
} EFI_SATA_CONTROLLER_PRIVATE_DATA;
#define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)