From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.1.43; helo=eur01-ve1-obe.outbound.protection.outlook.com; envelope-from=sami.mujawar@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0043.outbound.protection.outlook.com [104.47.1.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 236152119A44E for ; Wed, 20 Jun 2018 01:23:01 -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=Zf+3hQ/jHHmi1M30HgzrOyu9hxmEjUCwi+fQAS+J3b4=; b=aH/KI3gKCedjrUYK4kPV1/BCWgFzIyg2bW2sr4I29J708BjJI/70nM5vA40kSkWYY70TaYkREvkOzvOEd9noRBPJuRdpeUQdHHNDvgu+vPLTtMnJfqKHWHsgTM6O05J4fmhJ34NyLBTUY4Z7dHrVKn3ezRw4YwOS//aIMMEjPOw= Received: from DB6PR0802MB2375.eurprd08.prod.outlook.com (10.172.228.142) by DB6PR0802MB2360.eurprd08.prod.outlook.com (10.172.228.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.17; Wed, 20 Jun 2018 08:22:58 +0000 Received: from DB6PR0802MB2375.eurprd08.prod.outlook.com ([fe80::8176:1e3f:735b:69a9]) by DB6PR0802MB2375.eurprd08.prod.outlook.com ([fe80::8176:1e3f:735b:69a9%3]) with mapi id 15.20.0863.016; Wed, 20 Jun 2018 08:22:58 +0000 From: Sami Mujawar To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Dong, Eric" , "Ni, Ruiyu" , "ard.biesheuvel@linaro.org" , "leif.lindholm@linaro.org" , Matteo Carlini , Stephanie Hughes-Fitt , Evan Lloyd , Thomas Abraham , nd Thread-Topic: [PATCH v3] MdeModulePkg: Enable SATA Controller PCI mem space Thread-Index: AQHUCFES3VuUSCDffU6J9uPGOBPzJ6Rozr0Q Date: Wed, 20 Jun 2018 08:22:57 +0000 Message-ID: References: <20180619115814.17676-1-sami.mujawar@arm.com> <0C09AFA07DD0434D9E2A0C6AEB0483103BB5A3A4@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103BB5A3A4@shsmsx102.ccr.corp.intel.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Sami.Mujawar@arm.com; x-originating-ip: [217.140.96.140] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0802MB2360; 7:DGYGCHzuRSzxwVVzR+nmi/T16k5AhTQweI8bvhqgM0amPk+L3RrLQ22S8fC7LTiZ2HuroWTbl5n/u1ChxG2pMJtmH7OD/RdUhEVV/WsQ7yIeDKmp6kfEVSwS/KumDId3elB/0zezFJTBvd39oOgM5AFGlQ4RY50I311FqKJV9scrAKMOtibkTtOY+/nl+4m5Oj0n1CjvXZsdtyqPlbwTKV1JRFYEpg/ZnRY8/P7M4d2XsGHyrn5J800Cm2tV+UhS x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: f8bd570f-e49e-4bed-f304-08d5d68707c4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DB6PR0802MB2360; x-ms-traffictypediagnostic: DB6PR0802MB2360: 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)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DB6PR0802MB2360; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2360; x-forefront-prvs: 070912876F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(376002)(396003)(39380400002)(366004)(346002)(189003)(199004)(13464003)(72206003)(966005)(3660700001)(478600001)(55016002)(53936002)(2900100001)(68736007)(3280700002)(2501003)(66066001)(6246003)(6436002)(14454004)(2906002)(4326008)(5250100002)(33656002)(5660300001)(25786009)(81156014)(102836004)(74316002)(8676002)(6506007)(11346002)(446003)(81166006)(186003)(476003)(59450400001)(105586002)(316002)(26005)(7736002)(86362001)(305945005)(106356001)(9686003)(99286004)(97736004)(3846002)(6116002)(229853002)(7696005)(6306002)(110136005)(575784001)(8936002)(486006)(53546011)(76176011)(54906003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0802MB2360; H:DB6PR0802MB2375.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: hlviVj0E+NFmWbPO6OvgXm9+bxRYFmBsSXvgYFsmnFFYMN6ckVyr7YxrIhCLVZusVVwde105Ma+Se7LjixpDPL+3oEVDHk6ZXfYQ1N7mKFTeRwxjm78vvwWHXqBbQuNT8GhR2T1Kb4oNmU3Yx1fsu36qla1czy0yWT9bfC0L6jgzKbbI1OJzC+Q6TvkPXbLXPM0CjWqwoAEHATp2dfUYpHJn1uySmjFwm2lqn4kf/FUCfgt1On2eROvxqT3uq+zxPYS5u7DQ+LMlgH1tbgywxxdfY352t9+gJcYKpjLvuYhFhWKZIfkNgYRh0YgfDqbwakzaelnxFqdK2vXnFm9cTQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8bd570f-e49e-4bed-f304-08d5d68707c4 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jun 2018 08:22:58.0708 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2360 Subject: Re: [PATCH v3] 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: Wed, 20 Jun 2018 08:23:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Star, I agree with this change.=20 Regards, Sami Mujawar -----Original Message----- From: Zeng, Star =20 Sent: 20 June 2018 05:42 AM To: Sami Mujawar ; edk2-devel@lists.01.org Cc: Dong, Eric ; Ni, Ruiyu ; ard.b= iesheuvel@linaro.org; leif.lindholm@linaro.org; Matteo Carlini ; Stephanie Hughes-Fitt ; Evan L= loyd ; Thomas Abraham ; nd ; Zeng, Star Subject: RE: [PATCH v3] MdeModulePkg: Enable SATA Controller PCI mem space With + // + // Track the state so that the PCI attributes that were modified //=20 + can be restored to the original value later. Updated to + // + // Track the state so that the PCI attributes that were modified //=20 + can be restored to the original value later. + // Reviewed-by: Star Zeng If you agree, you do not need resend new patch. I will help update it simply and push the patch. Thanks, Star -----Original Message----- From: Sami Mujawar [mailto:sami.mujawar@arm.com] Sent: Tuesday, June 19, 2018 7:58 PM To: edk2-devel@lists.01.org Cc: Zeng, Star ; Dong, Eric ; Ni,= Ruiyu ; ard.biesheuvel@linaro.org; leif.lindholm@linar= o.org; Matteo.Carlini@arm.com; Stephanie.Hughes-Fitt@arm.com; evan.lloyd@ar= m.com; thomas.abraham@arm.com; nd@arm.com Subject: [PATCH v3] MdeModulePkg: Enable SATA Controller PCI mem space The SATA controller driver crashes while accessing the PCI memory [AHCI Bas= e Registers (ABAR)], as the PCI memory space is not enabled. Enable the PCI memory space access to prevent the SATA Controller driver fr= om crashing. 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_sat= a_controler_pci_mem_fix_v3 Notes: v3: - Integrated suggested changes. [SAMI= ] =20 v2: - Improved log message and code documentation based on feedback [SAMI= ] - Enable IO space, suggestion to use EFI_PCI_DEVICE_ENABLE [STAR= ] - This SATA Controller driver only uses the PCI BAR5 register space which is the AHCI Base Address (ABAR). According to the 'Serial ATA Advanced Host Controller Interface (AHCI) 1.3.1' specification, section 2.1.11, 'This register allocates space for the HBA memory registers'. The section 2.1.10, allows provision for Optional BARs which may support either memory or I/O spaces. However, in the context of the current SATA controller driver, which only ever access the ABAR, enabling I/O memory space is not required. [SAMI= ] - Prefer to use // surrounding comments [STAR= ] - Doing this would violate the edk2 coding standard. See EDK2 Coding Standard Specification, revision 2.20, section 6.2.3. [SAMI= ] =20 v1: - Fix SATA Controller driver crash [SAMI= ] MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c | 75 +++++++++++++= ++++++- MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h | 11 +++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c b/MdeM= odulePkg/Bus/Pci/SataControllerDxe/SataController.c index a6d55c15571728eb3fd572003f383ba7c86635ae..87c201dabdcf14fa228c0b3577f= bbead2ec9b6bd 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 Supports; =20 DEBUG ((EFI_D_INFO, "SataControllerStart start\n")); =20 @@ -406,6 +408,52 @@ 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, + "Original PCI Attributes =3D 0x%llx\n", + Private->OriginalPciAttributes + )); + + Status =3D PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSupported, + 0, + &Supports + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + DEBUG ((EFI_D_INFO, "Supported PCI Attributes =3D 0x%llx\n",=20 + Supports)); + + Supports &=3D (UINT64)EFI_PCI_DEVICE_ENABLE; Status =3D=20 + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationEnable, + Supports, + NULL + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + DEBUG ((EFI_D_INFO, "Enabled PCI Attributes =3D 0x%llx\n", Supports)); = =20 + Private->PciAttributesChanged =3D TRUE; =20 Status =3D 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; + } =20 if (IS_PCI_IDE (&PciData)) { Private->IdeInit.ChannelCount =3D IDE_MAX_CHANNEL; @@ -481,6 +532,17 @= @ 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 +618,17 @@ 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..26c44034f6cdf0d9a3e1abee14f= e316f6158d854 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) 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 @@ -104,6 +105,16 @@ typedef struct _EFI_SATA_CONTROLLER_PRIVATE= _DATA { // EFI_IDENTIFY_DATA *IdentifyData; BOOLEAN *IdentifyValid; + + // + // Track the state so that the PCI attributes that were modified //=20 + 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)'