Vlv2TbltDevicePkg: Enhance get mtrr mask logic.
In order to not use the deprecated macro, refine get mtrr mask value logic. Cc: Jeff Fan <jeff.fan@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: David Wei <david.wei@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
@@ -70,6 +70,34 @@ GetMemorySize (
|
||||
{ EfiMaxMemoryType, 0 }
|
||||
};
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetMemorySize (
|
||||
IN CONST EFI_PEI_SERVICES **PeiServices,
|
||||
OUT UINT64 *LowMemoryLength,
|
||||
OUT UINT64 *HighMemoryLength
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Initializes the valid address mask for MTRRs.
|
||||
|
||||
This function initializes the valid bits mask and valid address mask for MTRRs.
|
||||
|
||||
**/
|
||||
UINT64
|
||||
InitializeAddressMtrrMask (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINT32 RegEax;
|
||||
UINT8 PhysicalAddressBits;
|
||||
UINT64 ValidMtrrBitsMask;
|
||||
|
||||
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
|
||||
|
||||
if (RegEax >= 0x80000008) {
|
||||
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
|
||||
|
||||
PhysicalAddressBits = (UINT8) RegEax;
|
||||
} else {
|
||||
@@ -89,6 +117,7 @@ SetPeiCacheMode (
|
||||
EFI_STATUS Status;
|
||||
PEI_CACHE_PPI *CachePpi;
|
||||
|
||||
EFI_BOOT_MODE BootMode;
|
||||
UINT64 MemoryLength;
|
||||
UINT64 MemOverflow;
|
||||
UINT64 MemoryLengthUc;
|
||||
@@ -124,6 +153,8 @@ SetPeiCacheMode (
|
||||
//
|
||||
// Variable initialization
|
||||
//
|
||||
LowMemoryLength = 0;
|
||||
HighMemoryLength = 0;
|
||||
MemoryLengthUc = 0;
|
||||
|
||||
Status = (*PeiServices)->GetBootMode (
|
||||
@@ -166,15 +197,15 @@ SetPeiCacheMode (
|
||||
for (Index = 0; Index < 2; Index++) {
|
||||
MtrrSetting.Fixed.Mtrr[Index]=0x0606060606060606;
|
||||
}
|
||||
for (Index = 2; Index < 11; Index++) {
|
||||
for (Index = 2; Index < 11; Index++) {
|
||||
MtrrSetting.Fixed.Mtrr[Index]=0x0505050505050505;
|
||||
}
|
||||
|
||||
//
|
||||
// Cache the flash area to improve the boot performance in PEI phase
|
||||
// Cache the flash area to improve the boot performance in PEI phase
|
||||
//
|
||||
Index = 0;
|
||||
MtrrSetting.Variables.Mtrr[0].Base = (FixedPcdGet32 (PcdFlashAreaBaseAddress) | CacheWriteProtected);
|
||||
MtrrSetting.Variables.Mtrr[0].Base = (FixedPcdGet32 (PcdFlashAreaBaseAddress) | CacheWriteProtected);
|
||||
MtrrSetting.Variables.Mtrr[0].Mask = ((~((UINT64)(FixedPcdGet32 (PcdFlashAreaSize) - 1))) & ValidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED;
|
||||
Index ++;
|
||||
|
||||
@@ -185,15 +216,15 @@ SetPeiCacheMode (
|
||||
MemoryLength = GetPowerOfTwo64 (MemoryLength);
|
||||
MtrrSetting.Variables.Mtrr[Index].Mask = ((~(MemoryLength - 1)) & ValidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED;
|
||||
|
||||
MemOverflow += MemoryLength;
|
||||
Index++;
|
||||
MemOverflow += MemoryLength;
|
||||
Index++;
|
||||
}
|
||||
|
||||
MemoryLength = LowMemoryLength;
|
||||
|
||||
while (MaxMemoryLength != MemoryLength) {
|
||||
MemoryLengthUc = GetPowerOfTwo64 (MaxMemoryLength - MemoryLength);
|
||||
|
||||
|
||||
MtrrSetting.Variables.Mtrr[Index].Base = ((MaxMemoryLength - MemoryLengthUc) & ValidMtrrAddressMask) | CacheUncacheable;
|
||||
MtrrSetting.Variables.Mtrr[Index].Mask= ((~(MemoryLengthUc - 1)) & ValidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED;
|
||||
MaxMemoryLength -= MemoryLengthUc;
|
||||
@@ -201,7 +232,7 @@ SetPeiCacheMode (
|
||||
}
|
||||
|
||||
MemOverflow =0x100000000;
|
||||
while (HighMemoryLength > 0) {
|
||||
while (HighMemoryLength > 0) {
|
||||
MtrrSetting.Variables.Mtrr[Index].Base = (MemOverflow & ValidMtrrAddressMask) | CacheWriteBack;
|
||||
MemoryLength = HighMemoryLength;
|
||||
MemoryLength = GetPowerOfTwo64 (MemoryLength);
|
||||
|
Reference in New Issue
Block a user