2017-04-05 10:33:16 +02:00
|
|
|
/** @file
|
|
|
|
Machine Check features.
|
|
|
|
|
UefiCpuPkg/CpuCommonFeaturesLib: Use new macros.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2040
Below code is current implementation:
if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {
CPU_REGISTER_TABLE_WRITE_FIELD (
ProcessorNumber,
Msr,
MSR_IA32_FEATURE_CONTROL,
MSR_IA32_FEATURE_CONTROL_REGISTER,
Bits.Lock,
1
);
}
1. In first normal boot, the Bits.Lock is 0, 1 will be added
into the register table and then will set to the MSR.
2. Trig warm reboot, MSR value preserves. After normal boot phase,
the Bits.Lock is 1, so it will not be added into the register
table during the warm reboot phase.
3. Trig S3 then resume, the Bits.Lock change to 0 and Bits.Lock is
not added in register table, so it's still 0 after resume. This
is not an expect behavior. The expect value is the value should
always 1 after booting or resuming from S3.
The root cause for this issue is
1. driver bases on current value to insert the "set value action" to
the register table.
2. Some MSRs may reserve their value during warm reboot.
The solution for this issue is using new added macros for the MSRs which
preserve value during warm reboot.
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2019-08-16 05:57:30 +02:00
|
|
|
Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:07:22 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2017-04-05 10:33:16 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "CpuCommonFeatures.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Detects if Machine Check Exception feature supported on current processor.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
|
|
|
|
@retval TRUE Machine Check Exception feature is supported.
|
|
|
|
@retval FALSE Machine Check Exception feature is not supported.
|
|
|
|
|
|
|
|
@note This service could be called by BSP/APs.
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
MceSupport (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
|
|
|
IN VOID *ConfigData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCE == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes Machine Check Exception feature to specific state.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
@param[in] State If TRUE, then the Machine Check Exception feature must be enabled.
|
|
|
|
If FALSE, then the Machine Check Exception feature must be disabled.
|
|
|
|
|
|
|
|
@retval RETURN_SUCCESS Machine Check Exception feature is initialized.
|
|
|
|
|
|
|
|
@note This service could be called by BSP only.
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MceInitialize (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
2021-12-03 03:01:00 +01:00
|
|
|
IN VOID *ConfigData OPTIONAL,
|
2017-04-05 10:33:16 +02:00
|
|
|
IN BOOLEAN State
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Set MCE bit in CR4
|
|
|
|
//
|
|
|
|
CPU_REGISTER_TABLE_WRITE_FIELD (
|
|
|
|
ProcessorNumber,
|
|
|
|
ControlRegister,
|
|
|
|
4,
|
|
|
|
IA32_CR4,
|
|
|
|
Bits.MCE,
|
|
|
|
(State) ? 1 : 0
|
|
|
|
);
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Detects if Machine Check Architecture feature supported on current processor.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
|
|
|
|
@retval TRUE Machine Check Architecture feature is supported.
|
|
|
|
@retval FALSE Machine Check Architecture feature is not supported.
|
|
|
|
|
|
|
|
@note This service could be called by BSP/APs.
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
McaSupport (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
|
|
|
IN VOID *ConfigData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2018-01-12 03:19:00 +01:00
|
|
|
if (!MceSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-12-05 23:54:17 +01:00
|
|
|
|
2017-04-05 10:33:16 +02:00
|
|
|
return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCA == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes Machine Check Architecture feature to specific state.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
@param[in] State If TRUE, then the Machine Check Architecture feature must be enabled.
|
|
|
|
If FALSE, then the Machine Check Architecture feature must be disabled.
|
|
|
|
|
|
|
|
@retval RETURN_SUCCESS Machine Check Architecture feature is initialized.
|
|
|
|
|
|
|
|
@note This service could be called by BSP only.
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
McaInitialize (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
2021-12-03 03:01:00 +01:00
|
|
|
IN VOID *ConfigData OPTIONAL,
|
2017-04-05 10:33:16 +02:00
|
|
|
IN BOOLEAN State
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MSR_IA32_MCG_CAP_REGISTER McgCap;
|
|
|
|
UINT32 BankIndex;
|
|
|
|
|
2018-10-17 03:24:05 +02:00
|
|
|
//
|
|
|
|
// The scope of MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS is core for below processor type, only program
|
|
|
|
// MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS for thread 0 in each core.
|
|
|
|
//
|
|
|
|
if (IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_SANDY_BRIDGE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_SKYLAKE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_XEON_PHI_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
|
|
|
{
|
|
|
|
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// The scope of MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS is package for below processor type, only program
|
2021-06-02 05:01:13 +02:00
|
|
|
// MSR_IA32_MC*_CTL/MSR_IA32_MC*_STATUS once for each package.
|
2018-10-17 03:24:05 +02:00
|
|
|
//
|
|
|
|
if (IS_NEHALEM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
|
2021-06-02 05:01:13 +02:00
|
|
|
if ((CpuInfo->First.Thread == 0) || (CpuInfo->First.Core == 0)) {
|
2018-10-17 03:24:05 +02:00
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 06:20:29 +01:00
|
|
|
if (State) {
|
2018-02-08 07:43:20 +01:00
|
|
|
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
|
|
|
for (BankIndex = 0; BankIndex < (UINT32)McgCap.Bits.Count; BankIndex++) {
|
2017-04-05 10:33:16 +02:00
|
|
|
CPU_REGISTER_TABLE_WRITE64 (
|
|
|
|
ProcessorNumber,
|
|
|
|
Msr,
|
2018-02-08 07:43:20 +01:00
|
|
|
MSR_IA32_MC0_CTL + BankIndex * 4,
|
|
|
|
MAX_UINT64
|
2017-04-05 10:33:16 +02:00
|
|
|
);
|
|
|
|
}
|
2018-02-08 07:43:20 +01:00
|
|
|
|
|
|
|
if (PcdGetBool (PcdIsPowerOnReset)) {
|
|
|
|
for (BankIndex = 0; BankIndex < (UINTN)McgCap.Bits.Count; BankIndex++) {
|
|
|
|
CPU_REGISTER_TABLE_WRITE64 (
|
|
|
|
ProcessorNumber,
|
|
|
|
Msr,
|
|
|
|
MSR_IA32_MC0_STATUS + BankIndex * 4,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-04-05 10:33:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Detects if IA32_MCG_CTL feature supported on current processor.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
|
|
|
|
@retval TRUE IA32_MCG_CTL feature is supported.
|
|
|
|
@retval FALSE IA32_MCG_CTL feature is not supported.
|
|
|
|
|
|
|
|
@note This service could be called by BSP/APs.
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
McgCtlSupport (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
|
|
|
IN VOID *ConfigData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MSR_IA32_MCG_CAP_REGISTER McgCap;
|
|
|
|
|
|
|
|
if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-12-05 23:54:17 +01:00
|
|
|
|
2017-04-05 10:33:16 +02:00
|
|
|
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
|
|
|
return (McgCap.Bits.MCG_CTL_P == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes IA32_MCG_CTL feature to specific state.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
@param[in] State If TRUE, then the IA32_MCG_CTL feature must be enabled.
|
|
|
|
If FALSE, then the IA32_MCG_CTL feature must be disabled.
|
|
|
|
|
|
|
|
@retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized.
|
|
|
|
|
|
|
|
@note This service could be called by BSP only.
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
McgCtlInitialize (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
2021-12-03 03:01:00 +01:00
|
|
|
IN VOID *ConfigData OPTIONAL,
|
2017-04-05 10:33:16 +02:00
|
|
|
IN BOOLEAN State
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CPU_REGISTER_TABLE_WRITE64 (
|
|
|
|
ProcessorNumber,
|
|
|
|
Msr,
|
|
|
|
MSR_IA32_MCG_CTL,
|
|
|
|
(State) ? MAX_UINT64 : 0
|
|
|
|
);
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-08-17 05:40:38 +02:00
|
|
|
/**
|
2018-06-27 15:14:20 +02:00
|
|
|
Detects if Local machine check exception feature supported on current
|
2017-08-17 05:40:38 +02:00
|
|
|
processor.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
|
|
|
|
@retval TRUE Local machine check exception feature is supported.
|
|
|
|
@retval FALSE Local machine check exception feature is not supported.
|
|
|
|
|
|
|
|
@note This service could be called by BSP/APs.
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
LmceSupport (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
|
|
|
IN VOID *ConfigData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MSR_IA32_MCG_CAP_REGISTER McgCap;
|
|
|
|
|
|
|
|
if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
|
|
|
|
if (ProcessorNumber == 0) {
|
2020-08-01 02:27:47 +02:00
|
|
|
DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0)));
|
2017-08-17 05:40:38 +02:00
|
|
|
}
|
2021-12-05 23:54:17 +01:00
|
|
|
|
2017-08-17 05:40:38 +02:00
|
|
|
return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes Local machine check exception feature to specific state.
|
|
|
|
|
|
|
|
@param[in] ProcessorNumber The index of the CPU executing this function.
|
|
|
|
@param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
|
|
|
structure for the CPU executing this function.
|
|
|
|
@param[in] ConfigData A pointer to the configuration buffer returned
|
|
|
|
by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
|
|
|
CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
|
|
|
RegisterCpuFeature().
|
|
|
|
@param[in] State If TRUE, then the Local machine check exception
|
|
|
|
feature must be enabled.
|
|
|
|
If FALSE, then the Local machine check exception
|
|
|
|
feature must be disabled.
|
|
|
|
|
|
|
|
@retval RETURN_SUCCESS Local machine check exception feature is initialized.
|
|
|
|
|
|
|
|
**/
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
LmceInitialize (
|
|
|
|
IN UINTN ProcessorNumber,
|
|
|
|
IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
2021-12-03 03:01:00 +01:00
|
|
|
IN VOID *ConfigData OPTIONAL,
|
2017-08-17 05:40:38 +02:00
|
|
|
IN BOOLEAN State
|
|
|
|
)
|
|
|
|
{
|
2018-10-17 03:24:05 +02:00
|
|
|
//
|
2019-05-22 05:21:22 +02:00
|
|
|
// The scope of LcmeOn bit in the MSR_IA32_MISC_ENABLE is core for below processor type, only program
|
2018-10-17 03:24:05 +02:00
|
|
|
// MSR_IA32_MISC_ENABLE for thread 0 in each core.
|
|
|
|
//
|
|
|
|
if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
|
|
|
|
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
|
|
|
|
{
|
|
|
|
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
UefiCpuPkg/CpuCommonFeaturesLib: Use new macros.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2040
Below code is current implementation:
if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {
CPU_REGISTER_TABLE_WRITE_FIELD (
ProcessorNumber,
Msr,
MSR_IA32_FEATURE_CONTROL,
MSR_IA32_FEATURE_CONTROL_REGISTER,
Bits.Lock,
1
);
}
1. In first normal boot, the Bits.Lock is 0, 1 will be added
into the register table and then will set to the MSR.
2. Trig warm reboot, MSR value preserves. After normal boot phase,
the Bits.Lock is 1, so it will not be added into the register
table during the warm reboot phase.
3. Trig S3 then resume, the Bits.Lock change to 0 and Bits.Lock is
not added in register table, so it's still 0 after resume. This
is not an expect behavior. The expect value is the value should
always 1 after booting or resuming from S3.
The root cause for this issue is
1. driver bases on current value to insert the "set value action" to
the register table.
2. Some MSRs may reserve their value during warm reboot.
The solution for this issue is using new added macros for the MSRs which
preserve value during warm reboot.
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2019-08-16 05:57:30 +02:00
|
|
|
CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
|
|
|
|
ProcessorNumber,
|
|
|
|
Msr,
|
|
|
|
MSR_IA32_FEATURE_CONTROL,
|
|
|
|
MSR_IA32_FEATURE_CONTROL_REGISTER,
|
|
|
|
Bits.LmceOn,
|
|
|
|
(State) ? 1 : 0
|
|
|
|
);
|
|
|
|
|
2017-08-17 05:40:38 +02:00
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|