]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / ClockModulation.c
1 /** @file
2 Clock Modulation 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 Clock Modulation 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 Clock Modulation feature is supported.
23 @retval FALSE Clock Modulation feature is not supported.
24
25 @note This service could be called by BSP/APs.
26 **/
27 BOOLEAN
28 EFIAPI
29 ClockModulationSupport (
30 IN UINTN ProcessorNumber,
31 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
32 IN VOID *ConfigData OPTIONAL
33 )
34 {
35 return (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI == 1);
36 }
37
38 /**
39 Initializes Clock Modulation feature to specific state.
40
41 @param[in] ProcessorNumber The index of the CPU executing this function.
42 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
43 structure for the CPU executing this function.
44 @param[in] ConfigData A pointer to the configuration buffer returned
45 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
46 CPU_FEATURE_GET_CONFIG_DATA was not provided in
47 RegisterCpuFeature().
48 @param[in] State If TRUE, then the Clock Modulation feature must be enabled.
49 If FALSE, then the Clock Modulation feature must be disabled.
50
51 @retval RETURN_SUCCESS Clock Modulation feature is initialized.
52
53 @note This service could be called by BSP only.
54 **/
55 RETURN_STATUS
56 EFIAPI
57 ClockModulationInitialize (
58 IN UINTN ProcessorNumber,
59 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
60 IN VOID *ConfigData, OPTIONAL
61 IN BOOLEAN State
62 )
63 {
64 CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;
65 AsmCpuid (CPUID_THERMAL_POWER_MANAGEMENT, &ThermalPowerManagementEax.Uint32, NULL, NULL, NULL);
66
67 CPU_REGISTER_TABLE_WRITE_FIELD (
68 ProcessorNumber,
69 Msr,
70 MSR_IA32_CLOCK_MODULATION,
71 MSR_IA32_CLOCK_MODULATION_REGISTER,
72 Bits.OnDemandClockModulationDutyCycle,
73 PcdGet8 (PcdCpuClockModulationDutyCycle) >> 1
74 );
75 if (ThermalPowerManagementEax.Bits.ECMD == 1) {
76 CPU_REGISTER_TABLE_WRITE_FIELD (
77 ProcessorNumber,
78 Msr,
79 MSR_IA32_CLOCK_MODULATION,
80 MSR_IA32_CLOCK_MODULATION_REGISTER,
81 Bits.ExtendedOnDemandClockModulationDutyCycle,
82 PcdGet8 (PcdCpuClockModulationDutyCycle) & BIT0
83 );
84 }
85 CPU_REGISTER_TABLE_WRITE_FIELD (
86 ProcessorNumber,
87 Msr,
88 MSR_IA32_CLOCK_MODULATION,
89 MSR_IA32_CLOCK_MODULATION_REGISTER,
90 Bits.OnDemandClockModulationEnable,
91 (State) ? 1 : 0
92 );
93 return RETURN_SUCCESS;
94 }