2 MP initialize support functions for DXE phase.
4 Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/UefiLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/DebugAgentLib.h>
14 #include <Library/DxeServicesTableLib.h>
15 #include <Library/CcExitLib.h>
16 #include <Register/Amd/Fam17Msr.h>
17 #include <Register/Amd/Ghcb.h>
19 #include <Protocol/Timer.h>
21 #define AP_SAFE_STACK_SIZE 128
23 CPU_MP_DATA
*mCpuMpData
= NULL
;
24 EFI_EVENT mCheckAllApsEvent
= NULL
;
25 EFI_EVENT mMpInitExitBootServicesEvent
= NULL
;
26 EFI_EVENT mLegacyBootEvent
= NULL
;
27 volatile BOOLEAN mStopCheckAllApsStatus
= TRUE
;
28 RELOCATE_AP_LOOP_ENTRY mReservedApLoop
;
29 UINTN mReservedTopOfApStack
;
30 volatile UINT32 mNumberToFinish
= 0;
33 // Begin wakeup buffer allocation below 0x88000
35 STATIC EFI_PHYSICAL_ADDRESS mSevEsDxeWakeupBuffer
= 0x88000;
38 Enable Debug Agent to support source debugging on AP function.
47 // Initialize Debug Agent to support source level debug in DXE phase
49 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP
, NULL
, NULL
);
53 Get the pointer to CPU MP Data structure.
55 @return The pointer to CPU MP Data structure.
62 ASSERT (mCpuMpData
!= NULL
);
67 Save the pointer to CPU MP Data structure.
69 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
73 IN CPU_MP_DATA
*CpuMpData
76 mCpuMpData
= CpuMpData
;
80 Get available system memory below 0x88000 by specified size.
82 @param[in] WakeupBufferSize Wakeup buffer size required
84 @retval other Return wakeup buffer address below 1MB.
85 @retval -1 Cannot find free memory below 1MB.
89 IN UINTN WakeupBufferSize
93 EFI_PHYSICAL_ADDRESS StartAddress
;
94 EFI_MEMORY_TYPE MemoryType
;
96 if (ConfidentialComputingGuestHas (CCAttrAmdSevEs
) &&
97 !ConfidentialComputingGuestHas (CCAttrAmdSevSnp
))
100 // An SEV-ES-only guest requires the memory to be reserved. SEV-SNP, which
101 // is also considered SEV-ES, uses a different AP startup method, though,
102 // which does not have the same requirement.
104 MemoryType
= EfiReservedMemoryType
;
106 MemoryType
= EfiBootServicesData
;
110 // Try to allocate buffer below 1M for waking vector.
111 // LegacyBios driver only reports warning when page allocation in range
112 // [0x60000, 0x88000) fails.
113 // This library is consumed by CpuDxe driver to produce CPU Arch protocol.
114 // LagacyBios driver depends on CPU Arch protocol which guarantees below
115 // allocation runs earlier than LegacyBios driver.
117 if (ConfidentialComputingGuestHas (CCAttrAmdSevEs
)) {
119 // SEV-ES Wakeup buffer should be under 0x88000 and under any previous one
121 StartAddress
= mSevEsDxeWakeupBuffer
;
123 StartAddress
= 0x88000;
126 Status
= gBS
->AllocatePages (
129 EFI_SIZE_TO_PAGES (WakeupBufferSize
),
132 ASSERT_EFI_ERROR (Status
);
133 if (EFI_ERROR (Status
)) {
134 StartAddress
= (EFI_PHYSICAL_ADDRESS
)-1;
135 } else if (ConfidentialComputingGuestHas (CCAttrAmdSevEs
)) {
137 // Next SEV-ES wakeup buffer allocation must be below this allocation
139 mSevEsDxeWakeupBuffer
= StartAddress
;
144 "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
149 return (UINTN
)StartAddress
;
153 Get available EfiBootServicesCode memory below 4GB by specified size.
155 This buffer is required to safely transfer AP from real address mode to
156 protected mode or long mode, due to the fact that the buffer returned by
157 GetWakeupBuffer() may be marked as non-executable.
159 @param[in] BufferSize Wakeup transition buffer size.
161 @retval other Return wakeup transition buffer address below 4GB.
162 @retval 0 Cannot find free memory below 4GB.
170 EFI_PHYSICAL_ADDRESS StartAddress
;
172 StartAddress
= BASE_4GB
- 1;
173 Status
= gBS
->AllocatePages (
176 EFI_SIZE_TO_PAGES (BufferSize
),
179 if (EFI_ERROR (Status
)) {
183 return (UINTN
)StartAddress
;
187 Return the address of the SEV-ES AP jump table.
189 This buffer is required in order for an SEV-ES guest to transition from
192 @return Return SEV-ES AP jump table buffer
200 EFI_PHYSICAL_ADDRESS StartAddress
;
201 MSR_SEV_ES_GHCB_REGISTER Msr
;
203 BOOLEAN InterruptState
;
206 // Allocate 1 page for AP jump table page
208 StartAddress
= BASE_4GB
- 1;
209 Status
= gBS
->AllocatePages (
211 EfiReservedMemoryType
,
215 ASSERT_EFI_ERROR (Status
);
217 DEBUG ((DEBUG_INFO
, "Dxe: SevEsAPMemory = %lx\n", (UINTN
)StartAddress
));
220 // Save the SevEsAPMemory as the AP jump table.
222 Msr
.GhcbPhysicalAddress
= AsmReadMsr64 (MSR_SEV_ES_GHCB
);
225 CcExitVmgInit (Ghcb
, &InterruptState
);
226 CcExitVmgExit (Ghcb
, SVM_EXIT_AP_JUMP_TABLE
, 0, (UINT64
)(UINTN
)StartAddress
);
227 CcExitVmgDone (Ghcb
, InterruptState
);
229 return (UINTN
)StartAddress
;
233 Checks APs status and updates APs status if needed.
237 CheckAndUpdateApsStatus (
241 UINTN ProcessorNumber
;
243 CPU_MP_DATA
*CpuMpData
;
245 CpuMpData
= GetCpuMpData ();
248 // First, check whether pending StartupAllAPs() exists.
250 if (CpuMpData
->WaitEvent
!= NULL
) {
251 Status
= CheckAllAPs ();
253 // If all APs finish for StartupAllAPs(), signal the WaitEvent for it.
255 if (Status
!= EFI_NOT_READY
) {
256 Status
= gBS
->SignalEvent (CpuMpData
->WaitEvent
);
257 CpuMpData
->WaitEvent
= NULL
;
262 // Second, check whether pending StartupThisAPs() callings exist.
264 for (ProcessorNumber
= 0; ProcessorNumber
< CpuMpData
->CpuCount
; ProcessorNumber
++) {
265 if (CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
== NULL
) {
269 Status
= CheckThisAP (ProcessorNumber
);
271 if (Status
!= EFI_NOT_READY
) {
272 gBS
->SignalEvent (CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
);
273 CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
= NULL
;
279 Checks APs' status periodically.
281 This function is triggered by timer periodically to check the
282 state of APs for StartupAllAPs() and StartupThisAP() executed
283 in non-blocking mode.
285 @param[in] Event Event triggered.
286 @param[in] Context Parameter passed with the event.
297 // If CheckApsStatus() is not stopped, otherwise return immediately.
299 if (!mStopCheckAllApsStatus
) {
300 CheckAndUpdateApsStatus ();
305 Get Protected mode code segment with 16-bit default addressing
306 from current GDT table.
308 @return Protected mode 16-bit code segment value.
311 GetProtectedMode16CS (
315 IA32_DESCRIPTOR GdtrDesc
;
316 IA32_SEGMENT_DESCRIPTOR
*GdtEntry
;
321 AsmReadGdtr (&GdtrDesc
);
322 GdtEntryCount
= (GdtrDesc
.Limit
+ 1) / sizeof (IA32_SEGMENT_DESCRIPTOR
);
323 GdtEntry
= (IA32_SEGMENT_DESCRIPTOR
*)GdtrDesc
.Base
;
324 for (Index
= 0; Index
< GdtEntryCount
; Index
++) {
325 if (GdtEntry
->Bits
.L
== 0) {
326 if ((GdtEntry
->Bits
.Type
> 8) && (GdtEntry
->Bits
.DB
== 0)) {
334 ASSERT (Index
!= GdtEntryCount
);
339 Get Protected mode code segment from current GDT table.
341 @return Protected mode code segment value.
348 IA32_DESCRIPTOR GdtrDesc
;
349 IA32_SEGMENT_DESCRIPTOR
*GdtEntry
;
353 AsmReadGdtr (&GdtrDesc
);
354 GdtEntryCount
= (GdtrDesc
.Limit
+ 1) / sizeof (IA32_SEGMENT_DESCRIPTOR
);
355 GdtEntry
= (IA32_SEGMENT_DESCRIPTOR
*)GdtrDesc
.Base
;
356 for (Index
= 0; Index
< GdtEntryCount
; Index
++) {
357 if (GdtEntry
->Bits
.L
== 0) {
358 if ((GdtEntry
->Bits
.Type
> 8) && (GdtEntry
->Bits
.DB
== 1)) {
366 ASSERT (Index
!= GdtEntryCount
);
373 @param[in, out] Buffer Pointer to private data buffer.
381 CPU_MP_DATA
*CpuMpData
;
382 BOOLEAN MwaitSupport
;
383 UINTN ProcessorNumber
;
386 MpInitLibWhoAmI (&ProcessorNumber
);
387 CpuMpData
= GetCpuMpData ();
388 MwaitSupport
= IsMwaitSupport ();
389 if (CpuMpData
->UseSevEsAPMethod
) {
391 // 64-bit AMD processors with SEV-ES
393 StackStart
= CpuMpData
->SevEsAPResetStackStart
;
394 mReservedApLoop
.AmdSevEntry (
396 CpuMpData
->ApTargetCState
,
397 CpuMpData
->PmCodeSegment
,
398 StackStart
- ProcessorNumber
* AP_SAFE_STACK_SIZE
,
399 (UINTN
)&mNumberToFinish
,
400 CpuMpData
->Pm16CodeSegment
,
401 CpuMpData
->SevEsAPBuffer
,
402 CpuMpData
->WakeupBuffer
406 // Intel processors (32-bit or 64-bit), 32-bit AMD processors, or 64-bit AMD processors without SEV-ES
408 StackStart
= mReservedTopOfApStack
;
409 mReservedApLoop
.GenericEntry (
411 CpuMpData
->ApTargetCState
,
412 CpuMpData
->PmCodeSegment
,
413 StackStart
- ProcessorNumber
* AP_SAFE_STACK_SIZE
,
414 (UINTN
)&mNumberToFinish
,
415 CpuMpData
->Pm16CodeSegment
,
416 CpuMpData
->SevEsAPBuffer
,
417 CpuMpData
->WakeupBuffer
422 // It should never reach here
428 Callback function for ExitBootServices.
430 @param[in] Event Event whose notification function is being invoked.
431 @param[in] Context The pointer to the notification function's context,
432 which is implementation-dependent.
437 MpInitChangeApLoopCallback (
442 CPU_MP_DATA
*CpuMpData
;
444 CpuMpData
= GetCpuMpData ();
445 CpuMpData
->PmCodeSegment
= GetProtectedModeCS ();
446 CpuMpData
->Pm16CodeSegment
= GetProtectedMode16CS ();
447 CpuMpData
->ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
448 mNumberToFinish
= CpuMpData
->CpuCount
- 1;
449 WakeUpAP (CpuMpData
, TRUE
, 0, RelocateApLoop
, NULL
, TRUE
);
450 while (mNumberToFinish
> 0) {
454 if (CpuMpData
->UseSevEsAPMethod
&& (CpuMpData
->WakeupBuffer
!= (UINTN
)-1)) {
456 // There are APs present. Re-use reserved memory area below 1MB from
457 // WakeupBuffer as the area to be used for transitioning to 16-bit mode
458 // in support of booting of the AP by an OS.
461 (VOID
*)CpuMpData
->WakeupBuffer
,
462 (VOID
*)(CpuMpData
->AddressMap
.RendezvousFunnelAddress
+
463 CpuMpData
->AddressMap
.SwitchToRealPM16ModeOffset
),
464 CpuMpData
->AddressMap
.SwitchToRealPM16ModeSize
468 DEBUG ((DEBUG_INFO
, "%a() done!\n", __FUNCTION__
));
472 Initialize global data for MP support.
474 @param[in] CpuMpData The pointer to CPU MP Data structure.
478 IN CPU_MP_DATA
*CpuMpData
482 EFI_PHYSICAL_ADDRESS Address
;
484 EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc
;
486 CPU_INFO_IN_HOB
*CpuInfoInHob
;
490 SaveCpuMpData (CpuMpData
);
492 if (CpuMpData
->CpuCount
== 1) {
494 // If only BSP exists, return
499 if (PcdGetBool (PcdCpuStackGuard
)) {
501 // One extra page at the bottom of the stack is needed for Guard page.
503 if (CpuMpData
->CpuApStackSize
<= EFI_PAGE_SIZE
) {
504 DEBUG ((DEBUG_ERROR
, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));
509 // DXE will reuse stack allocated for APs at PEI phase if it's available.
510 // Let's check it here.
512 // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of
513 // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be
516 CpuInfoInHob
= (CPU_INFO_IN_HOB
*)(UINTN
)CpuMpData
->CpuInfoInHob
;
517 for (Index
= 0; Index
< CpuMpData
->CpuCount
; ++Index
) {
518 if ((CpuInfoInHob
!= NULL
) && (CpuInfoInHob
[Index
].ApTopOfStack
!= 0)) {
519 StackBase
= (UINTN
)CpuInfoInHob
[Index
].ApTopOfStack
- CpuMpData
->CpuApStackSize
;
521 StackBase
= CpuMpData
->Buffer
+ Index
* CpuMpData
->CpuApStackSize
;
524 Status
= gDS
->GetMemorySpaceDescriptor (StackBase
, &MemDesc
);
525 ASSERT_EFI_ERROR (Status
);
527 Status
= gDS
->SetMemorySpaceAttributes (
529 EFI_PAGES_TO_SIZE (1),
530 MemDesc
.Attributes
| EFI_MEMORY_RP
532 ASSERT_EFI_ERROR (Status
);
536 "Stack Guard set at %lx [cpu%lu]!\n",
544 // Avoid APs access invalid buffer data which allocated by BootServices,
545 // so we will allocate reserved data for AP loop code. We also need to
546 // allocate this buffer below 4GB due to APs may be transferred to 32bit
547 // protected mode on long mode DXE.
548 // Allocating it in advance since memory services are not available in
549 // Exit Boot Services callback function.
551 // +------------+ (TopOfApStack)
553 // +------------+ (stack base, 4k aligned)
557 // +------------+ ((low address, 4k-aligned)
560 StackPages
= EFI_SIZE_TO_PAGES (CpuMpData
->CpuCount
* AP_SAFE_STACK_SIZE
);
561 FuncPages
= EFI_SIZE_TO_PAGES (CpuMpData
->AddressMap
.RelocateApLoopFuncSize
);
563 Address
= BASE_4GB
- 1;
564 Status
= gBS
->AllocatePages (
566 EfiReservedMemoryType
,
567 StackPages
+ FuncPages
,
570 ASSERT_EFI_ERROR (Status
);
572 mReservedApLoop
.Data
= (VOID
*)(UINTN
)Address
;
573 ASSERT (mReservedApLoop
.Data
!= NULL
);
576 // Make sure that the buffer memory is executable if NX protection is enabled
577 // for EfiReservedMemoryType.
579 // TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD
582 Status
= gDS
->GetMemorySpaceDescriptor (Address
, &MemDesc
);
583 if (!EFI_ERROR (Status
)) {
584 gDS
->SetMemorySpaceAttributes (
586 EFI_PAGES_TO_SIZE (FuncPages
),
587 MemDesc
.Attributes
& (~EFI_MEMORY_XP
)
591 mReservedTopOfApStack
= (UINTN
)Address
+ EFI_PAGES_TO_SIZE (StackPages
+FuncPages
);
592 ASSERT ((mReservedTopOfApStack
& (UINTN
)(CPU_STACK_ALIGNMENT
- 1)) == 0);
594 mReservedApLoop
.Data
,
595 CpuMpData
->AddressMap
.RelocateApLoopFuncAddress
,
596 CpuMpData
->AddressMap
.RelocateApLoopFuncSize
599 Status
= gBS
->CreateEvent (
600 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
606 ASSERT_EFI_ERROR (Status
);
609 // Set timer to check all APs status.
611 Status
= gBS
->SetTimer (
614 EFI_TIMER_PERIOD_MICROSECONDS (
615 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds
)
618 ASSERT_EFI_ERROR (Status
);
620 Status
= gBS
->CreateEvent (
621 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
623 MpInitChangeApLoopCallback
,
625 &mMpInitExitBootServicesEvent
627 ASSERT_EFI_ERROR (Status
);
629 Status
= gBS
->CreateEventEx (
632 MpInitChangeApLoopCallback
,
634 &gEfiEventLegacyBootGuid
,
637 ASSERT_EFI_ERROR (Status
);
641 This service executes a caller provided function on all enabled APs.
643 @param[in] Procedure A pointer to the function to be run on
644 enabled APs of the system. See type
646 @param[in] SingleThread If TRUE, then all the enabled APs execute
647 the function specified by Procedure one by
648 one, in ascending order of processor handle
649 number. If FALSE, then all the enabled APs
650 execute the function specified by Procedure
652 @param[in] WaitEvent The event created by the caller with CreateEvent()
653 service. If it is NULL, then execute in
654 blocking mode. BSP waits until all APs finish
655 or TimeoutInMicroSeconds expires. If it's
656 not NULL, then execute in non-blocking mode.
657 BSP requests the function specified by
658 Procedure to be started on all the enabled
659 APs, and go on executing immediately. If
660 all return from Procedure, or TimeoutInMicroSeconds
661 expires, this event is signaled. The BSP
662 can use the CheckEvent() or WaitForEvent()
663 services to check the state of event. Type
664 EFI_EVENT is defined in CreateEvent() in
665 the Unified Extensible Firmware Interface
667 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
668 APs to return from Procedure, either for
669 blocking or non-blocking mode. Zero means
670 infinity. If the timeout expires before
671 all APs return from Procedure, then Procedure
672 on the failed APs is terminated. All enabled
673 APs are available for next function assigned
674 by MpInitLibStartupAllAPs() or
675 MPInitLibStartupThisAP().
676 If the timeout expires in blocking mode,
677 BSP returns EFI_TIMEOUT. If the timeout
678 expires in non-blocking mode, WaitEvent
679 is signaled with SignalEvent().
680 @param[in] ProcedureArgument The parameter passed into Procedure for
682 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
683 if all APs finish successfully, then its
684 content is set to NULL. If not all APs
685 finish before timeout expires, then its
686 content is set to address of the buffer
687 holding handle numbers of the failed APs.
688 The buffer is allocated by MP Initialization
689 library, and it's the caller's responsibility to
690 free the buffer with FreePool() service.
691 In blocking mode, it is ready for consumption
692 when the call returns. In non-blocking mode,
693 it is ready when WaitEvent is signaled. The
694 list of failed CPU is terminated by
697 @retval EFI_SUCCESS In blocking mode, all APs have finished before
699 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
701 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
702 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
704 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
706 @retval EFI_DEVICE_ERROR Caller processor is AP.
707 @retval EFI_NOT_STARTED No enabled APs exist in the system.
708 @retval EFI_NOT_READY Any enabled APs are busy.
709 @retval EFI_NOT_READY MP Initialize Library is not initialized.
710 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
711 all enabled APs have finished.
712 @retval EFI_INVALID_PARAMETER Procedure is NULL.
717 MpInitLibStartupAllAPs (
718 IN EFI_AP_PROCEDURE Procedure
,
719 IN BOOLEAN SingleThread
,
720 IN EFI_EVENT WaitEvent OPTIONAL
,
721 IN UINTN TimeoutInMicroseconds
,
722 IN VOID
*ProcedureArgument OPTIONAL
,
723 OUT UINTN
**FailedCpuList OPTIONAL
729 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.
731 mStopCheckAllApsStatus
= TRUE
;
733 Status
= StartupAllCPUsWorker (
738 TimeoutInMicroseconds
,
744 // Start checkAllApsStatus
746 mStopCheckAllApsStatus
= FALSE
;
752 This service lets the caller get one enabled AP to execute a caller-provided
755 @param[in] Procedure A pointer to the function to be run on the
756 designated AP of the system. See type
758 @param[in] ProcessorNumber The handle number of the AP. The range is
759 from 0 to the total number of logical
760 processors minus 1. The total number of
761 logical processors can be retrieved by
762 MpInitLibGetNumberOfProcessors().
763 @param[in] WaitEvent The event created by the caller with CreateEvent()
764 service. If it is NULL, then execute in
765 blocking mode. BSP waits until this AP finish
766 or TimeoutInMicroSeconds expires. If it's
767 not NULL, then execute in non-blocking mode.
768 BSP requests the function specified by
769 Procedure to be started on this AP,
770 and go on executing immediately. If this AP
771 return from Procedure or TimeoutInMicroSeconds
772 expires, this event is signaled. The BSP
773 can use the CheckEvent() or WaitForEvent()
774 services to check the state of event. Type
775 EFI_EVENT is defined in CreateEvent() in
776 the Unified Extensible Firmware Interface
778 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
779 this AP to finish this Procedure, either for
780 blocking or non-blocking mode. Zero means
781 infinity. If the timeout expires before
782 this AP returns from Procedure, then Procedure
783 on the AP is terminated. The
784 AP is available for next function assigned
785 by MpInitLibStartupAllAPs() or
786 MpInitLibStartupThisAP().
787 If the timeout expires in blocking mode,
788 BSP returns EFI_TIMEOUT. If the timeout
789 expires in non-blocking mode, WaitEvent
790 is signaled with SignalEvent().
791 @param[in] ProcedureArgument The parameter passed into Procedure on the
793 @param[out] Finished If NULL, this parameter is ignored. In
794 blocking mode, this parameter is ignored.
795 In non-blocking mode, if AP returns from
796 Procedure before the timeout expires, its
797 content is set to TRUE. Otherwise, the
798 value is set to FALSE. The caller can
799 determine if the AP returned from Procedure
800 by evaluating this value.
802 @retval EFI_SUCCESS In blocking mode, specified AP finished before
804 @retval EFI_SUCCESS In non-blocking mode, the function has been
805 dispatched to specified AP.
806 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
807 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
809 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
811 @retval EFI_DEVICE_ERROR The calling processor is an AP.
812 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
813 the specified AP has finished.
814 @retval EFI_NOT_READY The specified AP is busy.
815 @retval EFI_NOT_READY MP Initialize Library is not initialized.
816 @retval EFI_NOT_FOUND The processor with the handle specified by
817 ProcessorNumber does not exist.
818 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
819 @retval EFI_INVALID_PARAMETER Procedure is NULL.
824 MpInitLibStartupThisAP (
825 IN EFI_AP_PROCEDURE Procedure
,
826 IN UINTN ProcessorNumber
,
827 IN EFI_EVENT WaitEvent OPTIONAL
,
828 IN UINTN TimeoutInMicroseconds
,
829 IN VOID
*ProcedureArgument OPTIONAL
,
830 OUT BOOLEAN
*Finished OPTIONAL
836 // temporarily stop checkAllApsStatus for avoid resource dead-lock.
838 mStopCheckAllApsStatus
= TRUE
;
840 Status
= StartupThisAPWorker (
844 TimeoutInMicroseconds
,
849 mStopCheckAllApsStatus
= FALSE
;
855 This service switches the requested AP to be the BSP from that point onward.
856 This service changes the BSP for all purposes. This call can only be performed
859 @param[in] ProcessorNumber The handle number of AP that is to become the new
860 BSP. The range is from 0 to the total number of
861 logical processors minus 1. The total number of
862 logical processors can be retrieved by
863 MpInitLibGetNumberOfProcessors().
864 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
865 enabled AP. Otherwise, it will be disabled.
867 @retval EFI_SUCCESS BSP successfully switched.
868 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
869 this service returning.
870 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
871 @retval EFI_DEVICE_ERROR The calling processor is an AP.
872 @retval EFI_NOT_FOUND The processor with the handle specified by
873 ProcessorNumber does not exist.
874 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
876 @retval EFI_NOT_READY The specified AP is busy.
877 @retval EFI_NOT_READY MP Initialize Library is not initialized.
883 IN UINTN ProcessorNumber
,
884 IN BOOLEAN EnableOldBSP
888 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
893 // Locate Timer Arch Protocol
895 Status
= gBS
->LocateProtocol (&gEfiTimerArchProtocolGuid
, NULL
, (VOID
**)&Timer
);
896 if (EFI_ERROR (Status
)) {
902 // Save current rate of DXE Timer
904 Timer
->GetTimerPeriod (Timer
, &TimerPeriod
);
906 // Disable DXE Timer and drain pending interrupts
908 Timer
->SetTimerPeriod (Timer
, 0);
911 Status
= SwitchBSPWorker (ProcessorNumber
, EnableOldBSP
);
915 // Enable and restore rate of DXE Timer
917 Timer
->SetTimerPeriod (Timer
, TimerPeriod
);
924 This service lets the caller enable or disable an AP from this point onward.
925 This service may only be called from the BSP.
927 @param[in] ProcessorNumber The handle number of AP.
928 The range is from 0 to the total number of
929 logical processors minus 1. The total number of
930 logical processors can be retrieved by
931 MpInitLibGetNumberOfProcessors().
932 @param[in] EnableAP Specifies the new state for the processor for
933 enabled, FALSE for disabled.
934 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
935 the new health status of the AP. This flag
936 corresponds to StatusFlag defined in
937 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
938 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
939 bits are ignored. If it is NULL, this parameter
942 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
943 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
944 prior to this service returning.
945 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
946 @retval EFI_DEVICE_ERROR The calling processor is an AP.
947 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
949 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
950 @retval EFI_NOT_READY MP Initialize Library is not initialized.
955 MpInitLibEnableDisableAP (
956 IN UINTN ProcessorNumber
,
958 IN UINT32
*HealthFlag OPTIONAL
962 BOOLEAN TempStopCheckState
;
964 TempStopCheckState
= FALSE
;
966 // temporarily stop checkAllAPsStatus for initialize parameters.
968 if (!mStopCheckAllApsStatus
) {
969 mStopCheckAllApsStatus
= TRUE
;
970 TempStopCheckState
= TRUE
;
973 Status
= EnableDisableApWorker (ProcessorNumber
, EnableAP
, HealthFlag
);
975 if (TempStopCheckState
) {
976 mStopCheckAllApsStatus
= FALSE
;
983 This funtion will try to invoke platform specific microcode shadow logic to
984 relocate microcode update patches into memory.
986 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
988 @retval EFI_SUCCESS Shadow microcode success.
989 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
990 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
994 PlatformShadowMicrocode (
995 IN OUT CPU_MP_DATA
*CpuMpData
999 // There is no DXE version of platform shadow microcode protocol so far.
1000 // A platform which only uses DxeMpInitLib instance could only supports
1001 // the PCD based microcode shadowing.
1003 return EFI_UNSUPPORTED
;