summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-01-09 16:46:40 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-02-06 16:04:13 +0800
commitffa19162767aac8d96124bc79d1c8df4af53e04a (patch)
tree8abe7999cec7d20c696622fc1f04ee0d7dd2b6a8 /UefiCpuPkg
parent12204aa47f5007dba215cd6bbbff676b9235d668 (diff)
downloadedk2-ffa19162767aac8d96124bc79d1c8df4af53e04a.tar.gz
edk2-ffa19162767aac8d96124bc79d1c8df4af53e04a.tar.bz2
edk2-ffa19162767aac8d96124bc79d1c8df4af53e04a.zip
UefiCpuPkg/MtrrLib: Fix a MTRR calculation bug
80 A8 B0 B8 C0 +----------WB--------+-UC-+-WT-+-WB-+ For above memory settings, current code caused the final MTRR settings miss [A8, B0, UC] when default memory type is UC. The root cause is the code only checks the mandatory weight between A8 to B0, but skips to check the optional weight. The patch fixes this issue. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Eric Dong <eric.dong@intel.com> (cherry picked from commit 579510336e2ccbb22fa706c49baa07969e3d60f6)
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/Library/MtrrLib/MtrrLib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 4f7c28bf92..ba8fabfd9a 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -47,7 +47,7 @@ typedef struct {
UINT64 Address;
UINT64 Alignment;
UINT64 Length;
- UINT8 Type : 7;
+ MTRR_MEMORY_CACHE_TYPE Type : 7;
//
// Temprary use for calculating the best MTRR settings.
@@ -1429,7 +1429,7 @@ MtrrLibCalculateSubtractivePath (
while (SubStart != SubStop) {
Status = MtrrLibAppendVariableMtrr (
Mtrrs, MtrrCapacity, MtrrCount,
- Vertices[SubStart].Address, Vertices[SubStart].Length, (MTRR_MEMORY_CACHE_TYPE) Vertices[SubStart].Type
+ Vertices[SubStart].Address, Vertices[SubStart].Length, Vertices[SubStart].Type
);
if (RETURN_ERROR (Status)) {
return Status;
@@ -1450,10 +1450,11 @@ MtrrLibCalculateSubtractivePath (
Pre = Vertices[Cur].Previous;
SubStop = Pre;
- if (Weight[M (Pre, Cur)] != 0) {
+ if (Weight[M (Pre, Cur)] + Weight[O (Pre, Cur)] != 0) {
Status = MtrrLibAppendVariableMtrr (
Mtrrs, MtrrCapacity, MtrrCount,
- Vertices[Pre].Address, Vertices[Cur].Address - Vertices[Pre].Address, LowestPrecedentType
+ Vertices[Pre].Address, Vertices[Cur].Address - Vertices[Pre].Address,
+ (Pre != Cur - 1) ? LowestPrecedentType : Vertices[Pre].Type
);
if (RETURN_ERROR (Status)) {
return Status;