source: svn/trunk/newcon3bcm2_21bu/toolchain/mipsel-linux-uclibc/include/linux/cpufreq.h @ 48

Last change on this file since 48 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 9.8 KB
Line 
1/*
2 *  linux/include/linux/cpufreq.h
3 *
4 *  Copyright (C) 2001 Russell King
5 *            (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 *           
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef _LINUX_CPUFREQ_H
14#define _LINUX_CPUFREQ_H
15
16#include <linux/notifier.h>
17#include <linux/threads.h>
18#include <linux/device.h>
19#include <linux/kobject.h>
20#include <linux/sysfs.h>
21#include <linux/workqueue.h>
22#include <linux/cpumask.h>
23
24#define CPUFREQ_NAME_LEN 16
25
26
27/*********************************************************************
28 *                     CPUFREQ NOTIFIER INTERFACE                    *
29 *********************************************************************/
30
31int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
32int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
33
34#define CPUFREQ_TRANSITION_NOTIFIER     (0)
35#define CPUFREQ_POLICY_NOTIFIER         (1)
36
37
38/* if (cpufreq_driver->target) exists, the ->governor decides what frequency
39 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
40 * two generic policies are available:
41 */
42
43#define CPUFREQ_POLICY_POWERSAVE        (1)
44#define CPUFREQ_POLICY_PERFORMANCE      (2)
45
46/* Frequency values here are CPU kHz so that hardware which doesn't run
47 * with some frequencies can complain without having to guess what per
48 * cent / per mille means.
49 * Maximum transition latency is in nanoseconds - if it's unknown,
50 * CPUFREQ_ETERNAL shall be used.
51 */
52
53struct cpufreq_governor;
54
55#define CPUFREQ_ETERNAL                 (-1)
56struct cpufreq_cpuinfo {
57        unsigned int            max_freq;
58        unsigned int            min_freq;
59        unsigned int            transition_latency; /* in 10^(-9) s = nanoseconds */
60};
61
62struct cpufreq_real_policy {
63        unsigned int            min;    /* in kHz */
64        unsigned int            max;    /* in kHz */
65        unsigned int            policy; /* see above */
66        struct cpufreq_governor *governor; /* see below */
67};
68
69struct cpufreq_policy {
70        cpumask_t               cpus;   /* affected CPUs */
71        unsigned int            cpu;    /* cpu nr of registered CPU */
72        struct cpufreq_cpuinfo  cpuinfo;/* see above */
73
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 */
80
81        struct semaphore        lock;   /* CPU ->setpolicy or ->target may
82                                           only be called once a time */
83
84        struct work_struct      update; /* if update_policy() needs to be
85                                         * called, but you're in IRQ context */
86
87        struct cpufreq_real_policy      user_policy;
88
89        struct kobject          kobj;
90        struct completion       kobj_unregister;
91};
92
93#define CPUFREQ_ADJUST          (0)
94#define CPUFREQ_INCOMPATIBLE    (1)
95#define CPUFREQ_NOTIFY          (2)
96
97
98/******************** cpufreq transition notifiers *******************/
99
100#define CPUFREQ_PRECHANGE       (0)
101#define CPUFREQ_POSTCHANGE      (1)
102#define CPUFREQ_RESUMECHANGE    (8)
103#define CPUFREQ_SUSPENDCHANGE   (9)
104
105struct cpufreq_freqs {
106        unsigned int cpu;       /* cpu nr */
107        unsigned int old;
108        unsigned int new;
109        __u8 flags;             /* flags of cpufreq_driver, see below. */
110};
111
112
113/**
114 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
115 * @old:   old value
116 * @div:   divisor
117 * @mult:  multiplier
118 *
119 *
120 *    new = old * mult / div
121 */
122static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
123{
124#if BITS_PER_LONG == 32
125
126        __u64 result = ((__u64) old) * ((__u64) mult);
127        do_div(result, div);
128        return (unsigned long) result;
129
130#elif BITS_PER_LONG == 64
131
132        unsigned long result = old * ((__u64) mult);
133        result /= div;
134        return result;
135
136#endif
137};
138
139/*********************************************************************
140 *                          CPUFREQ GOVERNORS                        *
141 *********************************************************************/
142
143#define CPUFREQ_GOV_START  1
144#define CPUFREQ_GOV_STOP   2
145#define CPUFREQ_GOV_LIMITS 3
146
147struct cpufreq_governor {
148        char    name[CPUFREQ_NAME_LEN];
149        int     (*governor)     (struct cpufreq_policy *policy,
150                                 unsigned int event);
151        struct list_head        governor_list;
152        struct module           *owner;
153};
154
155/* pass a target to the cpufreq driver
156 */
157extern int cpufreq_driver_target(struct cpufreq_policy *policy,
158                                 unsigned int target_freq,
159                                 unsigned int relation);
160extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
161                                   unsigned int target_freq,
162                                   unsigned int relation);
163
164
165/* pass an event to the cpufreq governor */
166int cpufreq_governor(unsigned int cpu, unsigned int event);
167
168int cpufreq_register_governor(struct cpufreq_governor *governor);
169void cpufreq_unregister_governor(struct cpufreq_governor *governor);
170
171
172/*********************************************************************
173 *                      CPUFREQ DRIVER INTERFACE                     *
174 *********************************************************************/
175
176#define CPUFREQ_RELATION_L 0  /* lowest frequency at or above target */
177#define CPUFREQ_RELATION_H 1  /* highest frequency below or at target */
178
179struct freq_attr;
180
181struct cpufreq_driver {
182        struct module           *owner;
183        char                    name[CPUFREQ_NAME_LEN];
184        __u8                    flags;
185
186        /* needed by all drivers */
187        int     (*init)         (struct cpufreq_policy *policy);
188        int     (*verify)       (struct cpufreq_policy *policy);
189
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);
195
196        /* should be defined, if possible */
197        unsigned int    (*get)  (unsigned int cpu);
198
199        /* optional */
200        int     (*exit)         (struct cpufreq_policy *policy);
201        int     (*suspend)      (struct cpufreq_policy *policy, __u32 state);
202        int     (*resume)       (struct cpufreq_policy *policy);
203        struct freq_attr        **attr;
204};
205
206/* flags */
207
208#define CPUFREQ_STICKY          0x01    /* the driver isn't removed even if
209                                         * all ->init() calls failed */
210#define CPUFREQ_CONST_LOOPS     0x02    /* loops_per_jiffy or other kernel
211                                         * "constants" aren't affected by
212                                         * frequency transitions */
213#define CPUFREQ_PM_NO_WARN      0x04    /* don't warn on suspend/resume speed
214                                         * mismatches */
215
216int cpufreq_register_driver(struct cpufreq_driver *driver_data);
217int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
218
219
220void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
221
222
223static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max) 
224{
225        if (policy->min < min)
226                policy->min = min;
227        if (policy->max < min)
228                policy->max = min;
229        if (policy->min > max)
230                policy->min = max;
231        if (policy->max > max)
232                policy->max = max;
233        if (policy->min > policy->max)
234                policy->min = policy->max;
235        return;
236}
237
238struct freq_attr {
239        struct attribute attr;
240        ssize_t (*show)(struct cpufreq_policy *, char *);
241        ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
242};
243
244
245/*********************************************************************
246 *                        CPUFREQ 2.6. INTERFACE                     *
247 *********************************************************************/
248int cpufreq_set_policy(struct cpufreq_policy *policy);
249int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
250int cpufreq_update_policy(unsigned int cpu);
251
252/* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
253unsigned int cpufreq_get(unsigned int cpu);
254
255
256/*********************************************************************
257 *                       CPUFREQ DEFAULT GOVERNOR                    *
258 *********************************************************************/
259
260
261#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
262extern struct cpufreq_governor cpufreq_gov_performance;
263#define CPUFREQ_DEFAULT_GOVERNOR        &cpufreq_gov_performance
264#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
265extern struct cpufreq_governor cpufreq_gov_userspace;
266#define CPUFREQ_DEFAULT_GOVERNOR        &cpufreq_gov_userspace
267#endif
268
269
270/*********************************************************************
271 *                     FREQUENCY TABLE HELPERS                       *
272 *********************************************************************/
273
274#define CPUFREQ_ENTRY_INVALID ~0
275#define CPUFREQ_TABLE_END     ~1
276
277struct cpufreq_frequency_table {
278        unsigned int    index;     /* any */
279        unsigned int    frequency; /* kHz - doesn't need to be in ascending
280                                    * order */
281};
282
283int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
284                                    struct cpufreq_frequency_table *table);
285
286int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
287                                   struct cpufreq_frequency_table *table);
288
289int 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);
294
295/* the following 3 funtions are for cpufreq core use only */
296struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
297struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
298void   cpufreq_cpu_put (struct cpufreq_policy *data);
299
300/* the following are really really optional */
301extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
302
303void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, 
304                                      unsigned int cpu);
305
306void cpufreq_frequency_table_put_attr(unsigned int cpu);
307
308
309/*********************************************************************
310 *                     UNIFIED DEBUG HELPERS                         *
311 *********************************************************************/
312
313#define CPUFREQ_DEBUG_CORE      1
314#define CPUFREQ_DEBUG_DRIVER    2
315#define CPUFREQ_DEBUG_GOVERNOR  4
316
317#ifdef CONFIG_CPU_FREQ_DEBUG
318
319extern void cpufreq_debug_printk(unsigned int type, const char *prefix, 
320                                 const char *fmt, ...);
321
322#else
323
324#define cpufreq_debug_printk(msg...) do { } while(0)
325
326#endif /* CONFIG_CPU_FREQ_DEBUG */
327
328#endif /* _LINUX_CPUFREQ_H */
Note: See TracBrowser for help on using the repository browser.