]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c
UefiCpuPkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / ClockModulation.c
CommitLineData
80c4b236
JF
1/** @file\r
2 Clock Modulation feature.\r
3\r
fe0c2770 4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
80c4b236
JF
6\r
7**/\r
8\r
9#include "CpuCommonFeatures.h"\r
10\r
fe0c2770
SZ
11typedef struct {\r
12 CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;\r
13 MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation;\r
14} CLOCK_MODULATION_CONFIG_DATA;\r
15\r
16/**\r
17 Prepares for the data used by CPU feature detection and initialization.\r
18\r
19 @param[in] NumberOfProcessors The number of CPUs in the platform.\r
20\r
21 @return Pointer to a buffer of CPU related configuration data.\r
22\r
23 @note This service could be called by BSP only.\r
24**/\r
25VOID *\r
26EFIAPI\r
27ClockModulationGetConfigData (\r
28 IN UINTN NumberOfProcessors\r
29 )\r
30{\r
31 UINT32 *ConfigData;\r
32\r
33 ConfigData = AllocateZeroPool (sizeof (CLOCK_MODULATION_CONFIG_DATA) * NumberOfProcessors);\r
34 ASSERT (ConfigData != NULL);\r
35 return ConfigData;\r
36}\r
37\r
80c4b236
JF
38/**\r
39 Detects if Clock Modulation feature supported on current processor.\r
40\r
41 @param[in] ProcessorNumber The index of the CPU executing this function.\r
42 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
43 structure for the CPU executing this function.\r
44 @param[in] ConfigData A pointer to the configuration buffer returned\r
45 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
46 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
47 RegisterCpuFeature().\r
48\r
49 @retval TRUE Clock Modulation feature is supported.\r
50 @retval FALSE Clock Modulation feature is not supported.\r
51\r
52 @note This service could be called by BSP/APs.\r
53**/\r
54BOOLEAN\r
55EFIAPI\r
56ClockModulationSupport (\r
57 IN UINTN ProcessorNumber,\r
58 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
59 IN VOID *ConfigData OPTIONAL\r
60 )\r
61{\r
fe0c2770
SZ
62 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;\r
63\r
64 if (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI == 1) {\r
65 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;\r
66 ASSERT (CmConfigData != NULL);\r
67 AsmCpuid (\r
68 CPUID_THERMAL_POWER_MANAGEMENT,\r
69 &CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Uint32,\r
70 NULL,\r
71 NULL,\r
72 NULL\r
73 );\r
74 CmConfigData[ProcessorNumber].ClockModulation.Uint64 = AsmReadMsr64 (MSR_IA32_CLOCK_MODULATION);\r
75 return TRUE;\r
76 }\r
77 return FALSE;\r
80c4b236
JF
78}\r
79\r
80/**\r
81 Initializes Clock Modulation feature to specific state.\r
82\r
83 @param[in] ProcessorNumber The index of the CPU executing this function.\r
84 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
85 structure for the CPU executing this function.\r
86 @param[in] ConfigData A pointer to the configuration buffer returned\r
87 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
88 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
89 RegisterCpuFeature().\r
90 @param[in] State If TRUE, then the Clock Modulation feature must be enabled.\r
91 If FALSE, then the Clock Modulation feature must be disabled.\r
92\r
93 @retval RETURN_SUCCESS Clock Modulation feature is initialized.\r
94\r
95 @note This service could be called by BSP only.\r
96**/\r
97RETURN_STATUS\r
98EFIAPI\r
99ClockModulationInitialize (\r
100 IN UINTN ProcessorNumber,\r
101 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
4ec586b9 102 IN VOID *ConfigData OPTIONAL,\r
80c4b236
JF
103 IN BOOLEAN State\r
104 )\r
105{\r
fe0c2770
SZ
106 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;\r
107 MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;\r
0c8b8802 108\r
fe0c2770
SZ
109 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;\r
110 ASSERT (CmConfigData != NULL);\r
111 ClockModulation = &CmConfigData[ProcessorNumber].ClockModulation;\r
112\r
113 if (State) {\r
114 ClockModulation->Bits.OnDemandClockModulationEnable = 1;\r
115 ClockModulation->Bits.OnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) >> 1;\r
116 if (CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Bits.ECMD == 1) {\r
117 ClockModulation->Bits.ExtendedOnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) & BIT0;\r
118 }\r
119 } else {\r
120 ClockModulation->Bits.OnDemandClockModulationEnable = 0;\r
80c4b236 121 }\r
fe0c2770
SZ
122\r
123 CPU_REGISTER_TABLE_WRITE64 (\r
0c8b8802
RN
124 ProcessorNumber,\r
125 Msr,\r
126 MSR_IA32_CLOCK_MODULATION,\r
fe0c2770 127 ClockModulation->Uint64\r
0c8b8802 128 );\r
fe0c2770 129\r
80c4b236
JF
130 return RETURN_SUCCESS;\r
131}\r