aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/cpufreq.h373
1 files changed, 177 insertions, 196 deletions
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 97627bbbca82..0d3b0266bc98 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -17,60 +17,30 @@
17#include <linux/notifier.h> 17#include <linux/notifier.h>
18#include <linux/sysfs.h> 18#include <linux/sysfs.h>
19 19
20#define CPUFREQ_NAME_LEN 16
21/* Print length for names. Extra 1 space for accomodating '\n' in prints */
22#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
23
24/********************************************************************* 20/*********************************************************************
25 * CPUFREQ NOTIFIER INTERFACE * 21 * CPUFREQ INTERFACE *
26 *********************************************************************/ 22 *********************************************************************/
27 23/*
28#define CPUFREQ_TRANSITION_NOTIFIER (0) 24 * Frequency values here are CPU kHz
29#define CPUFREQ_POLICY_NOTIFIER (1) 25 *
30
31#ifdef CONFIG_CPU_FREQ
32int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
33int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
34extern void disable_cpufreq(void);
35#else /* CONFIG_CPU_FREQ */
36static inline int cpufreq_register_notifier(struct notifier_block *nb,
37 unsigned int list)
38{
39 return 0;
40}
41static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
42 unsigned int list)
43{
44 return 0;
45}
46static inline void disable_cpufreq(void) { }
47#endif /* CONFIG_CPU_FREQ */
48
49/* if (cpufreq_driver->target) exists, the ->governor decides what frequency
50 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
51 * two generic policies are available:
52 */
53
54#define CPUFREQ_POLICY_POWERSAVE (1)
55#define CPUFREQ_POLICY_PERFORMANCE (2)
56
57/* Frequency values here are CPU kHz so that hardware which doesn't run
58 * with some frequencies can complain without having to guess what per
59 * cent / per mille means.
60 * Maximum transition latency is in nanoseconds - if it's unknown, 26 * Maximum transition latency is in nanoseconds - if it's unknown,
61 * CPUFREQ_ETERNAL shall be used. 27 * CPUFREQ_ETERNAL shall be used.
62 */ 28 */
63 29
30#define CPUFREQ_ETERNAL (-1)
31#define CPUFREQ_NAME_LEN 16
32/* Print length for names. Extra 1 space for accomodating '\n' in prints */
33#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
34
64struct cpufreq_governor; 35struct cpufreq_governor;
65 36
66/* /sys/devices/system/cpu/cpufreq: entry point for global variables */ 37struct cpufreq_freqs {
67extern struct kobject *cpufreq_global_kobject; 38 unsigned int cpu; /* cpu nr */
68int cpufreq_get_global_kobject(void); 39 unsigned int old;
69void cpufreq_put_global_kobject(void); 40 unsigned int new;
70int cpufreq_sysfs_create_file(const struct attribute *attr); 41 u8 flags; /* flags of cpufreq_driver, see below. */
71void cpufreq_sysfs_remove_file(const struct attribute *attr); 42};
72 43
73#define CPUFREQ_ETERNAL (-1)
74struct cpufreq_cpuinfo { 44struct cpufreq_cpuinfo {
75 unsigned int max_freq; 45 unsigned int max_freq;
76 unsigned int min_freq; 46 unsigned int min_freq;
@@ -117,111 +87,95 @@ struct cpufreq_policy {
117 int transition_ongoing; /* Tracks transition status */ 87 int transition_ongoing; /* Tracks transition status */
118}; 88};
119 89
120#define CPUFREQ_ADJUST (0)
121#define CPUFREQ_INCOMPATIBLE (1)
122#define CPUFREQ_NOTIFY (2)
123#define CPUFREQ_START (3)
124#define CPUFREQ_UPDATE_POLICY_CPU (4)
125
126/* Only for ACPI */ 90/* Only for ACPI */
127#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */ 91#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
128#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */ 92#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
129#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */ 93#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
130#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/ 94#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
131 95
96struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
97void cpufreq_cpu_put(struct cpufreq_policy *data);
98
132static inline bool policy_is_shared(struct cpufreq_policy *policy) 99static inline bool policy_is_shared(struct cpufreq_policy *policy)
133{ 100{
134 return cpumask_weight(policy->cpus) > 1; 101 return cpumask_weight(policy->cpus) > 1;
135} 102}
136 103
137/******************** cpufreq transition notifiers *******************/ 104/* /sys/devices/system/cpu/cpufreq: entry point for global variables */
138 105extern struct kobject *cpufreq_global_kobject;
139#define CPUFREQ_PRECHANGE (0) 106int cpufreq_get_global_kobject(void);
140#define CPUFREQ_POSTCHANGE (1) 107void cpufreq_put_global_kobject(void);
141#define CPUFREQ_RESUMECHANGE (8) 108int cpufreq_sysfs_create_file(const struct attribute *attr);
142#define CPUFREQ_SUSPENDCHANGE (9) 109void cpufreq_sysfs_remove_file(const struct attribute *attr);
143 110
144struct cpufreq_freqs { 111#ifdef CONFIG_CPU_FREQ
145 unsigned int cpu; /* cpu nr */ 112unsigned int cpufreq_get(unsigned int cpu);
146 unsigned int old; 113unsigned int cpufreq_quick_get(unsigned int cpu);
147 unsigned int new; 114unsigned int cpufreq_quick_get_max(unsigned int cpu);
148 u8 flags; /* flags of cpufreq_driver, see below. */ 115void disable_cpufreq(void);
149};
150 116
151/** 117u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
152 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch 118int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
153 * safe) 119int cpufreq_update_policy(unsigned int cpu);
154 * @old: old value 120bool have_governor_per_policy(void);
155 * @div: divisor 121struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
156 * @mult: multiplier 122#else
157 * 123static inline unsigned int cpufreq_get(unsigned int cpu)
158 *
159 * new = old * mult / div
160 */
161static inline unsigned long cpufreq_scale(unsigned long old, u_int div,
162 u_int mult)
163{ 124{
164#if BITS_PER_LONG == 32 125 return 0;
165 126}
166 u64 result = ((u64) old) * ((u64) mult); 127static inline unsigned int cpufreq_quick_get(unsigned int cpu)
167 do_div(result, div); 128{
168 return (unsigned long) result; 129 return 0;
169 130}
170#elif BITS_PER_LONG == 64 131static inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
171 132{
172 unsigned long result = old * ((u64) mult); 133 return 0;
173 result /= div; 134}
174 return result; 135static inline void disable_cpufreq(void) { }
175
176#endif 136#endif
177};
178 137
179/********************************************************************* 138/*********************************************************************
180 * CPUFREQ GOVERNORS * 139 * CPUFREQ DRIVER INTERFACE *
181 *********************************************************************/ 140 *********************************************************************/
182 141
183#define CPUFREQ_GOV_START 1 142#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
184#define CPUFREQ_GOV_STOP 2 143#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
185#define CPUFREQ_GOV_LIMITS 3
186#define CPUFREQ_GOV_POLICY_INIT 4
187#define CPUFREQ_GOV_POLICY_EXIT 5
188 144
189struct cpufreq_governor { 145struct freq_attr {
190 char name[CPUFREQ_NAME_LEN]; 146 struct attribute attr;
191 int initialized; 147 ssize_t (*show)(struct cpufreq_policy *, char *);
192 int (*governor) (struct cpufreq_policy *policy, 148 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
193 unsigned int event);
194 ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
195 char *buf);
196 int (*store_setspeed) (struct cpufreq_policy *policy,
197 unsigned int freq);
198 unsigned int max_transition_latency; /* HW must be able to switch to
199 next freq faster than this value in nano secs or we
200 will fallback to performance governor */
201 struct list_head governor_list;
202 struct module *owner;
203}; 149};
204 150
205/* 151#define cpufreq_freq_attr_ro(_name) \
206 * Pass a target to the cpufreq driver. 152static struct freq_attr _name = \
207 */ 153__ATTR(_name, 0444, show_##_name, NULL)
208extern int cpufreq_driver_target(struct cpufreq_policy *policy,
209 unsigned int target_freq,
210 unsigned int relation);
211extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
212 unsigned int target_freq,
213 unsigned int relation);
214int cpufreq_register_governor(struct cpufreq_governor *governor);
215void cpufreq_unregister_governor(struct cpufreq_governor *governor);
216 154
217/********************************************************************* 155#define cpufreq_freq_attr_ro_perm(_name, _perm) \
218 * CPUFREQ DRIVER INTERFACE * 156static struct freq_attr _name = \
219 *********************************************************************/ 157__ATTR(_name, _perm, show_##_name, NULL)
220 158
221#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */ 159#define cpufreq_freq_attr_rw(_name) \
222#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */ 160static struct freq_attr _name = \
161__ATTR(_name, 0644, show_##_name, store_##_name)
162
163struct global_attr {
164 struct attribute attr;
165 ssize_t (*show)(struct kobject *kobj,
166 struct attribute *attr, char *buf);
167 ssize_t (*store)(struct kobject *a, struct attribute *b,
168 const char *c, size_t count);
169};
170
171#define define_one_global_ro(_name) \
172static struct global_attr _name = \
173__ATTR(_name, 0444, show_##_name, NULL)
174
175#define define_one_global_rw(_name) \
176static struct global_attr _name = \
177__ATTR(_name, 0644, show_##_name, store_##_name)
223 178
224struct freq_attr;
225 179
226struct cpufreq_driver { 180struct cpufreq_driver {
227 struct module *owner; 181 struct module *owner;
@@ -258,7 +212,6 @@ struct cpufreq_driver {
258}; 212};
259 213
260/* flags */ 214/* flags */
261
262#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if 215#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
263 * all ->init() calls failed */ 216 * all ->init() calls failed */
264#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel 217#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
@@ -270,8 +223,7 @@ struct cpufreq_driver {
270int cpufreq_register_driver(struct cpufreq_driver *driver_data); 223int cpufreq_register_driver(struct cpufreq_driver *driver_data);
271int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); 224int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
272 225
273void cpufreq_notify_transition(struct cpufreq_policy *policy, 226const char *cpufreq_get_current_driver(void);
274 struct cpufreq_freqs *freqs, unsigned int state);
275 227
276static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, 228static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
277 unsigned int min, unsigned int max) 229 unsigned int min, unsigned int max)
@@ -289,87 +241,118 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
289 return; 241 return;
290} 242}
291 243
292struct freq_attr { 244/*********************************************************************
293 struct attribute attr; 245 * CPUFREQ NOTIFIER INTERFACE *
294 ssize_t (*show)(struct cpufreq_policy *, char *); 246 *********************************************************************/
295 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
296};
297
298#define cpufreq_freq_attr_ro(_name) \
299static struct freq_attr _name = \
300__ATTR(_name, 0444, show_##_name, NULL)
301
302#define cpufreq_freq_attr_ro_perm(_name, _perm) \
303static struct freq_attr _name = \
304__ATTR(_name, _perm, show_##_name, NULL)
305
306#define cpufreq_freq_attr_rw(_name) \
307static struct freq_attr _name = \
308__ATTR(_name, 0644, show_##_name, store_##_name)
309 247
310struct global_attr { 248#define CPUFREQ_TRANSITION_NOTIFIER (0)
311 struct attribute attr; 249#define CPUFREQ_POLICY_NOTIFIER (1)
312 ssize_t (*show)(struct kobject *kobj,
313 struct attribute *attr, char *buf);
314 ssize_t (*store)(struct kobject *a, struct attribute *b,
315 const char *c, size_t count);
316};
317 250
318#define define_one_global_ro(_name) \ 251/* Transition notifiers */
319static struct global_attr _name = \ 252#define CPUFREQ_PRECHANGE (0)
320__ATTR(_name, 0444, show_##_name, NULL) 253#define CPUFREQ_POSTCHANGE (1)
254#define CPUFREQ_RESUMECHANGE (8)
255#define CPUFREQ_SUSPENDCHANGE (9)
321 256
322#define define_one_global_rw(_name) \ 257/* Policy Notifiers */
323static struct global_attr _name = \ 258#define CPUFREQ_ADJUST (0)
324__ATTR(_name, 0644, show_##_name, store_##_name) 259#define CPUFREQ_INCOMPATIBLE (1)
260#define CPUFREQ_NOTIFY (2)
261#define CPUFREQ_START (3)
262#define CPUFREQ_UPDATE_POLICY_CPU (4)
325 263
326struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); 264#ifdef CONFIG_CPU_FREQ
327void cpufreq_cpu_put(struct cpufreq_policy *data); 265int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
328const char *cpufreq_get_current_driver(void); 266int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
329 267
330/********************************************************************* 268void cpufreq_notify_transition(struct cpufreq_policy *policy,
331 * CPUFREQ 2.6. INTERFACE * 269 struct cpufreq_freqs *freqs, unsigned int state);
332 *********************************************************************/
333u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
334int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
335int cpufreq_update_policy(unsigned int cpu);
336bool have_governor_per_policy(void);
337struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
338 270
339#ifdef CONFIG_CPU_FREQ 271#else /* CONFIG_CPU_FREQ */
340/* 272static inline int cpufreq_register_notifier(struct notifier_block *nb,
341 * query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it 273 unsigned int list)
342 */
343unsigned int cpufreq_get(unsigned int cpu);
344#else
345static inline unsigned int cpufreq_get(unsigned int cpu)
346{ 274{
347 return 0; 275 return 0;
348} 276}
349#endif 277static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
350 278 unsigned int list)
351/*
352 * query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it
353 */
354#ifdef CONFIG_CPU_FREQ
355unsigned int cpufreq_quick_get(unsigned int cpu);
356unsigned int cpufreq_quick_get_max(unsigned int cpu);
357#else
358static inline unsigned int cpufreq_quick_get(unsigned int cpu)
359{ 279{
360 return 0; 280 return 0;
361} 281}
362static inline unsigned int cpufreq_quick_get_max(unsigned int cpu) 282#endif /* !CONFIG_CPU_FREQ */
283
284/**
285 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch
286 * safe)
287 * @old: old value
288 * @div: divisor
289 * @mult: multiplier
290 *
291 *
292 * new = old * mult / div
293 */
294static inline unsigned long cpufreq_scale(unsigned long old, u_int div,
295 u_int mult)
363{ 296{
364 return 0; 297#if BITS_PER_LONG == 32
365} 298 u64 result = ((u64) old) * ((u64) mult);
299 do_div(result, div);
300 return (unsigned long) result;
301
302#elif BITS_PER_LONG == 64
303 unsigned long result = old * ((u64) mult);
304 result /= div;
305 return result;
366#endif 306#endif
307}
367 308
368/********************************************************************* 309/*********************************************************************
369 * CPUFREQ DEFAULT GOVERNOR * 310 * CPUFREQ GOVERNORS *
370 *********************************************************************/ 311 *********************************************************************/
371 312
372/* 313/*
314 * If (cpufreq_driver->target) exists, the ->governor decides what frequency
315 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
316 * two generic policies are available:
317 */
318#define CPUFREQ_POLICY_POWERSAVE (1)
319#define CPUFREQ_POLICY_PERFORMANCE (2)
320
321/* Governor Events */
322#define CPUFREQ_GOV_START 1
323#define CPUFREQ_GOV_STOP 2
324#define CPUFREQ_GOV_LIMITS 3
325#define CPUFREQ_GOV_POLICY_INIT 4
326#define CPUFREQ_GOV_POLICY_EXIT 5
327
328struct cpufreq_governor {
329 char name[CPUFREQ_NAME_LEN];
330 int initialized;
331 int (*governor) (struct cpufreq_policy *policy,
332 unsigned int event);
333 ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
334 char *buf);
335 int (*store_setspeed) (struct cpufreq_policy *policy,
336 unsigned int freq);
337 unsigned int max_transition_latency; /* HW must be able to switch to
338 next freq faster than this value in nano secs or we
339 will fallback to performance governor */
340 struct list_head governor_list;
341 struct module *owner;
342};
343
344/* Pass a target to the cpufreq driver */
345int cpufreq_driver_target(struct cpufreq_policy *policy,
346 unsigned int target_freq,
347 unsigned int relation);
348int __cpufreq_driver_target(struct cpufreq_policy *policy,
349 unsigned int target_freq,
350 unsigned int relation);
351int cpufreq_register_governor(struct cpufreq_governor *governor);
352void cpufreq_unregister_governor(struct cpufreq_governor *governor);
353
354/* CPUFREQ DEFAULT GOVERNOR */
355/*
373 * Performance governor is fallback governor if any other gov failed to auto 356 * Performance governor is fallback governor if any other gov failed to auto
374 * load due latency restrictions 357 * load due latency restrictions
375 */ 358 */
@@ -417,18 +400,16 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
417 unsigned int relation, 400 unsigned int relation,
418 unsigned int *index); 401 unsigned int *index);
419 402
420/* the following 3 funtions are for cpufreq core use only */ 403void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy);
404ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
405
406/* the following funtion is for cpufreq core use only */
421struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu); 407struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
422 408
423/* the following are really really optional */ 409/* the following are really really optional */
424extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; 410extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
425
426void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, 411void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
427 unsigned int cpu); 412 unsigned int cpu);
428void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy);
429
430void cpufreq_frequency_table_put_attr(unsigned int cpu); 413void cpufreq_frequency_table_put_attr(unsigned int cpu);
431 414
432ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
433
434#endif /* _LINUX_CPUFREQ_H */ 415#endif /* _LINUX_CPUFREQ_H */