include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / include / linux / cpuidle.h
blob583baf22cad20a6082b688d079dd24dd8aa3aa18
1 /*
2 * cpuidle.h - a generic framework for CPU idle power management
4 * (C) 2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
8 * This code is licenced under the GPL.
9 */
11 #ifndef _LINUX_CPUIDLE_H
12 #define _LINUX_CPUIDLE_H
14 #include <linux/percpu.h>
15 #include <linux/list.h>
16 #include <linux/kobject.h>
17 #include <linux/completion.h>
19 #define CPUIDLE_STATE_MAX 8
20 #define CPUIDLE_NAME_LEN 16
21 #define CPUIDLE_DESC_LEN 32
23 struct module;
25 struct cpuidle_device;
28 /****************************
29 * CPUIDLE DEVICE INTERFACE *
30 ****************************/
32 struct cpuidle_state {
33 char name[CPUIDLE_NAME_LEN];
34 char desc[CPUIDLE_DESC_LEN];
35 void *driver_data;
37 unsigned int flags;
38 unsigned int exit_latency; /* in US */
39 unsigned int power_usage; /* in mW */
40 unsigned int target_residency; /* in US */
42 unsigned long long usage;
43 unsigned long long time; /* in US */
45 int (*enter) (struct cpuidle_device *dev,
46 struct cpuidle_state *state);
49 /* Idle State Flags */
50 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
51 #define CPUIDLE_FLAG_IGNORE (0x100) /* ignore during this idle period */
53 #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
55 /**
56 * cpuidle_get_statedata - retrieves private driver state data
57 * @state: the state
59 static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
61 return state->driver_data;
64 /**
65 * cpuidle_set_statedata - stores private driver state data
66 * @state: the state
67 * @data: the private data
69 static inline void
70 cpuidle_set_statedata(struct cpuidle_state *state, void *data)
72 state->driver_data = data;
75 struct cpuidle_state_kobj {
76 struct cpuidle_state *state;
77 struct completion kobj_unregister;
78 struct kobject kobj;
81 struct cpuidle_device {
82 unsigned int registered:1;
83 unsigned int enabled:1;
84 unsigned int power_specified:1;
85 unsigned int cpu;
87 int last_residency;
88 int state_count;
89 struct cpuidle_state states[CPUIDLE_STATE_MAX];
90 struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
91 struct cpuidle_state *last_state;
93 struct list_head device_list;
94 struct kobject kobj;
95 struct completion kobj_unregister;
96 void *governor_data;
97 struct cpuidle_state *safe_state;
99 int (*prepare) (struct cpuidle_device *dev);
102 DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
105 * cpuidle_get_last_residency - retrieves the last state's residency time
106 * @dev: the target CPU
108 * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
110 static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
112 return dev->last_residency;
116 /****************************
117 * CPUIDLE DRIVER INTERFACE *
118 ****************************/
120 struct cpuidle_driver {
121 char name[CPUIDLE_NAME_LEN];
122 struct module *owner;
125 #ifdef CONFIG_CPU_IDLE
126 extern void disable_cpuidle(void);
127 extern int cpuidle_idle_call(void);
129 extern int cpuidle_register_driver(struct cpuidle_driver *drv);
130 struct cpuidle_driver *cpuidle_get_driver(void);
131 extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
132 extern int cpuidle_register_device(struct cpuidle_device *dev);
133 extern void cpuidle_unregister_device(struct cpuidle_device *dev);
135 extern void cpuidle_pause_and_lock(void);
136 extern void cpuidle_resume_and_unlock(void);
137 extern int cpuidle_enable_device(struct cpuidle_device *dev);
138 extern void cpuidle_disable_device(struct cpuidle_device *dev);
140 #else
141 static inline void disable_cpuidle(void) { }
142 static inline int cpuidle_idle_call(void) { return -ENODEV; }
144 static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
145 {return -ENODEV; }
146 static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
147 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
148 static inline int cpuidle_register_device(struct cpuidle_device *dev)
149 {return -ENODEV; }
150 static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
152 static inline void cpuidle_pause_and_lock(void) { }
153 static inline void cpuidle_resume_and_unlock(void) { }
154 static inline int cpuidle_enable_device(struct cpuidle_device *dev)
155 {return -ENODEV; }
156 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
158 #endif
160 /******************************
161 * CPUIDLE GOVERNOR INTERFACE *
162 ******************************/
164 struct cpuidle_governor {
165 char name[CPUIDLE_NAME_LEN];
166 struct list_head governor_list;
167 unsigned int rating;
169 int (*enable) (struct cpuidle_device *dev);
170 void (*disable) (struct cpuidle_device *dev);
172 int (*select) (struct cpuidle_device *dev);
173 void (*reflect) (struct cpuidle_device *dev);
175 struct module *owner;
178 #ifdef CONFIG_CPU_IDLE
180 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
181 extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
183 #else
185 static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
186 {return 0;}
187 static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
189 #endif
191 #ifdef CONFIG_ARCH_HAS_CPU_RELAX
192 #define CPUIDLE_DRIVER_STATE_START 1
193 #else
194 #define CPUIDLE_DRIVER_STATE_START 0
195 #endif
197 #endif /* _LINUX_CPUIDLE_H */