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