]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Clock Modulation feature.\r | |
3 | \r | |
4 | Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #include "CpuCommonFeatures.h"\r | |
10 | \r | |
11 | typedef 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 | |
25 | VOID *\r | |
26 | EFIAPI\r | |
27 | ClockModulationGetConfigData (\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 | |
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 | |
54 | BOOLEAN\r | |
55 | EFIAPI\r | |
56 | ClockModulationSupport (\r | |
57 | IN UINTN ProcessorNumber,\r | |
58 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r | |
59 | IN VOID *ConfigData OPTIONAL\r | |
60 | )\r | |
61 | {\r | |
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 | \r | |
78 | return FALSE;\r | |
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 | |
98 | RETURN_STATUS\r | |
99 | EFIAPI\r | |
100 | ClockModulationInitialize (\r | |
101 | IN UINTN ProcessorNumber,\r | |
102 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r | |
103 | IN VOID *ConfigData OPTIONAL,\r | |
104 | IN BOOLEAN State\r | |
105 | )\r | |
106 | {\r | |
107 | CLOCK_MODULATION_CONFIG_DATA *CmConfigData;\r | |
108 | MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;\r | |
109 | \r | |
110 | CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *)ConfigData;\r | |
111 | ASSERT (CmConfigData != NULL);\r | |
112 | ClockModulation = &CmConfigData[ProcessorNumber].ClockModulation;\r | |
113 | \r | |
114 | if (State) {\r | |
115 | ClockModulation->Bits.OnDemandClockModulationEnable = 1;\r | |
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 | |
122 | }\r | |
123 | \r | |
124 | CPU_REGISTER_TABLE_WRITE64 (\r | |
125 | ProcessorNumber,\r | |
126 | Msr,\r | |
127 | MSR_IA32_CLOCK_MODULATION,\r | |
128 | ClockModulation->Uint64\r | |
129 | );\r | |
130 | \r | |
131 | return RETURN_SUCCESS;\r | |
132 | }\r |