2 * linux/include/linux/cpufreq.h
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
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 shared_type; /* ANY or ALL affected CPUs
78 unsigned int cpu; /* cpu nr of registered CPU */
79 struct cpufreq_cpuinfo cpuinfo;/* see above */
81 unsigned int min; /* in kHz */
82 unsigned int max; /* in kHz */
83 unsigned int cur; /* in kHz, only needed if cpufreq
84 * governors are used */
85 unsigned int policy; /* see above */
86 struct cpufreq_governor *governor; /* see below */
88 struct mutex lock; /* CPU ->setpolicy or ->target may
89 only be called once a time */
91 struct work_struct update; /* if update_policy() needs to be
92 * called, but you're in IRQ context */
94 struct cpufreq_real_policy user_policy;
97 struct completion kobj_unregister;
100 #define CPUFREQ_ADJUST (0)
101 #define CPUFREQ_INCOMPATIBLE (1)
102 #define CPUFREQ_NOTIFY (2)
104 #define CPUFREQ_SHARED_TYPE_ALL (0) /* All dependent CPUs should set freq */
105 #define CPUFREQ_SHARED_TYPE_ANY (1) /* Freq can be set from any dependent CPU */
107 /******************** cpufreq transition notifiers *******************/
109 #define CPUFREQ_PRECHANGE (0)
110 #define CPUFREQ_POSTCHANGE (1)
111 #define CPUFREQ_RESUMECHANGE (8)
112 #define CPUFREQ_SUSPENDCHANGE (9)
114 struct cpufreq_freqs {
115 unsigned int cpu; /* cpu nr */
118 u8 flags; /* flags of cpufreq_driver, see below. */
123 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
129 * new = old * mult / div
131 static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
133 #if BITS_PER_LONG == 32
135 u64 result = ((u64) old) * ((u64) mult);
137 return (unsigned long) result;
139 #elif BITS_PER_LONG == 64
141 unsigned long result = old * ((u64) mult);
148 /*********************************************************************
149 * CPUFREQ GOVERNORS *
150 *********************************************************************/
152 #define CPUFREQ_GOV_START 1
153 #define CPUFREQ_GOV_STOP 2
154 #define CPUFREQ_GOV_LIMITS 3
156 struct cpufreq_governor {
157 char name[CPUFREQ_NAME_LEN];
158 int (*governor) (struct cpufreq_policy *policy,
160 struct list_head governor_list;
161 struct module *owner;
164 /* pass a target to the cpufreq driver
166 extern int cpufreq_driver_target(struct cpufreq_policy *policy,
167 unsigned int target_freq,
168 unsigned int relation);
169 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
170 unsigned int target_freq,
171 unsigned int relation);
174 /* pass an event to the cpufreq governor */
175 int cpufreq_governor(unsigned int cpu, unsigned int event);
177 int cpufreq_register_governor(struct cpufreq_governor *governor);
178 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
181 /*********************************************************************
182 * CPUFREQ DRIVER INTERFACE *
183 *********************************************************************/
185 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
186 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
190 struct cpufreq_driver {
191 struct module *owner;
192 char name[CPUFREQ_NAME_LEN];
195 /* needed by all drivers */
196 int (*init) (struct cpufreq_policy *policy);
197 int (*verify) (struct cpufreq_policy *policy);
199 /* define one out of two */
200 int (*setpolicy) (struct cpufreq_policy *policy);
201 int (*target) (struct cpufreq_policy *policy,
202 unsigned int target_freq,
203 unsigned int relation);
205 /* should be defined, if possible */
206 unsigned int (*get) (unsigned int cpu);
209 int (*exit) (struct cpufreq_policy *policy);
210 int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
211 int (*resume) (struct cpufreq_policy *policy);
212 struct freq_attr **attr;
217 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
218 * all ->init() calls failed */
219 #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
220 * "constants" aren't affected by
221 * frequency transitions */
222 #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
225 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
226 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
229 void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
232 static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
234 if (policy->min < min)
236 if (policy->max < min)
238 if (policy->min > max)
240 if (policy->max > max)
242 if (policy->min > policy->max)
243 policy->min = policy->max;
248 struct attribute attr;
249 ssize_t (*show)(struct cpufreq_policy *, char *);
250 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
254 /*********************************************************************
255 * CPUFREQ 2.6. INTERFACE *
256 *********************************************************************/
257 int cpufreq_set_policy(struct cpufreq_policy *policy);
258 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
259 int cpufreq_update_policy(unsigned int cpu);
261 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
262 unsigned int cpufreq_get(unsigned int cpu);
264 /* query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it */
265 #ifdef CONFIG_CPU_FREQ
266 unsigned int cpufreq_quick_get(unsigned int cpu);
268 static inline unsigned int cpufreq_quick_get(unsigned int cpu)
275 /*********************************************************************
276 * CPUFREQ DEFAULT GOVERNOR *
277 *********************************************************************/
280 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
281 extern struct cpufreq_governor cpufreq_gov_performance;
282 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
283 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
284 extern struct cpufreq_governor cpufreq_gov_userspace;
285 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
289 /*********************************************************************
290 * FREQUENCY TABLE HELPERS *
291 *********************************************************************/
293 #define CPUFREQ_ENTRY_INVALID ~0
294 #define CPUFREQ_TABLE_END ~1
296 struct cpufreq_frequency_table {
297 unsigned int index; /* any */
298 unsigned int frequency; /* kHz - doesn't need to be in ascending
302 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
303 struct cpufreq_frequency_table *table);
305 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
306 struct cpufreq_frequency_table *table);
308 int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
309 struct cpufreq_frequency_table *table,
310 unsigned int target_freq,
311 unsigned int relation,
312 unsigned int *index);
314 /* the following 3 funtions are for cpufreq core use only */
315 struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
316 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
317 void cpufreq_cpu_put (struct cpufreq_policy *data);
319 /* the following are really really optional */
320 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
322 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
325 void cpufreq_frequency_table_put_attr(unsigned int cpu);
328 /*********************************************************************
329 * UNIFIED DEBUG HELPERS *
330 *********************************************************************/
332 #define CPUFREQ_DEBUG_CORE 1
333 #define CPUFREQ_DEBUG_DRIVER 2
334 #define CPUFREQ_DEBUG_GOVERNOR 4
336 #ifdef CONFIG_CPU_FREQ_DEBUG
338 extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
339 const char *fmt, ...);
343 #define cpufreq_debug_printk(msg...) do { } while(0)
345 #endif /* CONFIG_CPU_FREQ_DEBUG */
347 #endif /* _LINUX_CPUFREQ_H */