1 | /** @file
|
---|
2 | Machine Check features.
|
---|
3 |
|
---|
4 | Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "CpuCommonFeatures.h"
|
---|
10 |
|
---|
11 | /**
|
---|
12 | Detects if Machine Check Exception feature supported on current processor.
|
---|
13 |
|
---|
14 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
15 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
16 | structure for the CPU executing this function.
|
---|
17 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
18 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
19 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
20 | RegisterCpuFeature().
|
---|
21 |
|
---|
22 | @retval TRUE Machine Check Exception feature is supported.
|
---|
23 | @retval FALSE Machine Check Exception feature is not supported.
|
---|
24 |
|
---|
25 | @note This service could be called by BSP/APs.
|
---|
26 | **/
|
---|
27 | BOOLEAN
|
---|
28 | EFIAPI
|
---|
29 | MceSupport (
|
---|
30 | IN UINTN ProcessorNumber,
|
---|
31 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
32 | IN VOID *ConfigData OPTIONAL
|
---|
33 | )
|
---|
34 | {
|
---|
35 | return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCE == 1);
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | Initializes Machine Check Exception feature to specific state.
|
---|
40 |
|
---|
41 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
42 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
43 | structure for the CPU executing this function.
|
---|
44 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
45 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
46 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
47 | RegisterCpuFeature().
|
---|
48 | @param[in] State If TRUE, then the Machine Check Exception feature must be enabled.
|
---|
49 | If FALSE, then the Machine Check Exception feature must be disabled.
|
---|
50 |
|
---|
51 | @retval RETURN_SUCCESS Machine Check Exception feature is initialized.
|
---|
52 |
|
---|
53 | @note This service could be called by BSP only.
|
---|
54 | **/
|
---|
55 | RETURN_STATUS
|
---|
56 | EFIAPI
|
---|
57 | MceInitialize (
|
---|
58 | IN UINTN ProcessorNumber,
|
---|
59 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
60 | IN VOID *ConfigData OPTIONAL,
|
---|
61 | IN BOOLEAN State
|
---|
62 | )
|
---|
63 | {
|
---|
64 | //
|
---|
65 | // Set MCE bit in CR4
|
---|
66 | //
|
---|
67 | CPU_REGISTER_TABLE_WRITE_FIELD (
|
---|
68 | ProcessorNumber,
|
---|
69 | ControlRegister,
|
---|
70 | 4,
|
---|
71 | IA32_CR4,
|
---|
72 | Bits.MCE,
|
---|
73 | (State) ? 1 : 0
|
---|
74 | );
|
---|
75 | return RETURN_SUCCESS;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | Detects if Machine Check Architecture feature supported on current processor.
|
---|
80 |
|
---|
81 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
82 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
83 | structure for the CPU executing this function.
|
---|
84 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
85 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
86 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
87 | RegisterCpuFeature().
|
---|
88 |
|
---|
89 | @retval TRUE Machine Check Architecture feature is supported.
|
---|
90 | @retval FALSE Machine Check Architecture feature is not supported.
|
---|
91 |
|
---|
92 | @note This service could be called by BSP/APs.
|
---|
93 | **/
|
---|
94 | BOOLEAN
|
---|
95 | EFIAPI
|
---|
96 | McaSupport (
|
---|
97 | IN UINTN ProcessorNumber,
|
---|
98 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
99 | IN VOID *ConfigData OPTIONAL
|
---|
100 | )
|
---|
101 | {
|
---|
102 | if (!MceSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
---|
103 | return FALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 | return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCA == 1);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | Initializes Machine Check Architecture feature to specific state.
|
---|
111 |
|
---|
112 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
113 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
114 | structure for the CPU executing this function.
|
---|
115 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
116 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
117 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
118 | RegisterCpuFeature().
|
---|
119 | @param[in] State If TRUE, then the Machine Check Architecture feature must be enabled.
|
---|
120 | If FALSE, then the Machine Check Architecture feature must be disabled.
|
---|
121 |
|
---|
122 | @retval RETURN_SUCCESS Machine Check Architecture feature is initialized.
|
---|
123 |
|
---|
124 | @note This service could be called by BSP only.
|
---|
125 | **/
|
---|
126 | RETURN_STATUS
|
---|
127 | EFIAPI
|
---|
128 | McaInitialize (
|
---|
129 | IN UINTN ProcessorNumber,
|
---|
130 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
131 | IN VOID *ConfigData OPTIONAL,
|
---|
132 | IN BOOLEAN State
|
---|
133 | )
|
---|
134 | {
|
---|
135 | MSR_IA32_MCG_CAP_REGISTER McgCap;
|
---|
136 | UINT32 BankIndex;
|
---|
137 |
|
---|
138 | //
|
---|
139 | // The scope of MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS is core for below processor type, only program
|
---|
140 | // MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS for thread 0 in each core.
|
---|
141 | //
|
---|
142 | if (IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
143 | IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
144 | IS_SANDY_BRIDGE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
145 | IS_SKYLAKE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
146 | IS_XEON_PHI_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
147 | IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
148 | IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
---|
149 | {
|
---|
150 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
151 | return RETURN_SUCCESS;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | //
|
---|
156 | // The scope of MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS is package for below processor type, only program
|
---|
157 | // MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS once for each package.
|
---|
158 | //
|
---|
159 | if (IS_NEHALEM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
|
---|
160 | if ((CpuInfo->First.Thread == 0) || (CpuInfo->First.Core == 0)) {
|
---|
161 | return RETURN_SUCCESS;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (State) {
|
---|
166 | McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
---|
167 | for (BankIndex = 0; BankIndex < (UINT32)McgCap.Bits.Count; BankIndex++) {
|
---|
168 | CPU_REGISTER_TABLE_WRITE64 (
|
---|
169 | ProcessorNumber,
|
---|
170 | Msr,
|
---|
171 | MSR_IA32_MC0_CTL + BankIndex * 4,
|
---|
172 | MAX_UINT64
|
---|
173 | );
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (PcdGetBool (PcdIsPowerOnReset)) {
|
---|
177 | for (BankIndex = 0; BankIndex < (UINTN)McgCap.Bits.Count; BankIndex++) {
|
---|
178 | CPU_REGISTER_TABLE_WRITE64 (
|
---|
179 | ProcessorNumber,
|
---|
180 | Msr,
|
---|
181 | MSR_IA32_MC0_STATUS + BankIndex * 4,
|
---|
182 | 0
|
---|
183 | );
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | return RETURN_SUCCESS;
|
---|
189 | }
|
---|
190 |
|
---|
191 | /**
|
---|
192 | Detects if IA32_MCG_CTL feature supported on current processor.
|
---|
193 |
|
---|
194 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
195 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
196 | structure for the CPU executing this function.
|
---|
197 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
198 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
199 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
200 | RegisterCpuFeature().
|
---|
201 |
|
---|
202 | @retval TRUE IA32_MCG_CTL feature is supported.
|
---|
203 | @retval FALSE IA32_MCG_CTL feature is not supported.
|
---|
204 |
|
---|
205 | @note This service could be called by BSP/APs.
|
---|
206 | **/
|
---|
207 | BOOLEAN
|
---|
208 | EFIAPI
|
---|
209 | McgCtlSupport (
|
---|
210 | IN UINTN ProcessorNumber,
|
---|
211 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
212 | IN VOID *ConfigData OPTIONAL
|
---|
213 | )
|
---|
214 | {
|
---|
215 | MSR_IA32_MCG_CAP_REGISTER McgCap;
|
---|
216 |
|
---|
217 | if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
---|
218 | return FALSE;
|
---|
219 | }
|
---|
220 |
|
---|
221 | McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
---|
222 | return (McgCap.Bits.MCG_CTL_P == 1);
|
---|
223 | }
|
---|
224 |
|
---|
225 | /**
|
---|
226 | Initializes IA32_MCG_CTL feature to specific state.
|
---|
227 |
|
---|
228 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
229 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
230 | structure for the CPU executing this function.
|
---|
231 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
232 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
233 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
234 | RegisterCpuFeature().
|
---|
235 | @param[in] State If TRUE, then the IA32_MCG_CTL feature must be enabled.
|
---|
236 | If FALSE, then the IA32_MCG_CTL feature must be disabled.
|
---|
237 |
|
---|
238 | @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized.
|
---|
239 |
|
---|
240 | @note This service could be called by BSP only.
|
---|
241 | **/
|
---|
242 | RETURN_STATUS
|
---|
243 | EFIAPI
|
---|
244 | McgCtlInitialize (
|
---|
245 | IN UINTN ProcessorNumber,
|
---|
246 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
247 | IN VOID *ConfigData OPTIONAL,
|
---|
248 | IN BOOLEAN State
|
---|
249 | )
|
---|
250 | {
|
---|
251 | CPU_REGISTER_TABLE_WRITE64 (
|
---|
252 | ProcessorNumber,
|
---|
253 | Msr,
|
---|
254 | MSR_IA32_MCG_CTL,
|
---|
255 | (State) ? MAX_UINT64 : 0
|
---|
256 | );
|
---|
257 | return RETURN_SUCCESS;
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | Detects if Local machine check exception feature supported on current
|
---|
262 | processor.
|
---|
263 |
|
---|
264 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
265 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
266 | structure for the CPU executing this function.
|
---|
267 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
268 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
269 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
270 | RegisterCpuFeature().
|
---|
271 |
|
---|
272 | @retval TRUE Local machine check exception feature is supported.
|
---|
273 | @retval FALSE Local machine check exception feature is not supported.
|
---|
274 |
|
---|
275 | @note This service could be called by BSP/APs.
|
---|
276 | **/
|
---|
277 | BOOLEAN
|
---|
278 | EFIAPI
|
---|
279 | LmceSupport (
|
---|
280 | IN UINTN ProcessorNumber,
|
---|
281 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
282 | IN VOID *ConfigData OPTIONAL
|
---|
283 | )
|
---|
284 | {
|
---|
285 | MSR_IA32_MCG_CAP_REGISTER McgCap;
|
---|
286 |
|
---|
287 | if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
---|
288 | return FALSE;
|
---|
289 | }
|
---|
290 |
|
---|
291 | McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
---|
292 |
|
---|
293 | return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0);
|
---|
294 | }
|
---|
295 |
|
---|
296 | /**
|
---|
297 | Initializes Local machine check exception feature to specific state.
|
---|
298 |
|
---|
299 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
300 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
301 | structure for the CPU executing this function.
|
---|
302 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
303 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
304 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
305 | RegisterCpuFeature().
|
---|
306 | @param[in] State If TRUE, then the Local machine check exception
|
---|
307 | feature must be enabled.
|
---|
308 | If FALSE, then the Local machine check exception
|
---|
309 | feature must be disabled.
|
---|
310 |
|
---|
311 | @retval RETURN_SUCCESS Local machine check exception feature is initialized.
|
---|
312 |
|
---|
313 | **/
|
---|
314 | RETURN_STATUS
|
---|
315 | EFIAPI
|
---|
316 | LmceInitialize (
|
---|
317 | IN UINTN ProcessorNumber,
|
---|
318 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
319 | IN VOID *ConfigData OPTIONAL,
|
---|
320 | IN BOOLEAN State
|
---|
321 | )
|
---|
322 | {
|
---|
323 | //
|
---|
324 | // The scope of LcmeOn bit in the MSR_IA32_MISC_ENABLE is core for below processor type, only program
|
---|
325 | // MSR_IA32_MISC_ENABLE for thread 0 in each core.
|
---|
326 | //
|
---|
327 | if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
328 | IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
---|
329 | IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
---|
330 | {
|
---|
331 | if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
---|
332 | return RETURN_SUCCESS;
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
---|
337 | ProcessorNumber,
|
---|
338 | Msr,
|
---|
339 | MSR_IA32_FEATURE_CONTROL,
|
---|
340 | MSR_IA32_FEATURE_CONTROL_REGISTER,
|
---|
341 | Bits.LmceOn,
|
---|
342 | (State) ? 1 : 0
|
---|
343 | );
|
---|
344 |
|
---|
345 | return RETURN_SUCCESS;
|
---|
346 | }
|
---|