]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 11typedef struct {\r
053e878b
MK
12 CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;\r
13 MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation;\r
fe0c2770
SZ
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
053e878b 31 UINT32 *ConfigData;\r
fe0c2770
SZ
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
053e878b 62 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;\r
fe0c2770
SZ
63\r
64 if (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI == 1) {\r
053e878b 65 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *)ConfigData;\r
fe0c2770
SZ
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
053e878b 77\r
fe0c2770 78 return FALSE;\r
80c4b236
JF
79}\r
80\r
81/**\r
82 Initializes Clock Modulation feature to specific state.\r
83\r
84 @param[in] ProcessorNumber The index of the CPU executing this function.\r
85 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
86 structure for the CPU executing this function.\r
87 @param[in] ConfigData A pointer to the configuration buffer returned\r
88 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
89 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
90 RegisterCpuFeature().\r
91 @param[in] State If TRUE, then the Clock Modulation feature must be enabled.\r
92 If FALSE, then the Clock Modulation feature must be disabled.\r
93\r
94 @retval RETURN_SUCCESS Clock Modulation feature is initialized.\r
95\r
96 @note This service could be called by BSP only.\r
97**/\r
98RETURN_STATUS\r
99EFIAPI\r
100ClockModulationInitialize (\r
101 IN UINTN ProcessorNumber,\r
102 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
4ec586b9 103 IN VOID *ConfigData OPTIONAL,\r
80c4b236
JF
104 IN BOOLEAN State\r
105 )\r
106{\r
053e878b
MK
107 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;\r
108 MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;\r
0c8b8802 109\r
053e878b 110 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *)ConfigData;\r
fe0c2770
SZ
111 ASSERT (CmConfigData != NULL);\r
112 ClockModulation = &CmConfigData[ProcessorNumber].ClockModulation;\r
113\r
114 if (State) {\r
053e878b 115 ClockModulation->Bits.OnDemandClockModulationEnable = 1;\r
fe0c2770
SZ
116 ClockModulation->Bits.OnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) >> 1;\r
117 if (CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Bits.ECMD == 1) {\r
118 ClockModulation->Bits.ExtendedOnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) & BIT0;\r
119 }\r
120 } else {\r
121 ClockModulation->Bits.OnDemandClockModulationEnable = 0;\r
80c4b236 122 }\r
fe0c2770
SZ
123\r
124 CPU_REGISTER_TABLE_WRITE64 (\r
0c8b8802
RN
125 ProcessorNumber,\r
126 Msr,\r
127 MSR_IA32_CLOCK_MODULATION,\r
fe0c2770 128 ClockModulation->Uint64\r
0c8b8802 129 );\r
fe0c2770 130\r
80c4b236
JF
131 return RETURN_SUCCESS;\r
132}\r