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>
25 #include <linux/cpumask.h>
27 #define CPUFREQ_NAME_LEN 16
30 /*********************************************************************
31 * CPUFREQ NOTIFIER INTERFACE *
32 *********************************************************************/
34 int cpufreq_register_notifier(struct notifier_block
*nb
, unsigned int list
);
35 int cpufreq_unregister_notifier(struct notifier_block
*nb
, unsigned int list
);
37 #define CPUFREQ_TRANSITION_NOTIFIER (0)
38 #define CPUFREQ_POLICY_NOTIFIER (1)
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:
46 #define CPUFREQ_POLICY_POWERSAVE (1)
47 #define CPUFREQ_POLICY_PERFORMANCE (2)
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 nanoseconds - if it's unknown,
53 * CPUFREQ_ETERNAL shall be used.
56 struct cpufreq_governor
;
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 */
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 */
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 */
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 */
84 struct semaphore lock
; /* CPU ->setpolicy or ->target may
85 only be called once a time */
87 struct work_struct update
; /* if update_policy() needs to be
88 * called, but you're in IRQ context */
90 struct cpufreq_real_policy user_policy
;
93 struct completion kobj_unregister
;
96 #define CPUFREQ_ADJUST (0)
97 #define CPUFREQ_INCOMPATIBLE (1)
98 #define CPUFREQ_NOTIFY (2)
101 /******************** cpufreq transition notifiers *******************/
103 #define CPUFREQ_PRECHANGE (0)
104 #define CPUFREQ_POSTCHANGE (1)
105 #define CPUFREQ_RESUMECHANGE (8)
106 #define CPUFREQ_SUSPENDCHANGE (9)
108 struct cpufreq_freqs
{
109 unsigned int cpu
; /* cpu nr */
112 u8 flags
; /* flags of cpufreq_driver, see below. */
117 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
123 * new = old * mult / div
125 static inline unsigned long cpufreq_scale(unsigned long old
, u_int div
, u_int mult
)
127 #if BITS_PER_LONG == 32
129 u64 result
= ((u64
) old
) * ((u64
) mult
);
131 return (unsigned long) result
;
133 #elif BITS_PER_LONG == 64
135 unsigned long result
= old
* ((u64
) mult
);
142 /*********************************************************************
143 * CPUFREQ GOVERNORS *
144 *********************************************************************/
146 #define CPUFREQ_GOV_START 1
147 #define CPUFREQ_GOV_STOP 2
148 #define CPUFREQ_GOV_LIMITS 3
150 struct cpufreq_governor
{
151 char name
[CPUFREQ_NAME_LEN
];
152 int (*governor
) (struct cpufreq_policy
*policy
,
154 struct list_head governor_list
;
155 struct module
*owner
;
158 /* pass a target to the cpufreq driver
160 extern int cpufreq_driver_target(struct cpufreq_policy
*policy
,
161 unsigned int target_freq
,
162 unsigned int relation
);
163 extern int __cpufreq_driver_target(struct cpufreq_policy
*policy
,
164 unsigned int target_freq
,
165 unsigned int relation
);
168 /* pass an event to the cpufreq governor */
169 int cpufreq_governor(unsigned int cpu
, unsigned int event
);
171 int cpufreq_register_governor(struct cpufreq_governor
*governor
);
172 void cpufreq_unregister_governor(struct cpufreq_governor
*governor
);
175 /*********************************************************************
176 * CPUFREQ DRIVER INTERFACE *
177 *********************************************************************/
179 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
180 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
184 struct cpufreq_driver
{
185 struct module
*owner
;
186 char name
[CPUFREQ_NAME_LEN
];
189 /* needed by all drivers */
190 int (*init
) (struct cpufreq_policy
*policy
);
191 int (*verify
) (struct cpufreq_policy
*policy
);
193 /* define one out of two */
194 int (*setpolicy
) (struct cpufreq_policy
*policy
);
195 int (*target
) (struct cpufreq_policy
*policy
,
196 unsigned int target_freq
,
197 unsigned int relation
);
199 /* should be defined, if possible */
200 unsigned int (*get
) (unsigned int cpu
);
203 int (*exit
) (struct cpufreq_policy
*policy
);
204 int (*suspend
) (struct cpufreq_policy
*policy
, u32 state
);
205 int (*resume
) (struct cpufreq_policy
*policy
);
206 struct freq_attr
**attr
;
211 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
212 * all ->init() calls failed */
213 #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
214 * "constants" aren't affected by
215 * frequency transitions */
216 #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
219 int cpufreq_register_driver(struct cpufreq_driver
*driver_data
);
220 int cpufreq_unregister_driver(struct cpufreq_driver
*driver_data
);
223 void cpufreq_notify_transition(struct cpufreq_freqs
*freqs
, unsigned int state
);
226 static inline void cpufreq_verify_within_limits(struct cpufreq_policy
*policy
, unsigned int min
, unsigned int max
)
228 if (policy
->min
< min
)
230 if (policy
->max
< min
)
232 if (policy
->min
> max
)
234 if (policy
->max
> max
)
236 if (policy
->min
> policy
->max
)
237 policy
->min
= policy
->max
;
242 struct attribute attr
;
243 ssize_t (*show
)(struct cpufreq_policy
*, char *);
244 ssize_t (*store
)(struct cpufreq_policy
*, const char *, size_t count
);
248 /*********************************************************************
249 * CPUFREQ 2.6. INTERFACE *
250 *********************************************************************/
251 int cpufreq_set_policy(struct cpufreq_policy
*policy
);
252 int cpufreq_get_policy(struct cpufreq_policy
*policy
, unsigned int cpu
);
253 int cpufreq_update_policy(unsigned int cpu
);
255 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
256 unsigned int cpufreq_get(unsigned int cpu
);
259 /*********************************************************************
260 * CPUFREQ DEFAULT GOVERNOR *
261 *********************************************************************/
264 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
265 extern struct cpufreq_governor cpufreq_gov_performance
;
266 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
267 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
268 extern struct cpufreq_governor cpufreq_gov_userspace
;
269 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
273 /*********************************************************************
274 * FREQUENCY TABLE HELPERS *
275 *********************************************************************/
277 #define CPUFREQ_ENTRY_INVALID ~0
278 #define CPUFREQ_TABLE_END ~1
280 struct cpufreq_frequency_table
{
281 unsigned int index
; /* any */
282 unsigned int frequency
; /* kHz - doesn't need to be in ascending
286 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy
*policy
,
287 struct cpufreq_frequency_table
*table
);
289 int cpufreq_frequency_table_verify(struct cpufreq_policy
*policy
,
290 struct cpufreq_frequency_table
*table
);
292 int cpufreq_frequency_table_target(struct cpufreq_policy
*policy
,
293 struct cpufreq_frequency_table
*table
,
294 unsigned int target_freq
,
295 unsigned int relation
,
296 unsigned int *index
);
298 /* the following 3 funtions are for cpufreq core use only */
299 struct cpufreq_frequency_table
*cpufreq_frequency_get_table(unsigned int cpu
);
300 struct cpufreq_policy
*cpufreq_cpu_get(unsigned int cpu
);
301 void cpufreq_cpu_put (struct cpufreq_policy
*data
);
303 /* the following are really really optional */
304 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs
;
306 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table
*table
,
309 void cpufreq_frequency_table_put_attr(unsigned int cpu
);
312 /*********************************************************************
313 * UNIFIED DEBUG HELPERS *
314 *********************************************************************/
316 #define CPUFREQ_DEBUG_CORE 1
317 #define CPUFREQ_DEBUG_DRIVER 2
318 #define CPUFREQ_DEBUG_GOVERNOR 4
320 #ifdef CONFIG_CPU_FREQ_DEBUG
322 extern void cpufreq_debug_printk(unsigned int type
, const char *prefix
,
323 const char *fmt
, ...);
327 #define cpufreq_debug_printk(msg...) do { } while(0)
329 #endif /* CONFIG_CPU_FREQ_DEBUG */
331 #endif /* _LINUX_CPUFREQ_H */