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