]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCommonFeaturesLib/LimitCpuIdMaxval.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / LimitCpuIdMaxval.c
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
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
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 {
77 if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
78 return RETURN_SUCCESS;
79 }
80 }
81
82 CPU_REGISTER_TABLE_WRITE_FIELD (
83 ProcessorNumber,
84 Msr,
85 MSR_IA32_MISC_ENABLE,
86 MSR_IA32_MISC_ENABLE_REGISTER,
87 Bits.LimitCpuidMaxval,
88 (State) ? 1 : 0
89 );
90 return RETURN_SUCCESS;
91 }