Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 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
 * $Id: cpufreq.h,v 1.1 2004-01-28 15:25:05 giacomo Exp $
9
 *
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.
13
 */
14
#ifndef _LINUX_CPUFREQ_H
15
#define _LINUX_CPUFREQ_H
16
 
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
 
25
#define CPUFREQ_NAME_LEN 16
26
 
27
 
28
/*********************************************************************
29
 *                     CPUFREQ NOTIFIER INTERFACE                    *
30
 *********************************************************************/
31
 
32
int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
33
int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
34
 
35
#define CPUFREQ_TRANSITION_NOTIFIER     (0)
36
#define CPUFREQ_POLICY_NOTIFIER         (1)
37
 
38
 
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:
42
 */
43
 
44
#define CPUFREQ_POLICY_POWERSAVE        (1)
45
#define CPUFREQ_POLICY_PERFORMANCE      (2)
46
 
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.
52
 */
53
 
54
struct cpufreq_governor;
55
 
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 */
61
};
62
 
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 */
68
};
69
 
70
struct cpufreq_policy {
71
        unsigned int            cpu;    /* cpu nr */
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 cpufreq_real_policy      user_policy;
85
 
86
        struct kobject          kobj;
87
        struct completion       kobj_unregister;
88
};
89
 
90
#define CPUFREQ_ADJUST          (0)
91
#define CPUFREQ_INCOMPATIBLE    (1)
92
#define CPUFREQ_NOTIFY          (2)
93
 
94
 
95
/******************** cpufreq transition notifiers *******************/
96
 
97
#define CPUFREQ_PRECHANGE       (0)
98
#define CPUFREQ_POSTCHANGE      (1)
99
 
100
struct cpufreq_freqs {
101
        unsigned int cpu;       /* cpu nr */
102
        unsigned int old;
103
        unsigned int new;
104
};
105
 
106
 
107
/**
108
 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
109
 * @old:   old value
110
 * @div:   divisor
111
 * @mult:  multiplier
112
 *
113
 * Needed for loops_per_jiffy and similar calculations.  We do it
114
 * this way to avoid math overflow on 32-bit machines.  This will
115
 * become architecture dependent once high-resolution-timer is
116
 * merged (or any other thing that introduces sc_math.h).
117
 *
118
 *    new = old * mult / div
119
 */
120
static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
121
{
122
        unsigned long val, carry;
123
 
124
        mult /= 100;
125
        div  /= 100;
126
        val   = (old / div) * mult;
127
        carry = old % div;
128
        carry = carry * mult / div;
129
 
130
        return carry + val;
131
};
132
 
133
/*********************************************************************
134
 *                          CPUFREQ GOVERNORS                        *
135
 *********************************************************************/
136
 
137
#define CPUFREQ_GOV_START  1
138
#define CPUFREQ_GOV_STOP   2
139
#define CPUFREQ_GOV_LIMITS 3
140
 
141
struct cpufreq_governor {
142
        char    name[CPUFREQ_NAME_LEN];
143
        int     (*governor)     (struct cpufreq_policy *policy,
144
                                 unsigned int event);
145
        struct list_head        governor_list;
146
        struct module           *owner;
147
};
148
 
149
/* pass a target to the cpufreq driver
150
 */
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);
157
 
158
 
159
/* pass an event to the cpufreq governor */
160
int cpufreq_governor(unsigned int cpu, unsigned int event);
161
 
162
int cpufreq_register_governor(struct cpufreq_governor *governor);
163
void cpufreq_unregister_governor(struct cpufreq_governor *governor);
164
 
165
 
166
/*********************************************************************
167
 *                      CPUFREQ DRIVER INTERFACE                     *
168
 *********************************************************************/
169
 
170
#define CPUFREQ_RELATION_L 0  /* lowest frequency at or above target */
171
#define CPUFREQ_RELATION_H 1  /* highest frequency below or at target */
172
 
173
struct freq_attr;
174
 
175
struct cpufreq_driver {
176
        struct module           *owner;
177
        char                    name[CPUFREQ_NAME_LEN];
178
 
179
        /* needed by all drivers */
180
        int     (*init)         (struct cpufreq_policy *policy);
181
        int     (*verify)       (struct cpufreq_policy *policy);
182
 
183
        /* define one out of two */
184
        int     (*setpolicy)    (struct cpufreq_policy *policy);
185
        int     (*target)       (struct cpufreq_policy *policy,
186
                                 unsigned int target_freq,
187
                                 unsigned int relation);
188
 
189
        /* optional */
190
        int     (*exit)         (struct cpufreq_policy *policy);
191
        int     (*resume)       (struct cpufreq_policy *policy);
192
        struct freq_attr        **attr;
193
};
194
 
195
int cpufreq_register_driver(struct cpufreq_driver *driver_data);
196
int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
197
 
198
 
199
void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
200
 
201
 
202
static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
203
{
204
        if (policy->min < min)
205
                policy->min = min;
206
        if (policy->max < min)
207
                policy->max = min;
208
        if (policy->min > max)
209
                policy->min = max;
210
        if (policy->max > max)
211
                policy->max = max;
212
        if (policy->min > policy->max)
213
                policy->min = policy->max;
214
        return;
215
}
216
 
217
struct freq_attr {
218
        struct attribute attr;
219
        ssize_t (*show)(struct cpufreq_policy *, char *);
220
        ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
221
};
222
 
223
 
224
/*********************************************************************
225
 *                        CPUFREQ 2.6. INTERFACE                     *
226
 *********************************************************************/
227
int cpufreq_set_policy(struct cpufreq_policy *policy);
228
int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
229
int cpufreq_update_policy(unsigned int cpu);
230
 
231
/* the proc_intf.c needs this */
232
int cpufreq_parse_governor (char *str_governor, unsigned int *policy, struct cpufreq_governor **governor);
233
 
234
#if defined(CONFIG_CPU_FREQ_GOV_USERSPACE) || defined(CONFIG_CPU_FREQ_GOV_USERSPACE_MODULE)
235
/*********************************************************************
236
 *                      CPUFREQ USERSPACE GOVERNOR                   *
237
 *********************************************************************/
238
int cpufreq_gov_userspace_init(void);
239
 
240
int cpufreq_setmax(unsigned int cpu);
241
int cpufreq_set(unsigned int kHz, unsigned int cpu);
242
unsigned int cpufreq_get(unsigned int cpu);
243
 
244
#ifdef CONFIG_CPU_FREQ_24_API
245
 
246
/* /proc/sys/cpu */
247
enum {
248
        CPU_NR   = 1,           /* compatibilty reasons */
249
        CPU_NR_0 = 1,
250
        CPU_NR_1 = 2,
251
        CPU_NR_2 = 3,
252
        CPU_NR_3 = 4,
253
        CPU_NR_4 = 5,
254
        CPU_NR_5 = 6,
255
        CPU_NR_6 = 7,
256
        CPU_NR_7 = 8,
257
        CPU_NR_8 = 9,
258
        CPU_NR_9 = 10,
259
        CPU_NR_10 = 11,
260
        CPU_NR_11 = 12,
261
        CPU_NR_12 = 13,
262
        CPU_NR_13 = 14,
263
        CPU_NR_14 = 15,
264
        CPU_NR_15 = 16,
265
        CPU_NR_16 = 17,
266
        CPU_NR_17 = 18,
267
        CPU_NR_18 = 19,
268
        CPU_NR_19 = 20,
269
        CPU_NR_20 = 21,
270
        CPU_NR_21 = 22,
271
        CPU_NR_22 = 23,
272
        CPU_NR_23 = 24,
273
        CPU_NR_24 = 25,
274
        CPU_NR_25 = 26,
275
        CPU_NR_26 = 27,
276
        CPU_NR_27 = 28,
277
        CPU_NR_28 = 29,
278
        CPU_NR_29 = 30,
279
        CPU_NR_30 = 31,
280
        CPU_NR_31 = 32,
281
};
282
 
283
/* /proc/sys/cpu/{0,1,...,(NR_CPUS-1)} */
284
enum {
285
        CPU_NR_FREQ_MAX = 1,
286
        CPU_NR_FREQ_MIN = 2,
287
        CPU_NR_FREQ = 3,
288
};
289
 
290
#endif /* CONFIG_CPU_FREQ_24_API */
291
 
292
#endif /* CONFIG_CPU_FREQ_GOV_USERSPACE */
293
 
294
 
295
/*********************************************************************
296
 *                       CPUFREQ DEFAULT GOVERNOR                    *
297
 *********************************************************************/
298
 
299
 
300
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
301
extern struct cpufreq_governor cpufreq_gov_performance;
302
#define CPUFREQ_DEFAULT_GOVERNOR        &cpufreq_gov_performance
303
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
304
extern struct cpufreq_governor cpufreq_gov_userspace;
305
#define CPUFREQ_DEFAULT_GOVERNOR        &cpufreq_gov_userspace
306
#endif
307
 
308
/*********************************************************************
309
 *                     FREQUENCY TABLE HELPERS                       *
310
 *********************************************************************/
311
 
312
#define CPUFREQ_ENTRY_INVALID ~0
313
#define CPUFREQ_TABLE_END     ~1
314
 
315
struct cpufreq_frequency_table {
316
        unsigned int    index;     /* any */
317
        unsigned int    frequency; /* kHz - doesn't need to be in ascending
318
                                    * order */
319
};
320
 
321
#if defined(CONFIG_CPU_FREQ_TABLE) || defined(CONFIG_CPU_FREQ_TABLE_MODULE)
322
int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
323
                                    struct cpufreq_frequency_table *table);
324
 
325
int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
326
                                   struct cpufreq_frequency_table *table);
327
 
328
int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
329
                                   struct cpufreq_frequency_table *table,
330
                                   unsigned int target_freq,
331
                                   unsigned int relation,
332
                                   unsigned int *index);
333
 
334
/* the following are really really optional */
335
extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
336
 
337
void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
338
                                      unsigned int cpu);
339
 
340
void cpufreq_frequency_table_put_attr(unsigned int cpu);
341
 
342
 
343
#endif /* CONFIG_CPU_FREQ_TABLE */
344
#endif /* _LINUX_CPUFREQ_H */