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/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>
26 #define CPUFREQ_NAME_LEN 16
29 /*********************************************************************
30 * CPUFREQ NOTIFIER INTERFACE *
31 *********************************************************************/
33 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
34 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
36 #define CPUFREQ_TRANSITION_NOTIFIER (0)
37 #define CPUFREQ_POLICY_NOTIFIER (1)
40 /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
41 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
42 * two generic policies are available:
45 #define CPUFREQ_POLICY_POWERSAVE (1)
46 #define CPUFREQ_POLICY_PERFORMANCE (2)
48 /* Frequency values here are CPU kHz so that hardware which doesn't run
49 * with some frequencies can complain without having to guess what per
50 * cent / per mille means.
51 * Maximum transition latency is in microseconds - if it's unknown,
52 * CPUFREQ_ETERNAL shall be used.
55 struct cpufreq_governor;
57 #define CPUFREQ_ETERNAL (-1)
58 struct cpufreq_cpuinfo {
59 unsigned int max_freq;
60 unsigned int min_freq;
61 unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
64 struct cpufreq_real_policy {
65 unsigned int min; /* in kHz */
66 unsigned int max; /* in kHz */
67 unsigned int policy; /* see above */
68 struct cpufreq_governor *governor; /* see below */
71 struct cpufreq_policy {
72 unsigned int cpu; /* cpu nr */
73 struct cpufreq_cpuinfo cpuinfo;/* see above */
75 unsigned int min; /* in kHz */
76 unsigned int max; /* in kHz */
77 unsigned int cur; /* in kHz, only needed if cpufreq
78 * governors are used */
79 unsigned int policy; /* see above */
80 struct cpufreq_governor *governor; /* see below */
82 struct semaphore lock; /* CPU ->setpolicy or ->target may
83 only be called once a time */
85 struct work_struct update; /* if update_policy() needs to be
86 * called, but you're in IRQ context */
88 struct cpufreq_real_policy user_policy;
91 struct completion kobj_unregister;
94 #define CPUFREQ_ADJUST (0)
95 #define CPUFREQ_INCOMPATIBLE (1)
96 #define CPUFREQ_NOTIFY (2)
99 /******************** cpufreq transition notifiers *******************/
101 #define CPUFREQ_PRECHANGE (0)
102 #define CPUFREQ_POSTCHANGE (1)
103 #define CPUFREQ_RESUMECHANGE (8)
105 struct cpufreq_freqs {
106 unsigned int cpu; /* cpu nr */
109 u8 flags; /* flags of cpufreq_driver, see below. */
114 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
120 * new = old * mult / div
122 static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
124 #if BITS_PER_LONG == 32
126 u64 result = ((u64) old) * ((u64) mult);
128 return (unsigned long) result;
130 #elif BITS_PER_LONG == 64
132 unsigned long result = old * ((u64) mult);
139 /*********************************************************************
140 * CPUFREQ GOVERNORS *
141 *********************************************************************/
143 #define CPUFREQ_GOV_START 1
144 #define CPUFREQ_GOV_STOP 2
145 #define CPUFREQ_GOV_LIMITS 3
147 struct cpufreq_governor {
148 char name[CPUFREQ_NAME_LEN];
149 int (*governor) (struct cpufreq_policy *policy,
151 struct list_head governor_list;
152 struct module *owner;
155 /* pass a target to the cpufreq driver
157 extern int cpufreq_driver_target(struct cpufreq_policy *policy,
158 unsigned int target_freq,
159 unsigned int relation);
160 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
161 unsigned int target_freq,
162 unsigned int relation);
165 /* pass an event to the cpufreq governor */
166 int cpufreq_governor(unsigned int cpu, unsigned int event);
168 int cpufreq_register_governor(struct cpufreq_governor *governor);
169 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
172 /*********************************************************************
173 * CPUFREQ DRIVER INTERFACE *
174 *********************************************************************/
176 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
177 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
181 struct cpufreq_driver {
182 struct module *owner;
183 char name[CPUFREQ_NAME_LEN];
186 /* needed by all drivers */
187 int (*init) (struct cpufreq_policy *policy);
188 int (*verify) (struct cpufreq_policy *policy);
190 /* define one out of two */
191 int (*setpolicy) (struct cpufreq_policy *policy);
192 int (*target) (struct cpufreq_policy *policy,
193 unsigned int target_freq,
194 unsigned int relation);
196 /* should be defined, if possible */
197 unsigned int (*get) (unsigned int cpu);
200 int (*exit) (struct cpufreq_policy *policy);
201 int (*resume) (struct cpufreq_policy *policy);
202 struct freq_attr **attr;
207 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
208 * all ->init() calls failed */
209 #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
210 * "constants" aren't affected by
211 * frequency transitions */
212 #define CPUFREQ_PANIC_OUTOFSYNC 0x04 /* panic if cpufreq's opinion of
213 * current frequency differs from
214 * actual frequency */
215 #define CPUFREQ_PANIC_RESUME_OUTOFSYNC 0x08 /* panic if cpufreq's opinion of
216 * current frequency differs from
217 * actual frequency on resume
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)
232 if (policy->max < min)
234 if (policy->min > max)
236 if (policy->max > max)
238 if (policy->min > policy->max)
239 policy->min = policy->max;
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 /* the proc_intf.c needs this */
261 int cpufreq_parse_governor (char *str_governor, unsigned int *policy, struct cpufreq_governor **governor);
264 /*********************************************************************
265 * CPUFREQ USERSPACE GOVERNOR *
266 *********************************************************************/
267 #ifdef CONFIG_CPU_FREQ_24_API
269 int cpufreq_setmax(unsigned int cpu);
270 int cpufreq_set(unsigned int kHz, unsigned int cpu);
275 CPU_NR = 1, /* compatibilty reasons */
310 /* /proc/sys/cpu/{0,1,...,(NR_CPUS-1)} */
317 #endif /* CONFIG_CPU_FREQ_24_API */
320 /*********************************************************************
321 * CPUFREQ DEFAULT GOVERNOR *
322 *********************************************************************/
325 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
326 extern struct cpufreq_governor cpufreq_gov_performance;
327 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
328 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
329 extern struct cpufreq_governor cpufreq_gov_userspace;
330 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
334 /*********************************************************************
335 * FREQUENCY TABLE HELPERS *
336 *********************************************************************/
338 #define CPUFREQ_ENTRY_INVALID ~0
339 #define CPUFREQ_TABLE_END ~1
341 struct cpufreq_frequency_table {
342 unsigned int index; /* any */
343 unsigned int frequency; /* kHz - doesn't need to be in ascending
347 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
348 struct cpufreq_frequency_table *table);
350 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
351 struct cpufreq_frequency_table *table);
353 int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
354 struct cpufreq_frequency_table *table,
355 unsigned int target_freq,
356 unsigned int relation,
357 unsigned int *index);
359 /* the following are really really optional */
360 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
362 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
365 void cpufreq_frequency_table_put_attr(unsigned int cpu);
368 #endif /* _LINUX_CPUFREQ_H */