]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/cpufreq.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux...
[mirror_ubuntu-jammy-kernel.git] / include / linux / cpufreq.h
CommitLineData
1da177e4
LT
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.36 2003/01/20 17:31:48 db 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
83933af4 17#include <linux/mutex.h>
1da177e4
LT
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>
4e57b681 26#include <asm/div64.h>
1da177e4
LT
27
28#define CPUFREQ_NAME_LEN 16
29
30
31/*********************************************************************
32 * CPUFREQ NOTIFIER INTERFACE *
33 *********************************************************************/
34
184c44d2 35#ifdef CONFIG_CPU_FREQ
1da177e4 36int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
184c44d2
AM
37#else
38static inline int cpufreq_register_notifier(struct notifier_block *nb,
39 unsigned int list)
40{
41 return 0;
42}
43#endif
1da177e4
LT
44int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
45
46#define CPUFREQ_TRANSITION_NOTIFIER (0)
47#define CPUFREQ_POLICY_NOTIFIER (1)
48
49
50/* if (cpufreq_driver->target) exists, the ->governor decides what frequency
51 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
52 * two generic policies are available:
53 */
54
55#define CPUFREQ_POLICY_POWERSAVE (1)
56#define CPUFREQ_POLICY_PERFORMANCE (2)
57
58/* Frequency values here are CPU kHz so that hardware which doesn't run
59 * with some frequencies can complain without having to guess what per
60 * cent / per mille means.
b53cc6ea 61 * Maximum transition latency is in nanoseconds - if it's unknown,
1da177e4
LT
62 * CPUFREQ_ETERNAL shall be used.
63 */
64
65struct cpufreq_governor;
66
67#define CPUFREQ_ETERNAL (-1)
68struct cpufreq_cpuinfo {
69 unsigned int max_freq;
70 unsigned int min_freq;
71 unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
72};
73
74struct cpufreq_real_policy {
75 unsigned int min; /* in kHz */
76 unsigned int max; /* in kHz */
77 unsigned int policy; /* see above */
78 struct cpufreq_governor *governor; /* see below */
79};
80
81struct cpufreq_policy {
82 cpumask_t cpus; /* affected CPUs */
3b2d9942
VP
83 unsigned int shared_type; /* ANY or ALL affected CPUs
84 should set cpufreq */
1da177e4
LT
85 unsigned int cpu; /* cpu nr of registered CPU */
86 struct cpufreq_cpuinfo cpuinfo;/* see above */
87
88 unsigned int min; /* in kHz */
89 unsigned int max; /* in kHz */
90 unsigned int cur; /* in kHz, only needed if cpufreq
91 * governors are used */
92 unsigned int policy; /* see above */
93 struct cpufreq_governor *governor; /* see below */
94
1da177e4
LT
95 struct work_struct update; /* if update_policy() needs to be
96 * called, but you're in IRQ context */
97
98 struct cpufreq_real_policy user_policy;
99
100 struct kobject kobj;
101 struct completion kobj_unregister;
102};
103
104#define CPUFREQ_ADJUST (0)
105#define CPUFREQ_INCOMPATIBLE (1)
106#define CPUFREQ_NOTIFY (2)
107
46f18e3a
VP
108#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
109#define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
110#define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
111#define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
1da177e4
LT
112
113/******************** cpufreq transition notifiers *******************/
114
115#define CPUFREQ_PRECHANGE (0)
116#define CPUFREQ_POSTCHANGE (1)
117#define CPUFREQ_RESUMECHANGE (8)
42d4dc3f 118#define CPUFREQ_SUSPENDCHANGE (9)
1da177e4
LT
119
120struct cpufreq_freqs {
121 unsigned int cpu; /* cpu nr */
122 unsigned int old;
123 unsigned int new;
124 u8 flags; /* flags of cpufreq_driver, see below. */
125};
126
127
128/**
129 * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
130 * @old: old value
131 * @div: divisor
132 * @mult: multiplier
133 *
134 *
135 * new = old * mult / div
136 */
137static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
138{
139#if BITS_PER_LONG == 32
140
141 u64 result = ((u64) old) * ((u64) mult);
142 do_div(result, div);
143 return (unsigned long) result;
144
145#elif BITS_PER_LONG == 64
146
147 unsigned long result = old * ((u64) mult);
148 result /= div;
149 return result;
150
151#endif
152};
153
154/*********************************************************************
155 * CPUFREQ GOVERNORS *
156 *********************************************************************/
157
158#define CPUFREQ_GOV_START 1
159#define CPUFREQ_GOV_STOP 2
160#define CPUFREQ_GOV_LIMITS 3
161
162struct cpufreq_governor {
163 char name[CPUFREQ_NAME_LEN];
164 int (*governor) (struct cpufreq_policy *policy,
165 unsigned int event);
166 struct list_head governor_list;
167 struct module *owner;
168};
169
170/* pass a target to the cpufreq driver
171 */
172extern int cpufreq_driver_target(struct cpufreq_policy *policy,
173 unsigned int target_freq,
174 unsigned int relation);
175extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
176 unsigned int target_freq,
177 unsigned int relation);
178
179
5a01f2e8 180extern int __cpufreq_driver_getavg(struct cpufreq_policy *policy);
dfde5d62 181
1da177e4
LT
182int cpufreq_register_governor(struct cpufreq_governor *governor);
183void cpufreq_unregister_governor(struct cpufreq_governor *governor);
184
5a01f2e8
VP
185int lock_policy_rwsem_read(int cpu);
186int lock_policy_rwsem_write(int cpu);
187void unlock_policy_rwsem_read(int cpu);
188void unlock_policy_rwsem_write(int cpu);
189
1da177e4
LT
190
191/*********************************************************************
192 * CPUFREQ DRIVER INTERFACE *
193 *********************************************************************/
194
195#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
196#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
197
198struct freq_attr;
199
200struct cpufreq_driver {
201 struct module *owner;
202 char name[CPUFREQ_NAME_LEN];
203 u8 flags;
204
205 /* needed by all drivers */
206 int (*init) (struct cpufreq_policy *policy);
207 int (*verify) (struct cpufreq_policy *policy);
208
209 /* define one out of two */
210 int (*setpolicy) (struct cpufreq_policy *policy);
211 int (*target) (struct cpufreq_policy *policy,
212 unsigned int target_freq,
213 unsigned int relation);
214
215 /* should be defined, if possible */
216 unsigned int (*get) (unsigned int cpu);
217
218 /* optional */
dfde5d62 219 unsigned int (*getavg) (unsigned int cpu);
1da177e4 220 int (*exit) (struct cpufreq_policy *policy);
e00d9967 221 int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
1da177e4
LT
222 int (*resume) (struct cpufreq_policy *policy);
223 struct freq_attr **attr;
224};
225
226/* flags */
227
228#define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
229 * all ->init() calls failed */
230#define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
231 * "constants" aren't affected by
232 * frequency transitions */
42d4dc3f
BH
233#define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
234 * mismatches */
1da177e4 235
221dee28
LT
236int cpufreq_register_driver(struct cpufreq_driver *driver_data);
237int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
1da177e4
LT
238
239
240void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
241
242
243static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
244{
245 if (policy->min < min)
246 policy->min = min;
247 if (policy->max < min)
248 policy->max = min;
249 if (policy->min > max)
250 policy->min = max;
251 if (policy->max > max)
252 policy->max = max;
253 if (policy->min > policy->max)
254 policy->min = policy->max;
255 return;
256}
257
258struct freq_attr {
259 struct attribute attr;
260 ssize_t (*show)(struct cpufreq_policy *, char *);
261 ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
262};
263
264
265/*********************************************************************
266 * CPUFREQ 2.6. INTERFACE *
267 *********************************************************************/
1da177e4
LT
268int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
269int cpufreq_update_policy(unsigned int cpu);
270
1da177e4 271
184c44d2
AM
272/*
273 * query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it
274 */
95235ca2
VP
275#ifdef CONFIG_CPU_FREQ
276unsigned int cpufreq_quick_get(unsigned int cpu);
184c44d2 277unsigned int cpufreq_get(unsigned int cpu);
95235ca2
VP
278#else
279static inline unsigned int cpufreq_quick_get(unsigned int cpu)
280{
281 return 0;
282}
184c44d2
AM
283static inline unsigned int cpufreq_get(unsigned int cpu)
284{
285 return 0;
286}
95235ca2
VP
287#endif
288
1da177e4
LT
289
290/*********************************************************************
291 * CPUFREQ DEFAULT GOVERNOR *
292 *********************************************************************/
293
294
295#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
296extern struct cpufreq_governor cpufreq_gov_performance;
297#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
298#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
299extern struct cpufreq_governor cpufreq_gov_userspace;
300#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
301#endif
302
303
304/*********************************************************************
305 * FREQUENCY TABLE HELPERS *
306 *********************************************************************/
307
308#define CPUFREQ_ENTRY_INVALID ~0
309#define CPUFREQ_TABLE_END ~1
310
311struct cpufreq_frequency_table {
312 unsigned int index; /* any */
313 unsigned int frequency; /* kHz - doesn't need to be in ascending
314 * order */
315};
316
317int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
318 struct cpufreq_frequency_table *table);
319
320int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
321 struct cpufreq_frequency_table *table);
322
323int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
324 struct cpufreq_frequency_table *table,
325 unsigned int target_freq,
326 unsigned int relation,
327 unsigned int *index);
328
329/* the following 3 funtions are for cpufreq core use only */
330struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
331struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
332void cpufreq_cpu_put (struct cpufreq_policy *data);
333
334/* the following are really really optional */
335extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
336
337void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
338 unsigned int cpu);
339
340void cpufreq_frequency_table_put_attr(unsigned int cpu);
341
342
343/*********************************************************************
344 * UNIFIED DEBUG HELPERS *
345 *********************************************************************/
346
347#define CPUFREQ_DEBUG_CORE 1
348#define CPUFREQ_DEBUG_DRIVER 2
349#define CPUFREQ_DEBUG_GOVERNOR 4
350
351#ifdef CONFIG_CPU_FREQ_DEBUG
352
353extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
354 const char *fmt, ...);
355
356#else
357
358#define cpufreq_debug_printk(msg...) do { } while(0)
359
360#endif /* CONFIG_CPU_FREQ_DEBUG */
361
362#endif /* _LINUX_CPUFREQ_H */