]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / PiSmmCpuDxeSmm.h
CommitLineData
529a5a86
MK
1/** @file\r
2Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.\r
3\r
3fdc47c6 4Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>\r
241f9149
LD
5Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
6\r
0acd8697 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
529a5a86
MK
8\r
9**/\r
10\r
11#ifndef _CPU_PISMMCPUDXESMM_H_\r
12#define _CPU_PISMMCPUDXESMM_H_\r
13\r
14#include <PiSmm.h>\r
15\r
16#include <Protocol/MpService.h>\r
17#include <Protocol/SmmConfiguration.h>\r
18#include <Protocol/SmmCpu.h>\r
19#include <Protocol/SmmAccess2.h>\r
529a5a86
MK
20#include <Protocol/SmmReadyToLock.h>\r
21#include <Protocol/SmmCpuService.h>\r
827330cc 22#include <Protocol/SmmMemoryAttribute.h>\r
51dd408a 23#include <Protocol/MmMp.h>\r
529a5a86
MK
24\r
25#include <Guid/AcpiS3Context.h>\r
8a2e1a9d 26#include <Guid/MemoryAttributesTable.h>\r
717fb604 27#include <Guid/PiSmmMemoryAttributesTable.h>\r
529a5a86
MK
28\r
29#include <Library/BaseLib.h>\r
30#include <Library/IoLib.h>\r
31#include <Library/TimerLib.h>\r
529a5a86
MK
32#include <Library/SynchronizationLib.h>\r
33#include <Library/DebugLib.h>\r
34#include <Library/BaseMemoryLib.h>\r
35#include <Library/PcdLib.h>\r
529a5a86
MK
36#include <Library/MtrrLib.h>\r
37#include <Library/SmmCpuPlatformHookLib.h>\r
38#include <Library/SmmServicesTableLib.h>\r
39#include <Library/MemoryAllocationLib.h>\r
40#include <Library/UefiBootServicesTableLib.h>\r
41#include <Library/UefiRuntimeServicesTableLib.h>\r
42#include <Library/DebugAgentLib.h>\r
8a2e1a9d 43#include <Library/UefiLib.h>\r
529a5a86
MK
44#include <Library/HobLib.h>\r
45#include <Library/LocalApicLib.h>\r
46#include <Library/UefiCpuLib.h>\r
47#include <Library/CpuExceptionHandlerLib.h>\r
48#include <Library/ReportStatusCodeLib.h>\r
49#include <Library/SmmCpuFeaturesLib.h>\r
50#include <Library/PeCoffGetEntryPointLib.h>\r
93324390 51#include <Library/RegisterCpuFeaturesLib.h>\r
529a5a86
MK
52\r
53#include <AcpiCpuData.h>\r
54#include <CpuHotPlugData.h>\r
55\r
01acb06c
RN
56#include <Register/Intel/Cpuid.h>\r
57#include <Register/Intel/Msr.h>\r
529a5a86
MK
58\r
59#include "CpuService.h"\r
60#include "SmmProfile.h"\r
61\r
3eb69b08
JY
62//\r
63// CET definition\r
64//\r
65#define CPUID_CET_SS BIT7\r
66#define CPUID_CET_IBT BIT20\r
67\r
68#define CR4_CET_ENABLE BIT23\r
69\r
70#define MSR_IA32_S_CET 0x6A2\r
71#define MSR_IA32_PL0_SSP 0x6A4\r
72#define MSR_IA32_INTERRUPT_SSP_TABLE_ADDR 0x6A8\r
73\r
74typedef union {\r
75 struct {\r
76 // enable shadow stacks\r
77 UINT32 SH_STK_ENP:1;\r
78 // enable the WRSS{D,Q}W instructions.\r
79 UINT32 WR_SHSTK_EN:1;\r
80 // enable tracking of indirect call/jmp targets to be ENDBRANCH instruction.\r
81 UINT32 ENDBR_EN:1;\r
82 // enable legacy compatibility treatment for indirect call/jmp tracking.\r
83 UINT32 LEG_IW_EN:1;\r
84 // enable use of no-track prefix on indirect call/jmp.\r
85 UINT32 NO_TRACK_EN:1;\r
86 // disable suppression of CET indirect branch tracking on legacy compatibility.\r
87 UINT32 SUPPRESS_DIS:1;\r
88 UINT32 RSVD:4;\r
89 // indirect branch tracking is suppressed.\r
90 // This bit can be written to 1 only if TRACKER is written as IDLE.\r
91 UINT32 SUPPRESS:1;\r
92 // Value of the endbranch state machine\r
93 // Values: IDLE (0), WAIT_FOR_ENDBRANCH(1).\r
94 UINT32 TRACKER:1;\r
95 // linear address of a bitmap in memory indicating valid\r
96 // pages as target of CALL/JMP_indirect that do not land on ENDBRANCH when CET is enabled\r
97 // and not suppressed. Valid when ENDBR_EN is 1. Must be machine canonical when written on\r
98 // parts that support 64 bit mode. On parts that do not support 64 bit mode, the bits 63:32 are\r
99 // reserved and must be 0. This value is extended by 12 bits at the low end to form the base address\r
100 // (this automatically aligns the address on a 4-Kbyte boundary).\r
101 UINT32 EB_LEG_BITMAP_BASE_low:12;\r
102 UINT32 EB_LEG_BITMAP_BASE_high:32;\r
103 } Bits;\r
104 UINT64 Uint64;\r
105} MSR_IA32_CET;\r
106\r
529a5a86
MK
107//\r
108// MSRs required for configuration of SMM Code Access Check\r
109//\r
110#define EFI_MSR_SMM_MCA_CAP 0x17D\r
111#define SMM_CODE_ACCESS_CHK_BIT BIT58\r
112\r
113#define SMM_FEATURE_CONTROL_LOCK_BIT BIT0\r
114#define SMM_CODE_CHK_EN_BIT BIT2\r
115\r
116///\r
117/// Page Table Entry\r
118///\r
119#define IA32_PG_P BIT0\r
120#define IA32_PG_RW BIT1\r
881520ea 121#define IA32_PG_U BIT2\r
529a5a86
MK
122#define IA32_PG_WT BIT3\r
123#define IA32_PG_CD BIT4\r
124#define IA32_PG_A BIT5\r
881520ea 125#define IA32_PG_D BIT6\r
529a5a86
MK
126#define IA32_PG_PS BIT7\r
127#define IA32_PG_PAT_2M BIT12\r
128#define IA32_PG_PAT_4K IA32_PG_PS\r
129#define IA32_PG_PMNT BIT62\r
130#define IA32_PG_NX BIT63\r
131\r
717fb604 132#define PAGE_ATTRIBUTE_BITS (IA32_PG_D | IA32_PG_A | IA32_PG_U | IA32_PG_RW | IA32_PG_P)\r
881520ea
JY
133//\r
134// Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE\r
135// X64 PAE PDPTE does not have such restriction\r
136//\r
137#define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)\r
138\r
717fb604
JY
139#define PAGE_PROGATE_BITS (IA32_PG_NX | PAGE_ATTRIBUTE_BITS)\r
140\r
141#define PAGING_4K_MASK 0xFFF\r
142#define PAGING_2M_MASK 0x1FFFFF\r
143#define PAGING_1G_MASK 0x3FFFFFFF\r
144\r
145#define PAGING_PAE_INDEX_MASK 0x1FF\r
146\r
147#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull\r
148#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull\r
149#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull\r
150\r
7ed6f781
JF
151#define SMRR_MAX_ADDRESS BASE_4GB\r
152\r
717fb604
JY
153typedef enum {\r
154 PageNone,\r
155 Page4K,\r
156 Page2M,\r
157 Page1G,\r
158} PAGE_ATTRIBUTE;\r
159\r
160typedef struct {\r
161 PAGE_ATTRIBUTE Attribute;\r
162 UINT64 Length;\r
163 UINT64 AddressMask;\r
164} PAGE_ATTRIBUTE_TABLE;\r
165\r
529a5a86
MK
166//\r
167// Size of Task-State Segment defined in IA32 Manual\r
168//\r
169#define TSS_SIZE 104\r
3eb69b08 170#define EXCEPTION_TSS_SIZE (TSS_SIZE + 4) // Add 4 bytes SSP\r
529a5a86
MK
171#define TSS_X64_IST1_OFFSET 36\r
172#define TSS_IA32_CR3_OFFSET 28\r
173#define TSS_IA32_ESP_OFFSET 56\r
3eb69b08 174#define TSS_IA32_SSP_OFFSET 104\r
529a5a86 175\r
717fb604
JY
176#define CR0_WP BIT16\r
177\r
529a5a86
MK
178//\r
179// Code select value\r
180//\r
181#define PROTECT_MODE_CODE_SEGMENT 0x08\r
182#define LONG_MODE_CODE_SEGMENT 0x38\r
183\r
184//\r
185// The size 0x20 must be bigger than\r
186// the size of template code of SmmInit. Currently,\r
187// the size of SmmInit requires the 0x16 Bytes buffer\r
188// at least.\r
189//\r
190#define BACK_BUF_SIZE 0x20\r
191\r
192#define EXCEPTION_VECTOR_NUMBER 0x20\r
193\r
194#define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL\r
195\r
196typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS;\r
197#define ARRIVAL_EXCEPTION_BLOCKED 0x1\r
198#define ARRIVAL_EXCEPTION_DELAYED 0x2\r
199#define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4\r
200\r
51dd408a
ED
201//\r
202// Wrapper used to convert EFI_AP_PROCEDURE2 and EFI_AP_PROCEDURE.\r
203//\r
204typedef struct {\r
205 EFI_AP_PROCEDURE Procedure;\r
206 VOID *ProcedureArgument;\r
207} PROCEDURE_WRAPPER;\r
208\r
209#define PROCEDURE_TOKEN_SIGNATURE SIGNATURE_32 ('P', 'R', 'T', 'S')\r
210\r
211typedef struct {\r
212 UINTN Signature;\r
213 LIST_ENTRY Link;\r
214\r
a457823f
ED
215 SPIN_LOCK *SpinLock;\r
216 volatile UINT32 RunningApCount;\r
51dd408a
ED
217} PROCEDURE_TOKEN;\r
218\r
219#define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, Link, PROCEDURE_TOKEN_SIGNATURE)\r
220\r
9caaa79d
ED
221#define TOKEN_BUFFER_SIGNATURE SIGNATURE_32 ('T', 'K', 'B', 'S')\r
222\r
223typedef struct {\r
224 UINTN Signature;\r
225 LIST_ENTRY Link;\r
226\r
227 UINT8 *Buffer;\r
228} TOKEN_BUFFER;\r
229\r
230#define TOKEN_BUFFER_FROM_LINK(a) CR (a, TOKEN_BUFFER, Link, TOKEN_BUFFER_SIGNATURE)\r
231\r
529a5a86
MK
232//\r
233// Private structure for the SMM CPU module that is stored in DXE Runtime memory\r
234// Contains the SMM Configuration Protocols that is produced.\r
235// Contains a mix of DXE and SMM contents. All the fields must be used properly.\r
236//\r
237#define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')\r
238\r
239typedef struct {\r
240 UINTN Signature;\r
241\r
242 EFI_HANDLE SmmCpuHandle;\r
243\r
244 EFI_PROCESSOR_INFORMATION *ProcessorInfo;\r
245 SMM_CPU_OPERATION *Operation;\r
246 UINTN *CpuSaveStateSize;\r
247 VOID **CpuSaveState;\r
248\r
249 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion[1];\r
250 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext;\r
251 EFI_SMM_ENTRY_POINT SmmCoreEntry;\r
252\r
253 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration;\r
51dd408a
ED
254\r
255 PROCEDURE_WRAPPER *ApWrapperFunc;\r
256 LIST_ENTRY TokenList;\r
3fdc47c6 257 LIST_ENTRY *FirstFreeToken;\r
529a5a86
MK
258} SMM_CPU_PRIVATE_DATA;\r
259\r
260extern SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate;\r
261extern CPU_HOT_PLUG_DATA mCpuHotPlugData;\r
262extern UINTN mMaxNumberOfCpus;\r
263extern UINTN mNumberOfCpus;\r
529a5a86 264extern EFI_SMM_CPU_PROTOCOL mSmmCpu;\r
51dd408a 265extern EFI_MM_MP_PROTOCOL mSmmMp;\r
529a5a86
MK
266\r
267///\r
268/// The mode of the CPU at the time an SMI occurs\r
269///\r
270extern UINT8 mSmmSaveStateRegisterLma;\r
271\r
529a5a86
MK
272//\r
273// SMM CPU Protocol function prototypes.\r
274//\r
275\r
276/**\r
277 Read information from the CPU save state.\r
278\r
279 @param This EFI_SMM_CPU_PROTOCOL instance\r
280 @param Width The number of bytes to read from the CPU save state.\r
281 @param Register Specifies the CPU register to read form the save state.\r
282 @param CpuIndex Specifies the zero-based index of the CPU save state\r
283 @param Buffer Upon return, this holds the CPU register value read from the save state.\r
284\r
285 @retval EFI_SUCCESS The register was read from Save State\r
286 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor\r
ef62da4f 287 @retval EFI_INVALID_PARAMETER This or Buffer is NULL.\r
529a5a86
MK
288\r
289**/\r
290EFI_STATUS\r
291EFIAPI\r
292SmmReadSaveState (\r
293 IN CONST EFI_SMM_CPU_PROTOCOL *This,\r
294 IN UINTN Width,\r
295 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
296 IN UINTN CpuIndex,\r
297 OUT VOID *Buffer\r
298 );\r
299\r
300/**\r
301 Write data to the CPU save state.\r
302\r
303 @param This EFI_SMM_CPU_PROTOCOL instance\r
304 @param Width The number of bytes to read from the CPU save state.\r
305 @param Register Specifies the CPU register to write to the save state.\r
306 @param CpuIndex Specifies the zero-based index of the CPU save state\r
307 @param Buffer Upon entry, this holds the new CPU register value.\r
308\r
309 @retval EFI_SUCCESS The register was written from Save State\r
310 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor\r
ef62da4f 311 @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct\r
529a5a86
MK
312\r
313**/\r
314EFI_STATUS\r
315EFIAPI\r
316SmmWriteSaveState (\r
317 IN CONST EFI_SMM_CPU_PROTOCOL *This,\r
318 IN UINTN Width,\r
319 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
320 IN UINTN CpuIndex,\r
321 IN CONST VOID *Buffer\r
322 );\r
323\r
324/**\r
325Read a CPU Save State register on the target processor.\r
326\r
327This function abstracts the differences that whether the CPU Save State register is in the\r
328IA32 CPU Save State Map or X64 CPU Save State Map.\r
329\r
330This function supports reading a CPU Save State register in SMBase relocation handler.\r
331\r
332@param[in] CpuIndex Specifies the zero-based index of the CPU save state.\r
333@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.\r
334@param[in] Width The number of bytes to read from the CPU save state.\r
335@param[out] Buffer Upon return, this holds the CPU register value read from the save state.\r
336\r
337@retval EFI_SUCCESS The register was read from Save State.\r
338@retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.\r
ef62da4f 339@retval EFI_INVALID_PARAMETER This or Buffer is NULL.\r
529a5a86
MK
340\r
341**/\r
342EFI_STATUS\r
343EFIAPI\r
344ReadSaveStateRegister (\r
345 IN UINTN CpuIndex,\r
346 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
347 IN UINTN Width,\r
348 OUT VOID *Buffer\r
349 );\r
350\r
351/**\r
352Write value to a CPU Save State register on the target processor.\r
353\r
354This function abstracts the differences that whether the CPU Save State register is in the\r
355IA32 CPU Save State Map or X64 CPU Save State Map.\r
356\r
357This function supports writing a CPU Save State register in SMBase relocation handler.\r
358\r
359@param[in] CpuIndex Specifies the zero-based index of the CPU save state.\r
360@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.\r
361@param[in] Width The number of bytes to read from the CPU save state.\r
362@param[in] Buffer Upon entry, this holds the new CPU register value.\r
363\r
364@retval EFI_SUCCESS The register was written to Save State.\r
365@retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.\r
ef62da4f 366@retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct.\r
529a5a86
MK
367\r
368**/\r
369EFI_STATUS\r
370EFIAPI\r
371WriteSaveStateRegister (\r
372 IN UINTN CpuIndex,\r
373 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
374 IN UINTN Width,\r
375 IN CONST VOID *Buffer\r
376 );\r
377\r
529a5a86
MK
378extern CONST UINT8 gcSmmInitTemplate[];\r
379extern CONST UINT16 gcSmmInitSize;\r
f0053e83
LE
380X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0;\r
381extern UINT32 mSmmCr0;\r
6b0841c1 382X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3;\r
351b49c1
LE
383extern UINT32 mSmmCr4;\r
384X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4;\r
5830d2c3 385X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack;\r
3eb69b08
JY
386X86_ASSEMBLY_PATCH_LABEL mPatchCetSupported;\r
387extern BOOLEAN mCetSupported;\r
529a5a86
MK
388\r
389/**\r
390 Semaphore operation for all processor relocate SMMBase.\r
391**/\r
392VOID\r
393EFIAPI\r
394SmmRelocationSemaphoreComplete (\r
395 VOID\r
396 );\r
397\r
398///\r
399/// The type of SMM CPU Information\r
400///\r
401typedef struct {\r
ed3d5ecb 402 SPIN_LOCK *Busy;\r
51dd408a 403 volatile EFI_AP_PROCEDURE2 Procedure;\r
529a5a86 404 volatile VOID *Parameter;\r
ed3d5ecb
JF
405 volatile UINT32 *Run;\r
406 volatile BOOLEAN *Present;\r
a457823f 407 PROCEDURE_TOKEN *Token;\r
51dd408a 408 EFI_STATUS *Status;\r
529a5a86
MK
409} SMM_CPU_DATA_BLOCK;\r
410\r
411typedef enum {\r
412 SmmCpuSyncModeTradition,\r
413 SmmCpuSyncModeRelaxedAp,\r
414 SmmCpuSyncModeMax\r
415} SMM_CPU_SYNC_MODE;\r
416\r
417typedef struct {\r
418 //\r
419 // Pointer to an array. The array should be located immediately after this structure\r
420 // so that UC cache-ability can be set together.\r
421 //\r
422 SMM_CPU_DATA_BLOCK *CpuData;\r
fe3a75bc 423 volatile UINT32 *Counter;\r
529a5a86 424 volatile UINT32 BspIndex;\r
fe3a75bc
JF
425 volatile BOOLEAN *InsideSmm;\r
426 volatile BOOLEAN *AllCpusInSync;\r
529a5a86
MK
427 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode;\r
428 volatile BOOLEAN SwitchBsp;\r
429 volatile BOOLEAN *CandidateBsp;\r
51dd408a
ED
430 EFI_AP_PROCEDURE StartupProcedure;\r
431 VOID *StartupProcArgs;\r
529a5a86
MK
432} SMM_DISPATCHER_MP_SYNC_DATA;\r
433\r
529a5a86
MK
434#define SMM_PSD_OFFSET 0xfb00\r
435\r
1d648531
JF
436///\r
437/// All global semaphores' pointer\r
438///\r
439typedef struct {\r
440 volatile UINT32 *Counter;\r
441 volatile BOOLEAN *InsideSmm;\r
442 volatile BOOLEAN *AllCpusInSync;\r
443 SPIN_LOCK *PFLock;\r
444 SPIN_LOCK *CodeAccessCheckLock;\r
445} SMM_CPU_SEMAPHORE_GLOBAL;\r
446\r
4e920581
JF
447///\r
448/// All semaphores for each processor\r
449///\r
450typedef struct {\r
451 SPIN_LOCK *Busy;\r
452 volatile UINT32 *Run;\r
453 volatile BOOLEAN *Present;\r
51dd408a 454 SPIN_LOCK *Token;\r
4e920581
JF
455} SMM_CPU_SEMAPHORE_CPU;\r
456\r
1d648531
JF
457///\r
458/// All semaphores' information\r
459///\r
460typedef struct {\r
461 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal;\r
4e920581 462 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu;\r
1d648531
JF
463} SMM_CPU_SEMAPHORES;\r
464\r
529a5a86 465extern IA32_DESCRIPTOR gcSmiGdtr;\r
717fb604
JY
466extern EFI_PHYSICAL_ADDRESS mGdtBuffer;\r
467extern UINTN mGdtBufferSize;\r
529a5a86
MK
468extern IA32_DESCRIPTOR gcSmiIdtr;\r
469extern VOID *gcSmiIdtrPtr;\r
529a5a86 470extern UINT64 gPhyMask;\r
529a5a86 471extern SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData;\r
529a5a86
MK
472extern UINTN mSmmStackArrayBase;\r
473extern UINTN mSmmStackArrayEnd;\r
474extern UINTN mSmmStackSize;\r
475extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;\r
476extern IA32_DESCRIPTOR gcSmiInitGdtr;\r
dc99315b
JF
477extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores;\r
478extern UINTN mSemaphoreSize;\r
fe3a75bc
JF
479extern SPIN_LOCK *mPFLock;\r
480extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;\r
7ed6f781
JF
481extern EFI_SMRAM_DESCRIPTOR *mSmmCpuSmramRanges;\r
482extern UINTN mSmmCpuSmramRangeCount;\r
714c2603 483extern UINT8 mPhysicalAddressBits;\r
529a5a86 484\r
241f9149
LD
485//\r
486// Copy of the PcdPteMemoryEncryptionAddressOrMask\r
487//\r
488extern UINT64 mAddressEncMask;\r
489\r
529a5a86
MK
490/**\r
491 Create 4G PageTable in SMRAM.\r
492\r
717fb604 493 @param[in] Is32BitPageTable Whether the page table is 32-bit PAE\r
529a5a86
MK
494 @return PageTable Address\r
495\r
496**/\r
497UINT32\r
498Gen4GPageTable (\r
881520ea 499 IN BOOLEAN Is32BitPageTable\r
529a5a86
MK
500 );\r
501\r
502\r
503/**\r
504 Initialize global data for MP synchronization.\r
505\r
3eb69b08
JY
506 @param Stacks Base address of SMI stack buffer for all processors.\r
507 @param StackSize Stack size for each processor in SMM.\r
508 @param ShadowStackSize Shadow Stack size for each processor in SMM.\r
529a5a86
MK
509\r
510**/\r
511UINT32\r
512InitializeMpServiceData (\r
513 IN VOID *Stacks,\r
3eb69b08
JY
514 IN UINTN StackSize,\r
515 IN UINTN ShadowStackSize\r
529a5a86
MK
516 );\r
517\r
518/**\r
519 Initialize Timer for SMM AP Sync.\r
520\r
521**/\r
522VOID\r
523InitializeSmmTimer (\r
524 VOID\r
525 );\r
526\r
527/**\r
528 Start Timer for SMM AP Sync.\r
529\r
530**/\r
531UINT64\r
532EFIAPI\r
533StartSyncTimer (\r
534 VOID\r
535 );\r
536\r
537/**\r
538 Check if the SMM AP Sync timer is timeout.\r
539\r
540 @param Timer The start timer from the begin.\r
541\r
542**/\r
543BOOLEAN\r
544EFIAPI\r
545IsSyncTimerTimeout (\r
546 IN UINT64 Timer\r
547 );\r
548\r
549/**\r
550 Initialize IDT for SMM Stack Guard.\r
551\r
552**/\r
553VOID\r
554EFIAPI\r
555InitializeIDTSmmStackGuard (\r
556 VOID\r
557 );\r
558\r
fe5f1949
JY
559/**\r
560 Initialize Gdt for all processors.\r
717fb604 561\r
fe5f1949
JY
562 @param[in] Cr3 CR3 value.\r
563 @param[out] GdtStepSize The step size for GDT table.\r
564\r
565 @return GdtBase for processor 0.\r
566 GdtBase for processor X is: GdtBase + (GdtStepSize * X)\r
567**/\r
568VOID *\r
569InitGdt (\r
570 IN UINTN Cr3,\r
571 OUT UINTN *GdtStepSize\r
572 );\r
573\r
529a5a86
MK
574/**\r
575\r
576 Register the SMM Foundation entry point.\r
577\r
578 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance\r
579 @param SmmEntryPoint SMM Foundation EntryPoint\r
580\r
581 @retval EFI_SUCCESS Successfully to register SMM foundation entry point\r
582\r
583**/\r
584EFI_STATUS\r
585EFIAPI\r
586RegisterSmmEntry (\r
587 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This,\r
588 IN EFI_SMM_ENTRY_POINT SmmEntryPoint\r
589 );\r
590\r
591/**\r
592 Create PageTable for SMM use.\r
593\r
594 @return PageTable Address\r
595\r
596**/\r
597UINT32\r
598SmmInitPageTable (\r
599 VOID\r
600 );\r
601\r
602/**\r
603 Schedule a procedure to run on the specified CPU.\r
604\r
605 @param Procedure The address of the procedure to run\r
606 @param CpuIndex Target CPU number\r
607 @param ProcArguments The parameter to pass to the procedure\r
608\r
609 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
610 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
611 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
612 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
613 @retval EFI_SUCCESS - The procedure has been successfully scheduled\r
614\r
615**/\r
616EFI_STATUS\r
617EFIAPI\r
618SmmStartupThisAp (\r
619 IN EFI_AP_PROCEDURE Procedure,\r
620 IN UINTN CpuIndex,\r
621 IN OUT VOID *ProcArguments OPTIONAL\r
622 );\r
623\r
624/**\r
625 Schedule a procedure to run on the specified CPU in a blocking fashion.\r
626\r
627 @param Procedure The address of the procedure to run\r
628 @param CpuIndex Target CPU Index\r
629 @param ProcArguments The parameter to pass to the procedure\r
630\r
631 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
632 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
633 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
634 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
635 @retval EFI_SUCCESS The procedure has been successfully scheduled\r
636\r
637**/\r
638EFI_STATUS\r
639EFIAPI\r
640SmmBlockingStartupThisAp (\r
641 IN EFI_AP_PROCEDURE Procedure,\r
642 IN UINTN CpuIndex,\r
643 IN OUT VOID *ProcArguments OPTIONAL\r
644 );\r
645\r
e4435f71
JY
646/**\r
647 This function sets the attributes for the memory region specified by BaseAddress and\r
648 Length from their current attributes to the attributes specified by Attributes.\r
649\r
650 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
651 @param[in] Length The size in bytes of the memory region.\r
652 @param[in] Attributes The bit mask of attributes to set for the memory region.\r
653\r
654 @retval EFI_SUCCESS The attributes were set for the memory region.\r
655 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
656 BaseAddress and Length cannot be modified.\r
657 @retval EFI_INVALID_PARAMETER Length is zero.\r
658 Attributes specified an illegal combination of attributes that\r
659 cannot be set together.\r
660 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
661 the memory resource range.\r
662 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
663 resource range specified by BaseAddress and Length.\r
664 The bit mask of attributes is not support for the memory resource\r
665 range specified by BaseAddress and Length.\r
666\r
667**/\r
668EFI_STATUS\r
669EFIAPI\r
670SmmSetMemoryAttributes (\r
671 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
672 IN UINT64 Length,\r
673 IN UINT64 Attributes\r
674 );\r
675\r
676/**\r
677 This function clears the attributes for the memory region specified by BaseAddress and\r
678 Length from their current attributes to the attributes specified by Attributes.\r
679\r
680 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
681 @param[in] Length The size in bytes of the memory region.\r
682 @param[in] Attributes The bit mask of attributes to clear for the memory region.\r
683\r
684 @retval EFI_SUCCESS The attributes were cleared for the memory region.\r
685 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
686 BaseAddress and Length cannot be modified.\r
687 @retval EFI_INVALID_PARAMETER Length is zero.\r
688 Attributes specified an illegal combination of attributes that\r
689 cannot be set together.\r
690 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
691 the memory resource range.\r
692 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
693 resource range specified by BaseAddress and Length.\r
694 The bit mask of attributes is not support for the memory resource\r
695 range specified by BaseAddress and Length.\r
696\r
697**/\r
698EFI_STATUS\r
699EFIAPI\r
700SmmClearMemoryAttributes (\r
701 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
702 IN UINT64 Length,\r
703 IN UINT64 Attributes\r
704 );\r
705\r
529a5a86
MK
706/**\r
707 Initialize MP synchronization data.\r
708\r
709**/\r
710VOID\r
711EFIAPI\r
712InitializeMpSyncData (\r
713 VOID\r
714 );\r
715\r
716/**\r
717\r
718 Find out SMRAM information including SMRR base and SMRR size.\r
719\r
720 @param SmrrBase SMRR base\r
721 @param SmrrSize SMRR size\r
722\r
723**/\r
724VOID\r
725FindSmramInfo (\r
726 OUT UINT32 *SmrrBase,\r
727 OUT UINT32 *SmrrSize\r
728 );\r
729\r
730/**\r
0bdc9e75 731 Relocate SmmBases for each processor.\r
529a5a86 732\r
0bdc9e75 733 Execute on first boot and all S3 resumes\r
529a5a86
MK
734\r
735**/\r
736VOID\r
0bdc9e75
SZ
737EFIAPI\r
738SmmRelocateBases (\r
529a5a86
MK
739 VOID\r
740 );\r
741\r
742/**\r
743 Page Fault handler for SMM use.\r
744\r
745 @param InterruptType Defines the type of interrupt or exception that\r
746 occurred on the processor.This parameter is processor architecture specific.\r
747 @param SystemContext A pointer to the processor context when\r
748 the interrupt occurred on the processor.\r
749**/\r
750VOID\r
751EFIAPI\r
752SmiPFHandler (\r
b8caae19
JF
753 IN EFI_EXCEPTION_TYPE InterruptType,\r
754 IN EFI_SYSTEM_CONTEXT SystemContext\r
529a5a86
MK
755 );\r
756\r
757/**\r
758 Perform the remaining tasks.\r
759\r
760**/\r
761VOID\r
762PerformRemainingTasks (\r
763 VOID\r
764 );\r
765\r
9f419739
JY
766/**\r
767 Perform the pre tasks.\r
768\r
769**/\r
770VOID\r
771PerformPreTasks (\r
772 VOID\r
773 );\r
774\r
529a5a86
MK
775/**\r
776 Initialize MSR spin lock by MSR index.\r
777\r
778 @param MsrIndex MSR index value.\r
779\r
780**/\r
781VOID\r
782InitMsrSpinLockByIndex (\r
783 IN UINT32 MsrIndex\r
784 );\r
785\r
786/**\r
787 Hook return address of SMM Save State so that semaphore code\r
788 can be executed immediately after AP exits SMM to indicate to\r
789 the BSP that an AP has exited SMM after SMBASE relocation.\r
790\r
791 @param[in] CpuIndex The processor index.\r
792 @param[in] RebasedFlag A pointer to a flag that is set to TRUE\r
793 immediately after AP exits SMM.\r
794\r
795**/\r
796VOID\r
797SemaphoreHook (\r
798 IN UINTN CpuIndex,\r
799 IN volatile BOOLEAN *RebasedFlag\r
800 );\r
801\r
802/**\r
803Configure SMM Code Access Check feature for all processors.\r
804SMM Feature Control MSR will be locked after configuration.\r
805**/\r
806VOID\r
807ConfigSmmCodeAccessCheck (\r
808 VOID\r
809 );\r
810\r
811/**\r
812 Hook the code executed immediately after an RSM instruction on the currently\r
813 executing CPU. The mode of code executed immediately after RSM must be\r
814 detected, and the appropriate hook must be selected. Always clear the auto\r
815 HALT restart flag if it is set.\r
816\r
817 @param[in] CpuIndex The processor index for the currently\r
818 executing CPU.\r
819 @param[in] CpuState Pointer to SMRAM Save State Map for the\r
820 currently executing CPU.\r
821 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
822 32-bit mode from 64-bit SMM.\r
823 @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
824 same mode as SMM.\r
825\r
826 @retval The value of the original instruction pointer before it was hooked.\r
827\r
828**/\r
829UINT64\r
830EFIAPI\r
831HookReturnFromSmm (\r
832 IN UINTN CpuIndex,\r
833 SMRAM_SAVE_STATE_MAP *CpuState,\r
834 UINT64 NewInstructionPointer32,\r
835 UINT64 NewInstructionPointer\r
836 );\r
837\r
838/**\r
839 Get the size of the SMI Handler in bytes.\r
840\r
841 @retval The size, in bytes, of the SMI Handler.\r
842\r
843**/\r
844UINTN\r
845EFIAPI\r
846GetSmiHandlerSize (\r
847 VOID\r
848 );\r
849\r
850/**\r
851 Install the SMI handler for the CPU specified by CpuIndex. This function\r
852 is called by the CPU that was elected as monarch during System Management\r
853 Mode initialization.\r
854\r
855 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.\r
856 The value must be between 0 and the NumberOfCpus field\r
857 in the System Management System Table (SMST).\r
858 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.\r
859 @param[in] SmiStack The stack to use when an SMI is processed by the\r
860 the CPU specified by CpuIndex.\r
861 @param[in] StackSize The size, in bytes, if the stack used when an SMI is\r
862 processed by the CPU specified by CpuIndex.\r
863 @param[in] GdtBase The base address of the GDT to use when an SMI is\r
864 processed by the CPU specified by CpuIndex.\r
865 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is\r
866 processed by the CPU specified by CpuIndex.\r
867 @param[in] IdtBase The base address of the IDT to use when an SMI is\r
868 processed by the CPU specified by CpuIndex.\r
869 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is\r
870 processed by the CPU specified by CpuIndex.\r
871 @param[in] Cr3 The base address of the page tables to use when an SMI\r
872 is processed by the CPU specified by CpuIndex.\r
873**/\r
874VOID\r
875EFIAPI\r
876InstallSmiHandler (\r
877 IN UINTN CpuIndex,\r
878 IN UINT32 SmBase,\r
879 IN VOID *SmiStack,\r
880 IN UINTN StackSize,\r
881 IN UINTN GdtBase,\r
882 IN UINTN GdtSize,\r
883 IN UINTN IdtBase,\r
884 IN UINTN IdtSize,\r
885 IN UINT32 Cr3\r
886 );\r
887\r
888/**\r
889 Search module name by input IP address and output it.\r
890\r
891 @param CallerIpAddress Caller instruction pointer.\r
892\r
893**/\r
894VOID\r
895DumpModuleInfoByIp (\r
896 IN UINTN CallerIpAddress\r
897 );\r
21c17193 898\r
717fb604
JY
899/**\r
900 This function sets memory attribute according to MemoryAttributesTable.\r
901**/\r
902VOID\r
903SetMemMapAttributes (\r
904 VOID\r
905 );\r
906\r
d2fc7711
JY
907/**\r
908 This function sets UEFI memory attribute according to UEFI memory map.\r
909**/\r
910VOID\r
911SetUefiMemMapAttributes (\r
912 VOID\r
913 );\r
914\r
915/**\r
916 Return if the Address is forbidden as SMM communication buffer.\r
917\r
918 @param[in] Address the address to be checked\r
919\r
920 @return TRUE The address is forbidden as SMM communication buffer.\r
921 @return FALSE The address is allowed as SMM communication buffer.\r
922**/\r
923BOOLEAN\r
924IsSmmCommBufferForbiddenAddress (\r
925 IN UINT64 Address\r
926 );\r
927\r
928/**\r
929 This function caches the UEFI memory map information.\r
930**/\r
931VOID\r
932GetUefiMemoryMap (\r
933 VOID\r
934 );\r
935\r
717fb604
JY
936/**\r
937 This function sets memory attribute for page table.\r
938**/\r
939VOID\r
940SetPageTableAttributes (\r
941 VOID\r
942 );\r
943\r
944/**\r
945 Return page table base.\r
946\r
947 @return page table base.\r
948**/\r
949UINTN\r
950GetPageTableBase (\r
951 VOID\r
952 );\r
953\r
954/**\r
955 This function sets the attributes for the memory region specified by BaseAddress and\r
956 Length from their current attributes to the attributes specified by Attributes.\r
957\r
958 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
959 @param[in] Length The size in bytes of the memory region.\r
960 @param[in] Attributes The bit mask of attributes to set for the memory region.\r
961 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.\r
962\r
963 @retval EFI_SUCCESS The attributes were set for the memory region.\r
964 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
965 BaseAddress and Length cannot be modified.\r
966 @retval EFI_INVALID_PARAMETER Length is zero.\r
967 Attributes specified an illegal combination of attributes that\r
968 cannot be set together.\r
969 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
970 the memory resource range.\r
971 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
972 resource range specified by BaseAddress and Length.\r
973 The bit mask of attributes is not support for the memory resource\r
974 range specified by BaseAddress and Length.\r
975\r
976**/\r
977EFI_STATUS\r
978EFIAPI\r
979SmmSetMemoryAttributesEx (\r
980 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
981 IN UINT64 Length,\r
982 IN UINT64 Attributes,\r
983 OUT BOOLEAN *IsSplitted OPTIONAL\r
984 );\r
985\r
986/**\r
987 This function clears the attributes for the memory region specified by BaseAddress and\r
988 Length from their current attributes to the attributes specified by Attributes.\r
989\r
990 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
991 @param[in] Length The size in bytes of the memory region.\r
992 @param[in] Attributes The bit mask of attributes to clear for the memory region.\r
993 @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.\r
994\r
995 @retval EFI_SUCCESS The attributes were cleared for the memory region.\r
996 @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r
997 BaseAddress and Length cannot be modified.\r
998 @retval EFI_INVALID_PARAMETER Length is zero.\r
999 Attributes specified an illegal combination of attributes that\r
1000 cannot be set together.\r
1001 @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
1002 the memory resource range.\r
1003 @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r
1004 resource range specified by BaseAddress and Length.\r
1005 The bit mask of attributes is not support for the memory resource\r
1006 range specified by BaseAddress and Length.\r
1007\r
1008**/\r
1009EFI_STATUS\r
1010EFIAPI\r
1011SmmClearMemoryAttributesEx (\r
1012 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1013 IN UINT64 Length,\r
1014 IN UINT64 Attributes,\r
1015 OUT BOOLEAN *IsSplitted OPTIONAL\r
1016 );\r
1017\r
21c17193
JY
1018/**\r
1019 This API provides a way to allocate memory for page table.\r
1020\r
1021 This API can be called more once to allocate memory for page tables.\r
1022\r
1023 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
1024 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
1025 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
1026 returned.\r
1027\r
1028 @param Pages The number of 4 KB pages to allocate.\r
1029\r
1030 @return A pointer to the allocated buffer or NULL if allocation fails.\r
1031\r
1032**/\r
1033VOID *\r
1034AllocatePageTableMemory (\r
1035 IN UINTN Pages\r
1036 );\r
1037\r
717fb604
JY
1038/**\r
1039 Allocate pages for code.\r
1040\r
1041 @param[in] Pages Number of pages to be allocated.\r
1042\r
1043 @return Allocated memory.\r
1044**/\r
1045VOID *\r
1046AllocateCodePages (\r
1047 IN UINTN Pages\r
1048 );\r
1049\r
1050/**\r
1051 Allocate aligned pages for code.\r
1052\r
1053 @param[in] Pages Number of pages to be allocated.\r
1054 @param[in] Alignment The requested alignment of the allocation.\r
1055 Must be a power of two.\r
1056 If Alignment is zero, then byte alignment is used.\r
1057\r
1058 @return Allocated memory.\r
1059**/\r
1060VOID *\r
1061AllocateAlignedCodePages (\r
1062 IN UINTN Pages,\r
1063 IN UINTN Alignment\r
1064 );\r
1065\r
0bdc9e75
SZ
1066\r
1067//\r
1068// S3 related global variable and function prototype.\r
1069//\r
1070\r
1071extern BOOLEAN mSmmS3Flag;\r
1072\r
1073/**\r
1074 Initialize SMM S3 resume state structure used during S3 Resume.\r
1075\r
1076 @param[in] Cr3 The base address of the page tables to use in SMM.\r
1077\r
1078**/\r
1079VOID\r
1080InitSmmS3ResumeState (\r
1081 IN UINT32 Cr3\r
1082 );\r
1083\r
1084/**\r
1085 Get ACPI CPU data.\r
1086\r
1087**/\r
1088VOID\r
1089GetAcpiCpuData (\r
1090 VOID\r
1091 );\r
1092\r
1093/**\r
1094 Restore SMM Configuration in S3 boot path.\r
1095\r
1096**/\r
1097VOID\r
1098RestoreSmmConfigurationInS3 (\r
1099 VOID\r
1100 );\r
1101\r
b10d5ddc
SZ
1102/**\r
1103 Get ACPI S3 enable flag.\r
1104\r
1105**/\r
1106VOID\r
1107GetAcpiS3EnableFlag (\r
1108 VOID\r
1109 );\r
1110\r
4a0f88dd
JF
1111/**\r
1112 Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.\r
1113\r
672b80c8
MK
1114 @param[in] ApHltLoopCode The address of the safe hlt-loop function.\r
1115 @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.\r
1116 @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.\r
4a0f88dd
JF
1117\r
1118**/\r
1119VOID\r
1120TransferApToSafeState (\r
672b80c8
MK
1121 IN UINTN ApHltLoopCode,\r
1122 IN UINTN TopOfStack,\r
1123 IN UINTN NumberToFinishAddress\r
4a0f88dd
JF
1124 );\r
1125\r
3eb69b08
JY
1126/**\r
1127 Set ShadowStack memory.\r
1128\r
1129 @param[in] Cr3 The page table base address.\r
1130 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
1131 @param[in] Length The size in bytes of the memory region.\r
1132\r
1133 @retval EFI_SUCCESS The shadow stack memory is set.\r
1134**/\r
1135EFI_STATUS\r
1136SetShadowStack (\r
1137 IN UINTN Cr3,\r
1138 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1139 IN UINT64 Length\r
1140 );\r
1141\r
1142/**\r
1143 Set not present memory.\r
1144\r
1145 @param[in] Cr3 The page table base address.\r
1146 @param[in] BaseAddress The physical address that is the start address of a memory region.\r
1147 @param[in] Length The size in bytes of the memory region.\r
1148\r
1149 @retval EFI_SUCCESS The not present memory is set.\r
1150**/\r
1151EFI_STATUS\r
1152SetNotPresentPage (\r
1153 IN UINTN Cr3,\r
1154 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1155 IN UINT64 Length\r
1156 );\r
1157\r
1158/**\r
1159 Initialize the shadow stack related data structure.\r
1160\r
1161 @param CpuIndex The index of CPU.\r
1162 @param ShadowStack The bottom of the shadow stack for this CPU.\r
1163**/\r
1164VOID\r
1165InitShadowStack (\r
1166 IN UINTN CpuIndex,\r
1167 IN VOID *ShadowStack\r
1168 );\r
1169\r
827330cc
JW
1170/**\r
1171 This function set given attributes of the memory region specified by\r
1172 BaseAddress and Length.\r
1173\r
1174 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r
1175 @param BaseAddress The physical address that is the start address of\r
1176 a memory region.\r
1177 @param Length The size in bytes of the memory region.\r
1178 @param Attributes The bit mask of attributes to set for the memory\r
1179 region.\r
1180\r
1181 @retval EFI_SUCCESS The attributes were set for the memory region.\r
1182 @retval EFI_INVALID_PARAMETER Length is zero.\r
1183 Attributes specified an illegal combination of\r
1184 attributes that cannot be set together.\r
1185 @retval EFI_UNSUPPORTED The processor does not support one or more\r
1186 bytes of the memory resource range specified\r
1187 by BaseAddress and Length.\r
aae02dcc 1188 The bit mask of attributes is not supported for\r
827330cc
JW
1189 the memory resource range specified by\r
1190 BaseAddress and Length.\r
1191\r
1192**/\r
1193EFI_STATUS\r
1194EFIAPI\r
1195EdkiiSmmSetMemoryAttributes (\r
1196 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r
1197 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1198 IN UINT64 Length,\r
1199 IN UINT64 Attributes\r
1200 );\r
1201\r
1202/**\r
1203 This function clears given attributes of the memory region specified by\r
1204 BaseAddress and Length.\r
1205\r
1206 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r
1207 @param BaseAddress The physical address that is the start address of\r
1208 a memory region.\r
1209 @param Length The size in bytes of the memory region.\r
aae02dcc 1210 @param Attributes The bit mask of attributes to clear for the memory\r
827330cc
JW
1211 region.\r
1212\r
aae02dcc 1213 @retval EFI_SUCCESS The attributes were cleared for the memory region.\r
827330cc
JW
1214 @retval EFI_INVALID_PARAMETER Length is zero.\r
1215 Attributes specified an illegal combination of\r
aae02dcc 1216 attributes that cannot be cleared together.\r
827330cc
JW
1217 @retval EFI_UNSUPPORTED The processor does not support one or more\r
1218 bytes of the memory resource range specified\r
1219 by BaseAddress and Length.\r
aae02dcc 1220 The bit mask of attributes is not supported for\r
827330cc
JW
1221 the memory resource range specified by\r
1222 BaseAddress and Length.\r
1223\r
1224**/\r
1225EFI_STATUS\r
1226EFIAPI\r
1227EdkiiSmmClearMemoryAttributes (\r
1228 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r
1229 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1230 IN UINT64 Length,\r
1231 IN UINT64 Attributes\r
1232 );\r
1233\r
1234/**\r
aae02dcc 1235 This function retrieves the attributes of the memory region specified by\r
827330cc
JW
1236 BaseAddress and Length. If different attributes are got from different part\r
1237 of the memory region, EFI_NO_MAPPING will be returned.\r
1238\r
1239 @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r
1240 @param BaseAddress The physical address that is the start address of\r
1241 a memory region.\r
1242 @param Length The size in bytes of the memory region.\r
1243 @param Attributes Pointer to attributes returned.\r
1244\r
1245 @retval EFI_SUCCESS The attributes got for the memory region.\r
1246 @retval EFI_INVALID_PARAMETER Length is zero.\r
1247 Attributes is NULL.\r
1248 @retval EFI_NO_MAPPING Attributes are not consistent cross the memory\r
1249 region.\r
1250 @retval EFI_UNSUPPORTED The processor does not support one or more\r
1251 bytes of the memory resource range specified\r
1252 by BaseAddress and Length.\r
827330cc
JW
1253\r
1254**/\r
1255EFI_STATUS\r
1256EFIAPI\r
1257EdkiiSmmGetMemoryAttributes (\r
1258 IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r
1259 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
1260 IN UINT64 Length,\r
1261 IN UINT64 *Attributes\r
1262 );\r
1263\r
e21e355e
LG
1264/**\r
1265 This function fixes up the address of the global variable or function\r
ef62da4f 1266 referred in SmmInit assembly files to be the absolute address.\r
e21e355e
LG
1267**/\r
1268VOID\r
1269EFIAPI\r
1270PiSmmCpuSmmInitFixupAddress (\r
1271 );\r
1272\r
1273/**\r
1274 This function fixes up the address of the global variable or function\r
ef62da4f 1275 referred in SmiEntry assembly files to be the absolute address.\r
e21e355e
LG
1276**/\r
1277VOID\r
1278EFIAPI\r
1279PiSmmCpuSmiEntryFixupAddress (\r
1280 );\r
1281\r
37f9fea5
VN
1282/**\r
1283 This function reads CR2 register when on-demand paging is enabled\r
1284 for 64 bit and no action for 32 bit.\r
1285\r
1286 @param[out] *Cr2 Pointer to variable to hold CR2 register value.\r
1287**/\r
1288VOID\r
1289SaveCr2 (\r
1290 OUT UINTN *Cr2\r
1291 );\r
1292\r
1293/**\r
1294 This function writes into CR2 register when on-demand paging is enabled\r
1295 for 64 bit and no action for 32 bit.\r
1296\r
1297 @param[in] Cr2 Value to write into CR2 register.\r
1298**/\r
1299VOID\r
1300RestoreCr2 (\r
1301 IN UINTN Cr2\r
1302 );\r
1303\r
51dd408a
ED
1304/**\r
1305 Schedule a procedure to run on the specified CPU.\r
1306\r
1307 @param[in] Procedure The address of the procedure to run\r
1308 @param[in] CpuIndex Target CPU Index\r
1309 @param[in,out] ProcArguments The parameter to pass to the procedure\r
1310 @param[in,out] Token This is an optional parameter that allows the caller to execute the\r
1311 procedure in a blocking or non-blocking fashion. If it is NULL the\r
1312 call is blocking, and the call will not return until the AP has\r
1313 completed the procedure. If the token is not NULL, the call will\r
1314 return immediately. The caller can check whether the procedure has\r
1315 completed with CheckOnProcedure or WaitForProcedure.\r
1316 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for the APs to finish\r
1317 execution of Procedure, either for blocking or non-blocking mode.\r
1318 Zero means infinity. If the timeout expires before all APs return\r
1319 from Procedure, then Procedure on the failed APs is terminated. If\r
1320 the timeout expires in blocking mode, the call returns EFI_TIMEOUT.\r
1321 If the timeout expires in non-blocking mode, the timeout determined\r
1322 can be through CheckOnProcedure or WaitForProcedure.\r
1323 Note that timeout support is optional. Whether an implementation\r
1324 supports this feature can be determined via the Attributes data\r
1325 member.\r
073f2ced 1326 @param[in,out] CpuStatus This optional pointer may be used to get the status code returned\r
51dd408a
ED
1327 by Procedure when it completes execution on the target AP, or with\r
1328 EFI_TIMEOUT if the Procedure fails to complete within the optional\r
1329 timeout. The implementation will update this variable with\r
1330 EFI_NOT_READY prior to starting Procedure on the target AP.\r
1331\r
1332 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
1333 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
1334 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
1335 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
1336 @retval EFI_SUCCESS The procedure has been successfully scheduled\r
1337\r
1338**/\r
1339EFI_STATUS\r
1340InternalSmmStartupThisAp (\r
1341 IN EFI_AP_PROCEDURE2 Procedure,\r
1342 IN UINTN CpuIndex,\r
1343 IN OUT VOID *ProcArguments OPTIONAL,\r
5ed4c46f 1344 IN OUT MM_COMPLETION *Token,\r
51dd408a
ED
1345 IN UINTN TimeoutInMicroseconds,\r
1346 IN OUT EFI_STATUS *CpuStatus\r
1347 );\r
1348\r
1349/**\r
1350 Checks whether the input token is the current used token.\r
1351\r
1352 @param[in] Token This parameter describes the token that was passed into DispatchProcedure or\r
1353 BroadcastProcedure.\r
1354\r
1355 @retval TRUE The input token is the current used token.\r
1356 @retval FALSE The input token is not the current used token.\r
1357**/\r
1358BOOLEAN\r
1359IsTokenInUse (\r
1360 IN SPIN_LOCK *Token\r
1361 );\r
1362\r
1363/**\r
1364 Checks status of specified AP.\r
1365\r
1366 This function checks whether the specified AP has finished the task assigned\r
1367 by StartupThisAP(), and whether timeout expires.\r
1368\r
1369 @param[in] Token This parameter describes the token that was passed into DispatchProcedure or\r
1370 BroadcastProcedure.\r
1371\r
1372 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().\r
1373 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.\r
1374**/\r
1375EFI_STATUS\r
1376IsApReady (\r
1377 IN SPIN_LOCK *Token\r
1378 );\r
1379\r
1380/**\r
1381 Check whether it is an present AP.\r
1382\r
1383 @param CpuIndex The AP index which calls this function.\r
1384\r
1385 @retval TRUE It's a present AP.\r
1386 @retval TRUE This is not an AP or it is not present.\r
1387\r
1388**/\r
1389BOOLEAN\r
1390IsPresentAp (\r
1391 IN UINTN CpuIndex\r
1392 );\r
1393\r
1394/**\r
1395 Worker function to execute a caller provided function on all enabled APs.\r
1396\r
1397 @param[in] Procedure A pointer to the function to be run on\r
1398 enabled APs of the system.\r
1399 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
1400 APs to return from Procedure, either for\r
1401 blocking or non-blocking mode.\r
5ed4c46f 1402 @param[in,out] ProcedureArguments The parameter passed into Procedure for\r
51dd408a
ED
1403 all APs.\r
1404 @param[in,out] Token This is an optional parameter that allows the caller to execute the\r
1405 procedure in a blocking or non-blocking fashion. If it is NULL the\r
1406 call is blocking, and the call will not return until the AP has\r
1407 completed the procedure. If the token is not NULL, the call will\r
1408 return immediately. The caller can check whether the procedure has\r
1409 completed with CheckOnProcedure or WaitForProcedure.\r
1410 @param[in,out] CPUStatus This optional pointer may be used to get the status code returned\r
1411 by Procedure when it completes execution on the target AP, or with\r
1412 EFI_TIMEOUT if the Procedure fails to complete within the optional\r
1413 timeout. The implementation will update this variable with\r
1414 EFI_NOT_READY prior to starting Procedure on the target AP.\r
1415\r
1416 @retval EFI_SUCCESS In blocking mode, all APs have finished before\r
1417 the timeout expired.\r
1418 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r
1419 to all enabled APs.\r
1420 @retval others Failed to Startup all APs.\r
1421\r
1422**/\r
1423EFI_STATUS\r
1424InternalSmmStartupAllAPs (\r
1425 IN EFI_AP_PROCEDURE2 Procedure,\r
1426 IN UINTN TimeoutInMicroseconds,\r
1427 IN OUT VOID *ProcedureArguments OPTIONAL,\r
1428 IN OUT MM_COMPLETION *Token,\r
1429 IN OUT EFI_STATUS *CPUStatus\r
1430 );\r
1431\r
1432/**\r
1433\r
1434 Register the SMM Foundation entry point.\r
1435\r
1436 @param[in] Procedure A pointer to the code stream to be run on the designated target AP\r
1437 of the system. Type EFI_AP_PROCEDURE is defined below in Volume 2\r
1438 with the related definitions of\r
1439 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs.\r
1440 If caller may pass a value of NULL to deregister any existing\r
1441 startup procedure.\r
1442 @param[in,out] ProcedureArguments Allows the caller to pass a list of parameters to the code that is\r
1443 run by the AP. It is an optional common mailbox between APs and\r
1444 the caller to share information\r
1445\r
1446 @retval EFI_SUCCESS The Procedure has been set successfully.\r
1447 @retval EFI_INVALID_PARAMETER The Procedure is NULL but ProcedureArguments not NULL.\r
1448\r
1449**/\r
1450EFI_STATUS\r
1451RegisterStartupProcedure (\r
073f2ced
SZ
1452 IN EFI_AP_PROCEDURE Procedure,\r
1453 IN OUT VOID *ProcedureArguments OPTIONAL\r
51dd408a
ED
1454 );\r
1455\r
1456/**\r
1457 Allocate buffer for SpinLock and Wrapper function buffer.\r
1458\r
1459**/\r
1460VOID\r
1461InitializeDataForMmMp (\r
1462 VOID\r
1463 );\r
1464\r
79186ddc
RN
1465/**\r
1466 Return whether access to non-SMRAM is restricted.\r
1467\r
1468 @retval TRUE Access to non-SMRAM is restricted.\r
1469 @retval FALSE Access to non-SMRAM is not restricted.\r
9c33f16f 1470**/\r
79186ddc
RN
1471BOOLEAN\r
1472IsRestrictedMemoryAccess (\r
1473 VOID\r
1474 );\r
1475\r
529a5a86 1476#endif\r