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