Skip to content

Commit 5a73776

Browse files
VivianNKmergify[bot]
authored andcommitted
UefiCpuPkg: Use public Architectural MSRs from MdePkg
Replaced local Msr defines with inclusion of Register/Amd/Msr.h in Amd libraries. Signed-off-by: Vivian Nowka-Keane <vnowkakeane@linux.microsoft.com>
1 parent 961a9e1 commit 5a73776

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveState.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1010
#include "MmSaveState.h"
1111
#include <Register/Amd/SmramSaveStateMap.h>
1212
#include <Library/BaseLib.h>
13+
#include <Register/Amd/Msr.h>
1314

14-
// EFER register LMA bit
15-
#define LMA BIT10
16-
#define EFER_ADDRESS 0xC0000080ul
1715
#define AMD_MM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1
1816
#define AMD_MM_SAVE_STATE_REGISTER_MAX_INDEX 2
1917

@@ -280,6 +278,16 @@ MmSaveStateGetRegisterLma (
280278
VOID
281279
)
282280
{
281+
UINT32 LMAValue;
282+
283+
MSR_IA32_EFER_REGISTER Msr;
284+
285+
Msr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
286+
LMAValue = Msr.Bits.LMA;
287+
if (LMAValue) {
288+
return EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT;
289+
}
290+
283291
//
284292
// AMD64 processors support EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT only
285293
//

UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1717
#include <Library/DebugLib.h>
1818
#include <Library/MmSaveStateLib.h>
1919
#include <Library/HobLib.h>
20+
#include <Register/Amd/Msr.h>
2021

2122
// EFER register LMA bit
2223
#define LMA BIT10
2324

24-
// Machine Specific Registers (MSRs)
25-
#define SMMADDR_ADDRESS 0xC0010112ul
26-
#define SMMMASK_ADDRESS 0xC0010113ul
27-
#define EFER_ADDRESS 0XC0000080ul
28-
2925
// The mode of the CPU at the time an SMI occurs
3026
STATIC UINT8 mSmmSaveStateRegisterLma;
3127

@@ -105,6 +101,10 @@ SmmCpuFeaturesInitializeProcessor (
105101
CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
106102
}
107103

104+
// Re-initialize the value of mSmmSaveStateRegisterLma flag which might have been changed in PiCpuSmmDxeSmm Driver
105+
// Entry point, to make sure correct value on AMD platform is assigned to be used by SmmCpuFeaturesLib.
106+
mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
107+
108108
//
109109
// If SMRR is supported, then program SMRR base/mask MSRs.
110110
// The EFI_MSR_SMRR_PHYS_MASK_VALID bit is not set until the first normal SMI.
@@ -130,8 +130,8 @@ SmmCpuFeaturesInitializeProcessor (
130130
CpuDeadLoop ();
131131
}
132132
} else {
133-
AsmWriteMsr64 (SMMADDR_ADDRESS, CpuHotPlugData->SmrrBase);
134-
AsmWriteMsr64 (SMMMASK_ADDRESS, ((~(UINT64)(CpuHotPlugData->SmrrSize - 1)) | 0x6600));
133+
AsmWriteMsr64 (AMD_64_SMM_ADDR, CpuHotPlugData->SmrrBase);
134+
AsmWriteMsr64 (AMD_64_SMM_MASK, ((~(UINT64)(CpuHotPlugData->SmrrSize - 1)) | 0x6600));
135135
}
136136
}
137137
}

UefiCpuPkg/Library/SmmRelocationLib/AmdSmramSaveStateConfig.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "InternalSmmRelocationLib.h"
1010
#include <Register/Amd/SmramSaveStateMap.h>
1111

12-
#define EFER_ADDRESS 0XC0000080ul
13-
1412
/**
1513
Get the mode of the CPU at the time an SMI occurs
1614
@@ -23,13 +21,14 @@ GetMmSaveStateRegisterLma (
2321
VOID
2422
)
2523
{
26-
UINT8 SmmSaveStateRegisterLma;
27-
UINT32 LMAValue;
24+
UINT8 SmmSaveStateRegisterLma;
25+
MSR_IA32_EFER_REGISTER Msr;
26+
27+
Msr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
2828

2929
SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT;
3030

31-
LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA;
32-
if (LMAValue) {
31+
if (Msr.Bits.LMA) {
3332
SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT;
3433
}
3534

@@ -91,12 +90,14 @@ HookReturnFromSmm (
9190
{
9291
UINT64 OriginalInstructionPointer;
9392
AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState;
93+
MSR_IA32_EFER_REGISTER Msr;
9494

9595
AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState;
9696

9797
OriginalInstructionPointer = AmdCpuState->x64._RIP;
98+
Msr.Uint64 = AmdCpuState->x64.EFER;
9899

99-
if ((AmdCpuState->x64.EFER & LMA) == 0) {
100+
if (!Msr.Bits.LMA) {
100101
AmdCpuState->x64._RIP = NewInstructionPointer32;
101102
} else {
102103
AmdCpuState->x64._RIP = NewInstructionPointer;

UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <Guid/SmramMemoryReserve.h>
3030
#include <Guid/SmmBaseHob.h>
3131
#include <Register/Intel/Cpuid.h>
32+
#include <Register/Intel/Msr.h>
3233
#include <Register/Intel/SmramSaveStateMap.h>
3334
#include <Protocol/MmCpu.h>
3435

@@ -51,11 +52,6 @@ X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack;
5152

5253
#define CR4_CET_ENABLE BIT23
5354

54-
//
55-
// EFER register LMA bit
56-
//
57-
#define LMA BIT10
58-
5955
/**
6056
This function configures the SmBase on the currently executing CPU.
6157

UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ HookReturnFromSmm (
102102
IN UINT64 NewInstructionPointer
103103
)
104104
{
105-
UINT64 OriginalInstructionPointer;
105+
UINT64 OriginalInstructionPointer;
106+
MSR_IA32_EFER_REGISTER Msr;
106107

107108
if (GetMmSaveStateRegisterLma () == EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT) {
108109
OriginalInstructionPointer = (UINT64)CpuState->x86._EIP;
@@ -117,7 +118,8 @@ HookReturnFromSmm (
117118
}
118119
} else {
119120
OriginalInstructionPointer = CpuState->x64._RIP;
120-
if ((CpuState->x64.IA32_EFER & LMA) == 0) {
121+
Msr.Uint64 = CpuState->x64.IA32_EFER;
122+
if (!Msr.Bits.LMA) {
121123
CpuState->x64._RIP = (UINT32)NewInstructionPointer32;
122124
} else {
123125
CpuState->x64._RIP = (UINT32)NewInstructionPointer;

0 commit comments

Comments
 (0)