From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.92.19.33]) by mx.groups.io with SMTP id smtpd.web10.1109.1608317430534220259 for ; Fri, 18 Dec 2020 10:50:30 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=QiVL4HSG; spf=pass (domain: outlook.com, ip: 40.92.19.33, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VqxNiD8q2dyaooXqhYXkS566/iQkxD3SP/L3UG2x24us4YEr+4WWdy5hlFaZagBlxNtEu4DVkvZd6fr28GI8juu6HEz4mSX7Xh3k407hbFRd/HVgScd2JuisXteBGyGzIZTF9aSgZOspu4qTGMLXLi5PtNuxjy2LsP0JYJ3SPhz9vRF3Jib1Phw3guXEkOlXajQRRcBGfC9GwWsrLw6DS/sepNrDqs4/10ps4q2MhjJ5eWEMkK8v1RCzD/1ErYrr4ZfUBF4GoJquprM0/Pq4usUCjV5j89mRhg/VRSPzYdx/fqCZRry8T6FSUEKQ0rz30Sj9sUhy2BF/AXOTg0V3GA== 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=sqV5PyE3uQ2OqsJyWlSa1M8fJUn5N9V9BKThVGbV+Rs=; b=P/knjRURL/KakydVa7yD/ySlG3TkznjZsSu4v91opQDcbxAXpoRiXAVwgyTx5TRLgKhTPc99X1rhh4gjmsAUC9jcge5b6Bd3ceawjXEZsWrnrKvUZefY/nEaDRvm2Yhhg62MT1QT7M8JVE3lypSYLlhDDu2JOtHzUbnZTzMTIu3+gfvVfjSabnsMBgj47XWziisPYqyUqiJW3F0b0rHB9stbcPnCzcxOF9hL6h1O0dU92obLXpH9SWoifHwjviTh7nBzUBQrzmG+IQfe0MWTvG6GnQGrsBuByYnDk6ab9dSsaBCq1qH4qyseigtkLV6dYVfpqQE2aF9tV7Af6OZZQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sqV5PyE3uQ2OqsJyWlSa1M8fJUn5N9V9BKThVGbV+Rs=; b=QiVL4HSGzPZT4KTYrXOhpAGIDNDXkD/uC2QAc5UgxCryhf0bnH43ZE5Cn4H3QF+L/bLU6aA2OVwk5vprRr6Jvx+eExPx7MWyBvRcCHOoa2idWGEVAGg8G3/SBjT6tjnykySWqKQX1fV/54C/pEwgQuuda6IzBTC0IPr/8G3MKkKojB6QcRQ97MDcoSZ1t0WFvahDBQW4wZni2Lr6L/EUP98ER15RuTmO867/ndmIzFNRer7Lm3N00B2K+zMSFS7BeGBjSaBxwi6B51OhPKIiawuHRqnXJph8XISPt/qZVMwcEmhGienGcwK4sJAQXWBNgKriXjKnvJht4MCWVd+DZA== Received: from DM6NAM11FT039.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::45) by DM6NAM11HT054.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25; Fri, 18 Dec 2020 18:50:29 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:fc4d::48) by DM6NAM11FT039.mail.protection.outlook.com (2a01:111:e400:fc4d::83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25 via Frontend Transport; Fri, 18 Dec 2020 18:50:29 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:2222D9E629B127B17FED5F805DA8B1B5B94031F293D08BA23A2F529EDAF06C52;UpperCasedChecksum:7C3CA9A61646F5F3BF8D7916BD4909785A005049FFCA886F3FD01D148A5DACAE;SizeAsReceived:7507;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6%5]) with mapi id 15.20.3654.026; Fri, 18 Dec 2020 18:50:29 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Date: Fri, 18 Dec 2020 10:50:00 -0800 Message-ID: X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201218185011.1366-1-kun.q@outlook.com> References: <20201218185011.1366-1-kun.q@outlook.com> X-TMN: [1HKIG5gFgECHkVgcSxa++BF6ENg6ZQm3] X-ClientProxiedBy: MW2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:907::31) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20201218185011.1366-5-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MW2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:907::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Fri, 18 Dec 2020 18:50:29 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 705d337f-1a51-486f-ee11-08d8a385ca8a X-MS-TrafficTypeDiagnostic: DM6NAM11HT054: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tvVHTzcd0i+xLdZmAZmAfVkXQgxT9U21UWqVSaFTD7L7OmWNRFH54UwTjQn9WimDbOVhBNbhdqWe4zcF8qbDIzNR6uqh7ogE5xcyrXt11E+A4G8WIU2Pk3Ksq6brL6G6i26eZFjyH2S05RgPCTAQ75j/EfZ3tZzbOM58Aw5302WjM7Sca0xWh/2gcvhEBH4IDDEwY7mzKDCVQmoqaFvpTck6SxJEHyf0VilSuGmSsGmkUKH2QEoeHUegDEyiAPqb X-MS-Exchange-AntiSpam-MessageData: vTfzP/9a6JZNxrwjHjR0TZkujJsF4aRHaEe+WjWFQ0TihiX/oxzGOFkEvdgl+OTw9yxw+6NKXv4SPj1ziLw0PTtumITU/DUUQc7jq0krnOMnPzPuyNuLZsb+tM9gt0wWXvUT2z0EWt/UvyqjykUVng== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2020 18:50:29.5896 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 705d337f-1a51-486f-ee11-08d8a385ca8a X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM11HT054 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This change extends StandaloneMmMemLib library to support X64 architecture. The implementation is ported from MdePkg/Library/SmmMemLib. Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Jiewen Yao Cc: Supreeth Venkatesh Signed-off-by: Kun Qin --- StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInternal.= c | 67 ++++++++++++++++++++ StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf = | 6 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMem= LibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm= MemLibInternal.c new file mode 100644 index 000000000000..c5e21c583f44 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInte= rnal.c @@ -0,0 +1,67 @@ +/** @file + Internal ARCH Specific file of MM memory check library. + + MM memory check library implementation. This library consumes MM_ACCESS_= PROTOCOL + to get MMRAM information. In order to use this library instance, the pla= tform should produce + all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware= (like MM Core + and MM driver) and/or specific dedicated hardware. + + Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +// +// Maximum support address used to check input buffer +// +extern EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress; + +/** + Calculate and save the maximum support address. + +**/ +VOID +MmMemLibInternalCalculateMaximumSupportAddress ( + VOID + ) +{ + VOID *Hob; + UINT32 RegEax; + UINT8 PhysicalAddressBits; + + // + // Get physical address bits supported. + // + Hob =3D GetFirstHob (EFI_HOB_TYPE_CPU); + if (Hob !=3D NULL) { + PhysicalAddressBits =3D ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace; + } else { + AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); + if (RegEax >=3D 0x80000008) { + AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); + PhysicalAddressBits =3D (UINT8) RegEax; + } else { + PhysicalAddressBits =3D 36; + } + } + // + // IA-32e paging translates 48-bit linear addresses to 52-bit physical a= ddresses. + // + ASSERT (PhysicalAddressBits <=3D 52); + if (PhysicalAddressBits > 48) { + PhysicalAddressBits =3D 48; + } + + // + // Save the maximum support address in one global variable + // + mMmMemLibInternalMaximumSupportAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= (LShiftU64 (1, PhysicalAddressBits) - 1); + DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress =3D 0x%lx\n"= , mMmMemLibInternalMaximumSupportAddress)); +} + + diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.= inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf index 49da02e54e6d..65ad0a48905c 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf @@ -26,12 +26,15 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D AARCH64 +# VALID_ARCHITECTURES =3D X64 AARCH64 # =20 [Sources.Common] StandaloneMmMemLib.c =20 +[Sources.X64] + X64/StandaloneMmMemLibInternal.c + [Sources.AARCH64] AArch64/StandaloneMmMemLibInternal.c =20 @@ -42,3 +45,4 @@ [Packages] [LibraryClasses] BaseMemoryLib DebugLib + HobLib --=20 2.28.0.windows.1