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