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