\r
\r
/**\r
- Apply the variable MTRR settings to memory range array.\r
+ Apply the fixed MTRR settings to memory range array.\r
\r
@param Fixed The fixed MTRR settings.\r
@param Ranges Return the memory range array holding memory type\r
UINT64 OrMask;\r
UINT64 ClearMasks[ARRAY_SIZE (mMtrrLibFixedMtrrTable)];\r
UINT64 OrMasks[ARRAY_SIZE (mMtrrLibFixedMtrrTable)];\r
+ BOOLEAN LocalModified[ARRAY_SIZE (mMtrrLibFixedMtrrTable)];\r
\r
ASSERT (BaseAddress < BASE_1MB);\r
\r
+ SetMem (LocalModified, sizeof (LocalModified), FALSE);\r
+\r
+ //\r
+ // (Value & ~0 | 0) still equals to (Value)\r
+ //\r
+ SetMem (ClearMasks, sizeof (ClearMasks), 0);\r
+ SetMem (OrMasks, sizeof (OrMasks), 0);\r
+\r
MsrIndex = (UINT32)-1;\r
while ((BaseAddress < BASE_1MB) && (Length != 0)) {\r
Status = MtrrLibProgramFixedMtrr (Type, &BaseAddress, &Length, &MsrIndex, &ClearMask, &OrMask);\r
if (RETURN_ERROR (Status)) {\r
return Status;\r
}\r
- ClearMasks[MsrIndex] = ClearMask;\r
- OrMasks[MsrIndex] = OrMask;\r
- Modified[MsrIndex] = TRUE;\r
+ ClearMasks[MsrIndex] = ClearMask;\r
+ OrMasks[MsrIndex] = OrMask;\r
+ Modified[MsrIndex] = TRUE;\r
+ LocalModified[MsrIndex] = TRUE;\r
}\r
\r
for (MsrIndex = 0; MsrIndex < ARRAY_SIZE (mMtrrLibFixedMtrrTable); MsrIndex++) {\r
- if (Modified[MsrIndex]) {\r
+ if (LocalModified[MsrIndex]) {\r
FixedSettings->Mtrr[MsrIndex] = (FixedSettings->Mtrr[MsrIndex] & ~ClearMasks[MsrIndex]) | OrMasks[MsrIndex];\r
}\r
}\r
When range overlap happens, the last one takes higher priority.\r
When the function returns, either all the attributes are set successfully,\r
or none of them is set.\r
- @param[in] Count of MTRR_MEMORY_RANGE.\r
+ @param[in] RangeCount Count of MTRR_MEMORY_RANGE.\r
\r
@retval RETURN_SUCCESS The attributes were set for all the memory ranges.\r
@retval RETURN_INVALID_PARAMETER Length in any range is zero.\r
//\r
// 3. Apply the below-1MB memory attribute settings.\r
//\r
+ ZeroMem (WorkingFixedSettings.Mtrr, sizeof (WorkingFixedSettings.Mtrr));\r
for (Index = 0; Index < RangeCount; Index++) {\r
if (Ranges[Index].BaseAddress >= BASE_1MB) {\r
continue;\r
Range.Type = Attribute;\r
ScratchSize = sizeof (Scratch);\r
Status = MtrrSetMemoryAttributesInMtrrSettings (MtrrSetting, Scratch, &ScratchSize, &Range, 1);\r
- DEBUG ((DEBUG_CACHE, "MtrrSetMemoryAttribute(MtrrSettings = %p) %s: [%016lx, %016lx) - %x\n",\r
+ DEBUG ((DEBUG_CACHE, "MtrrSetMemoryAttribute(MtrrSettings = %p) %a: [%016lx, %016lx) - %r\n",\r
MtrrSetting,\r
mMtrrMemoryCacheTypeShortName[Attribute], BaseAddress, BaseAddress + Length, Status));\r
\r
UINTN RangeCount;\r
UINT64 MtrrValidBitsMask;\r
UINT64 MtrrValidAddressMask;\r
+ UINT32 VariableMtrrCount;\r
MTRR_MEMORY_RANGE Ranges[\r
ARRAY_SIZE (mMtrrLibFixedMtrrTable) * sizeof (UINT64) + 2 * ARRAY_SIZE (Mtrrs->Variables.Mtrr) + 1\r
];\r
return;\r
}\r
\r
+ VariableMtrrCount = GetVariableMtrrCountWorker ();\r
+\r
if (MtrrSetting != NULL) {\r
Mtrrs = MtrrSetting;\r
} else {\r
DEBUG((DEBUG_CACHE, "Fixed MTRR[%02d] : %016lx\n", Index, Mtrrs->Fixed.Mtrr[Index]));\r
}\r
\r
- for (Index = 0; Index < ARRAY_SIZE (Mtrrs->Variables.Mtrr); Index++) {\r
+ for (Index = 0; Index < VariableMtrrCount; Index++) {\r
if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&Mtrrs->Variables.Mtrr[Index].Mask)->Bits.V == 0) {\r
//\r
// If mask is not valid, then do not display range\r
RangeCount = 1;\r
\r
MtrrLibGetRawVariableRanges (\r
- &Mtrrs->Variables, ARRAY_SIZE (Mtrrs->Variables.Mtrr),\r
+ &Mtrrs->Variables, VariableMtrrCount,\r
MtrrValidBitsMask, MtrrValidAddressMask, RawVariableRanges\r
);\r
MtrrLibApplyVariableMtrrs (\r
- RawVariableRanges, ARRAY_SIZE (RawVariableRanges),\r
+ RawVariableRanges, VariableMtrrCount,\r
Ranges, ARRAY_SIZE (Ranges), &RangeCount\r
);\r
\r