diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/cpufreq.h |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'include/linux/cpufreq.h')
-rw-r--r-- | include/linux/cpufreq.h | 328 |
1 files changed, 328 insertions, 0 deletions
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h new file mode 100644 index 000000000000..910eca35583d --- /dev/null +++ b/include/linux/cpufreq.h | |||
@@ -0,0 +1,328 @@ | |||
1 | /* | ||
2 | * linux/include/linux/cpufreq.h | ||
3 | * | ||
4 | * Copyright (C) 2001 Russell King | ||
5 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
6 | * | ||
7 | * | ||
8 | * $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $ | ||
9 | * | ||
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. | ||
13 | */ | ||
14 | #ifndef _LINUX_CPUFREQ_H | ||
15 | #define _LINUX_CPUFREQ_H | ||
16 | |||
17 | #include <linux/config.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 | |||
27 | #define CPUFREQ_NAME_LEN 16 | ||
28 | |||
29 | |||
30 | /********************************************************************* | ||
31 | * CPUFREQ NOTIFIER INTERFACE * | ||
32 | *********************************************************************/ | ||
33 | |||
34 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list); | ||
35 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list); | ||
36 | |||
37 | #define CPUFREQ_TRANSITION_NOTIFIER (0) | ||
38 | #define CPUFREQ_POLICY_NOTIFIER (1) | ||
39 | |||
40 | |||
41 | /* if (cpufreq_driver->target) exists, the ->governor decides what frequency | ||
42 | * within the limits is used. If (cpufreq_driver->setpolicy> exists, these | ||
43 | * two generic policies are available: | ||
44 | */ | ||
45 | |||
46 | #define CPUFREQ_POLICY_POWERSAVE (1) | ||
47 | #define CPUFREQ_POLICY_PERFORMANCE (2) | ||
48 | |||
49 | /* Frequency values here are CPU kHz so that hardware which doesn't run | ||
50 | * with some frequencies can complain without having to guess what per | ||
51 | * cent / per mille means. | ||
52 | * Maximum transition latency is in microseconds - if it's unknown, | ||
53 | * CPUFREQ_ETERNAL shall be used. | ||
54 | */ | ||
55 | |||
56 | struct cpufreq_governor; | ||
57 | |||
58 | #define CPUFREQ_ETERNAL (-1) | ||
59 | struct cpufreq_cpuinfo { | ||
60 | unsigned int max_freq; | ||
61 | unsigned int min_freq; | ||
62 | unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */ | ||
63 | }; | ||
64 | |||
65 | struct cpufreq_real_policy { | ||
66 | unsigned int min; /* in kHz */ | ||
67 | unsigned int max; /* in kHz */ | ||
68 | unsigned int policy; /* see above */ | ||
69 | struct cpufreq_governor *governor; /* see below */ | ||
70 | }; | ||
71 | |||
72 | struct cpufreq_policy { | ||
73 | cpumask_t cpus; /* affected CPUs */ | ||
74 | unsigned int cpu; /* cpu nr of registered CPU */ | ||
75 | struct cpufreq_cpuinfo cpuinfo;/* see above */ | ||
76 | |||
77 | unsigned int min; /* in kHz */ | ||
78 | unsigned int max; /* in kHz */ | ||
79 | unsigned int cur; /* in kHz, only needed if cpufreq | ||
80 | * governors are used */ | ||
81 | unsigned int policy; /* see above */ | ||
82 | struct cpufreq_governor *governor; /* see below */ | ||
83 | |||
84 | struct semaphore lock; /* CPU ->setpolicy or ->target may | ||
85 | only be called once a time */ | ||
86 | |||
87 | struct work_struct update; /* if update_policy() needs to be | ||
88 | * called, but you're in IRQ context */ | ||
89 | |||
90 | struct cpufreq_real_policy user_policy; | ||
91 | |||
92 | struct kobject kobj; | ||
93 | struct completion kobj_unregister; | ||
94 | }; | ||
95 | |||
96 | #define CPUFREQ_ADJUST (0) | ||
97 | #define CPUFREQ_INCOMPATIBLE (1) | ||
98 | #define CPUFREQ_NOTIFY (2) | ||
99 | |||
100 | |||
101 | /******************** cpufreq transition notifiers *******************/ | ||
102 | |||
103 | #define CPUFREQ_PRECHANGE (0) | ||
104 | #define CPUFREQ_POSTCHANGE (1) | ||
105 | #define CPUFREQ_RESUMECHANGE (8) | ||
106 | |||
107 | struct cpufreq_freqs { | ||
108 | unsigned int cpu; /* cpu nr */ | ||
109 | unsigned int old; | ||
110 | unsigned int new; | ||
111 | u8 flags; /* flags of cpufreq_driver, see below. */ | ||
112 | }; | ||
113 | |||
114 | |||
115 | /** | ||
116 | * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe) | ||
117 | * @old: old value | ||
118 | * @div: divisor | ||
119 | * @mult: multiplier | ||
120 | * | ||
121 | * | ||
122 | * new = old * mult / div | ||
123 | */ | ||
124 | static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult) | ||
125 | { | ||
126 | #if BITS_PER_LONG == 32 | ||
127 | |||
128 | u64 result = ((u64) old) * ((u64) mult); | ||
129 | do_div(result, div); | ||
130 | return (unsigned long) result; | ||
131 | |||
132 | #elif BITS_PER_LONG == 64 | ||
133 | |||
134 | unsigned long result = old * ((u64) mult); | ||
135 | result /= div; | ||
136 | return result; | ||
137 | |||
138 | #endif | ||
139 | }; | ||
140 | |||
141 | /********************************************************************* | ||
142 | * CPUFREQ GOVERNORS * | ||
143 | *********************************************************************/ | ||
144 | |||
145 | #define CPUFREQ_GOV_START 1 | ||
146 | #define CPUFREQ_GOV_STOP 2 | ||
147 | #define CPUFREQ_GOV_LIMITS 3 | ||
148 | |||
149 | struct cpufreq_governor { | ||
150 | char name[CPUFREQ_NAME_LEN]; | ||
151 | int (*governor) (struct cpufreq_policy *policy, | ||
152 | unsigned int event); | ||
153 | struct list_head governor_list; | ||
154 | struct module *owner; | ||
155 | }; | ||
156 | |||
157 | /* pass a target to the cpufreq driver | ||
158 | */ | ||
159 | extern int cpufreq_driver_target(struct cpufreq_policy *policy, | ||
160 | unsigned int target_freq, | ||
161 | unsigned int relation); | ||
162 | extern int __cpufreq_driver_target(struct cpufreq_policy *policy, | ||
163 | unsigned int target_freq, | ||
164 | unsigned int relation); | ||
165 | |||
166 | |||
167 | /* pass an event to the cpufreq governor */ | ||
168 | int cpufreq_governor(unsigned int cpu, unsigned int event); | ||
169 | |||
170 | int cpufreq_register_governor(struct cpufreq_governor *governor); | ||
171 | void cpufreq_unregister_governor(struct cpufreq_governor *governor); | ||
172 | |||
173 | |||
174 | /********************************************************************* | ||
175 | * CPUFREQ DRIVER INTERFACE * | ||
176 | *********************************************************************/ | ||
177 | |||
178 | #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */ | ||
179 | #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */ | ||
180 | |||
181 | struct freq_attr; | ||
182 | |||
183 | struct cpufreq_driver { | ||
184 | struct module *owner; | ||
185 | char name[CPUFREQ_NAME_LEN]; | ||
186 | u8 flags; | ||
187 | |||
188 | /* needed by all drivers */ | ||
189 | int (*init) (struct cpufreq_policy *policy); | ||
190 | int (*verify) (struct cpufreq_policy *policy); | ||
191 | |||
192 | /* define one out of two */ | ||
193 | int (*setpolicy) (struct cpufreq_policy *policy); | ||
194 | int (*target) (struct cpufreq_policy *policy, | ||
195 | unsigned int target_freq, | ||
196 | unsigned int relation); | ||
197 | |||
198 | /* should be defined, if possible */ | ||
199 | unsigned int (*get) (unsigned int cpu); | ||
200 | |||
201 | /* optional */ | ||
202 | int (*exit) (struct cpufreq_policy *policy); | ||
203 | int (*resume) (struct cpufreq_policy *policy); | ||
204 | struct freq_attr **attr; | ||
205 | }; | ||
206 | |||
207 | /* flags */ | ||
208 | |||
209 | #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if | ||
210 | * all ->init() calls failed */ | ||
211 | #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel | ||
212 | * "constants" aren't affected by | ||
213 | * frequency transitions */ | ||
214 | |||
215 | |||
216 | int cpufreq_register_driver(struct cpufreq_driver *driver_data); | ||
217 | int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); | ||
218 | |||
219 | |||
220 | void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state); | ||
221 | |||
222 | |||
223 | static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max) | ||
224 | { | ||
225 | if (policy->min < min) | ||
226 | policy->min = min; | ||
227 | if (policy->max < min) | ||
228 | policy->max = min; | ||
229 | if (policy->min > max) | ||
230 | policy->min = max; | ||
231 | if (policy->max > max) | ||
232 | policy->max = max; | ||
233 | if (policy->min > policy->max) | ||
234 | policy->min = policy->max; | ||
235 | return; | ||
236 | } | ||
237 | |||
238 | struct freq_attr { | ||
239 | struct attribute attr; | ||
240 | ssize_t (*show)(struct cpufreq_policy *, char *); | ||
241 | ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count); | ||
242 | }; | ||
243 | |||
244 | |||
245 | /********************************************************************* | ||
246 | * CPUFREQ 2.6. INTERFACE * | ||
247 | *********************************************************************/ | ||
248 | int cpufreq_set_policy(struct cpufreq_policy *policy); | ||
249 | int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu); | ||
250 | int cpufreq_update_policy(unsigned int cpu); | ||
251 | |||
252 | /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */ | ||
253 | unsigned int cpufreq_get(unsigned int cpu); | ||
254 | |||
255 | |||
256 | /********************************************************************* | ||
257 | * CPUFREQ DEFAULT GOVERNOR * | ||
258 | *********************************************************************/ | ||
259 | |||
260 | |||
261 | #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE | ||
262 | extern struct cpufreq_governor cpufreq_gov_performance; | ||
263 | #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance | ||
264 | #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE) | ||
265 | extern struct cpufreq_governor cpufreq_gov_userspace; | ||
266 | #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace | ||
267 | #endif | ||
268 | |||
269 | |||
270 | /********************************************************************* | ||
271 | * FREQUENCY TABLE HELPERS * | ||
272 | *********************************************************************/ | ||
273 | |||
274 | #define CPUFREQ_ENTRY_INVALID ~0 | ||
275 | #define CPUFREQ_TABLE_END ~1 | ||
276 | |||
277 | struct cpufreq_frequency_table { | ||
278 | unsigned int index; /* any */ | ||
279 | unsigned int frequency; /* kHz - doesn't need to be in ascending | ||
280 | * order */ | ||
281 | }; | ||
282 | |||
283 | int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, | ||
284 | struct cpufreq_frequency_table *table); | ||
285 | |||
286 | int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, | ||
287 | struct cpufreq_frequency_table *table); | ||
288 | |||
289 | int cpufreq_frequency_table_target(struct cpufreq_policy *policy, | ||
290 | struct cpufreq_frequency_table *table, | ||
291 | unsigned int target_freq, | ||
292 | unsigned int relation, | ||
293 | unsigned int *index); | ||
294 | |||
295 | /* the following 3 funtions are for cpufreq core use only */ | ||
296 | struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu); | ||
297 | struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); | ||
298 | void cpufreq_cpu_put (struct cpufreq_policy *data); | ||
299 | |||
300 | /* the following are really really optional */ | ||
301 | extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; | ||
302 | |||
303 | void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, | ||
304 | unsigned int cpu); | ||
305 | |||
306 | void cpufreq_frequency_table_put_attr(unsigned int cpu); | ||
307 | |||
308 | |||
309 | /********************************************************************* | ||
310 | * UNIFIED DEBUG HELPERS * | ||
311 | *********************************************************************/ | ||
312 | |||
313 | #define CPUFREQ_DEBUG_CORE 1 | ||
314 | #define CPUFREQ_DEBUG_DRIVER 2 | ||
315 | #define CPUFREQ_DEBUG_GOVERNOR 4 | ||
316 | |||
317 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
318 | |||
319 | extern void cpufreq_debug_printk(unsigned int type, const char *prefix, | ||
320 | const char *fmt, ...); | ||
321 | |||
322 | #else | ||
323 | |||
324 | #define cpufreq_debug_printk(msg...) do { } while(0) | ||
325 | |||
326 | #endif /* CONFIG_CPU_FREQ_DEBUG */ | ||
327 | |||
328 | #endif /* _LINUX_CPUFREQ_H */ | ||