xref: /linux-6.15/include/linux/interrupt.h (revision a6037b61)
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 #include <linux/irqnr.h>
180ebb26e7SIngo Molnar 
191da177e4SLinus Torvalds #include <asm/atomic.h>
201da177e4SLinus Torvalds #include <asm/ptrace.h>
211da177e4SLinus Torvalds #include <asm/system.h>
221da177e4SLinus Torvalds 
236e213616SThomas Gleixner /*
246e213616SThomas Gleixner  * These correspond to the IORESOURCE_IRQ_* defines in
256e213616SThomas Gleixner  * linux/ioport.h to select the interrupt line behaviour.  When
266e213616SThomas Gleixner  * requesting an interrupt without specifying a IRQF_TRIGGER, the
276e213616SThomas Gleixner  * setting should be assumed to be "as already configured", which
286e213616SThomas Gleixner  * may be as per machine or firmware initialisation.
296e213616SThomas Gleixner  */
306e213616SThomas Gleixner #define IRQF_TRIGGER_NONE	0x00000000
316e213616SThomas Gleixner #define IRQF_TRIGGER_RISING	0x00000001
326e213616SThomas Gleixner #define IRQF_TRIGGER_FALLING	0x00000002
336e213616SThomas Gleixner #define IRQF_TRIGGER_HIGH	0x00000004
346e213616SThomas Gleixner #define IRQF_TRIGGER_LOW	0x00000008
356e213616SThomas Gleixner #define IRQF_TRIGGER_MASK	(IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
366e213616SThomas Gleixner 				 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
376e213616SThomas Gleixner #define IRQF_TRIGGER_PROBE	0x00000010
386e213616SThomas Gleixner 
396e213616SThomas Gleixner /*
406e213616SThomas Gleixner  * These flags used only by the kernel as part of the
416e213616SThomas Gleixner  * irq handling routines.
426e213616SThomas Gleixner  *
436e213616SThomas Gleixner  * IRQF_DISABLED - keep irqs disabled when calling the action handler
446e213616SThomas Gleixner  * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
456e213616SThomas Gleixner  * IRQF_SHARED - allow sharing the irq among several devices
466e213616SThomas Gleixner  * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
476e213616SThomas Gleixner  * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
48950f4427SThomas Gleixner  * IRQF_PERCPU - Interrupt is per cpu
49950f4427SThomas Gleixner  * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
50d85a60d8SBernhard Walle  * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
51d85a60d8SBernhard Walle  *                registered first in an shared interrupt is considered for
52d85a60d8SBernhard Walle  *                performance reasons)
536e213616SThomas Gleixner  */
546e213616SThomas Gleixner #define IRQF_DISABLED		0x00000020
556e213616SThomas Gleixner #define IRQF_SAMPLE_RANDOM	0x00000040
566e213616SThomas Gleixner #define IRQF_SHARED		0x00000080
576e213616SThomas Gleixner #define IRQF_PROBE_SHARED	0x00000100
586e213616SThomas Gleixner #define IRQF_TIMER		0x00000200
59284c6680SThomas Gleixner #define IRQF_PERCPU		0x00000400
60950f4427SThomas Gleixner #define IRQF_NOBALANCING	0x00000800
61d85a60d8SBernhard Walle #define IRQF_IRQPOLL		0x00001000
626e213616SThomas Gleixner 
637d12e780SDavid Howells typedef irqreturn_t (*irq_handler_t)(int, void *);
64da482792SDavid Howells 
651da177e4SLinus Torvalds struct irqaction {
66da482792SDavid Howells 	irq_handler_t handler;
671da177e4SLinus Torvalds 	unsigned long flags;
681da177e4SLinus Torvalds 	cpumask_t mask;
691da177e4SLinus Torvalds 	const char *name;
701da177e4SLinus Torvalds 	void *dev_id;
711da177e4SLinus Torvalds 	struct irqaction *next;
721da177e4SLinus Torvalds 	int irq;
731da177e4SLinus Torvalds 	struct proc_dir_entry *dir;
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds 
767d12e780SDavid Howells extern irqreturn_t no_action(int cpl, void *dev_id);
77616883dfSMonakhov Dmitriy extern int __must_check request_irq(unsigned int, irq_handler_t handler,
781da177e4SLinus Torvalds 		       unsigned long, const char *, void *);
791da177e4SLinus Torvalds extern void free_irq(unsigned int, void *);
801da177e4SLinus Torvalds 
810af3678fSAl Viro struct device;
820af3678fSAl Viro 
83616883dfSMonakhov Dmitriy extern int __must_check devm_request_irq(struct device *dev, unsigned int irq,
849ac7849eSTejun Heo 			    irq_handler_t handler, unsigned long irqflags,
859ac7849eSTejun Heo 			    const char *devname, void *dev_id);
869ac7849eSTejun Heo extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
879ac7849eSTejun Heo 
88d7e9629dSIngo Molnar /*
89d7e9629dSIngo Molnar  * On lockdep we dont want to enable hardirqs in hardirq
90d7e9629dSIngo Molnar  * context. Use local_irq_enable_in_hardirq() to annotate
91d7e9629dSIngo Molnar  * kernel code that has to do this nevertheless (pretty much
92d7e9629dSIngo Molnar  * the only valid case is for old/broken hardware that is
93d7e9629dSIngo Molnar  * insanely slow).
94d7e9629dSIngo Molnar  *
95d7e9629dSIngo Molnar  * NOTE: in theory this might break fragile code that relies
96d7e9629dSIngo Molnar  * on hardirq delivery - in practice we dont seem to have such
97d7e9629dSIngo Molnar  * places left. So the only effect should be slightly increased
98d7e9629dSIngo Molnar  * irqs-off latencies.
99d7e9629dSIngo Molnar  */
100d7e9629dSIngo Molnar #ifdef CONFIG_LOCKDEP
101d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	do { } while (0)
102d7e9629dSIngo Molnar #else
103d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	local_irq_enable()
104d7e9629dSIngo Molnar #endif
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds extern void disable_irq_nosync(unsigned int irq);
1071da177e4SLinus Torvalds extern void disable_irq(unsigned int irq);
1081da177e4SLinus Torvalds extern void enable_irq(unsigned int irq);
109ba9a2331SThomas Gleixner 
110d7b90689SRussell King #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
111d7b90689SRussell King 
112d036e67bSRusty Russell extern cpumask_var_t irq_default_affinity;
11318404756SMax Krasnyansky 
1140de26520SRusty Russell extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
115d7b90689SRussell King extern int irq_can_set_affinity(unsigned int irq);
11618404756SMax Krasnyansky extern int irq_select_affinity(unsigned int irq);
117d7b90689SRussell King 
118d7b90689SRussell King #else /* CONFIG_SMP */
119d7b90689SRussell King 
1200de26520SRusty Russell static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
121d7b90689SRussell King {
122d7b90689SRussell King 	return -EINVAL;
123d7b90689SRussell King }
124d7b90689SRussell King 
125d7b90689SRussell King static inline int irq_can_set_affinity(unsigned int irq)
126d7b90689SRussell King {
127d7b90689SRussell King 	return 0;
128d7b90689SRussell King }
129d7b90689SRussell King 
13018404756SMax Krasnyansky static inline int irq_select_affinity(unsigned int irq)  { return 0; }
13118404756SMax Krasnyansky 
132d7b90689SRussell King #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */
133d7b90689SRussell King 
134e9ed7e72SAl Viro #ifdef CONFIG_GENERIC_HARDIRQS
135c01d403bSIngo Molnar /*
136c01d403bSIngo Molnar  * Special lockdep variants of irq disabling/enabling.
137c01d403bSIngo Molnar  * These should be used for locking constructs that
138c01d403bSIngo Molnar  * know that a particular irq context which is disabled,
139c01d403bSIngo Molnar  * and which is the only irq-context user of a lock,
140c01d403bSIngo Molnar  * that it's safe to take the lock in the irq-disabled
141c01d403bSIngo Molnar  * section without disabling hardirqs.
142c01d403bSIngo Molnar  *
143c01d403bSIngo Molnar  * On !CONFIG_LOCKDEP they are equivalent to the normal
144c01d403bSIngo Molnar  * irq disable/enable methods.
145c01d403bSIngo Molnar  */
146c01d403bSIngo Molnar static inline void disable_irq_nosync_lockdep(unsigned int irq)
147c01d403bSIngo Molnar {
148c01d403bSIngo Molnar 	disable_irq_nosync(irq);
149c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
150c01d403bSIngo Molnar 	local_irq_disable();
151c01d403bSIngo Molnar #endif
152c01d403bSIngo Molnar }
153c01d403bSIngo Molnar 
154e8106b94SArjan van de Ven static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
155e8106b94SArjan van de Ven {
156e8106b94SArjan van de Ven 	disable_irq_nosync(irq);
157e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
158e8106b94SArjan van de Ven 	local_irq_save(*flags);
159e8106b94SArjan van de Ven #endif
160e8106b94SArjan van de Ven }
161e8106b94SArjan van de Ven 
162c01d403bSIngo Molnar static inline void disable_irq_lockdep(unsigned int irq)
163c01d403bSIngo Molnar {
164c01d403bSIngo Molnar 	disable_irq(irq);
165c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
166c01d403bSIngo Molnar 	local_irq_disable();
167c01d403bSIngo Molnar #endif
168c01d403bSIngo Molnar }
169c01d403bSIngo Molnar 
170c01d403bSIngo Molnar static inline void enable_irq_lockdep(unsigned int irq)
171c01d403bSIngo Molnar {
172c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
173c01d403bSIngo Molnar 	local_irq_enable();
174c01d403bSIngo Molnar #endif
175c01d403bSIngo Molnar 	enable_irq(irq);
176c01d403bSIngo Molnar }
177c01d403bSIngo Molnar 
178e8106b94SArjan van de Ven static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
179e8106b94SArjan van de Ven {
180e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
181e8106b94SArjan van de Ven 	local_irq_restore(*flags);
182e8106b94SArjan van de Ven #endif
183e8106b94SArjan van de Ven 	enable_irq(irq);
184e8106b94SArjan van de Ven }
185e8106b94SArjan van de Ven 
186ba9a2331SThomas Gleixner /* IRQ wakeup (PM) control: */
187ba9a2331SThomas Gleixner extern int set_irq_wake(unsigned int irq, unsigned int on);
188ba9a2331SThomas Gleixner 
189ba9a2331SThomas Gleixner static inline int enable_irq_wake(unsigned int irq)
190ba9a2331SThomas Gleixner {
191ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 1);
192ba9a2331SThomas Gleixner }
193ba9a2331SThomas Gleixner 
194ba9a2331SThomas Gleixner static inline int disable_irq_wake(unsigned int irq)
195ba9a2331SThomas Gleixner {
196ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 0);
197ba9a2331SThomas Gleixner }
198ba9a2331SThomas Gleixner 
199c01d403bSIngo Molnar #else /* !CONFIG_GENERIC_HARDIRQS */
200c01d403bSIngo Molnar /*
201c01d403bSIngo Molnar  * NOTE: non-genirq architectures, if they want to support the lock
202c01d403bSIngo Molnar  * validator need to define the methods below in their asm/irq.h
203c01d403bSIngo Molnar  * files, under an #ifdef CONFIG_LOCKDEP section.
204c01d403bSIngo Molnar  */
205c01d403bSIngo Molnar #ifndef CONFIG_LOCKDEP
206c01d403bSIngo Molnar #  define disable_irq_nosync_lockdep(irq)	disable_irq_nosync(irq)
207b3e2fd9cSRoman Zippel #  define disable_irq_nosync_lockdep_irqsave(irq, flags) \
208b3e2fd9cSRoman Zippel 						disable_irq_nosync(irq)
209c01d403bSIngo Molnar #  define disable_irq_lockdep(irq)		disable_irq(irq)
210c01d403bSIngo Molnar #  define enable_irq_lockdep(irq)		enable_irq(irq)
211b3e2fd9cSRoman Zippel #  define enable_irq_lockdep_irqrestore(irq, flags) \
212b3e2fd9cSRoman Zippel 						enable_irq(irq)
2131da177e4SLinus Torvalds # endif
2141da177e4SLinus Torvalds 
215aa5346a2SGuennadi Liakhovetski static inline int enable_irq_wake(unsigned int irq)
216aa5346a2SGuennadi Liakhovetski {
217aa5346a2SGuennadi Liakhovetski 	return 0;
218aa5346a2SGuennadi Liakhovetski }
219aa5346a2SGuennadi Liakhovetski 
220aa5346a2SGuennadi Liakhovetski static inline int disable_irq_wake(unsigned int irq)
221aa5346a2SGuennadi Liakhovetski {
222aa5346a2SGuennadi Liakhovetski 	return 0;
223aa5346a2SGuennadi Liakhovetski }
224c01d403bSIngo Molnar #endif /* CONFIG_GENERIC_HARDIRQS */
225c01d403bSIngo Molnar 
2263f74478bSAndi Kleen #ifndef __ARCH_SET_SOFTIRQ_PENDING
2273f74478bSAndi Kleen #define set_softirq_pending(x) (local_softirq_pending() = (x))
2283f74478bSAndi Kleen #define or_softirq_pending(x)  (local_softirq_pending() |= (x))
2293f74478bSAndi Kleen #endif
2303f74478bSAndi Kleen 
2312d3fbbb3SBenjamin Herrenschmidt /* Some architectures might implement lazy enabling/disabling of
2322d3fbbb3SBenjamin Herrenschmidt  * interrupts. In some cases, such as stop_machine, we might want
2332d3fbbb3SBenjamin Herrenschmidt  * to ensure that after a local_irq_disable(), interrupts have
2342d3fbbb3SBenjamin Herrenschmidt  * really been disabled in hardware. Such architectures need to
2352d3fbbb3SBenjamin Herrenschmidt  * implement the following hook.
2362d3fbbb3SBenjamin Herrenschmidt  */
2372d3fbbb3SBenjamin Herrenschmidt #ifndef hard_irq_disable
2382d3fbbb3SBenjamin Herrenschmidt #define hard_irq_disable()	do { } while(0)
2392d3fbbb3SBenjamin Herrenschmidt #endif
2402d3fbbb3SBenjamin Herrenschmidt 
2411da177e4SLinus Torvalds /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
2421da177e4SLinus Torvalds    frequency threaded job scheduling. For almost all the purposes
2431da177e4SLinus Torvalds    tasklets are more than enough. F.e. all serial device BHs et
2441da177e4SLinus Torvalds    al. should be converted to tasklets, not to softirqs.
2451da177e4SLinus Torvalds  */
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds enum
2481da177e4SLinus Torvalds {
2491da177e4SLinus Torvalds 	HI_SOFTIRQ=0,
2501da177e4SLinus Torvalds 	TIMER_SOFTIRQ,
2511da177e4SLinus Torvalds 	NET_TX_SOFTIRQ,
2521da177e4SLinus Torvalds 	NET_RX_SOFTIRQ,
253ff856badSJens Axboe 	BLOCK_SOFTIRQ,
254c9819f45SChristoph Lameter 	TASKLET_SOFTIRQ,
255c9819f45SChristoph Lameter 	SCHED_SOFTIRQ,
256*a6037b61SPeter Zijlstra 	HRTIMER_SOFTIRQ,
257c2d727aaSDipankar Sarma 	RCU_SOFTIRQ,	/* Preferable RCU should always be the last softirq */
258978b0116SAlexey Dobriyan 
259978b0116SAlexey Dobriyan 	NR_SOFTIRQS
2601da177e4SLinus Torvalds };
2611da177e4SLinus Torvalds 
2621da177e4SLinus Torvalds /* softirq mask and active fields moved to irq_cpustat_t in
2631da177e4SLinus Torvalds  * asm/hardirq.h to get better cache usage.  KAO
2641da177e4SLinus Torvalds  */
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds struct softirq_action
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds 	void	(*action)(struct softirq_action *);
2691da177e4SLinus Torvalds };
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds asmlinkage void do_softirq(void);
272eb0f1c44SAdrian Bunk asmlinkage void __do_softirq(void);
273962cf36cSCarlos R. Mafra extern void open_softirq(int nr, void (*action)(struct softirq_action *));
2741da177e4SLinus Torvalds extern void softirq_init(void);
2753f74478bSAndi Kleen #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
276b3c97528SHarvey Harrison extern void raise_softirq_irqoff(unsigned int nr);
277b3c97528SHarvey Harrison extern void raise_softirq(unsigned int nr);
2781da177e4SLinus Torvalds 
27954514a70SDavid S. Miller /* This is the worklist that queues up per-cpu softirq work.
28054514a70SDavid S. Miller  *
28154514a70SDavid S. Miller  * send_remote_sendirq() adds work to these lists, and
28254514a70SDavid S. Miller  * the softirq handler itself dequeues from them.  The queues
28354514a70SDavid S. Miller  * are protected by disabling local cpu interrupts and they must
28454514a70SDavid S. Miller  * only be accessed by the local cpu that they are for.
28554514a70SDavid S. Miller  */
28654514a70SDavid S. Miller DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list);
28754514a70SDavid S. Miller 
28854514a70SDavid S. Miller /* Try to send a softirq to a remote cpu.  If this cannot be done, the
28954514a70SDavid S. Miller  * work will be queued to the local cpu.
29054514a70SDavid S. Miller  */
29154514a70SDavid S. Miller extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq);
29254514a70SDavid S. Miller 
29354514a70SDavid S. Miller /* Like send_remote_softirq(), but the caller must disable local cpu interrupts
29454514a70SDavid S. Miller  * and compute the current cpu, passed in as 'this_cpu'.
29554514a70SDavid S. Miller  */
29654514a70SDavid S. Miller extern void __send_remote_softirq(struct call_single_data *cp, int cpu,
29754514a70SDavid S. Miller 				  int this_cpu, int softirq);
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds /* Tasklets --- multithreaded analogue of BHs.
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds    Main feature differing them of generic softirqs: tasklet
3021da177e4SLinus Torvalds    is running only on one CPU simultaneously.
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds    Main feature differing them of BHs: different tasklets
3051da177e4SLinus Torvalds    may be run simultaneously on different CPUs.
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds    Properties:
3081da177e4SLinus Torvalds    * If tasklet_schedule() is called, then tasklet is guaranteed
3091da177e4SLinus Torvalds      to be executed on some cpu at least once after this.
3101da177e4SLinus Torvalds    * If the tasklet is already scheduled, but its excecution is still not
3111da177e4SLinus Torvalds      started, it will be executed only once.
3121da177e4SLinus Torvalds    * If this tasklet is already running on another CPU (or schedule is called
3131da177e4SLinus Torvalds      from tasklet itself), it is rescheduled for later.
3141da177e4SLinus Torvalds    * Tasklet is strictly serialized wrt itself, but not
3151da177e4SLinus Torvalds      wrt another tasklets. If client needs some intertask synchronization,
3161da177e4SLinus Torvalds      he makes it with spinlocks.
3171da177e4SLinus Torvalds  */
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds struct tasklet_struct
3201da177e4SLinus Torvalds {
3211da177e4SLinus Torvalds 	struct tasklet_struct *next;
3221da177e4SLinus Torvalds 	unsigned long state;
3231da177e4SLinus Torvalds 	atomic_t count;
3241da177e4SLinus Torvalds 	void (*func)(unsigned long);
3251da177e4SLinus Torvalds 	unsigned long data;
3261da177e4SLinus Torvalds };
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds #define DECLARE_TASKLET(name, func, data) \
3291da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds #define DECLARE_TASKLET_DISABLED(name, func, data) \
3321da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds enum
3361da177e4SLinus Torvalds {
3371da177e4SLinus Torvalds 	TASKLET_STATE_SCHED,	/* Tasklet is scheduled for execution */
3381da177e4SLinus Torvalds 	TASKLET_STATE_RUN	/* Tasklet is running (SMP only) */
3391da177e4SLinus Torvalds };
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds #ifdef CONFIG_SMP
3421da177e4SLinus Torvalds static inline int tasklet_trylock(struct tasklet_struct *t)
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds 	return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
3451da177e4SLinus Torvalds }
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds static inline void tasklet_unlock(struct tasklet_struct *t)
3481da177e4SLinus Torvalds {
3491da177e4SLinus Torvalds 	smp_mb__before_clear_bit();
3501da177e4SLinus Torvalds 	clear_bit(TASKLET_STATE_RUN, &(t)->state);
3511da177e4SLinus Torvalds }
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds static inline void tasklet_unlock_wait(struct tasklet_struct *t)
3541da177e4SLinus Torvalds {
3551da177e4SLinus Torvalds 	while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
3561da177e4SLinus Torvalds }
3571da177e4SLinus Torvalds #else
3581da177e4SLinus Torvalds #define tasklet_trylock(t) 1
3591da177e4SLinus Torvalds #define tasklet_unlock_wait(t) do { } while (0)
3601da177e4SLinus Torvalds #define tasklet_unlock(t) do { } while (0)
3611da177e4SLinus Torvalds #endif
3621da177e4SLinus Torvalds 
363b3c97528SHarvey Harrison extern void __tasklet_schedule(struct tasklet_struct *t);
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds static inline void tasklet_schedule(struct tasklet_struct *t)
3661da177e4SLinus Torvalds {
3671da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
3681da177e4SLinus Torvalds 		__tasklet_schedule(t);
3691da177e4SLinus Torvalds }
3701da177e4SLinus Torvalds 
371b3c97528SHarvey Harrison extern void __tasklet_hi_schedule(struct tasklet_struct *t);
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds static inline void tasklet_hi_schedule(struct tasklet_struct *t)
3741da177e4SLinus Torvalds {
3751da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
3761da177e4SLinus Torvalds 		__tasklet_hi_schedule(t);
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds static inline void tasklet_disable_nosync(struct tasklet_struct *t)
3811da177e4SLinus Torvalds {
3821da177e4SLinus Torvalds 	atomic_inc(&t->count);
3831da177e4SLinus Torvalds 	smp_mb__after_atomic_inc();
3841da177e4SLinus Torvalds }
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds static inline void tasklet_disable(struct tasklet_struct *t)
3871da177e4SLinus Torvalds {
3881da177e4SLinus Torvalds 	tasklet_disable_nosync(t);
3891da177e4SLinus Torvalds 	tasklet_unlock_wait(t);
3901da177e4SLinus Torvalds 	smp_mb();
3911da177e4SLinus Torvalds }
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds static inline void tasklet_enable(struct tasklet_struct *t)
3941da177e4SLinus Torvalds {
3951da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
3961da177e4SLinus Torvalds 	atomic_dec(&t->count);
3971da177e4SLinus Torvalds }
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds static inline void tasklet_hi_enable(struct tasklet_struct *t)
4001da177e4SLinus Torvalds {
4011da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
4021da177e4SLinus Torvalds 	atomic_dec(&t->count);
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds extern void tasklet_kill(struct tasklet_struct *t);
4061da177e4SLinus Torvalds extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
4071da177e4SLinus Torvalds extern void tasklet_init(struct tasklet_struct *t,
4081da177e4SLinus Torvalds 			 void (*func)(unsigned long), unsigned long data);
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds /*
4111da177e4SLinus Torvalds  * Autoprobing for irqs:
4121da177e4SLinus Torvalds  *
4131da177e4SLinus Torvalds  * probe_irq_on() and probe_irq_off() provide robust primitives
4141da177e4SLinus Torvalds  * for accurate IRQ probing during kernel initialization.  They are
4151da177e4SLinus Torvalds  * reasonably simple to use, are not "fooled" by spurious interrupts,
4161da177e4SLinus Torvalds  * and, unlike other attempts at IRQ probing, they do not get hung on
4171da177e4SLinus Torvalds  * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
4181da177e4SLinus Torvalds  *
4191da177e4SLinus Torvalds  * For reasonably foolproof probing, use them as follows:
4201da177e4SLinus Torvalds  *
4211da177e4SLinus Torvalds  * 1. clear and/or mask the device's internal interrupt.
4221da177e4SLinus Torvalds  * 2. sti();
4231da177e4SLinus Torvalds  * 3. irqs = probe_irq_on();      // "take over" all unassigned idle IRQs
4241da177e4SLinus Torvalds  * 4. enable the device and cause it to trigger an interrupt.
4251da177e4SLinus Torvalds  * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
4261da177e4SLinus Torvalds  * 6. irq = probe_irq_off(irqs);  // get IRQ number, 0=none, negative=multiple
4271da177e4SLinus Torvalds  * 7. service the device to clear its pending interrupt.
4281da177e4SLinus Torvalds  * 8. loop again if paranoia is required.
4291da177e4SLinus Torvalds  *
4301da177e4SLinus Torvalds  * probe_irq_on() returns a mask of allocated irq's.
4311da177e4SLinus Torvalds  *
4321da177e4SLinus Torvalds  * probe_irq_off() takes the mask as a parameter,
4331da177e4SLinus Torvalds  * and returns the irq number which occurred,
4341da177e4SLinus Torvalds  * or zero if none occurred, or a negative irq number
4351da177e4SLinus Torvalds  * if more than one irq occurred.
4361da177e4SLinus Torvalds  */
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
4391da177e4SLinus Torvalds static inline unsigned long probe_irq_on(void)
4401da177e4SLinus Torvalds {
4411da177e4SLinus Torvalds 	return 0;
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds static inline int probe_irq_off(unsigned long val)
4441da177e4SLinus Torvalds {
4451da177e4SLinus Torvalds 	return 0;
4461da177e4SLinus Torvalds }
4471da177e4SLinus Torvalds static inline unsigned int probe_irq_mask(unsigned long val)
4481da177e4SLinus Torvalds {
4491da177e4SLinus Torvalds 	return 0;
4501da177e4SLinus Torvalds }
4511da177e4SLinus Torvalds #else
4521da177e4SLinus Torvalds extern unsigned long probe_irq_on(void);	/* returns 0 on failure */
4531da177e4SLinus Torvalds extern int probe_irq_off(unsigned long);	/* returns 0 or negative on failure */
4541da177e4SLinus Torvalds extern unsigned int probe_irq_mask(unsigned long);	/* returns mask of ISA interrupts */
4551da177e4SLinus Torvalds #endif
4561da177e4SLinus Torvalds 
4576168a702SAndrew Morton #ifdef CONFIG_PROC_FS
4586168a702SAndrew Morton /* Initialize /proc/irq/ */
4596168a702SAndrew Morton extern void init_irq_proc(void);
4606168a702SAndrew Morton #else
4616168a702SAndrew Morton static inline void init_irq_proc(void)
4626168a702SAndrew Morton {
4636168a702SAndrew Morton }
4646168a702SAndrew Morton #endif
4656168a702SAndrew Morton 
466f74596d0SAdrian Bunk int show_interrupts(struct seq_file *p, void *v);
467f74596d0SAdrian Bunk 
46843a25632SYinghai Lu struct irq_desc;
46943a25632SYinghai Lu 
47043a25632SYinghai Lu extern int early_irq_init(void);
47143a25632SYinghai Lu extern int arch_early_irq_init(void);
47243a25632SYinghai Lu extern int arch_init_chip_data(struct irq_desc *desc, int cpu);
47343a25632SYinghai Lu 
4741da177e4SLinus Torvalds #endif
475