mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
UefiCpuPkg/MtrrLib: Remove the loop of calculating Fixed-MTRR Mask
Introduce the 32bit mask seeds to calculate Fixed-MTRR or&and mask values. It could avoid the loop operation and 64bit shift operations. Cc: Feng Tian <feng.tian@intel.com> Cc: Michael Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan <jeff.fan@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com>
This commit is contained in:
parent
aaa1e579a5
commit
07e8892090
@ -20,6 +20,9 @@
|
|||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
|
||||||
|
#define OR_SEED 0x01010101
|
||||||
|
#define CLEAR_SEED 0xFFFFFFFF
|
||||||
|
|
||||||
//
|
//
|
||||||
// Context to save and restore when MTRRs are programmed
|
// Context to save and restore when MTRRs are programmed
|
||||||
//
|
//
|
||||||
@ -460,11 +463,12 @@ ProgramFixedMtrr (
|
|||||||
{
|
{
|
||||||
UINT32 MsrNum;
|
UINT32 MsrNum;
|
||||||
UINT32 ByteShift;
|
UINT32 ByteShift;
|
||||||
UINT64 OrMask;
|
UINT32 OrMask[2];
|
||||||
UINT64 ClearMask;
|
UINT32 ClearMask[2];
|
||||||
|
UINT64 SubLength;
|
||||||
|
|
||||||
OrMask = 0;
|
*(UINT64 *)OrMask = 0;
|
||||||
ClearMask = 0;
|
*(UINT64 *)ClearMask = 0;
|
||||||
|
|
||||||
for (MsrNum = *LastMsrNum + 1; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {
|
for (MsrNum = *LastMsrNum + 1; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {
|
||||||
if ((*Base >= mMtrrLibFixedMtrrTable[MsrNum].BaseAddress) &&
|
if ((*Base >= mMtrrLibFixedMtrrTable[MsrNum].BaseAddress) &&
|
||||||
@ -493,24 +497,27 @@ ProgramFixedMtrr (
|
|||||||
return RETURN_UNSUPPORTED;
|
return RETURN_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (
|
if (ByteShift < 4) {
|
||||||
;
|
OrMask[0] = OR_SEED * (UINT32)MemoryCacheType;
|
||||||
((ByteShift < 8) && (*Length >= mMtrrLibFixedMtrrTable[MsrNum].Length));
|
ClearMask[0] = CLEAR_SEED;
|
||||||
ByteShift++
|
OrMask[1] = (OR_SEED * (UINT32)MemoryCacheType) >> ((4 - ByteShift) * 8);
|
||||||
) {
|
ClearMask[1] = CLEAR_SEED >> ((4 - ByteShift) * 8);
|
||||||
OrMask |= LShiftU64 ((UINT64) MemoryCacheType, (UINT32) (ByteShift * 8));
|
} else {
|
||||||
ClearMask |= LShiftU64 ((UINT64) 0xFF, (UINT32) (ByteShift * 8));
|
OrMask[0] = (OR_SEED * (UINT32)MemoryCacheType) >> ((8 - ByteShift) * 8);
|
||||||
*Length -= mMtrrLibFixedMtrrTable[MsrNum].Length;
|
ClearMask[0] = CLEAR_SEED >> ((8 - ByteShift) * 8);
|
||||||
*Base += mMtrrLibFixedMtrrTable[MsrNum].Length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ByteShift < 8 && (*Length != 0)) {
|
SubLength = mMtrrLibFixedMtrrTable[MsrNum].Length * (8 - ByteShift);
|
||||||
|
if (*Length < SubLength) {
|
||||||
return RETURN_UNSUPPORTED;
|
return RETURN_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*Length -= SubLength;
|
||||||
|
*Base += SubLength;
|
||||||
|
|
||||||
*LastMsrNum = MsrNum;
|
*LastMsrNum = MsrNum;
|
||||||
*ReturnClearMask = ClearMask;
|
*ReturnClearMask = *(UINT64 *)ClearMask;
|
||||||
*ReturnOrMask = OrMask;
|
*ReturnOrMask = *(UINT64 *)OrMask;
|
||||||
|
|
||||||
return RETURN_SUCCESS;
|
return RETURN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user