device.h: audit and cleanup users in main include dir
[deliverable/linux.git] / include / linux / cpufreq.h
CommitLineData
1da177e4
LT
1/*
2 * linux/include/linux/cpufreq.h
3 *
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
335dc333 6 *
1da177e4
LT
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _LINUX_CPUFREQ_H
12#define _LINUX_CPUFREQ_H
13
83933af4 14#include <linux/mutex.h>
1da177e4
LT
15#include <linux/notifier.h>
16#include <linux/threads.h>
1da177e4
LT
17#include <linux/kobject.h>
18#include <linux/sysfs.h>
19#include <linux/completion.h>
20#include <linux/workqueue.h>
21#include <linux/cpumask.h>
4e57b681 22#include <asm/div64.h>
1da177e4
LT
23
24#define CPUFREQ_NAME_LEN 16
25
26
27/*********************************************************************
28 * CPUFREQ NOTIFIER INTERFACE *
29 *********************************************************************/
30
1da177e4
LT
31#define CPUFREQ_TRANSITION_NOTIFIER (0)
32#define CPUFREQ_POLICY_NOTIFIER (1)
33
6070b5de
SS
34#ifdef CONFIG_CPU_FREQ
35int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
36int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
37#else /* CONFIG_CPU_FREQ */
38static inline int cpufreq_register_notifier(struct notifier_block *nb,
39 unsigned int list)
40{
41 return 0;
42}
43static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
44 unsigned int list)
45{
46 return 0;
47}
48#endif /* CONFIG_CPU_FREQ */
1da177e4
LT
49
50/* if (cpufreq_driver->target) exists, the ->governor decides what frequency
51 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
52 * two generic policies are available:
53 */
54
55#define CPUFREQ_POLICY_POWERSAVE (1)
56#define CPUFREQ_POLICY_PERFORMANCE (2)
57
335dc333
TF
58/* Frequency values here are CPU kHz so that hardware which doesn't run
59 * with some frequencies can complain without having to guess what per
60 * cent / per mille means.
b53cc6ea 61 * Maximum transition latency is in nanoseconds - if it's unknown,
1da177e4
LT
62 * CPUFREQ_ETERNAL shall be used.
63 */
64
65struct cpufreq_governor;
66
8aa84ad8
TR
67/* /sys/devices/system/cpu/cpufreq: entry point for global variables */
68extern struct kobject *cpufreq_global_kobject;
69
1da177e4
LT
70#define CPUFREQ_ETERNAL (-1)
71struct cpufreq_cpuinfo {
72 unsigned int max_freq;
73 unsigned int min_freq;
335dc333
TF
74
75 /* in 10^(-9) s = nanoseconds */
76 unsigned int transition_latency;
1da177e4
LT
77};
78
79struct cpufreq_real_policy {
80 unsigned int min; /* in kHz */
81 unsigned int max; /* in kHz */
335dc333 82 unsigned int policy; /* see above */
1da177e4
LT
83 struct cpufreq_governor *governor; /* see below */
84};
85
86struct cpufreq_policy {
835481d9
RR
87 cpumask_var_t cpus; /* CPUs requiring sw coordination */
88 cpumask_var_t related_cpus; /* CPUs with any coordination */
3b2d9942
VP
89 unsigned int shared_type; /* ANY or ALL affected CPUs
90 should set cpufreq */
1da177e4
LT
91 unsigned int cpu; /* cpu nr of registered CPU */
92 struct cpufreq_cpuinfo cpuinfo;/* see above */
93
94 unsigned int min; /* in kHz */
95 unsigned int max; /* in kHz */
96 unsigned int cur; /* in kHz, only needed if cpufreq
97 * governors are used */
335dc333 98 unsigned int policy; /* see above */
1da177e4
LT
99 struct cpufreq_governor *governor; /* see below */
100
1da177e4
LT
101 struct work_struct update; /* if update_policy() needs to be
102 * called, but you're in IRQ context */
103
104 struct cpufreq_real_policy user_policy;
105
106 struct kobject kobj;
107 struct completion kobj_unregister;
108};
109
110#define CPUFREQ_ADJUST (0)
111#define CPUFREQ_INCOMPATIBLE (1)
112#define CPUFREQ_NOTIFY (2)
a1531acd 113#define CPUFREQ_START (3)
1da177e4 114
46f18e3a
VP
115#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
116#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
117#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
118#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
1da177e4
LT
119
120/******************** cpufreq transition notifiers *******************/
121
122#define CPUFREQ_PRECHANGE (0)
123#define CPUFREQ_POSTCHANGE (1)
124#define CPUFREQ_RESUMECHANGE (8)
42d4dc3f 125#define CPUFREQ_SUSPENDCHANGE (9)
1da177e4
LT
126
127struct cpufreq_freqs {
128 unsigned int cpu; /* cpu nr */
129 unsigned int old;
130 unsigned int new;
131 u8 flags; /* flags of cpufreq_driver, see below. */
132};
133
134
135/**
136 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
137 * @old: old value
138 * @div: divisor
139 * @mult: multiplier
140 *
141 *
142 * new = old * mult / div
143 */
144static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
145{
146#if BITS_PER_LONG == 32
147
148 u64 result = ((u64) old) * ((u64) mult);
149 do_div(result, div);
150 return (unsigned long) result;
151
152#elif BITS_PER_LONG == 64
153
154 unsigned long result = old * ((u64) mult);
155 result /= div;
156 return result;
157
158#endif
159};
160
161/*********************************************************************
162 * CPUFREQ GOVERNORS *
163 *********************************************************************/
164
165#define CPUFREQ_GOV_START 1
166#define CPUFREQ_GOV_STOP 2
167#define CPUFREQ_GOV_LIMITS 3
168
169struct cpufreq_governor {
170 char name[CPUFREQ_NAME_LEN];
335dc333 171 int (*governor) (struct cpufreq_policy *policy,
1da177e4 172 unsigned int event);
9e76988e
VP
173 ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
174 char *buf);
335dc333 175 int (*store_setspeed) (struct cpufreq_policy *policy,
9e76988e 176 unsigned int freq);
1c256245
TR
177 unsigned int max_transition_latency; /* HW must be able to switch to
178 next freq faster than this value in nano secs or we
179 will fallback to performance governor */
1da177e4
LT
180 struct list_head governor_list;
181 struct module *owner;
182};
183
335dc333
TF
184/*
185 * Pass a target to the cpufreq driver.
1da177e4
LT
186 */
187extern int cpufreq_driver_target(struct cpufreq_policy *policy,
188 unsigned int target_freq,
189 unsigned int relation);
190extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
191 unsigned int target_freq,
192 unsigned int relation);
193
194
bf0b90e3 195extern int __cpufreq_driver_getavg(struct cpufreq_policy *policy,
196 unsigned int cpu);
dfde5d62 197
1da177e4
LT
198int cpufreq_register_governor(struct cpufreq_governor *governor);
199void cpufreq_unregister_governor(struct cpufreq_governor *governor);
200
201
202/*********************************************************************
203 * CPUFREQ DRIVER INTERFACE *
204 *********************************************************************/
205
206#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
207#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
208
209struct freq_attr;
210
211struct cpufreq_driver {
212 struct module *owner;
213 char name[CPUFREQ_NAME_LEN];
214 u8 flags;
215
216 /* needed by all drivers */
217 int (*init) (struct cpufreq_policy *policy);
218 int (*verify) (struct cpufreq_policy *policy);
219
220 /* define one out of two */
221 int (*setpolicy) (struct cpufreq_policy *policy);
222 int (*target) (struct cpufreq_policy *policy,
223 unsigned int target_freq,
224 unsigned int relation);
225
226 /* should be defined, if possible */
227 unsigned int (*get) (unsigned int cpu);
228
229 /* optional */
bf0b90e3 230 unsigned int (*getavg) (struct cpufreq_policy *policy,
231 unsigned int cpu);
e2f74f35 232 int (*bios_limit) (int cpu, unsigned int *limit);
bf0b90e3 233
1da177e4 234 int (*exit) (struct cpufreq_policy *policy);
7ca64e2d 235 int (*suspend) (struct cpufreq_policy *policy);
1da177e4
LT
236 int (*resume) (struct cpufreq_policy *policy);
237 struct freq_attr **attr;
238};
239
240/* flags */
241
335dc333 242#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
1da177e4 243 * all ->init() calls failed */
335dc333 244#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
1da177e4
LT
245 * "constants" aren't affected by
246 * frequency transitions */
42d4dc3f
BH
247#define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
248 * mismatches */
1da177e4 249
221dee28
LT
250int cpufreq_register_driver(struct cpufreq_driver *driver_data);
251int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
1da177e4
LT
252
253
254void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
255
256
335dc333 257static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
1da177e4
LT
258{
259 if (policy->min < min)
260 policy->min = min;
261 if (policy->max < min)
262 policy->max = min;
263 if (policy->min > max)
264 policy->min = max;
265 if (policy->max > max)
266 policy->max = max;
267 if (policy->min > policy->max)
268 policy->min = policy->max;
269 return;
270}
271
272struct freq_attr {
273 struct attribute attr;
274 ssize_t (*show)(struct cpufreq_policy *, char *);
275 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
276};
277
6dad2a29
BP
278#define cpufreq_freq_attr_ro(_name) \
279static struct freq_attr _name = \
280__ATTR(_name, 0444, show_##_name, NULL)
281
282#define cpufreq_freq_attr_ro_perm(_name, _perm) \
283static struct freq_attr _name = \
284__ATTR(_name, _perm, show_##_name, NULL)
285
6dad2a29
BP
286#define cpufreq_freq_attr_rw(_name) \
287static struct freq_attr _name = \
288__ATTR(_name, 0644, show_##_name, store_##_name)
289
8aa84ad8
TR
290struct global_attr {
291 struct attribute attr;
292 ssize_t (*show)(struct kobject *kobj,
293 struct attribute *attr, char *buf);
294 ssize_t (*store)(struct kobject *a, struct attribute *b,
295 const char *c, size_t count);
296};
1da177e4 297
6dad2a29
BP
298#define define_one_global_ro(_name) \
299static struct global_attr _name = \
300__ATTR(_name, 0444, show_##_name, NULL)
301
302#define define_one_global_rw(_name) \
303static struct global_attr _name = \
304__ATTR(_name, 0644, show_##_name, store_##_name)
305
306
1da177e4
LT
307/*********************************************************************
308 * CPUFREQ 2.6. INTERFACE *
309 *********************************************************************/
1da177e4
LT
310int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
311int cpufreq_update_policy(unsigned int cpu);
312
2eca40a8 313#ifdef CONFIG_CPU_FREQ
ff0ce684
LT
314/* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
315unsigned int cpufreq_get(unsigned int cpu);
2eca40a8
RD
316#else
317static inline unsigned int cpufreq_get(unsigned int cpu)
318{
319 return 0;
320}
321#endif
1da177e4 322
ff0ce684 323/* query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it */
95235ca2
VP
324#ifdef CONFIG_CPU_FREQ
325unsigned int cpufreq_quick_get(unsigned int cpu);
3d737108 326unsigned int cpufreq_quick_get_max(unsigned int cpu);
95235ca2
VP
327#else
328static inline unsigned int cpufreq_quick_get(unsigned int cpu)
329{
330 return 0;
331}
3d737108
JB
332static inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
333{
334 return 0;
335}
95235ca2
VP
336#endif
337
1da177e4
LT
338
339/*********************************************************************
340 * CPUFREQ DEFAULT GOVERNOR *
341 *********************************************************************/
342
343
1c256245
TR
344/*
345 Performance governor is fallback governor if any other gov failed to
346 auto load due latency restrictions
347*/
6afde10c 348#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
1da177e4 349extern struct cpufreq_governor cpufreq_gov_performance;
6afde10c 350#endif
1c256245
TR
351#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
352#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
30d221db
AG
353#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
354extern struct cpufreq_governor cpufreq_gov_powersave;
355#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
1da177e4
LT
356#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
357extern struct cpufreq_governor cpufreq_gov_userspace;
1c256245
TR
358#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
359#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
360extern struct cpufreq_governor cpufreq_gov_ondemand;
361#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
362#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
363extern struct cpufreq_governor cpufreq_gov_conservative;
364#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
1da177e4
LT
365#endif
366
367
368/*********************************************************************
369 * FREQUENCY TABLE HELPERS *
370 *********************************************************************/
371
372#define CPUFREQ_ENTRY_INVALID ~0
373#define CPUFREQ_TABLE_END ~1
374
375struct cpufreq_frequency_table {
376 unsigned int index; /* any */
377 unsigned int frequency; /* kHz - doesn't need to be in ascending
378 * order */
379};
380
381int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
382 struct cpufreq_frequency_table *table);
383
384int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
385 struct cpufreq_frequency_table *table);
386
387int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
388 struct cpufreq_frequency_table *table,
389 unsigned int target_freq,
390 unsigned int relation,
391 unsigned int *index);
392
393/* the following 3 funtions are for cpufreq core use only */
394struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
395struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
335dc333 396void cpufreq_cpu_put(struct cpufreq_policy *data);
1da177e4
LT
397
398/* the following are really really optional */
399extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
400
335dc333 401void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
1da177e4
LT
402 unsigned int cpu);
403
404void cpufreq_frequency_table_put_attr(unsigned int cpu);
405
406
1da177e4 407#endif /* _LINUX_CPUFREQ_H */
This page took 0.648037 seconds and 5 git commands to generate.