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 (PcdGetBool (PcdSevEsIsEnabled
)) {
97 MemoryType
= EfiReservedMemoryType
;
99 MemoryType
= EfiBootServicesData
;
103 // Try to allocate buffer below 1M for waking vector.
104 // LegacyBios driver only reports warning when page allocation in range
105 // [0x60000, 0x88000) fails.
106 // This library is consumed by CpuDxe driver to produce CPU Arch protocol.
107 // LagacyBios driver depends on CPU Arch protocol which guarantees below
108 // allocation runs earlier than LegacyBios driver.
110 if (PcdGetBool (PcdSevEsIsEnabled
)) {
112 // SEV-ES Wakeup buffer should be under 0x88000 and under any previous one
114 StartAddress
= mSevEsDxeWakeupBuffer
;
116 StartAddress
= 0x88000;
119 Status
= gBS
->AllocatePages (
122 EFI_SIZE_TO_PAGES (WakeupBufferSize
),
125 ASSERT_EFI_ERROR (Status
);
126 if (EFI_ERROR (Status
)) {
127 StartAddress
= (EFI_PHYSICAL_ADDRESS
)-1;
128 } else if (PcdGetBool (PcdSevEsIsEnabled
)) {
130 // Next SEV-ES wakeup buffer allocation must be below this allocation
132 mSevEsDxeWakeupBuffer
= StartAddress
;
137 "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
142 return (UINTN
)StartAddress
;
146 Get available EfiBootServicesCode memory below 4GB by specified size.
148 This buffer is required to safely transfer AP from real address mode to
149 protected mode or long mode, due to the fact that the buffer returned by
150 GetWakeupBuffer() may be marked as non-executable.
152 @param[in] BufferSize Wakeup transition buffer size.
154 @retval other Return wakeup transition buffer address below 4GB.
155 @retval 0 Cannot find free memory below 4GB.
158 GetModeTransitionBuffer (
163 EFI_PHYSICAL_ADDRESS StartAddress
;
165 StartAddress
= BASE_4GB
- 1;
166 Status
= gBS
->AllocatePages (
169 EFI_SIZE_TO_PAGES (BufferSize
),
172 if (EFI_ERROR (Status
)) {
176 return (UINTN
)StartAddress
;
180 Return the address of the SEV-ES AP jump table.
182 This buffer is required in order for an SEV-ES guest to transition from
185 @return Return SEV-ES AP jump table buffer
193 EFI_PHYSICAL_ADDRESS StartAddress
;
194 MSR_SEV_ES_GHCB_REGISTER Msr
;
196 BOOLEAN InterruptState
;
199 // Allocate 1 page for AP jump table page
201 StartAddress
= BASE_4GB
- 1;
202 Status
= gBS
->AllocatePages (
204 EfiReservedMemoryType
,
208 ASSERT_EFI_ERROR (Status
);
210 DEBUG ((DEBUG_INFO
, "Dxe: SevEsAPMemory = %lx\n", (UINTN
)StartAddress
));
213 // Save the SevEsAPMemory as the AP jump table.
215 Msr
.GhcbPhysicalAddress
= AsmReadMsr64 (MSR_SEV_ES_GHCB
);
218 VmgInit (Ghcb
, &InterruptState
);
219 VmgExit (Ghcb
, SVM_EXIT_AP_JUMP_TABLE
, 0, (UINT64
)(UINTN
)StartAddress
);
220 VmgDone (Ghcb
, InterruptState
);
222 return (UINTN
)StartAddress
;
226 Checks APs status and updates APs status if needed.
230 CheckAndUpdateApsStatus (
234 UINTN ProcessorNumber
;
236 CPU_MP_DATA
*CpuMpData
;
238 CpuMpData
= GetCpuMpData ();
241 // First, check whether pending StartupAllAPs() exists.
243 if (CpuMpData
->WaitEvent
!= NULL
) {
244 Status
= CheckAllAPs ();
246 // If all APs finish for StartupAllAPs(), signal the WaitEvent for it.
248 if (Status
!= EFI_NOT_READY
) {
249 Status
= gBS
->SignalEvent (CpuMpData
->WaitEvent
);
250 CpuMpData
->WaitEvent
= NULL
;
255 // Second, check whether pending StartupThisAPs() callings exist.
257 for (ProcessorNumber
= 0; ProcessorNumber
< CpuMpData
->CpuCount
; ProcessorNumber
++) {
258 if (CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
== NULL
) {
262 Status
= CheckThisAP (ProcessorNumber
);
264 if (Status
!= EFI_NOT_READY
) {
265 gBS
->SignalEvent (CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
);
266 CpuMpData
->CpuData
[ProcessorNumber
].WaitEvent
= NULL
;
272 Checks APs' status periodically.
274 This function is triggered by timer periodically to check the
275 state of APs for StartupAllAPs() and StartupThisAP() executed
276 in non-blocking mode.
278 @param[in] Event Event triggered.
279 @param[in] Context Parameter passed with the event.
290 // If CheckApsStatus() is not stopped, otherwise return immediately.
292 if (!mStopCheckAllApsStatus
) {
293 CheckAndUpdateApsStatus ();
298 Get Protected mode code segment with 16-bit default addressing
299 from current GDT table.
301 @return Protected mode 16-bit code segment value.
304 GetProtectedMode16CS (
308 IA32_DESCRIPTOR GdtrDesc
;
309 IA32_SEGMENT_DESCRIPTOR
*GdtEntry
;
314 AsmReadGdtr (&GdtrDesc
);
315 GdtEntryCount
= (GdtrDesc
.Limit
+ 1) / sizeof (IA32_SEGMENT_DESCRIPTOR
);
316 GdtEntry
= (IA32_SEGMENT_DESCRIPTOR
*)GdtrDesc
.Base
;
317 for (Index
= 0; Index
< GdtEntryCount
; Index
++) {
318 if (GdtEntry
->Bits
.L
== 0) {
319 if ((GdtEntry
->Bits
.Type
> 8) && (GdtEntry
->Bits
.DB
== 0)) {
327 ASSERT (Index
!= GdtEntryCount
);
332 Get Protected mode code segment from current GDT table.
334 @return Protected mode code segment value.
341 IA32_DESCRIPTOR GdtrDesc
;
342 IA32_SEGMENT_DESCRIPTOR
*GdtEntry
;
346 AsmReadGdtr (&GdtrDesc
);
347 GdtEntryCount
= (GdtrDesc
.Limit
+ 1) / sizeof (IA32_SEGMENT_DESCRIPTOR
);
348 GdtEntry
= (IA32_SEGMENT_DESCRIPTOR
*)GdtrDesc
.Base
;
349 for (Index
= 0; Index
< GdtEntryCount
; Index
++) {
350 if (GdtEntry
->Bits
.L
== 0) {
351 if ((GdtEntry
->Bits
.Type
> 8) && (GdtEntry
->Bits
.DB
== 1)) {
359 ASSERT (Index
!= GdtEntryCount
);
366 @param[in, out] Buffer Pointer to private data buffer.
374 CPU_MP_DATA
*CpuMpData
;
375 BOOLEAN MwaitSupport
;
376 ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc
;
377 UINTN ProcessorNumber
;
380 MpInitLibWhoAmI (&ProcessorNumber
);
381 CpuMpData
= GetCpuMpData ();
382 MwaitSupport
= IsMwaitSupport ();
383 if (CpuMpData
->SevEsIsEnabled
) {
384 StackStart
= CpuMpData
->SevEsAPResetStackStart
;
386 StackStart
= mReservedTopOfApStack
;
389 AsmRelocateApLoopFunc
= (ASM_RELOCATE_AP_LOOP
)(UINTN
)mReservedApLoopFunc
;
390 AsmRelocateApLoopFunc (
392 CpuMpData
->ApTargetCState
,
393 CpuMpData
->PmCodeSegment
,
394 StackStart
- ProcessorNumber
* AP_SAFE_STACK_SIZE
,
395 (UINTN
)&mNumberToFinish
,
396 CpuMpData
->Pm16CodeSegment
,
397 CpuMpData
->SevEsAPBuffer
,
398 CpuMpData
->WakeupBuffer
401 // It should never reach here
407 Callback function for ExitBootServices.
409 @param[in] Event Event whose notification function is being invoked.
410 @param[in] Context The pointer to the notification function's context,
411 which is implementation-dependent.
416 MpInitChangeApLoopCallback (
421 CPU_MP_DATA
*CpuMpData
;
423 CpuMpData
= GetCpuMpData ();
424 CpuMpData
->PmCodeSegment
= GetProtectedModeCS ();
425 CpuMpData
->Pm16CodeSegment
= GetProtectedMode16CS ();
426 CpuMpData
->ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
427 mNumberToFinish
= CpuMpData
->CpuCount
- 1;
428 WakeUpAP (CpuMpData
, TRUE
, 0, RelocateApLoop
, NULL
, TRUE
);
429 while (mNumberToFinish
> 0) {
433 if (CpuMpData
->SevEsIsEnabled
&& (CpuMpData
->WakeupBuffer
!= (UINTN
)-1)) {
435 // There are APs present. Re-use reserved memory area below 1MB from
436 // WakeupBuffer as the area to be used for transitioning to 16-bit mode
437 // in support of booting of the AP by an OS.
440 (VOID
*)CpuMpData
->WakeupBuffer
,
441 (VOID
*)(CpuMpData
->AddressMap
.RendezvousFunnelAddress
+
442 CpuMpData
->AddressMap
.SwitchToRealPM16ModeOffset
),
443 CpuMpData
->AddressMap
.SwitchToRealPM16ModeSize
447 DEBUG ((DEBUG_INFO
, "%a() done!\n", __FUNCTION__
));
451 Initialize global data for MP support.
453 @param[in] CpuMpData The pointer to CPU MP Data structure.
457 IN CPU_MP_DATA
*CpuMpData
461 EFI_PHYSICAL_ADDRESS Address
;
462 UINTN ApSafeBufferSize
;
464 EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc
;
466 CPU_INFO_IN_HOB
*CpuInfoInHob
;
468 SaveCpuMpData (CpuMpData
);
470 if (CpuMpData
->CpuCount
== 1) {
472 // If only BSP exists, return
477 if (PcdGetBool (PcdCpuStackGuard
)) {
479 // One extra page at the bottom of the stack is needed for Guard page.
481 if (CpuMpData
->CpuApStackSize
<= EFI_PAGE_SIZE
) {
482 DEBUG ((DEBUG_ERROR
, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));
487 // DXE will reuse stack allocated for APs at PEI phase if it's available.
488 // Let's check it here.
490 // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of
491 // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be
494 CpuInfoInHob
= (CPU_INFO_IN_HOB
*)(UINTN
)CpuMpData
->CpuInfoInHob
;
495 for (Index
= 0; Index
< CpuMpData
->CpuCount
; ++Index
) {
496 if ((CpuInfoInHob
!= NULL
) && (CpuInfoInHob
[Index
].ApTopOfStack
!= 0)) {
497 StackBase
= (UINTN
)CpuInfoInHob
[Index
].ApTopOfStack
- CpuMpData
->CpuApStackSize
;
499 StackBase
= CpuMpData
->Buffer
+ Index
* CpuMpData
->CpuApStackSize
;
502 Status
= gDS
->GetMemorySpaceDescriptor (StackBase
, &MemDesc
);
503 ASSERT_EFI_ERROR (Status
);
505 Status
= gDS
->SetMemorySpaceAttributes (
507 EFI_PAGES_TO_SIZE (1),
508 MemDesc
.Attributes
| EFI_MEMORY_RP
510 ASSERT_EFI_ERROR (Status
);
514 "Stack Guard set at %lx [cpu%lu]!\n",
522 // Avoid APs access invalid buffer data which allocated by BootServices,
523 // so we will allocate reserved data for AP loop code. We also need to
524 // allocate this buffer below 4GB due to APs may be transferred to 32bit
525 // protected mode on long mode DXE.
526 // Allocating it in advance since memory services are not available in
527 // Exit Boot Services callback function.
529 ApSafeBufferSize
= EFI_PAGES_TO_SIZE (
531 CpuMpData
->AddressMap
.RelocateApLoopFuncSize
534 Address
= BASE_4GB
- 1;
535 Status
= gBS
->AllocatePages (
537 EfiReservedMemoryType
,
538 EFI_SIZE_TO_PAGES (ApSafeBufferSize
),
541 ASSERT_EFI_ERROR (Status
);
543 mReservedApLoopFunc
= (VOID
*)(UINTN
)Address
;
544 ASSERT (mReservedApLoopFunc
!= NULL
);
547 // Make sure that the buffer memory is executable if NX protection is enabled
548 // for EfiReservedMemoryType.
550 // TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD
553 Status
= gDS
->GetMemorySpaceDescriptor (Address
, &MemDesc
);
554 if (!EFI_ERROR (Status
)) {
555 gDS
->SetMemorySpaceAttributes (
558 MemDesc
.Attributes
& (~EFI_MEMORY_XP
)
562 ApSafeBufferSize
= EFI_PAGES_TO_SIZE (
564 CpuMpData
->CpuCount
* AP_SAFE_STACK_SIZE
567 Address
= BASE_4GB
- 1;
568 Status
= gBS
->AllocatePages (
570 EfiReservedMemoryType
,
571 EFI_SIZE_TO_PAGES (ApSafeBufferSize
),
574 ASSERT_EFI_ERROR (Status
);
576 mReservedTopOfApStack
= (UINTN
)Address
+ ApSafeBufferSize
;
577 ASSERT ((mReservedTopOfApStack
& (UINTN
)(CPU_STACK_ALIGNMENT
- 1)) == 0);
580 CpuMpData
->AddressMap
.RelocateApLoopFuncAddress
,
581 CpuMpData
->AddressMap
.RelocateApLoopFuncSize
584 Status
= gBS
->CreateEvent (
585 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
591 ASSERT_EFI_ERROR (Status
);
594 // Set timer to check all APs status.
596 Status
= gBS
->SetTimer (
599 EFI_TIMER_PERIOD_MICROSECONDS (
600 PcdGet32 (PcdCpuApStatusCheckIntervalInMicroSeconds
)
603 ASSERT_EFI_ERROR (Status
);
605 Status
= gBS
->CreateEvent (
606 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
608 MpInitChangeApLoopCallback
,
610 &mMpInitExitBootServicesEvent
612 ASSERT_EFI_ERROR (Status
);
614 Status
= gBS
->CreateEventEx (
617 MpInitChangeApLoopCallback
,
619 &gEfiEventLegacyBootGuid
,
622 ASSERT_EFI_ERROR (Status
);
626 This service executes a caller provided function on all enabled APs.
628 @param[in] Procedure A pointer to the function to be run on
629 enabled APs of the system. See type
631 @param[in] SingleThread If TRUE, then all the enabled APs execute
632 the function specified by Procedure one by
633 one, in ascending order of processor handle
634 number. If FALSE, then all the enabled APs
635 execute the function specified by Procedure
637 @param[in] WaitEvent The event created by the caller with CreateEvent()
638 service. If it is NULL, then execute in
639 blocking mode. BSP waits until all APs finish
640 or TimeoutInMicroSeconds expires. If it's
641 not NULL, then execute in non-blocking mode.
642 BSP requests the function specified by
643 Procedure to be started on all the enabled
644 APs, and go on executing immediately. If
645 all return from Procedure, or TimeoutInMicroSeconds
646 expires, this event is signaled. The BSP
647 can use the CheckEvent() or WaitForEvent()
648 services to check the state of event. Type
649 EFI_EVENT is defined in CreateEvent() in
650 the Unified Extensible Firmware Interface
652 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
653 APs to return from Procedure, either for
654 blocking or non-blocking mode. Zero means
655 infinity. If the timeout expires before
656 all APs return from Procedure, then Procedure
657 on the failed APs is terminated. All enabled
658 APs are available for next function assigned
659 by MpInitLibStartupAllAPs() or
660 MPInitLibStartupThisAP().
661 If the timeout expires in blocking mode,
662 BSP returns EFI_TIMEOUT. If the timeout
663 expires in non-blocking mode, WaitEvent
664 is signaled with SignalEvent().
665 @param[in] ProcedureArgument The parameter passed into Procedure for
667 @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,
668 if all APs finish successfully, then its
669 content is set to NULL. If not all APs
670 finish before timeout expires, then its
671 content is set to address of the buffer
672 holding handle numbers of the failed APs.
673 The buffer is allocated by MP Initialization
674 library, and it's the caller's responsibility to
675 free the buffer with FreePool() service.
676 In blocking mode, it is ready for consumption
677 when the call returns. In non-blocking mode,
678 it is ready when WaitEvent is signaled. The
679 list of failed CPU is terminated by
682 @retval EFI_SUCCESS In blocking mode, all APs have finished before
684 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched
686 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
687 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
689 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
691 @retval EFI_DEVICE_ERROR Caller processor is AP.
692 @retval EFI_NOT_STARTED No enabled APs exist in the system.
693 @retval EFI_NOT_READY Any enabled APs are busy.
694 @retval EFI_NOT_READY MP Initialize Library is not initialized.
695 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
696 all enabled APs have finished.
697 @retval EFI_INVALID_PARAMETER Procedure is NULL.
702 MpInitLibStartupAllAPs (
703 IN EFI_AP_PROCEDURE Procedure
,
704 IN BOOLEAN SingleThread
,
705 IN EFI_EVENT WaitEvent OPTIONAL
,
706 IN UINTN TimeoutInMicroseconds
,
707 IN VOID
*ProcedureArgument OPTIONAL
,
708 OUT UINTN
**FailedCpuList OPTIONAL
714 // Temporarily stop checkAllApsStatus for avoid resource dead-lock.
716 mStopCheckAllApsStatus
= TRUE
;
718 Status
= StartupAllCPUsWorker (
723 TimeoutInMicroseconds
,
729 // Start checkAllApsStatus
731 mStopCheckAllApsStatus
= FALSE
;
737 This service lets the caller get one enabled AP to execute a caller-provided
740 @param[in] Procedure A pointer to the function to be run on the
741 designated AP of the system. See type
743 @param[in] ProcessorNumber The handle number of the AP. The range is
744 from 0 to the total number of logical
745 processors minus 1. The total number of
746 logical processors can be retrieved by
747 MpInitLibGetNumberOfProcessors().
748 @param[in] WaitEvent The event created by the caller with CreateEvent()
749 service. If it is NULL, then execute in
750 blocking mode. BSP waits until this AP finish
751 or TimeoutInMicroSeconds expires. If it's
752 not NULL, then execute in non-blocking mode.
753 BSP requests the function specified by
754 Procedure to be started on this AP,
755 and go on executing immediately. If this AP
756 return from Procedure or TimeoutInMicroSeconds
757 expires, this event is signaled. The BSP
758 can use the CheckEvent() or WaitForEvent()
759 services to check the state of event. Type
760 EFI_EVENT is defined in CreateEvent() in
761 the Unified Extensible Firmware Interface
763 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for
764 this AP to finish this Procedure, either for
765 blocking or non-blocking mode. Zero means
766 infinity. If the timeout expires before
767 this AP returns from Procedure, then Procedure
768 on the AP is terminated. The
769 AP is available for next function assigned
770 by MpInitLibStartupAllAPs() or
771 MpInitLibStartupThisAP().
772 If the timeout expires in blocking mode,
773 BSP returns EFI_TIMEOUT. If the timeout
774 expires in non-blocking mode, WaitEvent
775 is signaled with SignalEvent().
776 @param[in] ProcedureArgument The parameter passed into Procedure on the
778 @param[out] Finished If NULL, this parameter is ignored. In
779 blocking mode, this parameter is ignored.
780 In non-blocking mode, if AP returns from
781 Procedure before the timeout expires, its
782 content is set to TRUE. Otherwise, the
783 value is set to FALSE. The caller can
784 determine if the AP returned from Procedure
785 by evaluating this value.
787 @retval EFI_SUCCESS In blocking mode, specified AP finished before
789 @retval EFI_SUCCESS In non-blocking mode, the function has been
790 dispatched to specified AP.
791 @retval EFI_UNSUPPORTED A non-blocking mode request was made after the
792 UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
794 @retval EFI_UNSUPPORTED WaitEvent is not NULL if non-blocking mode is not
796 @retval EFI_DEVICE_ERROR The calling processor is an AP.
797 @retval EFI_TIMEOUT In blocking mode, the timeout expired before
798 the specified AP has finished.
799 @retval EFI_NOT_READY The specified AP is busy.
800 @retval EFI_NOT_READY MP Initialize Library is not initialized.
801 @retval EFI_NOT_FOUND The processor with the handle specified by
802 ProcessorNumber does not exist.
803 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
804 @retval EFI_INVALID_PARAMETER Procedure is NULL.
809 MpInitLibStartupThisAP (
810 IN EFI_AP_PROCEDURE Procedure
,
811 IN UINTN ProcessorNumber
,
812 IN EFI_EVENT WaitEvent OPTIONAL
,
813 IN UINTN TimeoutInMicroseconds
,
814 IN VOID
*ProcedureArgument OPTIONAL
,
815 OUT BOOLEAN
*Finished OPTIONAL
821 // temporarily stop checkAllApsStatus for avoid resource dead-lock.
823 mStopCheckAllApsStatus
= TRUE
;
825 Status
= StartupThisAPWorker (
829 TimeoutInMicroseconds
,
834 mStopCheckAllApsStatus
= FALSE
;
840 This service switches the requested AP to be the BSP from that point onward.
841 This service changes the BSP for all purposes. This call can only be performed
844 @param[in] ProcessorNumber The handle number of AP that is to become the new
845 BSP. The range is from 0 to the total number of
846 logical processors minus 1. The total number of
847 logical processors can be retrieved by
848 MpInitLibGetNumberOfProcessors().
849 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an
850 enabled AP. Otherwise, it will be disabled.
852 @retval EFI_SUCCESS BSP successfully switched.
853 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to
854 this service returning.
855 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
856 @retval EFI_DEVICE_ERROR The calling processor is an AP.
857 @retval EFI_NOT_FOUND The processor with the handle specified by
858 ProcessorNumber does not exist.
859 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or
861 @retval EFI_NOT_READY The specified AP is busy.
862 @retval EFI_NOT_READY MP Initialize Library is not initialized.
868 IN UINTN ProcessorNumber
,
869 IN BOOLEAN EnableOldBSP
873 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
878 // Locate Timer Arch Protocol
880 Status
= gBS
->LocateProtocol (&gEfiTimerArchProtocolGuid
, NULL
, (VOID
**)&Timer
);
881 if (EFI_ERROR (Status
)) {
887 // Save current rate of DXE Timer
889 Timer
->GetTimerPeriod (Timer
, &TimerPeriod
);
891 // Disable DXE Timer and drain pending interrupts
893 Timer
->SetTimerPeriod (Timer
, 0);
896 Status
= SwitchBSPWorker (ProcessorNumber
, EnableOldBSP
);
900 // Enable and restore rate of DXE Timer
902 Timer
->SetTimerPeriod (Timer
, TimerPeriod
);
909 This service lets the caller enable or disable an AP from this point onward.
910 This service may only be called from the BSP.
912 @param[in] ProcessorNumber The handle number of AP.
913 The range is from 0 to the total number of
914 logical processors minus 1. The total number of
915 logical processors can be retrieved by
916 MpInitLibGetNumberOfProcessors().
917 @param[in] EnableAP Specifies the new state for the processor for
918 enabled, FALSE for disabled.
919 @param[in] HealthFlag If not NULL, a pointer to a value that specifies
920 the new health status of the AP. This flag
921 corresponds to StatusFlag defined in
922 EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
923 the PROCESSOR_HEALTH_STATUS_BIT is used. All other
924 bits are ignored. If it is NULL, this parameter
927 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
928 @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed
929 prior to this service returning.
930 @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
931 @retval EFI_DEVICE_ERROR The calling processor is an AP.
932 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
934 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
935 @retval EFI_NOT_READY MP Initialize Library is not initialized.
940 MpInitLibEnableDisableAP (
941 IN UINTN ProcessorNumber
,
943 IN UINT32
*HealthFlag OPTIONAL
947 BOOLEAN TempStopCheckState
;
949 TempStopCheckState
= FALSE
;
951 // temporarily stop checkAllAPsStatus for initialize parameters.
953 if (!mStopCheckAllApsStatus
) {
954 mStopCheckAllApsStatus
= TRUE
;
955 TempStopCheckState
= TRUE
;
958 Status
= EnableDisableApWorker (ProcessorNumber
, EnableAP
, HealthFlag
);
960 if (TempStopCheckState
) {
961 mStopCheckAllApsStatus
= FALSE
;
968 This funtion will try to invoke platform specific microcode shadow logic to
969 relocate microcode update patches into memory.
971 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
973 @retval EFI_SUCCESS Shadow microcode success.
974 @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.
975 @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow
979 PlatformShadowMicrocode (
980 IN OUT CPU_MP_DATA
*CpuMpData
984 // There is no DXE version of platform shadow microcode protocol so far.
985 // A platform which only uses DxeMpInitLib instance could only supports
986 // the PCD based microcode shadowing.
988 return EFI_UNSUPPORTED
;