]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c
UefiCpuPkg/CpuCommonFeaturesLib: Use MSR data structure when change MSR value.
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / Lmce.c
CommitLineData
3d6275c1
ED
1/** @file\r
2 Local machine check exception feature.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "CpuCommonFeatures.h"\r
16\r
17/**\r
18 Detects if Local machine check exception feature supported on current \r
19 processor.\r
20\r
21 @param[in] ProcessorNumber The index of the CPU executing this function.\r
22 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
23 structure for the CPU executing this function.\r
24 @param[in] ConfigData A pointer to the configuration buffer returned\r
25 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
26 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
27 RegisterCpuFeature().\r
28\r
29 @retval TRUE Local machine check exception feature is supported.\r
30 @retval FALSE Local machine check exception feature is not supported.\r
31\r
32 @note This service could be called by BSP/APs.\r
33**/\r
34BOOLEAN\r
35EFIAPI\r
36LmceSupport (\r
37 IN UINTN ProcessorNumber,\r
38 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
39 IN VOID *ConfigData OPTIONAL\r
40 )\r
41{\r
42 MSR_IA32_MCG_CAP_REGISTER McgCap;\r
43\r
44 McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);\r
45 if (ProcessorNumber == 0) {\r
46 DEBUG ((EFI_D_INFO, "LMCE eanble = %x\n", (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0)));\r
47 }\r
48 return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);\r
49}\r
50\r
51/**\r
52 Initializes Local machine check exception feature to specific state.\r
53\r
54 @param[in] ProcessorNumber The index of the CPU executing this function.\r
55 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
56 structure for the CPU executing this function.\r
57 @param[in] ConfigData A pointer to the configuration buffer returned\r
58 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
59 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
60 RegisterCpuFeature().\r
61 @param[in] State If TRUE, then the Local machine check exception\r
62 feature must be enabled.\r
63 If FALSE, then the Local machine check exception\r
64 feature must be disabled.\r
65\r
66 @retval RETURN_SUCCESS Local machine check exception feature is initialized.\r
67\r
68**/\r
69RETURN_STATUS\r
70EFIAPI\r
71LmceInitialize (\r
72 IN UINTN ProcessorNumber,\r
73 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
74 IN VOID *ConfigData, OPTIONAL\r
75 IN BOOLEAN State\r
76 )\r
77{\r
78 MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister;\r
79\r
80 ASSERT (ConfigData != NULL);\r
81 MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData;\r
82 if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {\r
83 CPU_REGISTER_TABLE_WRITE_FIELD (\r
84 ProcessorNumber,\r
85 Msr,\r
86 MSR_IA32_FEATURE_CONTROL,\r
87 MSR_IA32_FEATURE_CONTROL_REGISTER,\r
88 Bits.LmceOn,\r
89 (State) ? 1 : 0\r
90 );\r
91 }\r
92 return RETURN_SUCCESS;\r
93}\r