From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.81]) by mx.groups.io with SMTP id smtpd.web10.8558.1589445866041558888 for ; Thu, 14 May 2020 01:44:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=M7htVf5s; spf=pass (domain: arm.com, ip: 40.107.8.81, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=foB7t91IrB+j5qt6UpB34Dk54GMF6mt2OUm/BIWH000=; b=M7htVf5sch81LWl0OJp1YNPyg6yq5a/QVy4zlOQmG3wdHdejpMiKR63dwPegtUmoTfdzgu/A1d79hDaB/YTJU8K7URHITmB9+39uZ7IXU/yKGvUk+eOzidv0IMK6s7vZ14PXDN3lenHksySkR3aQ06edlP+BbVlixeQr0biEpng= Received: from AM5PR1001CA0006.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:2::19) by AM0PR08MB3923.eurprd08.prod.outlook.com (2603:10a6:208:123::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.33; Thu, 14 May 2020 08:44:22 +0000 Received: from VE1EUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:2:cafe::28) by AM5PR1001CA0006.outlook.office365.com (2603:10a6:206:2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Thu, 14 May 2020 08:44:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT052.mail.protection.outlook.com (10.152.19.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:22 +0000 Received: ("Tessian outbound 4cdf5642225a:v54"); Thu, 14 May 2020 08:44:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: eb8a0760d70cf0a5 X-CR-MTA-TID: 64aa7808 Received: from 297f7a79dd64.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 440491FC-CA95-4AB0-90C5-F3D8BAFF367E.1; Thu, 14 May 2020 08:44:21 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 297f7a79dd64.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 14 May 2020 08:44:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XG4rYl2TUQ/YBY0Jnu9aK/tZu7yN1RfscXmEYFJcV79nEajiiwNhZ1A//+wom8klDzCeWWMEbGfrofYwvUAdN1EOoGyXkAQ84nkCaEnDOsQe53RvIcyVz3KKV7gsTgkTr8F8bQRfdCEyYf0ENYoGNTcRwkYFxZxyVytK5yZ2IhTnAN2CeLcvz32u25BRmlfkFk1B2512qE4iCgDbwtDLmD7XhyziFR58IJ5UppCVRTdnEQub8rUzwfCPA/9bql3GA/mCwMuQeV1OgmNSjkN/Qr8AIpcap3QOW4xSXECnwg6zAhoAYvaLDVAuidsc+cBYgOXYWOtmYFMRlO9V99N1Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=foB7t91IrB+j5qt6UpB34Dk54GMF6mt2OUm/BIWH000=; b=dLa0qJ9g6EPZ4hKh9tOFz4qHJ9JijjGy/y3YY2Mni8qgSFGYw/ZRFpUtCX1jDhqlTVxPJ/XpQDW5gjQ7itXwI0edZYtt7bfioZV2uxXfLp/95wKlnYqU0/myH3TxDnhOXC+rdskP5WMMTnGWqwnpQTyrRnjKcPt46/2+TUwFyDnyJVvc0fyrzsiMhboFSE11pRKXxYYrObVo+xsR7lCgdTYu5fVV7VtxRoE1UfQ2SFC93xJBnjCLyYmKUlcp8TooWnDvt4YzCd1WIptmbiGuvOkZIaR8LVaQB20M4+0P6q5i4B7VVY31iZg4h1Q3iXio+cMan9gnx2CbHN9P4n8Trg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=foB7t91IrB+j5qt6UpB34Dk54GMF6mt2OUm/BIWH000=; b=M7htVf5sch81LWl0OJp1YNPyg6yq5a/QVy4zlOQmG3wdHdejpMiKR63dwPegtUmoTfdzgu/A1d79hDaB/YTJU8K7URHITmB9+39uZ7IXU/yKGvUk+eOzidv0IMK6s7vZ14PXDN3lenHksySkR3aQ06edlP+BbVlixeQr0biEpng= Received: from DB6PR07CA0117.eurprd07.prod.outlook.com (2603:10a6:6:2c::31) by HE1PR08MB2860.eurprd08.prod.outlook.com (2603:10a6:7:38::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.35; Thu, 14 May 2020 08:44:14 +0000 Received: from DB5EUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2c:cafe::9c) by DB6PR07CA0117.outlook.office365.com (2603:10a6:6:2c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.10 via Frontend Transport; Thu, 14 May 2020 08:44:14 +0000 Authentication-Results-Original: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT008.mail.protection.outlook.com (10.152.20.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:14 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 14 May 2020 08:40:26 +0000 Received: from E107187.Arm.com (10.57.42.179) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 14 May 2020 08:40:26 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , Subject: [PATCH v1 04/11] ArmPlatformPkg: Use MMIO to read device memory Date: Thu, 14 May 2020 09:40:12 +0100 Message-ID: <20200514084019.71368-5-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200514084019.71368-1-sami.mujawar@arm.com> References: <20200514084019.71368-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(376002)(39860400002)(346002)(46966005)(2906002)(70586007)(478600001)(7696005)(82310400002)(44832011)(1076003)(6666004)(54906003)(8676002)(5660300002)(356005)(6916009)(26005)(8936002)(426003)(70206006)(4326008)(82740400003)(336012)(47076004)(186003)(86362001)(36756003)(316002)(2616005)(81166007);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e74da1a6-5efc-4515-b5a3-08d7f7e2ffb9 X-MS-TrafficTypeDiagnostic: HE1PR08MB2860:|AM0PR08MB3923: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 040359335D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: N6Jx0gh4Jym//UjhWQiu2IiiWDLQ+H+qr0+ib0fpWvj7JvLUKI+L15t/IRPtcccIk+V8f+jpAxuu94OZbxZ3ftAL0nh24FdXduJYJ6wDrw6NHVaSQLRCyy/hZFHjKRaeVq/EIF8GPbQ9YfbJ4ICxQfOkCg77vy1shF5p/hRUaG+eW0YsEcTHcg0h/9ABFeH5VjWUuYErKBm8yHWe5IGB5tF6OWnXx61Ua0VmGNqCeHSGjk7xtqNtUpQxVVubsRGyq9n+8QCCaHXZtVKahQNpdKhuwAtxdztPTCRRCIitrK1Ich4DIy5oikVMe16OBof3VA7lgXb5Dbz4p0XNgVlJqTOUmqujHPLqpjkgOxAoB/NFdjeOQcvMVpXRXB6Gd60/5GBviuaNIsu6TDf9/PFsvoLHpif0IRD94WAO4g/MXXDFpmaQeixQqC7nwmmIOyteSRghx1gLDrs6UbnmbSu4PIoUZYcRjQsWCOOhqXv+iQaJ3I8WmOJ1ClcMpXH25VP07S07FsX6Sgndda99it54kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB2860 Original-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT052.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(346002)(376002)(39860400002)(136003)(396003)(46966005)(82310400002)(54906003)(70586007)(426003)(82740400003)(2616005)(47076004)(8676002)(36756003)(2906002)(36906005)(44832011)(316002)(86362001)(336012)(6916009)(8936002)(81166007)(6666004)(478600001)(70206006)(4326008)(1076003)(186003)(7696005)(26005)(5660300002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 58f371d1-fb8e-47b4-0459-08d7f7e2fb30 X-Forefront-PRVS: 040359335D X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JYVd4LcLFZW3noHtwJXgEj3305/OxiD/EkYt/vFlGKiBMp/wzcR7nlznSO0xYGhq9Li7b4jgX2uovDOE37IHyfhpVczJlbF72SBqshdlj30pWn7MHDgPvesshc1GtF9HIy8JBsaZDOfjlL7uYNJ3EoQeFJrEXCOR1cRbYkG3HpJH+P626i8ndGDLHsCc5wzRPg8rwApeUZf4YMpT/MOfECjVA9vH6BOdnSA8V/C59LHdGEVjBjLJrf5gf1q1LrFsbn3DlU/AH1zCL8aAAchfA4qsTOmBDf+jcLPQYDF+FFBBTIbeHtKIdqQIF/mnV+cckPSJ3/7txDe0oKXNnpHNGgtivW67mz/S9OX0tBTqajeO1e6lcFCMSt4YVXE5eROsP12jnwaejqKoB+9MCLgC8ae0/4syBTAF2kMGmAzMpLWOCVEOI4jtnPVfcQwcpAz+EQijMowL9EUBolwsVIqzSNCSD/G+rXBMlZd/N+E/tyVETxO6Xa1tD5HJIOSTjniO6AwxXiaEAa8jjJhTfkpDCw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 08:44:22.0185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e74da1a6-5efc-4515-b5a3-08d7f7e2ffb9 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3923 Content-Type: text/plain NorFlashDxe must use aligned MMIO accesses to read data from flash as this is device memory. The AlignedCopyMem() was used to copy the flash data which prevented unaligned access to device memory. However, the compiler could optimize the code to generate pre/post indexed or LDP operations. This is a problem for guest/virtual firmware as the hypervisor code cannot get the syndrome information for the trapped accesses. Similarly, the GUIDS FwVolHeader->FileSystemGuid and VariableStoreHeader->Signature in ValidateFvHeader() are compared using CompareGuid(). These GUIDs point to flash data (which is device memory) and therefore need aligned MMIO accesses. To address the above issues, BaseMemoryLibMmio library has been introduced to perform aligned MMIO accesses. This patch removes the usage of AlignedCopyMem() and replaces it with CopyMem() with an expectation that the BaseMemoryLibMmio will be linked with NorFlashDxe. Signed-off-by: Sami Mujawar --- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 65 +------------------- 1 file changed, 3 insertions(+), 62 deletions(-) diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index d9e196cbf18c32fe5306cc3c0674a7b5798a9191..f9890de8244d37e0e860fd183bb216ff7d1e7035 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -1,6 +1,6 @@ /** @file NorFlashDxe.c - Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2020, ARM Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -735,65 +735,6 @@ NorFlashWriteBlocks ( return Status; } -#define BOTH_ALIGNED(a, b, align) ((((UINTN)(a) | (UINTN)(b)) & ((align) - 1)) == 0) - -/** - Copy Length bytes from Source to Destination, using aligned accesses only. - Note that this implementation uses memcpy() semantics rather then memmove() - semantics, i.e., SourceBuffer and DestinationBuffer should not overlap. - - @param DestinationBuffer The target of the copy request. - @param SourceBuffer The place to copy from. - @param Length The number of bytes to copy. - - @return Destination - -**/ -STATIC -VOID * -AlignedCopyMem ( - OUT VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ) -{ - UINT8 *Destination8; - CONST UINT8 *Source8; - UINT32 *Destination32; - CONST UINT32 *Source32; - UINT64 *Destination64; - CONST UINT64 *Source64; - - if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 8) && Length >= 8) { - Destination64 = DestinationBuffer; - Source64 = SourceBuffer; - while (Length >= 8) { - *Destination64++ = *Source64++; - Length -= 8; - } - - Destination8 = (UINT8 *)Destination64; - Source8 = (CONST UINT8 *)Source64; - } else if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 4) && Length >= 4) { - Destination32 = DestinationBuffer; - Source32 = SourceBuffer; - while (Length >= 4) { - *Destination32++ = *Source32++; - Length -= 4; - } - - Destination8 = (UINT8 *)Destination32; - Source8 = (CONST UINT8 *)Source32; - } else { - Destination8 = DestinationBuffer; - Source8 = SourceBuffer; - } - while (Length-- != 0) { - *Destination8++ = *Source8++; - } - return DestinationBuffer; -} - EFI_STATUS NorFlashReadBlocks ( IN NOR_FLASH_INSTANCE *Instance, @@ -841,7 +782,7 @@ NorFlashReadBlocks ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); // Readout the data - AlignedCopyMem (Buffer, (VOID *)StartAddress, BufferSizeInBytes); + CopyMem (Buffer, (VOID *)StartAddress, BufferSizeInBytes); return EFI_SUCCESS; } @@ -882,7 +823,7 @@ NorFlashRead ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); // Readout the data - AlignedCopyMem (Buffer, (VOID *)(StartAddress + Offset), BufferSizeInBytes); + CopyMem (Buffer, (VOID *)(StartAddress + Offset), BufferSizeInBytes); return EFI_SUCCESS; } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'