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 | 19 +++++++++++++++++++ UefiCpuPkg/CpuDxe/Ia32/MpAsm.S | 1 + UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm | 2 ++ UefiCpuPkg/CpuDxe/X64/MpAsm.S | 1 + UefiCpuPkg/CpuDxe/X64/MpAsm.nasm | 2 ++ 5 files changed, 25 insertions(+) diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index f732ae5..536f998 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -18,6 +18,9 @@ VOID *mCommonStack = 0; VOID *mTopOfApCommonStack = 0; +UINTN mNumberOfProcessors; +BOOLEAN volatile mAllApsInitFinished = FALSE; + /** Application Processor C code entry point @@ -32,6 +35,9 @@ ApEntryPointInC ( /* Ap initialization */ AsmApDoneWithCommonStack (); + /* Wait for all Aps complete to initialization */ + while (!mAllApsInitFinished); + CpuDeadLoop (); } @@ -51,8 +57,21 @@ InitializeMpSupport ( return; } + mNumberOfProcessors = 1; + StartApsStackless (AsmApEntryPoint); + 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/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/Ia32/MpAsm.nasm b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm index 2ecaa7f..8e0b23f 100644 --- a/UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm +++ b/UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm @@ -13,6 +13,7 @@ extern ASM_PFX(mTopOfApCommonStack) extern ASM_PFX(ApEntryPointInC) +extern ASM_PFX(mNumberOfProcessors) ; ; point to the external interrupt vector table @@ -35,6 +36,7 @@ lock bts dword [ApStackLock], 0 pause jc AsmApEntryPointAcquireLock + inc dword [ASM_PFX(mNumberOfProcessors)] mov esp, [ASM_PFX(mTopOfApCommonStack)] 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) diff --git a/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm b/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm index 2323443..2de5e9c 100644 --- a/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm +++ b/UefiCpuPkg/CpuDxe/X64/MpAsm.nasm @@ -13,6 +13,7 @@ extern ASM_PFX(mTopOfApCommonStack) extern ASM_PFX(ApEntryPointInC) +extern ASM_PFX(mNumberOfProcessors) ; ; point to the external interrupt vector table @@ -35,6 +36,7 @@ lock bts dword [ApStackLock], 0 pause jc AsmApEntryPointAcquireLock + inc dword [ASM_PFX(mNumberOfProcessors)] mov rsp, [ASM_PFX(mTopOfApCommonStack)] 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
