15#define AMD_MM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1
16#define AMD_MM_SAVE_STATE_REGISTER_MAX_INDEX 2
19#define MM_CPU_OFFSET(Field) OFFSET_OF (AMD_SMRAM_SAVE_STATE_MAP, Field)
31 { 0, 0, 0, 0, 0,
FALSE },
36 { 0, 4, 0, MM_CPU_OFFSET (x64.SMMRevId), 0,
FALSE },
41 { 0, 8, 0, MM_CPU_OFFSET (x64._GDTRBaseLoDword), MM_CPU_OFFSET (x64._GDTRBaseHiDword),
FALSE },
42 { 0, 8, 0, MM_CPU_OFFSET (x64._IDTRBaseLoDword), MM_CPU_OFFSET (x64._IDTRBaseLoDword),
FALSE },
43 { 0, 8, 0, MM_CPU_OFFSET (x64._LDTRBaseLoDword), MM_CPU_OFFSET (x64._LDTRBaseLoDword),
FALSE },
44 { 0, 2, 0, MM_CPU_OFFSET (x64._GDTRLimit), 0,
FALSE },
45 { 0, 2, 0, MM_CPU_OFFSET (x64._IDTRLimit), 0,
FALSE },
46 { 0, 4, 0, MM_CPU_OFFSET (x64._LDTRLimit), 0,
FALSE },
47 { 0, 0, 0, 0, 0,
FALSE },
48 { 0, 2, 0, MM_CPU_OFFSET (x64._ES), 0,
FALSE },
49 { 0, 2, 0, MM_CPU_OFFSET (x64._CS), 0,
FALSE },
50 { 0, 2, 0, MM_CPU_OFFSET (x64._SS), 0,
FALSE },
51 { 0, 2, 0, MM_CPU_OFFSET (x64._DS), 0,
FALSE },
52 { 0, 2, 0, MM_CPU_OFFSET (x64._FS), 0,
FALSE },
53 { 0, 2, 0, MM_CPU_OFFSET (x64._GS), 0,
FALSE },
54 { 0, 2, 0, MM_CPU_OFFSET (x64._LDTR), 0,
FALSE },
55 { 0, 2, 0, MM_CPU_OFFSET (x64._TR), 0,
FALSE },
56 { 0, 8, 0, MM_CPU_OFFSET (x64._DR7), MM_CPU_OFFSET (x64._DR7) + 4,
FALSE },
57 { 0, 8, 0, MM_CPU_OFFSET (x64._DR6), MM_CPU_OFFSET (x64._DR6) + 4,
FALSE },
58 { 0, 8, 0, MM_CPU_OFFSET (x64._R8), MM_CPU_OFFSET (x64._R8) + 4,
TRUE },
59 { 0, 8, 0, MM_CPU_OFFSET (x64._R9), MM_CPU_OFFSET (x64._R9) + 4,
TRUE },
60 { 0, 8, 0, MM_CPU_OFFSET (x64._R10), MM_CPU_OFFSET (x64._R10) + 4,
TRUE },
61 { 0, 8, 0, MM_CPU_OFFSET (x64._R11), MM_CPU_OFFSET (x64._R11) + 4,
TRUE },
62 { 0, 8, 0, MM_CPU_OFFSET (x64._R12), MM_CPU_OFFSET (x64._R12) + 4,
TRUE },
63 { 0, 8, 0, MM_CPU_OFFSET (x64._R13), MM_CPU_OFFSET (x64._R13) + 4,
TRUE },
64 { 0, 8, 0, MM_CPU_OFFSET (x64._R14), MM_CPU_OFFSET (x64._R14) + 4,
TRUE },
65 { 0, 8, 0, MM_CPU_OFFSET (x64._R15), MM_CPU_OFFSET (x64._R15) + 4,
TRUE },
66 { 0, 8, 0, MM_CPU_OFFSET (x64._RAX), MM_CPU_OFFSET (x64._RAX) + 4,
TRUE },
67 { 0, 8, 0, MM_CPU_OFFSET (x64._RBX), MM_CPU_OFFSET (x64._RBX) + 4,
TRUE },
68 { 0, 8, 0, MM_CPU_OFFSET (x64._RCX), MM_CPU_OFFSET (x64._RCX) + 4,
TRUE },
69 { 0, 8, 0, MM_CPU_OFFSET (x64._RDX), MM_CPU_OFFSET (x64._RDX) + 4,
TRUE },
70 { 0, 8, 0, MM_CPU_OFFSET (x64._RSP), MM_CPU_OFFSET (x64._RSP) + 4,
TRUE },
71 { 0, 8, 0, MM_CPU_OFFSET (x64._RBP), MM_CPU_OFFSET (x64._RBP) + 4,
TRUE },
72 { 0, 8, 0, MM_CPU_OFFSET (x64._RSI), MM_CPU_OFFSET (x64._RSI) + 4,
TRUE },
73 { 0, 8, 0, MM_CPU_OFFSET (x64._RDI), MM_CPU_OFFSET (x64._RDI) + 4,
TRUE },
74 { 0, 8, 0, MM_CPU_OFFSET (x64._RIP), MM_CPU_OFFSET (x64._RIP) + 4,
TRUE },
76 { 0, 8, 0, MM_CPU_OFFSET (x64._RFLAGS), MM_CPU_OFFSET (x64._RFLAGS) + 4,
TRUE },
77 { 0, 8, 0, MM_CPU_OFFSET (x64._CR0), MM_CPU_OFFSET (x64._CR0) + 4,
FALSE },
78 { 0, 8, 0, MM_CPU_OFFSET (x64._CR3), MM_CPU_OFFSET (x64._CR3) + 4,
FALSE },
79 { 0, 8, 0, MM_CPU_OFFSET (x64._CR4), MM_CPU_OFFSET (x64._CR4) + 4,
FALSE },
80 { 0, 0, 0, 0, 0,
FALSE }
119 if (
Register == EFI_MM_SAVE_STATE_REGISTER_LMA) {
122 return EFI_INVALID_PARAMETER;
140 if (SmmRevId < AMD_SMM_MIN_REV_ID_X64) {
141 return EFI_NOT_FOUND;
145 if (!(CpuSaveState->x64.IO_DWord & 0x02u)) {
146 return EFI_NOT_FOUND;
153 IoInfo->
IoPort = (UINT16)(CpuSaveState->x64.IO_DWord >> 16u);
155 if (CpuSaveState->x64.IO_DWord & 0x10u) {
156 IoInfo->
IoWidth = EFI_MM_SAVE_STATE_IO_WIDTH_UINT8;
158 }
else if (CpuSaveState->x64.IO_DWord & 0x20u) {
159 IoInfo->
IoWidth = EFI_MM_SAVE_STATE_IO_WIDTH_UINT16;
162 IoInfo->
IoWidth = EFI_MM_SAVE_STATE_IO_WIDTH_UINT32;
166 if (CpuSaveState->x64.IO_DWord & 0x01u) {
167 IoInfo->
IoType = EFI_MM_SAVE_STATE_IO_TYPE_INPUT;
169 IoInfo->
IoType = EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT;
172 if ((IoInfo->
IoType == EFI_MM_SAVE_STATE_IO_TYPE_INPUT) || (IoInfo->
IoType == EFI_MM_SAVE_STATE_IO_TYPE_OUTPUT)) {
215 if (
Register == EFI_MM_SAVE_STATE_REGISTER_LMA) {
223 return EFI_NOT_FOUND;
230 if (RegisterIndex == 0) {
231 return EFI_NOT_FOUND;
239 if (!mCpuWidthOffset[RegisterIndex].Writeable) {
240 return EFI_UNSUPPORTED;
246 if (mCpuWidthOffset[RegisterIndex].Width64 == 0) {
247 return EFI_NOT_FOUND;
253 if (Width > mCpuWidthOffset[RegisterIndex].Width64) {
254 return EFI_INVALID_PARAMETER;
260 CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer,
MIN (4, Width));
265 CopyMem ((UINT8 *)CpuSaveState + mCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4);
286 LMAValue = Msr.Bits.LMA;
288 return EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT;
294 return EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT;
EFI_STATUS EFIAPI MmSaveStateWriteRegister(IN UINTN CpuIndex, IN EFI_MM_SAVE_STATE_REGISTER Register, IN UINTN Width, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI MmSaveStateReadRegister(IN UINTN CpuIndex, IN EFI_MM_SAVE_STATE_REGISTER Register, IN UINTN Width, OUT VOID *Buffer)
UINT8 MmSaveStateGetRegisterLma(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
EFI_MM_SAVE_STATE_REGISTER
@ EFI_MM_SAVE_STATE_REGISTER_IO
UINTN MmSaveStateGetRegisterIndex(IN EFI_MM_SAVE_STATE_REGISTER Register, IN UINTN RegOffset)
EFI_STATUS MmSaveStateReadRegisterByIndex(IN UINTN CpuIndex, IN UINTN RegisterIndex, IN UINTN Width, OUT VOID *Buffer)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
EFI_MM_SAVE_STATE_IO_TYPE IoType
EFI_MM_SAVE_STATE_IO_WIDTH IoWidth