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