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