diff options
author | Michael Kinney <michael.d.kinney@intel.com> | 2015-12-08 05:23:13 +0000 |
---|---|---|
committer | vanjeff <vanjeff@Edk2> | 2015-12-08 05:23:13 +0000 |
commit | d0baed7db51382d17efe92b1fc8fb741052f116a (patch) | |
tree | 8f6047eb8e28648f077b9e2a99f925719d30f3b9 /UefiCpuPkg | |
parent | acf431e6f7bd7691468904cb9bb19ab1cc44eccf (diff) | |
download | edk2-platforms-d0baed7db51382d17efe92b1fc8fb741052f116a.tar.xz |
UefiCpuPkg/MtrrLib: Add MtrrGetMemoryAttributeInVariableMtrrWorker ()
Add function to shadow the content of variable MTRRs into an internal array:
VariableMtrr. And used MtrrGetMemoryAttributeInVariableMtrrWorker() in other
functions.
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: Michael Kinney <michael.d.kinney@intel.com>
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19156 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r-- | UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 121 |
1 files changed, 82 insertions, 39 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 0358fffb28..697dc4352f 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -496,6 +496,50 @@ ProgramFixedMtrr ( /**
+ Worker function gets the attribute of variable MTRRs.
+
+ This function shadows the content of variable MTRRs into an
+ internal array: VariableMtrr.
+
+ @param[in] VariableSettings The variable MTRR values to shadow
+ @param[in] FirmwareVariableMtrrCount The number of variable MTRRs available to firmware
+ @param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR
+ @param[in] MtrrValidAddressMask The valid address mask for MTRR
+ @param[out] VariableMtrr The array to shadow variable MTRRs content
+
+ @return The return value of this parameter indicates the
+ number of MTRRs which has been used.
+
+**/
+UINT32
+MtrrGetMemoryAttributeInVariableMtrrWorker (
+ IN MTRR_VARIABLE_SETTINGS *VariableSettings,
+ IN UINTN FirmwareVariableMtrrCount,
+ IN UINT64 MtrrValidBitsMask,
+ IN UINT64 MtrrValidAddressMask,
+ OUT VARIABLE_MTRR *VariableMtrr
+ )
+{
+ UINTN Index;
+ UINT32 UsedMtrr;
+
+ ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * MTRR_NUMBER_OF_VARIABLE_MTRR);
+ for (Index = 0, UsedMtrr = 0; Index < FirmwareVariableMtrrCount; Index++) {
+ if ((VariableSettings->Mtrr[Index].Mask & MTRR_LIB_CACHE_MTRR_ENABLED) != 0) {
+ VariableMtrr[Index].Msr = (UINT32)Index;
+ VariableMtrr[Index].BaseAddress = (VariableSettings->Mtrr[Index].Base & MtrrValidAddressMask);
+ VariableMtrr[Index].Length = ((~(VariableSettings->Mtrr[Index].Mask & MtrrValidAddressMask)) & MtrrValidBitsMask) + 1;
+ VariableMtrr[Index].Type = (VariableSettings->Mtrr[Index].Base & 0x0ff);
+ VariableMtrr[Index].Valid = TRUE;
+ VariableMtrr[Index].Used = TRUE;
+ UsedMtrr++;
+ }
+ }
+ return UsedMtrr;
+}
+
+
+/**
Gets the attribute of variable MTRRs.
This function shadows the content of variable MTRRs into an
@@ -517,46 +561,24 @@ MtrrGetMemoryAttributeInVariableMtrr ( OUT VARIABLE_MTRR *VariableMtrr
)
{
- UINTN Index;
- UINT32 MsrNum;
- UINT32 UsedMtrr;
- UINT32 FirmwareVariableMtrrCount;
- UINT32 VariableMtrrEnd;
+ MTRR_VARIABLE_SETTINGS VariableSettings;
if (!IsMtrrSupported ()) {
return 0;
}
- FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCountWorker ();
- VariableMtrrEnd = MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (2 * GetVariableMtrrCount ()) - 1;
-
- ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * MTRR_NUMBER_OF_VARIABLE_MTRR);
- UsedMtrr = 0;
+ MtrrGetVariableMtrrWorker (
+ GetVariableMtrrCountWorker (),
+ &VariableSettings
+ );
- for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE, Index = 0;
- (
- (MsrNum < VariableMtrrEnd) &&
- (Index < FirmwareVariableMtrrCount)
- );
- MsrNum += 2
- ) {
- if ((AsmReadMsr64 (MsrNum + 1) & MTRR_LIB_CACHE_MTRR_ENABLED) != 0) {
- VariableMtrr[Index].Msr = MsrNum;
- VariableMtrr[Index].BaseAddress = (AsmReadMsr64 (MsrNum) &
- MtrrValidAddressMask);
- VariableMtrr[Index].Length = ((~(AsmReadMsr64 (MsrNum + 1) &
- MtrrValidAddressMask)
- ) &
- MtrrValidBitsMask
- ) + 1;
- VariableMtrr[Index].Type = (AsmReadMsr64 (MsrNum) & 0x0ff);
- VariableMtrr[Index].Valid = TRUE;
- VariableMtrr[Index].Used = TRUE;
- UsedMtrr = UsedMtrr + 1;
- Index++;
- }
- }
- return UsedMtrr;
+ return MtrrGetMemoryAttributeInVariableMtrrWorker (
+ &VariableSettings,
+ GetFirmwareVariableMtrrCountWorker (),
+ MtrrValidBitsMask,
+ MtrrValidAddressMask,
+ VariableMtrr
+ );
}
@@ -1092,6 +1114,7 @@ MtrrGetMemoryAttribute ( UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask;
UINTN VariableMtrrCount;
+ MTRR_VARIABLE_SETTINGS VariableSettings;
if (!IsMtrrSupported ()) {
return CacheUncacheable;
@@ -1133,12 +1156,20 @@ MtrrGetMemoryAttribute ( }
}
MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);
- MtrrGetMemoryAttributeInVariableMtrr(
- MtrrValidBitsMask,
- MtrrValidAddressMask,
- VariableMtrr
+
+ MtrrGetVariableMtrrWorker (
+ GetVariableMtrrCountWorker (),
+ &VariableSettings
);
+ MtrrGetMemoryAttributeInVariableMtrrWorker (
+ &VariableSettings,
+ GetFirmwareVariableMtrrCountWorker (),
+ MtrrValidBitsMask,
+ MtrrValidAddressMask,
+ VariableMtrr
+ );
+
//
// Go through the variable MTRR
//
@@ -1358,6 +1389,9 @@ MtrrSetMemoryAttribute ( UINT32 VariableMtrrEnd;
MTRR_CONTEXT MtrrContext;
UINT32 VariableMtrrCount;
+ MTRR_VARIABLE_SETTINGS OriginalVariableSettings;
+ MTRR_VARIABLE_SETTINGS WorkingVariableSettings;
+ MTRR_VARIABLE_SETTINGS *VariableSettings;
DEBUG((DEBUG_CACHE, "MtrrSetMemoryAttribute() %a:%016lx-%016lx\n", mMtrrMemoryCacheTypeShortName[Attribute], BaseAddress, Length));
@@ -1426,11 +1460,20 @@ MtrrSetMemoryAttribute ( // Read all variable MTRRs
//
VariableMtrrCount = GetVariableMtrrCountWorker ();
+ MtrrGetVariableMtrrWorker (VariableMtrrCount, &OriginalVariableSettings);
+ CopyMem (&WorkingVariableSettings, &OriginalVariableSettings, sizeof (WorkingVariableSettings));
+ VariableSettings = &WorkingVariableSettings;
//
// Check for overlap
//
- UsedMtrr = MtrrGetMemoryAttributeInVariableMtrr (MtrrValidBitsMask, MtrrValidAddressMask, VariableMtrr);
+ UsedMtrr = MtrrGetMemoryAttributeInVariableMtrrWorker (
+ VariableSettings,
+ FirmwareVariableMtrrCount,
+ MtrrValidBitsMask,
+ MtrrValidAddressMask,
+ VariableMtrr
+ );
OverLap = CheckMemoryAttributeOverlap (
FirmwareVariableMtrrCount,
BaseAddress,
|