From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.5530.1646212796036188164 for ; Wed, 02 Mar 2022 01:19:59 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=eRgsETl5; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1646212799; x=1677748799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rb9QLAx3eG00niSxWWxedc2osABJBl+4hkQCjI37OvQ=; b=eRgsETl5hJTYwk3nZq/R56CSNlE1j2OePttFxJzStTsG2GVfBPqVoFir RzlZPU/0vxNtDolph7xeOoS0oBUJCDbW+N4o6i67Gw9kLnNgfO2cWqdhM w63Ma0zA/FY7XkDcskRdEKAoS67JFbdGOGb6Le0llfGjLh8I4hMj5sAKP zadNKBLCIcvHOkoiBQ2cF6MpNbPhevA0kqOiSkr37oPEyvEyUDw93pRnS /xctAAJD7BC2Y4RpkLxytv5/7xodfG2dZizL4VVErdbei6SkXPaMx9nJU DHG0Bdru+NJdlAD9zuBFHI+Mryj8LSkEXAZduvp4LyhxtA4e642as/Osk w==; X-IronPort-AV: E=McAfee;i="6200,9189,10273"; a="233324188" X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="233324188" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 01:19:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,148,1643702400"; d="scan'208";a="641630321" Received: from shwdeopenlab704.ccr.corp.intel.com ([10.239.182.239]) by orsmga004.jf.intel.com with ESMTP; 02 Mar 2022 01:19:57 -0800 From: Yu Pu To: devel@edk2.groups.io Cc: Yu Pu , Jian J Wang , Liming Gao Subject: [PATCH v1 2/7] MdeModulePkg: Invoke GetPhysicalAddressBits() and remove the duplicated code Date: Wed, 2 Mar 2022 17:18:54 +0800 Message-Id: <20220302091859.2783-3-yu.pu@intel.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20220302091859.2783-1-yu.pu@intel.com> References: <20220302091859.2783-1-yu.pu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3394 Invoke GetPhysicalAddressBits() defined in UefiCpuPkg for CPU physical addr= ess mask calculation and remove the duplicated code in MdeModulePkg. Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Yu Pu --- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c = | 9 ++------- MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c = | 14 ++------------ MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c = | 14 ++------------ MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf = | 2 ++ MdeModulePkg/MdeModulePkg.dsc = | 1 + MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.in= f | 2 ++ MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf = | 2 ++ 7 files changed, 13 insertions(+), 31 deletions(-) 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/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..dd3dd2fc8c10 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 @@ -54,6 +55,7 @@ UefiBootServicesTableLib=0D CacheMaintenanceLib=0D UefiLib=0D + UefiCpuLib=0D DebugAgentLib=0D LockBoxLib=0D CpuExceptionHandlerLib=0D diff --git a/MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf b/MdeModulePk= g/Universal/CapsulePei/CapsuleX64.inf index 35d2535a5b48..75813b1e5481 100644 --- a/MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf +++ b/MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf @@ -38,12 +38,14 @@ [Packages]=0D MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D =0D [LibraryClasses]=0D BaseLib=0D DebugLib=0D CpuExceptionHandlerLib=0D DebugAgentLib=0D + UefiCpuLib=0D =0D [Depex]=0D FALSE=0D --=20 2.30.0.windows.2