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 microseconds - 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)
107 struct cpufreq_freqs
{
108 unsigned int cpu
; /* cpu nr */
111 u8 flags
; /* flags of cpufreq_driver, see below. */
116 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
122 * new = old * mult / div
124 static inline unsigned long cpufreq_scale(unsigned long old
, u_int div
, u_int mult
)
126 #if BITS_PER_LONG == 32
128 u64 result
= ((u64
) old
) * ((u64
) mult
);
130 return (unsigned long) result
;
132 #elif BITS_PER_LONG == 64
134 unsigned long result
= old
* ((u64
) mult
);
141 /*********************************************************************
142 * CPUFREQ GOVERNORS *
143 *********************************************************************/
145 #define CPUFREQ_GOV_START 1
146 #define CPUFREQ_GOV_STOP 2
147 #define CPUFREQ_GOV_LIMITS 3
149 struct cpufreq_governor
{
150 char name
[CPUFREQ_NAME_LEN
];
151 int (*governor
) (struct cpufreq_policy
*policy
,
153 struct list_head governor_list
;
154 struct module
*owner
;
157 /* pass a target to the cpufreq driver
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
);
167 /* pass an event to the cpufreq governor */
168 int cpufreq_governor(unsigned int cpu
, unsigned int event
);
170 int cpufreq_register_governor(struct cpufreq_governor
*governor
);
171 void cpufreq_unregister_governor(struct cpufreq_governor
*governor
);
174 /*********************************************************************
175 * CPUFREQ DRIVER INTERFACE *
176 *********************************************************************/
178 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
179 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
183 struct cpufreq_driver
{
184 struct module
*owner
;
185 char name
[CPUFREQ_NAME_LEN
];
188 /* needed by all drivers */
189 int (*init
) (struct cpufreq_policy
*policy
);
190 int (*verify
) (struct cpufreq_policy
*policy
);
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
);
198 /* should be defined, if possible */
199 unsigned int (*get
) (unsigned int cpu
);
202 int (*exit
) (struct cpufreq_policy
*policy
);
203 int (*resume
) (struct cpufreq_policy
*policy
);
204 struct freq_attr
**attr
;
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 */
216 int cpufreq_register_driver(struct cpufreq_driver
*driver_data
);
217 int cpufreq_unregister_driver(struct cpufreq_driver
*driver_data
);
220 void cpufreq_notify_transition(struct cpufreq_freqs
*freqs
, unsigned int state
);
223 static inline void cpufreq_verify_within_limits(struct cpufreq_policy
*policy
, unsigned int min
, unsigned int max
)
225 if (policy
->min
< min
)
227 if (policy
->max
< min
)
229 if (policy
->min
> max
)
231 if (policy
->max
> max
)
233 if (policy
->min
> policy
->max
)
234 policy
->min
= policy
->max
;
239 struct attribute attr
;
240 ssize_t (*show
)(struct cpufreq_policy
*, char *);
241 ssize_t (*store
)(struct cpufreq_policy
*, const char *, size_t count
);
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
);
252 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
253 unsigned int cpufreq_get(unsigned int cpu
);
256 /*********************************************************************
257 * CPUFREQ DEFAULT GOVERNOR *
258 *********************************************************************/
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
270 /*********************************************************************
271 * FREQUENCY TABLE HELPERS *
272 *********************************************************************/
274 #define CPUFREQ_ENTRY_INVALID ~0
275 #define CPUFREQ_TABLE_END ~1
277 struct cpufreq_frequency_table
{
278 unsigned int index
; /* any */
279 unsigned int frequency
; /* kHz - doesn't need to be in ascending
283 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy
*policy
,
284 struct cpufreq_frequency_table
*table
);
286 int cpufreq_frequency_table_verify(struct cpufreq_policy
*policy
,
287 struct cpufreq_frequency_table
*table
);
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
);
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
);
300 /* the following are really really optional */
301 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs
;
303 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table
*table
,
306 void cpufreq_frequency_table_put_attr(unsigned int cpu
);
309 /*********************************************************************
310 * UNIFIED DEBUG HELPERS *
311 *********************************************************************/
313 #define CPUFREQ_DEBUG_CORE 1
314 #define CPUFREQ_DEBUG_DRIVER 2
315 #define CPUFREQ_DEBUG_GOVERNOR 4
317 #ifdef CONFIG_CPU_FREQ_DEBUG
319 extern void cpufreq_debug_printk(unsigned int type
, const char *prefix
,
320 const char *fmt
, ...);
324 #define cpufreq_debug_printk(msg...) do { } while(0)
326 #endif /* CONFIG_CPU_FREQ_DEBUG */
328 #endif /* _LINUX_CPUFREQ_H */