BSP should detect the AP COUNT to know the AP presence. So in AP initialization code, AP increased the COUNT, and BSP waited 100ms to get the COUNT. then BSP could allocate stack spaces for the APs.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen Fan <[email protected]> --- UefiCpuPkg/CpuDxe/CpuMp.c | 20 ++++++++++++++++++++ UefiCpuPkg/CpuDxe/CpuMp.h | 2 ++ UefiCpuPkg/CpuDxe/Ia32/MpAsm.S | 1 + UefiCpuPkg/CpuDxe/X64/MpAsm.S | 1 + 4 files changed, 24 insertions(+) diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index 154c824..eda70e3 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -18,6 +18,8 @@ VOID *mCommonStack = 0; VOID *mTopOfApCommonStack = 0; +UINTN mNumberOfProcessors; +BOOLEAN mAllApsInitFinished = FALSE; VOID EFIAPI @@ -28,6 +30,9 @@ ApEntryPointInC ( /* Ap initialization */ AsmApDoneWithCommonStack (); + /* Wait for all Aps complete to initialization */ + while (!mAllApsInitFinished); + CpuDeadLoop (); } @@ -43,8 +48,23 @@ InitializeMpSupport ( return; } + mNumberOfProcessors = 1; + StartApsStackless (AsmApEntryPoint); + gBS->Stall (STALL_100_MILLI_SECOND); + + if (mNumberOfProcessors == 1) { + goto EXIT; + } + + DEBUG ((DEBUG_ERROR, "Detect CPU count: %d\n", mNumberOfProcessors)); + + mAllApsInitFinished = TRUE; + + CpuDeadLoop (); + +EXIT: mTopOfApCommonStack = NULL; FreePages (mCommonStack, EFI_SIZE_TO_PAGES (SIZE_64KB)); mCommonStack = NULL; diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h index c133c5f..35394f7 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.h +++ b/UefiCpuPkg/CpuDxe/CpuMp.h @@ -15,6 +15,8 @@ #ifndef _CPU_MP_H_ #define _CPU_MP_H_ +#define STALL_100_MILLI_SECOND (1000 * 100) + VOID InitializeMpSupport ( VOID ); diff --git a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S index 2b3d298..bc42c38 100644 --- a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S +++ b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.S @@ -33,6 +33,7 @@ lock btsl $0, ApStackLock pause jc AsmApEntryPointAcquireLock + incl ASM_PFX(mNumberOfProcessors) movl (ASM_PFX(mTopOfApCommonStack)), %esp call ASM_PFX(ApEntryPointInC) diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.S b/UefiCpuPkg/CpuDxe/X64/MpAsm.S index cfad551..bf488d3 100644 --- a/UefiCpuPkg/CpuDxe/X64/MpAsm.S +++ b/UefiCpuPkg/CpuDxe/X64/MpAsm.S @@ -33,6 +33,7 @@ lock btsl $0, ApStackLock pause jc AsmApEntryPointAcquireLock + incl ASM_PFX(mNumberOfProcessors) movq (ASM_PFX(mTopOfApCommonStack)), %rsp call ASM_PFX(ApEntryPointInC) -- 1.9.3 ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
