]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuCommonFeaturesLib: Support X2APIC enable
authorJeff Fan <jeff.fan@intel.com>
Wed, 24 May 2017 05:45:25 +0000 (13:45 +0800)
committerJeff Fan <jeff.fan@intel.com>
Sat, 27 May 2017 05:29:38 +0000 (13:29 +0800)
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>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c

index aa6d1122b1a290448ec33e351a9a3eb363681aff..9a7afed105706ae747036148d8192e7a11f2514a 100644 (file)
@@ -797,6 +797,21 @@ C1eInitialize (
   IN BOOLEAN                           State\r
   );\r
 \r
   IN BOOLEAN                           State\r
   );\r
 \r
+/**\r
+  Prepares for the data used by CPU feature detection and initialization.\r
+\r
+  @param[in]  NumberOfProcessors  The number of CPUs in the platform.\r
+\r
+  @return  Pointer to a buffer of CPU related configuration data.\r
+\r
+  @note This service could be called by BSP only.\r
+**/\r
+VOID *\r
+EFIAPI\r
+X2ApicGetConfigData (\r
+  IN UINTN  NumberOfProcessors\r
+  );\r
+\r
 /**\r
   Detects if X2Apci feature supported on current processor.\r
 \r
 /**\r
   Detects if X2Apci feature supported on current processor.\r
 \r
index 3390aa8f2a7af75994cc55a40c125467ade84662..793a0956d3f82520578fb0fa6261d1c70d1ed231 100644 (file)
@@ -211,7 +211,7 @@ CpuCommonFeaturesLibConstructor (
   if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) {\r
     Status = RegisterCpuFeature (\r
                "X2Apic",\r
   if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) {\r
     Status = RegisterCpuFeature (\r
                "X2Apic",\r
-               NULL,\r
+               X2ApicGetConfigData,\r
                X2ApicSupport,\r
                X2ApicInitialize,\r
                CPU_FEATURE_X2APIC,\r
                X2ApicSupport,\r
                X2ApicInitialize,\r
                CPU_FEATURE_X2APIC,\r
index 9c2ad9ad313e8a57260b1a10d3d0e9aa524b7275..b4a453c3525c4c9acf6b3af5ae665fb98c725610 100644 (file)
 \r
 #include "CpuCommonFeatures.h"\r
 \r
 \r
 #include "CpuCommonFeatures.h"\r
 \r
+/**\r
+  Prepares for the data used by CPU feature detection and initialization.\r
+\r
+  @param[in]  NumberOfProcessors  The number of CPUs in the platform.\r
+\r
+  @return  Pointer to a buffer of CPU related configuration data.\r
+\r
+  @note This service could be called by BSP only.\r
+**/\r
+VOID *\r
+EFIAPI\r
+X2ApicGetConfigData (\r
+  IN UINTN  NumberOfProcessors\r
+  )\r
+{\r
+  BOOLEAN                            *ConfigData;\r
+\r
+  ConfigData = AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors);\r
+  ASSERT (ConfigData != NULL);\r
+  return ConfigData;\r
+}\r
+\r
 /**\r
   Detects if X2Apci feature supported on current processor.\r
 \r
 /**\r
   Detects if X2Apci feature supported on current processor.\r
 \r
@@ -40,7 +62,16 @@ X2ApicSupport (
   IN VOID                              *ConfigData  OPTIONAL\r
   )\r
 {\r
   IN VOID                              *ConfigData  OPTIONAL\r
   )\r
 {\r
-  return (GetApicMode () == LOCAL_APIC_MODE_X2APIC);\r
+  BOOLEAN                            *X2ApicEnabled;\r
+\r
+  ASSERT (ConfigData != NULL);\r
+  X2ApicEnabled = (BOOLEAN *) ConfigData;\r
+  //\r
+  // *ConfigData indicates if X2APIC enabled on current processor\r
+  //\r
+  X2ApicEnabled[ProcessorNumber] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC) ? TRUE : FALSE;\r
+\r
+  return (CpuInfo->CpuIdVersionInfoEcx.Bits.x2APIC == 1);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -69,13 +100,34 @@ X2ApicInitialize (
   IN BOOLEAN                           State\r
   )\r
 {\r
   IN BOOLEAN                           State\r
   )\r
 {\r
-  PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (\r
-    ProcessorNumber,\r
-    Msr,\r
-    MSR_IA32_APIC_BASE,\r
-    MSR_IA32_APIC_BASE_REGISTER,\r
-    Bits.EXTD,\r
-    (State) ? 1 : 0\r
-    );\r
+  BOOLEAN                            *X2ApicEnabled;\r
+\r
+  ASSERT (ConfigData != NULL);\r
+  X2ApicEnabled = (BOOLEAN *) ConfigData;\r
+  if (X2ApicEnabled[ProcessorNumber]) {\r
+    PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (\r
+      ProcessorNumber,\r
+      Msr,\r
+      MSR_IA32_APIC_BASE,\r
+      MSR_IA32_APIC_BASE_REGISTER,\r
+      Bits.EXTD,\r
+      1\r
+      );\r
+  } else {\r
+    //\r
+    // Enable X2APIC mode only if X2APIC is not enabled,\r
+    // Needn't to disabe X2APIC mode again if X2APIC is not enabled\r
+    //\r
+    if (State) {\r
+      CPU_REGISTER_TABLE_WRITE_FIELD (\r
+        ProcessorNumber,\r
+        Msr,\r
+        MSR_IA32_APIC_BASE,\r
+        MSR_IA32_APIC_BASE_REGISTER,\r
+        Bits.EXTD,\r
+        1\r
+        );\r
+    }\r
+  }\r
   return RETURN_SUCCESS;\r
 }\r
   return RETURN_SUCCESS;\r
 }\r