]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
1 /** @file
2 Common header file for MP Initialize Library.
3
4 Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2020, AMD Inc. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #ifndef _MP_LIB_H_
12 #define _MP_LIB_H_
13
14 #include <PiPei.h>
15
16 #include <Register/Intel/Cpuid.h>
17 #include <Register/Amd/Cpuid.h>
18 #include <Register/Amd/Ghcb.h>
19 #include <Register/Intel/Msr.h>
20 #include <Register/Intel/LocalApic.h>
21 #include <Register/Intel/Microcode.h>
22
23 #include <Library/MpInitLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/LocalApicLib.h>
29 #include <Library/CpuLib.h>
30 #include <Library/UefiCpuLib.h>
31 #include <Library/TimerLib.h>
32 #include <Library/SynchronizationLib.h>
33 #include <Library/MtrrLib.h>
34 #include <Library/HobLib.h>
35 #include <Library/PcdLib.h>
36 #include <Library/MicrocodeLib.h>
37 #include <ConfidentialComputingGuestAttr.h>
38
39 #include <Register/Amd/Fam17Msr.h>
40 #include <Register/Amd/Ghcb.h>
41
42 #include <Guid/MicrocodePatchHob.h>
43
44 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')
45
46 #define CPU_INIT_MP_LIB_HOB_GUID \
47 { \
48 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \
49 }
50
51 //
52 // The MP data for switch BSP
53 //
54 #define CPU_SWITCH_STATE_IDLE 0
55 #define CPU_SWITCH_STATE_STORED 1
56 #define CPU_SWITCH_STATE_LOADED 2
57
58 //
59 // Default maximum number of entries to store the microcode patches information
60 //
61 #define DEFAULT_MAX_MICROCODE_PATCH_NUM 8
62
63 //
64 // Data structure for microcode patch information
65 //
66 typedef struct {
67 UINTN Address;
68 UINTN Size;
69 } MICROCODE_PATCH_INFO;
70
71 //
72 // CPU volatile registers around INIT-SIPI-SIPI
73 //
74 typedef struct {
75 UINTN Cr0;
76 UINTN Cr3;
77 UINTN Cr4;
78 UINTN Dr0;
79 UINTN Dr1;
80 UINTN Dr2;
81 UINTN Dr3;
82 UINTN Dr6;
83 UINTN Dr7;
84 IA32_DESCRIPTOR Gdtr;
85 IA32_DESCRIPTOR Idtr;
86 UINT16 Tr;
87 } CPU_VOLATILE_REGISTERS;
88
89 //
90 // CPU exchange information for switch BSP
91 //
92 typedef struct {
93 UINT8 State; // offset 0
94 UINTN StackPointer; // offset 4 / 8
95 CPU_VOLATILE_REGISTERS VolatileRegisters; // offset 8 / 16
96 } CPU_EXCHANGE_ROLE_INFO;
97
98 //
99 // AP loop state when APs are in idle state
100 // It's value is the same with PcdCpuApLoopMode
101 //
102 typedef enum {
103 ApInHltLoop = 1,
104 ApInMwaitLoop = 2,
105 ApInRunLoop = 3
106 } AP_LOOP_MODE;
107
108 //
109 // AP initialization state during APs wakeup
110 //
111 typedef enum {
112 ApInitConfig = 1,
113 ApInitReconfig = 2,
114 ApInitDone = 3
115 } AP_INIT_STATE;
116
117 //
118 // AP state
119 //
120 // The state transitions for an AP when it process a procedure are:
121 // Idle ----> Ready ----> Busy ----> Idle
122 // [BSP] [AP] [AP]
123 //
124 typedef enum {
125 CpuStateIdle,
126 CpuStateReady,
127 CpuStateBusy,
128 CpuStateFinished,
129 CpuStateDisabled
130 } CPU_STATE;
131
132 //
133 // AP related data
134 //
135 typedef struct {
136 SPIN_LOCK ApLock;
137 volatile UINT32 *StartupApSignal;
138 volatile UINTN ApFunction;
139 volatile UINTN ApFunctionArgument;
140 BOOLEAN CpuHealthy;
141 volatile CPU_STATE State;
142 CPU_VOLATILE_REGISTERS VolatileRegisters;
143 BOOLEAN Waiting;
144 BOOLEAN *Finished;
145 UINT64 ExpectedTime;
146 UINT64 CurrentTime;
147 UINT64 TotalTime;
148 EFI_EVENT WaitEvent;
149 UINT32 ProcessorSignature;
150 UINT8 PlatformId;
151 UINT64 MicrocodeEntryAddr;
152 UINT32 MicrocodeRevision;
153 SEV_ES_SAVE_AREA *SevEsSaveArea;
154 } CPU_AP_DATA;
155
156 //
157 // Basic CPU information saved in Guided HOB.
158 // Because the contents will be shard between PEI and DXE,
159 // we need to make sure the each fields offset same in different
160 // architecture.
161 //
162 #pragma pack (1)
163 typedef struct {
164 UINT32 InitialApicId;
165 UINT32 ApicId;
166 UINT32 Health;
167 UINT64 ApTopOfStack;
168 } CPU_INFO_IN_HOB;
169 #pragma pack ()
170
171 //
172 // AP reset code information including code address and size,
173 // this structure will be shared be C code and assembly code.
174 // It is natural aligned by design.
175 //
176 typedef struct {
177 UINT8 *RendezvousFunnelAddress;
178 UINTN ModeEntryOffset;
179 UINTN RendezvousFunnelSize;
180 UINT8 *RelocateApLoopFuncAddressGeneric;
181 UINTN RelocateApLoopFuncSizeGeneric;
182 UINT8 *RelocateApLoopFuncAddressAmdSev;
183 UINTN RelocateApLoopFuncSizeAmdSev;
184 UINTN ModeTransitionOffset;
185 UINTN SwitchToRealNoNxOffset;
186 UINTN SwitchToRealPM16ModeOffset;
187 UINTN SwitchToRealPM16ModeSize;
188 } MP_ASSEMBLY_ADDRESS_MAP;
189
190 typedef struct _CPU_MP_DATA CPU_MP_DATA;
191
192 #pragma pack(1)
193
194 //
195 // MP CPU exchange information for AP reset code
196 // This structure is required to be packed because fixed field offsets
197 // into this structure are used in assembly code in this module
198 //
199 typedef struct {
200 UINTN StackStart;
201 UINTN StackSize;
202 UINTN CFunction;
203 IA32_DESCRIPTOR GdtrProfile;
204 IA32_DESCRIPTOR IdtrProfile;
205 UINTN BufferStart;
206 UINTN ModeOffset;
207 UINTN ApIndex;
208 UINTN CodeSegment;
209 UINTN DataSegment;
210 UINTN EnableExecuteDisable;
211 UINTN Cr3;
212 UINTN InitFlag;
213 CPU_INFO_IN_HOB *CpuInfo;
214 UINTN NumApsExecuting;
215 CPU_MP_DATA *CpuMpData;
216 UINTN InitializeFloatingPointUnitsAddress;
217 UINT32 ModeTransitionMemory;
218 UINT16 ModeTransitionSegment;
219 UINT32 ModeHighMemory;
220 UINT16 ModeHighSegment;
221 //
222 // Enable5LevelPaging indicates whether 5-level paging is enabled in long mode.
223 //
224 BOOLEAN Enable5LevelPaging;
225 BOOLEAN SevEsIsEnabled;
226 BOOLEAN SevSnpIsEnabled;
227 UINTN GhcbBase;
228 BOOLEAN ExtTopoAvail;
229 } MP_CPU_EXCHANGE_INFO;
230
231 #pragma pack()
232
233 //
234 // CPU MP Data save in memory
235 //
236 struct _CPU_MP_DATA {
237 UINT64 CpuInfoInHob;
238 UINT32 CpuCount;
239 UINT32 BspNumber;
240 //
241 // The above fields data will be passed from PEI to DXE
242 // Please make sure the fields offset same in the different
243 // architecture.
244 //
245 SPIN_LOCK MpLock;
246 UINTN Buffer;
247 UINTN CpuApStackSize;
248 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
249 UINTN WakeupBuffer;
250 UINTN WakeupBufferHigh;
251 UINTN BackupBuffer;
252 UINTN BackupBufferSize;
253
254 volatile UINT32 FinishedCount;
255 UINT32 RunningCount;
256 BOOLEAN SingleThread;
257 EFI_AP_PROCEDURE Procedure;
258 VOID *ProcArguments;
259 BOOLEAN *Finished;
260 UINT64 ExpectedTime;
261 UINT64 CurrentTime;
262 UINT64 TotalTime;
263 EFI_EVENT WaitEvent;
264 UINTN **FailedCpuList;
265
266 AP_INIT_STATE InitFlag;
267 BOOLEAN SwitchBspFlag;
268 UINTN NewBspNumber;
269 CPU_EXCHANGE_ROLE_INFO BSPInfo;
270 CPU_EXCHANGE_ROLE_INFO APInfo;
271 MTRR_SETTINGS MtrrTable;
272 UINT8 ApLoopMode;
273 UINT8 ApTargetCState;
274 UINT16 PmCodeSegment;
275 UINT16 Pm16CodeSegment;
276 CPU_AP_DATA *CpuData;
277 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
278
279 UINT32 CurrentTimerCount;
280 UINTN DivideValue;
281 UINT8 Vector;
282 BOOLEAN PeriodicMode;
283 BOOLEAN TimerInterruptState;
284 UINT64 MicrocodePatchAddress;
285 UINT64 MicrocodePatchRegionSize;
286
287 //
288 // Whether need to use Init-Sipi-Sipi to wake up the APs.
289 // Two cases need to set this value to TRUE. One is in HLT
290 // loop mode, the other is resume from S3 which loop mode
291 // will be hardcode change to HLT mode by PiSmmCpuDxeSmm
292 // driver.
293 //
294 BOOLEAN WakeUpByInitSipiSipi;
295
296 BOOLEAN SevEsIsEnabled;
297 BOOLEAN SevSnpIsEnabled;
298 BOOLEAN UseSevEsAPMethod;
299 UINTN SevEsAPBuffer;
300 UINTN SevEsAPResetStackStart;
301 CPU_MP_DATA *NewCpuMpData;
302
303 UINT64 GhcbBase;
304 };
305
306 //
307 // AP_STACK_DATA is stored at the top of each AP stack.
308 //
309 typedef struct {
310 UINTN Bist;
311 CPU_MP_DATA *MpData;
312 } AP_STACK_DATA;
313
314 #define AP_SAFE_STACK_SIZE 128
315 #define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
316 STATIC_ASSERT ((AP_SAFE_STACK_SIZE & (CPU_STACK_ALIGNMENT - 1)) == 0, "AP_SAFE_STACK_SIZE is not aligned with CPU_STACK_ALIGNMENT");
317
318 #pragma pack(1)
319
320 typedef struct {
321 UINT8 InsnBuffer[8];
322 UINT16 Rip;
323 UINT16 Segment;
324 } SEV_ES_AP_JMP_FAR;
325
326 #pragma pack()
327
328 /**
329 Assembly code to move an AP from long mode to real mode.
330
331 Move an AP from long mode to real mode in preparation to invoking
332 the reset vector. This is used for SEV-ES guests where a hypervisor
333 is not allowed to set the CS and RIP to point to the reset vector.
334
335 @param[in] BufferStart The reset vector target.
336 @param[in] Code16 16-bit protected mode code segment value.
337 @param[in] Code32 32-bit protected mode code segment value.
338 @param[in] StackStart The start of a stack to be used for transitioning
339 from long mode to real mode.
340 **/
341 typedef
342 VOID
343 (EFIAPI AP_RESET)(
344 IN UINTN BufferStart,
345 IN UINT16 Code16,
346 IN UINT16 Code32,
347 IN UINTN StackStart
348 );
349
350 extern EFI_GUID mCpuInitMpLibHobGuid;
351
352 /**
353 Assembly code to place AP into safe loop mode.
354
355 Place AP into targeted C-State if MONITOR is supported, otherwise
356 place AP into hlt state.
357 Place AP in protected mode if the current is long mode. Due to AP maybe
358 wakeup by some hardware event. It could avoid accessing page table that
359 may not available during booting to OS.
360
361 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
362 FALSE indicates MONITOR is not supported.
363 @param[in] ApTargetCState Target C-State value.
364 @param[in] PmCodeSegment Protected mode code segment value.
365 **/
366 typedef
367 VOID
368 (EFIAPI *ASM_RELOCATE_AP_LOOP_GENERIC)(
369 IN BOOLEAN MwaitSupport,
370 IN UINTN ApTargetCState,
371 IN UINTN TopOfApStack,
372 IN UINTN NumberToFinish,
373 IN UINTN Cr3
374 );
375
376 /**
377 Assembly code to place AP into safe loop mode for Amd processors
378 with Sev enabled.
379 Place AP into targeted C-State if MONITOR is supported, otherwise
380 place AP into hlt state.
381 Place AP in protected mode if the current is long mode. Due to AP maybe
382 wakeup by some hardware event. It could avoid accessing page table that
383 may not available during booting to OS.
384 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
385 FALSE indicates MONITOR is not supported.
386 @param[in] ApTargetCState Target C-State value.
387 @param[in] PmCodeSegment Protected mode code segment value.
388 **/
389 typedef
390 VOID
391 (EFIAPI *ASM_RELOCATE_AP_LOOP_AMDSEV)(
392 IN BOOLEAN MwaitSupport,
393 IN UINTN ApTargetCState,
394 IN UINTN PmCodeSegment,
395 IN UINTN TopOfApStack,
396 IN UINTN NumberToFinish,
397 IN UINTN Pm16CodeSegment,
398 IN UINTN SevEsAPJumpTable,
399 IN UINTN WakeupBuffer
400 );
401
402 /**
403 Assembly code to get starting address and size of the rendezvous entry for APs.
404 Information for fixing a jump instruction in the code is also returned.
405
406 @param[out] AddressMap Output buffer for address map information.
407 **/
408 VOID
409 EFIAPI
410 AsmGetAddressMap (
411 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
412 );
413
414 /**
415 This function is called by both the BSP and the AP which is to become the BSP to
416 Exchange execution context including stack between them. After return from this
417 function, the BSP becomes AP and the AP becomes the BSP.
418
419 @param[in] MyInfo Pointer to buffer holding the exchanging information for the executing processor.
420 @param[in] OthersInfo Pointer to buffer holding the exchanging information for the peer.
421
422 **/
423 VOID
424 EFIAPI
425 AsmExchangeRole (
426 IN CPU_EXCHANGE_ROLE_INFO *MyInfo,
427 IN CPU_EXCHANGE_ROLE_INFO *OthersInfo
428 );
429
430 typedef union {
431 VOID *Data;
432 ASM_RELOCATE_AP_LOOP_AMDSEV AmdSevEntry; // 64-bit AMD Sev processors
433 ASM_RELOCATE_AP_LOOP_GENERIC GenericEntry; // Intel processors (32-bit or 64-bit), 32-bit AMD processors, or AMD non-Sev processors
434 } RELOCATE_AP_LOOP_ENTRY;
435
436 /**
437 Get the pointer to CPU MP Data structure.
438
439 @return The pointer to CPU MP Data structure.
440 **/
441 CPU_MP_DATA *
442 GetCpuMpData (
443 VOID
444 );
445
446 /**
447 Save the pointer to CPU MP Data structure.
448
449 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
450 **/
451 VOID
452 SaveCpuMpData (
453 IN CPU_MP_DATA *CpuMpData
454 );
455
456 /**
457 Get available system memory below 1MB by specified size.
458
459 @param[in] WakeupBufferSize Wakeup buffer size required
460
461 @retval other Return wakeup buffer address below 1MB.
462 @retval -1 Cannot find free memory below 1MB.
463 **/
464 UINTN
465 GetWakeupBuffer (
466 IN UINTN WakeupBufferSize
467 );
468
469 /**
470 Get available EfiBootServicesCode memory below 4GB by specified size.
471
472 This buffer is required to safely transfer AP from real address mode to
473 protected mode or long mode, due to the fact that the buffer returned by
474 GetWakeupBuffer() may be marked as non-executable.
475
476 @param[in] BufferSize Wakeup transition buffer size.
477
478 @retval other Return wakeup transition buffer address below 4GB.
479 @retval 0 Cannot find free memory below 4GB.
480 **/
481 UINTN
482 AllocateCodeBuffer (
483 IN UINTN BufferSize
484 );
485
486 /**
487 Return the address of the SEV-ES AP jump table.
488
489 This buffer is required in order for an SEV-ES guest to transition from
490 UEFI into an OS.
491
492 @return Return SEV-ES AP jump table buffer
493 **/
494 UINTN
495 GetSevEsAPMemory (
496 VOID
497 );
498
499 /**
500 Create 1:1 mapping page table in reserved memory to map the specified address range.
501 @param[in] LinearAddress The start of the linear address range.
502 @param[in] Length The length of the linear address range.
503 @return The page table to be created.
504 **/
505 UINTN
506 CreatePageTable (
507 IN UINTN Address,
508 IN UINTN Length
509 );
510
511 /**
512 This function will be called by BSP to wakeup AP.
513
514 @param[in] CpuMpData Pointer to CPU MP Data
515 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
516 FALSE: Send IPI to AP by ApicId
517 @param[in] ProcessorNumber The handle number of specified processor
518 @param[in] Procedure The function to be invoked by AP
519 @param[in] ProcedureArgument The argument to be passed into AP function
520 @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in broadcast mode.
521 **/
522 VOID
523 WakeUpAP (
524 IN CPU_MP_DATA *CpuMpData,
525 IN BOOLEAN Broadcast,
526 IN UINTN ProcessorNumber,
527 IN EFI_AP_PROCEDURE Procedure OPTIONAL,
528 IN VOID *ProcedureArgument OPTIONAL,
529 IN BOOLEAN WakeUpDisabledAps
530 );
531
532 /**
533 Initialize global data for MP support.
534
535 @param[in] CpuMpData The pointer to CPU MP Data structure.
536 **/
537 VOID
538 InitMpGlobalData (
539 IN CPU_MP_DATA *CpuMpData
540 );
541
542 /**
543 Worker function to execute a caller provided function on all enabled APs.
544
545 @param[in] Procedure A pointer to the function to be run on
546 enabled APs of the system.
547 @param[in] SingleThread If TRUE, then all the enabled APs execute
548 the function specified by Procedure one by
549 one, in ascending order of processor handle
550 number. If FALSE, then all the enabled APs
551 execute the function specified by Procedure
552 simultaneously.
553 @param[in] ExcludeBsp Whether let BSP also trig this task.
554 @param[in] WaitEvent The event created by the caller with CreateEvent()
555 service.
556 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
557 APs to return from Procedure, either for
558 blocking or non-blocking mode.
559 @param[in] ProcedureArgument The parameter passed into Procedure for
560 all APs.
561 @param[out] FailedCpuList If all APs finish successfully, then its
562 content is set to NULL. If not all APs
563 finish before timeout expires, then its
564 content is set to address of the buffer
565 holding handle numbers of the failed APs.
566
567 @retval EFI_SUCCESS In blocking mode, all APs have finished before
568 the timeout expired.
569 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
570 to all enabled APs.
571 @retval others Failed to Startup all APs.
572
573 **/
574 EFI_STATUS
575 StartupAllCPUsWorker (
576 IN EFI_AP_PROCEDURE Procedure,
577 IN BOOLEAN SingleThread,
578 IN BOOLEAN ExcludeBsp,
579 IN EFI_EVENT WaitEvent OPTIONAL,
580 IN UINTN TimeoutInMicroseconds,
581 IN VOID *ProcedureArgument OPTIONAL,
582 OUT UINTN **FailedCpuList OPTIONAL
583 );
584
585 /**
586 Worker function to let the caller get one enabled AP to execute a caller-provided
587 function.
588
589 @param[in] Procedure A pointer to the function to be run on
590 enabled APs of the system.
591 @param[in] ProcessorNumber The handle number of the AP.
592 @param[in] WaitEvent The event created by the caller with CreateEvent()
593 service.
594 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
595 APs to return from Procedure, either for
596 blocking or non-blocking mode.
597 @param[in] ProcedureArgument The parameter passed into Procedure for
598 all APs.
599 @param[out] Finished If AP returns from Procedure before the
600 timeout expires, its content is set to TRUE.
601 Otherwise, the value is set to FALSE.
602
603 @retval EFI_SUCCESS In blocking mode, specified AP finished before
604 the timeout expires.
605 @retval others Failed to Startup AP.
606
607 **/
608 EFI_STATUS
609 StartupThisAPWorker (
610 IN EFI_AP_PROCEDURE Procedure,
611 IN UINTN ProcessorNumber,
612 IN EFI_EVENT WaitEvent OPTIONAL,
613 IN UINTN TimeoutInMicroseconds,
614 IN VOID *ProcedureArgument OPTIONAL,
615 OUT BOOLEAN *Finished OPTIONAL
616 );
617
618 /**
619 Worker function to switch the requested AP to be the BSP from that point onward.
620
621 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
622 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
623 enabled AP. Otherwise, it will be disabled.
624
625 @retval EFI_SUCCESS BSP successfully switched.
626 @retval others Failed to switch BSP.
627
628 **/
629 EFI_STATUS
630 SwitchBSPWorker (
631 IN UINTN ProcessorNumber,
632 IN BOOLEAN EnableOldBSP
633 );
634
635 /**
636 Worker function to let the caller enable or disable an AP from this point onward.
637 This service may only be called from the BSP.
638
639 @param[in] ProcessorNumber The handle number of AP.
640 @param[in] EnableAP Specifies the new state for the processor for
641 enabled, FALSE for disabled.
642 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
643 the new health status of the AP.
644
645 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
646 @retval others Failed to Enable/Disable AP.
647
648 **/
649 EFI_STATUS
650 EnableDisableApWorker (
651 IN UINTN ProcessorNumber,
652 IN BOOLEAN EnableAP,
653 IN UINT32 *HealthFlag OPTIONAL
654 );
655
656 /**
657 Get pointer to CPU MP Data structure from GUIDed HOB.
658
659 @return The pointer to CPU MP Data structure.
660 **/
661 CPU_MP_DATA *
662 GetCpuMpDataFromGuidedHob (
663 VOID
664 );
665
666 /** Checks status of specified AP.
667
668 This function checks whether the specified AP has finished the task assigned
669 by StartupThisAP(), and whether timeout expires.
670
671 @param[in] ProcessorNumber The handle number of processor.
672
673 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
674 @retval EFI_TIMEOUT The timeout expires.
675 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
676 **/
677 EFI_STATUS
678 CheckThisAP (
679 IN UINTN ProcessorNumber
680 );
681
682 /**
683 Checks status of all APs.
684
685 This function checks whether all APs have finished task assigned by StartupAllAPs(),
686 and whether timeout expires.
687
688 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
689 @retval EFI_TIMEOUT The timeout expires.
690 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
691 **/
692 EFI_STATUS
693 CheckAllAPs (
694 VOID
695 );
696
697 /**
698 Checks APs status and updates APs status if needed.
699
700 **/
701 VOID
702 CheckAndUpdateApsStatus (
703 VOID
704 );
705
706 /**
707 Detect whether specified processor can find matching microcode patch and load it.
708
709 @param[in] CpuMpData The pointer to CPU MP Data structure.
710 @param[in] ProcessorNumber The handle number of the processor. The range is
711 from 0 to the total number of logical processors
712 minus 1.
713 **/
714 VOID
715 MicrocodeDetect (
716 IN CPU_MP_DATA *CpuMpData,
717 IN UINTN ProcessorNumber
718 );
719
720 /**
721 Shadow the required microcode patches data into memory.
722
723 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
724 **/
725 VOID
726 ShadowMicrocodeUpdatePatch (
727 IN OUT CPU_MP_DATA *CpuMpData
728 );
729
730 /**
731 Get the cached microcode patch base address and size from the microcode patch
732 information cache HOB.
733
734 @param[out] Address Base address of the microcode patches data.
735 It will be updated if the microcode patch
736 information cache HOB is found.
737 @param[out] RegionSize Size of the microcode patches data.
738 It will be updated if the microcode patch
739 information cache HOB is found.
740
741 @retval TRUE The microcode patch information cache HOB is found.
742 @retval FALSE The microcode patch information cache HOB is not found.
743
744 **/
745 BOOLEAN
746 GetMicrocodePatchInfoFromHob (
747 UINT64 *Address,
748 UINT64 *RegionSize
749 );
750
751 /**
752 Detect whether Mwait-monitor feature is supported.
753
754 @retval TRUE Mwait-monitor feature is supported.
755 @retval FALSE Mwait-monitor feature is not supported.
756 **/
757 BOOLEAN
758 IsMwaitSupport (
759 VOID
760 );
761
762 /**
763 Enable Debug Agent to support source debugging on AP function.
764
765 **/
766 VOID
767 EnableDebugAgent (
768 VOID
769 );
770
771 /**
772 Find the current Processor number by APIC ID.
773
774 @param[in] CpuMpData Pointer to PEI CPU MP Data
775 @param[out] ProcessorNumber Return the pocessor number found
776
777 @retval EFI_SUCCESS ProcessorNumber is found and returned.
778 @retval EFI_NOT_FOUND ProcessorNumber is not found.
779 **/
780 EFI_STATUS
781 GetProcessorNumber (
782 IN CPU_MP_DATA *CpuMpData,
783 OUT UINTN *ProcessorNumber
784 );
785
786 /**
787 This funtion will try to invoke platform specific microcode shadow logic to
788 relocate microcode update patches into memory.
789
790 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
791
792 @retval EFI_SUCCESS Shadow microcode success.
793 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
794 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
795 PPI/Protocol.
796 **/
797 EFI_STATUS
798 PlatformShadowMicrocode (
799 IN OUT CPU_MP_DATA *CpuMpData
800 );
801
802 /**
803 Allocate the SEV-ES AP jump table buffer.
804
805 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
806 **/
807 VOID
808 AllocateSevEsAPMemory (
809 IN OUT CPU_MP_DATA *CpuMpData
810 );
811
812 /**
813 Program the SEV-ES AP jump table buffer.
814
815 @param[in] SipiVector The SIPI vector used for the AP Reset
816 **/
817 VOID
818 SetSevEsJumpTable (
819 IN UINTN SipiVector
820 );
821
822 /**
823 The function puts the AP in halt loop.
824
825 @param[in] CpuMpData The pointer to CPU MP Data structure.
826 **/
827 VOID
828 SevEsPlaceApHlt (
829 CPU_MP_DATA *CpuMpData
830 );
831
832 /**
833 Check if the specified confidential computing attribute is active.
834
835 @retval TRUE The specified Attr is active.
836 @retval FALSE The specified Attr is not active.
837 **/
838 BOOLEAN
839 EFIAPI
840 ConfidentialComputingGuestHas (
841 CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr
842 );
843
844 /**
845 The function fills the exchange data for the AP.
846
847 @param[in] ExchangeInfo The pointer to CPU Exchange Data structure
848 **/
849 VOID
850 FillExchangeInfoDataSevEs (
851 IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
852 );
853
854 /**
855 Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page.
856
857 @param[in] PageAddress
858 @param[in] VmsaPage
859
860 @return RMPADJUST return value
861 **/
862 UINT32
863 SevSnpRmpAdjust (
864 IN EFI_PHYSICAL_ADDRESS PageAddress,
865 IN BOOLEAN VmsaPage
866 );
867
868 /**
869 Create an SEV-SNP AP save area (VMSA) for use in running the vCPU.
870
871 @param[in] CpuMpData Pointer to CPU MP Data
872 @param[in] CpuData Pointer to CPU AP Data
873 @param[in] ApicId APIC ID of the vCPU
874 **/
875 VOID
876 SevSnpCreateSaveArea (
877 IN CPU_MP_DATA *CpuMpData,
878 IN CPU_AP_DATA *CpuData,
879 UINT32 ApicId
880 );
881
882 /**
883 Create SEV-SNP APs.
884
885 @param[in] CpuMpData Pointer to CPU MP Data
886 @param[in] ProcessorNumber The handle number of specified processor
887 (-1 for all APs)
888 **/
889 VOID
890 SevSnpCreateAP (
891 IN CPU_MP_DATA *CpuMpData,
892 IN INTN ProcessorNumber
893 );
894
895 #endif