1 /** @file
2   LimitCpuidMaxval Feature.
3 
4   Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include "CpuCommonFeatures.h"
10 
11 /**
12   Detects if LimitCpuidMaxval feature supported on current processor.
13 
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
20                                RegisterCpuFeature().
21 
22   @retval TRUE     LimitCpuidMaxval feature is supported.
23   @retval FALSE    LimitCpuidMaxval feature is not supported.
24 
25   @note This service could be called by BSP/APs.
26 **/
27 BOOLEAN
28 EFIAPI
LimitCpuidMaxvalSupport(IN UINTN ProcessorNumber,IN REGISTER_CPU_FEATURE_INFORMATION * CpuInfo,IN VOID * ConfigData OPTIONAL)29 LimitCpuidMaxvalSupport (
30   IN UINTN                             ProcessorNumber,
31   IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
32   IN VOID                              *ConfigData  OPTIONAL
33   )
34 {
35   UINT32  Eax;
36 
37   AsmCpuid (CPUID_SIGNATURE, &Eax, NULL, NULL, NULL);
38   return (Eax > 2);
39 }
40 
41 /**
42   Initializes LimitCpuidMaxval feature to specific state.
43 
44   @param[in]  ProcessorNumber  The index of the CPU executing this function.
45   @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION
46                                structure for the CPU executing this function.
47   @param[in]  ConfigData       A pointer to the configuration buffer returned
48                                by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
49                                CPU_FEATURE_GET_CONFIG_DATA was not provided in
50                                RegisterCpuFeature().
51   @param[in]  State            If TRUE, then the LimitCpuidMaxval feature must be enabled.
52                                If FALSE, then the LimitCpuidMaxval feature must be disabled.
53 
54   @retval RETURN_SUCCESS       LimitCpuidMaxval feature is initialized.
55 
56   @note This service could be called by BSP only.
57 **/
58 RETURN_STATUS
59 EFIAPI
LimitCpuidMaxvalInitialize(IN UINTN ProcessorNumber,IN REGISTER_CPU_FEATURE_INFORMATION * CpuInfo,IN VOID * ConfigData,OPTIONAL IN BOOLEAN State)60 LimitCpuidMaxvalInitialize (
61   IN UINTN                             ProcessorNumber,
62   IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
63   IN VOID                              *ConfigData,  OPTIONAL
64   IN BOOLEAN                           State
65   )
66 {
67   //
68   // The scope of LimitCpuidMaxval bit in the MSR_IA32_MISC_ENABLE is core for below
69   // processor type, only program MSR_IA32_MISC_ENABLE for thread 0 in each core.
70   //
71   if (IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
72       IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
73       IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
74       IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
75       IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
76     if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
77       return RETURN_SUCCESS;
78     }
79   }
80 
81   CPU_REGISTER_TABLE_WRITE_FIELD (
82     ProcessorNumber,
83     Msr,
84     MSR_IA32_MISC_ENABLE,
85     MSR_IA32_MISC_ENABLE_REGISTER,
86     Bits.LimitCpuidMaxval,
87     (State) ? 1 : 0
88     );
89   return RETURN_SUCCESS;
90 }
91