]>
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 | |
529a5a86 MK |
298 | extern CONST UINT8 gcSmmInitTemplate[];\r |
299 | extern CONST UINT16 gcSmmInitSize;\r | |
f0053e83 LE |
300 | X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0;\r |
301 | extern UINT32 mSmmCr0;\r | |
6b0841c1 | 302 | X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3;\r |
351b49c1 LE |
303 | extern UINT32 mSmmCr4;\r |
304 | X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4;\r | |
5830d2c3 | 305 | X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack;\r |
529a5a86 MK |
306 | \r |
307 | /**\r | |
308 | Semaphore operation for all processor relocate SMMBase.\r | |
309 | **/\r | |
310 | VOID\r | |
311 | EFIAPI\r | |
312 | SmmRelocationSemaphoreComplete (\r | |
313 | VOID\r | |
314 | );\r | |
315 | \r | |
316 | ///\r | |
317 | /// The type of SMM CPU Information\r | |
318 | ///\r | |
319 | typedef struct {\r | |
ed3d5ecb | 320 | SPIN_LOCK *Busy;\r |
529a5a86 MK |
321 | volatile EFI_AP_PROCEDURE Procedure;\r |
322 | volatile VOID *Parameter;\r | |
ed3d5ecb JF |
323 | volatile UINT32 *Run;\r |
324 | volatile BOOLEAN *Present;\r | |
529a5a86 MK |
325 | } SMM_CPU_DATA_BLOCK;\r |
326 | \r | |
327 | typedef enum {\r | |
328 | SmmCpuSyncModeTradition,\r | |
329 | SmmCpuSyncModeRelaxedAp,\r | |
330 | SmmCpuSyncModeMax\r | |
331 | } SMM_CPU_SYNC_MODE;\r | |
332 | \r | |
333 | typedef struct {\r | |
334 | //\r | |
335 | // Pointer to an array. The array should be located immediately after this structure\r | |
336 | // so that UC cache-ability can be set together.\r | |
337 | //\r | |
338 | SMM_CPU_DATA_BLOCK *CpuData;\r | |
fe3a75bc | 339 | volatile UINT32 *Counter;\r |
529a5a86 | 340 | volatile UINT32 BspIndex;\r |
fe3a75bc JF |
341 | volatile BOOLEAN *InsideSmm;\r |
342 | volatile BOOLEAN *AllCpusInSync;\r | |
529a5a86 MK |
343 | volatile SMM_CPU_SYNC_MODE EffectiveSyncMode;\r |
344 | volatile BOOLEAN SwitchBsp;\r | |
345 | volatile BOOLEAN *CandidateBsp;\r | |
346 | } SMM_DISPATCHER_MP_SYNC_DATA;\r | |
347 | \r | |
695e62d1 JF |
348 | #define MSR_SPIN_LOCK_INIT_NUM 15\r |
349 | \r | |
529a5a86 | 350 | typedef struct {\r |
dc99315b | 351 | SPIN_LOCK *SpinLock;\r |
529a5a86 MK |
352 | UINT32 MsrIndex;\r |
353 | } MP_MSR_LOCK;\r | |
354 | \r | |
355 | #define SMM_PSD_OFFSET 0xfb00\r | |
356 | \r | |
1d648531 JF |
357 | ///\r |
358 | /// All global semaphores' pointer\r | |
359 | ///\r | |
360 | typedef struct {\r | |
361 | volatile UINT32 *Counter;\r | |
362 | volatile BOOLEAN *InsideSmm;\r | |
363 | volatile BOOLEAN *AllCpusInSync;\r | |
364 | SPIN_LOCK *PFLock;\r | |
365 | SPIN_LOCK *CodeAccessCheckLock;\r | |
6c4c15fa | 366 | SPIN_LOCK *MemoryMappedLock;\r |
1d648531 JF |
367 | } SMM_CPU_SEMAPHORE_GLOBAL;\r |
368 | \r | |
4e920581 JF |
369 | ///\r |
370 | /// All semaphores for each processor\r | |
371 | ///\r | |
372 | typedef struct {\r | |
373 | SPIN_LOCK *Busy;\r | |
374 | volatile UINT32 *Run;\r | |
375 | volatile BOOLEAN *Present;\r | |
376 | } SMM_CPU_SEMAPHORE_CPU;\r | |
377 | \r | |
695e62d1 JF |
378 | ///\r |
379 | /// All MSRs semaphores' pointer and counter\r | |
380 | ///\r | |
381 | typedef struct {\r | |
382 | SPIN_LOCK *Msr;\r | |
383 | UINTN AvailableCounter;\r | |
384 | } SMM_CPU_SEMAPHORE_MSR;\r | |
4e920581 | 385 | \r |
1d648531 JF |
386 | ///\r |
387 | /// All semaphores' information\r | |
388 | ///\r | |
389 | typedef struct {\r | |
390 | SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal;\r | |
4e920581 | 391 | SMM_CPU_SEMAPHORE_CPU SemaphoreCpu;\r |
695e62d1 | 392 | SMM_CPU_SEMAPHORE_MSR SemaphoreMsr;\r |
1d648531 JF |
393 | } SMM_CPU_SEMAPHORES;\r |
394 | \r | |
529a5a86 | 395 | extern IA32_DESCRIPTOR gcSmiGdtr;\r |
717fb604 JY |
396 | extern EFI_PHYSICAL_ADDRESS mGdtBuffer;\r |
397 | extern UINTN mGdtBufferSize;\r | |
529a5a86 MK |
398 | extern IA32_DESCRIPTOR gcSmiIdtr;\r |
399 | extern VOID *gcSmiIdtrPtr;\r | |
529a5a86 | 400 | extern UINT64 gPhyMask;\r |
529a5a86 | 401 | extern SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData;\r |
529a5a86 MK |
402 | extern UINTN mSmmStackArrayBase;\r |
403 | extern UINTN mSmmStackArrayEnd;\r | |
404 | extern UINTN mSmmStackSize;\r | |
405 | extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;\r | |
406 | extern IA32_DESCRIPTOR gcSmiInitGdtr;\r | |
dc99315b JF |
407 | extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores;\r |
408 | extern UINTN mSemaphoreSize;\r | |
fe3a75bc JF |
409 | extern SPIN_LOCK *mPFLock;\r |
410 | extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;\r | |
6c4c15fa | 411 | extern SPIN_LOCK *mMemoryMappedLock;\r |
7ed6f781 JF |
412 | extern EFI_SMRAM_DESCRIPTOR *mSmmCpuSmramRanges;\r |
413 | extern UINTN mSmmCpuSmramRangeCount;\r | |
714c2603 | 414 | extern UINT8 mPhysicalAddressBits;\r |
529a5a86 | 415 | \r |
241f9149 LD |
416 | //\r |
417 | // Copy of the PcdPteMemoryEncryptionAddressOrMask\r | |
418 | //\r | |
419 | extern UINT64 mAddressEncMask;\r | |
420 | \r | |
529a5a86 MK |
421 | /**\r |
422 | Create 4G PageTable in SMRAM.\r | |
423 | \r | |
717fb604 | 424 | @param[in] Is32BitPageTable Whether the page table is 32-bit PAE\r |
529a5a86 MK |
425 | @return PageTable Address\r |
426 | \r | |
427 | **/\r | |
428 | UINT32\r | |
429 | Gen4GPageTable (\r | |
881520ea | 430 | IN BOOLEAN Is32BitPageTable\r |
529a5a86 MK |
431 | );\r |
432 | \r | |
433 | \r | |
434 | /**\r | |
435 | Initialize global data for MP synchronization.\r | |
436 | \r | |
437 | @param Stacks Base address of SMI stack buffer for all processors.\r | |
438 | @param StackSize Stack size for each processor in SMM.\r | |
439 | \r | |
440 | **/\r | |
441 | UINT32\r | |
442 | InitializeMpServiceData (\r | |
443 | IN VOID *Stacks,\r | |
444 | IN UINTN StackSize\r | |
445 | );\r | |
446 | \r | |
447 | /**\r | |
448 | Initialize Timer for SMM AP Sync.\r | |
449 | \r | |
450 | **/\r | |
451 | VOID\r | |
452 | InitializeSmmTimer (\r | |
453 | VOID\r | |
454 | );\r | |
455 | \r | |
456 | /**\r | |
457 | Start Timer for SMM AP Sync.\r | |
458 | \r | |
459 | **/\r | |
460 | UINT64\r | |
461 | EFIAPI\r | |
462 | StartSyncTimer (\r | |
463 | VOID\r | |
464 | );\r | |
465 | \r | |
466 | /**\r | |
467 | Check if the SMM AP Sync timer is timeout.\r | |
468 | \r | |
469 | @param Timer The start timer from the begin.\r | |
470 | \r | |
471 | **/\r | |
472 | BOOLEAN\r | |
473 | EFIAPI\r | |
474 | IsSyncTimerTimeout (\r | |
475 | IN UINT64 Timer\r | |
476 | );\r | |
477 | \r | |
478 | /**\r | |
479 | Initialize IDT for SMM Stack Guard.\r | |
480 | \r | |
481 | **/\r | |
482 | VOID\r | |
483 | EFIAPI\r | |
484 | InitializeIDTSmmStackGuard (\r | |
485 | VOID\r | |
486 | );\r | |
487 | \r | |
fe5f1949 JY |
488 | /**\r |
489 | Initialize Gdt for all processors.\r | |
717fb604 | 490 | \r |
fe5f1949 JY |
491 | @param[in] Cr3 CR3 value.\r |
492 | @param[out] GdtStepSize The step size for GDT table.\r | |
493 | \r | |
494 | @return GdtBase for processor 0.\r | |
495 | GdtBase for processor X is: GdtBase + (GdtStepSize * X)\r | |
496 | **/\r | |
497 | VOID *\r | |
498 | InitGdt (\r | |
499 | IN UINTN Cr3,\r | |
500 | OUT UINTN *GdtStepSize\r | |
501 | );\r | |
502 | \r | |
529a5a86 MK |
503 | /**\r |
504 | \r | |
505 | Register the SMM Foundation entry point.\r | |
506 | \r | |
507 | @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance\r | |
508 | @param SmmEntryPoint SMM Foundation EntryPoint\r | |
509 | \r | |
510 | @retval EFI_SUCCESS Successfully to register SMM foundation entry point\r | |
511 | \r | |
512 | **/\r | |
513 | EFI_STATUS\r | |
514 | EFIAPI\r | |
515 | RegisterSmmEntry (\r | |
516 | IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This,\r | |
517 | IN EFI_SMM_ENTRY_POINT SmmEntryPoint\r | |
518 | );\r | |
519 | \r | |
520 | /**\r | |
521 | Create PageTable for SMM use.\r | |
522 | \r | |
523 | @return PageTable Address\r | |
524 | \r | |
525 | **/\r | |
526 | UINT32\r | |
527 | SmmInitPageTable (\r | |
528 | VOID\r | |
529 | );\r | |
530 | \r | |
531 | /**\r | |
532 | Schedule a procedure to run on the specified CPU.\r | |
533 | \r | |
534 | @param Procedure The address of the procedure to run\r | |
535 | @param CpuIndex Target CPU number\r | |
536 | @param ProcArguments The parameter to pass to the procedure\r | |
537 | \r | |
538 | @retval EFI_INVALID_PARAMETER CpuNumber not valid\r | |
539 | @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r | |
540 | @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r | |
541 | @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r | |
542 | @retval EFI_SUCCESS - The procedure has been successfully scheduled\r | |
543 | \r | |
544 | **/\r | |
545 | EFI_STATUS\r | |
546 | EFIAPI\r | |
547 | SmmStartupThisAp (\r | |
548 | IN EFI_AP_PROCEDURE Procedure,\r | |
549 | IN UINTN CpuIndex,\r | |
550 | IN OUT VOID *ProcArguments OPTIONAL\r | |
551 | );\r | |
552 | \r | |
553 | /**\r | |
554 | Schedule a procedure to run on the specified CPU in a blocking fashion.\r | |
555 | \r | |
556 | @param Procedure The address of the procedure to run\r | |
557 | @param CpuIndex Target CPU Index\r | |
558 | @param ProcArguments The parameter to pass to the procedure\r | |
559 | \r | |
560 | @retval EFI_INVALID_PARAMETER CpuNumber not valid\r | |
561 | @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r | |
562 | @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r | |
563 | @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r | |
564 | @retval EFI_SUCCESS The procedure has been successfully scheduled\r | |
565 | \r | |
566 | **/\r | |
567 | EFI_STATUS\r | |
568 | EFIAPI\r | |
569 | SmmBlockingStartupThisAp (\r | |
570 | IN EFI_AP_PROCEDURE Procedure,\r | |
571 | IN UINTN CpuIndex,\r | |
572 | IN OUT VOID *ProcArguments OPTIONAL\r | |
573 | );\r | |
574 | \r | |
e4435f71 JY |
575 | /**\r |
576 | This function sets the attributes for the memory region specified by BaseAddress and\r | |
577 | Length from their current attributes to the attributes specified by Attributes.\r | |
578 | \r | |
579 | @param[in] BaseAddress The physical address that is the start address of a memory region.\r | |
580 | @param[in] Length The size in bytes of the memory region.\r | |
581 | @param[in] Attributes The bit mask of attributes to set for the memory region.\r | |
582 | \r | |
583 | @retval EFI_SUCCESS The attributes were set for the memory region.\r | |
584 | @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
585 | BaseAddress and Length cannot be modified.\r | |
586 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
587 | Attributes specified an illegal combination of attributes that\r | |
588 | cannot be set together.\r | |
589 | @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
590 | the memory resource range.\r | |
591 | @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r | |
592 | resource range specified by BaseAddress and Length.\r | |
593 | The bit mask of attributes is not support for the memory resource\r | |
594 | range specified by BaseAddress and Length.\r | |
595 | \r | |
596 | **/\r | |
597 | EFI_STATUS\r | |
598 | EFIAPI\r | |
599 | SmmSetMemoryAttributes (\r | |
600 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
601 | IN UINT64 Length,\r | |
602 | IN UINT64 Attributes\r | |
603 | );\r | |
604 | \r | |
605 | /**\r | |
606 | This function clears the attributes for the memory region specified by BaseAddress and\r | |
607 | Length from their current attributes to the attributes specified by Attributes.\r | |
608 | \r | |
609 | @param[in] BaseAddress The physical address that is the start address of a memory region.\r | |
610 | @param[in] Length The size in bytes of the memory region.\r | |
611 | @param[in] Attributes The bit mask of attributes to clear for the memory region.\r | |
612 | \r | |
613 | @retval EFI_SUCCESS The attributes were cleared for the memory region.\r | |
614 | @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
615 | BaseAddress and Length cannot be modified.\r | |
616 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
617 | Attributes specified an illegal combination of attributes that\r | |
618 | cannot be set together.\r | |
619 | @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
620 | the memory resource range.\r | |
621 | @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r | |
622 | resource range specified by BaseAddress and Length.\r | |
623 | The bit mask of attributes is not support for the memory resource\r | |
624 | range specified by BaseAddress and Length.\r | |
625 | \r | |
626 | **/\r | |
627 | EFI_STATUS\r | |
628 | EFIAPI\r | |
629 | SmmClearMemoryAttributes (\r | |
630 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
631 | IN UINT64 Length,\r | |
632 | IN UINT64 Attributes\r | |
633 | );\r | |
634 | \r | |
529a5a86 MK |
635 | /**\r |
636 | Initialize MP synchronization data.\r | |
637 | \r | |
638 | **/\r | |
639 | VOID\r | |
640 | EFIAPI\r | |
641 | InitializeMpSyncData (\r | |
642 | VOID\r | |
643 | );\r | |
644 | \r | |
645 | /**\r | |
646 | \r | |
647 | Find out SMRAM information including SMRR base and SMRR size.\r | |
648 | \r | |
649 | @param SmrrBase SMRR base\r | |
650 | @param SmrrSize SMRR size\r | |
651 | \r | |
652 | **/\r | |
653 | VOID\r | |
654 | FindSmramInfo (\r | |
655 | OUT UINT32 *SmrrBase,\r | |
656 | OUT UINT32 *SmrrSize\r | |
657 | );\r | |
658 | \r | |
659 | /**\r | |
0bdc9e75 | 660 | Relocate SmmBases for each processor.\r |
529a5a86 | 661 | \r |
0bdc9e75 | 662 | Execute on first boot and all S3 resumes\r |
529a5a86 MK |
663 | \r |
664 | **/\r | |
665 | VOID\r | |
0bdc9e75 SZ |
666 | EFIAPI\r |
667 | SmmRelocateBases (\r | |
529a5a86 MK |
668 | VOID\r |
669 | );\r | |
670 | \r | |
671 | /**\r | |
672 | Page Fault handler for SMM use.\r | |
673 | \r | |
674 | @param InterruptType Defines the type of interrupt or exception that\r | |
675 | occurred on the processor.This parameter is processor architecture specific.\r | |
676 | @param SystemContext A pointer to the processor context when\r | |
677 | the interrupt occurred on the processor.\r | |
678 | **/\r | |
679 | VOID\r | |
680 | EFIAPI\r | |
681 | SmiPFHandler (\r | |
b8caae19 JF |
682 | IN EFI_EXCEPTION_TYPE InterruptType,\r |
683 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
529a5a86 MK |
684 | );\r |
685 | \r | |
686 | /**\r | |
687 | Perform the remaining tasks.\r | |
688 | \r | |
689 | **/\r | |
690 | VOID\r | |
691 | PerformRemainingTasks (\r | |
692 | VOID\r | |
693 | );\r | |
694 | \r | |
9f419739 JY |
695 | /**\r |
696 | Perform the pre tasks.\r | |
697 | \r | |
698 | **/\r | |
699 | VOID\r | |
700 | PerformPreTasks (\r | |
701 | VOID\r | |
702 | );\r | |
703 | \r | |
529a5a86 MK |
704 | /**\r |
705 | Initialize MSR spin lock by MSR index.\r | |
706 | \r | |
707 | @param MsrIndex MSR index value.\r | |
708 | \r | |
709 | **/\r | |
710 | VOID\r | |
711 | InitMsrSpinLockByIndex (\r | |
712 | IN UINT32 MsrIndex\r | |
713 | );\r | |
714 | \r | |
715 | /**\r | |
716 | Hook return address of SMM Save State so that semaphore code\r | |
717 | can be executed immediately after AP exits SMM to indicate to\r | |
718 | the BSP that an AP has exited SMM after SMBASE relocation.\r | |
719 | \r | |
720 | @param[in] CpuIndex The processor index.\r | |
721 | @param[in] RebasedFlag A pointer to a flag that is set to TRUE\r | |
722 | immediately after AP exits SMM.\r | |
723 | \r | |
724 | **/\r | |
725 | VOID\r | |
726 | SemaphoreHook (\r | |
727 | IN UINTN CpuIndex,\r | |
728 | IN volatile BOOLEAN *RebasedFlag\r | |
729 | );\r | |
730 | \r | |
731 | /**\r | |
732 | Configure SMM Code Access Check feature for all processors.\r | |
733 | SMM Feature Control MSR will be locked after configuration.\r | |
734 | **/\r | |
735 | VOID\r | |
736 | ConfigSmmCodeAccessCheck (\r | |
737 | VOID\r | |
738 | );\r | |
739 | \r | |
740 | /**\r | |
741 | Hook the code executed immediately after an RSM instruction on the currently\r | |
742 | executing CPU. The mode of code executed immediately after RSM must be\r | |
743 | detected, and the appropriate hook must be selected. Always clear the auto\r | |
744 | HALT restart flag if it is set.\r | |
745 | \r | |
746 | @param[in] CpuIndex The processor index for the currently\r | |
747 | executing CPU.\r | |
748 | @param[in] CpuState Pointer to SMRAM Save State Map for the\r | |
749 | currently executing CPU.\r | |
750 | @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r | |
751 | 32-bit mode from 64-bit SMM.\r | |
752 | @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r | |
753 | same mode as SMM.\r | |
754 | \r | |
755 | @retval The value of the original instruction pointer before it was hooked.\r | |
756 | \r | |
757 | **/\r | |
758 | UINT64\r | |
759 | EFIAPI\r | |
760 | HookReturnFromSmm (\r | |
761 | IN UINTN CpuIndex,\r | |
762 | SMRAM_SAVE_STATE_MAP *CpuState,\r | |
763 | UINT64 NewInstructionPointer32,\r | |
764 | UINT64 NewInstructionPointer\r | |
765 | );\r | |
766 | \r | |
767 | /**\r | |
768 | Get the size of the SMI Handler in bytes.\r | |
769 | \r | |
770 | @retval The size, in bytes, of the SMI Handler.\r | |
771 | \r | |
772 | **/\r | |
773 | UINTN\r | |
774 | EFIAPI\r | |
775 | GetSmiHandlerSize (\r | |
776 | VOID\r | |
777 | );\r | |
778 | \r | |
779 | /**\r | |
780 | Install the SMI handler for the CPU specified by CpuIndex. This function\r | |
781 | is called by the CPU that was elected as monarch during System Management\r | |
782 | Mode initialization.\r | |
783 | \r | |
784 | @param[in] CpuIndex The index of the CPU to install the custom SMI handler.\r | |
785 | The value must be between 0 and the NumberOfCpus field\r | |
786 | in the System Management System Table (SMST).\r | |
787 | @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.\r | |
788 | @param[in] SmiStack The stack to use when an SMI is processed by the\r | |
789 | the CPU specified by CpuIndex.\r | |
790 | @param[in] StackSize The size, in bytes, if the stack used when an SMI is\r | |
791 | processed by the CPU specified by CpuIndex.\r | |
792 | @param[in] GdtBase The base address of the GDT to use when an SMI is\r | |
793 | processed by the CPU specified by CpuIndex.\r | |
794 | @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is\r | |
795 | processed by the CPU specified by CpuIndex.\r | |
796 | @param[in] IdtBase The base address of the IDT to use when an SMI is\r | |
797 | processed by the CPU specified by CpuIndex.\r | |
798 | @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is\r | |
799 | processed by the CPU specified by CpuIndex.\r | |
800 | @param[in] Cr3 The base address of the page tables to use when an SMI\r | |
801 | is processed by the CPU specified by CpuIndex.\r | |
802 | **/\r | |
803 | VOID\r | |
804 | EFIAPI\r | |
805 | InstallSmiHandler (\r | |
806 | IN UINTN CpuIndex,\r | |
807 | IN UINT32 SmBase,\r | |
808 | IN VOID *SmiStack,\r | |
809 | IN UINTN StackSize,\r | |
810 | IN UINTN GdtBase,\r | |
811 | IN UINTN GdtSize,\r | |
812 | IN UINTN IdtBase,\r | |
813 | IN UINTN IdtSize,\r | |
814 | IN UINT32 Cr3\r | |
815 | );\r | |
816 | \r | |
817 | /**\r | |
818 | Search module name by input IP address and output it.\r | |
819 | \r | |
820 | @param CallerIpAddress Caller instruction pointer.\r | |
821 | \r | |
822 | **/\r | |
823 | VOID\r | |
824 | DumpModuleInfoByIp (\r | |
825 | IN UINTN CallerIpAddress\r | |
826 | );\r | |
21c17193 | 827 | \r |
717fb604 JY |
828 | /**\r |
829 | This function sets memory attribute according to MemoryAttributesTable.\r | |
830 | **/\r | |
831 | VOID\r | |
832 | SetMemMapAttributes (\r | |
833 | VOID\r | |
834 | );\r | |
835 | \r | |
d2fc7711 JY |
836 | /**\r |
837 | This function sets UEFI memory attribute according to UEFI memory map.\r | |
838 | **/\r | |
839 | VOID\r | |
840 | SetUefiMemMapAttributes (\r | |
841 | VOID\r | |
842 | );\r | |
843 | \r | |
844 | /**\r | |
845 | Return if the Address is forbidden as SMM communication buffer.\r | |
846 | \r | |
847 | @param[in] Address the address to be checked\r | |
848 | \r | |
849 | @return TRUE The address is forbidden as SMM communication buffer.\r | |
850 | @return FALSE The address is allowed as SMM communication buffer.\r | |
851 | **/\r | |
852 | BOOLEAN\r | |
853 | IsSmmCommBufferForbiddenAddress (\r | |
854 | IN UINT64 Address\r | |
855 | );\r | |
856 | \r | |
857 | /**\r | |
858 | This function caches the UEFI memory map information.\r | |
859 | **/\r | |
860 | VOID\r | |
861 | GetUefiMemoryMap (\r | |
862 | VOID\r | |
863 | );\r | |
864 | \r | |
717fb604 JY |
865 | /**\r |
866 | This function sets memory attribute for page table.\r | |
867 | **/\r | |
868 | VOID\r | |
869 | SetPageTableAttributes (\r | |
870 | VOID\r | |
871 | );\r | |
872 | \r | |
873 | /**\r | |
874 | Return page table base.\r | |
875 | \r | |
876 | @return page table base.\r | |
877 | **/\r | |
878 | UINTN\r | |
879 | GetPageTableBase (\r | |
880 | VOID\r | |
881 | );\r | |
882 | \r | |
883 | /**\r | |
884 | This function sets the attributes for the memory region specified by BaseAddress and\r | |
885 | Length from their current attributes to the attributes specified by Attributes.\r | |
886 | \r | |
887 | @param[in] BaseAddress The physical address that is the start address of a memory region.\r | |
888 | @param[in] Length The size in bytes of the memory region.\r | |
889 | @param[in] Attributes The bit mask of attributes to set for the memory region.\r | |
890 | @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.\r | |
891 | \r | |
892 | @retval EFI_SUCCESS The attributes were set for the memory region.\r | |
893 | @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
894 | BaseAddress and Length cannot be modified.\r | |
895 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
896 | Attributes specified an illegal combination of attributes that\r | |
897 | cannot be set together.\r | |
898 | @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
899 | the memory resource range.\r | |
900 | @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r | |
901 | resource range specified by BaseAddress and Length.\r | |
902 | The bit mask of attributes is not support for the memory resource\r | |
903 | range specified by BaseAddress and Length.\r | |
904 | \r | |
905 | **/\r | |
906 | EFI_STATUS\r | |
907 | EFIAPI\r | |
908 | SmmSetMemoryAttributesEx (\r | |
909 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
910 | IN UINT64 Length,\r | |
911 | IN UINT64 Attributes,\r | |
912 | OUT BOOLEAN *IsSplitted OPTIONAL\r | |
913 | );\r | |
914 | \r | |
915 | /**\r | |
916 | This function clears the attributes for the memory region specified by BaseAddress and\r | |
917 | Length from their current attributes to the attributes specified by Attributes.\r | |
918 | \r | |
919 | @param[in] BaseAddress The physical address that is the start address of a memory region.\r | |
920 | @param[in] Length The size in bytes of the memory region.\r | |
921 | @param[in] Attributes The bit mask of attributes to clear for the memory region.\r | |
922 | @param[out] IsSplitted TRUE means page table splitted. FALSE means page table not splitted.\r | |
923 | \r | |
924 | @retval EFI_SUCCESS The attributes were cleared for the memory region.\r | |
925 | @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
926 | BaseAddress and Length cannot be modified.\r | |
927 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
928 | Attributes specified an illegal combination of attributes that\r | |
929 | cannot be set together.\r | |
930 | @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
931 | the memory resource range.\r | |
932 | @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory\r | |
933 | resource range specified by BaseAddress and Length.\r | |
934 | The bit mask of attributes is not support for the memory resource\r | |
935 | range specified by BaseAddress and Length.\r | |
936 | \r | |
937 | **/\r | |
938 | EFI_STATUS\r | |
939 | EFIAPI\r | |
940 | SmmClearMemoryAttributesEx (\r | |
941 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
942 | IN UINT64 Length,\r | |
943 | IN UINT64 Attributes,\r | |
944 | OUT BOOLEAN *IsSplitted OPTIONAL\r | |
945 | );\r | |
946 | \r | |
21c17193 JY |
947 | /**\r |
948 | This API provides a way to allocate memory for page table.\r | |
949 | \r | |
950 | This API can be called more once to allocate memory for page tables.\r | |
951 | \r | |
952 | Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r | |
953 | allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r | |
954 | is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r | |
955 | returned.\r | |
956 | \r | |
957 | @param Pages The number of 4 KB pages to allocate.\r | |
958 | \r | |
959 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
960 | \r | |
961 | **/\r | |
962 | VOID *\r | |
963 | AllocatePageTableMemory (\r | |
964 | IN UINTN Pages\r | |
965 | );\r | |
966 | \r | |
717fb604 JY |
967 | /**\r |
968 | Allocate pages for code.\r | |
969 | \r | |
970 | @param[in] Pages Number of pages to be allocated.\r | |
971 | \r | |
972 | @return Allocated memory.\r | |
973 | **/\r | |
974 | VOID *\r | |
975 | AllocateCodePages (\r | |
976 | IN UINTN Pages\r | |
977 | );\r | |
978 | \r | |
979 | /**\r | |
980 | Allocate aligned pages for code.\r | |
981 | \r | |
982 | @param[in] Pages Number of pages to be allocated.\r | |
983 | @param[in] Alignment The requested alignment of the allocation.\r | |
984 | Must be a power of two.\r | |
985 | If Alignment is zero, then byte alignment is used.\r | |
986 | \r | |
987 | @return Allocated memory.\r | |
988 | **/\r | |
989 | VOID *\r | |
990 | AllocateAlignedCodePages (\r | |
991 | IN UINTN Pages,\r | |
992 | IN UINTN Alignment\r | |
993 | );\r | |
994 | \r | |
0bdc9e75 SZ |
995 | \r |
996 | //\r | |
997 | // S3 related global variable and function prototype.\r | |
998 | //\r | |
999 | \r | |
1000 | extern BOOLEAN mSmmS3Flag;\r | |
1001 | \r | |
1002 | /**\r | |
1003 | Initialize SMM S3 resume state structure used during S3 Resume.\r | |
1004 | \r | |
1005 | @param[in] Cr3 The base address of the page tables to use in SMM.\r | |
1006 | \r | |
1007 | **/\r | |
1008 | VOID\r | |
1009 | InitSmmS3ResumeState (\r | |
1010 | IN UINT32 Cr3\r | |
1011 | );\r | |
1012 | \r | |
1013 | /**\r | |
1014 | Get ACPI CPU data.\r | |
1015 | \r | |
1016 | **/\r | |
1017 | VOID\r | |
1018 | GetAcpiCpuData (\r | |
1019 | VOID\r | |
1020 | );\r | |
1021 | \r | |
1022 | /**\r | |
1023 | Restore SMM Configuration in S3 boot path.\r | |
1024 | \r | |
1025 | **/\r | |
1026 | VOID\r | |
1027 | RestoreSmmConfigurationInS3 (\r | |
1028 | VOID\r | |
1029 | );\r | |
1030 | \r | |
b10d5ddc SZ |
1031 | /**\r |
1032 | Get ACPI S3 enable flag.\r | |
1033 | \r | |
1034 | **/\r | |
1035 | VOID\r | |
1036 | GetAcpiS3EnableFlag (\r | |
1037 | VOID\r | |
1038 | );\r | |
1039 | \r | |
4a0f88dd JF |
1040 | /**\r |
1041 | Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.\r | |
1042 | \r | |
672b80c8 MK |
1043 | @param[in] ApHltLoopCode The address of the safe hlt-loop function.\r |
1044 | @param[in] TopOfStack A pointer to the new stack to use for the ApHltLoopCode.\r | |
1045 | @param[in] NumberToFinishAddress Address of Semaphore of APs finish count.\r | |
4a0f88dd JF |
1046 | \r |
1047 | **/\r | |
1048 | VOID\r | |
1049 | TransferApToSafeState (\r | |
672b80c8 MK |
1050 | IN UINTN ApHltLoopCode,\r |
1051 | IN UINTN TopOfStack,\r | |
1052 | IN UINTN NumberToFinishAddress\r | |
4a0f88dd JF |
1053 | );\r |
1054 | \r | |
827330cc JW |
1055 | /**\r |
1056 | This function set given attributes of the memory region specified by\r | |
1057 | BaseAddress and Length.\r | |
1058 | \r | |
1059 | @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r | |
1060 | @param BaseAddress The physical address that is the start address of\r | |
1061 | a memory region.\r | |
1062 | @param Length The size in bytes of the memory region.\r | |
1063 | @param Attributes The bit mask of attributes to set for the memory\r | |
1064 | region.\r | |
1065 | \r | |
1066 | @retval EFI_SUCCESS The attributes were set for the memory region.\r | |
1067 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
1068 | Attributes specified an illegal combination of\r | |
1069 | attributes that cannot be set together.\r | |
1070 | @retval EFI_UNSUPPORTED The processor does not support one or more\r | |
1071 | bytes of the memory resource range specified\r | |
1072 | by BaseAddress and Length.\r | |
aae02dcc | 1073 | The bit mask of attributes is not supported for\r |
827330cc JW |
1074 | the memory resource range specified by\r |
1075 | BaseAddress and Length.\r | |
1076 | \r | |
1077 | **/\r | |
1078 | EFI_STATUS\r | |
1079 | EFIAPI\r | |
1080 | EdkiiSmmSetMemoryAttributes (\r | |
1081 | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r | |
1082 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
1083 | IN UINT64 Length,\r | |
1084 | IN UINT64 Attributes\r | |
1085 | );\r | |
1086 | \r | |
1087 | /**\r | |
1088 | This function clears given attributes of the memory region specified by\r | |
1089 | BaseAddress and Length.\r | |
1090 | \r | |
1091 | @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r | |
1092 | @param BaseAddress The physical address that is the start address of\r | |
1093 | a memory region.\r | |
1094 | @param Length The size in bytes of the memory region.\r | |
aae02dcc | 1095 | @param Attributes The bit mask of attributes to clear for the memory\r |
827330cc JW |
1096 | region.\r |
1097 | \r | |
aae02dcc | 1098 | @retval EFI_SUCCESS The attributes were cleared for the memory region.\r |
827330cc JW |
1099 | @retval EFI_INVALID_PARAMETER Length is zero.\r |
1100 | Attributes specified an illegal combination of\r | |
aae02dcc | 1101 | attributes that cannot be cleared together.\r |
827330cc JW |
1102 | @retval EFI_UNSUPPORTED The processor does not support one or more\r |
1103 | bytes of the memory resource range specified\r | |
1104 | by BaseAddress and Length.\r | |
aae02dcc | 1105 | The bit mask of attributes is not supported for\r |
827330cc JW |
1106 | the memory resource range specified by\r |
1107 | BaseAddress and Length.\r | |
1108 | \r | |
1109 | **/\r | |
1110 | EFI_STATUS\r | |
1111 | EFIAPI\r | |
1112 | EdkiiSmmClearMemoryAttributes (\r | |
1113 | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r | |
1114 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
1115 | IN UINT64 Length,\r | |
1116 | IN UINT64 Attributes\r | |
1117 | );\r | |
1118 | \r | |
1119 | /**\r | |
aae02dcc | 1120 | This function retrieves the attributes of the memory region specified by\r |
827330cc JW |
1121 | BaseAddress and Length. If different attributes are got from different part\r |
1122 | of the memory region, EFI_NO_MAPPING will be returned.\r | |
1123 | \r | |
1124 | @param This The EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL instance.\r | |
1125 | @param BaseAddress The physical address that is the start address of\r | |
1126 | a memory region.\r | |
1127 | @param Length The size in bytes of the memory region.\r | |
1128 | @param Attributes Pointer to attributes returned.\r | |
1129 | \r | |
1130 | @retval EFI_SUCCESS The attributes got for the memory region.\r | |
1131 | @retval EFI_INVALID_PARAMETER Length is zero.\r | |
1132 | Attributes is NULL.\r | |
1133 | @retval EFI_NO_MAPPING Attributes are not consistent cross the memory\r | |
1134 | region.\r | |
1135 | @retval EFI_UNSUPPORTED The processor does not support one or more\r | |
1136 | bytes of the memory resource range specified\r | |
1137 | by BaseAddress and Length.\r | |
827330cc JW |
1138 | \r |
1139 | **/\r | |
1140 | EFI_STATUS\r | |
1141 | EFIAPI\r | |
1142 | EdkiiSmmGetMemoryAttributes (\r | |
1143 | IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This,\r | |
1144 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
1145 | IN UINT64 Length,\r | |
1146 | IN UINT64 *Attributes\r | |
1147 | );\r | |
1148 | \r | |
e21e355e LG |
1149 | /**\r |
1150 | This function fixes up the address of the global variable or function\r | |
1151 | referred in SmmInit assembly files to be the absoute address.\r | |
1152 | **/\r | |
1153 | VOID\r | |
1154 | EFIAPI\r | |
1155 | PiSmmCpuSmmInitFixupAddress (\r | |
1156 | );\r | |
1157 | \r | |
1158 | /**\r | |
1159 | This function fixes up the address of the global variable or function\r | |
1160 | referred in SmiEntry assembly files to be the absoute address.\r | |
1161 | **/\r | |
1162 | VOID\r | |
1163 | EFIAPI\r | |
1164 | PiSmmCpuSmiEntryFixupAddress (\r | |
1165 | );\r | |
1166 | \r | |
529a5a86 | 1167 | #endif\r |