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.
11 #ifndef _LINUX_CPUIDLE_H
12 #define _LINUX_CPUIDLE_H
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>
20 #define CPUIDLE_STATE_MAX 8
21 #define CPUIDLE_NAME_LEN 16
23 struct cpuidle_device
;
26 /****************************
27 * CPUIDLE DEVICE INTERFACE *
28 ****************************/
30 struct cpuidle_state
{
31 char name
[CPUIDLE_NAME_LEN
];
35 unsigned int exit_latency
; /* in US */
36 unsigned int power_usage
; /* in mW */
37 unsigned int target_residency
; /* in US */
40 unsigned int time
; /* in US */
42 int (*enter
) (struct cpuidle_device
*dev
,
43 struct cpuidle_state
*state
);
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 */
54 #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
57 * cpuidle_get_statedata - retrieves private driver state data
60 static inline void * cpuidle_get_statedata(struct cpuidle_state
*state
)
62 return state
->driver_data
;
66 * cpuidle_set_statedata - stores private driver state data
68 * @data: the private data
71 cpuidle_set_statedata(struct cpuidle_state
*state
, void *data
)
73 state
->driver_data
= data
;
76 struct cpuidle_state_kobj
{
77 struct cpuidle_state
*state
;
78 struct completion kobj_unregister
;
82 struct cpuidle_device
{
83 unsigned int enabled
:1;
88 struct cpuidle_state states
[CPUIDLE_STATE_MAX
];
89 struct cpuidle_state_kobj
*kobjs
[CPUIDLE_STATE_MAX
];
90 struct cpuidle_state
*last_state
;
92 struct list_head device_list
;
94 struct completion kobj_unregister
;
96 struct cpuidle_state
*safe_state
;
99 DECLARE_PER_CPU(struct cpuidle_device
*, cpuidle_devices
);
102 * cpuidle_get_last_residency - retrieves the last state's residency time
103 * @dev: the target CPU
105 * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
107 static inline int cpuidle_get_last_residency(struct cpuidle_device
*dev
)
109 return dev
->last_residency
;
113 /****************************
114 * CPUIDLE DRIVER INTERFACE *
115 ****************************/
117 struct cpuidle_driver
{
118 char name
[CPUIDLE_NAME_LEN
];
119 struct module
*owner
;
122 #ifdef CONFIG_CPU_IDLE
124 extern int cpuidle_register_driver(struct cpuidle_driver
*drv
);
125 extern void cpuidle_unregister_driver(struct cpuidle_driver
*drv
);
126 extern int cpuidle_register_device(struct cpuidle_device
*dev
);
127 extern void cpuidle_unregister_device(struct cpuidle_device
*dev
);
129 extern void cpuidle_pause_and_lock(void);
130 extern void cpuidle_resume_and_unlock(void);
131 extern int cpuidle_enable_device(struct cpuidle_device
*dev
);
132 extern void cpuidle_disable_device(struct cpuidle_device
*dev
);
136 static inline int cpuidle_register_driver(struct cpuidle_driver
*drv
)
138 static inline void cpuidle_unregister_driver(struct cpuidle_driver
*drv
) { }
139 static inline int cpuidle_register_device(struct cpuidle_device
*dev
)
141 static inline void cpuidle_unregister_device(struct cpuidle_device
*dev
) { }
143 static inline void cpuidle_pause_and_lock(void) { }
144 static inline void cpuidle_resume_and_unlock(void) { }
145 static inline int cpuidle_enable_device(struct cpuidle_device
*dev
)
147 static inline void cpuidle_disable_device(struct cpuidle_device
*dev
) { }
151 /******************************
152 * CPUIDLE GOVERNOR INTERFACE *
153 ******************************/
155 struct cpuidle_governor
{
156 char name
[CPUIDLE_NAME_LEN
];
157 struct list_head governor_list
;
160 int (*enable
) (struct cpuidle_device
*dev
);
161 void (*disable
) (struct cpuidle_device
*dev
);
163 int (*select
) (struct cpuidle_device
*dev
);
164 void (*reflect
) (struct cpuidle_device
*dev
);
166 struct module
*owner
;
169 #ifdef CONFIG_CPU_IDLE
171 extern int cpuidle_register_governor(struct cpuidle_governor
*gov
);
172 extern void cpuidle_unregister_governor(struct cpuidle_governor
*gov
);
176 static inline int cpuidle_register_governor(struct cpuidle_governor
*gov
)
178 static inline void cpuidle_unregister_governor(struct cpuidle_governor
*gov
) { }
182 #ifdef CONFIG_ARCH_HAS_CPU_RELAX
183 #define CPUIDLE_DRIVER_STATE_START 1
185 #define CPUIDLE_DRIVER_STATE_START 0
188 #endif /* _LINUX_CPUIDLE_H */