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>
This commit is contained in:
Ruiyu Ni 2018-01-09 16:46:40 +08:00
parent 479a3b6053
commit 579510336e
1 changed files with 5 additions and 4 deletions

View File

@ -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;