2 Machine Check features.
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuCommonFeatures.h"
12 Detects if Machine Check Exception feature supported on current processor.
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
22 @retval TRUE Machine Check Exception feature is supported.
23 @retval FALSE Machine Check Exception feature is not supported.
25 @note This service could be called by BSP/APs.
30 IN UINTN ProcessorNumber
,
31 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
32 IN VOID
*ConfigData OPTIONAL
35 return (CpuInfo
->CpuIdVersionInfoEdx
.Bits
.MCE
== 1);
39 Initializes Machine Check Exception feature to specific state.
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
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.
51 @retval RETURN_SUCCESS Machine Check Exception feature is initialized.
53 @note This service could be called by BSP only.
58 IN UINTN ProcessorNumber
,
59 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
60 IN VOID
*ConfigData OPTIONAL
,
67 CPU_REGISTER_TABLE_WRITE_FIELD (
75 return RETURN_SUCCESS
;
79 Detects if Machine Check Architecture feature supported on current processor.
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
89 @retval TRUE Machine Check Architecture feature is supported.
90 @retval FALSE Machine Check Architecture feature is not supported.
92 @note This service could be called by BSP/APs.
97 IN UINTN ProcessorNumber
,
98 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
99 IN VOID
*ConfigData OPTIONAL
102 if (!MceSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
106 return (CpuInfo
->CpuIdVersionInfoEdx
.Bits
.MCA
== 1);
110 Initializes Machine Check Architecture feature to specific state.
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.
122 @retval RETURN_SUCCESS Machine Check Architecture feature is initialized.
124 @note This service could be called by BSP only.
129 IN UINTN ProcessorNumber
,
130 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
131 IN VOID
*ConfigData OPTIONAL
,
135 MSR_IA32_MCG_CAP_REGISTER McgCap
;
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.
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
))
150 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
151 return RETURN_SUCCESS
;
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.
159 if (IS_NEHALEM_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
)) {
160 if ((CpuInfo
->First
.Thread
== 0) || (CpuInfo
->First
.Core
== 0)) {
161 return RETURN_SUCCESS
;
166 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
167 for (BankIndex
= 0; BankIndex
< (UINT32
)McgCap
.Bits
.Count
; BankIndex
++) {
168 CPU_REGISTER_TABLE_WRITE64 (
171 MSR_IA32_MC0_CTL
+ BankIndex
* 4,
176 if (PcdGetBool (PcdIsPowerOnReset
)) {
177 for (BankIndex
= 0; BankIndex
< (UINTN
)McgCap
.Bits
.Count
; BankIndex
++) {
178 CPU_REGISTER_TABLE_WRITE64 (
181 MSR_IA32_MC0_STATUS
+ BankIndex
* 4,
188 return RETURN_SUCCESS
;
192 Detects if IA32_MCG_CTL feature supported on current processor.
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().
202 @retval TRUE IA32_MCG_CTL feature is supported.
203 @retval FALSE IA32_MCG_CTL feature is not supported.
205 @note This service could be called by BSP/APs.
210 IN UINTN ProcessorNumber
,
211 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
212 IN VOID
*ConfigData OPTIONAL
215 MSR_IA32_MCG_CAP_REGISTER McgCap
;
217 if (!McaSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
221 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
222 return (McgCap
.Bits
.MCG_CTL_P
== 1);
226 Initializes IA32_MCG_CTL feature to specific state.
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.
238 @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized.
240 @note This service could be called by BSP only.
245 IN UINTN ProcessorNumber
,
246 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
247 IN VOID
*ConfigData OPTIONAL
,
251 CPU_REGISTER_TABLE_WRITE64 (
255 (State
) ? MAX_UINT64
: 0
257 return RETURN_SUCCESS
;
261 Detects if Local machine check exception feature supported on current
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().
272 @retval TRUE Local machine check exception feature is supported.
273 @retval FALSE Local machine check exception feature is not supported.
275 @note This service could be called by BSP/APs.
280 IN UINTN ProcessorNumber
,
281 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
282 IN VOID
*ConfigData OPTIONAL
285 MSR_IA32_MCG_CAP_REGISTER McgCap
;
287 if (!McaSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
291 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
292 if (ProcessorNumber
== 0) {
293 DEBUG ((DEBUG_INFO
, "LMCE enable = %x\n", (BOOLEAN
)(McgCap
.Bits
.MCG_LMCE_P
!= 0)));
296 return (BOOLEAN
)(McgCap
.Bits
.MCG_LMCE_P
!= 0);
300 Initializes Local machine check exception feature to specific state.
302 @param[in] ProcessorNumber The index of the CPU executing this function.
303 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
304 structure for the CPU executing this function.
305 @param[in] ConfigData A pointer to the configuration buffer returned
306 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
307 CPU_FEATURE_GET_CONFIG_DATA was not provided in
308 RegisterCpuFeature().
309 @param[in] State If TRUE, then the Local machine check exception
310 feature must be enabled.
311 If FALSE, then the Local machine check exception
312 feature must be disabled.
314 @retval RETURN_SUCCESS Local machine check exception feature is initialized.
320 IN UINTN ProcessorNumber
,
321 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
322 IN VOID
*ConfigData OPTIONAL
,
327 // The scope of LcmeOn bit in the MSR_IA32_MISC_ENABLE is core for below processor type, only program
328 // MSR_IA32_MISC_ENABLE for thread 0 in each core.
330 if (IS_SILVERMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
331 IS_GOLDMONT_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
) ||
332 IS_PENTIUM_4_PROCESSOR (CpuInfo
->DisplayFamily
, CpuInfo
->DisplayModel
))
334 if (CpuInfo
->ProcessorInfo
.Location
.Thread
!= 0) {
335 return RETURN_SUCCESS
;
339 CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
342 MSR_IA32_FEATURE_CONTROL
,
343 MSR_IA32_FEATURE_CONTROL_REGISTER
,
348 return RETURN_SUCCESS
;