1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * cpufreq.h - definitions for libcpufreq
5 * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
8 #ifndef __CPUPOWER_CPUFREQ_H__
9 #define __CPUPOWER_CPUFREQ_H__
11 struct cpufreq_policy
{
17 struct cpufreq_available_governors
{
19 struct cpufreq_available_governors
*next
;
20 struct cpufreq_available_governors
*first
;
23 struct cpufreq_available_frequencies
{
24 unsigned long frequency
;
25 struct cpufreq_available_frequencies
*next
;
26 struct cpufreq_available_frequencies
*first
;
30 struct cpufreq_affected_cpus
{
32 struct cpufreq_affected_cpus
*next
;
33 struct cpufreq_affected_cpus
*first
;
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
;
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.
54 * returns 0 on failure, else frequency in kHz.
57 unsigned long cpufreq_get_freq_kernel(unsigned int cpu
);
59 unsigned long cpufreq_get_freq_hardware(unsigned int cpu
);
61 #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
64 /* determine CPU transition latency
66 * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds
68 unsigned long cpufreq_get_transition_latency(unsigned int cpu
);
71 /* determine hardware CPU frequency limits
73 * These may be limited further by thermal, energy or other
74 * considerations by cpufreq policy notifiers in the kernel.
77 int cpufreq_get_hardware_limits(unsigned int cpu
,
82 /* determine CPUfreq driver used
84 * Remember to call cpufreq_put_driver when no longer needed
85 * to avoid memory leakage, please.
88 char *cpufreq_get_driver(unsigned int cpu
);
90 void cpufreq_put_driver(char *ptr
);
93 /* determine CPUfreq policy currently used
95 * Remember to call cpufreq_put_policy when no longer needed
96 * to avoid memory leakage, please.
100 struct cpufreq_policy
*cpufreq_get_policy(unsigned int cpu
);
102 void cpufreq_put_policy(struct cpufreq_policy
*policy
);
105 /* determine CPUfreq governors currently available
107 * may be modified by modprobe'ing or rmmod'ing other governors. Please
108 * free allocated memory by calling cpufreq_put_available_governors
113 struct cpufreq_available_governors
114 *cpufreq_get_available_governors(unsigned int cpu
);
116 void cpufreq_put_available_governors(
117 struct cpufreq_available_governors
*first
);
120 /* determine CPU frequency states available
122 * Only present on _some_ ->target() cpufreq drivers. For information purposes
123 * only. Please free allocated memory by calling
124 * cpufreq_put_frequencies after use.
127 struct cpufreq_available_frequencies
128 *cpufreq_get_available_frequencies(unsigned int cpu
);
130 void cpufreq_put_available_frequencies(
131 struct cpufreq_available_frequencies
*first
);
133 struct cpufreq_available_frequencies
134 *cpufreq_get_boost_frequencies(unsigned int cpu
);
136 void cpufreq_put_boost_frequencies(
137 struct cpufreq_available_frequencies
*first
);
140 /* determine affected CPUs
142 * Remember to call cpufreq_put_affected_cpus when no longer needed
143 * to avoid memory leakage, please.
146 struct cpufreq_affected_cpus
*cpufreq_get_affected_cpus(unsigned
149 void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus
*first
);
152 /* determine related CPUs
154 * Remember to call cpufreq_put_related_cpus when no longer needed
155 * to avoid memory leakage, please.
158 struct cpufreq_affected_cpus
*cpufreq_get_related_cpus(unsigned
161 void cpufreq_put_related_cpus(struct cpufreq_affected_cpus
*first
);
164 /* determine stats for cpufreq subsystem
166 * This is not available in all kernel versions or configurations.
169 struct cpufreq_stats
*cpufreq_get_stats(unsigned int cpu
,
170 unsigned long long *total_time
);
172 void cpufreq_put_stats(struct cpufreq_stats
*stats
);
174 unsigned long cpufreq_get_transitions(unsigned int cpu
);
177 /* set new cpufreq policy
179 * Tries to set the passed policy as new policy as close as possible,
180 * but results may differ depending e.g. on governors being available.
183 int cpufreq_set_policy(unsigned int cpu
, struct cpufreq_policy
*policy
);
186 /* modify a policy by only changing min/max freq or governor
188 * Does not check whether result is what was intended.
191 int cpufreq_modify_policy_min(unsigned int cpu
, unsigned long min_freq
);
192 int cpufreq_modify_policy_max(unsigned int cpu
, unsigned long max_freq
);
193 int cpufreq_modify_policy_governor(unsigned int cpu
, char *governor
);
196 /* set a specific frequency
198 * Does only work if userspace governor can be used and no external
199 * interference (other calls to this function or to set/modify_policy)
200 * occurs. Also does not work on ->range() cpufreq drivers.
203 int cpufreq_set_frequency(unsigned int cpu
,
204 unsigned long target_frequency
);
210 #endif /* _CPUFREQ_H */