2 Machine Check features.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "CpuCommonFeatures.h"
18 Detects if Machine Check Exception feature supported on current processor.
20 @param[in] ProcessorNumber The index of the CPU executing this function.
21 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
22 structure for the CPU executing this function.
23 @param[in] ConfigData A pointer to the configuration buffer returned
24 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
25 CPU_FEATURE_GET_CONFIG_DATA was not provided in
28 @retval TRUE Machine Check Exception feature is supported.
29 @retval FALSE Machine Check Exception feature is not supported.
31 @note This service could be called by BSP/APs.
36 IN UINTN ProcessorNumber
,
37 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
38 IN VOID
*ConfigData OPTIONAL
41 return (CpuInfo
->CpuIdVersionInfoEdx
.Bits
.MCE
== 1);
45 Initializes Machine Check Exception feature to specific state.
47 @param[in] ProcessorNumber The index of the CPU executing this function.
48 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
49 structure for the CPU executing this function.
50 @param[in] ConfigData A pointer to the configuration buffer returned
51 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
52 CPU_FEATURE_GET_CONFIG_DATA was not provided in
54 @param[in] State If TRUE, then the Machine Check Exception feature must be enabled.
55 If FALSE, then the Machine Check Exception feature must be disabled.
57 @retval RETURN_SUCCESS Machine Check Exception feature is initialized.
59 @note This service could be called by BSP only.
64 IN UINTN ProcessorNumber
,
65 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
66 IN VOID
*ConfigData
, OPTIONAL
73 CPU_REGISTER_TABLE_WRITE_FIELD (
81 return RETURN_SUCCESS
;
85 Detects if Machine Check Architecture feature supported on current processor.
87 @param[in] ProcessorNumber The index of the CPU executing this function.
88 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
89 structure for the CPU executing this function.
90 @param[in] ConfigData A pointer to the configuration buffer returned
91 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
92 CPU_FEATURE_GET_CONFIG_DATA was not provided in
95 @retval TRUE Machine Check Architecture feature is supported.
96 @retval FALSE Machine Check Architecture feature is not supported.
98 @note This service could be called by BSP/APs.
103 IN UINTN ProcessorNumber
,
104 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
105 IN VOID
*ConfigData OPTIONAL
108 if (!MceSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
111 return (CpuInfo
->CpuIdVersionInfoEdx
.Bits
.MCA
== 1);
115 Initializes Machine Check Architecture feature to specific state.
117 @param[in] ProcessorNumber The index of the CPU executing this function.
118 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
119 structure for the CPU executing this function.
120 @param[in] ConfigData A pointer to the configuration buffer returned
121 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
122 CPU_FEATURE_GET_CONFIG_DATA was not provided in
123 RegisterCpuFeature().
124 @param[in] State If TRUE, then the Machine Check Architecture feature must be enabled.
125 If FALSE, then the Machine Check Architecture feature must be disabled.
127 @retval RETURN_SUCCESS Machine Check Architecture feature is initialized.
129 @note This service could be called by BSP only.
134 IN UINTN ProcessorNumber
,
135 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
136 IN VOID
*ConfigData
, OPTIONAL
140 MSR_IA32_MCG_CAP_REGISTER McgCap
;
143 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
144 for (BankIndex
= 0; BankIndex
< (UINT32
) McgCap
.Bits
.Count
; BankIndex
++) {
145 CPU_REGISTER_TABLE_WRITE64 (
148 MSR_IA32_MC0_CTL
+ BankIndex
* 4,
153 if (PcdGetBool (PcdIsPowerOnReset
)) {
154 for (BankIndex
= 0; BankIndex
< (UINTN
) McgCap
.Bits
.Count
; BankIndex
++) {
155 CPU_REGISTER_TABLE_WRITE64 (
158 MSR_IA32_MC0_STATUS
+ BankIndex
* 4,
164 return RETURN_SUCCESS
;
168 Detects if IA32_MCG_CTL feature supported on current processor.
170 @param[in] ProcessorNumber The index of the CPU executing this function.
171 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
172 structure for the CPU executing this function.
173 @param[in] ConfigData A pointer to the configuration buffer returned
174 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
175 CPU_FEATURE_GET_CONFIG_DATA was not provided in
176 RegisterCpuFeature().
178 @retval TRUE IA32_MCG_CTL feature is supported.
179 @retval FALSE IA32_MCG_CTL feature is not supported.
181 @note This service could be called by BSP/APs.
186 IN UINTN ProcessorNumber
,
187 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
188 IN VOID
*ConfigData OPTIONAL
191 MSR_IA32_MCG_CAP_REGISTER McgCap
;
193 if (!McaSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
196 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
197 return (McgCap
.Bits
.MCG_CTL_P
== 1);
201 Initializes IA32_MCG_CTL feature to specific state.
203 @param[in] ProcessorNumber The index of the CPU executing this function.
204 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
205 structure for the CPU executing this function.
206 @param[in] ConfigData A pointer to the configuration buffer returned
207 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
208 CPU_FEATURE_GET_CONFIG_DATA was not provided in
209 RegisterCpuFeature().
210 @param[in] State If TRUE, then the IA32_MCG_CTL feature must be enabled.
211 If FALSE, then the IA32_MCG_CTL feature must be disabled.
213 @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized.
215 @note This service could be called by BSP only.
220 IN UINTN ProcessorNumber
,
221 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
222 IN VOID
*ConfigData
, OPTIONAL
226 CPU_REGISTER_TABLE_WRITE64 (
230 (State
)? MAX_UINT64
: 0
232 return RETURN_SUCCESS
;
236 Detects if Local machine check exception feature supported on current
239 @param[in] ProcessorNumber The index of the CPU executing this function.
240 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
241 structure for the CPU executing this function.
242 @param[in] ConfigData A pointer to the configuration buffer returned
243 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
244 CPU_FEATURE_GET_CONFIG_DATA was not provided in
245 RegisterCpuFeature().
247 @retval TRUE Local machine check exception feature is supported.
248 @retval FALSE Local machine check exception feature is not supported.
250 @note This service could be called by BSP/APs.
255 IN UINTN ProcessorNumber
,
256 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
257 IN VOID
*ConfigData OPTIONAL
260 MSR_IA32_MCG_CAP_REGISTER McgCap
;
262 if (!McaSupport (ProcessorNumber
, CpuInfo
, ConfigData
)) {
266 McgCap
.Uint64
= AsmReadMsr64 (MSR_IA32_MCG_CAP
);
267 if (ProcessorNumber
== 0) {
268 DEBUG ((EFI_D_INFO
, "LMCE eanble = %x\n", (BOOLEAN
) (McgCap
.Bits
.MCG_LMCE_P
!= 0)));
270 return (BOOLEAN
) (McgCap
.Bits
.MCG_LMCE_P
!= 0);
274 Initializes Local machine check exception feature to specific state.
276 @param[in] ProcessorNumber The index of the CPU executing this function.
277 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
278 structure for the CPU executing this function.
279 @param[in] ConfigData A pointer to the configuration buffer returned
280 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
281 CPU_FEATURE_GET_CONFIG_DATA was not provided in
282 RegisterCpuFeature().
283 @param[in] State If TRUE, then the Local machine check exception
284 feature must be enabled.
285 If FALSE, then the Local machine check exception
286 feature must be disabled.
288 @retval RETURN_SUCCESS Local machine check exception feature is initialized.
294 IN UINTN ProcessorNumber
,
295 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
296 IN VOID
*ConfigData
, OPTIONAL
300 MSR_IA32_FEATURE_CONTROL_REGISTER
*MsrRegister
;
302 ASSERT (ConfigData
!= NULL
);
303 MsrRegister
= (MSR_IA32_FEATURE_CONTROL_REGISTER
*) ConfigData
;
304 if (MsrRegister
[ProcessorNumber
].Bits
.Lock
== 0) {
305 CPU_REGISTER_TABLE_WRITE_FIELD (
308 MSR_IA32_FEATURE_CONTROL
,
309 MSR_IA32_FEATURE_CONTROL_REGISTER
,
314 return RETURN_SUCCESS
;