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...@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 +++++++++++
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index bf80455965..2372475a04 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -694,6 +694,12 @@ ApWakeupFunction (
       ApStackData  = (AP_STACK_DATA *)((UINTN)ApTopOfStack - sizeof 
(AP_STACK_DATA));
       BistData     = (UINT32)ApStackData->Bist;
 
+      //
+      // Synchronize APIC mode with BSP in the first time AP wakeup ONLY.
+      //
+      SetApicMode (CpuMpData->InitialBspApicMode);
+      CurrentApicMode = CpuMpData->InitialBspApicMode;
+
       //
       // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP 
environment,
       //   to initialize AP in InitConfig path.
@@ -1977,6 +1983,11 @@ MpInitLibInitialize (
   //
   ProgramVirtualWireMode ();
 
+  //
+  // Save APIC mode for AP to sync
+  //
+  CpuMpData->InitialBspApicMode = GetApicMode ();
+
   if (OldCpuMpData == NULL) {
     if (MaxLogicalProcessorNumber > 1) {
       //
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index b694c7b40f..1ede253334 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -243,6 +243,17 @@ struct _CPU_MP_DATA {
   //
   SPIN_LOCK                        MpLock;
   UINTN                            Buffer;
+  //
+  // InitialBspApicMode stores the initial BSP APIC mode.
+  // It is used to synchroneize 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;
-- 
2.39.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106716): https://edk2.groups.io/g/devel/message/106716
Mute This Topic: https://groups.io/mt/100000876/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: 
https://edk2.groups.io/g/devel/leave/9847357/21656/1706620634/xyzzy 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to