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