| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 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> | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 16 | #include <linux/kobject.h> | 
 | 17 | #include <linux/completion.h> | 
 | 18 |  | 
 | 19 | #define CPUIDLE_STATE_MAX	8 | 
 | 20 | #define CPUIDLE_NAME_LEN	16 | 
| Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 21 | #define CPUIDLE_DESC_LEN	32 | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 22 |  | 
| Paul Gortmaker | de47725 | 2011-05-26 13:46:22 -0400 | [diff] [blame] | 23 | struct module; | 
 | 24 |  | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 25 | struct cpuidle_device; | 
| Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 26 | struct cpuidle_driver; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 27 |  | 
 | 28 |  | 
 | 29 | /**************************** | 
 | 30 |  * CPUIDLE DEVICE INTERFACE * | 
 | 31 |  ****************************/ | 
 | 32 |  | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 33 | struct cpuidle_state_usage { | 
 | 34 | 	void		*driver_data; | 
 | 35 |  | 
 | 36 | 	unsigned long long	usage; | 
 | 37 | 	unsigned long long	time; /* in US */ | 
 | 38 | }; | 
 | 39 |  | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 40 | struct cpuidle_state { | 
 | 41 | 	char		name[CPUIDLE_NAME_LEN]; | 
| Venkatesh Pallipadi | 4fcb2fc | 2008-02-11 17:46:31 -0800 | [diff] [blame] | 42 | 	char		desc[CPUIDLE_DESC_LEN]; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 43 |  | 
 | 44 | 	unsigned int	flags; | 
 | 45 | 	unsigned int	exit_latency; /* in US */ | 
 | 46 | 	unsigned int	power_usage; /* in mW */ | 
 | 47 | 	unsigned int	target_residency; /* in US */ | 
 | 48 |  | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 49 | 	int (*enter)	(struct cpuidle_device *dev, | 
| Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 50 | 			struct cpuidle_driver *drv, | 
| Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 51 | 			int index); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 52 | }; | 
 | 53 |  | 
 | 54 | /* Idle State Flags */ | 
 | 55 | #define CPUIDLE_FLAG_TIME_VALID	(0x01) /* is residency time measurable? */ | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 56 |  | 
 | 57 | #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000) | 
 | 58 |  | 
 | 59 | /** | 
 | 60 |  * cpuidle_get_statedata - retrieves private driver state data | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 61 |  * @st_usage: the state usage statistics | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 62 |  */ | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 63 | static inline void *cpuidle_get_statedata(struct cpuidle_state_usage *st_usage) | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 64 | { | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 65 | 	return st_usage->driver_data; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 66 | } | 
 | 67 |  | 
 | 68 | /** | 
 | 69 |  * cpuidle_set_statedata - stores private driver state data | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 70 |  * @st_usage: the state usage statistics | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 71 |  * @data: the private data | 
 | 72 |  */ | 
 | 73 | static inline void | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 74 | cpuidle_set_statedata(struct cpuidle_state_usage *st_usage, void *data) | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 75 | { | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 76 | 	st_usage->driver_data = data; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 77 | } | 
 | 78 |  | 
 | 79 | struct cpuidle_state_kobj { | 
 | 80 | 	struct cpuidle_state *state; | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 81 | 	struct cpuidle_state_usage *state_usage; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 82 | 	struct completion kobj_unregister; | 
 | 83 | 	struct kobject kobj; | 
 | 84 | }; | 
 | 85 |  | 
 | 86 | struct cpuidle_device { | 
| Venkatesh Pallipadi | dcb84f3 | 2008-05-19 19:09:27 -0400 | [diff] [blame] | 87 | 	unsigned int		registered:1; | 
| Harvey Harrison | b5556a6 | 2008-02-06 22:39:44 +0100 | [diff] [blame] | 88 | 	unsigned int		enabled:1; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 89 | 	unsigned int		cpu; | 
 | 90 |  | 
 | 91 | 	int			last_residency; | 
 | 92 | 	int			state_count; | 
| Deepthi Dharwar | 4202735 | 2011-10-28 16:20:33 +0530 | [diff] [blame] | 93 | 	struct cpuidle_state_usage	states_usage[CPUIDLE_STATE_MAX]; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 94 | 	struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX]; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 95 |  | 
 | 96 | 	struct list_head 	device_list; | 
 | 97 | 	struct kobject		kobj; | 
 | 98 | 	struct completion	kobj_unregister; | 
 | 99 | 	void			*governor_data; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 100 | }; | 
 | 101 |  | 
 | 102 | DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices); | 
 | 103 |  | 
 | 104 | /** | 
 | 105 |  * cpuidle_get_last_residency - retrieves the last state's residency time | 
 | 106 |  * @dev: the target CPU | 
 | 107 |  * | 
 | 108 |  * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set | 
 | 109 |  */ | 
 | 110 | static inline int cpuidle_get_last_residency(struct cpuidle_device *dev) | 
 | 111 | { | 
 | 112 | 	return dev->last_residency; | 
 | 113 | } | 
 | 114 |  | 
 | 115 |  | 
 | 116 | /**************************** | 
 | 117 |  * CPUIDLE DRIVER INTERFACE * | 
 | 118 |  ****************************/ | 
 | 119 |  | 
 | 120 | struct cpuidle_driver { | 
 | 121 | 	char			name[CPUIDLE_NAME_LEN]; | 
 | 122 | 	struct module 		*owner; | 
| Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 123 |  | 
 | 124 | 	unsigned int		power_specified:1; | 
 | 125 | 	struct cpuidle_state	states[CPUIDLE_STATE_MAX]; | 
 | 126 | 	int			state_count; | 
 | 127 | 	int			safe_state_index; | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 128 | }; | 
 | 129 |  | 
 | 130 | #ifdef CONFIG_CPU_IDLE | 
| Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 131 | extern void disable_cpuidle(void); | 
| Len Brown | a0bfa13 | 2011-04-01 19:34:59 -0400 | [diff] [blame] | 132 | extern int cpuidle_idle_call(void); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 133 | extern int cpuidle_register_driver(struct cpuidle_driver *drv); | 
| Len Brown | 752138d | 2010-05-22 16:57:26 -0400 | [diff] [blame] | 134 | struct cpuidle_driver *cpuidle_get_driver(void); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 135 | extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); | 
 | 136 | extern int cpuidle_register_device(struct cpuidle_device *dev); | 
 | 137 | extern void cpuidle_unregister_device(struct cpuidle_device *dev); | 
 | 138 |  | 
 | 139 | extern void cpuidle_pause_and_lock(void); | 
 | 140 | extern void cpuidle_resume_and_unlock(void); | 
 | 141 | extern int cpuidle_enable_device(struct cpuidle_device *dev); | 
 | 142 | extern void cpuidle_disable_device(struct cpuidle_device *dev); | 
 | 143 |  | 
 | 144 | #else | 
| Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 145 | static inline void disable_cpuidle(void) { } | 
| Len Brown | a0bfa13 | 2011-04-01 19:34:59 -0400 | [diff] [blame] | 146 | static inline int cpuidle_idle_call(void) { return -ENODEV; } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 147 | static inline int cpuidle_register_driver(struct cpuidle_driver *drv) | 
| Len Brown | 6b2c676 | 2010-05-11 16:50:52 -0400 | [diff] [blame] | 148 | {return -ENODEV; } | 
| Len Brown | 752138d | 2010-05-22 16:57:26 -0400 | [diff] [blame] | 149 | static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 150 | static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { } | 
 | 151 | static inline int cpuidle_register_device(struct cpuidle_device *dev) | 
| Len Brown | 6b2c676 | 2010-05-11 16:50:52 -0400 | [diff] [blame] | 152 | {return -ENODEV; } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 153 | static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { } | 
 | 154 |  | 
 | 155 | static inline void cpuidle_pause_and_lock(void) { } | 
 | 156 | static inline void cpuidle_resume_and_unlock(void) { } | 
 | 157 | static inline int cpuidle_enable_device(struct cpuidle_device *dev) | 
| Len Brown | 6b2c676 | 2010-05-11 16:50:52 -0400 | [diff] [blame] | 158 | {return -ENODEV; } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 159 | static inline void cpuidle_disable_device(struct cpuidle_device *dev) { } | 
 | 160 |  | 
 | 161 | #endif | 
 | 162 |  | 
 | 163 | /****************************** | 
 | 164 |  * CPUIDLE GOVERNOR INTERFACE * | 
 | 165 |  ******************************/ | 
 | 166 |  | 
 | 167 | struct cpuidle_governor { | 
 | 168 | 	char			name[CPUIDLE_NAME_LEN]; | 
 | 169 | 	struct list_head 	governor_list; | 
 | 170 | 	unsigned int		rating; | 
 | 171 |  | 
| Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 172 | 	int  (*enable)		(struct cpuidle_driver *drv, | 
 | 173 | 					struct cpuidle_device *dev); | 
 | 174 | 	void (*disable)		(struct cpuidle_driver *drv, | 
 | 175 | 					struct cpuidle_device *dev); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 176 |  | 
| Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 177 | 	int  (*select)		(struct cpuidle_driver *drv, | 
 | 178 | 					struct cpuidle_device *dev); | 
| Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 179 | 	void (*reflect)		(struct cpuidle_device *dev, int index); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 180 |  | 
 | 181 | 	struct module 		*owner; | 
 | 182 | }; | 
 | 183 |  | 
 | 184 | #ifdef CONFIG_CPU_IDLE | 
 | 185 |  | 
 | 186 | extern int cpuidle_register_governor(struct cpuidle_governor *gov); | 
 | 187 | extern void cpuidle_unregister_governor(struct cpuidle_governor *gov); | 
 | 188 |  | 
| Thomas Renninger | 65b7f83 | 2012-01-17 22:40:08 +0100 | [diff] [blame] | 189 | #ifdef CONFIG_INTEL_IDLE | 
 | 190 | extern int intel_idle_cpu_init(int cpu); | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 191 | #else | 
| Thomas Renninger | 65b7f83 | 2012-01-17 22:40:08 +0100 | [diff] [blame] | 192 | static inline int intel_idle_cpu_init(int cpu) { return -1; } | 
 | 193 | #endif | 
 | 194 |  | 
 | 195 | #else | 
 | 196 | static inline int intel_idle_cpu_init(int cpu) { return -1; } | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 197 |  | 
 | 198 | static inline int cpuidle_register_governor(struct cpuidle_governor *gov) | 
 | 199 | {return 0;} | 
 | 200 | static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { } | 
 | 201 |  | 
 | 202 | #endif | 
 | 203 |  | 
| venkatesh.pallipadi@intel.com | 9a0b841 | 2008-01-31 17:35:06 -0800 | [diff] [blame] | 204 | #ifdef CONFIG_ARCH_HAS_CPU_RELAX | 
 | 205 | #define CPUIDLE_DRIVER_STATE_START	1 | 
 | 206 | #else | 
 | 207 | #define CPUIDLE_DRIVER_STATE_START	0 | 
 | 208 | #endif | 
 | 209 |  | 
| Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 210 | #endif /* _LINUX_CPUIDLE_H */ |