]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c
UefiCpuPkg/CpuCommonFeaturesLib: Remove unnecessary explicit type cast
[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 if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
45 return FALSE;
46 }
47
48 McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
49 if (ProcessorNumber == 0) {
50 DEBUG ((EFI_D_INFO, "LMCE eanble = %x\n", (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0)));
51 }
52 return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);
53 }
54
55 /**
56 Initializes Local machine check exception feature to specific state.
57
58 @param[in] ProcessorNumber The index of the CPU executing this function.
59 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
60 structure for the CPU executing this function.
61 @param[in] ConfigData A pointer to the configuration buffer returned
62 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
63 CPU_FEATURE_GET_CONFIG_DATA was not provided in
64 RegisterCpuFeature().
65 @param[in] State If TRUE, then the Local machine check exception
66 feature must be enabled.
67 If FALSE, then the Local machine check exception
68 feature must be disabled.
69
70 @retval RETURN_SUCCESS Local machine check exception feature is initialized.
71
72 **/
73 RETURN_STATUS
74 EFIAPI
75 LmceInitialize (
76 IN UINTN ProcessorNumber,
77 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
78 IN VOID *ConfigData, OPTIONAL
79 IN BOOLEAN State
80 )
81 {
82 MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister;
83
84 ASSERT (ConfigData != NULL);
85 MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData;
86 if (MsrRegister[ProcessorNumber].Bits.Lock == 0) {
87 CPU_REGISTER_TABLE_WRITE_FIELD (
88 ProcessorNumber,
89 Msr,
90 MSR_IA32_FEATURE_CONTROL,
91 MSR_IA32_FEATURE_CONTROL_REGISTER,
92 Bits.LmceOn,
93 (State) ? 1 : 0
94 );
95 }
96 return RETURN_SUCCESS;
97 }