Skip to content

Commit

Permalink
UefiCpuPkg/MtrrLib: Improve MtrrDebugPrintAllMtrrsWorker.
Browse files Browse the repository at this point in the history
Improve MtrrDebugPrintAllMtrrsWorker by making use of
MtrrGetMemoryAttributesInMtrrSettings.

Signed-off-by: Ray Ni <[email protected]>
Cc: Eric Dong <[email protected]>
Cc: Rahul Kumar <[email protected]>
Cc: Gerd Hoffmann <[email protected]>

Reviewed-by: Eric Dong <[email protected]>
Reviewed-by: Ray Ni <[email protected]>
  • Loading branch information
xieyuanh authored and mergify[bot] committed Oct 9, 2023
1 parent 4b7b32f commit c4fdec0
Showing 1 changed file with 10 additions and 35 deletions.
45 changes: 10 additions & 35 deletions UefiCpuPkg/Library/MtrrLib/MtrrLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3069,24 +3069,15 @@ MtrrDebugPrintAllMtrrsWorker (
)
{
DEBUG_CODE_BEGIN ();
UINT32 Index;
MTRR_SETTINGS LocalMtrrs;
MTRR_SETTINGS *Mtrrs;
UINTN Index;
RETURN_STATUS Status;
UINTN RangeCount;
UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask;
UINT32 VariableMtrrCount;
BOOLEAN ContainVariableMtrr;
MTRR_MEMORY_RANGE Ranges[
ARRAY_SIZE (mMtrrLibFixedMtrrTable) * sizeof (UINT64) + 2 * ARRAY_SIZE (Mtrrs->Variables.Mtrr) + 1
];
MTRR_MEMORY_RANGE RawVariableRanges[ARRAY_SIZE (Mtrrs->Variables.Mtrr)];

if (!IsMtrrSupported ()) {
return;
}

VariableMtrrCount = GetVariableMtrrCountWorker ();

if (MtrrSetting != NULL) {
Mtrrs = MtrrSetting;
Expand All @@ -3095,6 +3086,13 @@ MtrrDebugPrintAllMtrrsWorker (
Mtrrs = &LocalMtrrs;
}

RangeCount = ARRAY_SIZE (Ranges);
Status = MtrrGetMemoryAttributesInMtrrSettings (Mtrrs, Ranges, &RangeCount);
if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_CACHE, "MTRR is not enabled.\n"));
return;
}

//
// Dump RAW MTRR contents
//
Expand All @@ -3106,7 +3104,7 @@ MtrrDebugPrintAllMtrrsWorker (
}

ContainVariableMtrr = FALSE;
for (Index = 0; Index < VariableMtrrCount; Index++) {
for (Index = 0; Index < ARRAY_SIZE (Mtrrs->Variables.Mtrr); Index++) {
if ((Mtrrs->Variables.Mtrr[Index].Mask & BIT11) == 0) {
//
// If mask is not valid, then do not display range
Expand Down Expand Up @@ -3135,29 +3133,6 @@ MtrrDebugPrintAllMtrrsWorker (
//
DEBUG ((DEBUG_CACHE, "Memory Ranges:\n"));
DEBUG ((DEBUG_CACHE, "====================================\n"));
MtrrLibInitializeMtrrMask (&MtrrValidBitsMask, &MtrrValidAddressMask);
Ranges[0].BaseAddress = 0;
Ranges[0].Length = MtrrValidBitsMask + 1;
Ranges[0].Type = MtrrGetDefaultMemoryTypeWorker (Mtrrs);
RangeCount = 1;

MtrrLibGetRawVariableRanges (
&Mtrrs->Variables,
VariableMtrrCount,
MtrrValidBitsMask,
MtrrValidAddressMask,
RawVariableRanges
);
MtrrLibApplyVariableMtrrs (
RawVariableRanges,
VariableMtrrCount,
Ranges,
ARRAY_SIZE (Ranges),
&RangeCount
);

MtrrLibApplyFixedMtrrs (&Mtrrs->Fixed, Ranges, ARRAY_SIZE (Ranges), &RangeCount);

for (Index = 0; Index < RangeCount; Index++) {
DEBUG ((
DEBUG_CACHE,
Expand Down

0 comments on commit c4fdec0

Please sign in to comment.