From: Sami Mujawar Date: Tue, 19 Jun 2018 11:58:14 +0000 (+0800) Subject: MdeModulePkg: Enable SATA Controller PCI mem space X-Git-Tag: edk2-stable201903~1562 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=24fee0528c32b240720547afdd737ca928b34e60 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 Reviewed-by: Star Zeng --- 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.
+ Copyright (c) 2018, ARM Ltd. All rights reserved.
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.
+ Copyright (c) 2018, ARM Ltd. All rights reserved.
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)