]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MtrrLib: Fix bug that may calculate wrong MTRR result
authorRuiyu Ni <ruiyu.ni@intel.com>
Mon, 8 Jan 2018 10:11:39 +0000 (18:11 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 10 Jan 2018 02:28:28 +0000 (10:28 +0800)
Code forgot to initialize the optional weight between adjacent
vertices. It caused wrong MTRR result was calculated for some
memory settings.

The logic was incorrectly removed when converting from POC
code. The patch adds back the initialization.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/MtrrLib/MtrrLib.c

index ddf90e2a8c0fea3e035a642958549f5020d16889..1f85ac7e65232bd1294cf2f9a9e1f1b4dd4bc909 100644 (file)
@@ -1583,20 +1583,33 @@ MtrrLibCalculateMtrrs (
   Vector[VectorCount - 1].Address = Base1;\r
 \r
   Weight = (UINT8 *) &Vector[VectorCount];\r
-  //\r
-  // Set mandatory weight between any vector to max\r
-  // Set optional weight and between any vector and self->self to 0\r
-  // E.g.:\r
-  //   00 FF FF FF\r
-  //   00 00 FF FF\r
-  //   00 00 00 FF\r
-  //   00 00 00 00\r
-  //\r
   for (VectorIndex = 0; VectorIndex < VectorCount; VectorIndex++) {\r
+    //\r
+    // Set optional weight between vertices and self->self to 0\r
+    //\r
     SetMem (&Weight[M(VectorIndex, 0)], VectorIndex + 1, 0);\r
-    if (VectorIndex != VectorCount - 1) {\r
-      Weight[M (VectorIndex, VectorIndex + 1)] = (DefaultType == Vector[VectorIndex].Type) ? 0 : 1;\r
-      SetMem (&Weight[M (VectorIndex, VectorIndex + 2)], VectorCount - VectorIndex - 2, MAX_WEIGHT);\r
+    //\r
+    // Set mandatory weight between vectors to MAX_WEIGHT\r
+    //\r
+    SetMem (&Weight[M (VectorIndex, VectorIndex + 1)], VectorCount - VectorIndex - 1, MAX_WEIGHT);\r
+\r
+    // Final result looks like:\r
+    //   00 FF FF FF\r
+    //   00 00 FF FF\r
+    //   00 00 00 FF\r
+    //   00 00 00 00\r
+  }\r
+\r
+  //\r
+  // Set mandatory weight and optional weight for adjacent vertices\r
+  //\r
+  for (VectorIndex = 0; VectorIndex < VectorCount - 1; VectorIndex++) {\r
+    if (Vector[VectorIndex].Type != DefaultType) {\r
+      Weight[M (VectorIndex, VectorIndex + 1)] = 1;\r
+      Weight[O (VectorIndex, VectorIndex + 1)] = 0;\r
+    } else {\r
+      Weight[M (VectorIndex, VectorIndex + 1)] = 0;\r
+      Weight[O (VectorIndex, VectorIndex + 1)] = 1;\r
     }\r
   }\r
 \r