12#ifndef _CPU_PISMMCPUDXESMM_H_
13#define _CPU_PISMMCPUDXESMM_H_
74#define CPUID_CET_SS BIT7
75#define CPUID_CET_IBT BIT20
77#define CR4_CET_ENABLE BIT23
79#define MSR_IA32_S_CET 0x6A2
80#define MSR_IA32_PL0_SSP 0x6A4
81#define MSR_IA32_INTERRUPT_SSP_TABLE_ADDR 0x6A8
86 UINT32 SH_STK_ENP : 1;
88 UINT32 WR_SHSTK_EN : 1;
94 UINT32 NO_TRACK_EN : 1;
96 UINT32 SUPPRESS_DIS : 1;
110 UINT32 EB_LEG_BITMAP_BASE_low : 12;
111 UINT32 EB_LEG_BITMAP_BASE_high : 32;
119#define EFI_MSR_SMM_MCA_CAP 0x17D
120#define SMM_CODE_ACCESS_CHK_BIT BIT58
122#define SMM_FEATURE_CONTROL_LOCK_BIT BIT0
123#define SMM_CODE_CHK_EN_BIT BIT2
128#define IA32_PG_P BIT0
129#define IA32_PG_RW BIT1
130#define IA32_PG_U BIT2
131#define IA32_PG_WT BIT3
132#define IA32_PG_CD BIT4
133#define IA32_PG_A BIT5
134#define IA32_PG_D BIT6
135#define IA32_PG_PS BIT7
136#define IA32_PG_PAT_2M BIT12
137#define IA32_PG_PAT_4K IA32_PG_PS
138#define IA32_PG_PMNT BIT62
139#define IA32_PG_NX BIT63
141#define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)
146#define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)
148#define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)
150#define PAGING_4K_MASK 0xFFF
151#define PAGING_2M_MASK 0x1FFFFF
152#define PAGING_1G_MASK 0x3FFFFFFF
154#define PAGING_PAE_INDEX_MASK 0x1FF
156#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
157#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
158#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
160#define SMRR_MAX_ADDRESS BASE_4GB
170 PAGE_ATTRIBUTE Attribute;
179#define EXCEPTION_TSS_SIZE (TSS_SIZE + 4)
180#define TSS_X64_IST1_OFFSET 36
181#define TSS_IA32_CR3_OFFSET 28
182#define TSS_IA32_ESP_OFFSET 56
183#define TSS_IA32_SSP_OFFSET 104
190#define PROTECT_MODE_CODE_SEGMENT 0x08
191#define LONG_MODE_CODE_SEGMENT 0x38
193#define EXCEPTION_VECTOR_NUMBER 0x20
195#define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL
202 VOID *ProcedureArgument;
205#define PROCEDURE_TOKEN_SIGNATURE SIGNATURE_32 ('P', 'R', 'T', 'S')
212 volatile UINT32 RunningApCount;
215#define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, Link, PROCEDURE_TOKEN_SIGNATURE)
217#define TOKEN_BUFFER_SIGNATURE SIGNATURE_32 ('T', 'K', 'B', 'S')
226#define TOKEN_BUFFER_FROM_LINK(a) CR (a, TOKEN_BUFFER, Link, TOKEN_BUFFER_SIGNATURE)
233#define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')
241 SMM_CPU_OPERATION *Operation;
242 UINTN *CpuSaveStateSize;
256extern const BOOLEAN mIsStandaloneMm;
260extern UINTN mMaxNumberOfCpus;
261extern UINTN mNumberOfCpus;
264extern BOOLEAN m5LevelPagingNeeded;
265extern PAGING_MODE mPagingMode;
266extern UINTN mSmmShadowStackSize;
273extern BOOLEAN mAcpiS3Enable;
275#define PAGE_TABLE_POOL_ALIGNMENT BASE_128KB
276#define PAGE_TABLE_POOL_UNIT_SIZE BASE_128KB
277#define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)
278#define PAGE_TABLE_POOL_ALIGN_MASK \
279 (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))
375extern volatile BOOLEAN *mSmmInitialized;
376extern UINT32 mBspApicId;
378X86_ASSEMBLY_PATCH_LABEL mPatchCetSupported;
379extern BOOLEAN mCetSupported;
396 volatile VOID *Parameter;
397 volatile BOOLEAN *Present;
408 volatile UINT32 BspIndex;
409 volatile BOOLEAN *InsideSmm;
410 volatile BOOLEAN *AllCpusInSync;
411 volatile MM_CPU_SYNC_MODE EffectiveSyncMode;
412 volatile BOOLEAN SwitchBsp;
413 volatile BOOLEAN *CandidateBsp;
414 volatile BOOLEAN AllApArrivedWithException;
416 VOID *StartupProcArgs;
420#define SMM_PSD_OFFSET 0xfb00
426 volatile BOOLEAN *InsideSmm;
427 volatile BOOLEAN *AllCpusInSync;
437 volatile BOOLEAN *Present;
449extern IA32_DESCRIPTOR gcSmiGdtr;
451extern UINTN mGdtBufferSize;
452extern IA32_DESCRIPTOR gcSmiIdtr;
453extern VOID *gcSmiIdtrPtr;
454extern UINT64 gPhyMask;
456extern UINTN mSmmStackArrayBase;
457extern UINTN mSmmStackArrayEnd;
458extern UINTN mSmmStackSize;
461extern UINTN mSemaphoreSize;
463extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;
465extern UINTN mSmmCpuSmramRangeCount;
466extern UINT8 mPhysicalAddressBits;
467extern BOOLEAN mSmmDebugAgentSupport;
468extern BOOLEAN mSmmCodeAccessCheckEnable;
473extern UINT64 mAddressEncMask;
475extern UINT64 mTimeoutTicker;
476extern UINT64 mTimeoutTicker2;
502 IN BOOLEAN Is32BitPageTable
516 IN PAGING_MODE PagingMode,
517 IN UINT8 PhysicalAddressBits
654 IN OUT VOID *ProcArguments OPTIONAL
676 IN OUT VOID *ProcArguments OPTIONAL
708 IN PAGING_MODE PagingMode,
709 IN PHYSICAL_ADDRESS BaseAddress,
711 IN UINT64 Attributes,
713 OUT BOOLEAN *IsModified OPTIONAL
812 OUT UINT32 *SmrrBase,
1031 IN UINT8 PhysicalAddressBits,
1088 IN PAGING_MODE PagingMode,
1089 IN PHYSICAL_ADDRESS BaseAddress,
1091 IN UINT64 Attributes
1121 IN PAGING_MODE PagingMode,
1124 IN UINT64 Attributes
1163extern BOOLEAN mSmmS3Flag;
1194 IN OUT BOOLEAN *RelaxedMode, OPTIONAL
1195 IN OUT UINT64 *SyncTimeout, OPTIONAL
1196 IN OUT UINT64 *SyncTimeout2 OPTIONAL
1233 IN VOID *ShadowStack
1265 IN UINT64 Attributes
1297 IN UINT64 Attributes
1327 IN UINT64 *Attributes
1400 IN OUT VOID *ProcArguments OPTIONAL,
1401 IN OUT MM_COMPLETION *Token,
1402 IN UINTN TimeoutInMicroseconds,
1483 IN UINTN TimeoutInMicroseconds,
1484 IN OUT VOID *ProcedureArguments OPTIONAL,
1485 IN OUT MM_COMPLETION *Token,
1510 IN OUT VOID *ProcedureArguments OPTIONAL
1558 IN BOOLEAN BlockingMode
1578 OUT BOOLEAN *WriteProtect
1589 IN BOOLEAN WriteProtect
1612#define WRITE_UNPROTECT_RO_PAGES(Wp, Cet) \
1614 Cet = ((AsmReadCr4 () & CR4_CET_ENABLE) != 0); \
1618 SmmWriteUnprotectReadOnlyPage (&Wp); \
1621#define WRITE_PROTECT_RO_PAGES(Wp, Cet) \
1623 SmmWriteProtectReadOnlyPage (Wp); \
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
EFI_MM_SAVE_STATE_REGISTER
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
EFI_STATUS(EFIAPI * EFI_AP_PROCEDURE2)(IN VOID *ProcedureArgument)
VOID(EFIAPI * EFI_SMM_ENTRY_POINT)(IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext)
VOID EFIAPI SmmEntryPoint(IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext)
VOID EFIAPI InitializeIdtIst(IN EFI_EXCEPTION_TYPE ExceptionType, IN UINT8 Ist)
UINT64 EFIAPI StartSyncTimer(VOID)
BOOLEAN IsPresentAp(IN UINTN CpuIndex)
BOOLEAN IsRestrictedMemoryAccess(VOID)
UINTN GenSmmPageTable(IN PAGING_MODE PagingMode, IN UINT8 PhysicalAddressBits)
EFI_STATUS SmmSetMemoryAttributes(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
VOID GetAcpiS3EnableFlag(VOID)
VOID InitializeDataForMmMp(VOID)
VOID PerformRemainingTasks(VOID)
VOID EFIAPI EnableCet(VOID)
EFI_STATUS EFIAPI SmmCpuRendezvous(IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, IN BOOLEAN BlockingMode)
EFI_STATUS SmmClearMemoryAttributesEx(IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
VOID InitSmmS3ResumeState(VOID)
EFI_STATUS EFIAPI SmmGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
VOID FindSmramInfo(OUT UINT32 *SmrrBase, OUT UINT32 *SmrrSize)
EFI_STATUS EFIAPI EdkiiSmmGetMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 *Attributes)
EFI_PROCESSOR_INFORMATION * GetMpInformationFromMpServices(OUT UINTN *NumberOfCpus, OUT UINTN *MaxNumberOfCpus)
RETURN_STATUS ConvertMemoryPageAttributes(IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN BOOLEAN IsSet, OUT BOOLEAN *IsModified OPTIONAL)
EFI_STATUS InternalSmmStartupAllAPs(IN EFI_AP_PROCEDURE2 Procedure, IN UINTN TimeoutInMicroseconds, IN OUT VOID *ProcedureArguments OPTIONAL, IN OUT MM_COMPLETION *Token, IN OUT EFI_STATUS *CPUStatus)
VOID EFIAPI PiSmmCpuSmiEntryFixupAddress()
VOID EFIAPI InitializeIDTSmmStackGuard(VOID)
UINT32 SmmInitPageTable(VOID)
VOID InitShadowStack(IN UINTN CpuIndex, IN VOID *ShadowStack)
UINT32 Gen4GPageTable(IN BOOLEAN Is32BitPageTable)
EFI_STATUS RegisterStartupProcedure(IN EFI_AP_PROCEDURE Procedure, IN OUT VOID *ProcedureArguments OPTIONAL)
BOOLEAN IsNonMmramLoggingAddress(IN UINT64 Address)
VOID ConfigSmmCodeAccessCheck(VOID)
VOID RestoreSmmConfigurationInS3(VOID)
VOID EFIAPI SmmRelocationSemaphoreComplete(VOID)
EFI_STATUS SetShadowStack(IN UINTN Cr3, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
EFI_STATUS SmmSetMemoryAttributesEx(IN UINTN PageTableBase, IN PAGING_MODE PagingMode, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
VOID SmmWriteUnprotectReadOnlyPage(OUT BOOLEAN *WriteProtect)
VOID * AllocatePageTableMemory(IN UINTN Pages)
VOID EFIAPI DisableCet(VOID)
EFI_STATUS EFIAPI SmmWriteSaveState(IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI EdkiiSmmSetMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
EFI_STATUS EFIAPI SmmStartupThisAp(IN EFI_AP_PROCEDURE Procedure, IN UINTN CpuIndex, IN OUT VOID *ProcArguments OPTIONAL)
VOID CreateExtendedProtectionRange(OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
VOID InitPackageFirstThreadIndexInfo(VOID)
UINT32 InitializeMpServiceData(IN VOID *Stacks, IN UINTN StackSize, IN UINTN ShadowStackSize)
VOID SmmWaitForApArrival(VOID)
EFI_STATUS PiSmmCpuEntryCommon(VOID)
EFI_STATUS EFIAPI RegisterSmmEntry(IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This, IN EFI_SMM_ENTRY_POINT SmmEntryPoint)
VOID EFIAPI ConfigSmmCodeAccessCheckOnCurrentProcessor(IN OUT VOID *Buffer)
UINTN EFIAPI GetSmiHandlerSize(VOID)
EFI_STATUS IsApReady(IN SPIN_LOCK *Token)
VOID GetSmmCpuSyncConfigData(IN OUT BOOLEAN *RelaxedMode, OPTIONAL IN OUT UINT64 *SyncTimeout, OPTIONAL IN OUT UINT64 *SyncTimeout2 OPTIONAL)
VOID InitializeSmmTimer(VOID)
VOID * AllocateCodePages(IN UINTN Pages)
VOID RestoreCr2(IN UINTN Cr2)
VOID ExecuteFirstSmiInit(VOID)
BOOLEAN IsSmmProfileEnabled(VOID)
VOID SetMemMapAttributes(EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable)
VOID EFIAPI SmiPFHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
VOID SmmWriteProtectReadOnlyPage(IN BOOLEAN WriteProtect)
VOID InitMsrSpinLockByIndex(IN UINT32 MsrIndex)
BOOLEAN IsTokenInUse(IN SPIN_LOCK *Token)
VOID DumpModuleInfoByIp(IN UINTN CallerIpAddress)
UINT8 mSmmSaveStateRegisterLma
VOID PerformPreTasks(VOID)
EFI_SMM_CPU_PROTOCOL mSmmCpu
UINTN GetSupportedMaxLogicalProcessorNumber(VOID)
VOID SetPageTableAttributes(VOID)
EFI_PHYSICAL_ADDRESS GetSmmProfileData(IN OUT UINT64 *Size)
EFI_MM_MP_PROTOCOL mSmmMp
VOID EFIAPI InstallSmiHandler(IN UINTN CpuIndex, IN UINT32 SmBase, IN VOID *SmiStack, IN UINTN StackSize, IN UINTN GdtBase, IN UINTN GdtSize, IN UINTN IdtBase, IN UINTN IdtSize, IN UINT32 Cr3)
EFI_STATUS EFIAPI SmmReadSaveState(IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, OUT VOID *Buffer)
VOID CreateNonMmramMemMap(IN UINT8 PhysicalAddressBits, OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
VOID UpdateUefiMemMapAttributes(VOID)
BOOLEAN EFIAPI IsSyncTimerTimeout(IN UINT64 Timer, IN UINT64 Timeout)
EFI_STATUS InternalSmmStartupThisAp(IN EFI_AP_PROCEDURE2 Procedure, IN UINTN CpuIndex, IN OUT VOID *ProcArguments OPTIONAL, IN OUT MM_COMPLETION *Token, IN UINTN TimeoutInMicroseconds, IN OUT EFI_STATUS *CpuStatus)
VOID GetUefiMemoryMap(VOID)
VOID * InitGdt(IN UINTN Cr3, OUT UINTN *GdtStepSize)
VOID SaveCr2(OUT UINTN *Cr2)
BOOLEAN IsSmmCommBufferForbiddenAddress(IN UINT64 Address)
EFI_STATUS EFIAPI EdkiiSmmClearMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
VOID EFIAPI InitializeMpSyncData(VOID)
EFI_STATUS EFIAPI SmmBlockingStartupThisAp(IN EFI_AP_PROCEDURE Procedure, IN UINTN CpuIndex, IN OUT VOID *ProcArguments OPTIONAL)
EFI_STATUS SmmClearMemoryAttributes(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
UINT64 EFI_PHYSICAL_ADDRESS
EFI_PHYSICAL_ADDRESS Base