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>
(cherry picked from commit ffb4c72d7b)
This commit is contained in:
Ruiyu Ni
2018-01-08 18:11:39 +08:00
parent 393908e084
commit 9730ca2d50

View File

@@ -1583,20 +1583,33 @@ MtrrLibCalculateMtrrs (
Vector[VectorCount - 1].Address = Base1; Vector[VectorCount - 1].Address = Base1;
Weight = (UINT8 *) &Vector[VectorCount]; Weight = (UINT8 *) &Vector[VectorCount];
for (VectorIndex = 0; VectorIndex < VectorCount; VectorIndex++) {
// //
// Set mandatory weight between any vector to max // Set optional weight between vertices and self->self to 0
// Set optional weight and between any vector and self->self to 0 //
// E.g.: SetMem (&Weight[M(VectorIndex, 0)], VectorIndex + 1, 0);
//
// 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 FF FF FF
// 00 00 FF FF // 00 00 FF FF
// 00 00 00 FF // 00 00 00 FF
// 00 00 00 00 // 00 00 00 00
}
// //
for (VectorIndex = 0; VectorIndex < VectorCount; VectorIndex++) { // Set mandatory weight and optional weight for adjacent vertices
SetMem (&Weight[M(VectorIndex, 0)], VectorIndex + 1, 0); //
if (VectorIndex != VectorCount - 1) { for (VectorIndex = 0; VectorIndex < VectorCount - 1; VectorIndex++) {
Weight[M (VectorIndex, VectorIndex + 1)] = (DefaultType == Vector[VectorIndex].Type) ? 0 : 1; if (Vector[VectorIndex].Type != DefaultType) {
SetMem (&Weight[M (VectorIndex, VectorIndex + 2)], VectorCount - VectorIndex - 2, MAX_WEIGHT); 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;
} }
} }