X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=UefiCpuPkg%2FLibrary%2FMtrrLib%2FMtrrLib.c;h=200becdd4a2500eb3145788bc2f97a19a47c3aae;hb=86cabbcfa005ca9c9589402d4fb7c984e741cc19;hp=cb22558103cd5db28b69c31ffa18ec287c5a6f04;hpb=1c29d03869355a5e9dfafb88332c139d8c5c2215;p=mirror_edk2.git diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index cb22558103..200becdd4a 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -2114,22 +2114,32 @@ MtrrLibSetBelow1MBMemoryAttribute ( UINT64 OrMask; UINT64 ClearMasks[ARRAY_SIZE (mMtrrLibFixedMtrrTable)]; UINT64 OrMasks[ARRAY_SIZE (mMtrrLibFixedMtrrTable)]; + BOOLEAN LocalModified[ARRAY_SIZE (mMtrrLibFixedMtrrTable)]; ASSERT (BaseAddress < BASE_1MB); + SetMem (LocalModified, sizeof (LocalModified), FALSE); + + // + // (Value & ~0 | 0) still equals to (Value) + // + SetMem64 (ClearMasks, sizeof (ClearMasks), 0); + SetMem64 (OrMasks, sizeof (OrMasks), 0); + MsrIndex = (UINT32)-1; while ((BaseAddress < BASE_1MB) && (Length != 0)) { Status = MtrrLibProgramFixedMtrr (Type, &BaseAddress, &Length, &MsrIndex, &ClearMask, &OrMask); if (RETURN_ERROR (Status)) { return Status; } - ClearMasks[MsrIndex] = ClearMask; - OrMasks[MsrIndex] = OrMask; - Modified[MsrIndex] = TRUE; + ClearMasks[MsrIndex] = ClearMask; + OrMasks[MsrIndex] = OrMask; + Modified[MsrIndex] = TRUE; + LocalModified[MsrIndex] = TRUE; } for (MsrIndex = 0; MsrIndex < ARRAY_SIZE (mMtrrLibFixedMtrrTable); MsrIndex++) { - if (Modified[MsrIndex]) { + if (LocalModified[MsrIndex]) { FixedSettings->Mtrr[MsrIndex] = (FixedSettings->Mtrr[MsrIndex] & ~ClearMasks[MsrIndex]) | OrMasks[MsrIndex]; } } @@ -2354,6 +2364,7 @@ MtrrSetMemoryAttributesInMtrrSettings ( // // 3. Apply the below-1MB memory attribute settings. // + ZeroMem (WorkingFixedSettings.Mtrr, sizeof (WorkingFixedSettings.Mtrr)); for (Index = 0; Index < RangeCount; Index++) { if (Ranges[Index].BaseAddress >= BASE_1MB) { continue;