]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
UefiCpuPkg/PiSmmCpuDxeSmm: Allocate buffer for MSRs semaphores
[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
MK
328typedef struct {\r
329 SPIN_LOCK SpinLock;\r
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
369} SMM_CPU_SEMAPHORE_GLOBAL;\r
370\r
4e920581
JF
371///\r
372/// All semaphores for each processor\r
373///\r
374typedef struct {\r
375 SPIN_LOCK *Busy;\r
376 volatile UINT32 *Run;\r
377 volatile BOOLEAN *Present;\r
378} SMM_CPU_SEMAPHORE_CPU;\r
379\r
695e62d1
JF
380///\r
381/// All MSRs semaphores' pointer and counter\r
382///\r
383typedef struct {\r
384 SPIN_LOCK *Msr;\r
385 UINTN AvailableCounter;\r
386} SMM_CPU_SEMAPHORE_MSR;\r
4e920581 387\r
1d648531
JF
388///\r
389/// All semaphores' information\r
390///\r
391typedef struct {\r
392 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal;\r
4e920581 393 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu;\r
695e62d1 394 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr;\r
1d648531
JF
395} SMM_CPU_SEMAPHORES;\r
396\r
529a5a86
MK
397extern IA32_DESCRIPTOR gcSmiGdtr;\r
398extern IA32_DESCRIPTOR gcSmiIdtr;\r
399extern VOID *gcSmiIdtrPtr;\r
400extern CONST PROCESSOR_SMM_DESCRIPTOR gcPsd;\r
401extern UINT64 gPhyMask;\r
402extern ACPI_CPU_DATA mAcpiCpuData;\r
403extern SMM_DISPATCHER_MP_SYNC_DATA *mSmmMpSyncData;\r
404extern VOID *mGdtForAp;\r
405extern VOID *mIdtForAp;\r
406extern VOID *mMachineCheckHandlerForAp;\r
407extern UINTN mSmmStackArrayBase;\r
408extern UINTN mSmmStackArrayEnd;\r
409extern UINTN mSmmStackSize;\r
410extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;\r
411extern IA32_DESCRIPTOR gcSmiInitGdtr;\r
fe3a75bc
JF
412extern SPIN_LOCK *mPFLock;\r
413extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;\r
529a5a86
MK
414\r
415/**\r
416 Create 4G PageTable in SMRAM.\r
417\r
418 @param ExtraPages Additional page numbers besides for 4G memory\r
881520ea 419 @param Is32BitPageTable Whether the page table is 32-bit PAE\r
529a5a86
MK
420 @return PageTable Address\r
421\r
422**/\r
423UINT32\r
424Gen4GPageTable (\r
881520ea
JY
425 IN UINTN ExtraPages,\r
426 IN BOOLEAN Is32BitPageTable\r
529a5a86
MK
427 );\r
428\r
429\r
430/**\r
431 Initialize global data for MP synchronization.\r
432\r
433 @param Stacks Base address of SMI stack buffer for all processors.\r
434 @param StackSize Stack size for each processor in SMM.\r
435\r
436**/\r
437UINT32\r
438InitializeMpServiceData (\r
439 IN VOID *Stacks,\r
440 IN UINTN StackSize\r
441 );\r
442\r
443/**\r
444 Initialize Timer for SMM AP Sync.\r
445\r
446**/\r
447VOID\r
448InitializeSmmTimer (\r
449 VOID\r
450 );\r
451\r
452/**\r
453 Start Timer for SMM AP Sync.\r
454\r
455**/\r
456UINT64\r
457EFIAPI\r
458StartSyncTimer (\r
459 VOID\r
460 );\r
461\r
462/**\r
463 Check if the SMM AP Sync timer is timeout.\r
464\r
465 @param Timer The start timer from the begin.\r
466\r
467**/\r
468BOOLEAN\r
469EFIAPI\r
470IsSyncTimerTimeout (\r
471 IN UINT64 Timer\r
472 );\r
473\r
474/**\r
475 Initialize IDT for SMM Stack Guard.\r
476\r
477**/\r
478VOID\r
479EFIAPI\r
480InitializeIDTSmmStackGuard (\r
481 VOID\r
482 );\r
483\r
fe5f1949
JY
484/**\r
485 Initialize Gdt for all processors.\r
486 \r
487 @param[in] Cr3 CR3 value.\r
488 @param[out] GdtStepSize The step size for GDT table.\r
489\r
490 @return GdtBase for processor 0.\r
491 GdtBase for processor X is: GdtBase + (GdtStepSize * X)\r
492**/\r
493VOID *\r
494InitGdt (\r
495 IN UINTN Cr3,\r
496 OUT UINTN *GdtStepSize\r
497 );\r
498\r
529a5a86
MK
499/**\r
500\r
501 Register the SMM Foundation entry point.\r
502\r
503 @param This Pointer to EFI_SMM_CONFIGURATION_PROTOCOL instance\r
504 @param SmmEntryPoint SMM Foundation EntryPoint\r
505\r
506 @retval EFI_SUCCESS Successfully to register SMM foundation entry point\r
507\r
508**/\r
509EFI_STATUS\r
510EFIAPI\r
511RegisterSmmEntry (\r
512 IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This,\r
513 IN EFI_SMM_ENTRY_POINT SmmEntryPoint\r
514 );\r
515\r
516/**\r
517 Create PageTable for SMM use.\r
518\r
519 @return PageTable Address\r
520\r
521**/\r
522UINT32\r
523SmmInitPageTable (\r
524 VOID\r
525 );\r
526\r
527/**\r
528 Schedule a procedure to run on the specified CPU.\r
529\r
530 @param Procedure The address of the procedure to run\r
531 @param CpuIndex Target CPU number\r
532 @param ProcArguments The parameter to pass to the procedure\r
533\r
534 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
535 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
536 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
537 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
538 @retval EFI_SUCCESS - The procedure has been successfully scheduled\r
539\r
540**/\r
541EFI_STATUS\r
542EFIAPI\r
543SmmStartupThisAp (\r
544 IN EFI_AP_PROCEDURE Procedure,\r
545 IN UINTN CpuIndex,\r
546 IN OUT VOID *ProcArguments OPTIONAL\r
547 );\r
548\r
549/**\r
550 Schedule a procedure to run on the specified CPU in a blocking fashion.\r
551\r
552 @param Procedure The address of the procedure to run\r
553 @param CpuIndex Target CPU Index\r
554 @param ProcArguments The parameter to pass to the procedure\r
555\r
556 @retval EFI_INVALID_PARAMETER CpuNumber not valid\r
557 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP\r
558 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM\r
559 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy\r
560 @retval EFI_SUCCESS The procedure has been successfully scheduled\r
561\r
562**/\r
563EFI_STATUS\r
564EFIAPI\r
565SmmBlockingStartupThisAp (\r
566 IN EFI_AP_PROCEDURE Procedure,\r
567 IN UINTN CpuIndex,\r
568 IN OUT VOID *ProcArguments OPTIONAL\r
569 );\r
570\r
571/**\r
572 Initialize MP synchronization data.\r
573\r
574**/\r
575VOID\r
576EFIAPI\r
577InitializeMpSyncData (\r
578 VOID\r
579 );\r
580\r
581/**\r
582\r
583 Find out SMRAM information including SMRR base and SMRR size.\r
584\r
585 @param SmrrBase SMRR base\r
586 @param SmrrSize SMRR size\r
587\r
588**/\r
589VOID\r
590FindSmramInfo (\r
591 OUT UINT32 *SmrrBase,\r
592 OUT UINT32 *SmrrSize\r
593 );\r
594\r
595/**\r
596 The function is invoked before SMBASE relocation in S3 path to restores CPU status.\r
597\r
598 The function is invoked before SMBASE relocation in S3 path. It does first time microcode load\r
599 and restores MTRRs for both BSP and APs.\r
600\r
601**/\r
602VOID\r
603EarlyInitializeCpu (\r
604 VOID\r
605 );\r
606\r
607/**\r
608 The function is invoked after SMBASE relocation in S3 path to restores CPU status.\r
609\r
610 The function is invoked after SMBASE relocation in S3 path. It restores configuration according to\r
611 data saved by normal boot path for both BSP and APs.\r
612\r
613**/\r
614VOID\r
615InitializeCpu (\r
616 VOID\r
617 );\r
618\r
619/**\r
620 Page Fault handler for SMM use.\r
621\r
622 @param InterruptType Defines the type of interrupt or exception that\r
623 occurred on the processor.This parameter is processor architecture specific.\r
624 @param SystemContext A pointer to the processor context when\r
625 the interrupt occurred on the processor.\r
626**/\r
627VOID\r
628EFIAPI\r
629SmiPFHandler (\r
630 IN EFI_EXCEPTION_TYPE InterruptType,\r
631 IN EFI_SYSTEM_CONTEXT SystemContext\r
632 );\r
633\r
634/**\r
635 Perform the remaining tasks.\r
636\r
637**/\r
638VOID\r
639PerformRemainingTasks (\r
640 VOID\r
641 );\r
642\r
9f419739
JY
643/**\r
644 Perform the pre tasks.\r
645\r
646**/\r
647VOID\r
648PerformPreTasks (\r
649 VOID\r
650 );\r
651\r
529a5a86
MK
652/**\r
653 Initialize MSR spin lock by MSR index.\r
654\r
655 @param MsrIndex MSR index value.\r
656\r
657**/\r
658VOID\r
659InitMsrSpinLockByIndex (\r
660 IN UINT32 MsrIndex\r
661 );\r
662\r
663/**\r
664 Hook return address of SMM Save State so that semaphore code\r
665 can be executed immediately after AP exits SMM to indicate to\r
666 the BSP that an AP has exited SMM after SMBASE relocation.\r
667\r
668 @param[in] CpuIndex The processor index.\r
669 @param[in] RebasedFlag A pointer to a flag that is set to TRUE\r
670 immediately after AP exits SMM.\r
671\r
672**/\r
673VOID\r
674SemaphoreHook (\r
675 IN UINTN CpuIndex,\r
676 IN volatile BOOLEAN *RebasedFlag\r
677 );\r
678\r
679/**\r
680Configure SMM Code Access Check feature for all processors.\r
681SMM Feature Control MSR will be locked after configuration.\r
682**/\r
683VOID\r
684ConfigSmmCodeAccessCheck (\r
685 VOID\r
686 );\r
687\r
688/**\r
689 Hook the code executed immediately after an RSM instruction on the currently\r
690 executing CPU. The mode of code executed immediately after RSM must be\r
691 detected, and the appropriate hook must be selected. Always clear the auto\r
692 HALT restart flag if it is set.\r
693\r
694 @param[in] CpuIndex The processor index for the currently\r
695 executing CPU.\r
696 @param[in] CpuState Pointer to SMRAM Save State Map for the\r
697 currently executing CPU.\r
698 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
699 32-bit mode from 64-bit SMM.\r
700 @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
701 same mode as SMM.\r
702\r
703 @retval The value of the original instruction pointer before it was hooked.\r
704\r
705**/\r
706UINT64\r
707EFIAPI\r
708HookReturnFromSmm (\r
709 IN UINTN CpuIndex,\r
710 SMRAM_SAVE_STATE_MAP *CpuState,\r
711 UINT64 NewInstructionPointer32,\r
712 UINT64 NewInstructionPointer\r
713 );\r
714\r
715/**\r
716 Get the size of the SMI Handler in bytes.\r
717\r
718 @retval The size, in bytes, of the SMI Handler.\r
719\r
720**/\r
721UINTN\r
722EFIAPI\r
723GetSmiHandlerSize (\r
724 VOID\r
725 );\r
726\r
727/**\r
728 Install the SMI handler for the CPU specified by CpuIndex. This function\r
729 is called by the CPU that was elected as monarch during System Management\r
730 Mode initialization.\r
731\r
732 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.\r
733 The value must be between 0 and the NumberOfCpus field\r
734 in the System Management System Table (SMST).\r
735 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.\r
736 @param[in] SmiStack The stack to use when an SMI is processed by the\r
737 the CPU specified by CpuIndex.\r
738 @param[in] StackSize The size, in bytes, if the stack used when an SMI is\r
739 processed by the CPU specified by CpuIndex.\r
740 @param[in] GdtBase The base address of the GDT to use when an SMI is\r
741 processed by the CPU specified by CpuIndex.\r
742 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is\r
743 processed by the CPU specified by CpuIndex.\r
744 @param[in] IdtBase The base address of the IDT to use when an SMI is\r
745 processed by the CPU specified by CpuIndex.\r
746 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is\r
747 processed by the CPU specified by CpuIndex.\r
748 @param[in] Cr3 The base address of the page tables to use when an SMI\r
749 is processed by the CPU specified by CpuIndex.\r
750**/\r
751VOID\r
752EFIAPI\r
753InstallSmiHandler (\r
754 IN UINTN CpuIndex,\r
755 IN UINT32 SmBase,\r
756 IN VOID *SmiStack,\r
757 IN UINTN StackSize,\r
758 IN UINTN GdtBase,\r
759 IN UINTN GdtSize,\r
760 IN UINTN IdtBase,\r
761 IN UINTN IdtSize,\r
762 IN UINT32 Cr3\r
763 );\r
764\r
765/**\r
766 Search module name by input IP address and output it.\r
767\r
768 @param CallerIpAddress Caller instruction pointer.\r
769\r
770**/\r
771VOID\r
772DumpModuleInfoByIp (\r
773 IN UINTN CallerIpAddress\r
774 );\r
21c17193
JY
775\r
776/**\r
777 This API provides a way to allocate memory for page table.\r
778\r
779 This API can be called more once to allocate memory for page tables.\r
780\r
781 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
782 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
783 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
784 returned.\r
785\r
786 @param Pages The number of 4 KB pages to allocate.\r
787\r
788 @return A pointer to the allocated buffer or NULL if allocation fails.\r
789\r
790**/\r
791VOID *\r
792AllocatePageTableMemory (\r
793 IN UINTN Pages\r
794 );\r
795\r
529a5a86 796#endif\r