Merge tag 'pm-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-2.6-block.git] / tools / power / cpupower / lib / cpufreq.h
CommitLineData
7fe2f639
DB
1/*
2 * cpufreq.h - definitions for libcpufreq
3 *
4 * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
ac5a181d
TR
20#ifndef __CPUPOWER_CPUFREQ_H__
21#define __CPUPOWER_CPUFREQ_H__
7fe2f639
DB
22
23struct cpufreq_policy {
24 unsigned long min;
25 unsigned long max;
26 char *governor;
27};
28
29struct cpufreq_available_governors {
30 char *governor;
31 struct cpufreq_available_governors *next;
32 struct cpufreq_available_governors *first;
33};
34
35struct cpufreq_available_frequencies {
36 unsigned long frequency;
37 struct cpufreq_available_frequencies *next;
38 struct cpufreq_available_frequencies *first;
39};
40
41
42struct cpufreq_affected_cpus {
43 unsigned int cpu;
44 struct cpufreq_affected_cpus *next;
45 struct cpufreq_affected_cpus *first;
46};
47
48struct cpufreq_stats {
49 unsigned long frequency;
50 unsigned long long time_in_state;
51 struct cpufreq_stats *next;
52 struct cpufreq_stats *first;
53};
54
55
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
7fe2f639
DB
61/* determine current CPU frequency
62 * - _kernel variant means kernel's opinion of CPU frequency
63 * - _hardware variant means actual hardware CPU frequency,
64 * which is only available to root.
65 *
66 * returns 0 on failure, else frequency in kHz.
67 */
68
ac5a181d 69unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
7fe2f639 70
ac5a181d 71unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
7fe2f639
DB
72
73#define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
74
75
76/* determine CPU transition latency
77 *
78 * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds
79 */
ac5a181d 80unsigned long cpufreq_get_transition_latency(unsigned int cpu);
7fe2f639
DB
81
82
83/* determine hardware CPU frequency limits
84 *
85 * These may be limited further by thermal, energy or other
86 * considerations by cpufreq policy notifiers in the kernel.
87 */
88
ac5a181d 89int cpufreq_get_hardware_limits(unsigned int cpu,
6c2b8185
DB
90 unsigned long *min,
91 unsigned long *max);
7fe2f639
DB
92
93
94/* determine CPUfreq driver used
95 *
96 * Remember to call cpufreq_put_driver when no longer needed
97 * to avoid memory leakage, please.
98 */
99
ac5a181d 100char *cpufreq_get_driver(unsigned int cpu);
7fe2f639 101
ac5a181d 102void cpufreq_put_driver(char *ptr);
7fe2f639
DB
103
104
105/* determine CPUfreq policy currently used
106 *
107 * Remember to call cpufreq_put_policy when no longer needed
108 * to avoid memory leakage, please.
109 */
110
111
ac5a181d 112struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);
7fe2f639 113
ac5a181d 114void cpufreq_put_policy(struct cpufreq_policy *policy);
7fe2f639
DB
115
116
117/* determine CPUfreq governors currently available
118 *
119 * may be modified by modprobe'ing or rmmod'ing other governors. Please
120 * free allocated memory by calling cpufreq_put_available_governors
121 * after use.
122 */
123
124
ac5a181d 125struct cpufreq_available_governors
6c2b8185 126*cpufreq_get_available_governors(unsigned int cpu);
7fe2f639 127
ac5a181d 128void cpufreq_put_available_governors(
6c2b8185 129 struct cpufreq_available_governors *first);
7fe2f639
DB
130
131
132/* determine CPU frequency states available
133 *
6c2b8185
DB
134 * Only present on _some_ ->target() cpufreq drivers. For information purposes
135 * only. Please free allocated memory by calling
136 * cpufreq_put_available_frequencies after use.
7fe2f639
DB
137 */
138
ac5a181d 139struct cpufreq_available_frequencies
6c2b8185 140*cpufreq_get_available_frequencies(unsigned int cpu);
7fe2f639 141
ac5a181d 142void cpufreq_put_available_frequencies(
6c2b8185 143 struct cpufreq_available_frequencies *first);
7fe2f639
DB
144
145
6c2b8185 146/* determine affected CPUs
7fe2f639
DB
147 *
148 * Remember to call cpufreq_put_affected_cpus when no longer needed
149 * to avoid memory leakage, please.
150 */
151
ac5a181d 152struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned
6c2b8185 153 int cpu);
7fe2f639 154
ac5a181d 155void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);
7fe2f639
DB
156
157
6c2b8185 158/* determine related CPUs
7fe2f639
DB
159 *
160 * Remember to call cpufreq_put_related_cpus when no longer needed
161 * to avoid memory leakage, please.
162 */
163
ac5a181d 164struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned
6c2b8185 165 int cpu);
7fe2f639 166
ac5a181d 167void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
7fe2f639
DB
168
169
170/* determine stats for cpufreq subsystem
171 *
172 * This is not available in all kernel versions or configurations.
173 */
174
ac5a181d 175struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
6c2b8185 176 unsigned long long *total_time);
7fe2f639 177
ac5a181d 178void cpufreq_put_stats(struct cpufreq_stats *stats);
7fe2f639 179
ac5a181d 180unsigned long cpufreq_get_transitions(unsigned int cpu);
7fe2f639
DB
181
182
6c2b8185
DB
183/* set new cpufreq policy
184 *
7fe2f639
DB
185 * Tries to set the passed policy as new policy as close as possible,
186 * but results may differ depending e.g. on governors being available.
187 */
188
ac5a181d 189int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
7fe2f639
DB
190
191
6c2b8185 192/* modify a policy by only changing min/max freq or governor
7fe2f639
DB
193 *
194 * Does not check whether result is what was intended.
195 */
196
ac5a181d
TR
197int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
198int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
199int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
7fe2f639
DB
200
201
202/* set a specific frequency
203 *
204 * Does only work if userspace governor can be used and no external
6c2b8185 205 * interference (other calls to this function or to set/modify_policy)
7fe2f639
DB
206 * occurs. Also does not work on ->range() cpufreq drivers.
207 */
208
ac5a181d 209int cpufreq_set_frequency(unsigned int cpu,
6c2b8185 210 unsigned long target_frequency);
7fe2f639
DB
211
212#ifdef __cplusplus
213}
214#endif
215
216#endif /* _CPUFREQ_H */