UefiCpuPkg/MpInitLib: Sync BSP's APIC mode to APs in InitConfig path

The change saves the BSP's initial APIC mode and syncs to all APs
in first time wakeup. It allows certain platforms to switch to X2 APIC
as early as possible and also independent on CpuFeaturePei/Dxe.
The platform should switch BSP to X2 APIC mode first before the
CpuMpPeim runs.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Ray Ni 2023-04-14 13:58:15 +08:00 committed by mergify[bot]
parent 94f68d0b56
commit 7ed3989166
2 changed files with 28 additions and 5 deletions

View File

@ -758,6 +758,12 @@ ApWakeupFunction (
CurrentApicMode = GetApicMode ();
while (TRUE) {
if (CpuMpData->InitFlag == ApInitConfig) {
//
// Synchronize APIC mode with BSP in the first time AP wakeup ONLY.
//
SetApicMode (CpuMpData->InitialBspApicMode);
CurrentApicMode = CpuMpData->InitialBspApicMode;
ProcessorNumber = ApIndex;
//
// This is first time AP wakeup, get BIST information from AP stack
@ -2221,6 +2227,11 @@ MpInitLibInitialize (
);
DEBUG ((DEBUG_INFO, "AP Vector: non-16-bit = %p/%x\n", CpuMpData->WakeupBufferHigh, ApResetVectorSizeAbove1Mb));
//
// Save APIC mode for AP to sync
//
CpuMpData->InitialBspApicMode = GetApicMode ();
//
// Enable the local APIC for Virtual Wire Mode.
//

View File

@ -255,6 +255,18 @@ struct _CPU_MP_DATA {
UINT32 BspNumber;
SPIN_LOCK MpLock;
UINTN Buffer;
//
// InitialBspApicMode stores the initial BSP APIC mode.
// It is used to synchronize the BSP APIC mode with APs
// in the first time APs wake up.
// Its value doesn't reflect the current APIC mode since there are
// two cases the APIC mode is changed:
// 1. MpLib explicitly switches to X2 APIC mode because number of threads is greater than 255,
// or there are any logical processors reporting an initial APIC ID of 255 or greater.
// 2. Some code switches to X2 APIC mode in all threads through MP services PPI/Protocol.
//
UINTN InitialBspApicMode;
UINTN CpuApStackSize;
MP_ASSEMBLY_ADDRESS_MAP AddressMap;
UINTN WakeupBuffer;