UefiCpuPkg/PiSmmCpuDxeSmm: Supports test then write new value logic.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2040

Supports new logic which test current value before write new value.
Only write new value when current value not same as new value.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Dong, Eric 2019-08-16 11:57:27 +08:00 committed by Ray Ni
parent ef21a304e0
commit cfbcaad251
1 changed files with 29 additions and 0 deletions

View File

@ -241,6 +241,7 @@ ProgramProcessorRegister (
UINTN ValidThreadCount;
UINT32 *ValidCoreCountPerPackage;
EFI_STATUS Status;
UINT64 CurrentValue;
//
// Traverse Register Table of this logical processor
@ -263,6 +264,16 @@ ProgramProcessorRegister (
if (EFI_ERROR (Status)) {
break;
}
if (RegisterTableEntry->TestThenWrite) {
CurrentValue = BitFieldRead64 (
Value,
RegisterTableEntry->ValidBitStart,
RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1
);
if (CurrentValue == RegisterTableEntry->Value) {
break;
}
}
Value = (UINTN) BitFieldWrite64 (
Value,
RegisterTableEntry->ValidBitStart,
@ -275,6 +286,24 @@ ProgramProcessorRegister (
// The specified register is Model Specific Register
//
case Msr:
if (RegisterTableEntry->TestThenWrite) {
Value = (UINTN)AsmReadMsr64 (RegisterTableEntry->Index);
if (RegisterTableEntry->ValidBitLength >= 64) {
if (Value == RegisterTableEntry->Value) {
break;
}
} else {
CurrentValue = BitFieldRead64 (
Value,
RegisterTableEntry->ValidBitStart,
RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1
);
if (CurrentValue == RegisterTableEntry->Value) {
break;
}
}
}
//
// If this function is called to restore register setting after INIT signal,
// there is no need to restore MSRs in register table.