]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/cpuidle.h
cpuidle: build fix for non-x86
[linux-2.6-omap-h63xx.git] / include / linux / cpuidle.h
1 /*
2  * cpuidle.h - a generic framework for CPU idle power management
3  *
4  * (C) 2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5  *          Shaohua Li <shaohua.li@intel.com>
6  *          Adam Belay <abelay@novell.com>
7  *
8  * This code is licenced under the GPL.
9  */
10
11 #ifndef _LINUX_CPUIDLE_H
12 #define _LINUX_CPUIDLE_H
13
14 #include <linux/percpu.h>
15 #include <linux/list.h>
16 #include <linux/module.h>
17 #include <linux/kobject.h>
18 #include <linux/completion.h>
19
20 #define CPUIDLE_STATE_MAX       8
21 #define CPUIDLE_NAME_LEN        16
22
23 struct cpuidle_device;
24
25
26 /****************************
27  * CPUIDLE DEVICE INTERFACE *
28  ****************************/
29
30 struct cpuidle_state {
31         char            name[CPUIDLE_NAME_LEN];
32         void            *driver_data;
33
34         unsigned int    flags;
35         unsigned int    exit_latency; /* in US */
36         unsigned int    power_usage; /* in mW */
37         unsigned int    target_residency; /* in US */
38
39         unsigned int    usage;
40         unsigned int    time; /* in US */
41
42         int (*enter)    (struct cpuidle_device *dev,
43                          struct cpuidle_state *state);
44 };
45
46 /* Idle State Flags */
47 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
48 #define CPUIDLE_FLAG_CHECK_BM   (0x02) /* BM activity will exit state */
49 #define CPUIDLE_FLAG_SHALLOW    (0x10) /* low latency, minimal savings */
50 #define CPUIDLE_FLAG_BALANCED   (0x20) /* medium latency, moderate savings */
51 #define CPUIDLE_FLAG_DEEP       (0x40) /* high latency, large savings */
52
53 #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
54
55 /**
56  * cpuidle_get_statedata - retrieves private driver state data
57  * @state: the state
58  */
59 static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
60 {
61         return state->driver_data;
62 }
63
64 /**
65  * cpuidle_set_statedata - stores private driver state data
66  * @state: the state
67  * @data: the private data
68  */
69 static inline void
70 cpuidle_set_statedata(struct cpuidle_state *state, void *data)
71 {
72         state->driver_data = data;
73 }
74
75 #ifdef CONFIG_SMP
76 #ifdef CONFIG_ARCH_HAS_CPU_IDLE_WAIT
77 static inline void cpuidle_kick_cpus(void)
78 {
79         cpu_idle_wait();
80 }
81 #else /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
82 #error "Arch needs cpu_idle_wait() equivalent here"
83 #endif /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
84 #else /* !CONFIG_SMP */
85 static inline void cpuidle_kick_cpus(void) {}
86 #endif /* !CONFIG_SMP */
87
88 struct cpuidle_state_kobj {
89         struct cpuidle_state *state;
90         struct completion kobj_unregister;
91         struct kobject kobj;
92 };
93
94 struct cpuidle_device {
95         int                     enabled:1;
96         unsigned int            cpu;
97
98         int                     last_residency;
99         int                     state_count;
100         struct cpuidle_state    states[CPUIDLE_STATE_MAX];
101         struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
102         struct cpuidle_state    *last_state;
103
104         struct list_head        device_list;
105         struct kobject          kobj;
106         struct completion       kobj_unregister;
107         void                    *governor_data;
108 };
109
110 DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
111
112 /**
113  * cpuidle_get_last_residency - retrieves the last state's residency time
114  * @dev: the target CPU
115  *
116  * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
117  */
118 static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
119 {
120         return dev->last_residency;
121 }
122
123
124 /****************************
125  * CPUIDLE DRIVER INTERFACE *
126  ****************************/
127
128 struct cpuidle_driver {
129         char                    name[CPUIDLE_NAME_LEN];
130         struct module           *owner;
131 };
132
133 #ifdef CONFIG_CPU_IDLE
134
135 extern int cpuidle_register_driver(struct cpuidle_driver *drv);
136 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
137 extern int cpuidle_register_device(struct cpuidle_device *dev);
138 extern void cpuidle_unregister_device(struct cpuidle_device *dev);
139
140 extern void cpuidle_pause_and_lock(void);
141 extern void cpuidle_resume_and_unlock(void);
142 extern int cpuidle_enable_device(struct cpuidle_device *dev);
143 extern void cpuidle_disable_device(struct cpuidle_device *dev);
144
145 #else
146
147 static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
148 {return 0;}
149 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
150 static inline int cpuidle_register_device(struct cpuidle_device *dev)
151 {return 0;}
152 static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
153
154 static inline void cpuidle_pause_and_lock(void) { }
155 static inline void cpuidle_resume_and_unlock(void) { }
156 static inline int cpuidle_enable_device(struct cpuidle_device *dev)
157 {return 0;}
158 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
159
160 #endif
161
162 /******************************
163  * CPUIDLE GOVERNOR INTERFACE *
164  ******************************/
165
166 struct cpuidle_governor {
167         char                    name[CPUIDLE_NAME_LEN];
168         struct list_head        governor_list;
169         unsigned int            rating;
170
171         int  (*enable)          (struct cpuidle_device *dev);
172         void (*disable)         (struct cpuidle_device *dev);
173
174         int  (*select)          (struct cpuidle_device *dev);
175         void (*reflect)         (struct cpuidle_device *dev);
176
177         struct module           *owner;
178 };
179
180 #ifdef CONFIG_CPU_IDLE
181
182 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
183 extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
184
185 #else
186
187 static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
188 {return 0;}
189 static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
190
191 #endif
192
193 #endif /* _LINUX_CPUIDLE_H */