xref: /linux-6.15/include/linux/interrupt.h (revision f48fe81e)
11da177e4SLinus Torvalds /* interrupt.h */
21da177e4SLinus Torvalds #ifndef _LINUX_INTERRUPT_H
31da177e4SLinus Torvalds #define _LINUX_INTERRUPT_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/kernel.h>
61da177e4SLinus Torvalds #include <linux/linkage.h>
71da177e4SLinus Torvalds #include <linux/bitops.h>
81da177e4SLinus Torvalds #include <linux/preempt.h>
91da177e4SLinus Torvalds #include <linux/cpumask.h>
10908dcecdSJan Beulich #include <linux/irqreturn.h>
11dd3a1db9SThomas Gleixner #include <linux/irqnr.h>
121da177e4SLinus Torvalds #include <linux/hardirq.h>
13f037360fSAl Viro #include <linux/sched.h>
14de30a2b3SIngo Molnar #include <linux/irqflags.h>
1554514a70SDavid S. Miller #include <linux/smp.h>
1654514a70SDavid S. Miller #include <linux/percpu.h>
170ebb26e7SIngo Molnar 
181da177e4SLinus Torvalds #include <asm/atomic.h>
191da177e4SLinus Torvalds #include <asm/ptrace.h>
201da177e4SLinus Torvalds #include <asm/system.h>
211da177e4SLinus Torvalds 
226e213616SThomas Gleixner /*
236e213616SThomas Gleixner  * These correspond to the IORESOURCE_IRQ_* defines in
246e213616SThomas Gleixner  * linux/ioport.h to select the interrupt line behaviour.  When
256e213616SThomas Gleixner  * requesting an interrupt without specifying a IRQF_TRIGGER, the
266e213616SThomas Gleixner  * setting should be assumed to be "as already configured", which
276e213616SThomas Gleixner  * may be as per machine or firmware initialisation.
286e213616SThomas Gleixner  */
296e213616SThomas Gleixner #define IRQF_TRIGGER_NONE	0x00000000
306e213616SThomas Gleixner #define IRQF_TRIGGER_RISING	0x00000001
316e213616SThomas Gleixner #define IRQF_TRIGGER_FALLING	0x00000002
326e213616SThomas Gleixner #define IRQF_TRIGGER_HIGH	0x00000004
336e213616SThomas Gleixner #define IRQF_TRIGGER_LOW	0x00000008
346e213616SThomas Gleixner #define IRQF_TRIGGER_MASK	(IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
356e213616SThomas Gleixner 				 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
366e213616SThomas Gleixner #define IRQF_TRIGGER_PROBE	0x00000010
376e213616SThomas Gleixner 
386e213616SThomas Gleixner /*
396e213616SThomas Gleixner  * These flags used only by the kernel as part of the
406e213616SThomas Gleixner  * irq handling routines.
416e213616SThomas Gleixner  *
426e213616SThomas Gleixner  * IRQF_DISABLED - keep irqs disabled when calling the action handler
436e213616SThomas Gleixner  * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
446e213616SThomas Gleixner  * IRQF_SHARED - allow sharing the irq among several devices
456e213616SThomas Gleixner  * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
466e213616SThomas Gleixner  * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
47950f4427SThomas Gleixner  * IRQF_PERCPU - Interrupt is per cpu
48950f4427SThomas Gleixner  * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
49d85a60d8SBernhard Walle  * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
50d85a60d8SBernhard Walle  *                registered first in an shared interrupt is considered for
51d85a60d8SBernhard Walle  *                performance reasons)
526e213616SThomas Gleixner  */
536e213616SThomas Gleixner #define IRQF_DISABLED		0x00000020
546e213616SThomas Gleixner #define IRQF_SAMPLE_RANDOM	0x00000040
556e213616SThomas Gleixner #define IRQF_SHARED		0x00000080
566e213616SThomas Gleixner #define IRQF_PROBE_SHARED	0x00000100
576e213616SThomas Gleixner #define IRQF_TIMER		0x00000200
58284c6680SThomas Gleixner #define IRQF_PERCPU		0x00000400
59950f4427SThomas Gleixner #define IRQF_NOBALANCING	0x00000800
60d85a60d8SBernhard Walle #define IRQF_IRQPOLL		0x00001000
616e213616SThomas Gleixner 
623aa551c9SThomas Gleixner /*
633aa551c9SThomas Gleixner  * Bits used by threaded handlers:
643aa551c9SThomas Gleixner  * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
653aa551c9SThomas Gleixner  * IRQTF_DIED      - handler thread died
66*f48fe81eSThomas Gleixner  * IRQTF_WARNED    - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
673aa551c9SThomas Gleixner  */
683aa551c9SThomas Gleixner enum {
693aa551c9SThomas Gleixner 	IRQTF_RUNTHREAD,
703aa551c9SThomas Gleixner 	IRQTF_DIED,
71*f48fe81eSThomas Gleixner 	IRQTF_WARNED,
723aa551c9SThomas Gleixner };
733aa551c9SThomas Gleixner 
747d12e780SDavid Howells typedef irqreturn_t (*irq_handler_t)(int, void *);
75da482792SDavid Howells 
76a9d0a1a3SThomas Gleixner /**
77a9d0a1a3SThomas Gleixner  * struct irqaction - per interrupt action descriptor
78a9d0a1a3SThomas Gleixner  * @handler:	interrupt handler function
79a9d0a1a3SThomas Gleixner  * @flags:	flags (see IRQF_* above)
80a9d0a1a3SThomas Gleixner  * @mask:	no comment as it is useless and about to be removed
81a9d0a1a3SThomas Gleixner  * @name:	name of the device
82a9d0a1a3SThomas Gleixner  * @dev_id:	cookie to identify the device
83a9d0a1a3SThomas Gleixner  * @next:	pointer to the next irqaction for shared interrupts
84a9d0a1a3SThomas Gleixner  * @irq:	interrupt number
85a9d0a1a3SThomas Gleixner  * @dir:	pointer to the proc/irq/NN/name entry
863aa551c9SThomas Gleixner  * @thread_fn:	interupt handler function for threaded interrupts
873aa551c9SThomas Gleixner  * @thread:	thread pointer for threaded interrupts
883aa551c9SThomas Gleixner  * @thread_flags:	flags related to @thread
89a9d0a1a3SThomas Gleixner  */
901da177e4SLinus Torvalds struct irqaction {
91da482792SDavid Howells 	irq_handler_t handler;
921da177e4SLinus Torvalds 	unsigned long flags;
931da177e4SLinus Torvalds 	cpumask_t mask;
941da177e4SLinus Torvalds 	const char *name;
951da177e4SLinus Torvalds 	void *dev_id;
961da177e4SLinus Torvalds 	struct irqaction *next;
971da177e4SLinus Torvalds 	int irq;
981da177e4SLinus Torvalds 	struct proc_dir_entry *dir;
993aa551c9SThomas Gleixner 	irq_handler_t thread_fn;
1003aa551c9SThomas Gleixner 	struct task_struct *thread;
1013aa551c9SThomas Gleixner 	unsigned long thread_flags;
1021da177e4SLinus Torvalds };
1031da177e4SLinus Torvalds 
1047d12e780SDavid Howells extern irqreturn_t no_action(int cpl, void *dev_id);
1053aa551c9SThomas Gleixner 
1063aa551c9SThomas Gleixner extern int __must_check
1073aa551c9SThomas Gleixner request_threaded_irq(unsigned int irq, irq_handler_t handler,
1083aa551c9SThomas Gleixner 		     irq_handler_t thread_fn,
1093aa551c9SThomas Gleixner 		     unsigned long flags, const char *name, void *dev);
1103aa551c9SThomas Gleixner 
1113aa551c9SThomas Gleixner static inline int __must_check
1123aa551c9SThomas Gleixner request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
1133aa551c9SThomas Gleixner 	    const char *name, void *dev)
1143aa551c9SThomas Gleixner {
1153aa551c9SThomas Gleixner 	return request_threaded_irq(irq, handler, NULL, flags, name, dev);
1163aa551c9SThomas Gleixner }
1173aa551c9SThomas Gleixner 
1183aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS
1193aa551c9SThomas Gleixner extern void exit_irq_thread(void);
1203aa551c9SThomas Gleixner #else
1213aa551c9SThomas Gleixner static inline void exit_irq_thread(void) { }
1223aa551c9SThomas Gleixner #endif
1233aa551c9SThomas Gleixner 
1241da177e4SLinus Torvalds extern void free_irq(unsigned int, void *);
1251da177e4SLinus Torvalds 
1260af3678fSAl Viro struct device;
1270af3678fSAl Viro 
128935bd5b9SArjan van de Ven extern int __must_check
129935bd5b9SArjan van de Ven devm_request_threaded_irq(struct device *dev, unsigned int irq,
130935bd5b9SArjan van de Ven 			  irq_handler_t handler, irq_handler_t thread_fn,
131935bd5b9SArjan van de Ven 			  unsigned long irqflags, const char *devname,
132935bd5b9SArjan van de Ven 			  void *dev_id);
133935bd5b9SArjan van de Ven 
134935bd5b9SArjan van de Ven static inline int __must_check
135935bd5b9SArjan van de Ven devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
136935bd5b9SArjan van de Ven 		 unsigned long irqflags, const char *devname, void *dev_id)
137935bd5b9SArjan van de Ven {
138935bd5b9SArjan van de Ven 	return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
139935bd5b9SArjan van de Ven 					 devname, dev_id);
140935bd5b9SArjan van de Ven }
141935bd5b9SArjan van de Ven 
1429ac7849eSTejun Heo extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
1439ac7849eSTejun Heo 
144d7e9629dSIngo Molnar /*
145d7e9629dSIngo Molnar  * On lockdep we dont want to enable hardirqs in hardirq
146d7e9629dSIngo Molnar  * context. Use local_irq_enable_in_hardirq() to annotate
147d7e9629dSIngo Molnar  * kernel code that has to do this nevertheless (pretty much
148d7e9629dSIngo Molnar  * the only valid case is for old/broken hardware that is
149d7e9629dSIngo Molnar  * insanely slow).
150d7e9629dSIngo Molnar  *
151d7e9629dSIngo Molnar  * NOTE: in theory this might break fragile code that relies
152d7e9629dSIngo Molnar  * on hardirq delivery - in practice we dont seem to have such
153d7e9629dSIngo Molnar  * places left. So the only effect should be slightly increased
154d7e9629dSIngo Molnar  * irqs-off latencies.
155d7e9629dSIngo Molnar  */
156d7e9629dSIngo Molnar #ifdef CONFIG_LOCKDEP
157d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	do { } while (0)
158d7e9629dSIngo Molnar #else
159d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	local_irq_enable()
160d7e9629dSIngo Molnar #endif
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds extern void disable_irq_nosync(unsigned int irq);
1631da177e4SLinus Torvalds extern void disable_irq(unsigned int irq);
1641da177e4SLinus Torvalds extern void enable_irq(unsigned int irq);
165ba9a2331SThomas Gleixner 
166d7b90689SRussell King #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
167d7b90689SRussell King 
168d036e67bSRusty Russell extern cpumask_var_t irq_default_affinity;
16918404756SMax Krasnyansky 
1700de26520SRusty Russell extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
171d7b90689SRussell King extern int irq_can_set_affinity(unsigned int irq);
17218404756SMax Krasnyansky extern int irq_select_affinity(unsigned int irq);
173d7b90689SRussell King 
174d7b90689SRussell King #else /* CONFIG_SMP */
175d7b90689SRussell King 
1760de26520SRusty Russell static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
177d7b90689SRussell King {
178d7b90689SRussell King 	return -EINVAL;
179d7b90689SRussell King }
180d7b90689SRussell King 
181d7b90689SRussell King static inline int irq_can_set_affinity(unsigned int irq)
182d7b90689SRussell King {
183d7b90689SRussell King 	return 0;
184d7b90689SRussell King }
185d7b90689SRussell King 
18618404756SMax Krasnyansky static inline int irq_select_affinity(unsigned int irq)  { return 0; }
18718404756SMax Krasnyansky 
188d7b90689SRussell King #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */
189d7b90689SRussell King 
190e9ed7e72SAl Viro #ifdef CONFIG_GENERIC_HARDIRQS
191c01d403bSIngo Molnar /*
192c01d403bSIngo Molnar  * Special lockdep variants of irq disabling/enabling.
193c01d403bSIngo Molnar  * These should be used for locking constructs that
194c01d403bSIngo Molnar  * know that a particular irq context which is disabled,
195c01d403bSIngo Molnar  * and which is the only irq-context user of a lock,
196c01d403bSIngo Molnar  * that it's safe to take the lock in the irq-disabled
197c01d403bSIngo Molnar  * section without disabling hardirqs.
198c01d403bSIngo Molnar  *
199c01d403bSIngo Molnar  * On !CONFIG_LOCKDEP they are equivalent to the normal
200c01d403bSIngo Molnar  * irq disable/enable methods.
201c01d403bSIngo Molnar  */
202c01d403bSIngo Molnar static inline void disable_irq_nosync_lockdep(unsigned int irq)
203c01d403bSIngo Molnar {
204c01d403bSIngo Molnar 	disable_irq_nosync(irq);
205c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
206c01d403bSIngo Molnar 	local_irq_disable();
207c01d403bSIngo Molnar #endif
208c01d403bSIngo Molnar }
209c01d403bSIngo Molnar 
210e8106b94SArjan van de Ven static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
211e8106b94SArjan van de Ven {
212e8106b94SArjan van de Ven 	disable_irq_nosync(irq);
213e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
214e8106b94SArjan van de Ven 	local_irq_save(*flags);
215e8106b94SArjan van de Ven #endif
216e8106b94SArjan van de Ven }
217e8106b94SArjan van de Ven 
218c01d403bSIngo Molnar static inline void disable_irq_lockdep(unsigned int irq)
219c01d403bSIngo Molnar {
220c01d403bSIngo Molnar 	disable_irq(irq);
221c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
222c01d403bSIngo Molnar 	local_irq_disable();
223c01d403bSIngo Molnar #endif
224c01d403bSIngo Molnar }
225c01d403bSIngo Molnar 
226c01d403bSIngo Molnar static inline void enable_irq_lockdep(unsigned int irq)
227c01d403bSIngo Molnar {
228c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
229c01d403bSIngo Molnar 	local_irq_enable();
230c01d403bSIngo Molnar #endif
231c01d403bSIngo Molnar 	enable_irq(irq);
232c01d403bSIngo Molnar }
233c01d403bSIngo Molnar 
234e8106b94SArjan van de Ven static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
235e8106b94SArjan van de Ven {
236e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
237e8106b94SArjan van de Ven 	local_irq_restore(*flags);
238e8106b94SArjan van de Ven #endif
239e8106b94SArjan van de Ven 	enable_irq(irq);
240e8106b94SArjan van de Ven }
241e8106b94SArjan van de Ven 
242ba9a2331SThomas Gleixner /* IRQ wakeup (PM) control: */
243ba9a2331SThomas Gleixner extern int set_irq_wake(unsigned int irq, unsigned int on);
244ba9a2331SThomas Gleixner 
245ba9a2331SThomas Gleixner static inline int enable_irq_wake(unsigned int irq)
246ba9a2331SThomas Gleixner {
247ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 1);
248ba9a2331SThomas Gleixner }
249ba9a2331SThomas Gleixner 
250ba9a2331SThomas Gleixner static inline int disable_irq_wake(unsigned int irq)
251ba9a2331SThomas Gleixner {
252ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 0);
253ba9a2331SThomas Gleixner }
254ba9a2331SThomas Gleixner 
255c01d403bSIngo Molnar #else /* !CONFIG_GENERIC_HARDIRQS */
256c01d403bSIngo Molnar /*
257c01d403bSIngo Molnar  * NOTE: non-genirq architectures, if they want to support the lock
258c01d403bSIngo Molnar  * validator need to define the methods below in their asm/irq.h
259c01d403bSIngo Molnar  * files, under an #ifdef CONFIG_LOCKDEP section.
260c01d403bSIngo Molnar  */
261c01d403bSIngo Molnar #ifndef CONFIG_LOCKDEP
262c01d403bSIngo Molnar #  define disable_irq_nosync_lockdep(irq)	disable_irq_nosync(irq)
263b3e2fd9cSRoman Zippel #  define disable_irq_nosync_lockdep_irqsave(irq, flags) \
264b3e2fd9cSRoman Zippel 						disable_irq_nosync(irq)
265c01d403bSIngo Molnar #  define disable_irq_lockdep(irq)		disable_irq(irq)
266c01d403bSIngo Molnar #  define enable_irq_lockdep(irq)		enable_irq(irq)
267b3e2fd9cSRoman Zippel #  define enable_irq_lockdep_irqrestore(irq, flags) \
268b3e2fd9cSRoman Zippel 						enable_irq(irq)
2691da177e4SLinus Torvalds # endif
2701da177e4SLinus Torvalds 
271aa5346a2SGuennadi Liakhovetski static inline int enable_irq_wake(unsigned int irq)
272aa5346a2SGuennadi Liakhovetski {
273aa5346a2SGuennadi Liakhovetski 	return 0;
274aa5346a2SGuennadi Liakhovetski }
275aa5346a2SGuennadi Liakhovetski 
276aa5346a2SGuennadi Liakhovetski static inline int disable_irq_wake(unsigned int irq)
277aa5346a2SGuennadi Liakhovetski {
278aa5346a2SGuennadi Liakhovetski 	return 0;
279aa5346a2SGuennadi Liakhovetski }
280c01d403bSIngo Molnar #endif /* CONFIG_GENERIC_HARDIRQS */
281c01d403bSIngo Molnar 
2823f74478bSAndi Kleen #ifndef __ARCH_SET_SOFTIRQ_PENDING
2833f74478bSAndi Kleen #define set_softirq_pending(x) (local_softirq_pending() = (x))
2843f74478bSAndi Kleen #define or_softirq_pending(x)  (local_softirq_pending() |= (x))
2853f74478bSAndi Kleen #endif
2863f74478bSAndi Kleen 
2872d3fbbb3SBenjamin Herrenschmidt /* Some architectures might implement lazy enabling/disabling of
2882d3fbbb3SBenjamin Herrenschmidt  * interrupts. In some cases, such as stop_machine, we might want
2892d3fbbb3SBenjamin Herrenschmidt  * to ensure that after a local_irq_disable(), interrupts have
2902d3fbbb3SBenjamin Herrenschmidt  * really been disabled in hardware. Such architectures need to
2912d3fbbb3SBenjamin Herrenschmidt  * implement the following hook.
2922d3fbbb3SBenjamin Herrenschmidt  */
2932d3fbbb3SBenjamin Herrenschmidt #ifndef hard_irq_disable
2942d3fbbb3SBenjamin Herrenschmidt #define hard_irq_disable()	do { } while(0)
2952d3fbbb3SBenjamin Herrenschmidt #endif
2962d3fbbb3SBenjamin Herrenschmidt 
2971da177e4SLinus Torvalds /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
2981da177e4SLinus Torvalds    frequency threaded job scheduling. For almost all the purposes
2991da177e4SLinus Torvalds    tasklets are more than enough. F.e. all serial device BHs et
3001da177e4SLinus Torvalds    al. should be converted to tasklets, not to softirqs.
3011da177e4SLinus Torvalds  */
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds enum
3041da177e4SLinus Torvalds {
3051da177e4SLinus Torvalds 	HI_SOFTIRQ=0,
3061da177e4SLinus Torvalds 	TIMER_SOFTIRQ,
3071da177e4SLinus Torvalds 	NET_TX_SOFTIRQ,
3081da177e4SLinus Torvalds 	NET_RX_SOFTIRQ,
309ff856badSJens Axboe 	BLOCK_SOFTIRQ,
310c9819f45SChristoph Lameter 	TASKLET_SOFTIRQ,
311c9819f45SChristoph Lameter 	SCHED_SOFTIRQ,
312a6037b61SPeter Zijlstra 	HRTIMER_SOFTIRQ,
313c2d727aaSDipankar Sarma 	RCU_SOFTIRQ,	/* Preferable RCU should always be the last softirq */
314978b0116SAlexey Dobriyan 
315978b0116SAlexey Dobriyan 	NR_SOFTIRQS
3161da177e4SLinus Torvalds };
3171da177e4SLinus Torvalds 
3181da177e4SLinus Torvalds /* softirq mask and active fields moved to irq_cpustat_t in
3191da177e4SLinus Torvalds  * asm/hardirq.h to get better cache usage.  KAO
3201da177e4SLinus Torvalds  */
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds struct softirq_action
3231da177e4SLinus Torvalds {
3241da177e4SLinus Torvalds 	void	(*action)(struct softirq_action *);
3251da177e4SLinus Torvalds };
3261da177e4SLinus Torvalds 
3271da177e4SLinus Torvalds asmlinkage void do_softirq(void);
328eb0f1c44SAdrian Bunk asmlinkage void __do_softirq(void);
329962cf36cSCarlos R. Mafra extern void open_softirq(int nr, void (*action)(struct softirq_action *));
3301da177e4SLinus Torvalds extern void softirq_init(void);
3313f74478bSAndi Kleen #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
332b3c97528SHarvey Harrison extern void raise_softirq_irqoff(unsigned int nr);
333b3c97528SHarvey Harrison extern void raise_softirq(unsigned int nr);
3341da177e4SLinus Torvalds 
33554514a70SDavid S. Miller /* This is the worklist that queues up per-cpu softirq work.
33654514a70SDavid S. Miller  *
33754514a70SDavid S. Miller  * send_remote_sendirq() adds work to these lists, and
33854514a70SDavid S. Miller  * the softirq handler itself dequeues from them.  The queues
33954514a70SDavid S. Miller  * are protected by disabling local cpu interrupts and they must
34054514a70SDavid S. Miller  * only be accessed by the local cpu that they are for.
34154514a70SDavid S. Miller  */
34254514a70SDavid S. Miller DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list);
34354514a70SDavid S. Miller 
34454514a70SDavid S. Miller /* Try to send a softirq to a remote cpu.  If this cannot be done, the
34554514a70SDavid S. Miller  * work will be queued to the local cpu.
34654514a70SDavid S. Miller  */
34754514a70SDavid S. Miller extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq);
34854514a70SDavid S. Miller 
34954514a70SDavid S. Miller /* Like send_remote_softirq(), but the caller must disable local cpu interrupts
35054514a70SDavid S. Miller  * and compute the current cpu, passed in as 'this_cpu'.
35154514a70SDavid S. Miller  */
35254514a70SDavid S. Miller extern void __send_remote_softirq(struct call_single_data *cp, int cpu,
35354514a70SDavid S. Miller 				  int this_cpu, int softirq);
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds /* Tasklets --- multithreaded analogue of BHs.
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds    Main feature differing them of generic softirqs: tasklet
3581da177e4SLinus Torvalds    is running only on one CPU simultaneously.
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds    Main feature differing them of BHs: different tasklets
3611da177e4SLinus Torvalds    may be run simultaneously on different CPUs.
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds    Properties:
3641da177e4SLinus Torvalds    * If tasklet_schedule() is called, then tasklet is guaranteed
3651da177e4SLinus Torvalds      to be executed on some cpu at least once after this.
3661da177e4SLinus Torvalds    * If the tasklet is already scheduled, but its excecution is still not
3671da177e4SLinus Torvalds      started, it will be executed only once.
3681da177e4SLinus Torvalds    * If this tasklet is already running on another CPU (or schedule is called
3691da177e4SLinus Torvalds      from tasklet itself), it is rescheduled for later.
3701da177e4SLinus Torvalds    * Tasklet is strictly serialized wrt itself, but not
3711da177e4SLinus Torvalds      wrt another tasklets. If client needs some intertask synchronization,
3721da177e4SLinus Torvalds      he makes it with spinlocks.
3731da177e4SLinus Torvalds  */
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds struct tasklet_struct
3761da177e4SLinus Torvalds {
3771da177e4SLinus Torvalds 	struct tasklet_struct *next;
3781da177e4SLinus Torvalds 	unsigned long state;
3791da177e4SLinus Torvalds 	atomic_t count;
3801da177e4SLinus Torvalds 	void (*func)(unsigned long);
3811da177e4SLinus Torvalds 	unsigned long data;
3821da177e4SLinus Torvalds };
3831da177e4SLinus Torvalds 
3841da177e4SLinus Torvalds #define DECLARE_TASKLET(name, func, data) \
3851da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
3861da177e4SLinus Torvalds 
3871da177e4SLinus Torvalds #define DECLARE_TASKLET_DISABLED(name, func, data) \
3881da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds enum
3921da177e4SLinus Torvalds {
3931da177e4SLinus Torvalds 	TASKLET_STATE_SCHED,	/* Tasklet is scheduled for execution */
3941da177e4SLinus Torvalds 	TASKLET_STATE_RUN	/* Tasklet is running (SMP only) */
3951da177e4SLinus Torvalds };
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds #ifdef CONFIG_SMP
3981da177e4SLinus Torvalds static inline int tasklet_trylock(struct tasklet_struct *t)
3991da177e4SLinus Torvalds {
4001da177e4SLinus Torvalds 	return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds static inline void tasklet_unlock(struct tasklet_struct *t)
4041da177e4SLinus Torvalds {
4051da177e4SLinus Torvalds 	smp_mb__before_clear_bit();
4061da177e4SLinus Torvalds 	clear_bit(TASKLET_STATE_RUN, &(t)->state);
4071da177e4SLinus Torvalds }
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds static inline void tasklet_unlock_wait(struct tasklet_struct *t)
4101da177e4SLinus Torvalds {
4111da177e4SLinus Torvalds 	while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
4121da177e4SLinus Torvalds }
4131da177e4SLinus Torvalds #else
4141da177e4SLinus Torvalds #define tasklet_trylock(t) 1
4151da177e4SLinus Torvalds #define tasklet_unlock_wait(t) do { } while (0)
4161da177e4SLinus Torvalds #define tasklet_unlock(t) do { } while (0)
4171da177e4SLinus Torvalds #endif
4181da177e4SLinus Torvalds 
419b3c97528SHarvey Harrison extern void __tasklet_schedule(struct tasklet_struct *t);
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds static inline void tasklet_schedule(struct tasklet_struct *t)
4221da177e4SLinus Torvalds {
4231da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
4241da177e4SLinus Torvalds 		__tasklet_schedule(t);
4251da177e4SLinus Torvalds }
4261da177e4SLinus Torvalds 
427b3c97528SHarvey Harrison extern void __tasklet_hi_schedule(struct tasklet_struct *t);
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds static inline void tasklet_hi_schedule(struct tasklet_struct *t)
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
4321da177e4SLinus Torvalds 		__tasklet_hi_schedule(t);
4331da177e4SLinus Torvalds }
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds static inline void tasklet_disable_nosync(struct tasklet_struct *t)
4371da177e4SLinus Torvalds {
4381da177e4SLinus Torvalds 	atomic_inc(&t->count);
4391da177e4SLinus Torvalds 	smp_mb__after_atomic_inc();
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds static inline void tasklet_disable(struct tasklet_struct *t)
4431da177e4SLinus Torvalds {
4441da177e4SLinus Torvalds 	tasklet_disable_nosync(t);
4451da177e4SLinus Torvalds 	tasklet_unlock_wait(t);
4461da177e4SLinus Torvalds 	smp_mb();
4471da177e4SLinus Torvalds }
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds static inline void tasklet_enable(struct tasklet_struct *t)
4501da177e4SLinus Torvalds {
4511da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
4521da177e4SLinus Torvalds 	atomic_dec(&t->count);
4531da177e4SLinus Torvalds }
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds static inline void tasklet_hi_enable(struct tasklet_struct *t)
4561da177e4SLinus Torvalds {
4571da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
4581da177e4SLinus Torvalds 	atomic_dec(&t->count);
4591da177e4SLinus Torvalds }
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds extern void tasklet_kill(struct tasklet_struct *t);
4621da177e4SLinus Torvalds extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
4631da177e4SLinus Torvalds extern void tasklet_init(struct tasklet_struct *t,
4641da177e4SLinus Torvalds 			 void (*func)(unsigned long), unsigned long data);
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds /*
4671da177e4SLinus Torvalds  * Autoprobing for irqs:
4681da177e4SLinus Torvalds  *
4691da177e4SLinus Torvalds  * probe_irq_on() and probe_irq_off() provide robust primitives
4701da177e4SLinus Torvalds  * for accurate IRQ probing during kernel initialization.  They are
4711da177e4SLinus Torvalds  * reasonably simple to use, are not "fooled" by spurious interrupts,
4721da177e4SLinus Torvalds  * and, unlike other attempts at IRQ probing, they do not get hung on
4731da177e4SLinus Torvalds  * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
4741da177e4SLinus Torvalds  *
4751da177e4SLinus Torvalds  * For reasonably foolproof probing, use them as follows:
4761da177e4SLinus Torvalds  *
4771da177e4SLinus Torvalds  * 1. clear and/or mask the device's internal interrupt.
4781da177e4SLinus Torvalds  * 2. sti();
4791da177e4SLinus Torvalds  * 3. irqs = probe_irq_on();      // "take over" all unassigned idle IRQs
4801da177e4SLinus Torvalds  * 4. enable the device and cause it to trigger an interrupt.
4811da177e4SLinus Torvalds  * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
4821da177e4SLinus Torvalds  * 6. irq = probe_irq_off(irqs);  // get IRQ number, 0=none, negative=multiple
4831da177e4SLinus Torvalds  * 7. service the device to clear its pending interrupt.
4841da177e4SLinus Torvalds  * 8. loop again if paranoia is required.
4851da177e4SLinus Torvalds  *
4861da177e4SLinus Torvalds  * probe_irq_on() returns a mask of allocated irq's.
4871da177e4SLinus Torvalds  *
4881da177e4SLinus Torvalds  * probe_irq_off() takes the mask as a parameter,
4891da177e4SLinus Torvalds  * and returns the irq number which occurred,
4901da177e4SLinus Torvalds  * or zero if none occurred, or a negative irq number
4911da177e4SLinus Torvalds  * if more than one irq occurred.
4921da177e4SLinus Torvalds  */
4931da177e4SLinus Torvalds 
4941da177e4SLinus Torvalds #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
4951da177e4SLinus Torvalds static inline unsigned long probe_irq_on(void)
4961da177e4SLinus Torvalds {
4971da177e4SLinus Torvalds 	return 0;
4981da177e4SLinus Torvalds }
4991da177e4SLinus Torvalds static inline int probe_irq_off(unsigned long val)
5001da177e4SLinus Torvalds {
5011da177e4SLinus Torvalds 	return 0;
5021da177e4SLinus Torvalds }
5031da177e4SLinus Torvalds static inline unsigned int probe_irq_mask(unsigned long val)
5041da177e4SLinus Torvalds {
5051da177e4SLinus Torvalds 	return 0;
5061da177e4SLinus Torvalds }
5071da177e4SLinus Torvalds #else
5081da177e4SLinus Torvalds extern unsigned long probe_irq_on(void);	/* returns 0 on failure */
5091da177e4SLinus Torvalds extern int probe_irq_off(unsigned long);	/* returns 0 or negative on failure */
5101da177e4SLinus Torvalds extern unsigned int probe_irq_mask(unsigned long);	/* returns mask of ISA interrupts */
5111da177e4SLinus Torvalds #endif
5121da177e4SLinus Torvalds 
5136168a702SAndrew Morton #ifdef CONFIG_PROC_FS
5146168a702SAndrew Morton /* Initialize /proc/irq/ */
5156168a702SAndrew Morton extern void init_irq_proc(void);
5166168a702SAndrew Morton #else
5176168a702SAndrew Morton static inline void init_irq_proc(void)
5186168a702SAndrew Morton {
5196168a702SAndrew Morton }
5206168a702SAndrew Morton #endif
5216168a702SAndrew Morton 
52274296a8eSIngo Molnar #if defined(CONFIG_GENERIC_HARDIRQS) && defined(CONFIG_DEBUG_SHIRQ)
52374296a8eSIngo Molnar extern void debug_poll_all_shared_irqs(void);
52474296a8eSIngo Molnar #else
52574296a8eSIngo Molnar static inline void debug_poll_all_shared_irqs(void) { }
52674296a8eSIngo Molnar #endif
52774296a8eSIngo Molnar 
528f74596d0SAdrian Bunk int show_interrupts(struct seq_file *p, void *v);
529f74596d0SAdrian Bunk 
53043a25632SYinghai Lu struct irq_desc;
53143a25632SYinghai Lu 
53243a25632SYinghai Lu extern int early_irq_init(void);
5334a046d17SYinghai Lu extern int arch_probe_nr_irqs(void);
53443a25632SYinghai Lu extern int arch_early_irq_init(void);
53543a25632SYinghai Lu extern int arch_init_chip_data(struct irq_desc *desc, int cpu);
53643a25632SYinghai Lu 
5371da177e4SLinus Torvalds #endif
538