From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.20950.1641979953960299875 for ; Wed, 12 Jan 2022 01:32:34 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=AJN0iSF0; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: yu.pu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641979953; x=1673515953; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=IG3kY4nzQ25I8F1WceKjOapaI98HCQq1PFpELXDIbfw=; b=AJN0iSF0NN3aASHNhD9I3Y4JfrEMz9ofKhTyMmNNLUYL20GAaY5eaVD0 Lc7AjfMQjyVwoSm75R7SAX3FD/reVqw34p/f4yk6RWQqMlRWhIJU81y04 XIh0G/dVtIq0z0fiV4xi65RLeN0P8LJY9NIEr6nHpb6uN6o/cKZVhNaxw WsEa+iWBL9iWJZXsZ2r7KUv9gbAv2RUz1f47VW2+grKnlFyMTcb5wu7Tn 7ocGZD1yNkxIgWFVl+wRVgxwuYxHKJUBDz8r/yvku6LYTybjifpJt1GeB LgXXfa+pEodCbp9rtWNVDYqmCsunHPPLEGOeGnxTXoTzSy09/IEnuNh17 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="241251546" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="241251546" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:32:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="558656677" Received: from shwdeopenlab704.ccr.corp.intel.com ([10.239.182.239]) by orsmga001.jf.intel.com with ESMTP; 12 Jan 2022 01:32:30 -0800 From: Yu Pu To: devel@edk2.groups.io Cc: Yu Pu , Eric Dong , Ray Ni , Rahul Kumar Subject: [PATCH v1 1/1] UefiCpuPackage: Add APIs for CPU physical address mask calculation Date: Wed, 12 Jan 2022 17:32:23 +0800 Message-Id: <20220112093223.963-1-yu.pu@intel.com> X-Mailer: git-send-email 2.30.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3394 Firmware contains lots of code that deals with page table.These code need the information of cpu physical address mask which can be calculated from CPUID result.Today all these code implements directly calls CPUID and calculates the address mask. This bugzilla requests to add a new API as below so that all the duplicated code can be removed. Cc: Eric Dong Cc: Ray Ni Signed-off-by: Yu Pu Reviewed-by: Rahul Kumar --- IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c = | 10 +---- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c = | 9 +--- MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c = | 14 +----- MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c = | 14 +----- OvmfPkg/XenPlatformPei/MemDetect.c = | 11 +---- StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c= | 9 +--- UefiCpuPkg/CpuDxe/CpuDxe.c = | 16 +------ UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c = | 47 ++++++++++++++++++++ UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c = | 9 +--- UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c = | 9 +--- UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c = | 9 +--- UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c = | 10 +---- UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c = | 9 +--- EmulatorPkg/EmulatorPkg.dsc = | 1 + IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf = | 1 + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf = | 2 + MdeModulePkg/MdeModulePkg.dsc = | 1 + MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.in= f | 1 + StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf = | 2 + StandaloneMmPkg/StandaloneMmPkg.dsc = | 1 + UefiCpuPkg/Include/Library/UefiCpuLib.h = | 17 +++++++ 21 files changed, 95 insertions(+), 107 deletions(-) diff --git a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c b/IntelFsp2Pkg/Li= brary/BaseCacheLib/CacheLib.c index f879c268e7ec..3f8ed122b2be 100644 --- a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c +++ b/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c @@ -9,6 +9,7 @@ #include =0D #include =0D #include =0D +#include =0D #include "CacheLibInternal.h"=0D =0D /**=0D @@ -388,15 +389,8 @@ SetCacheAttributes ( UINT32 UsedMsrNum;=0D EFI_MEMORY_CACHE_TYPE UsedMemoryCacheType;=0D UINT64 ValidMtrrAddressMask;=0D - UINT32 Cpuid_RegEax;=0D =0D - AsmCpuid (CPUID_EXTENDED_FUNCTION, &Cpuid_RegEax, NULL, NULL, NULL);=0D - if (Cpuid_RegEax >=3D CPUID_VIR_PHY_ADDRESS_SIZE) {=0D - AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &Cpuid_RegEax, NULL, NULL, NULL)= ;=0D - ValidMtrrAddressMask =3D (LShiftU64 ((UINT64)1, (Cpuid_RegEax & 0xFF))= - 1) & (~(UINT64)0x0FFF);=0D - } else {=0D - ValidMtrrAddressMask =3D (LShiftU64 ((UINT64)1, 36) - 1) & (~(UINT64)0= x0FFF);=0D - }=0D + GetPhysicalAddressBits(NULL, &ValidMtrrAddressMask);=0D =0D //=0D // Check for invalid parameter=0D diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 0700f310b203..78e91e6e9024 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D **/=0D =0D +#include =0D #include =0D #include "DxeIpl.h"=0D #include "VirtualMemory.h"=0D @@ -733,13 +734,7 @@ CreateIdentityMappingPageTables ( if (Hob !=3D NULL) {=0D PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;=0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits(NULL, NULL);=0D }=0D =0D Page5LevelSupport =3D FALSE;=0D diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEn= try.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c index 6b44f50bac70..367bf8cdd1e6 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c @@ -10,6 +10,7 @@ Copyright (c) 2017, AMD Incorporated. All rights reserved= .
SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D +#include =0D #include "ScriptExecute.h"=0D =0D //=0D @@ -51,20 +52,9 @@ HookPageFaultHandler ( IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry=0D )=0D {=0D - UINT32 RegEax;=0D - UINT8 PhysicalAddressBits;=0D UINTN PageFaultHandlerHookAddress;=0D =0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D -=0D - mPhyMask =3D LShiftU64 (1, PhysicalAddressBits) - 1;=0D - mPhyMask &=3D (1ull << 48) - SIZE_4KB;=0D + GetPhysicalAddressBits(NULL, &mPhyMask);=0D =0D //=0D // Set Page Fault entry to catch >4G access=0D diff --git a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c b/MdeModulePk= g/Universal/CapsulePei/X64/X64Entry.c index 05941f9f8d56..06d6129c5e6d 100644 --- a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c +++ b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include "CommonHeader.h"=0D =0D #define EXCEPTION_VECTOR_NUMBER 0x22=0D @@ -61,20 +62,9 @@ HookPageFaultHandler ( IN OUT PAGE_FAULT_CONTEXT *PageFaultContext=0D )=0D {=0D - UINT32 RegEax;=0D - UINT8 PhysicalAddressBits;=0D UINTN PageFaultHandlerHookAddress;=0D =0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D -=0D - PageFaultContext->PhyMask =3D LShiftU64 (1, PhysicalAddressBits) - 1;=0D - PageFaultContext->PhyMask &=3D (1ull << 48) - SIZE_4KB;=0D + GetPhysicalAddressBits(NULL, &(PageFaultContext->PhyMask));=0D =0D //=0D // Set Page Fault entry to catch >4G access=0D diff --git a/OvmfPkg/XenPlatformPei/MemDetect.c b/OvmfPkg/XenPlatformPei/Me= mDetect.c index d412d1f4db6f..bd24612c21ef 100644 --- a/OvmfPkg/XenPlatformPei/MemDetect.c +++ b/OvmfPkg/XenPlatformPei/MemDetect.c @@ -30,6 +30,7 @@ Module Name: #include =0D #include =0D #include =0D +#include =0D =0D #include "Platform.h"=0D #include "Cmos.h"=0D @@ -180,15 +181,7 @@ AddressWidthInitialization ( VOID=0D )=0D {=0D - UINT32 RegEax;=0D -=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - mPhysMemAddressWidth =3D (UINT8)RegEax;=0D - } else {=0D - mPhysMemAddressWidth =3D 36;=0D - }=0D + mPhysMemAddressWidth =3D GetPhysicalAddressBits(NULL, NULL);=0D =0D //=0D // IA-32e paging translates 48-bit linear addresses to 52-bit physical a= ddresses.=0D diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemL= ibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMe= mLibInternal.c index c309d1bc6a56..a5a96889ef85 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInter= nal.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInter= nal.c @@ -19,6 +19,7 @@ #include =0D #include =0D #include =0D +#include =0D =0D #include =0D #include =0D @@ -50,13 +51,7 @@ MmMemLibInternalCalculateMaximumSupportAddress ( if (Hob !=3D NULL) {=0D PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;=0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits (NULL, NULL);=0D }=0D =0D //=0D diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index 00f3cb09572c..8aca1bf72b4c 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -503,21 +503,7 @@ InitializeMtrrMask ( VOID=0D )=0D {=0D - UINT32 RegEax;=0D - UINT8 PhysicalAddressBits;=0D -=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D -=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D -=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D -=0D - mValidMtrrBitsMask =3D LShiftU64 (1, PhysicalAddressBits) - 1;=0D - mValidMtrrAddressMask =3D mValidMtrrBitsMask & 0xfffffffffffff000ULL;=0D + GetPhysicalAddressBits(&mValidMtrrBitsMask, &mValidMtrrAddressMask);=0D }=0D =0D /**=0D diff --git a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c b/UefiCpuPk= g/Library/BaseUefiCpuLib/BaseUefiCpuLib.c index 5d925bc273f8..bb1343f3cd21 100644 --- a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c +++ b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c @@ -79,3 +79,50 @@ GetCpuSteppingId ( =0D return (UINT8)Eax.Bits.SteppingId;=0D }=0D +=0D +/**=0D + Get the physical address width supported by the processor.=0D + @param[out] ValidAddressMask Bitmask with valid address bits se= t to=0D + one; other bits are clear. Optiona= l=0D + parameter.=0D + @param[out] ValidPageBaseAddressMask Bitmask with valid page base addre= ss=0D + bits set to one; other bits are cl= ear.=0D + Optional parameter.=0D + @return The physical address width supported by the processor.=0D +**/=0D +UINT8=0D +EFIAPI=0D +GetPhysicalAddressBits (=0D + OUT UINT64 *ValidAddressMask OPTIONAL,=0D + OUT UINT64 *ValidPageBaseAddressMask OPTIONAL=0D + )=0D +{=0D + UINT32 MaxExtendedFunction;=0D + CPUID_VIR_PHY_ADDRESS_SIZE_EAX VirPhyAddressSize;=0D + UINT64 AddressMask;=0D + UINT64 PageBaseAddressMask;=0D +=0D + AsmCpuid (CPUID_EXTENDED_FUNCTION, &MaxExtendedFunction, NULL, NULL, NUL= L);=0D + if (MaxExtendedFunction >=3D CPUID_VIR_PHY_ADDRESS_SIZE) {=0D + AsmCpuid (=0D + CPUID_VIR_PHY_ADDRESS_SIZE,=0D + &VirPhyAddressSize.Uint32,=0D + NULL,=0D + NULL,=0D + NULL=0D + );=0D + } else {=0D + VirPhyAddressSize.Bits.PhysicalAddressBits =3D 36;=0D + }=0D +=0D + AddressMask =3D LShiftU64 (1, VirPhyAddressSize.Bits.PhysicalAddressBits= ) - 1;=0D + PageBaseAddressMask =3D AddressMask & ~(UINT64)0xFFF;=0D +=0D + if (ValidAddressMask !=3D NULL) {=0D + *ValidAddressMask =3D AddressMask;=0D + }=0D + if (ValidPageBaseAddressMask !=3D NULL) {=0D + *ValidPageBaseAddressMask =3D PageBaseAddressMask;=0D + }=0D + return (UINT8)VirPhyAddressSize.Bits.PhysicalAddressBits;=0D +}=0D diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Lib= rary/SmmCpuFeaturesLib/SmmStm.c index 4e8f897f5e9c..ec7cd4013132 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c @@ -15,6 +15,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -330,13 +331,7 @@ SmmCpuFeaturesInstallSmiHandler ( if (Hob !=3D NULL) {=0D Psd->PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;= =0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - Psd->PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - Psd->PhysicalAddressBits =3D 36;=0D - }=0D + Psd->PhysicalAddressBits =3D GetPhysicalAddressBits (NULL, NULL);=0D }=0D =0D if (!mStmConfigurationTableInitialized) {=0D diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuD= xeSmm/X64/PageTbl.c index 538394f23910..de1385a86948 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -194,7 +194,6 @@ CalculateMaximumSupportAddress ( VOID=0D )=0D {=0D - UINT32 RegEax;=0D UINT8 PhysicalAddressBits;=0D VOID *Hob;=0D =0D @@ -205,13 +204,7 @@ CalculateMaximumSupportAddress ( if (Hob !=3D NULL) {=0D PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;=0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits (NULL, NULL);=0D }=0D =0D return PhysicalAddressBits;=0D diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c b/UefiCpuPkg= /Universal/Acpi/S3Resume2Pei/S3Resume.c index 8419a4e32acb..1017f0316093 100644 --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c @@ -42,6 +42,7 @@ #include =0D #include =0D #include =0D +#include =0D =0D /**=0D This macro aligns the address of a variable with auto storage=0D @@ -646,13 +647,7 @@ RestoreS3PageTables ( if (Hob !=3D NULL) {=0D PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;=0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits (NULL, NULL);=0D }=0D =0D //=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e36918a..4378aa4f1d97 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -4,6 +4,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D +#include =0D =0D #include "UefiPayloadEntry.h"=0D =0D @@ -341,7 +342,6 @@ BuildGenericHob ( VOID=0D )=0D {=0D - UINT32 RegEax;=0D UINT8 PhysicalAddressBits;=0D EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;=0D =0D @@ -351,13 +351,7 @@ BuildGenericHob ( //=0D // Build CPU memory space and IO space hob=0D //=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits(NULL, NULL);=0D =0D BuildCpuHob (PhysicalAddressBits, 16);=0D =0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayl= oadPkg/UefiPayloadEntry/X64/VirtualMemory.c index ac0d58e685c8..c61aeeda7f2e 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -25,6 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -738,13 +739,7 @@ CreateIdentityMappingPageTables ( if (Hob !=3D NULL) {=0D PhysicalAddressBits =3D ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;=0D } else {=0D - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);=0D - if (RegEax >=3D 0x80000008) {=0D - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);=0D - PhysicalAddressBits =3D (UINT8)RegEax;=0D - } else {=0D - PhysicalAddressBits =3D 36;=0D - }=0D + PhysicalAddressBits =3D GetPhysicalAddressBits (NULL, NULL);=0D }=0D =0D //=0D diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index 554c13ddb500..e33b98a4b682 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -78,6 +78,7 @@ HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf=0D DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf=0D UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompres= sLib.inf=0D + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf=0D =0D PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf=0D DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf=0D diff --git a/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf b/IntelFsp2= Pkg/Library/BaseCacheLib/BaseCacheLib.inf index 9a513fb6df77..52a6e839d77e 100644 --- a/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf +++ b/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf @@ -21,6 +21,7 @@ =0D [Packages]=0D MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D IntelFsp2Pkg/IntelFsp2Pkg.dec=0D =0D [LibraryClasses]=0D diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 19b8a4c8aefa..45808bcdcd6c 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -55,6 +55,7 @@ =0D [Packages]=0D MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D =0D [Packages.ARM, Packages.AARCH64]=0D @@ -75,6 +76,7 @@ DebugAgentLib=0D PeiServicesTablePointerLib=0D PerformanceLib=0D + UefiCpuLib=0D =0D [LibraryClasses.ARM, LibraryClasses.AARCH64]=0D ArmMmuLib=0D diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index b1d83461865e..da6213c02da0 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -62,6 +62,7 @@ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf=0D UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManag= erLib.inf=0D VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= ib.inf=0D + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf=0D #=0D # Generic Modules=0D #=0D diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptEx= ecutorDxe.inf b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScrip= tExecutorDxe.inf index fb149c2f0271..2839dedaccbe 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf @@ -41,6 +41,7 @@ =0D [Packages]=0D MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D =0D [LibraryClasses]=0D diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.= inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf index b29d97a74607..94f7fbb1c4f7 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf @@ -43,12 +43,14 @@ [Packages]=0D MdePkg/MdePkg.dec=0D StandaloneMmPkg/StandaloneMmPkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D =0D [LibraryClasses]=0D BaseMemoryLib=0D DebugLib=0D HobLib=0D MemoryAllocationLib=0D + UefiCpuLib=0D =0D [Guids]=0D gMmCoreDataHobGuid ## SOMETIMES_CONSUMES ## HOB=0D diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/StandaloneMmPkg/Standalo= neMmPkg.dsc index 8012f93b7dcc..41449046799f 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dsc +++ b/StandaloneMmPkg/StandaloneMmPkg.dsc @@ -59,6 +59,7 @@ StandaloneMmCoreEntryPoint|StandaloneMmPkg/Library/StandaloneMmCoreEntry= Point/StandaloneMmCoreEntryPoint.inf=0D StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint= /StandaloneMmDriverEntryPoint.inf=0D VariableMmDependency|StandaloneMmPkg/Library/VariableMmDependency/Variab= leMmDependency.inf=0D + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf=0D =0D [LibraryClasses.AARCH64, LibraryClasses.ARM]=0D ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf=0D diff --git a/UefiCpuPkg/Include/Library/UefiCpuLib.h b/UefiCpuPkg/Include/L= ibrary/UefiCpuLib.h index 0ff4a35774c1..dabed95ab38a 100644 --- a/UefiCpuPkg/Include/Library/UefiCpuLib.h +++ b/UefiCpuPkg/Include/Library/UefiCpuLib.h @@ -62,4 +62,21 @@ GetCpuSteppingId ( VOID=0D );=0D =0D +/**=0D + Get the physical address width supported by the processor.=0D + @param[out] ValidAddressMask Bitmask with valid address bits se= t to=0D + one; other bits are clear. Optiona= l=0D + parameter.=0D + @param[out] ValidPageBaseAddressMask Bitmask with valid page base addre= ss=0D + bits set to one; other bits are cl= ear.=0D + Optional parameter.=0D + @return The physical address width supported by the processor.=0D +**/=0D +UINT8=0D +EFIAPI=0D +GetPhysicalAddressBits (=0D + OUT UINT64 *ValidAddressMask OPTIONAL,=0D + OUT UINT64 *ValidPageBaseAddressMask OPTIONAL=0D + );=0D +=0D #endif=0D --=20 2.30.0.windows.2