From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.2.70; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=evan.lloyd@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0070.outbound.protection.outlook.com [104.47.2.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3624521122E5D for ; Thu, 14 Jun 2018 08:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=goQ42l6bXIC/pmfRNH3YoWUFI+LuoCFDxJLdHjmFX24=; b=Cll/Unbx7uQi63kysCSrrWiiAftZIL/truTdZX4srqbALLK/3fgoknutsPU2q8qFYA/+vgyqZvHaRl6hluSSKnL5lR0aqAEtT5ZY8J6pafkhcCHMDlaiQ1Sbfrwhoz25L3sS1i75Y9Ic9BerZktseJWrD5Iuhn7fukVLseKAquE= Received: from AM4PR08MB2804.eurprd08.prod.outlook.com (10.171.191.22) by AM4PR08MB2834.eurprd08.prod.outlook.com (10.171.191.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Thu, 14 Jun 2018 15:17:33 +0000 Received: from AM4PR08MB2804.eurprd08.prod.outlook.com ([fe80::6073:51d0:4592:cfcc]) by AM4PR08MB2804.eurprd08.prod.outlook.com ([fe80::6073:51d0:4592:cfcc%4]) with mapi id 15.20.0841.019; Thu, 14 Jun 2018 15:17:33 +0000 From: Evan Lloyd To: Sami Mujawar , "edk2-devel@lists.01.org" CC: "star.zeng@intel.com" , "eric.dong@intel.com" , "ruiyu.ni@intel.com" , "ard.biesheuvel@linaro.org" , "leif.lindholm@linaro.org" , Matteo Carlini , Stephanie Hughes-Fitt , Thomas Abraham , nd Thread-Topic: [PATCH v1] MdeModulePkg: Enable SATA Controller PCI mem space Thread-Index: AQHUA9RJIXPXlxWrc0GJ7ylXSbEg4KRf3ZtA Date: Thu, 14 Jun 2018 15:17:33 +0000 Message-ID: References: <20180614113820.11872-1-sami.mujawar@arm.com> In-Reply-To: <20180614113820.11872-1-sami.mujawar@arm.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Evan.Lloyd@arm.com; x-originating-ip: [217.140.96.140] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR08MB2834; 7:5MQ4c4GGg/mYXo6yce5jgQfJRfWhgrDyplXVEtfCxmPlJqROEZg4Eyhk+GG8BNfJLa0FwiU3Ew5Zm44Mn4i9NEB/Mh9cvsSaMfBrwbDYncQXdpmDVmRndifMzCIV8ByIttMI9Ntpqi3DKz0yYc8KFWNbBCdX6KssY/unl2R4dUNOEs1m9ZQbIa/qFXoiAIptLhVOOiTG8S7qlM8UkMOho5BhSaGkP6SjbZ1sqKFcaDN5hvSHRtaXVV2M7wrix5f2 x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d957cbe4-9640-46a1-27da-08d5d209f3fe x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(711020)(2017052603328)(7153060)(7193020); SRVR:AM4PR08MB2834; x-ms-traffictypediagnostic: AM4PR08MB2834: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(166708455590820)(162533806227266)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:AM4PR08MB2834; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB2834; x-forefront-prvs: 0703B549E4 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(39380400002)(39860400002)(376002)(13464003)(189003)(199004)(110136005)(53936002)(6436002)(2900100001)(97736004)(11346002)(81166006)(14454004)(476003)(76176011)(53546011)(6116002)(55016002)(3846002)(3280700002)(54906003)(106356001)(33656002)(59450400001)(446003)(81156014)(99286004)(26005)(105586002)(102836004)(6506007)(6246003)(5660300001)(9686003)(74316002)(7736002)(8676002)(966005)(575784001)(25786009)(8936002)(2906002)(229853002)(478600001)(486006)(2501003)(4326008)(5250100002)(68736007)(3660700001)(86362001)(6306002)(66066001)(316002)(305945005)(7696005)(72206003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB2834; H:AM4PR08MB2804.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Pn0AZ/7zxauOL9Cm5HjpUkRzWc3zKej0fmwuCUBjCZTv9ulmqbsVfK/HFuNQcCb60P/qO1zPIuxNHNf//vFQR/PSks7CAQ3Ued1Mpz+fYaoTpnQDnnrzkbikYXw+x/kjRRE9dmx7iBDlqKh2PIL6nNhgg20xZnhMxyQUGpWgiSUPT67iCicCCYGupBqX8FWH spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: d957cbe4-9640-46a1-27da-08d5d209f3fe X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2018 15:17:33.2021 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2834 Subject: Re: [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: , X-List-Received-Date: Thu, 14 Jun 2018 15:17:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Evan Lloyd > -----Original Message----- > From: Sami Mujawar > Sent: 14 June 2018 12:38 > To: edk2-devel@lists.01.org > Cc: star.zeng@intel.com; eric.dong@intel.com; ruiyu.ni@intel.com; > ard.biesheuvel@linaro.org; leif.lindholm@linaro.org; Matteo Carlini > ; Stephanie Hughes-Fitt Fitt@arm.com>; Evan Lloyd ; Thomas Abraham > ; nd > Subject: [PATCH v1] MdeModulePkg: Enable SATA Controller PCI mem space >=20 > The SATA controller driver crashes while accessing the PCI memory, as the > PCI memory space is not enabled. >=20 > Enable the PCI memory space access to prevent the SATA Controller driver > from crashing. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Sami Mujawar > --- > The changes can be seen at > https://github.com/samimujawar/edk2/tree/284_sata_controler_pci_mem_f > ix_v1 >=20 > Notes: > v1: > - Fix SATA Controller driver crash [SA= MI] >=20 > MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c | 80 > +++++++++++++++++++- > MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h | 7 ++ > 2 files changed, 86 insertions(+), 1 deletion(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c > b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c > index > a6d55c15571728eb3fd572003f383ba7c86635ae..21cc101d693f5adfd9d43f0c2 > 1a096eb59ba73b1 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. >=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 = 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 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", > + PciAttributes)); > + > + 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_ATTRIBUTE_MEMORY; > + > + DEBUG ((EFI_D_INFO, "Enable PCI Attributes =3D 0x%llx\n", PciAttribu= tes)); > + 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/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h > index > f7db3b832a14c0c8314518cfdf4198c7a4e8ef25..cb82b55763a077f5994c4a00e > a4893bfa2e07a79 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 = BSD > License > which accompanies this distribution. The full text of the license may= be > 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_CONTROLLER_PRIVATE_DATA, IdeInit, > SATA_CONTROLLER_SIGNATURE) > -- > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' >=20