If x2APIC flag is set, enable x2APIC mode on all APs and BSP. Before we wakeup
APs to enable x2APIC mode, we should wait all APs have finished initialization.

Cc: Feng Tian <[email protected]>
Cc: Michael Kinney <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>
---
 UefiCpuPkg/CpuMpPei/CpuMpPei.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index c6fcb8f..b815bb9 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -459,7 +459,31 @@ CountProcessorNumber (
     PeiCpuMpData->InitFlag  = FALSE;
     PeiCpuMpData->CpuCount += 
(UINT32)PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting;
     ASSERT (PeiCpuMpData->CpuCount <= PcdGet32 
(PcdCpuMaxLogicalProcessorNumber));
+    //
+    // Wait for all APs finished the initialization
+    //
+    while (PeiCpuMpData->FinishedCount < (PeiCpuMpData->CpuCount - 1)) {
+      CpuPause ();
+    }
 
+    if (PeiCpuMpData->X2ApicEnable) {
+      DEBUG ((EFI_D_INFO, "Force x2APIC mode!\n"));
+      //
+      // Send 2nd broadcast IPI to all APs to enable x2APIC mode
+      //
+      WakeUpAP (PeiCpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL);
+      //
+      // Wait for all known APs finished
+      //
+      while (PeiCpuMpData->FinishedCount < (PeiCpuMpData->CpuCount - 1)) {
+        CpuPause ();
+      }
+      //
+      // Enable x2APIC on BSP
+      //
+      SetApicMode (LOCAL_APIC_MODE_X2APIC);
+    }
+    DEBUG ((EFI_D_INFO, "APIC MODE is %d\n", GetApicMode ()));
     //
     // Sort BSP/Aps by CPU APIC ID in ascending order
     //
-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to