TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuHotplug.c File Reference

Go to the source code of this file.

Functions

STATIC EFI_STATUS ProcessHotAddedCpus (IN APIC_ID *PluggedApicIds, IN UINT32 PluggedCount)
 
STATIC BOOLEAN CheckIfBsp (VOID)
 
VOID EFIAPI EjectCpu (IN UINTN ProcessorNum)
 
STATIC EFI_STATUS UnplugCpus (IN APIC_ID *ToUnplugApicIds, IN UINT32 *ToUnplugSelectors, IN UINT32 ToUnplugCount)
 
STATIC EFI_STATUS EFIAPI CpuHotplugMmi (IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
 
EFI_STATUS EFIAPI CpuHotplugEntry (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

STATIC EFI_MM_CPU_IO_PROTOCOLmMmCpuIo
 
STATIC EFI_SMM_CPU_SERVICE_PROTOCOLmMmCpuService
 
STATIC CPU_HOT_PLUG_DATAmCpuHotPlugData
 
STATIC CPU_HOT_EJECT_DATAmCpuHotEjectData
 
STATIC APIC_ID * mPluggedApicIds
 
STATIC APIC_ID * mToUnplugApicIds
 
STATIC UINT32 * mToUnplugSelectors
 
STATIC UINT32 mPostSmmPenAddress
 
STATIC EFI_HANDLE mDispatchHandle
 

Detailed Description

Root SMI handler for VCPU hotplug SMIs.

Copyright (c) 2020, Red Hat, Inc.

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

Definition in file CpuHotplug.c.

Function Documentation

◆ CheckIfBsp()

STATIC BOOLEAN CheckIfBsp ( VOID  )

EjectCpu needs to know the BSP at SMI exit at a point when some of the EFI_SMM_CPU_SERVICE_PROTOCOL state has been torn down. Reuse the logic from OvmfPkg::PlatformSmmBspElection() to do that.

Return values
TRUEIf the CPU executing this function is the BSP.
FALSEIf the CPU executing this function is an AP.

Definition at line 238 of file CpuHotplug.c.

◆ CpuHotplugEntry()

EFI_STATUS EFIAPI CpuHotplugEntry ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Definition at line 709 of file CpuHotplug.c.

◆ CpuHotplugMmi()

STATIC EFI_STATUS EFIAPI CpuHotplugMmi ( IN EFI_HANDLE  DispatchHandle,
IN CONST VOID *Context  OPTIONAL,
IN OUT VOID *CommBuffer  OPTIONAL,
IN OUT UINTN *CommBufferSize  OPTIONAL 
)

CPU Hotplug MMI handler function.

This is a root MMI handler.

Parameters
[in]DispatchHandleThe unique handle assigned to this handler by EFI_MM_SYSTEM_TABLE.MmiHandlerRegister().
[in]ContextContext passed in by EFI_MM_SYSTEM_TABLE.MmiManage(). Due to CpuHotplugMmi() being a root MMI handler, Context is ASSERT()ed to be NULL.
[in,out]CommBufferIgnored, due to CpuHotplugMmi() being a root MMI handler.
[in,out]CommBufferSizeIgnored, due to CpuHotplugMmi() being a root MMI handler.
Return values
EFI_SUCCESSThe MMI was handled and the MMI source was quiesced. When returned by a non-root MMI handler, EFI_SUCCESS terminates the processing of MMI handlers in EFI_MM_SYSTEM_TABLE.MmiManage(). For a root MMI handler (i.e., for the present function too), EFI_SUCCESS behaves identically to EFI_WARN_INTERRUPT_SOURCE_QUIESCED, as further root MMI handlers are going to be called by EFI_MM_SYSTEM_TABLE.MmiManage() anyway.
EFI_WARN_INTERRUPT_SOURCE_QUIESCEDThe MMI source has been quiesced, but other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_PENDINGThe MMI source is still pending, and other handlers should still be called.
EFI_INTERRUPT_PENDINGThe MMI source could not be quiesced.

Definition at line 605 of file CpuHotplug.c.

◆ EjectCpu()

VOID EFIAPI EjectCpu ( IN UINTN  ProcessorNum)

CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit() on each CPU at exit from SMM.

If, the executing CPU is neither the BSP, nor being ejected, nothing to be done. If, the executing CPU is being ejected, wait in a halted loop until ejected. If, the executing CPU is the BSP, set QEMU CPU status to eject for CPUs being ejected.

Parameters
[in]ProcessorNumProcessorNum denotes the CPU exiting SMM, and will be used as an index into CPU_HOT_EJECT_DATA->QemuSelectorMap. It is identical to the processor handle number in EFI_SMM_CPU_SERVICE_PROTOCOL.

Definition at line 269 of file CpuHotplug.c.

◆ ProcessHotAddedCpus()

STATIC EFI_STATUS ProcessHotAddedCpus ( IN APIC_ID *  PluggedApicIds,
IN UINT32  PluggedCount 
)

Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds().

For each such CPU, relocate the SMBASE, and report the CPU to PiSmmCpuDxeSmm via EFI_SMM_CPU_SERVICE_PROTOCOL. If the supposedly hot-added CPU is already known, skip it silently.

Parameters
[in]PluggedApicIdsThe APIC IDs of the CPUs that have been hot-plugged.
[in]PluggedCountThe number of filled-in APIC IDs in PluggedApicIds.
Return values
EFI_SUCCESSCPUs corresponding to all the APIC IDs are populated.
EFI_OUT_OF_RESOURCESOut of APIC ID space in "mCpuHotPlugData".
Returns
Error codes propagated from SmbaseRelocate() and mMmCpuService->AddProcessor().

Definition at line 95 of file CpuHotplug.c.

◆ UnplugCpus()

STATIC EFI_STATUS UnplugCpus ( IN APIC_ID *  ToUnplugApicIds,
IN UINT32 *  ToUnplugSelectors,
IN UINT32  ToUnplugCount 
)

Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds().

For each such CPU, report the CPU to PiSmmCpuDxeSmm via EFI_SMM_CPU_SERVICE_PROTOCOL and stash the QEMU Cpu Selectors for later ejection. If the to be hot-unplugged CPU is unknown, skip it silently.

Additonally, if we do stash any Cpu Selectors, also install a CPU eject handler which would handle the ejection.

Parameters
[in]ToUnplugApicIdsThe APIC IDs of the CPUs that are about to be hot-unplugged.
[in]ToUnplugSelectorsThe QEMU Selectors of the CPUs that are about to be hot-unplugged.
[in]ToUnplugCountThe number of filled-in APIC IDs in ToUnplugApicIds.
Return values
EFI_ALREADY_STARTEDFor the ProcessorNum that EFI_SMM_CPU_SERVICE_PROTOCOL had assigned to one of the APIC IDs in ToUnplugApicIds, mCpuHotEjectData->QemuSelectorMap already has the QemuSelector value stashed. (This should never happen.)
EFI_SUCCESSKnown APIC IDs have been removed from SMM data structures.
Returns
Error codes propagated from mMmCpuService->RemoveProcessor().

Definition at line 413 of file CpuHotplug.c.

Variable Documentation

◆ mCpuHotEjectData

STATIC CPU_HOT_EJECT_DATA* mCpuHotEjectData

Definition at line 43 of file CpuHotplug.c.

◆ mCpuHotPlugData

STATIC CPU_HOT_PLUG_DATA* mCpuHotPlugData

Definition at line 42 of file CpuHotplug.c.

◆ mDispatchHandle

STATIC EFI_HANDLE mDispatchHandle

Definition at line 70 of file CpuHotplug.c.

◆ mMmCpuIo

Definition at line 31 of file CpuHotplug.c.

◆ mMmCpuService

Definition at line 36 of file CpuHotplug.c.

◆ mPluggedApicIds

STATIC APIC_ID* mPluggedApicIds

Definition at line 59 of file CpuHotplug.c.

◆ mPostSmmPenAddress

STATIC UINT32 mPostSmmPenAddress

Definition at line 66 of file CpuHotplug.c.

◆ mToUnplugApicIds

STATIC APIC_ID* mToUnplugApicIds

Definition at line 60 of file CpuHotplug.c.

◆ mToUnplugSelectors

STATIC UINT32* mToUnplugSelectors

Definition at line 61 of file CpuHotplug.c.