From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.3218.1609904331918544983 for ; Tue, 05 Jan 2021 19:38:52 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=VNWG5gl7; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: jiewen.yao@intel.com) IronPort-SDR: 1RPpPg46i7MQk5/KiVVxFKEcWDwFTqGlE/tgD+7qYM5giwvymg/T8Ekcp3SO1eaWbFihu0bLC5 nLxFIWVyEKRQ== X-IronPort-AV: E=McAfee;i="6000,8403,9855"; a="164922224" X-IronPort-AV: E=Sophos;i="5.78,478,1599548400"; d="scan'208";a="164922224" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2021 19:38:51 -0800 IronPort-SDR: ukFagxkSd4zGUUVRto0E2ij3tGKpHLO0+fusgea2yC71Z1DvJtTULU/ASpG3UScGdH864l3FJr 3Jmo/ltCE8WQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,478,1599548400"; d="scan'208";a="398074831" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga002.fm.intel.com with ESMTP; 05 Jan 2021 19:38:51 -0800 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 5 Jan 2021 19:38:50 -0800 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 5 Jan 2021 19:38:49 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 5 Jan 2021 19:38:49 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.177) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Tue, 5 Jan 2021 19:38:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k3IdLrtUVU8BC7DBWb8xM+BVd8vDB59nO6HX0007ylyKbdFZzrgy41ze7NSpxD2wQJCVUrz7VUfWIlfYISZ3HDVannXpWvP1nmZIcT3MCD7mjyCZFDIQ0UAsqVFfaO2hXg69YdcFB2mogADx7qYxjIjuWES2sPwOGLX7qoAYQSEmxT1agtfcwftFj1g43cDXk2DA8lrWzSn5jB9ePTohlC+eGozEqDtx44HHZ0Ba8LMtldMdHkWC47xXa45Mdk1Beqqg+tx2LaRLqWhCK3hJ70taq7AOah4zA2gv10eJmbwaEaS5cjd+uWGnl9OMM+chc8Mgv+qx+bCmFb3Rxv+ekw== 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=EAaT5hi78z+eb6U9mvjOSCE4wBbjpgYq8XqAIsFVcLE=; b=Oy1iBBCCHgE/4YhLPYYBTsVjIeOZLFvoAgZh16KH4Tsllxb15MKnKeyFhmskORZIc15NVgTHZTx0gxmiv4jkgdfMv8JfhuPN7iCEk6RDMjMm8foTrRJF2DA7XNj/zBMAmXBfBjVskRcbwqwJ1Lxs2e2tiI1QoFPSnBK515nJy1ohLuTnI6egdGVs6Ey57kGv+pHzIrKziCoxXiCSD9nhYgDMENf5tHADkClHa97FOQ/ILr7FQCU6J3FSmEl4ercU4ntZwaadmsY2KZphxFBds7puzkzpcnUYR4PvM5p5Mdl6bz9h4Kkia/yh8UJ+GCv8uAo0T2yCJMn/BfEhJUyo9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EAaT5hi78z+eb6U9mvjOSCE4wBbjpgYq8XqAIsFVcLE=; b=VNWG5gl74wMUaYgQ5THmKHHNv/mOnd0mQZoHKVN7IWEiR7KvZ210ciLd1pAdSMQU+jwLo72kmkp5uK2Tdjx0GqxhovY6cV/sVMosxkAyUda07u6VGgHvUq9NAd9nBZ0luIHdI+FwdVMpudPN07/2xxsZKgl8Syi9X6xaDZUscBM= Received: from CO1PR11MB5188.namprd11.prod.outlook.com (2603:10b6:303:95::16) by MW3PR11MB4729.namprd11.prod.outlook.com (2603:10b6:303:5d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.21; Wed, 6 Jan 2021 03:38:48 +0000 Received: from CO1PR11MB5188.namprd11.prod.outlook.com ([fe80::14d2:6c29:dc6d:5d6a]) by CO1PR11MB5188.namprd11.prod.outlook.com ([fe80::14d2:6c29:dc6d:5d6a%3]) with mapi id 15.20.3742.006; Wed, 6 Jan 2021 03:38:48 +0000 From: "Yao, Jiewen" To: Kun Qin , "devel@edk2.groups.io" CC: Ard Biesheuvel , Sami Mujawar , Supreeth Venkatesh Subject: Re: [PATCH v2 04/16] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Thread-Topic: [PATCH v2 04/16] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Thread-Index: AQHW45UEVvK2qfaQNUW5Kl12BFaWXKoZ8ruA Date: Wed, 6 Jan 2021 03:38:48 +0000 Message-ID: References: <20210105185935.3769-1-kun.q@outlook.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: outlook.com; dkim=none (message not signed) header.d=none;outlook.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.204] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7ea93db5-21e8-4031-f6eb-08d8b1f493d8 x-ms-traffictypediagnostic: MW3PR11MB4729: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: oBpHkTR68V5Ca1ea5meWYiIAtwGM0hUABGITP9tEX2E2BMS3jpJESc6XWiW6lIhsq0TN4rmcbJzoUX1gro38EnFqhEpQkJ9KWpu5fJ+ZBS8EyZxBOPR8IF5Ca01o3r32Hud9RDuHtlWfJLBVhJ3I1i5iIq6Nm6O+tjIsk3nBpILr+hcAOH0HH8t+rtoUDqRTtbY3v0Br701HL26rdc/niow2MrMur4LdbXW8AaD/03akH855L2etMHLkTLg1mkdXxxCWrFpfHOnN/ZgnyIw9XOoO1W7W6po+wPgyoV36LBfq4xOgo+ZCoINQZkEUhHhUe1/tsCfjyYS9IosgYRPgPs0cNGHcRJpRdT1tAagbtKqNqWGflxykFlOaVe/sMDAbLBoqTi0+pgxYDTJz+pa6Wg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB5188.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(346002)(39860400002)(366004)(376002)(136003)(396003)(66946007)(66446008)(66476007)(66556008)(8676002)(64756008)(2906002)(8936002)(76116006)(52536014)(4326008)(86362001)(7696005)(54906003)(110136005)(53546011)(9686003)(26005)(83380400001)(19627235002)(45080400002)(71200400001)(6506007)(316002)(33656002)(5660300002)(478600001)(30864003)(55016002)(186003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?8ocHB1NEkj9RO9msE9WYkJuEJ5MF3iaTC3a2Sj5G3acljjfeLhL0YfaIj61v?= =?us-ascii?Q?/pqpiTC3MRXvkP57P1ipNqHS6/Gq6QI6aQN478OHa6kXCByPIihMYG05zYI8?= =?us-ascii?Q?szjQfk/FRLp9+ScOLIkzsRT2idzFLrnm8VXwxzSKFNth2TvuKFU1Xlw8n797?= =?us-ascii?Q?B2ChPlVkWyUyt7UpjcXy2QkwFWzNGmb6Eq1+TW9KASA0Meva+ZEa1+DRt9na?= =?us-ascii?Q?KXfF8yjEnMTegVcrOsZ+eYLpA90RDTtBQNdHwfUbcT0P9gqwAl4PKS5FipDD?= =?us-ascii?Q?Gl6D8/Sdd3ecSyf3dBGJsgTnj58sutAqT4C99Cxu7HRH20kLVQxdncrefLYI?= =?us-ascii?Q?XvyjJCQptIhf8ecN8xfjvVreIFM/T6eXgNvlvOfPEJfL4xuPhr2u2gCSEc9a?= =?us-ascii?Q?IodNXCBrlEFIFDtqrsCwqC1BHGnP8Sd51Vq/I1753P7CRqtOlVp9l8BfxhnU?= =?us-ascii?Q?PVcjCBnsfZ7Rn0AB2aaphxWOOhgPQ/lCB2kG2eZjP3/TgY6f8o5fRM5JCZ5B?= =?us-ascii?Q?V21f6OVgwT4EA5bKFx+oM2mY+ItBFd+rhLe+IHlx/K9Ehq7AcqVcyxG4xGYT?= =?us-ascii?Q?UQ006gSLKKiPr4CNsFGAuvLbfN8ANNuW4zSrgR7f8SwumOBGQdVO/Zgd4wqZ?= =?us-ascii?Q?6gHiZBueQIFeIxVUVcX1OHyn1Rq/iKpiOxBfI0OvfwSYFNpsWlYXgOozds4b?= =?us-ascii?Q?JOkoRjkYvPLuVMpRjB4fB61/hYCubocBu1IxZ8hxVdspaIjxyxJsELgoRqOe?= =?us-ascii?Q?RILThISQZnbaAexSSQpsUk5ajrD7RoM9D7nxgs1jzPfTJQ13lcQJ+burzsYY?= =?us-ascii?Q?J/johKtrBiHig9TE+AOtIY++TSSfutmihONdijAVjKWLNvJJ13vm+OCfsoG2?= =?us-ascii?Q?8r3+su7Hp/DHyqoqRBRr/wu8XjdT9OLVUrvP1BQoteFWLyAaDX8fQMIeMsuZ?= =?us-ascii?Q?BoHLfIH7KM8E/qkRbvq6ld028OeWn9ucHX+WJydX+Mo=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5188.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ea93db5-21e8-4031-f6eb-08d8b1f493d8 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2021 03:38:48.2097 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +RppvwPSZ2wWGGm6aEgVef0Mvvsoc2jzpxVE2a7NCQARYa/mT15PSE3+Vj2Qf9DlK5gDn/otIdkLsDPnPj+pmA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4729 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Qin. A quick question: May I know what test you have run for this change? Also, I think this patch only protect the MM memory, but not OS memory. Is = that expected? Will you consider adding OS memory protection later? > -----Original Message----- > From: Kun Qin > Sent: Wednesday, January 6, 2021 2:59 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Sami Mujawar > ; Yao, Jiewen ; Supreeth > Venkatesh > Subject: [PATCH v2 04/16] StandaloneMmPkg: StandaloneMmMemLib: > Extends support for X64 architecture >=20 > This change extends StandaloneMmMemLib library to support X64 > architecture. The implementation is ported from > MdePkg/Library/SmmMemLib. >=20 > Cc: Ard Biesheuvel > Cc: Sami Mujawar > Cc: Jiewen Yao > Cc: Supreeth Venkatesh >=20 > Signed-off-by: Kun Qin > --- >=20 > Notes: > v2: > - Added routine to fix bug of not initializing MmRanges [Jiewen] > - Extends support to x86 instead of x64 only [Hao] >=20 >=20 > StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneM > mMemLibInternal.c | 26 ++++ >=20 > StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib > .c | 52 +++++++ >=20 > StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMe > mLibInternal.c | 155 ++++++++++++++++++++ >=20 > StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib > .inf | 13 +- > 4 files changed, 245 insertions(+), 1 deletion(-) >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/Standalone > MmMemLibInternal.c > b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/Standalone > MmMemLibInternal.c > index cb7c5e677a6b..46dfce5cac86 100644 > --- > a/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/Standalone > MmMemLibInternal.c > +++ > b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/Standalone > MmMemLibInternal.c > @@ -40,4 +40,30 @@ > MmMemLibInternalCalculateMaximumSupportAddress ( > DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress > =3D 0x%lx\n", mMmMemLibInternalMaximumSupportAddress)); > } >=20 > +/** > + Initialize cached Mmram Ranges from HOB. > + > + @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM > information. > + @retval EFI_SUCCESS MmRanges are populated successfully. > + > +**/ > +EFI_STATUS > +MmMemLibInternalPopulateMmramRanges ( > + VOID > + ) > +{ > + // Not implemented for AARCH64. > +} > + > +/** > + Deinitialize cached Mmram Ranges. > + > +**/ > +VOID > +MmMemLibInternalFreeMmramRanges ( > + VOID > + ) > +{ > + // Not implemented for AARCH64. > +} >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.c > b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.c > index f82cdb3ba816..f43af2b1cc9b 100644 > --- > a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.c > +++ > b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.c > @@ -37,6 +37,27 @@ > MmMemLibInternalCalculateMaximumSupportAddress ( > VOID > ); >=20 > +/** > + Initialize cached Mmram Ranges from HOB. > + > + @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM > information. > + @retval EFI_SUCCESS MmRanges are populated successfully. > + > +**/ > +EFI_STATUS > +MmMemLibInternalPopulateMmramRanges ( > + VOID > + ); > + > +/** > + Deinitialize cached Mmram Ranges. > + > +**/ > +VOID > +MmMemLibInternalFreeMmramRanges ( > + VOID > + ); > + > /** > This function check if the buffer is valid per processor architecture = and not > overlap with MMRAM. >=20 > @@ -253,11 +274,42 @@ MemLibConstructor ( > IN EFI_MM_SYSTEM_TABLE *MmSystemTable > ) > { > + EFI_STATUS Status; >=20 > // > // Calculate and save maximum support address > // > MmMemLibInternalCalculateMaximumSupportAddress (); >=20 > + // > + // Initialize cached Mmram Ranges from HOB. > + // > + Status =3D MmMemLibInternalPopulateMmramRanges (); > + > + return Status; > +} > + > +/** > + Destructor for the library. free any resources for Mm Mem library > + > + @param ImageHandle The image handle of the process. > + @param SystemTable The EFI System Table pointer. > + > + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. > + > +**/ > +EFI_STATUS > +EFIAPI > +MemLibDestructor ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_MM_SYSTEM_TABLE *MmSystemTable > + ) > +{ > + > + // > + // Deinitialize cached Mmram Ranges. > + // > + MmMemLibInternalFreeMmramRanges (); > + > return EFI_SUCCESS; > } > diff --git > a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmM > emLibInternal.c > b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMm > MemLibInternal.c > new file mode 100644 > index 000000000000..1a978541716a > --- /dev/null > +++ > b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMm > MemLibInternal.c > @@ -0,0 +1,155 @@ > +/** @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 > platform 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.
> + Copyright (c) Microsoft Corporation. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +// > +// Maximum support address used to check input buffer > +// > +extern EFI_PHYSICAL_ADDRESS > mMmMemLibInternalMaximumSupportAddress; > +extern EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges; > +extern UINTN mMmMemLibInternalMmramCount; > + > +/** > + 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 > addresses. > + // > + 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)); > +} > + > +/** > + Initialize cached Mmram Ranges from HOB. > + > + @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM > information. > + @retval EFI_SUCCESS MmRanges are populated successfully. > + > +**/ > +EFI_STATUS > +MmMemLibInternalPopulateMmramRanges ( > + VOID > + ) > +{ > + VOID *HobStart; > + EFI_HOB_GUID_TYPE *GuidHob; > + MM_CORE_DATA_HOB_DATA *DataInHob; > + MM_CORE_PRIVATE_DATA *MmCorePrivateData; > + EFI_HOB_GUID_TYPE *MmramRangesHob; > + EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData; > + EFI_MMRAM_DESCRIPTOR *MmramDescriptors; > + > + HobStart =3D GetHobList (); > + DEBUG ((DEBUG_INFO, "%a - 0x%x\n", __FUNCTION__, HobStart)); > + > + // > + // Extract MM Core Private context from the Hob. If absent search for > + // a Hob containing the MMRAM ranges > + // > + GuidHob =3D GetNextGuidHob (&gMmCoreDataHobGuid, HobStart); > + if (GuidHob =3D=3D NULL) { > + MmramRangesHob =3D GetFirstGuidHob > (&gEfiMmPeiMmramMemoryReserveGuid); > + if (MmramRangesHob =3D=3D NULL) { > + return EFI_UNSUPPORTED; > + } > + > + MmramRangesHobData =3D GET_GUID_HOB_DATA (MmramRangesHob); > + if (MmramRangesHobData =3D=3D NULL || MmramRangesHobData- > >Descriptor =3D=3D NULL) { > + return EFI_UNSUPPORTED; > + } > + > + mMmMemLibInternalMmramCount =3D MmramRangesHobData- > >NumberOfMmReservedRegions; > + MmramDescriptors =3D MmramRangesHobData->Descriptor; > + } else { > + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); > + if (DataInHob =3D=3D NULL) { > + return EFI_UNSUPPORTED; > + } > + > + MmCorePrivateData =3D (MM_CORE_PRIVATE_DATA *) (UINTN) > DataInHob->Address; > + if (MmCorePrivateData =3D=3D NULL || MmCorePrivateData- > >MmramRanges =3D=3D 0) { > + return EFI_UNSUPPORTED; > + } > + > + mMmMemLibInternalMmramCount =3D (UINTN) MmCorePrivateData- > >MmramRangeCount; > + MmramDescriptors =3D (EFI_MMRAM_DESCRIPTOR *) (UINTN) > MmCorePrivateData->MmramRanges; > + } > + > + mMmMemLibInternalMmramRanges =3D AllocatePool > (mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR)); > + if (mMmMemLibInternalMmramRanges) { > + CopyMem (mMmMemLibInternalMmramRanges, > + MmramDescriptors, > + mMmMemLibInternalMmramCount * sizeof > (EFI_MMRAM_DESCRIPTOR)); > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Deinitialize cached Mmram Ranges. > + > +**/ > +VOID > +MmMemLibInternalFreeMmramRanges ( > + VOID > + ) > +{ > + if (mMmMemLibInternalMmramRanges !=3D NULL) { > + FreePool (mMmMemLibInternalMmramRanges); > + } > +} > + > diff --git > a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.inf > b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.inf > index 49da02e54e6d..062b0d7a1161 100644 > --- > a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.inf > +++ > b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem > Lib.inf > @@ -8,6 +8,7 @@ > # > # Copyright (c) 2015, Intel Corporation. All rights reserved.
> # Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
> +# Copyright (c) Microsoft Corporation. > # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -22,16 +23,20 @@ [Defines] > PI_SPECIFICATION_VERSION =3D 0x00010032 > LIBRARY_CLASS =3D MemLib|MM_STANDALONE > MM_CORE_STANDALONE > CONSTRUCTOR =3D MemLibConstructor > + DESTRUCTOR =3D MemLibDestructor >=20 > # > # The following information is for reference only and not required by th= e > build tools. > # > -# VALID_ARCHITECTURES =3D AARCH64 > +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 > # >=20 > [Sources.Common] > StandaloneMmMemLib.c >=20 > +[Sources.IA32, Sources.X64] > + X86StandaloneMmMemLibInternal.c > + > [Sources.AARCH64] > AArch64/StandaloneMmMemLibInternal.c >=20 > @@ -42,3 +47,9 @@ [Packages] > [LibraryClasses] > BaseMemoryLib > DebugLib > + HobLib > + MemoryAllocationLib > + > +[Guids] > + gMmCoreDataHobGuid ## SOMETIMES_CONSUMES ## HOB > + gEfiMmPeiMmramMemoryReserveGuid ## SOMETIMES_CONSUMES > ## HOB > -- > 2.30.0.windows.1