public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Enable X2APIC after MP service is ready
@ 2017-05-26 13:12 Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable Jeff Fan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jeff Fan @ 2017-05-26 13:12 UTC (permalink / raw)
  To: edk2-devel

https://bugzilla.tianocore.org/show_bug.cgi?id=575

v2:
  Updated #1 comments

v3:
  1. Remove ASSERT() in #1 if X2APIC enable but user configuration is FALSE.
  2. Add #3 to force X2APIC mode if CPU number > 255.


Jeff Fan (3):
  UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable
  UefiCpuPkg/MpInitLib: Check APIC mode change around AP function
  UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255

 .../CpuCommonFeaturesLib/CpuCommonFeatures.h       | 15 +++++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c    |  2 +-
 UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c   | 72 +++++++++++++++++++---
 UefiCpuPkg/Library/MpInitLib/MpLib.c               | 32 ++++++++--
 4 files changed, 104 insertions(+), 17 deletions(-)

-- 
2.9.3.windows.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable
  2017-05-26 13:12 [PATCH v3 0/3] Enable X2APIC after MP service is ready Jeff Fan
@ 2017-05-26 13:12 ` Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 2/3] UefiCpuPkg/MpInitLib: Check APIC mode change around AP function Jeff Fan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Fan @ 2017-05-26 13:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Eric Dong

Current X2APIC is enabled in MpInitLib (used by CpuMpPei and CpuDxe) to follow
SDM suggestion. That means we only enable X2APIC if we found there are any
initial CPU ID value >= 255.

This patch is to provide one chance for platform to enable X2APIC even there is
no any initial CPU ID value >= 255.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 .../CpuCommonFeaturesLib/CpuCommonFeatures.h       | 15 +++++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c    |  2 +-
 UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c   | 72 +++++++++++++++++++---
 3 files changed, 78 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
index aa6d112..9a7afed 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
@@ -798,6 +798,21 @@ C1eInitialize (
   );
 
 /**
+  Prepares for the data used by CPU feature detection and initialization.
+
+  @param[in]  NumberOfProcessors  The number of CPUs in the platform.
+
+  @return  Pointer to a buffer of CPU related configuration data.
+
+  @note This service could be called by BSP only.
+**/
+VOID *
+EFIAPI
+X2ApicGetConfigData (
+  IN UINTN  NumberOfProcessors
+  );
+
+/**
   Detects if X2Apci feature supported on current processor.
 
   Detect if X2Apci has been already enabled.
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
index 3390aa8..793a095 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
@@ -211,7 +211,7 @@ CpuCommonFeaturesLibConstructor (
   if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) {
     Status = RegisterCpuFeature (
                "X2Apic",
-               NULL,
+               X2ApicGetConfigData,
                X2ApicSupport,
                X2ApicInitialize,
                CPU_FEATURE_X2APIC,
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c
index 9c2ad9a..fe36368 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c
@@ -15,6 +15,28 @@
 #include "CpuCommonFeatures.h"
 
 /**
+  Prepares for the data used by CPU feature detection and initialization.
+
+  @param[in]  NumberOfProcessors  The number of CPUs in the platform.
+
+  @return  Pointer to a buffer of CPU related configuration data.
+
+  @note This service could be called by BSP only.
+**/
+VOID *
+EFIAPI
+X2ApicGetConfigData (
+  IN UINTN  NumberOfProcessors
+  )
+{
+  BOOLEAN                            *ConfigData;
+
+  ConfigData = AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors);
+  ASSERT (ConfigData != NULL);
+  return ConfigData;
+}
+
+/**
   Detects if X2Apci feature supported on current processor.
 
   Detect if X2Apci has been already enabled.
@@ -39,8 +61,17 @@ X2ApicSupport (
   IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
   IN VOID                              *ConfigData  OPTIONAL
   )
-{
-  return (GetApicMode () == LOCAL_APIC_MODE_X2APIC);
+{  
+  BOOLEAN                            *X2ApicEnabled;
+
+  ASSERT (ConfigData != NULL);
+  X2ApicEnabled = (BOOLEAN *) ConfigData;
+  //
+  // *ConfigData indicates if X2APIC enabled on current processor
+  //
+  X2ApicEnabled[ProcessorNumber] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC) ? TRUE : FALSE;
+
+  return (CpuInfo->CpuIdVersionInfoEcx.Bits.x2APIC == 1);
 }
 
 /**
@@ -69,13 +100,34 @@ X2ApicInitialize (
   IN BOOLEAN                           State
   )
 {
-  PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
-    ProcessorNumber,
-    Msr,
-    MSR_IA32_APIC_BASE,
-    MSR_IA32_APIC_BASE_REGISTER,
-    Bits.EXTD,
-    (State) ? 1 : 0
-    );
+  BOOLEAN                            *X2ApicEnabled;
+
+  ASSERT (ConfigData != NULL);
+  X2ApicEnabled = (BOOLEAN *) ConfigData;
+  if (X2ApicEnabled[ProcessorNumber]) {
+    PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
+      ProcessorNumber,
+      Msr,
+      MSR_IA32_APIC_BASE,
+      MSR_IA32_APIC_BASE_REGISTER,
+      Bits.EXTD,
+      1
+      );
+  } else {
+    //
+    // Enable X2APIC mode only if X2APIC is not enabled,
+    // Needn't to disabe X2APIC mode again if X2APIC is not enabled
+    //
+    if (State) {
+      CPU_REGISTER_TABLE_WRITE_FIELD (
+        ProcessorNumber,
+        Msr,
+        MSR_IA32_APIC_BASE,
+        MSR_IA32_APIC_BASE_REGISTER,
+        Bits.EXTD,
+        1
+        );
+    }
+  }
   return RETURN_SUCCESS;
 }
-- 
2.9.3.windows.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] UefiCpuPkg/MpInitLib: Check APIC mode change around AP function
  2017-05-26 13:12 [PATCH v3 0/3] Enable X2APIC after MP service is ready Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable Jeff Fan
@ 2017-05-26 13:12 ` Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 3/3] UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255 Jeff Fan
  2017-05-27  3:21 ` [PATCH v3 0/3] Enable X2APIC after MP service is ready Dong, Eric
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Fan @ 2017-05-26 13:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Eric Dong

If APIC ID values are changed during AP functions execution, we need to update
new APIC ID values in local data structure accordingly.

But if APIC mode change happened during AP function execution, we do not support
APIC ID value changed.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 735e099..c6f8191 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -547,6 +547,7 @@ ApWakeupFunction (
   volatile UINT32            *ApStartupSignalBuffer;
   CPU_INFO_IN_HOB            *CpuInfoInHob;
   UINT64                     ApTopOfStack;
+  UINTN                      CurrentApicMode;
 
   //
   // AP finished assembly code and begin to execute C code
@@ -560,6 +561,7 @@ ApWakeupFunction (
   ProgramVirtualWireMode ();
   SyncLocalApicTimerSetting (CpuMpData);
 
+  CurrentApicMode = GetApicMode ();
   while (TRUE) {
     if (CpuMpData->InitFlag == ApInitConfig) {
       //
@@ -627,11 +629,23 @@ ApWakeupFunction (
             ApStartupSignalBuffer = CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
             CpuInfoInHob[ProcessorNumber].ApTopOfStack = CpuInfoInHob[CpuMpData->NewBspNumber].ApTopOfStack;
           } else {
-            //
-            // Re-get the CPU APICID and Initial APICID
-            //
-            CpuInfoInHob[ProcessorNumber].ApicId        = GetApicId ();
-            CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
+            if (CpuInfoInHob[ProcessorNumber].ApicId != GetApicId () ||
+                CpuInfoInHob[ProcessorNumber].InitialApicId != GetInitialApicId ()) {
+              if (CurrentApicMode != GetApicMode ()) {
+                //
+                // If APIC mode change happened during AP function execution,
+                // we do not support APIC ID value changed.
+                //
+                ASSERT (FALSE);
+                CpuDeadLoop ();
+              } else {
+                //
+                // Re-get the CPU APICID and Initial APICID if they are changed
+                //
+                CpuInfoInHob[ProcessorNumber].ApicId        = GetApicId ();
+                CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
+              }
+            }
           }
         }
         SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
-- 
2.9.3.windows.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255
  2017-05-26 13:12 [PATCH v3 0/3] Enable X2APIC after MP service is ready Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable Jeff Fan
  2017-05-26 13:12 ` [PATCH v3 2/3] UefiCpuPkg/MpInitLib: Check APIC mode change around AP function Jeff Fan
@ 2017-05-26 13:12 ` Jeff Fan
  2017-05-27  3:21 ` [PATCH v3 0/3] Enable X2APIC after MP service is ready Dong, Eric
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Fan @ 2017-05-26 13:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Eric Dong

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index c6f8191..df19b43 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -451,6 +451,12 @@ CollectProcessorCount (
     CpuPause ();
   }
 
+  if (CpuMpData->CpuCount > 255) {
+    //
+    // If there are more than 255 processor found, force to enable X2APIC
+    //
+    CpuMpData->X2ApicEnable = TRUE;
+  }
   if (CpuMpData->X2ApicEnable) {
     DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n"));
     //
@@ -1412,7 +1418,7 @@ MpInitLibInitialize (
     CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
     for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
       InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
-      if (CpuInfoInHob[Index].InitialApicId >= 255) {
+      if (CpuInfoInHob[Index].InitialApicId >= 255 || Index > 254) {
         CpuMpData->X2ApicEnable = TRUE;
       }
       CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
-- 
2.9.3.windows.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] Enable X2APIC after MP service is ready
  2017-05-26 13:12 [PATCH v3 0/3] Enable X2APIC after MP service is ready Jeff Fan
                   ` (2 preceding siblings ...)
  2017-05-26 13:12 ` [PATCH v3 3/3] UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255 Jeff Fan
@ 2017-05-27  3:21 ` Dong, Eric
  3 siblings, 0 replies; 5+ messages in thread
From: Dong, Eric @ 2017-05-27  3:21 UTC (permalink / raw)
  To: Fan, Jeff, edk2-devel@lists.01.org

Please remove the extra space in patch 1/3 when you check in.

Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jeff Fan
Sent: Friday, May 26, 2017 9:12 PM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v3 0/3] Enable X2APIC after MP service is ready

https://bugzilla.tianocore.org/show_bug.cgi?id=575

v2:
  Updated #1 comments

v3:
  1. Remove ASSERT() in #1 if X2APIC enable but user configuration is FALSE.
  2. Add #3 to force X2APIC mode if CPU number > 255.


Jeff Fan (3):
  UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable
  UefiCpuPkg/MpInitLib: Check APIC mode change around AP function
  UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255

 .../CpuCommonFeaturesLib/CpuCommonFeatures.h       | 15 +++++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c    |  2 +-
 UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c   | 72 +++++++++++++++++++---
 UefiCpuPkg/Library/MpInitLib/MpLib.c               | 32 ++++++++--
 4 files changed, 104 insertions(+), 17 deletions(-)

-- 
2.9.3.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-27  3:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-26 13:12 [PATCH v3 0/3] Enable X2APIC after MP service is ready Jeff Fan
2017-05-26 13:12 ` [PATCH v3 1/3] UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable Jeff Fan
2017-05-26 13:12 ` [PATCH v3 2/3] UefiCpuPkg/MpInitLib: Check APIC mode change around AP function Jeff Fan
2017-05-26 13:12 ` [PATCH v3 3/3] UefiCpuPkg/MpInitLib: Force to enable X2APIC if CPU number > 255 Jeff Fan
2017-05-27  3:21 ` [PATCH v3 0/3] Enable X2APIC after MP service is ready Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox