UefiCpuPkg/MpInitLib: Separate X2APIC enabling to subfunction

It's very confusing that auto X2 APIC enabling and APIC ID sorting
are all performed inside CollectProcessorCount().

The change is to separate the X2 APIC enabling to AutoEnableX2Apic()
and call that from MpInitLibInitialize().
SortApicId() is called from MpInitLibInitialize() as well.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Ray Ni 2023-04-14 17:19:37 +08:00 committed by mergify[bot]
parent 84e7b74c8c
commit 94f68d0b56
1 changed files with 43 additions and 24 deletions

View File

@ -502,33 +502,20 @@ GetProcessorNumber (
}
/**
This function will get CPU count in the system.
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.
@param[in] CpuMpData Pointer to PEI CPU MP Data
@return CPU count detected
**/
UINTN
CollectProcessorCount (
VOID
AutoEnableX2Apic (
IN CPU_MP_DATA *CpuMpData
)
{
BOOLEAN X2Apic;
UINTN Index;
CPU_INFO_IN_HOB *CpuInfoInHob;
BOOLEAN X2Apic;
//
// Send 1st broadcast IPI to APs to wakeup APs
//
CpuMpData->InitFlag = ApInitConfig;
WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
CpuMpData->InitFlag = ApInitDone;
//
// When InitFlag == ApInitConfig, WakeUpAP () guarantees all APs are checked in.
// FinishedCount is the number of check-in APs.
//
CpuMpData->CpuCount = CpuMpData->FinishedCount + 1;
ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
//
// Enable x2APIC mode if
@ -577,12 +564,32 @@ CollectProcessorCount (
}
DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ()));
//
// Sort BSP/Aps by CPU APIC ID in ascending order
//
SortApicId (CpuMpData);
}
DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));
/**
This function will get CPU count in the system.
@param[in] CpuMpData Pointer to PEI CPU MP Data
@return CPU count detected
**/
UINTN
CollectProcessorCount (
IN CPU_MP_DATA *CpuMpData
)
{
//
// Send 1st broadcast IPI to APs to wakeup APs
//
CpuMpData->InitFlag = ApInitConfig;
WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
CpuMpData->InitFlag = ApInitDone;
//
// When InitFlag == ApInitConfig, WakeUpAP () guarantees all APs are checked in.
// FinishedCount is the number of check-in APs.
//
CpuMpData->CpuCount = CpuMpData->FinishedCount + 1;
ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
return CpuMpData->CpuCount;
}
@ -2226,6 +2233,18 @@ MpInitLibInitialize (
// Wakeup all APs and calculate the processor count in system
//
CollectProcessorCount (CpuMpData);
//
// Enable X2APIC if needed.
//
AutoEnableX2Apic (CpuMpData);
//
// Sort BSP/Aps by CPU APIC ID in ascending order
//
SortApicId (CpuMpData);
DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpData->CpuCount));
}
} else {
//