2 MP initialize support functions for DXE phase.
4 Copyright (c) 2016 - 2020, 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/VmgExitLib.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 VOID
*mReservedApLoopFunc
= NULL
;
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 VmgInit (Ghcb
, &InterruptState
);
226 VmgExit (Ghcb
, SVM_EXIT_AP_JUMP_TABLE
, 0, (UINT64
)(UINTN
)StartAddress
);
227 VmgDone (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 ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc
;
384 UINTN ProcessorNumber
;
387 MpInitLibWhoAmI (&ProcessorNumber
);
388 CpuMpData
= GetCpuMpData ();
389 MwaitSupport
= IsMwaitSupport ();
390 if (CpuMpData
->UseSevEsAPMethod
) {
391 StackStart
= CpuMpData
->SevEsAPResetStackStart
;
393 StackStart
= mReservedTopOfApStack
;
396 AsmRelocateApLoopFunc
= (ASM_RELOCATE_AP_LOOP
)(UINTN
)mReservedApLoopFunc
;
397 AsmRelocateApLoopFunc (
399 CpuMpData
->ApTargetCState
,
400 CpuMpData
->PmCodeSegment
,
401 StackStart
- ProcessorNumber
* AP_SAFE_STACK_SIZE
,
402 (UINTN
)&mNumberToFinish
,
403 CpuMpData
->Pm16CodeSegment
,
404 CpuMpData
->SevEsAPBuffer
,
405 CpuMpData
->WakeupBuffer
408 // It should never reach here
414 Callback function for ExitBootServices.
416 @param[in] Event Event whose notification function is being invoked.
417 @param[in] Context The pointer to the notification function's context,
418 which is implementation-dependent.
423 MpInitChangeApLoopCallback (
428 CPU_MP_DATA
*CpuMpData
;
430 CpuMpData
= GetCpuMpData ();
431 CpuMpData
->PmCodeSegment
= GetProtectedModeCS ();
432 CpuMpData
->Pm16CodeSegment
= GetProtectedMode16CS ();
433 CpuMpData
->ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
434 mNumberToFinish
= CpuMpData
->CpuCount
- 1;
435 WakeUpAP (CpuMpData
, TRUE
, 0, RelocateApLoop
, NULL
, TRUE
);
436 while (mNumberToFinish
> 0) {
440 if (CpuMpData
->UseSevEsAPMethod
&& (CpuMpData
->WakeupBuffer
!= (UINTN
)-1)) {
442 // There are APs present. Re-use reserved memory area below 1MB from
443 // WakeupBuffer as the area to be used for transitioning to 16-bit mode
444 // in support of booting of the AP by an OS.
447 (VOID
*)CpuMpData
->WakeupBuffer
,
448 (VOID
*)(CpuMpData
->AddressMap
.RendezvousFunnelAddress
+
449 CpuMpData
->AddressMap
.SwitchToRealPM16ModeOffset
),
450 CpuMpData
->AddressMap
.SwitchToRealPM16ModeSize
454 DEBUG ((DEBUG_INFO
, "%a() done!\n", __FUNCTION__
));
458 Initialize global data for MP support.
460 @param[in] CpuMpData The pointer to CPU MP Data structure.
464 IN CPU_MP_DATA
*CpuMpData
468 EFI_PHYSICAL_ADDRESS Address
;
469 UINTN ApSafeBufferSize
;
471 EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc
;
473 CPU_INFO_IN_HOB
*CpuInfoInHob
;
475 SaveCpuMpData (CpuMpData
);
477 if (CpuMpData
->CpuCount
== 1) {
479 // If only BSP exists, return
484 if (PcdGetBool (PcdCpuStackGuard
)) {
486 // One extra page at the bottom of the stack is needed for Guard page.
488 if (CpuMpData
->CpuApStackSize
<= EFI_PAGE_SIZE
) {
489 DEBUG ((DEBUG_ERROR
, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));
494 // DXE will reuse stack allocated for APs at PEI phase if it's available.
495 // Let's check it here.
497 // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of
498 // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be
501 CpuInfoInHob
= (CPU_INFO_IN_HOB
*)(UINTN
)CpuMpData
->CpuInfoInHob
;
502 for (Index
= 0; Index
< CpuMpData
->CpuCount
; ++Index
) {
503 if ((CpuInfoInHob
!= NULL
) && (CpuInfoInHob
[Index
].ApTopOfStack
!= 0)) {
504 StackBase
= (UINTN
)CpuInfoInHob
[Index
].ApTopOfStack
- CpuMpData
->CpuApStackSize
;
506 StackBase
= CpuMpData
->Buffer
+ Index
* CpuMpData
->CpuApStackSize
;
509 Status
= gDS
->GetMemorySpaceDescriptor (StackBase
, &MemDesc
);
510 ASSERT_EFI_ERROR (Status
);
512 Status
= gDS
->SetMemorySpaceAttributes (
514 EFI_PAGES_TO_SIZE (1),
515 MemDesc
.Attributes
| EFI_MEMORY_RP
517 ASSERT_EFI_ERROR (Status
);
521 "Stack Guard set at %lx [cpu%lu]!\n",
529 // Avoid APs access invalid buffer data which allocated by BootServices,
530 // so we will allocate reserved data for AP loop code. We also need to
531 // allocate this buffer below 4GB due to APs may be transferred to 32bit
532 // protected mode on long mode DXE.
533 // Allocating it in advance since memory services are not available in
534 // Exit Boot Services callback function.
536 ApSafeBufferSize
= EFI_PAGES_TO_SIZE (
538 CpuMpData
->AddressMap
.RelocateApLoopFuncSize
541 Address
= BASE_4GB
- 1;
542 Status
= gBS
->AllocatePages (
544 EfiReservedMemoryType
,
545 EFI_SIZE_TO_PAGES (ApSafeBufferSize
),
548 ASSERT_EFI_ERROR (Status
);
550 mReservedApLoopFunc
= (VOID
*)(UINTN
)Address
;
551 ASSERT (mReservedApLoopFunc
!= NULL
);
554 // Make sure that the buffer memory is executable if NX protection is enabled
555 // for EfiReservedMemoryType.
557 // TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD
560 Status
= gDS
->GetMemorySpaceDescriptor (Address
, &MemDesc
);
561 if (!EFI_ERROR (Status
)) {
562 gDS
->SetMemorySpaceAttributes (
565 MemDesc
.Attributes
& (~EFI_MEMORY_XP
)
569 ApSafeBufferSize
= EFI_PAGES_TO_SIZE (
571 CpuMpData
->CpuCount
* AP_SAFE_STACK_SIZE
574 Address
= BASE_4GB
- 1;
575 Status
= gBS
->AllocatePages (
577 EfiReservedMemoryType
,
578 EFI_SIZE_TO_PAGES (ApSafeBufferSize
),
581 ASSERT_EFI_ERROR (Status
);
583 mReservedTopOfApStack
= (UINTN
)Address
+ ApSafeBufferSize
;
584 ASSERT ((mReservedTopOfApStack
& (UINTN
)(CPU_STACK_ALIGNMENT
- 1)) == 0);
587 CpuMpData
->AddressMap
.RelocateApLoopFuncAddress
,
588 CpuMpData
->AddressMap
.RelocateApLoopFuncSize
591 Status
= gBS
->CreateEvent (
592 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
598 ASSERT_EFI_ERROR (Status
);
601 // Set timer to check all APs status.
603 Status
= gBS
->SetTimer (
606 EFI_TIMER_PERIOD_MICROSECONDS (
607 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds
)
610 ASSERT_EFI_ERROR (Status
);
612 Status
= gBS
->CreateEvent (
613 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
615 MpInitChangeApLoopCallback
,
617 &mMpInitExitBootServicesEvent
619 ASSERT_EFI_ERROR (Status
);
621 Status
= gBS
->CreateEventEx (
624 MpInitChangeApLoopCallback
,
626 &gEfiEventLegacyBootGuid
,
629 ASSERT_EFI_ERROR (Status
);
633 This service executes a caller provided function on all enabled APs.
635 @param[in] Procedure A pointer to the function to be run on
636 enabled APs of the system. See type
638 @param[in] SingleThread If TRUE, then all the enabled APs execute
639 the function specified by Procedure one by
640 one, in ascending order of processor handle
641 number. If FALSE, then all the enabled APs
642 execute the function specified by Procedure
644 @param[in] WaitEvent The event created by the caller with CreateEvent()
645 service. If it is NULL, then execute in
646 blocking mode. BSP waits until all APs finish
647 or TimeoutInMicroSeconds expires. If it's
648 not NULL, then execute in non-blocking mode.
649 BSP requests the function specified by
650 Procedure to be started on all the enabled
651 APs, and go on executing immediately. If
652 all return from Procedure, or TimeoutInMicroSeconds
653 expires, this event is signaled. The BSP
654 can use the CheckEvent() or WaitForEvent()
655 services to check the state of event. Type
656 EFI_EVENT is defined in CreateEvent() in
657 the Unified Extensible Firmware Interface
659 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
660 APs to return from Procedure, either for
661 blocking or non-blocking mode. Zero means
662 infinity. If the timeout expires before
663 all APs return from Procedure, then Procedure
664 on the failed APs is terminated. All enabled
665 APs are available for next function assigned
666 by MpInitLibStartupAllAPs() or
667 MPInitLibStartupThisAP().
668 If the timeout expires in blocking mode,
669 BSP returns EFI_TIMEOUT. If the timeout
670 expires in non-blocking mode, WaitEvent
671 is signaled with SignalEvent().
672 @param[in] ProcedureArgument The parameter passed into Procedure for
674 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
675 if all APs finish successfully, then its
676 content is set to NULL. If not all APs
677 finish before timeout expires, then its
678 content is set to address of the buffer
679 holding handle numbers of the failed APs.
680 The buffer is allocated by MP Initialization
681 library, and it's the caller's responsibility to
682 free the buffer with FreePool() service.
683 In blocking mode, it is ready for consumption
684 when the call returns. In non-blocking mode,
685 it is ready when WaitEvent is signaled. The
686 list of failed CPU is terminated by
689 @retval EFI_SUCCESS In blocking mode, all APs have finished before
691 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
693 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
694 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
696 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
698 @retval EFI_DEVICE_ERROR Caller processor is AP.
699 @retval EFI_NOT_STARTED No enabled APs exist in the system.
700 @retval EFI_NOT_READY Any enabled APs are busy.
701 @retval EFI_NOT_READY MP Initialize Library is not initialized.
702 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
703 all enabled APs have finished.
704 @retval EFI_INVALID_PARAMETER Procedure is NULL.
709 MpInitLibStartupAllAPs (
710 IN EFI_AP_PROCEDURE Procedure
,
711 IN BOOLEAN SingleThread
,
712 IN EFI_EVENT WaitEvent OPTIONAL
,
713 IN UINTN TimeoutInMicroseconds
,
714 IN VOID
*ProcedureArgument OPTIONAL
,
715 OUT UINTN
**FailedCpuList OPTIONAL
721 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.
723 mStopCheckAllApsStatus
= TRUE
;
725 Status
= StartupAllCPUsWorker (
730 TimeoutInMicroseconds
,
736 // Start checkAllApsStatus
738 mStopCheckAllApsStatus
= FALSE
;
744 This service lets the caller get one enabled AP to execute a caller-provided
747 @param[in] Procedure A pointer to the function to be run on the
748 designated AP of the system. See type
750 @param[in] ProcessorNumber The handle number of the AP. The range is
751 from 0 to the total number of logical
752 processors minus 1. The total number of
753 logical processors can be retrieved by
754 MpInitLibGetNumberOfProcessors().
755 @param[in] WaitEvent The event created by the caller with CreateEvent()
756 service. If it is NULL, then execute in
757 blocking mode. BSP waits until this AP finish
758 or TimeoutInMicroSeconds expires. If it's
759 not NULL, then execute in non-blocking mode.
760 BSP requests the function specified by
761 Procedure to be started on this AP,
762 and go on executing immediately. If this AP
763 return from Procedure or TimeoutInMicroSeconds
764 expires, this event is signaled. The BSP
765 can use the CheckEvent() or WaitForEvent()
766 services to check the state of event. Type
767 EFI_EVENT is defined in CreateEvent() in
768 the Unified Extensible Firmware Interface
770 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
771 this AP to finish this Procedure, either for
772 blocking or non-blocking mode. Zero means
773 infinity. If the timeout expires before
774 this AP returns from Procedure, then Procedure
775 on the AP is terminated. The
776 AP is available for next function assigned
777 by MpInitLibStartupAllAPs() or
778 MpInitLibStartupThisAP().
779 If the timeout expires in blocking mode,
780 BSP returns EFI_TIMEOUT. If the timeout
781 expires in non-blocking mode, WaitEvent
782 is signaled with SignalEvent().
783 @param[in] ProcedureArgument The parameter passed into Procedure on the
785 @param[out] Finished If NULL, this parameter is ignored. In
786 blocking mode, this parameter is ignored.
787 In non-blocking mode, if AP returns from
788 Procedure before the timeout expires, its
789 content is set to TRUE. Otherwise, the
790 value is set to FALSE. The caller can
791 determine if the AP returned from Procedure
792 by evaluating this value.
794 @retval EFI_SUCCESS In blocking mode, specified AP finished before
796 @retval EFI_SUCCESS In non-blocking mode, the function has been
797 dispatched to specified AP.
798 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
799 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
801 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
803 @retval EFI_DEVICE_ERROR The calling processor is an AP.
804 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
805 the specified AP has finished.
806 @retval EFI_NOT_READY The specified AP is busy.
807 @retval EFI_NOT_READY MP Initialize Library is not initialized.
808 @retval EFI_NOT_FOUND The processor with the handle specified by
809 ProcessorNumber does not exist.
810 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
811 @retval EFI_INVALID_PARAMETER Procedure is NULL.
816 MpInitLibStartupThisAP (
817 IN EFI_AP_PROCEDURE Procedure
,
818 IN UINTN ProcessorNumber
,
819 IN EFI_EVENT WaitEvent OPTIONAL
,
820 IN UINTN TimeoutInMicroseconds
,
821 IN VOID
*ProcedureArgument OPTIONAL
,
822 OUT BOOLEAN
*Finished OPTIONAL
828 // temporarily stop checkAllApsStatus for avoid resource dead-lock.
830 mStopCheckAllApsStatus
= TRUE
;
832 Status
= StartupThisAPWorker (
836 TimeoutInMicroseconds
,
841 mStopCheckAllApsStatus
= FALSE
;
847 This service switches the requested AP to be the BSP from that point onward.
848 This service changes the BSP for all purposes. This call can only be performed
851 @param[in] ProcessorNumber The handle number of AP that is to become the new
852 BSP. The range is from 0 to the total number of
853 logical processors minus 1. The total number of
854 logical processors can be retrieved by
855 MpInitLibGetNumberOfProcessors().
856 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
857 enabled AP. Otherwise, it will be disabled.
859 @retval EFI_SUCCESS BSP successfully switched.
860 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
861 this service returning.
862 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
863 @retval EFI_DEVICE_ERROR The calling processor is an AP.
864 @retval EFI_NOT_FOUND The processor with the handle specified by
865 ProcessorNumber does not exist.
866 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
868 @retval EFI_NOT_READY The specified AP is busy.
869 @retval EFI_NOT_READY MP Initialize Library is not initialized.
875 IN UINTN ProcessorNumber
,
876 IN BOOLEAN EnableOldBSP
880 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
885 // Locate Timer Arch Protocol
887 Status
= gBS
->LocateProtocol (&gEfiTimerArchProtocolGuid
, NULL
, (VOID
**)&Timer
);
888 if (EFI_ERROR (Status
)) {
894 // Save current rate of DXE Timer
896 Timer
->GetTimerPeriod (Timer
, &TimerPeriod
);
898 // Disable DXE Timer and drain pending interrupts
900 Timer
->SetTimerPeriod (Timer
, 0);
903 Status
= SwitchBSPWorker (ProcessorNumber
, EnableOldBSP
);
907 // Enable and restore rate of DXE Timer
909 Timer
->SetTimerPeriod (Timer
, TimerPeriod
);
916 This service lets the caller enable or disable an AP from this point onward.
917 This service may only be called from the BSP.
919 @param[in] ProcessorNumber The handle number of AP.
920 The range is from 0 to the total number of
921 logical processors minus 1. The total number of
922 logical processors can be retrieved by
923 MpInitLibGetNumberOfProcessors().
924 @param[in] EnableAP Specifies the new state for the processor for
925 enabled, FALSE for disabled.
926 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
927 the new health status of the AP. This flag
928 corresponds to StatusFlag defined in
929 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
930 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
931 bits are ignored. If it is NULL, this parameter
934 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
935 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
936 prior to this service returning.
937 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
938 @retval EFI_DEVICE_ERROR The calling processor is an AP.
939 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
941 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
942 @retval EFI_NOT_READY MP Initialize Library is not initialized.
947 MpInitLibEnableDisableAP (
948 IN UINTN ProcessorNumber
,
950 IN UINT32
*HealthFlag OPTIONAL
954 BOOLEAN TempStopCheckState
;
956 TempStopCheckState
= FALSE
;
958 // temporarily stop checkAllAPsStatus for initialize parameters.
960 if (!mStopCheckAllApsStatus
) {
961 mStopCheckAllApsStatus
= TRUE
;
962 TempStopCheckState
= TRUE
;
965 Status
= EnableDisableApWorker (ProcessorNumber
, EnableAP
, HealthFlag
);
967 if (TempStopCheckState
) {
968 mStopCheckAllApsStatus
= FALSE
;
975 This funtion will try to invoke platform specific microcode shadow logic to
976 relocate microcode update patches into memory.
978 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
980 @retval EFI_SUCCESS Shadow microcode success.
981 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
982 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
986 PlatformShadowMicrocode (
987 IN OUT CPU_MP_DATA
*CpuMpData
991 // There is no DXE version of platform shadow microcode protocol so far.
992 // A platform which only uses DxeMpInitLib instance could only supports
993 // the PCD based microcode shadowing.
995 return EFI_UNSUPPORTED
;