2 Clock Modulation feature.
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuCommonFeatures.h"
12 CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax
;
13 MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation
;
14 } CLOCK_MODULATION_CONFIG_DATA
;
17 Prepares for the data used by CPU feature detection and initialization.
19 @param[in] NumberOfProcessors The number of CPUs in the platform.
21 @return Pointer to a buffer of CPU related configuration data.
23 @note This service could be called by BSP only.
27 ClockModulationGetConfigData (
28 IN UINTN NumberOfProcessors
33 ConfigData
= AllocateZeroPool (sizeof (CLOCK_MODULATION_CONFIG_DATA
) * NumberOfProcessors
);
34 ASSERT (ConfigData
!= NULL
);
39 Detects if Clock Modulation feature supported on current processor.
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
49 @retval TRUE Clock Modulation feature is supported.
50 @retval FALSE Clock Modulation feature is not supported.
52 @note This service could be called by BSP/APs.
56 ClockModulationSupport (
57 IN UINTN ProcessorNumber
,
58 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
59 IN VOID
*ConfigData OPTIONAL
62 CLOCK_MODULATION_CONFIG_DATA
*CmConfigData
;
64 if (CpuInfo
->CpuIdVersionInfoEdx
.Bits
.ACPI
== 1) {
65 CmConfigData
= (CLOCK_MODULATION_CONFIG_DATA
*)ConfigData
;
66 ASSERT (CmConfigData
!= NULL
);
68 CPUID_THERMAL_POWER_MANAGEMENT
,
69 &CmConfigData
[ProcessorNumber
].ThermalPowerManagementEax
.Uint32
,
74 CmConfigData
[ProcessorNumber
].ClockModulation
.Uint64
= AsmReadMsr64 (MSR_IA32_CLOCK_MODULATION
);
82 Initializes Clock Modulation feature to specific state.
84 @param[in] ProcessorNumber The index of the CPU executing this function.
85 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
86 structure for the CPU executing this function.
87 @param[in] ConfigData A pointer to the configuration buffer returned
88 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
89 CPU_FEATURE_GET_CONFIG_DATA was not provided in
91 @param[in] State If TRUE, then the Clock Modulation feature must be enabled.
92 If FALSE, then the Clock Modulation feature must be disabled.
94 @retval RETURN_SUCCESS Clock Modulation feature is initialized.
96 @note This service could be called by BSP only.
100 ClockModulationInitialize (
101 IN UINTN ProcessorNumber
,
102 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
103 IN VOID
*ConfigData OPTIONAL
,
107 CLOCK_MODULATION_CONFIG_DATA
*CmConfigData
;
108 MSR_IA32_CLOCK_MODULATION_REGISTER
*ClockModulation
;
110 CmConfigData
= (CLOCK_MODULATION_CONFIG_DATA
*)ConfigData
;
111 ASSERT (CmConfigData
!= NULL
);
112 ClockModulation
= &CmConfigData
[ProcessorNumber
].ClockModulation
;
115 ClockModulation
->Bits
.OnDemandClockModulationEnable
= 1;
116 ClockModulation
->Bits
.OnDemandClockModulationDutyCycle
= PcdGet8 (PcdCpuClockModulationDutyCycle
) >> 1;
117 if (CmConfigData
[ProcessorNumber
].ThermalPowerManagementEax
.Bits
.ECMD
== 1) {
118 ClockModulation
->Bits
.ExtendedOnDemandClockModulationDutyCycle
= PcdGet8 (PcdCpuClockModulationDutyCycle
) & BIT0
;
121 ClockModulation
->Bits
.OnDemandClockModulationEnable
= 0;
124 CPU_REGISTER_TABLE_WRITE64 (
127 MSR_IA32_CLOCK_MODULATION
,
128 ClockModulation
->Uint64
131 return RETURN_SUCCESS
;