[CPUFREQ] convert remaining cpufreq semaphore to a mutex
[linux-2.6/mini2440.git] / include / linux / cpufreq.h
blob17866d7e2b71ad08e12fc9340d5b77448032da48
1 /*
2 * linux/include/linux/cpufreq.h
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 *
8 * $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 #ifndef _LINUX_CPUFREQ_H
15 #define _LINUX_CPUFREQ_H
17 #include <linux/mutex.h>
18 #include <linux/config.h>
19 #include <linux/notifier.h>
20 #include <linux/threads.h>
21 #include <linux/device.h>
22 #include <linux/kobject.h>
23 #include <linux/sysfs.h>
24 #include <linux/completion.h>
25 #include <linux/workqueue.h>
26 #include <linux/cpumask.h>
27 #include <asm/div64.h>
29 #define CPUFREQ_NAME_LEN 16
32 /*********************************************************************
33 * CPUFREQ NOTIFIER INTERFACE *
34 *********************************************************************/
36 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
37 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
39 #define CPUFREQ_TRANSITION_NOTIFIER (0)
40 #define CPUFREQ_POLICY_NOTIFIER (1)
43 /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
44 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
45 * two generic policies are available:
48 #define CPUFREQ_POLICY_POWERSAVE (1)
49 #define CPUFREQ_POLICY_PERFORMANCE (2)
51 /* Frequency values here are CPU kHz so that hardware which doesn't run
52 * with some frequencies can complain without having to guess what per
53 * cent / per mille means.
54 * Maximum transition latency is in nanoseconds - if it's unknown,
55 * CPUFREQ_ETERNAL shall be used.
58 struct cpufreq_governor;
60 #define CPUFREQ_ETERNAL (-1)
61 struct cpufreq_cpuinfo {
62 unsigned int max_freq;
63 unsigned int min_freq;
64 unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
67 struct cpufreq_real_policy {
68 unsigned int min; /* in kHz */
69 unsigned int max; /* in kHz */
70 unsigned int policy; /* see above */
71 struct cpufreq_governor *governor; /* see below */
74 struct cpufreq_policy {
75 cpumask_t cpus; /* affected CPUs */
76 unsigned int cpu; /* cpu nr of registered CPU */
77 struct cpufreq_cpuinfo cpuinfo;/* see above */
79 unsigned int min; /* in kHz */
80 unsigned int max; /* in kHz */
81 unsigned int cur; /* in kHz, only needed if cpufreq
82 * governors are used */
83 unsigned int policy; /* see above */
84 struct cpufreq_governor *governor; /* see below */
86 struct mutex lock; /* CPU ->setpolicy or ->target may
87 only be called once a time */
89 struct work_struct update; /* if update_policy() needs to be
90 * called, but you're in IRQ context */
92 struct cpufreq_real_policy user_policy;
94 struct kobject kobj;
95 struct completion kobj_unregister;
98 #define CPUFREQ_ADJUST (0)
99 #define CPUFREQ_INCOMPATIBLE (1)
100 #define CPUFREQ_NOTIFY (2)
103 /******************** cpufreq transition notifiers *******************/
105 #define CPUFREQ_PRECHANGE (0)
106 #define CPUFREQ_POSTCHANGE (1)
107 #define CPUFREQ_RESUMECHANGE (8)
108 #define CPUFREQ_SUSPENDCHANGE (9)
110 struct cpufreq_freqs {
111 unsigned int cpu; /* cpu nr */
112 unsigned int old;
113 unsigned int new;
114 u8 flags; /* flags of cpufreq_driver, see below. */
119 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
120 * @old: old value
121 * @div: divisor
122 * @mult: multiplier
125 * new = old * mult / div
127 static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
129 #if BITS_PER_LONG == 32
131 u64 result = ((u64) old) * ((u64) mult);
132 do_div(result, div);
133 return (unsigned long) result;
135 #elif BITS_PER_LONG == 64
137 unsigned long result = old * ((u64) mult);
138 result /= div;
139 return result;
141 #endif
144 /*********************************************************************
145 * CPUFREQ GOVERNORS *
146 *********************************************************************/
148 #define CPUFREQ_GOV_START 1
149 #define CPUFREQ_GOV_STOP 2
150 #define CPUFREQ_GOV_LIMITS 3
152 struct cpufreq_governor {
153 char name[CPUFREQ_NAME_LEN];
154 int (*governor) (struct cpufreq_policy *policy,
155 unsigned int event);
156 struct list_head governor_list;
157 struct module *owner;
160 /* pass a target to the cpufreq driver
162 extern int cpufreq_driver_target(struct cpufreq_policy *policy,
163 unsigned int target_freq,
164 unsigned int relation);
165 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
166 unsigned int target_freq,
167 unsigned int relation);
170 /* pass an event to the cpufreq governor */
171 int cpufreq_governor(unsigned int cpu, unsigned int event);
173 int cpufreq_register_governor(struct cpufreq_governor *governor);
174 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
177 /*********************************************************************
178 * CPUFREQ DRIVER INTERFACE *
179 *********************************************************************/
181 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
182 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
184 struct freq_attr;
186 struct cpufreq_driver {
187 struct module *owner;
188 char name[CPUFREQ_NAME_LEN];
189 u8 flags;
191 /* needed by all drivers */
192 int (*init) (struct cpufreq_policy *policy);
193 int (*verify) (struct cpufreq_policy *policy);
195 /* define one out of two */
196 int (*setpolicy) (struct cpufreq_policy *policy);
197 int (*target) (struct cpufreq_policy *policy,
198 unsigned int target_freq,
199 unsigned int relation);
201 /* should be defined, if possible */
202 unsigned int (*get) (unsigned int cpu);
204 /* optional */
205 int (*exit) (struct cpufreq_policy *policy);
206 int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
207 int (*resume) (struct cpufreq_policy *policy);
208 struct freq_attr **attr;
211 /* flags */
213 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
214 * all ->init() calls failed */
215 #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
216 * "constants" aren't affected by
217 * frequency transitions */
218 #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
219 * mismatches */
221 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
222 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
225 void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
228 static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
230 if (policy->min < min)
231 policy->min = min;
232 if (policy->max < min)
233 policy->max = min;
234 if (policy->min > max)
235 policy->min = max;
236 if (policy->max > max)
237 policy->max = max;
238 if (policy->min > policy->max)
239 policy->min = policy->max;
240 return;
243 struct freq_attr {
244 struct attribute attr;
245 ssize_t (*show)(struct cpufreq_policy *, char *);
246 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
250 /*********************************************************************
251 * CPUFREQ 2.6. INTERFACE *
252 *********************************************************************/
253 int cpufreq_set_policy(struct cpufreq_policy *policy);
254 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
255 int cpufreq_update_policy(unsigned int cpu);
257 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
258 unsigned int cpufreq_get(unsigned int cpu);
260 /* query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it */
261 #ifdef CONFIG_CPU_FREQ
262 unsigned int cpufreq_quick_get(unsigned int cpu);
263 #else
264 static inline unsigned int cpufreq_quick_get(unsigned int cpu)
266 return 0;
268 #endif
271 /*********************************************************************
272 * CPUFREQ DEFAULT GOVERNOR *
273 *********************************************************************/
276 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
277 extern struct cpufreq_governor cpufreq_gov_performance;
278 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
279 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
280 extern struct cpufreq_governor cpufreq_gov_userspace;
281 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
282 #endif
285 /*********************************************************************
286 * FREQUENCY TABLE HELPERS *
287 *********************************************************************/
289 #define CPUFREQ_ENTRY_INVALID ~0
290 #define CPUFREQ_TABLE_END ~1
292 struct cpufreq_frequency_table {
293 unsigned int index; /* any */
294 unsigned int frequency; /* kHz - doesn't need to be in ascending
295 * order */
298 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
299 struct cpufreq_frequency_table *table);
301 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
302 struct cpufreq_frequency_table *table);
304 int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
305 struct cpufreq_frequency_table *table,
306 unsigned int target_freq,
307 unsigned int relation,
308 unsigned int *index);
310 /* the following 3 funtions are for cpufreq core use only */
311 struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
312 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
313 void cpufreq_cpu_put (struct cpufreq_policy *data);
315 /* the following are really really optional */
316 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
318 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
319 unsigned int cpu);
321 void cpufreq_frequency_table_put_attr(unsigned int cpu);
324 /*********************************************************************
325 * UNIFIED DEBUG HELPERS *
326 *********************************************************************/
328 #define CPUFREQ_DEBUG_CORE 1
329 #define CPUFREQ_DEBUG_DRIVER 2
330 #define CPUFREQ_DEBUG_GOVERNOR 4
332 #ifdef CONFIG_CPU_FREQ_DEBUG
334 extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
335 const char *fmt, ...);
337 #else
339 #define cpufreq_debug_printk(msg...) do { } while(0)
341 #endif /* CONFIG_CPU_FREQ_DEBUG */
343 #endif /* _LINUX_CPUFREQ_H */