]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - include/linux/cpuidle.h
Merge branches 'release' and 'stats' into release
[mirror_ubuntu-artful-kernel.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_POLL (0x10) /* no latency, no savings */
50 #define CPUIDLE_FLAG_SHALLOW (0x20) /* low latency, minimal savings */
51 #define CPUIDLE_FLAG_BALANCED (0x40) /* medium latency, moderate savings */
52 #define CPUIDLE_FLAG_DEEP (0x80) /* high latency, large savings */
53
54 #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
55
56 /**
57 * cpuidle_get_statedata - retrieves private driver state data
58 * @state: the state
59 */
60 static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
61 {
62 return state->driver_data;
63 }
64
65 /**
66 * cpuidle_set_statedata - stores private driver state data
67 * @state: the state
68 * @data: the private data
69 */
70 static inline void
71 cpuidle_set_statedata(struct cpuidle_state *state, void *data)
72 {
73 state->driver_data = data;
74 }
75
76 #ifdef CONFIG_SMP
77 #ifdef CONFIG_ARCH_HAS_CPU_IDLE_WAIT
78 static inline void cpuidle_kick_cpus(void)
79 {
80 cpu_idle_wait();
81 }
82 #else /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
83 #error "Arch needs cpu_idle_wait() equivalent here"
84 #endif /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */
85 #else /* !CONFIG_SMP */
86 static inline void cpuidle_kick_cpus(void) {}
87 #endif /* !CONFIG_SMP */
88
89 struct cpuidle_state_kobj {
90 struct cpuidle_state *state;
91 struct completion kobj_unregister;
92 struct kobject kobj;
93 };
94
95 struct cpuidle_device {
96 unsigned int enabled:1;
97 unsigned int cpu;
98
99 int last_residency;
100 int state_count;
101 struct cpuidle_state states[CPUIDLE_STATE_MAX];
102 struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
103 struct cpuidle_state *last_state;
104
105 struct list_head device_list;
106 struct kobject kobj;
107 struct completion kobj_unregister;
108 void *governor_data;
109 struct cpuidle_state *safe_state;
110 };
111
112 DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
113
114 /**
115 * cpuidle_get_last_residency - retrieves the last state's residency time
116 * @dev: the target CPU
117 *
118 * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
119 */
120 static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
121 {
122 return dev->last_residency;
123 }
124
125
126 /****************************
127 * CPUIDLE DRIVER INTERFACE *
128 ****************************/
129
130 struct cpuidle_driver {
131 char name[CPUIDLE_NAME_LEN];
132 struct module *owner;
133 };
134
135 #ifdef CONFIG_CPU_IDLE
136
137 extern int cpuidle_register_driver(struct cpuidle_driver *drv);
138 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
139 extern int cpuidle_register_device(struct cpuidle_device *dev);
140 extern void cpuidle_unregister_device(struct cpuidle_device *dev);
141
142 extern void cpuidle_pause_and_lock(void);
143 extern void cpuidle_resume_and_unlock(void);
144 extern int cpuidle_enable_device(struct cpuidle_device *dev);
145 extern void cpuidle_disable_device(struct cpuidle_device *dev);
146
147 #else
148
149 static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
150 {return 0;}
151 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
152 static inline int cpuidle_register_device(struct cpuidle_device *dev)
153 {return 0;}
154 static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
155
156 static inline void cpuidle_pause_and_lock(void) { }
157 static inline void cpuidle_resume_and_unlock(void) { }
158 static inline int cpuidle_enable_device(struct cpuidle_device *dev)
159 {return 0;}
160 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
161
162 #endif
163
164 /******************************
165 * CPUIDLE GOVERNOR INTERFACE *
166 ******************************/
167
168 struct cpuidle_governor {
169 char name[CPUIDLE_NAME_LEN];
170 struct list_head governor_list;
171 unsigned int rating;
172
173 int (*enable) (struct cpuidle_device *dev);
174 void (*disable) (struct cpuidle_device *dev);
175
176 int (*select) (struct cpuidle_device *dev);
177 void (*reflect) (struct cpuidle_device *dev);
178
179 struct module *owner;
180 };
181
182 #ifdef CONFIG_CPU_IDLE
183
184 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
185 extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
186
187 #else
188
189 static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
190 {return 0;}
191 static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
192
193 #endif
194
195 #ifdef CONFIG_ARCH_HAS_CPU_RELAX
196 #define CPUIDLE_DRIVER_STATE_START 1
197 #else
198 #define CPUIDLE_DRIVER_STATE_START 0
199 #endif
200
201 #endif /* _LINUX_CPUIDLE_H */