From 1e60a0ecfc8a2fc5f8b48052141e89a93c40f67f Mon Sep 17 00:00:00 2001 From: rsun3 Date: Tue, 20 Sep 2011 07:36:11 +0000 Subject: 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 --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'UefiCpuPkg/Library') diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index edb75c04a5..04c6a1c268 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -477,10 +477,12 @@ CombineMemoryAttribute ( UINT64 MtrrEnd; UINT64 EndAddress; UINT32 FirmwareVariableMtrrCount; + BOOLEAN CoveredByExistingMtrr; FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount (); *OverwriteExistingMtrr = FALSE; + CoveredByExistingMtrr = FALSE; EndAddress = *Base +*Length - 1; for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) { @@ -501,11 +503,12 @@ CombineMemoryAttribute ( // 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) { - *Length = 0; - return RETURN_SUCCESS; + CoveredByExistingMtrr = TRUE; + continue; } // // invalid this MTRR, and program the combine range @@ -552,6 +555,10 @@ CombineMemoryAttribute ( return RETURN_ACCESS_DENIED; } + if (CoveredByExistingMtrr) { + *Length = 0; + } + return RETURN_SUCCESS; } @@ -1007,8 +1014,9 @@ MtrrSetMemoryAttribute ( if (Length == 0) { // - // Combined successfully + // Combined successfully, invalidate the now-unused MTRRs // + InvalidateMtrr(VariableMtrr); Status = RETURN_SUCCESS; goto Done; } -- cgit v1.2.3