UefiCpuPkg MTRR Library: enhance MTRR Library.

When it finds that a request range is covered by an existing MTRR with same cache type, the MTRR library set a flag and continues to check other MTRRs and invalidate any MTRR of the same request range with a higher-priority cache type.

Signed-off-by: rsun3
Reviewed-by: gxing


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12388 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
rsun3 2011-09-20 07:36:11 +00:00
parent 89a90ae648
commit 1e60a0ecfc
1 changed files with 12 additions and 4 deletions

View File

@ -477,10 +477,12 @@ CombineMemoryAttribute (
UINT64 MtrrEnd; UINT64 MtrrEnd;
UINT64 EndAddress; UINT64 EndAddress;
UINT32 FirmwareVariableMtrrCount; UINT32 FirmwareVariableMtrrCount;
BOOLEAN CoveredByExistingMtrr;
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount (); FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();
*OverwriteExistingMtrr = FALSE; *OverwriteExistingMtrr = FALSE;
CoveredByExistingMtrr = FALSE;
EndAddress = *Base +*Length - 1; EndAddress = *Base +*Length - 1;
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) { for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
@ -501,11 +503,12 @@ CombineMemoryAttribute (
// //
if (Attributes == VariableMtrr[Index].Type) { if (Attributes == VariableMtrr[Index].Type) {
// //
// if the Mtrr range contain the request range, return RETURN_SUCCESS // if the Mtrr range contain the request range, set a flag, then continue to
// invalidate any MTRR of the same request range with higher priority cache type.
// //
if (VariableMtrr[Index].BaseAddress <= *Base && MtrrEnd >= EndAddress) { if (VariableMtrr[Index].BaseAddress <= *Base && MtrrEnd >= EndAddress) {
*Length = 0; CoveredByExistingMtrr = TRUE;
return RETURN_SUCCESS; continue;
} }
// //
// invalid this MTRR, and program the combine range // invalid this MTRR, and program the combine range
@ -552,6 +555,10 @@ CombineMemoryAttribute (
return RETURN_ACCESS_DENIED; return RETURN_ACCESS_DENIED;
} }
if (CoveredByExistingMtrr) {
*Length = 0;
}
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -1007,8 +1014,9 @@ MtrrSetMemoryAttribute (
if (Length == 0) { if (Length == 0) {
// //
// Combined successfully // Combined successfully, invalidate the now-unused MTRRs
// //
InvalidateMtrr(VariableMtrr);
Status = RETURN_SUCCESS; Status = RETURN_SUCCESS;
goto Done; goto Done;
} }