[SCSI] arcmsr: irq handler fixes, cleanups, micro-opts
[linux-2.6/zen-sources.git] / include / linux / cpufreq.h
blob963051a967d6c22510840473e4913cbe71cf03d0
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/notifier.h>
19 #include <linux/threads.h>
20 #include <linux/device.h>
21 #include <linux/kobject.h>
22 #include <linux/sysfs.h>
23 #include <linux/completion.h>
24 #include <linux/workqueue.h>
25 #include <linux/cpumask.h>
26 #include <asm/div64.h>
28 #define CPUFREQ_NAME_LEN 16
31 /*********************************************************************
32 * CPUFREQ NOTIFIER INTERFACE *
33 *********************************************************************/
35 #ifdef CONFIG_CPU_FREQ
36 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
37 #else
38 static inline int cpufreq_register_notifier(struct notifier_block *nb,
39 unsigned int list)
41 return 0;
43 #endif
44 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
46 #define CPUFREQ_TRANSITION_NOTIFIER (0)
47 #define CPUFREQ_POLICY_NOTIFIER (1)
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:
55 #define CPUFREQ_POLICY_POWERSAVE (1)
56 #define CPUFREQ_POLICY_PERFORMANCE (2)
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.
61 * Maximum transition latency is in nanoseconds - if it's unknown,
62 * CPUFREQ_ETERNAL shall be used.
65 struct cpufreq_governor;
67 #define CPUFREQ_ETERNAL (-1)
68 struct cpufreq_cpuinfo {
69 unsigned int max_freq;
70 unsigned int min_freq;
71 unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
74 struct cpufreq_real_policy {
75 unsigned int min; /* in kHz */
76 unsigned int max; /* in kHz */
77 unsigned int policy; /* see above */
78 struct cpufreq_governor *governor; /* see below */
81 struct cpufreq_policy {
82 cpumask_t cpus; /* affected CPUs */
83 unsigned int shared_type; /* ANY or ALL affected CPUs
84 should set cpufreq */
85 unsigned int cpu; /* cpu nr of registered CPU */
86 struct cpufreq_cpuinfo cpuinfo;/* see above */
88 unsigned int min; /* in kHz */
89 unsigned int max; /* in kHz */
90 unsigned int cur; /* in kHz, only needed if cpufreq
91 * governors are used */
92 unsigned int policy; /* see above */
93 struct cpufreq_governor *governor; /* see below */
95 struct work_struct update; /* if update_policy() needs to be
96 * called, but you're in IRQ context */
98 struct cpufreq_real_policy user_policy;
100 struct kobject kobj;
101 struct completion kobj_unregister;
104 #define CPUFREQ_ADJUST (0)
105 #define CPUFREQ_INCOMPATIBLE (1)
106 #define CPUFREQ_NOTIFY (2)
108 #define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
109 #define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
110 #define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
111 #define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
113 /******************** cpufreq transition notifiers *******************/
115 #define CPUFREQ_PRECHANGE (0)
116 #define CPUFREQ_POSTCHANGE (1)
117 #define CPUFREQ_RESUMECHANGE (8)
118 #define CPUFREQ_SUSPENDCHANGE (9)
120 struct cpufreq_freqs {
121 unsigned int cpu; /* cpu nr */
122 unsigned int old;
123 unsigned int new;
124 u8 flags; /* flags of cpufreq_driver, see below. */
129 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
130 * @old: old value
131 * @div: divisor
132 * @mult: multiplier
135 * new = old * mult / div
137 static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
139 #if BITS_PER_LONG == 32
141 u64 result = ((u64) old) * ((u64) mult);
142 do_div(result, div);
143 return (unsigned long) result;
145 #elif BITS_PER_LONG == 64
147 unsigned long result = old * ((u64) mult);
148 result /= div;
149 return result;
151 #endif
154 /*********************************************************************
155 * CPUFREQ GOVERNORS *
156 *********************************************************************/
158 #define CPUFREQ_GOV_START 1
159 #define CPUFREQ_GOV_STOP 2
160 #define CPUFREQ_GOV_LIMITS 3
162 struct cpufreq_governor {
163 char name[CPUFREQ_NAME_LEN];
164 int (*governor) (struct cpufreq_policy *policy,
165 unsigned int event);
166 struct list_head governor_list;
167 struct module *owner;
170 /* pass a target to the cpufreq driver
172 extern int cpufreq_driver_target(struct cpufreq_policy *policy,
173 unsigned int target_freq,
174 unsigned int relation);
175 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
176 unsigned int target_freq,
177 unsigned int relation);
180 extern int __cpufreq_driver_getavg(struct cpufreq_policy *policy);
182 int cpufreq_register_governor(struct cpufreq_governor *governor);
183 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
185 int lock_policy_rwsem_read(int cpu);
186 int lock_policy_rwsem_write(int cpu);
187 void unlock_policy_rwsem_read(int cpu);
188 void unlock_policy_rwsem_write(int cpu);
191 /*********************************************************************
192 * CPUFREQ DRIVER INTERFACE *
193 *********************************************************************/
195 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
196 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
198 struct freq_attr;
200 struct cpufreq_driver {
201 struct module *owner;
202 char name[CPUFREQ_NAME_LEN];
203 u8 flags;
205 /* needed by all drivers */
206 int (*init) (struct cpufreq_policy *policy);
207 int (*verify) (struct cpufreq_policy *policy);
209 /* define one out of two */
210 int (*setpolicy) (struct cpufreq_policy *policy);
211 int (*target) (struct cpufreq_policy *policy,
212 unsigned int target_freq,
213 unsigned int relation);
215 /* should be defined, if possible */
216 unsigned int (*get) (unsigned int cpu);
218 /* optional */
219 unsigned int (*getavg) (unsigned int cpu);
220 int (*exit) (struct cpufreq_policy *policy);
221 int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
222 int (*resume) (struct cpufreq_policy *policy);
223 struct freq_attr **attr;
226 /* flags */
228 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
229 * all ->init() calls failed */
230 #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
231 * "constants" aren't affected by
232 * frequency transitions */
233 #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
234 * mismatches */
236 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
237 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
240 void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
243 static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
245 if (policy->min < min)
246 policy->min = min;
247 if (policy->max < min)
248 policy->max = min;
249 if (policy->min > max)
250 policy->min = max;
251 if (policy->max > max)
252 policy->max = max;
253 if (policy->min > policy->max)
254 policy->min = policy->max;
255 return;
258 struct freq_attr {
259 struct attribute attr;
260 ssize_t (*show)(struct cpufreq_policy *, char *);
261 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
265 /*********************************************************************
266 * CPUFREQ 2.6. INTERFACE *
267 *********************************************************************/
268 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
269 int cpufreq_update_policy(unsigned int cpu);
273 * query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it
275 #ifdef CONFIG_CPU_FREQ
276 unsigned int cpufreq_quick_get(unsigned int cpu);
277 unsigned int cpufreq_get(unsigned int cpu);
278 #else
279 static inline unsigned int cpufreq_quick_get(unsigned int cpu)
281 return 0;
283 static inline unsigned int cpufreq_get(unsigned int cpu)
285 return 0;
287 #endif
290 /*********************************************************************
291 * CPUFREQ DEFAULT GOVERNOR *
292 *********************************************************************/
295 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
296 extern struct cpufreq_governor cpufreq_gov_performance;
297 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
298 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
299 extern struct cpufreq_governor cpufreq_gov_userspace;
300 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
301 #endif
304 /*********************************************************************
305 * FREQUENCY TABLE HELPERS *
306 *********************************************************************/
308 #define CPUFREQ_ENTRY_INVALID ~0
309 #define CPUFREQ_TABLE_END ~1
311 struct cpufreq_frequency_table {
312 unsigned int index; /* any */
313 unsigned int frequency; /* kHz - doesn't need to be in ascending
314 * order */
317 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
318 struct cpufreq_frequency_table *table);
320 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
321 struct cpufreq_frequency_table *table);
323 int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
324 struct cpufreq_frequency_table *table,
325 unsigned int target_freq,
326 unsigned int relation,
327 unsigned int *index);
329 /* the following 3 funtions are for cpufreq core use only */
330 struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
331 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
332 void cpufreq_cpu_put (struct cpufreq_policy *data);
334 /* the following are really really optional */
335 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
337 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
338 unsigned int cpu);
340 void cpufreq_frequency_table_put_attr(unsigned int cpu);
343 /*********************************************************************
344 * UNIFIED DEBUG HELPERS *
345 *********************************************************************/
347 #define CPUFREQ_DEBUG_CORE 1
348 #define CPUFREQ_DEBUG_DRIVER 2
349 #define CPUFREQ_DEBUG_GOVERNOR 4
351 #ifdef CONFIG_CPU_FREQ_DEBUG
353 extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
354 const char *fmt, ...);
356 #else
358 #define cpufreq_debug_printk(msg...) do { } while(0)
360 #endif /* CONFIG_CPU_FREQ_DEBUG */
362 #endif /* _LINUX_CPUFREQ_H */