TianoCore EDK2 master
Loading...
Searching...
No Matches
MpLib.c File Reference
#include "MpLib.h"
#include <Library/CcExitLib.h>
#include <Register/Amd/SevSnpMsr.h>
#include <Register/Amd/Ghcb.h>

Go to the source code of this file.

Functions

VOID SaveVolatileRegisters (OUT CPU_VOLATILE_REGISTERS *VolatileRegisters)
 
VOID RestoreVolatileRegisters (IN CPU_VOLATILE_REGISTERS *VolatileRegisters)
 
BOOLEAN IsBspExecuteDisableEnabled (VOID)
 
VOID EFIAPI FutureBSPProc (IN VOID *Buffer)
 
CPU_STATE GetApState (IN CPU_AP_DATA *CpuData)
 
VOID SetApState (IN CPU_AP_DATA *CpuData, IN CPU_STATE State)
 
VOID SaveLocalApicTimerSetting (IN CPU_MP_DATA *CpuMpData)
 
VOID SyncLocalApicTimerSetting (IN CPU_MP_DATA *CpuMpData)
 
BOOLEAN IsMwaitSupport (VOID)
 
UINT8 GetApLoopMode (OUT UINT32 *MonitorFilterSize)
 
VOID SortApicId (IN CPU_MP_DATA *CpuMpData)
 
VOID EFIAPI ApFuncEnableX2Apic (IN OUT VOID *Buffer)
 
VOID EFIAPI ApInitializeSync (IN OUT VOID *Buffer)
 
EFI_STATUS GetProcessorNumber (IN CPU_MP_DATA *CpuMpData, OUT UINTN *ProcessorNumber)
 
VOID AutoEnableX2Apic (IN CPU_MP_DATA *CpuMpData)
 
UINTN CollectProcessorCount (IN CPU_MP_DATA *CpuMpData)
 
VOID InitializeApData (IN OUT CPU_MP_DATA *CpuMpData, IN UINTN ProcessorNumber, IN UINT32 BistData, IN UINT64 ApTopOfStack)
 
VOID PlaceAPInHltLoop (IN CPU_MP_DATA *CpuMpData)
 
VOID PlaceAPInMwaitLoopOrRunLoop (IN UINT8 ApLoopMode, IN volatile UINT32 *ApStartupSignalBuffer, IN UINT8 ApTargetCState)
 
VOID EFIAPI ApWakeupFunction (IN CPU_MP_DATA *CpuMpData, IN UINTN ApIndex)
 
VOID EFIAPI DxeApEntryPoint (CPU_MP_DATA *CpuMpData)
 
VOID WaitApWakeup (IN volatile UINT32 *ApStartupSignalBuffer)
 
STATIC VOID GetApResetVectorSize (IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap, OUT UINTN *SizeBelow1Mb OPTIONAL, OUT UINTN *SizeAbove1Mb OPTIONAL)
 
VOID FillExchangeInfoData (IN CPU_MP_DATA *CpuMpData)
 
VOID TimedWaitForApFinish (IN CPU_MP_DATA *CpuMpData, IN UINT32 FinishedApLimit, IN UINT32 TimeLimit)
 
VOID BackupAndPrepareWakeupBuffer (IN CPU_MP_DATA *CpuMpData)
 
VOID RestoreWakeupBuffer (IN CPU_MP_DATA *CpuMpData)
 
VOID AllocateResetVectorBelow1Mb (IN OUT CPU_MP_DATA *CpuMpData)
 
VOID FreeResetVector (IN CPU_MP_DATA *CpuMpData)
 
VOID WakeUpAP (IN CPU_MP_DATA *CpuMpData, IN BOOLEAN Broadcast, IN UINTN ProcessorNumber, IN EFI_AP_PROCEDURE Procedure OPTIONAL, IN VOID *ProcedureArgument OPTIONAL, IN BOOLEAN WakeUpDisabledAps)
 
UINT64 CalculateTimeout (IN UINTN TimeoutInMicroseconds, OUT UINT64 *CurrentTime)
 
VOID EFIAPI SwitchContextPerAp (VOID)
 
BOOLEAN CheckTimeout (IN OUT UINT64 *PreviousTime, IN UINT64 *TotalTime, IN UINT64 Timeout)
 
VOID ResetProcessorToIdleState (IN UINTN ProcessorNumber)
 
EFI_STATUS GetNextWaitingProcessorNumber (OUT UINTN *NextProcessorNumber)
 
EFI_STATUS CheckThisAP (IN UINTN ProcessorNumber)
 
EFI_STATUS CheckAllAPs (VOID)
 
UINT32 GetBspNumber (IN CONST MP_HAND_OFF *FirstMpHandOff)
 
VOID SwitchApContext (IN CONST MP_HAND_OFF_CONFIG *MpHandOffConfig, IN CONST MP_HAND_OFF *FirstMpHandOff)
 
MP_HAND_OFF_CONFIGGetMpHandOffConfigHob (VOID)
 
MP_HAND_OFFGetNextMpHandOffHob (IN CONST MP_HAND_OFF *MpHandOff)
 
EFI_STATUS EFIAPI MpInitLibInitialize (VOID)
 
EFI_STATUS EFIAPI MpInitLibGetProcessorInfo (IN UINTN ProcessorNumber, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL)
 
EFI_STATUS SwitchBSPWorker (IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
 
EFI_STATUS EnableDisableApWorker (IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL)
 
EFI_STATUS EFIAPI MpInitLibWhoAmI (OUT UINTN *ProcessorNumber)
 
EFI_STATUS EFIAPI MpInitLibGetNumberOfProcessors (OUT UINTN *NumberOfProcessors OPTIONAL, OUT UINTN *NumberOfEnabledProcessors OPTIONAL)
 
EFI_STATUS StartupAllCPUsWorker (IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN BOOLEAN ExcludeBsp, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT UINTN **FailedCpuList OPTIONAL)
 
EFI_STATUS StartupThisAPWorker (IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT BOOLEAN *Finished OPTIONAL)
 
CPU_MP_DATAGetCpuMpDataFromGuidedHob (VOID)
 
EFI_STATUS EFIAPI MpInitLibStartupAllCPUs (IN EFI_AP_PROCEDURE Procedure, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL)
 
STATIC BOOLEAN AmdMemEncryptionAttrCheck (IN UINT64 CurrentAttr, IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
 
BOOLEAN EFIAPI ConfidentialComputingGuestHas (IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr)
 
VOID EFIAPI RelocateApLoop (IN OUT VOID *Buffer)
 
VOID PrepareApLoopCode (IN CPU_MP_DATA *CpuMpData)
 

Variables

EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID
 
EFI_GUID mMpHandOffGuid = MP_HANDOFF_GUID
 
EFI_GUID mMpHandOffConfigGuid = MP_HANDOFF_CONFIG_GUID
 
RELOCATE_AP_LOOP_ENTRY mReservedApLoop
 
UINTN mReservedTopOfApStack
 
volatile UINT32 mNumberToFinish = 0
 
UINTN mApPageTable
 

Detailed Description

CPU MP Initialize Library common functions.

Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2020 - 2024, AMD Inc. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file MpLib.c.

Function Documentation

◆ AllocateResetVectorBelow1Mb()

VOID AllocateResetVectorBelow1Mb ( IN OUT CPU_MP_DATA CpuMpData)

Allocate reset vector buffer.

Parameters
[in,out]CpuMpDataThe pointer to CPU MP Data structure.

Definition at line 1122 of file MpLib.c.

◆ AmdMemEncryptionAttrCheck()

STATIC BOOLEAN AmdMemEncryptionAttrCheck ( IN UINT64  CurrentAttr,
IN CONFIDENTIAL_COMPUTING_GUEST_ATTR  Attr 
)

The function check if the specified Attr is set.

Parameters
[in]CurrentAttrThe current attribute.
[in]AttrThe attribute to check.
Return values
TRUEThe specified Attr is set.
FALSEThe specified Attr is not set.

Definition at line 3296 of file MpLib.c.

◆ ApFuncEnableX2Apic()

VOID EFIAPI ApFuncEnableX2Apic ( IN OUT VOID *  Buffer)

Enable x2APIC mode on APs.

Parameters
[in,out]BufferPointer to private data buffer.

Definition at line 435 of file MpLib.c.

◆ ApInitializeSync()

VOID EFIAPI ApInitializeSync ( IN OUT VOID *  Buffer)

Do sync on APs.

Parameters
[in,out]BufferPointer to private data buffer.

Definition at line 449 of file MpLib.c.

◆ ApWakeupFunction()

VOID EFIAPI ApWakeupFunction ( IN CPU_MP_DATA CpuMpData,
IN UINTN  ApIndex 
)

This function will be called from AP reset code if BSP uses WakeUpAP.

Parameters
[in]CpuMpDataPointer to CPU MP Data
[in]ApIndexNumber of current executing AP

Definition at line 731 of file MpLib.c.

◆ AutoEnableX2Apic()

VOID AutoEnableX2Apic ( IN CPU_MP_DATA CpuMpData)

Enable x2APIC mode if

  1. Number of CPU is greater than 255; or
  2. There are any logical processors reporting an Initial APIC ID of 255 or greater.
Parameters
[in]CpuMpDataPointer to PEI CPU MP Data

Definition at line 512 of file MpLib.c.

◆ BackupAndPrepareWakeupBuffer()

VOID BackupAndPrepareWakeupBuffer ( IN CPU_MP_DATA CpuMpData)

Get available system memory below 1MB by specified size.

Parameters
[in]CpuMpDataThe pointer to CPU MP Data structure.

Definition at line 1083 of file MpLib.c.

◆ CalculateTimeout()

UINT64 CalculateTimeout ( IN UINTN  TimeoutInMicroseconds,
OUT UINT64 *  CurrentTime 
)

Calculate timeout value and return the current performance counter value.

Calculate the number of performance counter ticks required for a timeout. If TimeoutInMicroseconds is 0, return value is also 0, which is recognized as infinity.

Parameters
[in]TimeoutInMicrosecondsTimeout value in microseconds.
[out]CurrentTimeReturns the current value of the performance counter.
Returns
Expected time stamp counter for timeout. If TimeoutInMicroseconds is 0, return value is also 0, which is recognized as infinity.

Definition at line 1445 of file MpLib.c.

◆ CheckAllAPs()

EFI_STATUS CheckAllAPs ( VOID  )

Checks status of all APs.

This function checks whether all APs have finished task assigned by StartupAllAPs(), and whether timeout expires.

Return values
EFI_SUCCESSAll APs have finished task assigned by StartupAllAPs().
EFI_TIMEOUTThe timeout expires.
EFI_NOT_READYAPs have not finished task and timeout has not expired.

Definition at line 1784 of file MpLib.c.

◆ CheckThisAP()

EFI_STATUS CheckThisAP ( IN UINTN  ProcessorNumber)

Checks status of specified AP.

This function checks whether the specified AP has finished the task assigned by StartupThisAP(), and whether timeout expires.

Parameters
[in]ProcessorNumberThe handle number of processor.
Return values
EFI_SUCCESSSpecified AP has finished task assigned by StartupThisAPs().
EFI_TIMEOUTThe timeout expires.
EFI_NOT_READYSpecified AP has not finished task and timeout has not expired.

Definition at line 1721 of file MpLib.c.

◆ CheckTimeout()

BOOLEAN CheckTimeout ( IN OUT UINT64 *  PreviousTime,
IN UINT64 *  TotalTime,
IN UINT64  Timeout 
)

Checks whether timeout expires.

Check whether the number of elapsed performance counter ticks required for a timeout condition has been reached. If Timeout is zero, which means infinity, return value is always FALSE.

Parameters
[in,out]PreviousTimeOn input, the value of the performance counter when it was last read. On output, the current value of the performance counter
[in]TotalTimeThe total amount of elapsed time in performance counter ticks.
[in]TimeoutThe number of performance counter ticks required to reach a timeout condition.
Return values
TRUEA timeout condition has been reached.
FALSEA timeout condition has not been reached.

Definition at line 1547 of file MpLib.c.

◆ CollectProcessorCount()

UINTN CollectProcessorCount ( IN CPU_MP_DATA CpuMpData)

This function will get CPU count in the system.

Parameters
[in]CpuMpDataPointer to PEI CPU MP Data
Returns
CPU count detected

Definition at line 577 of file MpLib.c.

◆ ConfidentialComputingGuestHas()

BOOLEAN EFIAPI ConfidentialComputingGuestHas ( IN CONFIDENTIAL_COMPUTING_GUEST_ATTR  Attr)

Check if the specified confidential computing attribute is active.

Parameters
[in]AttrThe attribute to check.
Return values
TRUEThe specified Attr is active.
FALSEThe specified Attr is not active.

Definition at line 3336 of file MpLib.c.

◆ DxeApEntryPoint()

VOID EFIAPI DxeApEntryPoint ( CPU_MP_DATA CpuMpData)

This function serves as the entry point for APs when they are awakened by the stores in the memory address indicated by the MP_HANDOFF_INFO structure.

Parameters
[in]CpuMpDataPointer to PEI CPU MP Data

Definition at line 899 of file MpLib.c.

◆ EnableDisableApWorker()

EFI_STATUS EnableDisableApWorker ( IN UINTN  ProcessorNumber,
IN BOOLEAN  EnableAP,
IN UINT32 *HealthFlag  OPTIONAL 
)

Worker function to let the caller enable or disable an AP from this point onward. This service may only be called from the BSP.

Parameters
[in]ProcessorNumberThe handle number of AP.
[in]EnableAPSpecifies the new state for the processor for enabled, FALSE for disabled.
[in]HealthFlagIf not NULL, a pointer to a value that specifies the new health status of the AP.
Return values
EFI_SUCCESSThe specified AP was enabled or disabled successfully.
othersFailed to Enable/Disable AP.

Definition at line 2745 of file MpLib.c.

◆ FillExchangeInfoData()

VOID FillExchangeInfoData ( IN CPU_MP_DATA CpuMpData)

This function will fill the exchange info structure.

Parameters
[in]CpuMpDataPointer to CPU MP Data

Definition at line 978 of file MpLib.c.

◆ FreeResetVector()

VOID FreeResetVector ( IN CPU_MP_DATA CpuMpData)

Free AP reset vector buffer.

Parameters
[in]CpuMpDataThe pointer to CPU MP Data structure.

Definition at line 1189 of file MpLib.c.

◆ FutureBSPProc()

VOID EFIAPI FutureBSPProc ( IN VOID *  Buffer)

Worker function for SwitchBSP().

Worker function for SwitchBSP(), assigned to the AP which is intended to become BSP.

Parameters
[in]BufferPointer to CPU MP Data

Definition at line 108 of file MpLib.c.

◆ GetApLoopMode()

UINT8 GetApLoopMode ( OUT UINT32 *  MonitorFilterSize)

Get AP loop mode.

Parameters
[out]MonitorFilterSizeReturns the largest monitor-line size in bytes.
Returns
The AP loop mode.

Definition at line 313 of file MpLib.c.

◆ GetApResetVectorSize()

STATIC VOID GetApResetVectorSize ( IN MP_ASSEMBLY_ADDRESS_MAP AddressMap,
OUT UINTN *SizeBelow1Mb  OPTIONAL,
OUT UINTN *SizeAbove1Mb  OPTIONAL 
)

Calculate the size of the reset vector.

Parameters
[in]AddressMapThe pointer to Address Map structure.
[out]SizeBelow1MbReturn the size of below 1MB memory for AP reset area.
[out]SizeAbove1MbReturn the size of abvoe 1MB memory for AP reset area.

Definition at line 956 of file MpLib.c.

◆ GetApState()

CPU_STATE GetApState ( IN CPU_AP_DATA CpuData)

Get the Application Processors state.

Parameters
[in]CpuDataThe pointer to CPU_AP_DATA of specified AP
Returns
The AP status

Definition at line 131 of file MpLib.c.

◆ GetBspNumber()

UINT32 GetBspNumber ( IN CONST MP_HAND_OFF FirstMpHandOff)

This function Get BspNumber.

Parameters
[in]FirstMpHandOffPointer to first MpHandOff HOB body.
Returns
BspNumber

Definition at line 1904 of file MpLib.c.

◆ GetCpuMpDataFromGuidedHob()

CPU_MP_DATA * GetCpuMpDataFromGuidedHob ( VOID  )

Get pointer to CPU MP Data structure from GUIDed HOB.

Returns
The pointer to CPU MP Data structure.

Definition at line 3221 of file MpLib.c.

◆ GetMpHandOffConfigHob()

MP_HAND_OFF_CONFIG * GetMpHandOffConfigHob ( VOID  )

Get pointer to MP_HAND_OFF_CONFIG GUIDed HOB body.

Returns
The pointer to MP_HAND_OFF_CONFIG structure.

Definition at line 1989 of file MpLib.c.

◆ GetNextMpHandOffHob()

MP_HAND_OFF * GetNextMpHandOffHob ( IN CONST MP_HAND_OFF MpHandOff)

Get pointer to next MP_HAND_OFF GUIDed HOB body.

Parameters
[in]MpHandOffPrevious HOB body. Pass NULL to get the first HOB.
Returns
The pointer to MP_HAND_OFF structure.

Definition at line 2011 of file MpLib.c.

◆ GetNextWaitingProcessorNumber()

EFI_STATUS GetNextWaitingProcessorNumber ( OUT UINTN NextProcessorNumber)

Searches for the next waiting AP.

Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().

Parameters
[out]NextProcessorNumberPointer to the processor number of the next waiting AP.
Return values
EFI_SUCCESSThe next waiting AP has been found.
EFI_NOT_FOUNDNo waiting AP exists.

Definition at line 1685 of file MpLib.c.

◆ GetProcessorNumber()

EFI_STATUS GetProcessorNumber ( IN CPU_MP_DATA CpuMpData,
OUT UINTN ProcessorNumber 
)

Find the current Processor number by APIC ID.

Parameters
[in]CpuMpDataPointer to PEI CPU MP Data
[out]ProcessorNumberReturn the pocessor number found
Return values
EFI_SUCCESSProcessorNumber is found and returned.
EFI_NOT_FOUNDProcessorNumber is not found.

Definition at line 480 of file MpLib.c.

◆ InitializeApData()

VOID InitializeApData ( IN OUT CPU_MP_DATA CpuMpData,
IN UINTN  ProcessorNumber,
IN UINT32  BistData,
IN UINT64  ApTopOfStack 
)

Initialize CPU AP Data when AP is wakeup at the first time.

Parameters
[in,out]CpuMpDataPointer to PEI CPU MP Data
[in]ProcessorNumberThe handle number of processor
[in]BistDataProcessor BIST data
[in]ApTopOfStackTop of AP stack

Definition at line 607 of file MpLib.c.

◆ IsBspExecuteDisableEnabled()

BOOLEAN IsBspExecuteDisableEnabled ( VOID  )

The function will check if BSP Execute Disable is enabled.

DxeIpl may have enabled Execute Disable for BSP, APs need to get the status and sync up the settings. If BSP's CR0.Paging is not set, BSP execute Disble feature is not working actually.

Return values
TRUEBSP Execute Disable is enabled.
FALSEBSP Execute Disable is not enabled.

Definition at line 59 of file MpLib.c.

◆ IsMwaitSupport()

BOOLEAN IsMwaitSupport ( VOID  )

Detect whether Mwait-monitor feature is supported.

Return values
TRUEMwait-monitor feature is supported.
FALSEMwait-monitor feature is not supported.

Definition at line 295 of file MpLib.c.

◆ MpInitLibGetNumberOfProcessors()

EFI_STATUS EFIAPI MpInitLibGetNumberOfProcessors ( OUT UINTN *NumberOfProcessors  OPTIONAL,
OUT UINTN *NumberOfEnabledProcessors  OPTIONAL 
)

Retrieves the number of logical processor in the platform and the number of those logical processors that are enabled on this boot. This service may only be called from the BSP.

Parameters
[out]NumberOfProcessorsPointer to the total number of logical processors in the system, including the BSP and disabled APs.
[out]NumberOfEnabledProcessorsPointer to the number of enabled logical processors that exist in system, including the BSP.
Return values
EFI_SUCCESSThe number of logical processors and enabled logical processors was retrieved.
EFI_DEVICE_ERRORThe calling processor is an AP.
EFI_INVALID_PARAMETERNumberOfProcessors is NULL and NumberOfEnabledProcessors is NULL.
EFI_NOT_READYMP Initialize Library is not initialized.

Definition at line 2858 of file MpLib.c.

◆ MpInitLibGetProcessorInfo()

EFI_STATUS EFIAPI MpInitLibGetProcessorInfo ( IN UINTN  ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer,
OUT EFI_HEALTH_FLAGS *HealthData  OPTIONAL 
)

Gets detailed MP-related information on the requested processor at the instant this call is made. This service may only be called from the BSP.

Parameters
[in]ProcessorNumberThe handle number of processor. Lower 24 bits contains the actual processor number. BIT24 indicates if the EXTENDED_PROCESSOR_INFORMATION will be retrived.
[out]ProcessorInfoBufferA pointer to the buffer where information for the requested processor is deposited.
[out]HealthDataReturn processor health data.
Return values
EFI_SUCCESSProcessor information was returned.
EFI_DEVICE_ERRORThe calling processor is an AP.
EFI_INVALID_PARAMETERProcessorInfoBuffer is NULL.
EFI_NOT_FOUNDThe processor with the handle specified by ProcessorNumber does not exist in the platform.
EFI_NOT_READYMP Initialize Library is not initialized.

Definition at line 2475 of file MpLib.c.

◆ MpInitLibInitialize()

EFI_STATUS EFIAPI MpInitLibInitialize ( VOID  )

MP Initialize Library initialization.

This service will allocate AP reset vector and wakeup all APs to do APs initialization.

This service must be invoked before all other MP Initialize Library service are invoked.

Return values
EFI_SUCCESSMP initialization succeeds.
OthersMP initialization fails.

Definition at line 2046 of file MpLib.c.

◆ MpInitLibStartupAllCPUs()

EFI_STATUS EFIAPI MpInitLibStartupAllCPUs ( IN EFI_AP_PROCEDURE  Procedure,
IN UINTN  TimeoutInMicroseconds,
IN VOID *ProcedureArgument  OPTIONAL 
)

This service executes a caller provided function on all enabled CPUs.

Parameters
[in]ProcedureA pointer to the function to be run on enabled APs of the system. See type EFI_AP_PROCEDURE.
[in]TimeoutInMicrosecondsIndicates the time limit in microseconds for APs to return from Procedure, either for blocking or non-blocking mode. Zero means infinity. TimeoutInMicroseconds is ignored for BSP.
[in]ProcedureArgumentThe parameter passed into Procedure for all APs.
Return values
EFI_SUCCESSIn blocking mode, all CPUs have finished before the timeout expired.
EFI_SUCCESSIn non-blocking mode, function has been dispatched to all enabled CPUs.
EFI_DEVICE_ERRORCaller processor is AP.
EFI_NOT_READYAny enabled APs are busy.
EFI_NOT_READYMP Initialize Library is not initialized.
EFI_TIMEOUTIn blocking mode, the timeout expired before all enabled APs have finished.
EFI_INVALID_PARAMETERProcedure is NULL.

Definition at line 3267 of file MpLib.c.

◆ MpInitLibWhoAmI()

EFI_STATUS EFIAPI MpInitLibWhoAmI ( OUT UINTN ProcessorNumber)

This return the handle number for the calling processor. This service may be called from the BSP and APs.

Parameters
[out]ProcessorNumberPointer to the handle number of AP. The range is from 0 to the total number of logical processors minus 1. The total number of logical processors can be retrieved by MpInitLibGetNumberOfProcessors().
Return values
EFI_SUCCESSThe current processor handle number was returned in ProcessorNumber.
EFI_INVALID_PARAMETERProcessorNumber is NULL.
EFI_NOT_READYMP Initialize Library is not initialized.

Definition at line 2816 of file MpLib.c.

◆ PlaceAPInHltLoop()

VOID PlaceAPInHltLoop ( IN CPU_MP_DATA CpuMpData)

This function place APs in Halt loop.

Parameters
[in]CpuMpDataPointer to CPU MP Data

Definition at line 659 of file MpLib.c.

◆ PlaceAPInMwaitLoopOrRunLoop()

VOID PlaceAPInMwaitLoopOrRunLoop ( IN UINT8  ApLoopMode,
IN volatile UINT32 *  ApStartupSignalBuffer,
IN UINT8  ApTargetCState 
)

This function place APs in Mwait or Run loop.

Parameters
[in]ApLoopModeAp Loop Mode
[in]ApStartupSignalBufferPointer to Ap Startup Signal Buffer
[in]ApTargetCStateAp Target CState

Definition at line 683 of file MpLib.c.

◆ PrepareApLoopCode()

VOID PrepareApLoopCode ( IN CPU_MP_DATA CpuMpData)

Prepare ApLoopCode.

Parameters
[in]CpuMpDataPointer to CpuMpData.

Definition at line 3424 of file MpLib.c.

◆ RelocateApLoop()

VOID EFIAPI RelocateApLoop ( IN OUT VOID *  Buffer)

Do sync on APs.

Parameters
[in,out]BufferPointer to private data buffer.

Definition at line 3364 of file MpLib.c.

◆ ResetProcessorToIdleState()

VOID ResetProcessorToIdleState ( IN UINTN  ProcessorNumber)

Reset an AP to Idle state.

Any task being executed by the AP will be aborted and the AP will be waiting for a new task in Wait-For-SIPI state.

Parameters
[in]ProcessorNumberThe handle number of processor.

Definition at line 1651 of file MpLib.c.

◆ RestoreVolatileRegisters()

VOID RestoreVolatileRegisters ( IN CPU_VOLATILE_REGISTERS VolatileRegisters)

Restore the volatile registers following INIT IPI.

Parameters
[in]VolatileRegistersPointer to volatile resisters
[in]IsRestoreDrTRUE: Restore DRx if supported FALSE: Do not restore DRx

Restore the volatile registers following INIT IPI.

Parameters
[in]VolatileRegistersPointer to volatile resisters

Definition at line 249 of file MpLib.c.

◆ RestoreWakeupBuffer()

VOID RestoreWakeupBuffer ( IN CPU_MP_DATA CpuMpData)

Restore wakeup buffer data.

Parameters
[in]CpuMpDataThe pointer to CPU MP Data structure.

Definition at line 1105 of file MpLib.c.

◆ SaveLocalApicTimerSetting()

VOID SaveLocalApicTimerSetting ( IN CPU_MP_DATA CpuMpData)

Save BSP's local APIC timer setting.

Parameters
[in]CpuMpDataPointer to CPU MP Data

Definition at line 161 of file MpLib.c.

◆ SaveVolatileRegisters()

VOID SaveVolatileRegisters ( OUT CPU_VOLATILE_REGISTERS VolatileRegisters)

Save the volatile registers required to be restored following INIT IPI.

Parameters
[out]VolatileRegistersReturns buffer saved the volatile resisters

Definition at line 213 of file MpLib.c.

◆ SetApState()

VOID SetApState ( IN CPU_AP_DATA CpuData,
IN CPU_STATE  State 
)

Set the Application Processors state.

Parameters
[in]CpuDataThe pointer to CPU_AP_DATA of specified AP
[in]StateThe AP status

Definition at line 145 of file MpLib.c.

◆ SortApicId()

VOID SortApicId ( IN CPU_MP_DATA CpuMpData)

Sort the APIC ID of all processors.

This function sorts the APIC ID of all processors so that processor number is assigned in the ascending order of APIC ID which eases MP debugging.

Parameters
[in]CpuMpDataPointer to PEI CPU MP Data

Definition at line 367 of file MpLib.c.

◆ StartupAllCPUsWorker()

EFI_STATUS StartupAllCPUsWorker ( IN EFI_AP_PROCEDURE  Procedure,
IN BOOLEAN  SingleThread,
IN BOOLEAN  ExcludeBsp,
IN EFI_EVENT WaitEvent  OPTIONAL,
IN UINTN  TimeoutInMicroseconds,
IN VOID *ProcedureArgument  OPTIONAL,
OUT UINTN **FailedCpuList  OPTIONAL 
)

Worker function to execute a caller provided function on all enabled APs.

Parameters
[in]ProcedureA pointer to the function to be run on enabled APs of the system.
[in]SingleThreadIf TRUE, then all the enabled APs execute the function specified by Procedure one by one, in ascending order of processor handle number. If FALSE, then all the enabled APs execute the function specified by Procedure simultaneously.
[in]ExcludeBspWhether let BSP also trig this task.
[in]WaitEventThe event created by the caller with CreateEvent() service.
[in]TimeoutInMicrosecondsIndicates the time limit in microseconds for APs to return from Procedure, either for blocking or non-blocking mode.
[in]ProcedureArgumentThe parameter passed into Procedure for all APs.
[out]FailedCpuListIf all APs finish successfully, then its content is set to NULL. If not all APs finish before timeout expires, then its content is set to address of the buffer holding handle numbers of the failed APs.
Return values
EFI_SUCCESSIn blocking mode, all APs have finished before the timeout expired.
EFI_SUCCESSIn non-blocking mode, function has been dispatched to all enabled APs.
othersFailed to Startup all APs.

Definition at line 2947 of file MpLib.c.

◆ StartupThisAPWorker()

EFI_STATUS StartupThisAPWorker ( IN EFI_AP_PROCEDURE  Procedure,
IN UINTN  ProcessorNumber,
IN EFI_EVENT WaitEvent  OPTIONAL,
IN UINTN  TimeoutInMicroseconds,
IN VOID *ProcedureArgument  OPTIONAL,
OUT BOOLEAN *Finished  OPTIONAL 
)

Worker function to let the caller get one enabled AP to execute a caller-provided function.

Parameters
[in]ProcedureA pointer to the function to be run on enabled APs of the system.
[in]ProcessorNumberThe handle number of the AP.
[in]WaitEventThe event created by the caller with CreateEvent() service.
[in]TimeoutInMicrosecondsIndicates the time limit in microseconds for APs to return from Procedure, either for blocking or non-blocking mode.
[in]ProcedureArgumentThe parameter passed into Procedure for all APs.
[out]FinishedIf AP returns from Procedure before the timeout expires, its content is set to TRUE. Otherwise, the value is set to FALSE.
Return values
EFI_SUCCESSIn blocking mode, specified AP finished before the timeout expires.
othersFailed to Startup AP.

Definition at line 3116 of file MpLib.c.

◆ SwitchApContext()

VOID SwitchApContext ( IN CONST MP_HAND_OFF_CONFIG MpHandOffConfig,
IN CONST MP_HAND_OFF FirstMpHandOff 
)

This function is intended to be invoked by the BSP in order to wake up the AP. The BSP accomplishes this by triggering a start-up signal, which in turn causes any APs that are currently in a loop on the PEI-prepared memory to awaken and begin running the procedure called SwitchContextPerAp. This procedure allows the AP to switch to another section of memory and continue its loop there.

Parameters
[in]MpHandOffConfigPointer to MP hand-off config HOB body.
[in]FirstMpHandOffPointer to first MP hand-off HOB body.

Definition at line 1945 of file MpLib.c.

◆ SwitchBSPWorker()

EFI_STATUS SwitchBSPWorker ( IN UINTN  ProcessorNumber,
IN BOOLEAN  EnableOldBSP 
)

Worker function to switch the requested AP to be the BSP from that point onward.

Parameters
[in]ProcessorNumberThe handle number of AP that is to become the new BSP.
[in]EnableOldBSPIf TRUE, then the old BSP will be listed as an enabled AP. Otherwise, it will be disabled.
Return values
EFI_SUCCESSBSP successfully switched.
othersFailed to switch BSP.

Definition at line 2581 of file MpLib.c.

◆ SwitchContextPerAp()

VOID EFIAPI SwitchContextPerAp ( VOID  )

Switch Context for each AP.

Definition at line 1506 of file MpLib.c.

◆ SyncLocalApicTimerSetting()

VOID SyncLocalApicTimerSetting ( IN CPU_MP_DATA CpuMpData)

Sync local APIC timer setting from BSP to AP.

Parameters
[in]CpuMpDataPointer to CPU MP Data

Definition at line 186 of file MpLib.c.

◆ TimedWaitForApFinish()

VOID TimedWaitForApFinish ( IN CPU_MP_DATA CpuMpData,
IN UINT32  FinishedApLimit,
IN UINT32  TimeLimit 
)

Helper function that waits until the finished AP count reaches the specified limit, or the specified timeout elapses (whichever comes first).

Parameters
[in]CpuMpDataPointer to CPU MP Data.
[in]FinishedApLimitThe number of finished APs to wait for.
[in]TimeLimitThe number of microseconds to wait for.

Definition at line 1598 of file MpLib.c.

◆ WaitApWakeup()

VOID WaitApWakeup ( IN volatile UINT32 *  ApStartupSignalBuffer)

Wait for AP wakeup and write AP start-up signal till AP is waken up.

Parameters
[in]ApStartupSignalBufferPointer to AP wakeup signal

Definition at line 929 of file MpLib.c.

◆ WakeUpAP()

VOID WakeUpAP ( IN CPU_MP_DATA CpuMpData,
IN BOOLEAN  Broadcast,
IN UINTN  ProcessorNumber,
IN EFI_AP_PROCEDURE Procedure  OPTIONAL,
IN VOID *ProcedureArgument  OPTIONAL,
IN BOOLEAN  WakeUpDisabledAps 
)

This function will be called by BSP to wakeup AP.

Parameters
[in]CpuMpDataPointer to CPU MP Data
[in]BroadcastTRUE: Send broadcast IPI to all APs FALSE: Send IPI to AP by ApicId
[in]ProcessorNumberThe handle number of specified processor
[in]ProcedureThe function to be invoked by AP
[in]ProcedureArgumentThe argument to be passed into AP function
[in]WakeUpDisabledApsWhether need to wake up disabled APs in broadcast mode.

Definition at line 1216 of file MpLib.c.

Variable Documentation

◆ mApPageTable

UINTN mApPageTable

Definition at line 23 of file MpLib.c.

◆ mCpuInitMpLibHobGuid

EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID

Definition at line 16 of file MpLib.c.

◆ mMpHandOffConfigGuid

EFI_GUID mMpHandOffConfigGuid = MP_HANDOFF_CONFIG_GUID

Definition at line 18 of file MpLib.c.

◆ mMpHandOffGuid

EFI_GUID mMpHandOffGuid = MP_HANDOFF_GUID

Definition at line 17 of file MpLib.c.

◆ mNumberToFinish

volatile UINT32 mNumberToFinish = 0

Definition at line 22 of file MpLib.c.

◆ mReservedApLoop

RELOCATE_AP_LOOP_ENTRY mReservedApLoop

Definition at line 20 of file MpLib.c.

◆ mReservedTopOfApStack

UINTN mReservedTopOfApStack

Definition at line 21 of file MpLib.c.