]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuCommonFeaturesLib: Merge machine check code to same file.
authorEric Dong <eric.dong@intel.com>
Thu, 17 Aug 2017 03:40:38 +0000 (11:40 +0800)
committerEric Dong <eric.dong@intel.com>
Mon, 28 Aug 2017 07:23:21 +0000 (15:23 +0800)
Original code about Local Machine Check exception feature saves in a
discrete file, because features related to machine check architecture
all saved in MachineCheck.c file. This patch moved LMCE logic to same
file for easy maintenance.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c

index 9fc3a9c86d69720c378d0572b724f1dbf76c7ee1..e9225bb96ae6fc8097fe2864f43899b7c333f919 100644 (file)
@@ -48,7 +48,6 @@
   PendingBreak.c\r
   X2Apic.c\r
   Ppin.c\r
-  Lmce.c\r
   ProcTrace.c\r
 \r
 [Packages]\r
index 72f665d32e36ec442dec20deb307622405ae4e68..b012c6926e602126e7ea6953a715fe7cbd7b8ad8 100644 (file)
@@ -229,3 +229,84 @@ McgCtlInitialize (
   return RETURN_SUCCESS;\r
 }\r
 \r
+/**\r
+  Detects if Local machine check exception feature supported on current \r
+  processor.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+\r
+  @retval TRUE     Local machine check exception feature is supported.\r
+  @retval FALSE    Local machine check exception feature is not supported.\r
+\r
+  @note This service could be called by BSP/APs.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LmceSupport (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData  OPTIONAL\r
+  )\r
+{\r
+  MSR_IA32_MCG_CAP_REGISTER    McgCap;\r
+\r
+  if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {\r
+    return FALSE;\r
+  }\r
+\r
+  McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);\r
+  if (ProcessorNumber == 0) {\r
+    DEBUG ((EFI_D_INFO, "LMCE eanble = %x\n", (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0)));\r
+  }\r
+  return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);\r
+}\r
+\r
+/**\r
+  Initializes Local machine check exception feature to specific state.\r
+\r
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.\r
+  @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
+                               structure for the CPU executing this function.\r
+  @param[in]  ConfigData       A pointer to the configuration buffer returned\r
+                               by CPU_FEATURE_GET_CONFIG_DATA.  NULL if\r
+                               CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
+                               RegisterCpuFeature().\r
+  @param[in]  State            If TRUE, then the Local machine check exception\r
+                               feature must be enabled.\r
+                               If FALSE, then the Local machine check exception\r
+                               feature must be disabled.\r
+\r
+  @retval RETURN_SUCCESS       Local machine check exception feature is initialized.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LmceInitialize (\r
+  IN UINTN                             ProcessorNumber,\r
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,\r
+  IN VOID                              *ConfigData,  OPTIONAL\r
+  IN BOOLEAN                           State\r
+  )\r
+{\r
+  MSR_IA32_FEATURE_CONTROL_REGISTER    *MsrRegister;\r
+\r
+  ASSERT (ConfigData != NULL);\r
+  MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData;\r
+  if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {\r
+    CPU_REGISTER_TABLE_WRITE_FIELD (\r
+      ProcessorNumber,\r
+      Msr,\r
+      MSR_IA32_FEATURE_CONTROL,\r
+      MSR_IA32_FEATURE_CONTROL_REGISTER,\r
+      Bits.LmceOn,\r
+      (State) ? 1 : 0\r
+      );\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r