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 */
214 int cpufreq_register_driver(struct cpufreq_driver
*driver_data
);
215 int cpufreq_unregister_driver(struct cpufreq_driver
*driver_data
);
218 void cpufreq_notify_transition(struct cpufreq_freqs
*freqs
, unsigned int state
);
221 static inline void cpufreq_verify_within_limits(struct cpufreq_policy
*policy
, unsigned int min
, unsigned int max
)
223 if (policy
->min
< min
)
225 if (policy
->max
< min
)
227 if (policy
->min
> max
)
229 if (policy
->max
> max
)
231 if (policy
->min
> policy
->max
)
232 policy
->min
= policy
->max
;
237 struct attribute attr
;
238 ssize_t (*show
)(struct cpufreq_policy
*, char *);
239 ssize_t (*store
)(struct cpufreq_policy
*, const char *, size_t count
);
243 /*********************************************************************
244 * CPUFREQ 2.6. INTERFACE *
245 *********************************************************************/
246 int cpufreq_set_policy(struct cpufreq_policy
*policy
);
247 int cpufreq_get_policy(struct cpufreq_policy
*policy
, unsigned int cpu
);
248 int cpufreq_update_policy(unsigned int cpu
);
250 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
251 unsigned int cpufreq_get(unsigned int cpu
);
253 /* the proc_intf.c needs this */
254 int cpufreq_parse_governor (char *str_governor
, unsigned int *policy
, struct cpufreq_governor
**governor
);
257 /*********************************************************************
258 * CPUFREQ USERSPACE GOVERNOR *
259 *********************************************************************/
260 #ifdef CONFIG_CPU_FREQ_24_API
262 int cpufreq_setmax(unsigned int cpu
);
263 int cpufreq_set(unsigned int kHz
, unsigned int cpu
);
268 CPU_NR
= 1, /* compatibilty reasons */
303 /* /proc/sys/cpu/{0,1,...,(NR_CPUS-1)} */
310 #endif /* CONFIG_CPU_FREQ_24_API */
313 /*********************************************************************
314 * CPUFREQ DEFAULT GOVERNOR *
315 *********************************************************************/
318 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
319 extern struct cpufreq_governor cpufreq_gov_performance
;
320 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
321 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
322 extern struct cpufreq_governor cpufreq_gov_userspace
;
323 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
327 /*********************************************************************
328 * FREQUENCY TABLE HELPERS *
329 *********************************************************************/
331 #define CPUFREQ_ENTRY_INVALID ~0
332 #define CPUFREQ_TABLE_END ~1
334 struct cpufreq_frequency_table
{
335 unsigned int index
; /* any */
336 unsigned int frequency
; /* kHz - doesn't need to be in ascending
340 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy
*policy
,
341 struct cpufreq_frequency_table
*table
);
343 int cpufreq_frequency_table_verify(struct cpufreq_policy
*policy
,
344 struct cpufreq_frequency_table
*table
);
346 int cpufreq_frequency_table_target(struct cpufreq_policy
*policy
,
347 struct cpufreq_frequency_table
*table
,
348 unsigned int target_freq
,
349 unsigned int relation
,
350 unsigned int *index
);
352 /* the following are really really optional */
353 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs
;
355 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table
*table
,
358 void cpufreq_frequency_table_put_attr(unsigned int cpu
);
361 #endif /* _LINUX_CPUFREQ_H */