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>
25 #define CPUFREQ_NAME_LEN 16
28 /*********************************************************************
29 * CPUFREQ NOTIFIER INTERFACE *
30 *********************************************************************/
32 int cpufreq_register_notifier(struct notifier_block
*nb
, unsigned int list
);
33 int cpufreq_unregister_notifier(struct notifier_block
*nb
, unsigned int list
);
35 #define CPUFREQ_TRANSITION_NOTIFIER (0)
36 #define CPUFREQ_POLICY_NOTIFIER (1)
39 /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
40 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
41 * two generic policies are available:
44 #define CPUFREQ_POLICY_POWERSAVE (1)
45 #define CPUFREQ_POLICY_PERFORMANCE (2)
47 /* Frequency values here are CPU kHz so that hardware which doesn't run
48 * with some frequencies can complain without having to guess what per
49 * cent / per mille means.
50 * Maximum transition latency is in microseconds - if it's unknown,
51 * CPUFREQ_ETERNAL shall be used.
54 struct cpufreq_governor
;
56 #define CPUFREQ_ETERNAL (-1)
57 struct cpufreq_cpuinfo
{
58 unsigned int max_freq
;
59 unsigned int min_freq
;
60 unsigned int transition_latency
; /* in 10^(-9) s = nanoseconds */
63 struct cpufreq_real_policy
{
64 unsigned int min
; /* in kHz */
65 unsigned int max
; /* in kHz */
66 unsigned int policy
; /* see above */
67 struct cpufreq_governor
*governor
; /* see below */
70 struct cpufreq_policy
{
71 unsigned int cpu
; /* cpu nr */
72 struct cpufreq_cpuinfo cpuinfo
;/* see above */
74 unsigned int min
; /* in kHz */
75 unsigned int max
; /* in kHz */
76 unsigned int cur
; /* in kHz, only needed if cpufreq
77 * governors are used */
78 unsigned int policy
; /* see above */
79 struct cpufreq_governor
*governor
; /* see below */
81 struct semaphore lock
; /* CPU ->setpolicy or ->target may
82 only be called once a time */
84 struct cpufreq_real_policy user_policy
;
87 struct completion kobj_unregister
;
90 #define CPUFREQ_ADJUST (0)
91 #define CPUFREQ_INCOMPATIBLE (1)
92 #define CPUFREQ_NOTIFY (2)
95 /******************** cpufreq transition notifiers *******************/
97 #define CPUFREQ_PRECHANGE (0)
98 #define CPUFREQ_POSTCHANGE (1)
100 struct cpufreq_freqs
{
101 unsigned int cpu
; /* cpu nr */
108 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
114 * new = old * mult / div
116 static inline unsigned long cpufreq_scale(unsigned long old
, u_int div
, u_int mult
)
118 #if BITS_PER_LONG == 32
120 u64 result
= ((u64
) old
) * ((u64
) mult
);
122 return (unsigned long) result
;
124 #elif BITS_PER_LONG == 64
126 unsigned long result
= old
* ((u64
) mult
);
133 /*********************************************************************
134 * CPUFREQ GOVERNORS *
135 *********************************************************************/
137 #define CPUFREQ_GOV_START 1
138 #define CPUFREQ_GOV_STOP 2
139 #define CPUFREQ_GOV_LIMITS 3
141 struct cpufreq_governor
{
142 char name
[CPUFREQ_NAME_LEN
];
143 int (*governor
) (struct cpufreq_policy
*policy
,
145 struct list_head governor_list
;
146 struct module
*owner
;
149 /* pass a target to the cpufreq driver
151 extern int cpufreq_driver_target(struct cpufreq_policy
*policy
,
152 unsigned int target_freq
,
153 unsigned int relation
);
154 extern int __cpufreq_driver_target(struct cpufreq_policy
*policy
,
155 unsigned int target_freq
,
156 unsigned int relation
);
159 /* pass an event to the cpufreq governor */
160 int cpufreq_governor(unsigned int cpu
, unsigned int event
);
162 int cpufreq_register_governor(struct cpufreq_governor
*governor
);
163 void cpufreq_unregister_governor(struct cpufreq_governor
*governor
);
166 /*********************************************************************
167 * CPUFREQ DRIVER INTERFACE *
168 *********************************************************************/
170 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
171 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
175 struct cpufreq_driver
{
176 struct module
*owner
;
177 char name
[CPUFREQ_NAME_LEN
];
180 /* needed by all drivers */
181 int (*init
) (struct cpufreq_policy
*policy
);
182 int (*verify
) (struct cpufreq_policy
*policy
);
184 /* define one out of two */
185 int (*setpolicy
) (struct cpufreq_policy
*policy
);
186 int (*target
) (struct cpufreq_policy
*policy
,
187 unsigned int target_freq
,
188 unsigned int relation
);
191 int (*exit
) (struct cpufreq_policy
*policy
);
192 int (*resume
) (struct cpufreq_policy
*policy
);
193 struct freq_attr
**attr
;
198 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
199 all ->init() calls failed */
201 int cpufreq_register_driver(struct cpufreq_driver
*driver_data
);
202 int cpufreq_unregister_driver(struct cpufreq_driver
*driver_data
);
205 void cpufreq_notify_transition(struct cpufreq_freqs
*freqs
, unsigned int state
);
208 static inline void cpufreq_verify_within_limits(struct cpufreq_policy
*policy
, unsigned int min
, unsigned int max
)
210 if (policy
->min
< min
)
212 if (policy
->max
< min
)
214 if (policy
->min
> max
)
216 if (policy
->max
> max
)
218 if (policy
->min
> policy
->max
)
219 policy
->min
= policy
->max
;
224 struct attribute attr
;
225 ssize_t (*show
)(struct cpufreq_policy
*, char *);
226 ssize_t (*store
)(struct cpufreq_policy
*, const char *, size_t count
);
230 /*********************************************************************
231 * CPUFREQ 2.6. INTERFACE *
232 *********************************************************************/
233 int cpufreq_set_policy(struct cpufreq_policy
*policy
);
234 int cpufreq_get_policy(struct cpufreq_policy
*policy
, unsigned int cpu
);
235 int cpufreq_update_policy(unsigned int cpu
);
237 /* the proc_intf.c needs this */
238 int cpufreq_parse_governor (char *str_governor
, unsigned int *policy
, struct cpufreq_governor
**governor
);
241 /*********************************************************************
242 * CPUFREQ USERSPACE GOVERNOR *
243 *********************************************************************/
244 int cpufreq_gov_userspace_init(void);
246 #ifdef CONFIG_CPU_FREQ_24_API
248 int cpufreq_setmax(unsigned int cpu
);
249 int cpufreq_set(unsigned int kHz
, unsigned int cpu
);
250 unsigned int cpufreq_get(unsigned int cpu
);
255 CPU_NR
= 1, /* compatibilty reasons */
290 /* /proc/sys/cpu/{0,1,...,(NR_CPUS-1)} */
297 #endif /* CONFIG_CPU_FREQ_24_API */
300 /*********************************************************************
301 * CPUFREQ DEFAULT GOVERNOR *
302 *********************************************************************/
305 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
306 extern struct cpufreq_governor cpufreq_gov_performance
;
307 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
308 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
309 extern struct cpufreq_governor cpufreq_gov_userspace
;
310 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
314 /*********************************************************************
315 * FREQUENCY TABLE HELPERS *
316 *********************************************************************/
318 #define CPUFREQ_ENTRY_INVALID ~0
319 #define CPUFREQ_TABLE_END ~1
321 struct cpufreq_frequency_table
{
322 unsigned int index
; /* any */
323 unsigned int frequency
; /* kHz - doesn't need to be in ascending
327 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy
*policy
,
328 struct cpufreq_frequency_table
*table
);
330 int cpufreq_frequency_table_verify(struct cpufreq_policy
*policy
,
331 struct cpufreq_frequency_table
*table
);
333 int cpufreq_frequency_table_target(struct cpufreq_policy
*policy
,
334 struct cpufreq_frequency_table
*table
,
335 unsigned int target_freq
,
336 unsigned int relation
,
337 unsigned int *index
);
339 /* the following are really really optional */
340 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs
;
342 void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table
*table
,
345 void cpufreq_frequency_table_put_attr(unsigned int cpu
);
348 #endif /* _LINUX_CPUFREQ_H */