TianoCore EDK2 master
Loading...
Searching...
No Matches
MpLib.c File Reference
#include "MpLib.h"
#include <Library/BaseLib.h>
#include <Register/LoongArch64/Csr.h>

Go to the source code of this file.

Macros

#define INVALID_APIC_ID   0xFFFFFFFF
 

Functions

CPU_STATE GetApState (IN CPU_AP_DATA *CpuData)
 
VOID SetApState (IN CPU_AP_DATA *CpuData, IN CPU_STATE State)
 
UINT32 GetApicId (VOID)
 
EFI_STATUS GetProcessorNumber (IN CPU_MP_DATA *CpuMpData, OUT UINTN *ProcessorNumber)
 
VOID SortApicId (IN CPU_MP_DATA *CpuMpData)
 
PROCESSOR_RESOURCE_DATAGetProcessorResourceDataFromGuidedHob (VOID)
 
UINTN CollectProcessorCount (IN CPU_MP_DATA *CpuMpData)
 
VOID InitializeApData (IN OUT CPU_MP_DATA *CpuMpData, IN UINTN ProcessorNumber, IN UINT32 BistData)
 
VOID EFIAPI ApWakeupFunction (IN UINTN ApIndex, IN MP_CPU_EXCHANGE_INFO *ExchangeInfo)
 
UINT64 CalculateTimeout (IN UINTN TimeoutInMicroseconds, OUT UINT64 *CurrentTime)
 
BOOLEAN CheckTimeout (IN OUT UINT64 *PreviousTime, IN UINT64 *TotalTime, IN UINT64 Timeout)
 
VOID TimedWaitForApFinish (IN CPU_MP_DATA *CpuMpData, IN UINT32 FinishedApLimit, IN UINT32 TimeLimit)
 
VOID WaitApWakeup (IN volatile UINT32 *ApStartupSignalBuffer)
 
VOID FillExchangeInfoData (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)
 
EFI_STATUS GetNextWaitingProcessorNumber (OUT UINTN *NextProcessorNumber)
 
EFI_STATUS CheckThisAP (IN UINTN ProcessorNumber)
 
EFI_STATUS CheckAllAPs (VOID)
 
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)
 
EFI_STATUS EFIAPI MpInitLibStartupAllCPUs (IN EFI_AP_PROCEDURE Procedure, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL)
 
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 EFIAPI MpInitLibWhoAmI (OUT UINTN *ProcessorNumber)
 
EFI_STATUS EFIAPI MpInitLibGetNumberOfProcessors (OUT UINTN *NumberOfProcessors OPTIONAL, OUT UINTN *NumberOfEnabledProcessors OPTIONAL)
 
CPU_MP_DATAGetCpuMpDataFromGuidedHob (VOID)
 

Variables

EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID
 

Detailed Description

LoongArch64 CPU MP Initialize Library common functions.

Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.

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

Definition in file MpLib.c.

Macro Definition Documentation

◆ INVALID_APIC_ID

#define INVALID_APIC_ID   0xFFFFFFFF

Definition at line 15 of file MpLib.c.

Function Documentation

◆ ApWakeupFunction()

VOID EFIAPI ApWakeupFunction ( IN UINTN  ApIndex,
IN MP_CPU_EXCHANGE_INFO ExchangeInfo 
)

Ap wake up function.

Ap will wait for scheduling here, and if the IPI or wake-up signal is enabled, Ap will preform the corresponding functions.

Parameters
[in]ApIndexNumber of current executing AP
[in]ExchangeInfoPointer to the MP exchange info buffer

Definition at line 326 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 444 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 910 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 863 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 520 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 222 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 646 of file MpLib.c.

◆ GetApicId()

UINT32 GetApicId ( VOID  )

Get APIC ID of the executing processor.

Returns
32-bit APIC ID of the executing processor.

Definition at line 57 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 27 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 1609 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 832 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 78 of file MpLib.c.

◆ GetProcessorResourceDataFromGuidedHob()

PROCESSOR_RESOURCE_DATA * GetProcessorResourceDataFromGuidedHob ( VOID  )

Get pointer to Processor Resource Data structure from GUIDd HOB.

Returns
The pointer to Processor Resource Data structure.

Definition at line 196 of file MpLib.c.

◆ InitializeApData()

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

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

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 1559 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.
[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 1452 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 1319 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 1287 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 1522 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 41 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 109 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 1019 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 1176 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 571 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 621 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. Currently not used on LoongArch.

Definition at line 672 of file MpLib.c.

Variable Documentation

◆ mCpuInitMpLibHobGuid

EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID

Definition at line 17 of file MpLib.c.