From nobody Tue Apr 30 04:20:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1528976321656751.289974948178; Thu, 14 Jun 2018 04:38:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 99A9C211CACB8; Thu, 14 Jun 2018 04:38:39 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E5E04211CAC84 for ; Thu, 14 Jun 2018 04:38:37 -0700 (PDT) Received: from E107187.Emea.Arm.com (e107187.emea.arm.com [10.1.31.130]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id w5EBcP8p026824; Thu, 14 Jun 2018 12:38:25 +0100 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.96.140; helo=cam-smtp0.cambridge.arm.com; envelope-from=sami.mujawar@arm.com; receiver=edk2-devel@lists.01.org From: Sami Mujawar To: edk2-devel@lists.01.org Date: Thu, 14 Jun 2018 12:38:20 +0100 Message-Id: <20180614113820.11872-1-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 Subject: [edk2] [PATCH v1] MdeModulePkg: Enable SATA Controller PCI mem space X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ruiyu.ni@intel.com, nd@arm.com, Stephanie.Hughes-Fitt@arm.com, eric.dong@intel.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, star.zeng@intel.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The SATA controller driver crashes while accessing the PCI memory, 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: Evan Lloyd Tested-by: Thomas Abraham --- The changes can be seen at https://github.com/samimujawar/edk2/tree/284_sat= a_controler_pci_mem_fix_v1 Notes: v1: - Fix SATA Controller driver crash [SAMI] MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c | 80 +++++++++++++= ++++++- MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h | 7 ++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c b/MdeM= odulePkg/Bus/Pci/SataControllerDxe/SataController.c index a6d55c15571728eb3fd572003f383ba7c86635ae..21cc101d693f5adfd9d43f0c21a= 096eb59ba73b1 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 Contro= llers. =20 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 BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -364,6 +365,7 @@ SataControllerStart ( EFI_SATA_CONTROLLER_PRIVATE_DATA *Private; UINT32 Data32; UINTN TotalCount; + UINT64 PciAttributes; =20 DEBUG ((EFI_D_INFO, "SataControllerStart start\n")); =20 @@ -406,6 +408,61 @@ SataControllerStart ( Private->IdeInit.CalculateMode =3D IdeInitCalculateMode; Private->IdeInit.SetTiming =3D IdeInitSetTiming; Private->IdeInit.EnumAll =3D SATA_ENUMER_ALL; + Private->PciAttributesChanged =3D FALSE; + + // Save original PCI attributes + Status =3D PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationGet, + 0, + &Private->OriginalPciAttributes + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + DEBUG (( + EFI_D_INFO, + "PCI Attributes =3D 0x%llx\n", + Private->OriginalPciAttributes + )); + + if ((Private->OriginalPciAttributes & EFI_PCI_IO_ATTRIBUTE_MEMORY) =3D= =3D 0) { + Status =3D PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSupported, + 0, + &PciAttributes + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + DEBUG ((EFI_D_INFO, "Supported PCI Attributes =3D 0x%llx\n", PciAttrib= utes)); + + if ((PciAttributes & EFI_PCI_IO_ATTRIBUTE_MEMORY) =3D=3D 0) { + DEBUG (( + EFI_D_ERROR, + "Error: EFI_PCI_IO_ATTRIBUTE_MEMORY not supported\n" + )); + Status =3D EFI_UNSUPPORTED; + goto Done; + } + + PciAttributes =3D Private->OriginalPciAttributes | EFI_PCI_IO_ATTRIBUT= E_MEMORY; + + DEBUG ((EFI_D_INFO, "Enable PCI Attributes =3D 0x%llx\n", PciAttribute= s)); + Status =3D PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationEnable, + PciAttributes, + NULL + ); + if (EFI_ERROR (Status)) { + goto Done; + } + Private->PciAttributesChanged =3D TRUE; + } =20 Status =3D PciIo->Pci.Read ( PciIo, @@ -414,7 +471,10 @@ SataControllerStart ( sizeof (PciData.Hdr.ClassCode), PciData.Hdr.ClassCode ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + ASSERT (FALSE); + goto Done; + } =20 if (IS_PCI_IDE (&PciData)) { Private->IdeInit.ChannelCount =3D IDE_MAX_CHANNEL; @@ -481,6 +541,15 @@ Done: if (Private->IdentifyValid !=3D NULL) { FreePool (Private->IdentifyValid); } + if (Private->PciAttributesChanged) { + // Restore original PCI attributes + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSet, + Private->OriginalPciAttributes, + NULL + ); + } FreePool (Private); } } @@ -556,6 +625,15 @@ SataControllerStop ( if (Private->IdentifyValid !=3D NULL) { FreePool (Private->IdentifyValid); } + if (Private->PciAttributesChanged) { + // Restore original PCI attributes + Private->PciIo->Attributes ( + Private->PciIo, + EfiPciIoAttributeOperationSet, + Private->OriginalPciAttributes, + NULL + ); + } FreePool (Private); } =20 diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h b/MdeM= odulePkg/Bus/Pci/SataControllerDxe/SataController.h index f7db3b832a14c0c8314518cfdf4198c7a4e8ef25..cb82b55763a077f5994c4a00ea4= 893bfa2e07a79 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. =20 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -104,6 +105,12 @@ 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; =20 #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLE= R_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE) --=20 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel