]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c
UefiCpuPkg/CpuFeatures: Change files format to DOS
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / MachineCheck.c
CommitLineData
80c4b236
JF
1/** @file\r
2 Machine Check features.\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 Machine Check Exception feature supported on current processor.\r
19\r
20 @param[in] ProcessorNumber The index of the CPU executing this function.\r
21 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
22 structure for the CPU executing this function.\r
23 @param[in] ConfigData A pointer to the configuration buffer returned\r
24 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
25 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
26 RegisterCpuFeature().\r
27\r
28 @retval TRUE Machine Check Exception feature is supported.\r
29 @retval FALSE Machine Check Exception feature is not supported.\r
30\r
31 @note This service could be called by BSP/APs.\r
32**/\r
33BOOLEAN\r
34EFIAPI\r
35MceSupport (\r
36 IN UINTN ProcessorNumber,\r
37 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
38 IN VOID *ConfigData OPTIONAL\r
39 )\r
40{\r
41 return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCE == 1);\r
42}\r
43\r
44/**\r
45 Initializes Machine Check Exception feature to specific state.\r
46\r
47 @param[in] ProcessorNumber The index of the CPU executing this function.\r
48 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
49 structure for the CPU executing this function.\r
50 @param[in] ConfigData A pointer to the configuration buffer returned\r
51 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
52 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
53 RegisterCpuFeature().\r
54 @param[in] State If TRUE, then the Machine Check Exception feature must be enabled.\r
55 If FALSE, then the Machine Check Exception feature must be disabled.\r
56\r
57 @retval RETURN_SUCCESS Machine Check Exception feature is initialized.\r
58\r
59 @note This service could be called by BSP only.\r
60**/\r
61RETURN_STATUS\r
62EFIAPI\r
63MceInitialize (\r
64 IN UINTN ProcessorNumber,\r
65 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
66 IN VOID *ConfigData, OPTIONAL\r
67 IN BOOLEAN State\r
68 )\r
69{\r
70 //\r
71 // Set MCE bit in CR4\r
72 //\r
73 CPU_REGISTER_TABLE_WRITE_FIELD (\r
74 ProcessorNumber,\r
75 ControlRegister,\r
76 4,\r
77 IA32_CR4,\r
78 Bits.MCE,\r
79 (State) ? 1 : 0\r
80 );\r
81 return RETURN_SUCCESS;\r
82}\r
83\r
84/**\r
85 Detects if Machine Check Architecture feature supported on current processor.\r
86\r
87 @param[in] ProcessorNumber The index of the CPU executing this function.\r
88 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
89 structure for the CPU executing this function.\r
90 @param[in] ConfigData A pointer to the configuration buffer returned\r
91 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
92 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
93 RegisterCpuFeature().\r
94\r
95 @retval TRUE Machine Check Architecture feature is supported.\r
96 @retval FALSE Machine Check Architecture feature is not supported.\r
97\r
98 @note This service could be called by BSP/APs.\r
99**/\r
100BOOLEAN\r
101EFIAPI\r
102McaSupport (\r
103 IN UINTN ProcessorNumber,\r
104 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
105 IN VOID *ConfigData OPTIONAL\r
106 )\r
107{\r
108 return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCA == 1);\r
109}\r
110\r
111/**\r
112 Initializes Machine Check Architecture feature to specific state.\r
113\r
114 @param[in] ProcessorNumber The index of the CPU executing this function.\r
115 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
116 structure for the CPU executing this function.\r
117 @param[in] ConfigData A pointer to the configuration buffer returned\r
118 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
119 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
120 RegisterCpuFeature().\r
121 @param[in] State If TRUE, then the Machine Check Architecture feature must be enabled.\r
122 If FALSE, then the Machine Check Architecture feature must be disabled.\r
123\r
124 @retval RETURN_SUCCESS Machine Check Architecture feature is initialized.\r
125\r
126 @note This service could be called by BSP only.\r
127**/\r
128RETURN_STATUS\r
129EFIAPI\r
130McaInitialize (\r
131 IN UINTN ProcessorNumber,\r
132 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
133 IN VOID *ConfigData, OPTIONAL\r
134 IN BOOLEAN State\r
135 )\r
136{\r
137 MSR_IA32_MCG_CAP_REGISTER McgCap;\r
138 UINT32 BankIndex;\r
139\r
140 McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);\r
141 for (BankIndex = 0; BankIndex < (UINT32) McgCap.Bits.Count; BankIndex++) {\r
142 CPU_REGISTER_TABLE_WRITE64 (\r
143 ProcessorNumber,\r
144 Msr,\r
145 MSR_IA32_MC0_CTL + BankIndex * 4,\r
146 MAX_UINT64\r
147 );\r
148 }\r
149\r
150 if (PcdGetBool (PcdIsPowerOnReset)) {\r
151 for (BankIndex = 0; BankIndex < (UINTN) McgCap.Bits.Count; BankIndex++) {\r
152 CPU_REGISTER_TABLE_WRITE64 (\r
153 ProcessorNumber,\r
154 Msr,\r
155 MSR_IA32_MC0_STATUS + BankIndex * 4,\r
156 0\r
157 );\r
158 }\r
159 }\r
160\r
161 return RETURN_SUCCESS;\r
162}\r
163\r
164/**\r
165 Detects if IA32_MCG_CTL feature supported on current processor.\r
166\r
167 @param[in] ProcessorNumber The index of the CPU executing this function.\r
168 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
169 structure for the CPU executing this function.\r
170 @param[in] ConfigData A pointer to the configuration buffer returned\r
171 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
172 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
173 RegisterCpuFeature().\r
174\r
175 @retval TRUE IA32_MCG_CTL feature is supported.\r
176 @retval FALSE IA32_MCG_CTL feature is not supported.\r
177\r
178 @note This service could be called by BSP/APs.\r
179**/\r
180BOOLEAN\r
181EFIAPI\r
182McgCtlSupport (\r
183 IN UINTN ProcessorNumber,\r
184 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
185 IN VOID *ConfigData OPTIONAL\r
186 )\r
187{\r
188 MSR_IA32_MCG_CAP_REGISTER McgCap;\r
189\r
190 if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {\r
191 return FALSE;\r
192 }\r
193 McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);\r
194 return (McgCap.Bits.MCG_CTL_P == 1);\r
195}\r
196\r
197/**\r
198 Initializes IA32_MCG_CTL feature to specific state.\r
199\r
200 @param[in] ProcessorNumber The index of the CPU executing this function.\r
201 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
202 structure for the CPU executing this function.\r
203 @param[in] ConfigData A pointer to the configuration buffer returned\r
204 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
205 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
206 RegisterCpuFeature().\r
207 @param[in] State If TRUE, then the IA32_MCG_CTL feature must be enabled.\r
208 If FALSE, then the IA32_MCG_CTL feature must be disabled.\r
209\r
210 @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized.\r
211\r
212 @note This service could be called by BSP only.\r
213**/\r
214RETURN_STATUS\r
215EFIAPI\r
216McgCtlInitialize (\r
217 IN UINTN ProcessorNumber,\r
218 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
219 IN VOID *ConfigData, OPTIONAL\r
220 IN BOOLEAN State\r
221 )\r
222{\r
223 CPU_REGISTER_TABLE_WRITE64 (\r
224 ProcessorNumber,\r
225 Msr,\r
226 MSR_IA32_MCG_CTL,\r
227 (State)? MAX_UINT64 : 0\r
228 );\r
229 return RETURN_SUCCESS;\r
230}\r
231\r