]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg: Split the path in RelocateApLoop into two.
[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 *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 STATIC_ASSERT ((AP_SAFE_STACK_SIZE & (CPU_STACK_ALIGNMENT - 1)) == 0, "AP_SAFE_STACK_SIZE is not aligned with CPU_STACK_ALIGNMENT");
315
316 #pragma pack(1)
317
318 typedef struct {
319 UINT8 InsnBuffer[8];
320 UINT16 Rip;
321 UINT16 Segment;
322 } SEV_ES_AP_JMP_FAR;
323
324 #pragma pack()
325
326 /**
327 Assembly code to move an AP from long mode to real mode.
328
329 Move an AP from long mode to real mode in preparation to invoking
330 the reset vector. This is used for SEV-ES guests where a hypervisor
331 is not allowed to set the CS and RIP to point to the reset vector.
332
333 @param[in] BufferStart The reset vector target.
334 @param[in] Code16 16-bit protected mode code segment value.
335 @param[in] Code32 32-bit protected mode code segment value.
336 @param[in] StackStart The start of a stack to be used for transitioning
337 from long mode to real mode.
338 **/
339 typedef
340 VOID
341 (EFIAPI AP_RESET)(
342 IN UINTN BufferStart,
343 IN UINT16 Code16,
344 IN UINT16 Code32,
345 IN UINTN StackStart
346 );
347
348 extern EFI_GUID mCpuInitMpLibHobGuid;
349
350 /**
351 Assembly code to place AP into safe loop mode.
352
353 Place AP into targeted C-State if MONITOR is supported, otherwise
354 place AP into hlt state.
355 Place AP in protected mode if the current is long mode. Due to AP maybe
356 wakeup by some hardware event. It could avoid accessing page table that
357 may not available during booting to OS.
358
359 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
360 FALSE indicates MONITOR is not supported.
361 @param[in] ApTargetCState Target C-State value.
362 @param[in] PmCodeSegment Protected mode code segment value.
363 **/
364 typedef
365 VOID
366 (EFIAPI *ASM_RELOCATE_AP_LOOP)(
367 IN BOOLEAN MwaitSupport,
368 IN UINTN ApTargetCState,
369 IN UINTN PmCodeSegment,
370 IN UINTN TopOfApStack,
371 IN UINTN NumberToFinish,
372 IN UINTN Pm16CodeSegment,
373 IN UINTN SevEsAPJumpTable,
374 IN UINTN WakeupBuffer
375 );
376
377 /**
378 Assembly code to get starting address and size of the rendezvous entry for APs.
379 Information for fixing a jump instruction in the code is also returned.
380
381 @param[out] AddressMap Output buffer for address map information.
382 **/
383 VOID
384 EFIAPI
385 AsmGetAddressMap (
386 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
387 );
388
389 /**
390 This function is called by both the BSP and the AP which is to become the BSP to
391 Exchange execution context including stack between them. After return from this
392 function, the BSP becomes AP and the AP becomes the BSP.
393
394 @param[in] MyInfo Pointer to buffer holding the exchanging information for the executing processor.
395 @param[in] OthersInfo Pointer to buffer holding the exchanging information for the peer.
396
397 **/
398 VOID
399 EFIAPI
400 AsmExchangeRole (
401 IN CPU_EXCHANGE_ROLE_INFO *MyInfo,
402 IN CPU_EXCHANGE_ROLE_INFO *OthersInfo
403 );
404
405 typedef union {
406 VOID *Data;
407 ASM_RELOCATE_AP_LOOP AmdSevEntry; // 64-bit AMD Sev processors
408 ASM_RELOCATE_AP_LOOP GenericEntry; // Intel processors (32-bit or 64-bit), 32-bit AMD processors, or AMD non-Sev processors
409 } RELOCATE_AP_LOOP_ENTRY;
410
411 /**
412 Get the pointer to CPU MP Data structure.
413
414 @return The pointer to CPU MP Data structure.
415 **/
416 CPU_MP_DATA *
417 GetCpuMpData (
418 VOID
419 );
420
421 /**
422 Save the pointer to CPU MP Data structure.
423
424 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
425 **/
426 VOID
427 SaveCpuMpData (
428 IN CPU_MP_DATA *CpuMpData
429 );
430
431 /**
432 Get available system memory below 1MB by specified size.
433
434 @param[in] WakeupBufferSize Wakeup buffer size required
435
436 @retval other Return wakeup buffer address below 1MB.
437 @retval -1 Cannot find free memory below 1MB.
438 **/
439 UINTN
440 GetWakeupBuffer (
441 IN UINTN WakeupBufferSize
442 );
443
444 /**
445 Get available EfiBootServicesCode memory below 4GB by specified size.
446
447 This buffer is required to safely transfer AP from real address mode to
448 protected mode or long mode, due to the fact that the buffer returned by
449 GetWakeupBuffer() may be marked as non-executable.
450
451 @param[in] BufferSize Wakeup transition buffer size.
452
453 @retval other Return wakeup transition buffer address below 4GB.
454 @retval 0 Cannot find free memory below 4GB.
455 **/
456 UINTN
457 AllocateCodeBuffer (
458 IN UINTN BufferSize
459 );
460
461 /**
462 Return the address of the SEV-ES AP jump table.
463
464 This buffer is required in order for an SEV-ES guest to transition from
465 UEFI into an OS.
466
467 @return Return SEV-ES AP jump table buffer
468 **/
469 UINTN
470 GetSevEsAPMemory (
471 VOID
472 );
473
474 /**
475 This function will be called by BSP to wakeup AP.
476
477 @param[in] CpuMpData Pointer to CPU MP Data
478 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
479 FALSE: Send IPI to AP by ApicId
480 @param[in] ProcessorNumber The handle number of specified processor
481 @param[in] Procedure The function to be invoked by AP
482 @param[in] ProcedureArgument The argument to be passed into AP function
483 @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in broadcast mode.
484 **/
485 VOID
486 WakeUpAP (
487 IN CPU_MP_DATA *CpuMpData,
488 IN BOOLEAN Broadcast,
489 IN UINTN ProcessorNumber,
490 IN EFI_AP_PROCEDURE Procedure OPTIONAL,
491 IN VOID *ProcedureArgument OPTIONAL,
492 IN BOOLEAN WakeUpDisabledAps
493 );
494
495 /**
496 Initialize global data for MP support.
497
498 @param[in] CpuMpData The pointer to CPU MP Data structure.
499 **/
500 VOID
501 InitMpGlobalData (
502 IN CPU_MP_DATA *CpuMpData
503 );
504
505 /**
506 Worker function to execute a caller provided function on all enabled APs.
507
508 @param[in] Procedure A pointer to the function to be run on
509 enabled APs of the system.
510 @param[in] SingleThread If TRUE, then all the enabled APs execute
511 the function specified by Procedure one by
512 one, in ascending order of processor handle
513 number. If FALSE, then all the enabled APs
514 execute the function specified by Procedure
515 simultaneously.
516 @param[in] ExcludeBsp Whether let BSP also trig this task.
517 @param[in] WaitEvent The event created by the caller with CreateEvent()
518 service.
519 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
520 APs to return from Procedure, either for
521 blocking or non-blocking mode.
522 @param[in] ProcedureArgument The parameter passed into Procedure for
523 all APs.
524 @param[out] FailedCpuList If all APs finish successfully, then its
525 content is set to NULL. If not all APs
526 finish before timeout expires, then its
527 content is set to address of the buffer
528 holding handle numbers of the failed APs.
529
530 @retval EFI_SUCCESS In blocking mode, all APs have finished before
531 the timeout expired.
532 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
533 to all enabled APs.
534 @retval others Failed to Startup all APs.
535
536 **/
537 EFI_STATUS
538 StartupAllCPUsWorker (
539 IN EFI_AP_PROCEDURE Procedure,
540 IN BOOLEAN SingleThread,
541 IN BOOLEAN ExcludeBsp,
542 IN EFI_EVENT WaitEvent OPTIONAL,
543 IN UINTN TimeoutInMicroseconds,
544 IN VOID *ProcedureArgument OPTIONAL,
545 OUT UINTN **FailedCpuList OPTIONAL
546 );
547
548 /**
549 Worker function to let the caller get one enabled AP to execute a caller-provided
550 function.
551
552 @param[in] Procedure A pointer to the function to be run on
553 enabled APs of the system.
554 @param[in] ProcessorNumber The handle number of the AP.
555 @param[in] WaitEvent The event created by the caller with CreateEvent()
556 service.
557 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
558 APs to return from Procedure, either for
559 blocking or non-blocking mode.
560 @param[in] ProcedureArgument The parameter passed into Procedure for
561 all APs.
562 @param[out] Finished If AP returns from Procedure before the
563 timeout expires, its content is set to TRUE.
564 Otherwise, the value is set to FALSE.
565
566 @retval EFI_SUCCESS In blocking mode, specified AP finished before
567 the timeout expires.
568 @retval others Failed to Startup AP.
569
570 **/
571 EFI_STATUS
572 StartupThisAPWorker (
573 IN EFI_AP_PROCEDURE Procedure,
574 IN UINTN ProcessorNumber,
575 IN EFI_EVENT WaitEvent OPTIONAL,
576 IN UINTN TimeoutInMicroseconds,
577 IN VOID *ProcedureArgument OPTIONAL,
578 OUT BOOLEAN *Finished OPTIONAL
579 );
580
581 /**
582 Worker function to switch the requested AP to be the BSP from that point onward.
583
584 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
585 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
586 enabled AP. Otherwise, it will be disabled.
587
588 @retval EFI_SUCCESS BSP successfully switched.
589 @retval others Failed to switch BSP.
590
591 **/
592 EFI_STATUS
593 SwitchBSPWorker (
594 IN UINTN ProcessorNumber,
595 IN BOOLEAN EnableOldBSP
596 );
597
598 /**
599 Worker function to let the caller enable or disable an AP from this point onward.
600 This service may only be called from the BSP.
601
602 @param[in] ProcessorNumber The handle number of AP.
603 @param[in] EnableAP Specifies the new state for the processor for
604 enabled, FALSE for disabled.
605 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
606 the new health status of the AP.
607
608 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
609 @retval others Failed to Enable/Disable AP.
610
611 **/
612 EFI_STATUS
613 EnableDisableApWorker (
614 IN UINTN ProcessorNumber,
615 IN BOOLEAN EnableAP,
616 IN UINT32 *HealthFlag OPTIONAL
617 );
618
619 /**
620 Get pointer to CPU MP Data structure from GUIDed HOB.
621
622 @return The pointer to CPU MP Data structure.
623 **/
624 CPU_MP_DATA *
625 GetCpuMpDataFromGuidedHob (
626 VOID
627 );
628
629 /** Checks status of specified AP.
630
631 This function checks whether the specified AP has finished the task assigned
632 by StartupThisAP(), and whether timeout expires.
633
634 @param[in] ProcessorNumber The handle number of processor.
635
636 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
637 @retval EFI_TIMEOUT The timeout expires.
638 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
639 **/
640 EFI_STATUS
641 CheckThisAP (
642 IN UINTN ProcessorNumber
643 );
644
645 /**
646 Checks status of all APs.
647
648 This function checks whether all APs have finished task assigned by StartupAllAPs(),
649 and whether timeout expires.
650
651 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
652 @retval EFI_TIMEOUT The timeout expires.
653 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
654 **/
655 EFI_STATUS
656 CheckAllAPs (
657 VOID
658 );
659
660 /**
661 Checks APs status and updates APs status if needed.
662
663 **/
664 VOID
665 CheckAndUpdateApsStatus (
666 VOID
667 );
668
669 /**
670 Detect whether specified processor can find matching microcode patch and load it.
671
672 @param[in] CpuMpData The pointer to CPU MP Data structure.
673 @param[in] ProcessorNumber The handle number of the processor. The range is
674 from 0 to the total number of logical processors
675 minus 1.
676 **/
677 VOID
678 MicrocodeDetect (
679 IN CPU_MP_DATA *CpuMpData,
680 IN UINTN ProcessorNumber
681 );
682
683 /**
684 Shadow the required microcode patches data into memory.
685
686 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
687 **/
688 VOID
689 ShadowMicrocodeUpdatePatch (
690 IN OUT CPU_MP_DATA *CpuMpData
691 );
692
693 /**
694 Get the cached microcode patch base address and size from the microcode patch
695 information cache HOB.
696
697 @param[out] Address Base address of the microcode patches data.
698 It will be updated if the microcode patch
699 information cache HOB is found.
700 @param[out] RegionSize Size of the microcode patches data.
701 It will be updated if the microcode patch
702 information cache HOB is found.
703
704 @retval TRUE The microcode patch information cache HOB is found.
705 @retval FALSE The microcode patch information cache HOB is not found.
706
707 **/
708 BOOLEAN
709 GetMicrocodePatchInfoFromHob (
710 UINT64 *Address,
711 UINT64 *RegionSize
712 );
713
714 /**
715 Detect whether Mwait-monitor feature is supported.
716
717 @retval TRUE Mwait-monitor feature is supported.
718 @retval FALSE Mwait-monitor feature is not supported.
719 **/
720 BOOLEAN
721 IsMwaitSupport (
722 VOID
723 );
724
725 /**
726 Enable Debug Agent to support source debugging on AP function.
727
728 **/
729 VOID
730 EnableDebugAgent (
731 VOID
732 );
733
734 /**
735 Find the current Processor number by APIC ID.
736
737 @param[in] CpuMpData Pointer to PEI CPU MP Data
738 @param[out] ProcessorNumber Return the pocessor number found
739
740 @retval EFI_SUCCESS ProcessorNumber is found and returned.
741 @retval EFI_NOT_FOUND ProcessorNumber is not found.
742 **/
743 EFI_STATUS
744 GetProcessorNumber (
745 IN CPU_MP_DATA *CpuMpData,
746 OUT UINTN *ProcessorNumber
747 );
748
749 /**
750 This funtion will try to invoke platform specific microcode shadow logic to
751 relocate microcode update patches into memory.
752
753 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
754
755 @retval EFI_SUCCESS Shadow microcode success.
756 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
757 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
758 PPI/Protocol.
759 **/
760 EFI_STATUS
761 PlatformShadowMicrocode (
762 IN OUT CPU_MP_DATA *CpuMpData
763 );
764
765 /**
766 Allocate the SEV-ES AP jump table buffer.
767
768 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
769 **/
770 VOID
771 AllocateSevEsAPMemory (
772 IN OUT CPU_MP_DATA *CpuMpData
773 );
774
775 /**
776 Program the SEV-ES AP jump table buffer.
777
778 @param[in] SipiVector The SIPI vector used for the AP Reset
779 **/
780 VOID
781 SetSevEsJumpTable (
782 IN UINTN SipiVector
783 );
784
785 /**
786 The function puts the AP in halt loop.
787
788 @param[in] CpuMpData The pointer to CPU MP Data structure.
789 **/
790 VOID
791 SevEsPlaceApHlt (
792 CPU_MP_DATA *CpuMpData
793 );
794
795 /**
796 Check if the specified confidential computing attribute is active.
797
798 @retval TRUE The specified Attr is active.
799 @retval FALSE The specified Attr is not active.
800 **/
801 BOOLEAN
802 EFIAPI
803 ConfidentialComputingGuestHas (
804 CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr
805 );
806
807 /**
808 The function fills the exchange data for the AP.
809
810 @param[in] ExchangeInfo The pointer to CPU Exchange Data structure
811 **/
812 VOID
813 FillExchangeInfoDataSevEs (
814 IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
815 );
816
817 /**
818 Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page.
819
820 @param[in] PageAddress
821 @param[in] VmsaPage
822
823 @return RMPADJUST return value
824 **/
825 UINT32
826 SevSnpRmpAdjust (
827 IN EFI_PHYSICAL_ADDRESS PageAddress,
828 IN BOOLEAN VmsaPage
829 );
830
831 /**
832 Create an SEV-SNP AP save area (VMSA) for use in running the vCPU.
833
834 @param[in] CpuMpData Pointer to CPU MP Data
835 @param[in] CpuData Pointer to CPU AP Data
836 @param[in] ApicId APIC ID of the vCPU
837 **/
838 VOID
839 SevSnpCreateSaveArea (
840 IN CPU_MP_DATA *CpuMpData,
841 IN CPU_AP_DATA *CpuData,
842 UINT32 ApicId
843 );
844
845 /**
846 Create SEV-SNP APs.
847
848 @param[in] CpuMpData Pointer to CPU MP Data
849 @param[in] ProcessorNumber The handle number of specified processor
850 (-1 for all APs)
851 **/
852 VOID
853 SevSnpCreateAP (
854 IN CPU_MP_DATA *CpuMpData,
855 IN INTN ProcessorNumber
856 );
857
858 #endif