mirror of https://github.com/acidanthera/audk.git
UefiCpuPkg/MtrrLib: Avoid running unnecessary code
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
parent
17c3dc1939
commit
c9b4492133
|
@ -1536,6 +1536,7 @@ MtrrLibAddVariableMtrr (
|
|||
|
||||
MTRR_LIB_ASSERT_ALIGNED (BaseAddress, Length);
|
||||
if (Type == CacheInvalid) {
|
||||
ASSERT (Ranges != NULL);
|
||||
for (Index = 0; Index < RangeCount; Index++) {
|
||||
if (Ranges[Index].BaseAddress <= BaseAddress && BaseAddress < Ranges[Index].BaseAddress + Ranges[Index].Length) {
|
||||
|
||||
|
@ -2027,25 +2028,27 @@ MtrrSetMemoryAttributeWorker (
|
|||
ASSERT (OriginalVariableMtrrCount - FreeVariableMtrrCount <= FirmwareVariableMtrrCount);
|
||||
|
||||
//
|
||||
// Move MTRRs after the FirmwraeVariableMtrrCount position to beginning
|
||||
// Move MTRRs after the FirmwareVariableMtrrCount position to beginning
|
||||
//
|
||||
WorkingIndex = FirmwareVariableMtrrCount;
|
||||
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
|
||||
if (!OriginalVariableMtrr[Index].Valid) {
|
||||
//
|
||||
// Found an empty MTRR in WorkingIndex position
|
||||
//
|
||||
for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
|
||||
if (OriginalVariableMtrr[WorkingIndex].Valid) {
|
||||
break;
|
||||
if (FirmwareVariableMtrrCount < OriginalVariableMtrrCount) {
|
||||
WorkingIndex = FirmwareVariableMtrrCount;
|
||||
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
|
||||
if (!OriginalVariableMtrr[Index].Valid) {
|
||||
//
|
||||
// Found an empty MTRR in WorkingIndex position
|
||||
//
|
||||
for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
|
||||
if (OriginalVariableMtrr[WorkingIndex].Valid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WorkingIndex != OriginalVariableMtrrCount) {
|
||||
CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
|
||||
VariableSettingModified[Index] = TRUE;
|
||||
VariableSettingModified[WorkingIndex] = TRUE;
|
||||
OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
|
||||
if (WorkingIndex != OriginalVariableMtrrCount) {
|
||||
CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
|
||||
VariableSettingModified[Index] = TRUE;
|
||||
VariableSettingModified[WorkingIndex] = TRUE;
|
||||
OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue