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