Linux Audio

Check our new training course

Loading...
v5.14.15
  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/hrtimer.h>
 
 17
 18#define CPUIDLE_STATE_MAX	10
 19#define CPUIDLE_NAME_LEN	16
 20#define CPUIDLE_DESC_LEN	32
 21
 22struct module;
 23
 24struct cpuidle_device;
 25struct cpuidle_driver;
 26
 27
 28/****************************
 29 * CPUIDLE DEVICE INTERFACE *
 30 ****************************/
 31
 32#define CPUIDLE_STATE_DISABLED_BY_USER		BIT(0)
 33#define CPUIDLE_STATE_DISABLED_BY_DRIVER	BIT(1)
 34
 35struct cpuidle_state_usage {
 36	unsigned long long	disable;
 37	unsigned long long	usage;
 38	u64			time_ns;
 39	unsigned long long	above; /* Number of times it's been too deep */
 40	unsigned long long	below; /* Number of times it's been too shallow */
 41	unsigned long long	rejected; /* Number of times idle entry was rejected */
 42#ifdef CONFIG_SUSPEND
 43	unsigned long long	s2idle_usage;
 44	unsigned long long	s2idle_time; /* in US */
 45#endif
 46};
 47
 48struct cpuidle_state {
 49	char		name[CPUIDLE_NAME_LEN];
 50	char		desc[CPUIDLE_DESC_LEN];
 51
 52	s64		exit_latency_ns;
 53	s64		target_residency_ns;
 54	unsigned int	flags;
 55	unsigned int	exit_latency; /* in US */
 56	int		power_usage; /* in mW */
 57	unsigned int	target_residency; /* in US */
 58
 59	int (*enter)	(struct cpuidle_device *dev,
 60			struct cpuidle_driver *drv,
 61			int index);
 62
 63	int (*enter_dead) (struct cpuidle_device *dev, int index);
 64
 65	/*
 66	 * CPUs execute ->enter_s2idle with the local tick or entire timekeeping
 67	 * suspended, so it must not re-enable interrupts at any point (even
 68	 * temporarily) or attempt to change states of clock event devices.
 69	 *
 70	 * This callback may point to the same function as ->enter if all of
 71	 * the above requirements are met by it.
 72	 */
 73	int (*enter_s2idle)(struct cpuidle_device *dev,
 74			    struct cpuidle_driver *drv,
 75			    int index);
 76};
 77
 78/* Idle State Flags */
 79#define CPUIDLE_FLAG_NONE       	(0x00)
 80#define CPUIDLE_FLAG_POLLING		BIT(0) /* polling state */
 81#define CPUIDLE_FLAG_COUPLED		BIT(1) /* state applies to multiple cpus */
 82#define CPUIDLE_FLAG_TIMER_STOP 	BIT(2) /* timer is stopped on this state */
 83#define CPUIDLE_FLAG_UNUSABLE		BIT(3) /* avoid using this state */
 84#define CPUIDLE_FLAG_OFF		BIT(4) /* disable this state by default */
 85#define CPUIDLE_FLAG_TLB_FLUSHED	BIT(5) /* idle-state flushes TLBs */
 86#define CPUIDLE_FLAG_RCU_IDLE		BIT(6) /* idle-state takes care of RCU */
 87
 88struct cpuidle_device_kobj;
 89struct cpuidle_state_kobj;
 90struct cpuidle_driver_kobj;
 91
 92struct cpuidle_device {
 93	unsigned int		registered:1;
 94	unsigned int		enabled:1;
 95	unsigned int		poll_time_limit:1;
 96	unsigned int		cpu;
 97	ktime_t			next_hrtimer;
 98
 99	int			last_state_idx;
100	u64			last_residency_ns;
101	u64			poll_limit_ns;
102	u64			forced_idle_latency_limit_ns;
103	struct cpuidle_state_usage	states_usage[CPUIDLE_STATE_MAX];
104	struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
105	struct cpuidle_driver_kobj *kobj_driver;
106	struct cpuidle_device_kobj *kobj_dev;
107	struct list_head 	device_list;
108
109#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
110	cpumask_t		coupled_cpus;
111	struct cpuidle_coupled	*coupled;
112#endif
113};
114
115DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
116DECLARE_PER_CPU(struct cpuidle_device, cpuidle_dev);
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118/****************************
119 * CPUIDLE DRIVER INTERFACE *
120 ****************************/
121
122struct cpuidle_driver {
123	const char		*name;
124	struct module 		*owner;
125
126        /* used by the cpuidle framework to setup the broadcast timer */
127	unsigned int            bctimer:1;
128	/* states array must be ordered in decreasing power consumption */
129	struct cpuidle_state	states[CPUIDLE_STATE_MAX];
130	int			state_count;
131	int			safe_state_index;
132
133	/* the driver handles the cpus in cpumask */
134	struct cpumask		*cpumask;
135
136	/* preferred governor to switch at register time */
137	const char		*governor;
138};
139
140#ifdef CONFIG_CPU_IDLE
141extern void disable_cpuidle(void);
142extern bool cpuidle_not_available(struct cpuidle_driver *drv,
143				  struct cpuidle_device *dev);
144
145extern int cpuidle_select(struct cpuidle_driver *drv,
146			  struct cpuidle_device *dev,
147			  bool *stop_tick);
148extern int cpuidle_enter(struct cpuidle_driver *drv,
149			 struct cpuidle_device *dev, int index);
150extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
151extern u64 cpuidle_poll_time(struct cpuidle_driver *drv,
152			     struct cpuidle_device *dev);
153
154extern int cpuidle_register_driver(struct cpuidle_driver *drv);
155extern struct cpuidle_driver *cpuidle_get_driver(void);
156extern void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, int idx,
157					bool disable);
158extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
159extern int cpuidle_register_device(struct cpuidle_device *dev);
160extern void cpuidle_unregister_device(struct cpuidle_device *dev);
161extern int cpuidle_register(struct cpuidle_driver *drv,
162			    const struct cpumask *const coupled_cpus);
163extern void cpuidle_unregister(struct cpuidle_driver *drv);
164extern void cpuidle_pause_and_lock(void);
165extern void cpuidle_resume_and_unlock(void);
166extern void cpuidle_pause(void);
167extern void cpuidle_resume(void);
168extern int cpuidle_enable_device(struct cpuidle_device *dev);
169extern void cpuidle_disable_device(struct cpuidle_device *dev);
170extern int cpuidle_play_dead(void);
171
172extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
173static inline struct cpuidle_device *cpuidle_get_device(void)
174{return __this_cpu_read(cpuidle_devices); }
175#else
176static inline void disable_cpuidle(void) { }
177static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
178					 struct cpuidle_device *dev)
179{return true; }
180static inline int cpuidle_select(struct cpuidle_driver *drv,
181				 struct cpuidle_device *dev, bool *stop_tick)
182{return -ENODEV; }
183static inline int cpuidle_enter(struct cpuidle_driver *drv,
184				struct cpuidle_device *dev, int index)
185{return -ENODEV; }
186static inline void cpuidle_reflect(struct cpuidle_device *dev, int index) { }
187static inline u64 cpuidle_poll_time(struct cpuidle_driver *drv,
188			     struct cpuidle_device *dev)
189{return 0; }
190static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
191{return -ENODEV; }
192static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
193static inline void cpuidle_driver_state_disabled(struct cpuidle_driver *drv,
194					       int idx, bool disable) { }
195static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
196static inline int cpuidle_register_device(struct cpuidle_device *dev)
197{return -ENODEV; }
198static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
199static inline int cpuidle_register(struct cpuidle_driver *drv,
200				   const struct cpumask *const coupled_cpus)
201{return -ENODEV; }
202static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
203static inline void cpuidle_pause_and_lock(void) { }
204static inline void cpuidle_resume_and_unlock(void) { }
205static inline void cpuidle_pause(void) { }
206static inline void cpuidle_resume(void) { }
207static inline int cpuidle_enable_device(struct cpuidle_device *dev)
208{return -ENODEV; }
209static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
210static inline int cpuidle_play_dead(void) {return -ENODEV; }
211static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
212	struct cpuidle_device *dev) {return NULL; }
213static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
214#endif
215
216#ifdef CONFIG_CPU_IDLE
217extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
218				      struct cpuidle_device *dev,
219				      u64 latency_limit_ns);
220extern int cpuidle_enter_s2idle(struct cpuidle_driver *drv,
221				struct cpuidle_device *dev);
222extern void cpuidle_use_deepest_state(u64 latency_limit_ns);
223#else
224static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
225					     struct cpuidle_device *dev,
226					     u64 latency_limit_ns)
227{return -ENODEV; }
228static inline int cpuidle_enter_s2idle(struct cpuidle_driver *drv,
229				       struct cpuidle_device *dev)
230{return -ENODEV; }
231static inline void cpuidle_use_deepest_state(u64 latency_limit_ns)
232{
233}
234#endif
235
236/* kernel/sched/idle.c */
237extern void sched_idle_set_state(struct cpuidle_state *idle_state);
238extern void default_idle_call(void);
239
240#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
241void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
242#else
243static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
244{
245}
246#endif
247
248#if defined(CONFIG_CPU_IDLE) && defined(CONFIG_ARCH_HAS_CPU_RELAX)
249void cpuidle_poll_state_init(struct cpuidle_driver *drv);
250#else
251static inline void cpuidle_poll_state_init(struct cpuidle_driver *drv) {}
252#endif
253
254/******************************
255 * CPUIDLE GOVERNOR INTERFACE *
256 ******************************/
257
258struct cpuidle_governor {
259	char			name[CPUIDLE_NAME_LEN];
260	struct list_head 	governor_list;
261	unsigned int		rating;
262
263	int  (*enable)		(struct cpuidle_driver *drv,
264					struct cpuidle_device *dev);
265	void (*disable)		(struct cpuidle_driver *drv,
266					struct cpuidle_device *dev);
267
268	int  (*select)		(struct cpuidle_driver *drv,
269					struct cpuidle_device *dev,
270					bool *stop_tick);
271	void (*reflect)		(struct cpuidle_device *dev, int index);
272};
273
274extern int cpuidle_register_governor(struct cpuidle_governor *gov);
275extern s64 cpuidle_governor_latency_req(unsigned int cpu);
276
277#define __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter,			\
278				idx,					\
279				state,					\
280				is_retention)				\
281({									\
282	int __ret = 0;							\
283									\
284	if (!idx) {							\
285		cpu_do_idle();						\
286		return idx;						\
287	}								\
288									\
289	if (!is_retention)						\
290		__ret =  cpu_pm_enter();				\
291	if (!__ret) {							\
 
 
292		__ret = low_level_idle_enter(state);			\
 
 
293		if (!is_retention)					\
294			cpu_pm_exit();					\
295	}								\
296									\
297	__ret ? -1 : idx;						\
298})
299
300#define CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx)	\
301	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, idx, 0)
302
303#define CPU_PM_CPU_IDLE_ENTER_RETENTION(low_level_idle_enter, idx)	\
304	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, idx, 1)
305
306#define CPU_PM_CPU_IDLE_ENTER_PARAM(low_level_idle_enter, idx, state)	\
307	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 0)
 
 
 
308
309#define CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(low_level_idle_enter, idx, state)	\
310	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 1)
 
 
 
311
312#endif /* _LINUX_CPUIDLE_H */
v6.9.4
  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/hrtimer.h>
 17#include <linux/context_tracking.h>
 18
 19#define CPUIDLE_STATE_MAX	10
 20#define CPUIDLE_NAME_LEN	16
 21#define CPUIDLE_DESC_LEN	32
 22
 23struct module;
 24
 25struct cpuidle_device;
 26struct cpuidle_driver;
 27
 28
 29/****************************
 30 * CPUIDLE DEVICE INTERFACE *
 31 ****************************/
 32
 33#define CPUIDLE_STATE_DISABLED_BY_USER		BIT(0)
 34#define CPUIDLE_STATE_DISABLED_BY_DRIVER	BIT(1)
 35
 36struct cpuidle_state_usage {
 37	unsigned long long	disable;
 38	unsigned long long	usage;
 39	u64			time_ns;
 40	unsigned long long	above; /* Number of times it's been too deep */
 41	unsigned long long	below; /* Number of times it's been too shallow */
 42	unsigned long long	rejected; /* Number of times idle entry was rejected */
 43#ifdef CONFIG_SUSPEND
 44	unsigned long long	s2idle_usage;
 45	unsigned long long	s2idle_time; /* in US */
 46#endif
 47};
 48
 49struct cpuidle_state {
 50	char		name[CPUIDLE_NAME_LEN];
 51	char		desc[CPUIDLE_DESC_LEN];
 52
 53	s64		exit_latency_ns;
 54	s64		target_residency_ns;
 55	unsigned int	flags;
 56	unsigned int	exit_latency; /* in US */
 57	int		power_usage; /* in mW */
 58	unsigned int	target_residency; /* in US */
 59
 60	int (*enter)	(struct cpuidle_device *dev,
 61			struct cpuidle_driver *drv,
 62			int index);
 63
 64	int (*enter_dead) (struct cpuidle_device *dev, int index);
 65
 66	/*
 67	 * CPUs execute ->enter_s2idle with the local tick or entire timekeeping
 68	 * suspended, so it must not re-enable interrupts at any point (even
 69	 * temporarily) or attempt to change states of clock event devices.
 70	 *
 71	 * This callback may point to the same function as ->enter if all of
 72	 * the above requirements are met by it.
 73	 */
 74	int (*enter_s2idle)(struct cpuidle_device *dev,
 75			    struct cpuidle_driver *drv,
 76			    int index);
 77};
 78
 79/* Idle State Flags */
 80#define CPUIDLE_FLAG_NONE       	(0x00)
 81#define CPUIDLE_FLAG_POLLING		BIT(0) /* polling state */
 82#define CPUIDLE_FLAG_COUPLED		BIT(1) /* state applies to multiple cpus */
 83#define CPUIDLE_FLAG_TIMER_STOP 	BIT(2) /* timer is stopped on this state */
 84#define CPUIDLE_FLAG_UNUSABLE		BIT(3) /* avoid using this state */
 85#define CPUIDLE_FLAG_OFF		BIT(4) /* disable this state by default */
 86#define CPUIDLE_FLAG_TLB_FLUSHED	BIT(5) /* idle-state flushes TLBs */
 87#define CPUIDLE_FLAG_RCU_IDLE		BIT(6) /* idle-state takes care of RCU */
 88
 89struct cpuidle_device_kobj;
 90struct cpuidle_state_kobj;
 91struct cpuidle_driver_kobj;
 92
 93struct cpuidle_device {
 94	unsigned int		registered:1;
 95	unsigned int		enabled:1;
 96	unsigned int		poll_time_limit:1;
 97	unsigned int		cpu;
 98	ktime_t			next_hrtimer;
 99
100	int			last_state_idx;
101	u64			last_residency_ns;
102	u64			poll_limit_ns;
103	u64			forced_idle_latency_limit_ns;
104	struct cpuidle_state_usage	states_usage[CPUIDLE_STATE_MAX];
105	struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
106	struct cpuidle_driver_kobj *kobj_driver;
107	struct cpuidle_device_kobj *kobj_dev;
108	struct list_head 	device_list;
109
110#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
111	cpumask_t		coupled_cpus;
112	struct cpuidle_coupled	*coupled;
113#endif
114};
115
116DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
117DECLARE_PER_CPU(struct cpuidle_device, cpuidle_dev);
118
119static __always_inline void ct_cpuidle_enter(void)
120{
121	lockdep_assert_irqs_disabled();
122	/*
123	 * Idle is allowed to (temporary) enable IRQs. It
124	 * will return with IRQs disabled.
125	 *
126	 * Trace IRQs enable here, then switch off RCU, and have
127	 * arch_cpu_idle() use raw_local_irq_enable(). Note that
128	 * ct_idle_enter() relies on lockdep IRQ state, so switch that
129	 * last -- this is very similar to the entry code.
130	 */
131	trace_hardirqs_on_prepare();
132	lockdep_hardirqs_on_prepare();
133	instrumentation_end();
134	ct_idle_enter();
135	lockdep_hardirqs_on(_RET_IP_);
136}
137
138static __always_inline void ct_cpuidle_exit(void)
139{
140	/*
141	 * Carefully undo the above.
142	 */
143	lockdep_hardirqs_off(_RET_IP_);
144	ct_idle_exit();
145	instrumentation_begin();
146}
147
148/****************************
149 * CPUIDLE DRIVER INTERFACE *
150 ****************************/
151
152struct cpuidle_driver {
153	const char		*name;
154	struct module 		*owner;
155
156        /* used by the cpuidle framework to setup the broadcast timer */
157	unsigned int            bctimer:1;
158	/* states array must be ordered in decreasing power consumption */
159	struct cpuidle_state	states[CPUIDLE_STATE_MAX];
160	int			state_count;
161	int			safe_state_index;
162
163	/* the driver handles the cpus in cpumask */
164	struct cpumask		*cpumask;
165
166	/* preferred governor to switch at register time */
167	const char		*governor;
168};
169
170#ifdef CONFIG_CPU_IDLE
171extern void disable_cpuidle(void);
172extern bool cpuidle_not_available(struct cpuidle_driver *drv,
173				  struct cpuidle_device *dev);
174
175extern int cpuidle_select(struct cpuidle_driver *drv,
176			  struct cpuidle_device *dev,
177			  bool *stop_tick);
178extern int cpuidle_enter(struct cpuidle_driver *drv,
179			 struct cpuidle_device *dev, int index);
180extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
181extern u64 cpuidle_poll_time(struct cpuidle_driver *drv,
182			     struct cpuidle_device *dev);
183
184extern int cpuidle_register_driver(struct cpuidle_driver *drv);
185extern struct cpuidle_driver *cpuidle_get_driver(void);
186extern void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, int idx,
187					bool disable);
188extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
189extern int cpuidle_register_device(struct cpuidle_device *dev);
190extern void cpuidle_unregister_device(struct cpuidle_device *dev);
191extern int cpuidle_register(struct cpuidle_driver *drv,
192			    const struct cpumask *const coupled_cpus);
193extern void cpuidle_unregister(struct cpuidle_driver *drv);
194extern void cpuidle_pause_and_lock(void);
195extern void cpuidle_resume_and_unlock(void);
196extern void cpuidle_pause(void);
197extern void cpuidle_resume(void);
198extern int cpuidle_enable_device(struct cpuidle_device *dev);
199extern void cpuidle_disable_device(struct cpuidle_device *dev);
200extern int cpuidle_play_dead(void);
201
202extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
203static inline struct cpuidle_device *cpuidle_get_device(void)
204{return __this_cpu_read(cpuidle_devices); }
205#else
206static inline void disable_cpuidle(void) { }
207static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
208					 struct cpuidle_device *dev)
209{return true; }
210static inline int cpuidle_select(struct cpuidle_driver *drv,
211				 struct cpuidle_device *dev, bool *stop_tick)
212{return -ENODEV; }
213static inline int cpuidle_enter(struct cpuidle_driver *drv,
214				struct cpuidle_device *dev, int index)
215{return -ENODEV; }
216static inline void cpuidle_reflect(struct cpuidle_device *dev, int index) { }
217static inline u64 cpuidle_poll_time(struct cpuidle_driver *drv,
218			     struct cpuidle_device *dev)
219{return 0; }
220static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
221{return -ENODEV; }
222static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
223static inline void cpuidle_driver_state_disabled(struct cpuidle_driver *drv,
224					       int idx, bool disable) { }
225static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
226static inline int cpuidle_register_device(struct cpuidle_device *dev)
227{return -ENODEV; }
228static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
229static inline int cpuidle_register(struct cpuidle_driver *drv,
230				   const struct cpumask *const coupled_cpus)
231{return -ENODEV; }
232static inline void cpuidle_unregister(struct cpuidle_driver *drv) { }
233static inline void cpuidle_pause_and_lock(void) { }
234static inline void cpuidle_resume_and_unlock(void) { }
235static inline void cpuidle_pause(void) { }
236static inline void cpuidle_resume(void) { }
237static inline int cpuidle_enable_device(struct cpuidle_device *dev)
238{return -ENODEV; }
239static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
240static inline int cpuidle_play_dead(void) {return -ENODEV; }
241static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
242	struct cpuidle_device *dev) {return NULL; }
243static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
244#endif
245
246#ifdef CONFIG_CPU_IDLE
247extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
248				      struct cpuidle_device *dev,
249				      u64 latency_limit_ns);
250extern int cpuidle_enter_s2idle(struct cpuidle_driver *drv,
251				struct cpuidle_device *dev);
252extern void cpuidle_use_deepest_state(u64 latency_limit_ns);
253#else
254static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
255					     struct cpuidle_device *dev,
256					     u64 latency_limit_ns)
257{return -ENODEV; }
258static inline int cpuidle_enter_s2idle(struct cpuidle_driver *drv,
259				       struct cpuidle_device *dev)
260{return -ENODEV; }
261static inline void cpuidle_use_deepest_state(u64 latency_limit_ns)
262{
263}
264#endif
265
266/* kernel/sched/idle.c */
267extern void sched_idle_set_state(struct cpuidle_state *idle_state);
268extern void default_idle_call(void);
269
270#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
271void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a);
272#else
273static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, atomic_t *a)
274{
275}
276#endif
277
278#if defined(CONFIG_CPU_IDLE) && defined(CONFIG_ARCH_HAS_CPU_RELAX)
279void cpuidle_poll_state_init(struct cpuidle_driver *drv);
280#else
281static inline void cpuidle_poll_state_init(struct cpuidle_driver *drv) {}
282#endif
283
284/******************************
285 * CPUIDLE GOVERNOR INTERFACE *
286 ******************************/
287
288struct cpuidle_governor {
289	char			name[CPUIDLE_NAME_LEN];
290	struct list_head 	governor_list;
291	unsigned int		rating;
292
293	int  (*enable)		(struct cpuidle_driver *drv,
294					struct cpuidle_device *dev);
295	void (*disable)		(struct cpuidle_driver *drv,
296					struct cpuidle_device *dev);
297
298	int  (*select)		(struct cpuidle_driver *drv,
299					struct cpuidle_device *dev,
300					bool *stop_tick);
301	void (*reflect)		(struct cpuidle_device *dev, int index);
302};
303
304extern int cpuidle_register_governor(struct cpuidle_governor *gov);
305extern s64 cpuidle_governor_latency_req(unsigned int cpu);
306
307#define __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter,			\
308				idx,					\
309				state,					\
310				is_retention, is_rcu)			\
311({									\
312	int __ret = 0;							\
313									\
314	if (!idx) {							\
315		cpu_do_idle();						\
316		return idx;						\
317	}								\
318									\
319	if (!is_retention)						\
320		__ret =  cpu_pm_enter();				\
321	if (!__ret) {							\
322		if (!is_rcu)						\
323			ct_cpuidle_enter();				\
324		__ret = low_level_idle_enter(state);			\
325		if (!is_rcu)						\
326			ct_cpuidle_exit();				\
327		if (!is_retention)					\
328			cpu_pm_exit();					\
329	}								\
330									\
331	__ret ? -1 : idx;						\
332})
333
334#define CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx)	\
335	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, idx, 0, 0)
336
337#define CPU_PM_CPU_IDLE_ENTER_RETENTION(low_level_idle_enter, idx)	\
338	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, idx, 1, 0)
339
340#define CPU_PM_CPU_IDLE_ENTER_PARAM(low_level_idle_enter, idx, state)	\
341	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 0, 0)
342
343#define CPU_PM_CPU_IDLE_ENTER_PARAM_RCU(low_level_idle_enter, idx, state)	\
344	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 0, 1)
345
346#define CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(low_level_idle_enter, idx, state)	\
347	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 1, 0)
348
349#define CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM_RCU(low_level_idle_enter, idx, state)	\
350	__CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, state, 1, 1)
351
352#endif /* _LINUX_CPUIDLE_H */