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 <[email protected]>
Cc: Star Zeng <[email protected]>
---
 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c 
b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index fafa15fd63..768d4d5cff 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;
-- 
2.15.1.windows.2

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to