xref: /linux/kernel/irq/internals.h (revision 9c255583)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * IRQ subsystem internal functions and variables:
3dbec07baSThomas Gleixner  *
4dbec07baSThomas Gleixner  * Do not ever include this file from anything else than
5dbec07baSThomas Gleixner  * kernel/irq/. Do not even think about using any information outside
6dbec07baSThomas Gleixner  * of this file for your non core code.
71da177e4SLinus Torvalds  */
8e144710bSThomas Gleixner #include <linux/irqdesc.h>
98f945a33SThomas Gleixner #include <linux/kernel_stat.h>
101da177e4SLinus Torvalds 
11c1ee6264SThomas Gleixner #ifdef CONFIG_SPARSE_IRQ
12c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS	(NR_IRQS + 8196)
13c1ee6264SThomas Gleixner #else
14c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS	NR_IRQS
15c1ee6264SThomas Gleixner #endif
16c1ee6264SThomas Gleixner 
17dbec07baSThomas Gleixner #define istate core_internal_state__do_not_mess_with_it
18dbec07baSThomas Gleixner 
192329abfaSRusty Russell extern bool noirqdebug;
201da177e4SLinus Torvalds 
21e509bd7dSMika Westerberg extern struct irqaction chained_action;
22e509bd7dSMika Westerberg 
231535dfacSThomas Gleixner /*
241535dfacSThomas Gleixner  * Bits used by threaded handlers:
251535dfacSThomas Gleixner  * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
261535dfacSThomas Gleixner  * IRQTF_WARNED    - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
271535dfacSThomas Gleixner  * IRQTF_AFFINITY  - irq thread is requested to adjust affinity
288d32a307SThomas Gleixner  * IRQTF_FORCED_THREAD  - irq action is force threaded
291535dfacSThomas Gleixner  */
301535dfacSThomas Gleixner enum {
311535dfacSThomas Gleixner 	IRQTF_RUNTHREAD,
321535dfacSThomas Gleixner 	IRQTF_WARNED,
331535dfacSThomas Gleixner 	IRQTF_AFFINITY,
348d32a307SThomas Gleixner 	IRQTF_FORCED_THREAD,
351535dfacSThomas Gleixner };
361535dfacSThomas Gleixner 
37bd062e76SThomas Gleixner /*
38a257954bSJiang Liu  * Bit masks for desc->core_internal_state__do_not_mess_with_it
39bd062e76SThomas Gleixner  *
40bd062e76SThomas Gleixner  * IRQS_AUTODETECT		- autodetection in progress
417acdd53eSThomas Gleixner  * IRQS_SPURIOUS_DISABLED	- was disabled due to spurious interrupt
427acdd53eSThomas Gleixner  *				  detection
436954b75bSThomas Gleixner  * IRQS_POLL_INPROGRESS		- polling in progress
443d67baecSThomas Gleixner  * IRQS_ONESHOT			- irq is not unmasked in primary handler
45163ef309SThomas Gleixner  * IRQS_REPLAY			- irq is replayed
46163ef309SThomas Gleixner  * IRQS_WAITING			- irq is waiting
472a0d6fb3SThomas Gleixner  * IRQS_PENDING			- irq is pending and replayed later
48c531e836SThomas Gleixner  * IRQS_SUSPENDED		- irq is suspended
49bd062e76SThomas Gleixner  */
50bd062e76SThomas Gleixner enum {
51bd062e76SThomas Gleixner 	IRQS_AUTODETECT		= 0x00000001,
527acdd53eSThomas Gleixner 	IRQS_SPURIOUS_DISABLED	= 0x00000002,
536954b75bSThomas Gleixner 	IRQS_POLL_INPROGRESS	= 0x00000008,
543d67baecSThomas Gleixner 	IRQS_ONESHOT		= 0x00000020,
55163ef309SThomas Gleixner 	IRQS_REPLAY		= 0x00000040,
56163ef309SThomas Gleixner 	IRQS_WAITING		= 0x00000080,
572a0d6fb3SThomas Gleixner 	IRQS_PENDING		= 0x00000200,
58c531e836SThomas Gleixner 	IRQS_SUSPENDED		= 0x00000800,
59bd062e76SThomas Gleixner };
60bd062e76SThomas Gleixner 
611ce6068dSThomas Gleixner #include "debug.h"
621ce6068dSThomas Gleixner #include "settings.h"
631ce6068dSThomas Gleixner 
64a1ff541aSJiang Liu extern int __irq_set_trigger(struct irq_desc *desc, unsigned long flags);
6579ff1cdaSJiang Liu extern void __disable_irq(struct irq_desc *desc);
6679ff1cdaSJiang Liu extern void __enable_irq(struct irq_desc *desc);
670c5d1eb7SDavid Brownell 
68b4bc724eSThomas Gleixner extern int irq_startup(struct irq_desc *desc, bool resend);
6946999238SThomas Gleixner extern void irq_shutdown(struct irq_desc *desc);
7087923470SThomas Gleixner extern void irq_enable(struct irq_desc *desc);
7187923470SThomas Gleixner extern void irq_disable(struct irq_desc *desc);
7231d9d9b6SMarc Zyngier extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu);
7331d9d9b6SMarc Zyngier extern void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu);
74d4d5e089SThomas Gleixner extern void mask_irq(struct irq_desc *desc);
75d4d5e089SThomas Gleixner extern void unmask_irq(struct irq_desc *desc);
76328a4978SThomas Gleixner extern void unmask_threaded_irq(struct irq_desc *desc);
7746999238SThomas Gleixner 
78f63b6a05SThomas Gleixner #ifdef CONFIG_SPARSE_IRQ
79f63b6a05SThomas Gleixner static inline void irq_mark_irq(unsigned int irq) { }
80f63b6a05SThomas Gleixner #else
81f63b6a05SThomas Gleixner extern void irq_mark_irq(unsigned int irq);
82f63b6a05SThomas Gleixner #endif
83f63b6a05SThomas Gleixner 
8485ac16d0SYinghai Lu extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
850fa0ebbfSMike Travis 
8671f64340SHuang Shijie irqreturn_t handle_irq_event_percpu(struct irq_desc *desc);
874912609fSThomas Gleixner irqreturn_t handle_irq_event(struct irq_desc *desc);
884912609fSThomas Gleixner 
89e144710bSThomas Gleixner /* Resending of interrupts :*/
900798abebSJiang Liu void check_irq_resend(struct irq_desc *desc);
91fe200ae4SThomas Gleixner bool irq_wait_for_poll(struct irq_desc *desc);
92a92444c6SThomas Gleixner void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action);
93e144710bSThomas Gleixner 
941da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
952c6927a3SYinghai Lu extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
9613bfe99eSThomas Gleixner extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc);
971da177e4SLinus Torvalds extern void register_handler_proc(unsigned int irq, struct irqaction *action);
981da177e4SLinus Torvalds extern void unregister_handler_proc(unsigned int irq, struct irqaction *action);
991da177e4SLinus Torvalds #else
1002c6927a3SYinghai Lu static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { }
10113bfe99eSThomas Gleixner static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { }
1021da177e4SLinus Torvalds static inline void register_handler_proc(unsigned int irq,
1031da177e4SLinus Torvalds 					 struct irqaction *action) { }
1041da177e4SLinus Torvalds static inline void unregister_handler_proc(unsigned int irq,
1051da177e4SLinus Torvalds 					   struct irqaction *action) { }
1061da177e4SLinus Torvalds #endif
1071da177e4SLinus Torvalds 
108*9c255583SThomas Gleixner extern bool irq_can_set_affinity_usr(unsigned int irq);
109*9c255583SThomas Gleixner 
1103b8249e7SThomas Gleixner extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask);
111f6d87f4bSThomas Gleixner 
112591d2fb0SThomas Gleixner extern void irq_set_thread_affinity(struct irq_desc *desc);
11357b150ccSYinghai Lu 
114818b0f3bSJiang Liu extern int irq_do_set_affinity(struct irq_data *data,
115818b0f3bSJiang Liu 			       const struct cpumask *dest, bool force);
116818b0f3bSJiang Liu 
11770aedd24SThomas Gleixner /* Inline functions for support of irq chips on slow busses */
1183876ec9eSThomas Gleixner static inline void chip_bus_lock(struct irq_desc *desc)
11970aedd24SThomas Gleixner {
1203876ec9eSThomas Gleixner 	if (unlikely(desc->irq_data.chip->irq_bus_lock))
1213876ec9eSThomas Gleixner 		desc->irq_data.chip->irq_bus_lock(&desc->irq_data);
12270aedd24SThomas Gleixner }
12370aedd24SThomas Gleixner 
1243876ec9eSThomas Gleixner static inline void chip_bus_sync_unlock(struct irq_desc *desc)
12570aedd24SThomas Gleixner {
1263876ec9eSThomas Gleixner 	if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock))
1273876ec9eSThomas Gleixner 		desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data);
12870aedd24SThomas Gleixner }
12970aedd24SThomas Gleixner 
13031d9d9b6SMarc Zyngier #define _IRQ_DESC_CHECK		(1 << 0)
13131d9d9b6SMarc Zyngier #define _IRQ_DESC_PERCPU	(1 << 1)
13231d9d9b6SMarc Zyngier 
13331d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_GLOBAL	(_IRQ_DESC_CHECK)
13431d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_PERCPU	(_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU)
13531d9d9b6SMarc Zyngier 
136f944b5a7SDaniel Lezcano #define for_each_action_of_desc(desc, act)			\
137f944b5a7SDaniel Lezcano 	for (act = desc->act; act; act = act->next)
138f944b5a7SDaniel Lezcano 
139d5eb4ad2SThomas Gleixner struct irq_desc *
14031d9d9b6SMarc Zyngier __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
14131d9d9b6SMarc Zyngier 		    unsigned int check);
142d5eb4ad2SThomas Gleixner void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus);
143d5eb4ad2SThomas Gleixner 
144d5eb4ad2SThomas Gleixner static inline struct irq_desc *
14531d9d9b6SMarc Zyngier irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check)
146d5eb4ad2SThomas Gleixner {
14731d9d9b6SMarc Zyngier 	return __irq_get_desc_lock(irq, flags, true, check);
148d5eb4ad2SThomas Gleixner }
149d5eb4ad2SThomas Gleixner 
150d5eb4ad2SThomas Gleixner static inline void
151d5eb4ad2SThomas Gleixner irq_put_desc_busunlock(struct irq_desc *desc, unsigned long flags)
152d5eb4ad2SThomas Gleixner {
153d5eb4ad2SThomas Gleixner 	__irq_put_desc_unlock(desc, flags, true);
154d5eb4ad2SThomas Gleixner }
155d5eb4ad2SThomas Gleixner 
156d5eb4ad2SThomas Gleixner static inline struct irq_desc *
15731d9d9b6SMarc Zyngier irq_get_desc_lock(unsigned int irq, unsigned long *flags, unsigned int check)
158d5eb4ad2SThomas Gleixner {
15931d9d9b6SMarc Zyngier 	return __irq_get_desc_lock(irq, flags, false, check);
160d5eb4ad2SThomas Gleixner }
161d5eb4ad2SThomas Gleixner 
162d5eb4ad2SThomas Gleixner static inline void
163d5eb4ad2SThomas Gleixner irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags)
164d5eb4ad2SThomas Gleixner {
165d5eb4ad2SThomas Gleixner 	__irq_put_desc_unlock(desc, flags, false);
166d5eb4ad2SThomas Gleixner }
167d5eb4ad2SThomas Gleixner 
168b354286eSBoqun Feng #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
169b354286eSBoqun Feng 
17043f77759SIngo Molnar /*
171f230b6d5SThomas Gleixner  * Manipulation functions for irq_data.state
172f230b6d5SThomas Gleixner  */
173f230b6d5SThomas Gleixner static inline void irqd_set_move_pending(struct irq_data *d)
174f230b6d5SThomas Gleixner {
1750d0b4c86SJiang Liu 	__irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING;
176f230b6d5SThomas Gleixner }
177f230b6d5SThomas Gleixner 
178f230b6d5SThomas Gleixner static inline void irqd_clr_move_pending(struct irq_data *d)
179f230b6d5SThomas Gleixner {
1800d0b4c86SJiang Liu 	__irqd_to_state(d) &= ~IRQD_SETAFFINITY_PENDING;
181f230b6d5SThomas Gleixner }
182a005677bSThomas Gleixner 
183a005677bSThomas Gleixner static inline void irqd_clear(struct irq_data *d, unsigned int mask)
184a005677bSThomas Gleixner {
1850d0b4c86SJiang Liu 	__irqd_to_state(d) &= ~mask;
186a005677bSThomas Gleixner }
187a005677bSThomas Gleixner 
188a005677bSThomas Gleixner static inline void irqd_set(struct irq_data *d, unsigned int mask)
189a005677bSThomas Gleixner {
1900d0b4c86SJiang Liu 	__irqd_to_state(d) |= mask;
191a005677bSThomas Gleixner }
192a005677bSThomas Gleixner 
1932bdd1055SThomas Gleixner static inline bool irqd_has_set(struct irq_data *d, unsigned int mask)
1942bdd1055SThomas Gleixner {
1950d0b4c86SJiang Liu 	return __irqd_to_state(d) & mask;
1962bdd1055SThomas Gleixner }
1978f945a33SThomas Gleixner 
198b354286eSBoqun Feng #undef __irqd_to_state
199b354286eSBoqun Feng 
200b51bf95cSJiang Liu static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc)
2018f945a33SThomas Gleixner {
2028f945a33SThomas Gleixner 	__this_cpu_inc(*desc->kstat_irqs);
2038f945a33SThomas Gleixner 	__this_cpu_inc(kstat.irqs_sum);
2048f945a33SThomas Gleixner }
205cab303beSThomas Gleixner 
2066783011bSJiang Liu static inline int irq_desc_get_node(struct irq_desc *desc)
2076783011bSJiang Liu {
208449e9caeSJiang Liu 	return irq_common_data_get_node(&desc->irq_common_data);
2096783011bSJiang Liu }
2106783011bSJiang Liu 
2114717f133SGrygorii Strashko static inline int irq_desc_is_chained(struct irq_desc *desc)
2124717f133SGrygorii Strashko {
2134717f133SGrygorii Strashko 	return (desc->action && desc->action == &chained_action);
2144717f133SGrygorii Strashko }
2154717f133SGrygorii Strashko 
216cab303beSThomas Gleixner #ifdef CONFIG_PM_SLEEP
2179ce7a258SThomas Gleixner bool irq_pm_check_wakeup(struct irq_desc *desc);
218cab303beSThomas Gleixner void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action);
219cab303beSThomas Gleixner void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action);
220cab303beSThomas Gleixner #else
2219ce7a258SThomas Gleixner static inline bool irq_pm_check_wakeup(struct irq_desc *desc) { return false; }
222cab303beSThomas Gleixner static inline void
223cab303beSThomas Gleixner irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
224cab303beSThomas Gleixner static inline void
225cab303beSThomas Gleixner irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { }
226cab303beSThomas Gleixner #endif
227