]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
UefiCpuPkg/CpuS3DataDxe: Consume PcdAcpiS3Enable to control the code
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / PiSmmCpuDxeSmm.h
CommitLineData
529a5a86
MK
1/** @file\r
2Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.\r
3\r
f85d3ce2 4Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
529a5a86
MK
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _CPU_PISMMCPUDXESMM_H_\r
16#define _CPU_PISMMCPUDXESMM_H_\r
17\r
18#include <PiSmm.h>\r
19\r
20#include <Protocol/MpService.h>\r
21#include <Protocol/SmmConfiguration.h>\r
22#include <Protocol/SmmCpu.h>\r
23#include <Protocol/SmmAccess2.h>\r
529a5a86
MK
24#include <Protocol/SmmReadyToLock.h>\r
25#include <Protocol/SmmCpuService.h>\r
26\r
27#include <Guid/AcpiS3Context.h>\r
28\r
29#include <Library/BaseLib.h>\r
30#include <Library/IoLib.h>\r
31#include <Library/TimerLib.h>\r
529a5a86
MK
32#include <Library/SynchronizationLib.h>\r
33#include <Library/DebugLib.h>\r
34#include <Library/BaseMemoryLib.h>\r
35#include <Library/PcdLib.h>\r
36#include <Library/CacheMaintenanceLib.h>\r
37#include <Library/MtrrLib.h>\r
38#include <Library/SmmCpuPlatformHookLib.h>\r
39#include <Library/SmmServicesTableLib.h>\r
40#include <Library/MemoryAllocationLib.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42#include <Library/UefiRuntimeServicesTableLib.h>\r
43#include <Library/DebugAgentLib.h>\r
44#include <Library/HobLib.h>\r
45#include <Library/LocalApicLib.h>\r
46#include <Library/UefiCpuLib.h>\r
47#include <Library/CpuExceptionHandlerLib.h>\r
48#include <Library/ReportStatusCodeLib.h>\r
49#include <Library/SmmCpuFeaturesLib.h>\r
50#include <Library/PeCoffGetEntryPointLib.h>\r
51\r
52#include <AcpiCpuData.h>\r
53#include <CpuHotPlugData.h>\r
54\r
55#include <Register/Cpuid.h>\r
f85d3ce2 56#include <Register/Msr.h>\r
529a5a86
MK
57\r
58#include "CpuService.h"\r
59#include "SmmProfile.h"\r
60\r
61//\r
62// MSRs required for configuration of SMM Code Access Check\r
63//\r
64#define EFI_MSR_SMM_MCA_CAP 0x17D\r
65#define SMM_CODE_ACCESS_CHK_BIT BIT58\r
66\r
67#define SMM_FEATURE_CONTROL_LOCK_BIT BIT0\r
68#define SMM_CODE_CHK_EN_BIT BIT2\r
69\r
70///\r
71/// Page Table Entry\r
72///\r
73#define IA32_PG_P BIT0\r
74#define IA32_PG_RW BIT1\r
881520ea 75#define IA32_PG_U BIT2\r
529a5a86
MK
76#define IA32_PG_WT BIT3\r
77#define IA32_PG_CD BIT4\r
78#define IA32_PG_A BIT5\r
881520ea 79#define IA32_PG_D BIT6\r
529a5a86
MK
80#define IA32_PG_PS BIT7\r
81#define IA32_PG_PAT_2M BIT12\r
82#define IA32_PG_PAT_4K IA32_PG_PS\r
83#define IA32_PG_PMNT BIT62\r
84#define IA32_PG_NX BIT63\r
85\r
881520ea
JY
86#define PAGE_ATTRIBUTE_BITS (IA32_PG_RW | IA32_PG_P)\r
87//\r
88// Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE\r
89// X64 PAE PDPTE does not have such restriction\r
90//\r
91#define IA32_PAE_PDPTE_ATTRIBUTE_BITS (IA32_PG_P)\r
92\r
529a5a86
MK
93//\r
94// Size of Task-State Segment defined in IA32 Manual\r
95//\r
96#define TSS_SIZE 104\r
97#define TSS_X64_IST1_OFFSET 36\r
98#define TSS_IA32_CR3_OFFSET 28\r
99#define TSS_IA32_ESP_OFFSET 56\r
100\r
101//\r
102// Code select value\r
103//\r
104#define PROTECT_MODE_CODE_SEGMENT 0x08\r
105#define LONG_MODE_CODE_SEGMENT 0x38\r
106\r
107//\r
108// The size 0x20 must be bigger than\r
109// the size of template code of SmmInit. Currently,\r
110// the size of SmmInit requires the 0x16 Bytes buffer\r
111// at least.\r
112//\r
113#define BACK_BUF_SIZE 0x20\r
114\r
115#define EXCEPTION_VECTOR_NUMBER 0x20\r
116\r
117#define INVALID_APIC_ID 0xFFFFFFFFFFFFFFFFULL\r
118\r
119typedef UINT32 SMM_CPU_ARRIVAL_EXCEPTIONS;\r
120#define ARRIVAL_EXCEPTION_BLOCKED 0x1\r
121#define ARRIVAL_EXCEPTION_DELAYED 0x2\r
122#define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4\r
123\r
124//\r
125// Private structure for the SMM CPU module that is stored in DXE Runtime memory\r
126// Contains the SMM Configuration Protocols that is produced.\r
127// Contains a mix of DXE and SMM contents. All the fields must be used properly.\r
128//\r
129#define SMM_CPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('s', 'c', 'p', 'u')\r
130\r
131typedef struct {\r
132 UINTN Signature;\r
133\r
134 EFI_HANDLE SmmCpuHandle;\r
135\r
136 EFI_PROCESSOR_INFORMATION *ProcessorInfo;\r
137 SMM_CPU_OPERATION *Operation;\r
138 UINTN *CpuSaveStateSize;\r
139 VOID **CpuSaveState;\r
140\r
141 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion[1];\r
142 EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext;\r
143 EFI_SMM_ENTRY_POINT SmmCoreEntry;\r
144\r
145 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration;\r
146} SMM_CPU_PRIVATE_DATA;\r
147\r
148extern SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate;\r
149extern CPU_HOT_PLUG_DATA mCpuHotPlugData;\r
150extern UINTN mMaxNumberOfCpus;\r
151extern UINTN mNumberOfCpus;\r
152extern BOOLEAN mRestoreSmmConfigurationInS3;\r
153extern EFI_SMM_CPU_PROTOCOL mSmmCpu;\r
154\r
155///\r
156/// The mode of the CPU at the time an SMI occurs\r
157///\r
158extern UINT8 mSmmSaveStateRegisterLma;\r
159\r
160\r
161//\r
162// SMM CPU Protocol function prototypes.\r
163//\r
164\r
165/**\r
166 Read information from the CPU save state.\r
167\r
168 @param This EFI_SMM_CPU_PROTOCOL instance\r
169 @param Width The number of bytes to read from the CPU save state.\r
170 @param Register Specifies the CPU register to read form the save state.\r
171 @param CpuIndex Specifies the zero-based index of the CPU save state\r
172 @param Buffer Upon return, this holds the CPU register value read from the save state.\r
173\r
174 @retval EFI_SUCCESS The register was read from Save State\r
175 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor\r
176 @retval EFI_INVALID_PARAMTER This or Buffer is NULL.\r
177\r
178**/\r
179EFI_STATUS\r
180EFIAPI\r
181SmmReadSaveState (\r
182 IN CONST EFI_SMM_CPU_PROTOCOL *This,\r
183 IN UINTN Width,\r
184 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
185 IN UINTN CpuIndex,\r
186 OUT VOID *Buffer\r
187 );\r
188\r
189/**\r
190 Write data to the CPU save state.\r
191\r
192 @param This EFI_SMM_CPU_PROTOCOL instance\r
193 @param Width The number of bytes to read from the CPU save state.\r
194 @param Register Specifies the CPU register to write to the save state.\r
195 @param CpuIndex Specifies the zero-based index of the CPU save state\r
196 @param Buffer Upon entry, this holds the new CPU register value.\r
197\r
198 @retval EFI_SUCCESS The register was written from Save State\r
199 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor\r
200 @retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct\r
201\r
202**/\r
203EFI_STATUS\r
204EFIAPI\r
205SmmWriteSaveState (\r
206 IN CONST EFI_SMM_CPU_PROTOCOL *This,\r
207 IN UINTN Width,\r
208 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
209 IN UINTN CpuIndex,\r
210 IN CONST VOID *Buffer\r
211 );\r
212\r
213/**\r
214Read a CPU Save State register on the target processor.\r
215\r
216This function abstracts the differences that whether the CPU Save State register is in the\r
217IA32 CPU Save State Map or X64 CPU Save State Map.\r
218\r
219This function supports reading a CPU Save State register in SMBase relocation handler.\r
220\r
221@param[in] CpuIndex Specifies the zero-based index of the CPU save state.\r
222@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.\r
223@param[in] Width The number of bytes to read from the CPU save state.\r
224@param[out] Buffer Upon return, this holds the CPU register value read from the save state.\r
225\r
226@retval EFI_SUCCESS The register was read from Save State.\r
227@retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.\r
228@retval EFI_INVALID_PARAMTER This or Buffer is NULL.\r
229\r
230**/\r
231EFI_STATUS\r
232EFIAPI\r
233ReadSaveStateRegister (\r
234 IN UINTN CpuIndex,\r
235 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
236 IN UINTN Width,\r
237 OUT VOID *Buffer\r
238 );\r
239\r
240/**\r
241Write value to a CPU Save State register on the target processor.\r
242\r
243This function abstracts the differences that whether the CPU Save State register is in the\r
244IA32 CPU Save State Map or X64 CPU Save State Map.\r
245\r
246This function supports writing a CPU Save State register in SMBase relocation handler.\r
247\r
248@param[in] CpuIndex Specifies the zero-based index of the CPU save state.\r
249@param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.\r
250@param[in] Width The number of bytes to read from the CPU save state.\r
251@param[in] Buffer Upon entry, this holds the new CPU register value.\r
252\r
253@retval EFI_SUCCESS The register was written to Save State.\r
254@retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.\r
255@retval EFI_INVALID_PARAMTER ProcessorIndex or Width is not correct.\r
256\r
257**/\r
258EFI_STATUS\r
259EFIAPI\r
260WriteSaveStateRegister (\r
261 IN UINTN CpuIndex,\r
262 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
263 IN UINTN Width,\r
264 IN CONST VOID *Buffer\r
265 );\r
266\r
267//\r
268//\r
269//\r
270typedef struct {\r
271 UINT32 Offset;\r
272 UINT16 Segment;\r
273 UINT16 Reserved;\r
274} IA32_FAR_ADDRESS;\r
275\r
276extern IA32_FAR_ADDRESS gSmmJmpAddr;\r
277\r
278extern CONST UINT8 gcSmmInitTemplate[];\r
279extern CONST UINT16 gcSmmInitSize;\r
280extern UINT32 gSmmCr0;\r
281extern UINT32 gSmmCr3;\r
282extern UINT32 gSmmCr4;\r
283extern UINTN gSmmInitStack;\r
284\r
285/**\r
286 Semaphore operation for all processor relocate SMMBase.\r
287**/\r
288VOID\r
289EFIAPI\r
290SmmRelocationSemaphoreComplete (\r
291 VOID\r
292 );\r
293\r
294///\r
295/// The type of SMM CPU Information\r
296///\r
297typedef struct {\r
ed3d5ecb 298 SPIN_LOCK *Busy;\r
529a5a86
MK
299 volatile EFI_AP_PROCEDURE Procedure;\r
300 volatile VOID *Parameter;\r
ed3d5ecb
JF
301 volatile UINT32 *Run;\r
302 volatile BOOLEAN *Present;\r
529a5a86
MK
303} SMM_CPU_DATA_BLOCK;\r
304\r
305typedef enum {\r
306 SmmCpuSyncModeTradition,\r
307 SmmCpuSyncModeRelaxedAp,\r
308 SmmCpuSyncModeMax\r
309} SMM_CPU_SYNC_MODE;\r
310\r
311typedef struct {\r
312 //\r
313 // Pointer to an array. The array should be located immediately after this structure\r
314 // so that UC cache-ability can be set together.\r
315 //\r
316 SMM_CPU_DATA_BLOCK *CpuData;\r
fe3a75bc 317 volatile UINT32 *Counter;\r
529a5a86 318 volatile UINT32 BspIndex;\r
fe3a75bc
JF
319 volatile BOOLEAN *InsideSmm;\r
320 volatile BOOLEAN *AllCpusInSync;\r
529a5a86
MK
321 volatile SMM_CPU_SYNC_MODE EffectiveSyncMode;\r
322 volatile BOOLEAN SwitchBsp;\r
323 volatile BOOLEAN *CandidateBsp;\r
324} SMM_DISPATCHER_MP_SYNC_DATA;\r
325\r
695e62d1
JF
326#define MSR_SPIN_LOCK_INIT_NUM 15\r
327\r
529a5a86 328typedef struct {\r
dc99315b 329 SPIN_LOCK *SpinLock;\r
529a5a86
MK
330 UINT32 MsrIndex;\r
331} MP_MSR_LOCK;\r
332\r
333#define SMM_PSD_OFFSET 0xfb00\r
334\r
335typedef struct {\r
336 UINT64 Signature; // Offset 0x00\r
337 UINT16 Reserved1; // Offset 0x08\r
338 UINT16 Reserved2; // Offset 0x0A\r
339 UINT16 Reserved3; // Offset 0x0C\r
340 UINT16 SmmCs; // Offset 0x0E\r
341 UINT16 SmmDs; // Offset 0x10\r
342 UINT16 SmmSs; // Offset 0x12\r
343 UINT16 SmmOtherSegment; // Offset 0x14\r
344 UINT16 Reserved4; // Offset 0x16\r
345 UINT64 Reserved5; // Offset 0x18\r
346 UINT64 Reserved6; // Offset 0x20\r
347 UINT64 Reserved7; // Offset 0x28\r
348 UINT64 SmmGdtPtr; // Offset 0x30\r
349 UINT32 SmmGdtSize; // Offset 0x38\r
350 UINT32 Reserved8; // Offset 0x3C\r
351 UINT64 Reserved9; // Offset 0x40\r
352 UINT64 Reserved10; // Offset 0x48\r
353 UINT16 Reserved11; // Offset 0x50\r
354 UINT16 Reserved12; // Offset 0x52\r
355 UINT32 Reserved13; // Offset 0x54\r
356 UINT64 MtrrBaseMaskPtr; // Offset 0x58\r
357} PROCESSOR_SMM_DESCRIPTOR;\r
358\r
1d648531
JF
359\r
360///\r
361/// All global semaphores' pointer\r
362///\r
363typedef struct {\r
364 volatile UINT32 *Counter;\r
365 volatile BOOLEAN *InsideSmm;\r
366 volatile BOOLEAN *AllCpusInSync;\r
367 SPIN_LOCK *PFLock;\r
368 SPIN_LOCK *CodeAccessCheckLock;\r
6c4c15fa 369 SPIN_LOCK *MemoryMappedLock;\r
1d648531
JF
370} SMM_CPU_SEMAPHORE_GLOBAL;\r
371\r
4e920581
JF
372///\r
373/// All semaphores for each processor\r
374///\r
375typedef struct {\r
376 SPIN_LOCK *Busy;\r
377 volatile UINT32 *Run;\r
378 volatile BOOLEAN *Present;\r
379} SMM_CPU_SEMAPHORE_CPU;\r
380\r
695e62d1
JF
381///\r
382/// All MSRs semaphores' pointer and counter\r
383///\r
384typedef struct {\r
385 SPIN_LOCK *Msr;\r
386 UINTN AvailableCounter;\r
387} SMM_CPU_SEMAPHORE_MSR;\r
4e920581 388\r
1d648531
JF
389///\r
390/// All semaphores' information\r
391///\r
392typedef struct {\r
393 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal;\r
4e920581 394 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu;\r
695e62d1 395 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr;\r
1d648531
JF
396} SMM_CPU_SEMAPHORES;\r
397\r
529a5a86
MK
398extern IA32_DESCRIPTOR gcSmiGdtr;\r
399extern IA32_DESCRIPTOR gcSmiIdtr;\r
400extern VOID *gcSmiIdtrPtr;\r
401extern CONST PROCESSOR_SMM_DESCRIPTOR gcPsd;\r
402extern UINT64 gPhyMask;\r
403extern ACPI_CPU_DATA mAcpiCpuData;\r
404extern SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData;\r
405extern VOID *mGdtForAp;\r
406extern VOID *mIdtForAp;\r
407extern VOID *mMachineCheckHandlerForAp;\r
408extern UINTN mSmmStackArrayBase;\r
409extern UINTN mSmmStackArrayEnd;\r
410extern UINTN mSmmStackSize;\r
411extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;\r
412extern IA32_DESCRIPTOR gcSmiInitGdtr;\r
dc99315b
JF
413extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores;\r
414extern UINTN mSemaphoreSize;\r
fe3a75bc
JF
415extern SPIN_LOCK *mPFLock;\r
416extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;\r
6c4c15fa 417extern SPIN_LOCK *mMemoryMappedLock;\r
529a5a86
MK
418\r
419/**\r
420 Create 4G PageTable in SMRAM.\r
421\r
422 @param ExtraPages Additional page numbers besides for 4G memory\r
881520ea 423 @param Is32BitPageTable Whether the page table is 32-bit PAE\r
529a5a86
MK
424 @return PageTable Address\r
425\r
426**/\r
427UINT32\r
428Gen4GPageTable (\r
881520ea
JY
429 IN UINTN ExtraPages,\r
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
441UINT32\r
442InitializeMpServiceData (\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
451VOID\r
452InitializeSmmTimer (\r
453 VOID\r
454 );\r
455\r
456/**\r
457 Start Timer for SMM AP Sync.\r
458\r
459**/\r
460UINT64\r
461EFIAPI\r
462StartSyncTimer (\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
472BOOLEAN\r
473EFIAPI\r
474IsSyncTimerTimeout (\r
475 IN UINT64 Timer\r
476 );\r
477\r
478/**\r
479 Initialize IDT for SMM Stack Guard.\r
480\r
481**/\r
482VOID\r
483EFIAPI\r
484InitializeIDTSmmStackGuard (\r
485 VOID\r
486 );\r
487\r
fe5f1949
JY
488/**\r
489 Initialize Gdt for all processors.\r
490 \r
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
497VOID *\r
498InitGdt (\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
513EFI_STATUS\r
514EFIAPI\r
515RegisterSmmEntry (\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
526UINT32\r
527SmmInitPageTable (\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
545EFI_STATUS\r
546EFIAPI\r
547SmmStartupThisAp (\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
567EFI_STATUS\r
568EFIAPI\r
569SmmBlockingStartupThisAp (\r
570 IN EFI_AP_PROCEDURE Procedure,\r
571 IN UINTN CpuIndex,\r
572 IN OUT VOID *ProcArguments OPTIONAL\r
573 );\r
574\r
575/**\r
576 Initialize MP synchronization data.\r
577\r
578**/\r
579VOID\r
580EFIAPI\r
581InitializeMpSyncData (\r
582 VOID\r
583 );\r
584\r
585/**\r
586\r
587 Find out SMRAM information including SMRR base and SMRR size.\r
588\r
589 @param SmrrBase SMRR base\r
590 @param SmrrSize SMRR size\r
591\r
592**/\r
593VOID\r
594FindSmramInfo (\r
595 OUT UINT32 *SmrrBase,\r
596 OUT UINT32 *SmrrSize\r
597 );\r
598\r
599/**\r
600 The function is invoked before SMBASE relocation in S3 path to restores CPU status.\r
601\r
602 The function is invoked before SMBASE relocation in S3 path. It does first time microcode load\r
603 and restores MTRRs for both BSP and APs.\r
604\r
605**/\r
606VOID\r
607EarlyInitializeCpu (\r
608 VOID\r
609 );\r
610\r
611/**\r
612 The function is invoked after SMBASE relocation in S3 path to restores CPU status.\r
613\r
614 The function is invoked after SMBASE relocation in S3 path. It restores configuration according to\r
615 data saved by normal boot path for both BSP and APs.\r
616\r
617**/\r
618VOID\r
619InitializeCpu (\r
620 VOID\r
621 );\r
622\r
623/**\r
624 Page Fault handler for SMM use.\r
625\r
626 @param InterruptType Defines the type of interrupt or exception that\r
627 occurred on the processor.This parameter is processor architecture specific.\r
628 @param SystemContext A pointer to the processor context when\r
629 the interrupt occurred on the processor.\r
630**/\r
631VOID\r
632EFIAPI\r
633SmiPFHandler (\r
634 IN EFI_EXCEPTION_TYPE InterruptType,\r
635 IN EFI_SYSTEM_CONTEXT SystemContext\r
636 );\r
637\r
638/**\r
639 Perform the remaining tasks.\r
640\r
641**/\r
642VOID\r
643PerformRemainingTasks (\r
644 VOID\r
645 );\r
646\r
9f419739
JY
647/**\r
648 Perform the pre tasks.\r
649\r
650**/\r
651VOID\r
652PerformPreTasks (\r
653 VOID\r
654 );\r
655\r
529a5a86
MK
656/**\r
657 Initialize MSR spin lock by MSR index.\r
658\r
659 @param MsrIndex MSR index value.\r
660\r
661**/\r
662VOID\r
663InitMsrSpinLockByIndex (\r
664 IN UINT32 MsrIndex\r
665 );\r
666\r
667/**\r
668 Hook return address of SMM Save State so that semaphore code\r
669 can be executed immediately after AP exits SMM to indicate to\r
670 the BSP that an AP has exited SMM after SMBASE relocation.\r
671\r
672 @param[in] CpuIndex The processor index.\r
673 @param[in] RebasedFlag A pointer to a flag that is set to TRUE\r
674 immediately after AP exits SMM.\r
675\r
676**/\r
677VOID\r
678SemaphoreHook (\r
679 IN UINTN CpuIndex,\r
680 IN volatile BOOLEAN *RebasedFlag\r
681 );\r
682\r
683/**\r
684Configure SMM Code Access Check feature for all processors.\r
685SMM Feature Control MSR will be locked after configuration.\r
686**/\r
687VOID\r
688ConfigSmmCodeAccessCheck (\r
689 VOID\r
690 );\r
691\r
692/**\r
693 Hook the code executed immediately after an RSM instruction on the currently\r
694 executing CPU. The mode of code executed immediately after RSM must be\r
695 detected, and the appropriate hook must be selected. Always clear the auto\r
696 HALT restart flag if it is set.\r
697\r
698 @param[in] CpuIndex The processor index for the currently\r
699 executing CPU.\r
700 @param[in] CpuState Pointer to SMRAM Save State Map for the\r
701 currently executing CPU.\r
702 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
703 32-bit mode from 64-bit SMM.\r
704 @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
705 same mode as SMM.\r
706\r
707 @retval The value of the original instruction pointer before it was hooked.\r
708\r
709**/\r
710UINT64\r
711EFIAPI\r
712HookReturnFromSmm (\r
713 IN UINTN CpuIndex,\r
714 SMRAM_SAVE_STATE_MAP *CpuState,\r
715 UINT64 NewInstructionPointer32,\r
716 UINT64 NewInstructionPointer\r
717 );\r
718\r
719/**\r
720 Get the size of the SMI Handler in bytes.\r
721\r
722 @retval The size, in bytes, of the SMI Handler.\r
723\r
724**/\r
725UINTN\r
726EFIAPI\r
727GetSmiHandlerSize (\r
728 VOID\r
729 );\r
730\r
731/**\r
732 Install the SMI handler for the CPU specified by CpuIndex. This function\r
733 is called by the CPU that was elected as monarch during System Management\r
734 Mode initialization.\r
735\r
736 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.\r
737 The value must be between 0 and the NumberOfCpus field\r
738 in the System Management System Table (SMST).\r
739 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.\r
740 @param[in] SmiStack The stack to use when an SMI is processed by the\r
741 the CPU specified by CpuIndex.\r
742 @param[in] StackSize The size, in bytes, if the stack used when an SMI is\r
743 processed by the CPU specified by CpuIndex.\r
744 @param[in] GdtBase The base address of the GDT to use when an SMI is\r
745 processed by the CPU specified by CpuIndex.\r
746 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is\r
747 processed by the CPU specified by CpuIndex.\r
748 @param[in] IdtBase The base address of the IDT to use when an SMI is\r
749 processed by the CPU specified by CpuIndex.\r
750 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is\r
751 processed by the CPU specified by CpuIndex.\r
752 @param[in] Cr3 The base address of the page tables to use when an SMI\r
753 is processed by the CPU specified by CpuIndex.\r
754**/\r
755VOID\r
756EFIAPI\r
757InstallSmiHandler (\r
758 IN UINTN CpuIndex,\r
759 IN UINT32 SmBase,\r
760 IN VOID *SmiStack,\r
761 IN UINTN StackSize,\r
762 IN UINTN GdtBase,\r
763 IN UINTN GdtSize,\r
764 IN UINTN IdtBase,\r
765 IN UINTN IdtSize,\r
766 IN UINT32 Cr3\r
767 );\r
768\r
769/**\r
770 Search module name by input IP address and output it.\r
771\r
772 @param CallerIpAddress Caller instruction pointer.\r
773\r
774**/\r
775VOID\r
776DumpModuleInfoByIp (\r
777 IN UINTN CallerIpAddress\r
778 );\r
21c17193
JY
779\r
780/**\r
781 This API provides a way to allocate memory for page table.\r
782\r
783 This API can be called more once to allocate memory for page tables.\r
784\r
785 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
786 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
787 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
788 returned.\r
789\r
790 @param Pages The number of 4 KB pages to allocate.\r
791\r
792 @return A pointer to the allocated buffer or NULL if allocation fails.\r
793\r
794**/\r
795VOID *\r
796AllocatePageTableMemory (\r
797 IN UINTN Pages\r
798 );\r
799\r
529a5a86 800#endif\r