]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c
UefiCpuPkg CpuCommonFeaturesLib: Enable LMCE feature.
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / Lmce.c
1 /** @file
2 Local machine check exception feature.
3
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
9
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.
12
13 **/
14
15 #include "CpuCommonFeatures.h"
16
17 /**
18 Detects if Local machine check exception feature supported on current
19 processor.
20
21 @param[in] ProcessorNumber The index of the CPU executing this function.
22 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
23 structure for the CPU executing this function.
24 @param[in] ConfigData A pointer to the configuration buffer returned
25 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
26 CPU_FEATURE_GET_CONFIG_DATA was not provided in
27 RegisterCpuFeature().
28
29 @retval TRUE Local machine check exception feature is supported.
30 @retval FALSE Local machine check exception feature is not supported.
31
32 @note This service could be called by BSP/APs.
33 **/
34 BOOLEAN
35 EFIAPI
36 LmceSupport (
37 IN UINTN ProcessorNumber,
38 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
39 IN VOID *ConfigData OPTIONAL
40 )
41 {
42 MSR_IA32_MCG_CAP_REGISTER McgCap;
43
44 McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
45 if (ProcessorNumber == 0) {
46 DEBUG ((EFI_D_INFO, "LMCE eanble = %x\n", (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0)));
47 }
48 return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);
49 }
50
51 /**
52 Initializes Local machine check exception feature to specific state.
53
54 @param[in] ProcessorNumber The index of the CPU executing this function.
55 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
56 structure for the CPU executing this function.
57 @param[in] ConfigData A pointer to the configuration buffer returned
58 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
59 CPU_FEATURE_GET_CONFIG_DATA was not provided in
60 RegisterCpuFeature().
61 @param[in] State If TRUE, then the Local machine check exception
62 feature must be enabled.
63 If FALSE, then the Local machine check exception
64 feature must be disabled.
65
66 @retval RETURN_SUCCESS Local machine check exception feature is initialized.
67
68 **/
69 RETURN_STATUS
70 EFIAPI
71 LmceInitialize (
72 IN UINTN ProcessorNumber,
73 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
74 IN VOID *ConfigData, OPTIONAL
75 IN BOOLEAN State
76 )
77 {
78 MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister;
79
80 ASSERT (ConfigData != NULL);
81 MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData;
82 if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {
83 CPU_REGISTER_TABLE_WRITE_FIELD (
84 ProcessorNumber,
85 Msr,
86 MSR_IA32_FEATURE_CONTROL,
87 MSR_IA32_FEATURE_CONTROL_REGISTER,
88 Bits.LmceOn,
89 (State) ? 1 : 0
90 );
91 }
92 return RETURN_SUCCESS;
93 }