X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=UefiCpuPkg%2FLibrary%2FMtrrLib%2FMtrrLib.c;h=f37b740fdf7db5929d7611f86561ab8b5a29b8d6;hb=218d55a050b12f9e2de672d8d75314005baad993;hp=2fd1d0153ee6d9f5accfecd99c3271101ab1d69e;hpb=9c8c4478cfcacaf5fd60b75ff78d26732d93a5b8;p=mirror_edk2.git diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 2fd1d0153e..f37b740fdf 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -1683,7 +1683,7 @@ MtrrLibCalculateMtrrs ( /** - Apply the variable MTRR settings to memory range array. + Apply the fixed MTRR settings to memory range array. @param Fixed The fixed MTRR settings. @param Ranges Return the memory range array holding memory type @@ -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) + // + SetMem (ClearMasks, sizeof (ClearMasks), 0); + SetMem (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]; } } @@ -2148,7 +2158,7 @@ MtrrLibSetBelow1MBMemoryAttribute ( When range overlap happens, the last one takes higher priority. When the function returns, either all the attributes are set successfully, or none of them is set. - @param[in] Count of MTRR_MEMORY_RANGE. + @param[in] RangeCount Count of MTRR_MEMORY_RANGE. @retval RETURN_SUCCESS The attributes were set for all the memory ranges. @retval RETURN_INVALID_PARAMETER Length in any range is zero. @@ -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; @@ -2478,7 +2489,7 @@ MtrrSetMemoryAttributeInMtrrSettings ( Range.Type = Attribute; ScratchSize = sizeof (Scratch); Status = MtrrSetMemoryAttributesInMtrrSettings (MtrrSetting, Scratch, &ScratchSize, &Range, 1); - DEBUG ((DEBUG_CACHE, "MtrrSetMemoryAttribute(MtrrSettings = %p) %s: [%016lx, %016lx) - %x\n", + DEBUG ((DEBUG_CACHE, "MtrrSetMemoryAttribute(MtrrSettings = %p) %a: [%016lx, %016lx) - %r\n", MtrrSetting, mMtrrMemoryCacheTypeShortName[Attribute], BaseAddress, BaseAddress + Length, Status)); @@ -2776,6 +2787,7 @@ MtrrDebugPrintAllMtrrsWorker ( UINTN RangeCount; UINT64 MtrrValidBitsMask; UINT64 MtrrValidAddressMask; + UINT32 VariableMtrrCount; MTRR_MEMORY_RANGE Ranges[ ARRAY_SIZE (mMtrrLibFixedMtrrTable) * sizeof (UINT64) + 2 * ARRAY_SIZE (Mtrrs->Variables.Mtrr) + 1 ]; @@ -2785,6 +2797,8 @@ MtrrDebugPrintAllMtrrsWorker ( return; } + VariableMtrrCount = GetVariableMtrrCountWorker (); + if (MtrrSetting != NULL) { Mtrrs = MtrrSetting; } else { @@ -2802,7 +2816,7 @@ MtrrDebugPrintAllMtrrsWorker ( DEBUG((DEBUG_CACHE, "Fixed MTRR[%02d] : %016lx\n", Index, Mtrrs->Fixed.Mtrr[Index])); } - for (Index = 0; Index < ARRAY_SIZE (Mtrrs->Variables.Mtrr); Index++) { + for (Index = 0; Index < VariableMtrrCount; Index++) { if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&Mtrrs->Variables.Mtrr[Index].Mask)->Bits.V == 0) { // // If mask is not valid, then do not display range @@ -2829,11 +2843,11 @@ MtrrDebugPrintAllMtrrsWorker ( RangeCount = 1; MtrrLibGetRawVariableRanges ( - &Mtrrs->Variables, ARRAY_SIZE (Mtrrs->Variables.Mtrr), + &Mtrrs->Variables, VariableMtrrCount, MtrrValidBitsMask, MtrrValidAddressMask, RawVariableRanges ); MtrrLibApplyVariableMtrrs ( - RawVariableRanges, ARRAY_SIZE (RawVariableRanges), + RawVariableRanges, VariableMtrrCount, Ranges, ARRAY_SIZE (Ranges), &RangeCount );