REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3394

Invoke GetPhysicalAddressBits() defined in UefiCpuPkg for CPU
physical address mask calculation and remove the duplicated
code in edk2\IntelFsp2Pkg\Library\BaseCacheLib\CacheLib.c.

Cc: Chasel Chiu <chasel.c...@intel.com>

Signed-off-by: Yu Pu <yu...@intel.com>
---
 IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c       | 10 ++--------
 IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf |  2 ++
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c 
b/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c
index f879c268e7ec..3f8ed122b2be 100644
--- a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c
+++ b/IntelFsp2Pkg/Library/BaseCacheLib/CacheLib.c
@@ -9,6 +9,7 @@
 #include <Library/BaseLib.h>
 #include <Library/CacheLib.h>
 #include <Library/CacheAsRamLib.h>
+#include <Library/UefiCpuLib.h>
 #include "CacheLibInternal.h"
 
 /**
@@ -388,15 +389,8 @@ SetCacheAttributes (
   UINT32                 UsedMsrNum;
   EFI_MEMORY_CACHE_TYPE  UsedMemoryCacheType;
   UINT64                 ValidMtrrAddressMask;
-  UINT32                 Cpuid_RegEax;
 
-  AsmCpuid (CPUID_EXTENDED_FUNCTION, &Cpuid_RegEax, NULL, NULL, NULL);
-  if (Cpuid_RegEax >= CPUID_VIR_PHY_ADDRESS_SIZE) {
-    AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &Cpuid_RegEax, NULL, NULL, NULL);
-    ValidMtrrAddressMask = (LShiftU64 ((UINT64)1, (Cpuid_RegEax & 0xFF)) - 1) 
& (~(UINT64)0x0FFF);
-  } else {
-    ValidMtrrAddressMask = (LShiftU64 ((UINT64)1, 36) - 1) & (~(UINT64)0x0FFF);
-  }
+  GetPhysicalAddressBits(NULL, &ValidMtrrAddressMask);
 
   //
   // Check for invalid parameter
diff --git a/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf 
b/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf
index 9a513fb6df77..e6b14ae4a802 100644
--- a/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf
+++ b/IntelFsp2Pkg/Library/BaseCacheLib/BaseCacheLib.inf
@@ -21,9 +21,11 @@
 
 [Packages]
   MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
   IntelFsp2Pkg/IntelFsp2Pkg.dec
 
 [LibraryClasses]
   BaseMemoryLib
   CacheAsRamLib
+  UefiCpuLib
 
-- 
2.30.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#87236): https://edk2.groups.io/g/devel/message/87236
Mute This Topic: https://groups.io/mt/89503326/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to