summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-01-08 18:11:39 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-01-10 10:28:28 +0800
commitffb4c72d7b637d4ac377fc7da7575069f15c288e (patch)
tree6a3142cc513c2e0ac82466323ae4cd1977adf10e /UefiCpuPkg
parent5a6c5af64af9e6f5ea26a4c4682aed57c37c221c (diff)
downloadedk2-ffb4c72d7b637d4ac377fc7da7575069f15c288e.tar.gz
edk2-ffb4c72d7b637d4ac377fc7da7575069f15c288e.tar.bz2
edk2-ffb4c72d7b637d4ac377fc7da7575069f15c288e.zip
UefiCpuPkg/MtrrLib: Fix bug that may calculate wrong MTRR result
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>
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/Library/MtrrLib/MtrrLib.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index ddf90e2a8c..1f85ac7e65 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -1583,20 +1583,33 @@ MtrrLibCalculateMtrrs (
Vector[VectorCount - 1].Address = Base1;
Weight = (UINT8 *) &Vector[VectorCount];
- //
- // Set mandatory weight between any vector to max
- // Set optional weight and between any vector and self->self to 0
- // E.g.:
- // 00 FF FF FF
- // 00 00 FF FF
- // 00 00 00 FF
- // 00 00 00 00
- //
for (VectorIndex = 0; VectorIndex < VectorCount; VectorIndex++) {
+ //
+ // Set optional weight between vertices and self->self to 0
+ //
SetMem (&Weight[M(VectorIndex, 0)], VectorIndex + 1, 0);
- if (VectorIndex != VectorCount - 1) {
- Weight[M (VectorIndex, VectorIndex + 1)] = (DefaultType == Vector[VectorIndex].Type) ? 0 : 1;
- SetMem (&Weight[M (VectorIndex, VectorIndex + 2)], VectorCount - VectorIndex - 2, MAX_WEIGHT);
+ //
+ // Set mandatory weight between vectors to MAX_WEIGHT
+ //
+ SetMem (&Weight[M (VectorIndex, VectorIndex + 1)], VectorCount - VectorIndex - 1, MAX_WEIGHT);
+
+ // Final result looks like:
+ // 00 FF FF FF
+ // 00 00 FF FF
+ // 00 00 00 FF
+ // 00 00 00 00
+ }
+
+ //
+ // Set mandatory weight and optional weight for adjacent vertices
+ //
+ for (VectorIndex = 0; VectorIndex < VectorCount - 1; VectorIndex++) {
+ if (Vector[VectorIndex].Type != DefaultType) {
+ Weight[M (VectorIndex, VectorIndex + 1)] = 1;
+ Weight[O (VectorIndex, VectorIndex + 1)] = 0;
+ } else {
+ Weight[M (VectorIndex, VectorIndex + 1)] = 0;
+ Weight[O (VectorIndex, VectorIndex + 1)] = 1;
}
}