summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2017-05-05 10:10:00 +0800
committerGuo Mang <mang.guo@intel.com>2017-07-12 11:24:37 +0800
commitdc38ac830cba15375137c846949062c20eddaf5a (patch)
treea8ac271a2524939fcf7a5fc30ed1b2eaa09445f6
parentf736f40633ea4e670bd61a5a81cfa9b391737960 (diff)
downloadedk2-platforms-dc38ac830cba15375137c846949062c20eddaf5a.tar.xz
UefiCpuPkg/MtrrLib: Don't report OutOfResource when MTRR is enough
The MTRR calculation algorithm contains a bug that when left subtraction cannot produce better MTRR solution, it forgets to restore the BaseAddress/Length so that MtrrLibGetMtrrNumber() returns bigger value of actual required MTRR numbers. As a result, the MtrrLib reports OutOfResource but actually the MTRR is enough. MEMORY_RANGE mC[] = { 0, 0x100000, CacheUncacheable, 0x100000, 0x89F00000, CacheWriteBack, 0x8A000000, 0x75000000, CacheUncacheable, 0xFF000000, 0x01000000, CacheWriteProtected, 0x100000000, 0x7F00000000, CacheUncacheable, 0xFC240000, 0x2000, CacheWriteCombining // <-- trigger the error }; Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jeff Fan <jeff.fan@intel.com> (cherry picked from commit 3654c4623c9b37ddc64426995fa399d8626b7ced)
-rw-r--r--Core/UefiCpuPkg/Library/MtrrLib/MtrrLib.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Core/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/Core/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 9d1927262a..cf1af29936 100644
--- a/Core/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/Core/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -851,6 +851,8 @@ MtrrLibGetMtrrNumber (
UINT64 SubtractiveLength;
UINT64 BaseAlignment;
UINT32 Index;
+ UINT64 OriginalBaseAddress;
+ UINT64 OriginalLength;
*SubLeft = 0;
*SubRight = 0;
@@ -861,6 +863,9 @@ MtrrLibGetMtrrNumber (
// Get the optimal left subtraction solution.
//
if (BaseAddress != 0) {
+
+ OriginalBaseAddress = BaseAddress;
+ OriginalLength = Length;
SubtractiveBaseAddress = 0;
SubtractiveLength = 0;
//
@@ -915,7 +920,10 @@ MtrrLibGetMtrrNumber (
//
if (*SubLeft != 0) {
BaseAddress = SubtractiveBaseAddress;
- Length = SubtractiveLength;
+ Length = SubtractiveLength;
+ } else {
+ BaseAddress = OriginalBaseAddress;
+ Length = OriginalLength;
}
}