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