1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * cpufreq.h - definitions for libcpufreq 4 * 5 * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de> 6 */ 7 8 #ifndef __CPUPOWER_CPUFREQ_H__ 9 #define __CPUPOWER_CPUFREQ_H__ 10 11 struct cpufreq_policy { 12 unsigned long min; 13 unsigned long max; 14 char *governor; 15 }; 16 17 struct cpufreq_available_governors { 18 char *governor; 19 struct cpufreq_available_governors *next; 20 struct cpufreq_available_governors *first; 21 }; 22 23 struct cpufreq_available_frequencies { 24 unsigned long frequency; 25 struct cpufreq_available_frequencies *next; 26 struct cpufreq_available_frequencies *first; 27 }; 28 29 30 struct cpufreq_affected_cpus { 31 unsigned int cpu; 32 struct cpufreq_affected_cpus *next; 33 struct cpufreq_affected_cpus *first; 34 }; 35 36 struct cpufreq_stats { 37 unsigned long frequency; 38 unsigned long long time_in_state; 39 struct cpufreq_stats *next; 40 struct cpufreq_stats *first; 41 }; 42 43 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /* determine current CPU frequency 50 * - _kernel variant means kernel's opinion of CPU frequency 51 * - _hardware variant means actual hardware CPU frequency, 52 * which is only available to root. 53 * 54 * returns 0 on failure, else frequency in kHz. 55 */ 56 57 unsigned long cpufreq_get_freq_kernel(unsigned int cpu); 58 59 unsigned long cpufreq_get_freq_hardware(unsigned int cpu); 60 61 #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu); 62 63 64 /* determine CPU transition latency 65 * 66 * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds 67 */ 68 unsigned long cpufreq_get_transition_latency(unsigned int cpu); 69 70 71 /* determine energy performance preference 72 * 73 * returns NULL on failure, else the string that represents the energy performance 74 * preference requested. 75 */ 76 char *cpufreq_get_energy_performance_preference(unsigned int cpu); 77 void cpufreq_put_energy_performance_preference(char *ptr); 78 79 /* determine hardware CPU frequency limits 80 * 81 * These may be limited further by thermal, energy or other 82 * considerations by cpufreq policy notifiers in the kernel. 83 */ 84 85 int cpufreq_get_hardware_limits(unsigned int cpu, 86 unsigned long *min, 87 unsigned long *max); 88 89 90 /* determine CPUfreq driver used 91 * 92 * Remember to call cpufreq_put_driver when no longer needed 93 * to avoid memory leakage, please. 94 */ 95 96 char *cpufreq_get_driver(unsigned int cpu); 97 98 void cpufreq_put_driver(char *ptr); 99 100 101 /* determine CPUfreq policy currently used 102 * 103 * Remember to call cpufreq_put_policy when no longer needed 104 * to avoid memory leakage, please. 105 */ 106 107 108 struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu); 109 110 void cpufreq_put_policy(struct cpufreq_policy *policy); 111 112 113 /* determine CPUfreq governors currently available 114 * 115 * may be modified by modprobe'ing or rmmod'ing other governors. Please 116 * free allocated memory by calling cpufreq_put_available_governors 117 * after use. 118 */ 119 120 121 struct cpufreq_available_governors 122 *cpufreq_get_available_governors(unsigned int cpu); 123 124 void cpufreq_put_available_governors( 125 struct cpufreq_available_governors *first); 126 127 128 /* determine CPU frequency states available 129 * 130 * Only present on _some_ ->target() cpufreq drivers. For information purposes 131 * only. Please free allocated memory by calling 132 * cpufreq_put_frequencies after use. 133 */ 134 135 struct cpufreq_available_frequencies 136 *cpufreq_get_available_frequencies(unsigned int cpu); 137 138 void cpufreq_put_available_frequencies( 139 struct cpufreq_available_frequencies *first); 140 141 struct cpufreq_available_frequencies 142 *cpufreq_get_boost_frequencies(unsigned int cpu); 143 144 void cpufreq_put_boost_frequencies( 145 struct cpufreq_available_frequencies *first); 146 147 148 /* determine affected CPUs 149 * 150 * Remember to call cpufreq_put_affected_cpus when no longer needed 151 * to avoid memory leakage, please. 152 */ 153 154 struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned 155 int cpu); 156 157 void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first); 158 159 160 /* determine related CPUs 161 * 162 * Remember to call cpufreq_put_related_cpus when no longer needed 163 * to avoid memory leakage, please. 164 */ 165 166 struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned 167 int cpu); 168 169 void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first); 170 171 172 /* determine stats for cpufreq subsystem 173 * 174 * This is not available in all kernel versions or configurations. 175 */ 176 177 struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu, 178 unsigned long long *total_time); 179 180 void cpufreq_put_stats(struct cpufreq_stats *stats); 181 182 unsigned long cpufreq_get_transitions(unsigned int cpu); 183 184 185 /* set new cpufreq policy 186 * 187 * Tries to set the passed policy as new policy as close as possible, 188 * but results may differ depending e.g. on governors being available. 189 */ 190 191 int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy); 192 193 194 /* modify a policy by only changing min/max freq or governor 195 * 196 * Does not check whether result is what was intended. 197 */ 198 199 int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq); 200 int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq); 201 int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); 202 203 204 /* set a specific frequency 205 * 206 * Does only work if userspace governor can be used and no external 207 * interference (other calls to this function or to set/modify_policy) 208 * occurs. Also does not work on ->range() cpufreq drivers. 209 */ 210 211 int cpufreq_set_frequency(unsigned int cpu, 212 unsigned long target_frequency); 213 214 /* 215 * get the sysfs value from specific table 216 * 217 * Read the value with the sysfs file name from specific table. Does 218 * only work if the cpufreq driver has the specific sysfs interfaces. 219 */ 220 221 unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 222 const char **table, 223 unsigned int index, 224 unsigned int size); 225 226 #ifdef __cplusplus 227 } 228 #endif 229 230 #endif /* _CPUFREQ_H */ 231