xref: /linux-6.15/include/linux/interrupt.h (revision 54cdfdb4)
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>
111da177e4SLinus Torvalds #include <linux/hardirq.h>
12f037360fSAl Viro #include <linux/sched.h>
13de30a2b3SIngo Molnar #include <linux/irqflags.h>
14676dcb8bSAndrew Morton #include <linux/bottom_half.h>
159ac7849eSTejun Heo #include <linux/device.h>
161da177e4SLinus Torvalds #include <asm/atomic.h>
171da177e4SLinus Torvalds #include <asm/ptrace.h>
181da177e4SLinus Torvalds #include <asm/system.h>
191da177e4SLinus Torvalds 
206e213616SThomas Gleixner /*
216e213616SThomas Gleixner  * These correspond to the IORESOURCE_IRQ_* defines in
226e213616SThomas Gleixner  * linux/ioport.h to select the interrupt line behaviour.  When
236e213616SThomas Gleixner  * requesting an interrupt without specifying a IRQF_TRIGGER, the
246e213616SThomas Gleixner  * setting should be assumed to be "as already configured", which
256e213616SThomas Gleixner  * may be as per machine or firmware initialisation.
266e213616SThomas Gleixner  */
276e213616SThomas Gleixner #define IRQF_TRIGGER_NONE	0x00000000
286e213616SThomas Gleixner #define IRQF_TRIGGER_RISING	0x00000001
296e213616SThomas Gleixner #define IRQF_TRIGGER_FALLING	0x00000002
306e213616SThomas Gleixner #define IRQF_TRIGGER_HIGH	0x00000004
316e213616SThomas Gleixner #define IRQF_TRIGGER_LOW	0x00000008
326e213616SThomas Gleixner #define IRQF_TRIGGER_MASK	(IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
336e213616SThomas Gleixner 				 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
346e213616SThomas Gleixner #define IRQF_TRIGGER_PROBE	0x00000010
356e213616SThomas Gleixner 
366e213616SThomas Gleixner /*
376e213616SThomas Gleixner  * These flags used only by the kernel as part of the
386e213616SThomas Gleixner  * irq handling routines.
396e213616SThomas Gleixner  *
406e213616SThomas Gleixner  * IRQF_DISABLED - keep irqs disabled when calling the action handler
416e213616SThomas Gleixner  * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
426e213616SThomas Gleixner  * IRQF_SHARED - allow sharing the irq among several devices
436e213616SThomas Gleixner  * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
446e213616SThomas Gleixner  * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
45950f4427SThomas Gleixner  * IRQF_PERCPU - Interrupt is per cpu
46950f4427SThomas Gleixner  * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
476e213616SThomas Gleixner  */
486e213616SThomas Gleixner #define IRQF_DISABLED		0x00000020
496e213616SThomas Gleixner #define IRQF_SAMPLE_RANDOM	0x00000040
506e213616SThomas Gleixner #define IRQF_SHARED		0x00000080
516e213616SThomas Gleixner #define IRQF_PROBE_SHARED	0x00000100
526e213616SThomas Gleixner #define IRQF_TIMER		0x00000200
53284c6680SThomas Gleixner #define IRQF_PERCPU		0x00000400
54950f4427SThomas Gleixner #define IRQF_NOBALANCING	0x00000800
556e213616SThomas Gleixner 
566e213616SThomas Gleixner /*
576e213616SThomas Gleixner  * Migration helpers. Scheduled for removal in 1/2007
586e213616SThomas Gleixner  * Do not use for new code !
596e213616SThomas Gleixner  */
606e213616SThomas Gleixner #define SA_INTERRUPT		IRQF_DISABLED
616e213616SThomas Gleixner #define SA_SAMPLE_RANDOM	IRQF_SAMPLE_RANDOM
626e213616SThomas Gleixner #define SA_SHIRQ		IRQF_SHARED
636e213616SThomas Gleixner #define SA_PROBEIRQ		IRQF_PROBE_SHARED
64284c6680SThomas Gleixner #define SA_PERCPU		IRQF_PERCPU
656e213616SThomas Gleixner 
666e213616SThomas Gleixner #define SA_TRIGGER_LOW		IRQF_TRIGGER_LOW
676e213616SThomas Gleixner #define SA_TRIGGER_HIGH		IRQF_TRIGGER_HIGH
686e213616SThomas Gleixner #define SA_TRIGGER_FALLING	IRQF_TRIGGER_FALLING
696e213616SThomas Gleixner #define SA_TRIGGER_RISING	IRQF_TRIGGER_RISING
706e213616SThomas Gleixner #define SA_TRIGGER_MASK		IRQF_TRIGGER_MASK
716e213616SThomas Gleixner 
727d12e780SDavid Howells typedef irqreturn_t (*irq_handler_t)(int, void *);
73da482792SDavid Howells 
741da177e4SLinus Torvalds struct irqaction {
75da482792SDavid Howells 	irq_handler_t handler;
761da177e4SLinus Torvalds 	unsigned long flags;
771da177e4SLinus Torvalds 	cpumask_t mask;
781da177e4SLinus Torvalds 	const char *name;
791da177e4SLinus Torvalds 	void *dev_id;
801da177e4SLinus Torvalds 	struct irqaction *next;
811da177e4SLinus Torvalds 	int irq;
821da177e4SLinus Torvalds 	struct proc_dir_entry *dir;
831da177e4SLinus Torvalds };
841da177e4SLinus Torvalds 
857d12e780SDavid Howells extern irqreturn_t no_action(int cpl, void *dev_id);
86da482792SDavid Howells extern int request_irq(unsigned int, irq_handler_t handler,
871da177e4SLinus Torvalds 		       unsigned long, const char *, void *);
881da177e4SLinus Torvalds extern void free_irq(unsigned int, void *);
891da177e4SLinus Torvalds 
909ac7849eSTejun Heo extern int devm_request_irq(struct device *dev, unsigned int irq,
919ac7849eSTejun Heo 			    irq_handler_t handler, unsigned long irqflags,
929ac7849eSTejun Heo 			    const char *devname, void *dev_id);
939ac7849eSTejun Heo extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
949ac7849eSTejun Heo 
95d7e9629dSIngo Molnar /*
96d7e9629dSIngo Molnar  * On lockdep we dont want to enable hardirqs in hardirq
97d7e9629dSIngo Molnar  * context. Use local_irq_enable_in_hardirq() to annotate
98d7e9629dSIngo Molnar  * kernel code that has to do this nevertheless (pretty much
99d7e9629dSIngo Molnar  * the only valid case is for old/broken hardware that is
100d7e9629dSIngo Molnar  * insanely slow).
101d7e9629dSIngo Molnar  *
102d7e9629dSIngo Molnar  * NOTE: in theory this might break fragile code that relies
103d7e9629dSIngo Molnar  * on hardirq delivery - in practice we dont seem to have such
104d7e9629dSIngo Molnar  * places left. So the only effect should be slightly increased
105d7e9629dSIngo Molnar  * irqs-off latencies.
106d7e9629dSIngo Molnar  */
107d7e9629dSIngo Molnar #ifdef CONFIG_LOCKDEP
108d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	do { } while (0)
109d7e9629dSIngo Molnar #else
110d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq()	local_irq_enable()
111d7e9629dSIngo Molnar #endif
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds #ifdef CONFIG_GENERIC_HARDIRQS
1141da177e4SLinus Torvalds extern void disable_irq_nosync(unsigned int irq);
1151da177e4SLinus Torvalds extern void disable_irq(unsigned int irq);
1161da177e4SLinus Torvalds extern void enable_irq(unsigned int irq);
117ba9a2331SThomas Gleixner 
118c01d403bSIngo Molnar /*
119c01d403bSIngo Molnar  * Special lockdep variants of irq disabling/enabling.
120c01d403bSIngo Molnar  * These should be used for locking constructs that
121c01d403bSIngo Molnar  * know that a particular irq context which is disabled,
122c01d403bSIngo Molnar  * and which is the only irq-context user of a lock,
123c01d403bSIngo Molnar  * that it's safe to take the lock in the irq-disabled
124c01d403bSIngo Molnar  * section without disabling hardirqs.
125c01d403bSIngo Molnar  *
126c01d403bSIngo Molnar  * On !CONFIG_LOCKDEP they are equivalent to the normal
127c01d403bSIngo Molnar  * irq disable/enable methods.
128c01d403bSIngo Molnar  */
129c01d403bSIngo Molnar static inline void disable_irq_nosync_lockdep(unsigned int irq)
130c01d403bSIngo Molnar {
131c01d403bSIngo Molnar 	disable_irq_nosync(irq);
132c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
133c01d403bSIngo Molnar 	local_irq_disable();
134c01d403bSIngo Molnar #endif
135c01d403bSIngo Molnar }
136c01d403bSIngo Molnar 
137e8106b94SArjan van de Ven static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
138e8106b94SArjan van de Ven {
139e8106b94SArjan van de Ven 	disable_irq_nosync(irq);
140e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
141e8106b94SArjan van de Ven 	local_irq_save(*flags);
142e8106b94SArjan van de Ven #endif
143e8106b94SArjan van de Ven }
144e8106b94SArjan van de Ven 
145c01d403bSIngo Molnar static inline void disable_irq_lockdep(unsigned int irq)
146c01d403bSIngo Molnar {
147c01d403bSIngo Molnar 	disable_irq(irq);
148c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
149c01d403bSIngo Molnar 	local_irq_disable();
150c01d403bSIngo Molnar #endif
151c01d403bSIngo Molnar }
152c01d403bSIngo Molnar 
153c01d403bSIngo Molnar static inline void enable_irq_lockdep(unsigned int irq)
154c01d403bSIngo Molnar {
155c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP
156c01d403bSIngo Molnar 	local_irq_enable();
157c01d403bSIngo Molnar #endif
158c01d403bSIngo Molnar 	enable_irq(irq);
159c01d403bSIngo Molnar }
160c01d403bSIngo Molnar 
161e8106b94SArjan van de Ven static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
162e8106b94SArjan van de Ven {
163e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP
164e8106b94SArjan van de Ven 	local_irq_restore(*flags);
165e8106b94SArjan van de Ven #endif
166e8106b94SArjan van de Ven 	enable_irq(irq);
167e8106b94SArjan van de Ven }
168e8106b94SArjan van de Ven 
169ba9a2331SThomas Gleixner /* IRQ wakeup (PM) control: */
170ba9a2331SThomas Gleixner extern int set_irq_wake(unsigned int irq, unsigned int on);
171ba9a2331SThomas Gleixner 
172ba9a2331SThomas Gleixner static inline int enable_irq_wake(unsigned int irq)
173ba9a2331SThomas Gleixner {
174ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 1);
175ba9a2331SThomas Gleixner }
176ba9a2331SThomas Gleixner 
177ba9a2331SThomas Gleixner static inline int disable_irq_wake(unsigned int irq)
178ba9a2331SThomas Gleixner {
179ba9a2331SThomas Gleixner 	return set_irq_wake(irq, 0);
180ba9a2331SThomas Gleixner }
181ba9a2331SThomas Gleixner 
182c01d403bSIngo Molnar #else /* !CONFIG_GENERIC_HARDIRQS */
183c01d403bSIngo Molnar /*
184c01d403bSIngo Molnar  * NOTE: non-genirq architectures, if they want to support the lock
185c01d403bSIngo Molnar  * validator need to define the methods below in their asm/irq.h
186c01d403bSIngo Molnar  * files, under an #ifdef CONFIG_LOCKDEP section.
187c01d403bSIngo Molnar  */
188c01d403bSIngo Molnar # ifndef CONFIG_LOCKDEP
189c01d403bSIngo Molnar #  define disable_irq_nosync_lockdep(irq)	disable_irq_nosync(irq)
190c01d403bSIngo Molnar #  define disable_irq_lockdep(irq)		disable_irq(irq)
191c01d403bSIngo Molnar #  define enable_irq_lockdep(irq)		enable_irq(irq)
1921da177e4SLinus Torvalds # endif
1931da177e4SLinus Torvalds 
194c01d403bSIngo Molnar #endif /* CONFIG_GENERIC_HARDIRQS */
195c01d403bSIngo Molnar 
1963f74478bSAndi Kleen #ifndef __ARCH_SET_SOFTIRQ_PENDING
1973f74478bSAndi Kleen #define set_softirq_pending(x) (local_softirq_pending() = (x))
1983f74478bSAndi Kleen #define or_softirq_pending(x)  (local_softirq_pending() |= (x))
1993f74478bSAndi Kleen #endif
2003f74478bSAndi Kleen 
2011da177e4SLinus Torvalds /*
2021da177e4SLinus Torvalds  * Temporary defines for UP kernels, until all code gets fixed.
2031da177e4SLinus Torvalds  */
2041da177e4SLinus Torvalds #ifndef CONFIG_SMP
2051da177e4SLinus Torvalds static inline void __deprecated cli(void)
2061da177e4SLinus Torvalds {
2071da177e4SLinus Torvalds 	local_irq_disable();
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds static inline void __deprecated sti(void)
2101da177e4SLinus Torvalds {
2111da177e4SLinus Torvalds 	local_irq_enable();
2121da177e4SLinus Torvalds }
2131da177e4SLinus Torvalds static inline void __deprecated save_flags(unsigned long *x)
2141da177e4SLinus Torvalds {
2151da177e4SLinus Torvalds 	local_save_flags(*x);
2161da177e4SLinus Torvalds }
217ef9ceab2SAndrew Morton #define save_flags(x) save_flags(&x)
2181da177e4SLinus Torvalds static inline void __deprecated restore_flags(unsigned long x)
2191da177e4SLinus Torvalds {
2201da177e4SLinus Torvalds 	local_irq_restore(x);
2211da177e4SLinus Torvalds }
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds static inline void __deprecated save_and_cli(unsigned long *x)
2241da177e4SLinus Torvalds {
2251da177e4SLinus Torvalds 	local_irq_save(*x);
2261da177e4SLinus Torvalds }
2271da177e4SLinus Torvalds #define save_and_cli(x)	save_and_cli(&x)
2281da177e4SLinus Torvalds #endif /* CONFIG_SMP */
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
2311da177e4SLinus Torvalds    frequency threaded job scheduling. For almost all the purposes
2321da177e4SLinus Torvalds    tasklets are more than enough. F.e. all serial device BHs et
2331da177e4SLinus Torvalds    al. should be converted to tasklets, not to softirqs.
2341da177e4SLinus Torvalds  */
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds enum
2371da177e4SLinus Torvalds {
2381da177e4SLinus Torvalds 	HI_SOFTIRQ=0,
2391da177e4SLinus Torvalds 	TIMER_SOFTIRQ,
2401da177e4SLinus Torvalds 	NET_TX_SOFTIRQ,
2411da177e4SLinus Torvalds 	NET_RX_SOFTIRQ,
242ff856badSJens Axboe 	BLOCK_SOFTIRQ,
243c9819f45SChristoph Lameter 	TASKLET_SOFTIRQ,
244c9819f45SChristoph Lameter 	SCHED_SOFTIRQ,
245*54cdfdb4SThomas Gleixner #ifdef CONFIG_HIGH_RES_TIMERS
246*54cdfdb4SThomas Gleixner 	HRTIMER_SOFTIRQ,
247*54cdfdb4SThomas Gleixner #endif
2481da177e4SLinus Torvalds };
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds /* softirq mask and active fields moved to irq_cpustat_t in
2511da177e4SLinus Torvalds  * asm/hardirq.h to get better cache usage.  KAO
2521da177e4SLinus Torvalds  */
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds struct softirq_action
2551da177e4SLinus Torvalds {
2561da177e4SLinus Torvalds 	void	(*action)(struct softirq_action *);
2571da177e4SLinus Torvalds 	void	*data;
2581da177e4SLinus Torvalds };
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds asmlinkage void do_softirq(void);
2611da177e4SLinus Torvalds extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
2621da177e4SLinus Torvalds extern void softirq_init(void);
2633f74478bSAndi Kleen #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
2641da177e4SLinus Torvalds extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
2651da177e4SLinus Torvalds extern void FASTCALL(raise_softirq(unsigned int nr));
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds /* Tasklets --- multithreaded analogue of BHs.
2691da177e4SLinus Torvalds 
2701da177e4SLinus Torvalds    Main feature differing them of generic softirqs: tasklet
2711da177e4SLinus Torvalds    is running only on one CPU simultaneously.
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds    Main feature differing them of BHs: different tasklets
2741da177e4SLinus Torvalds    may be run simultaneously on different CPUs.
2751da177e4SLinus Torvalds 
2761da177e4SLinus Torvalds    Properties:
2771da177e4SLinus Torvalds    * If tasklet_schedule() is called, then tasklet is guaranteed
2781da177e4SLinus Torvalds      to be executed on some cpu at least once after this.
2791da177e4SLinus Torvalds    * If the tasklet is already scheduled, but its excecution is still not
2801da177e4SLinus Torvalds      started, it will be executed only once.
2811da177e4SLinus Torvalds    * If this tasklet is already running on another CPU (or schedule is called
2821da177e4SLinus Torvalds      from tasklet itself), it is rescheduled for later.
2831da177e4SLinus Torvalds    * Tasklet is strictly serialized wrt itself, but not
2841da177e4SLinus Torvalds      wrt another tasklets. If client needs some intertask synchronization,
2851da177e4SLinus Torvalds      he makes it with spinlocks.
2861da177e4SLinus Torvalds  */
2871da177e4SLinus Torvalds 
2881da177e4SLinus Torvalds struct tasklet_struct
2891da177e4SLinus Torvalds {
2901da177e4SLinus Torvalds 	struct tasklet_struct *next;
2911da177e4SLinus Torvalds 	unsigned long state;
2921da177e4SLinus Torvalds 	atomic_t count;
2931da177e4SLinus Torvalds 	void (*func)(unsigned long);
2941da177e4SLinus Torvalds 	unsigned long data;
2951da177e4SLinus Torvalds };
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds #define DECLARE_TASKLET(name, func, data) \
2981da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds #define DECLARE_TASKLET_DISABLED(name, func, data) \
3011da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds enum
3051da177e4SLinus Torvalds {
3061da177e4SLinus Torvalds 	TASKLET_STATE_SCHED,	/* Tasklet is scheduled for execution */
3071da177e4SLinus Torvalds 	TASKLET_STATE_RUN	/* Tasklet is running (SMP only) */
3081da177e4SLinus Torvalds };
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds #ifdef CONFIG_SMP
3111da177e4SLinus Torvalds static inline int tasklet_trylock(struct tasklet_struct *t)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds static inline void tasklet_unlock(struct tasklet_struct *t)
3171da177e4SLinus Torvalds {
3181da177e4SLinus Torvalds 	smp_mb__before_clear_bit();
3191da177e4SLinus Torvalds 	clear_bit(TASKLET_STATE_RUN, &(t)->state);
3201da177e4SLinus Torvalds }
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds static inline void tasklet_unlock_wait(struct tasklet_struct *t)
3231da177e4SLinus Torvalds {
3241da177e4SLinus Torvalds 	while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
3251da177e4SLinus Torvalds }
3261da177e4SLinus Torvalds #else
3271da177e4SLinus Torvalds #define tasklet_trylock(t) 1
3281da177e4SLinus Torvalds #define tasklet_unlock_wait(t) do { } while (0)
3291da177e4SLinus Torvalds #define tasklet_unlock(t) do { } while (0)
3301da177e4SLinus Torvalds #endif
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds static inline void tasklet_schedule(struct tasklet_struct *t)
3351da177e4SLinus Torvalds {
3361da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
3371da177e4SLinus Torvalds 		__tasklet_schedule(t);
3381da177e4SLinus Torvalds }
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds static inline void tasklet_hi_schedule(struct tasklet_struct *t)
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds 	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
3451da177e4SLinus Torvalds 		__tasklet_hi_schedule(t);
3461da177e4SLinus Torvalds }
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds static inline void tasklet_disable_nosync(struct tasklet_struct *t)
3501da177e4SLinus Torvalds {
3511da177e4SLinus Torvalds 	atomic_inc(&t->count);
3521da177e4SLinus Torvalds 	smp_mb__after_atomic_inc();
3531da177e4SLinus Torvalds }
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds static inline void tasklet_disable(struct tasklet_struct *t)
3561da177e4SLinus Torvalds {
3571da177e4SLinus Torvalds 	tasklet_disable_nosync(t);
3581da177e4SLinus Torvalds 	tasklet_unlock_wait(t);
3591da177e4SLinus Torvalds 	smp_mb();
3601da177e4SLinus Torvalds }
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds static inline void tasklet_enable(struct tasklet_struct *t)
3631da177e4SLinus Torvalds {
3641da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
3651da177e4SLinus Torvalds 	atomic_dec(&t->count);
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds static inline void tasklet_hi_enable(struct tasklet_struct *t)
3691da177e4SLinus Torvalds {
3701da177e4SLinus Torvalds 	smp_mb__before_atomic_dec();
3711da177e4SLinus Torvalds 	atomic_dec(&t->count);
3721da177e4SLinus Torvalds }
3731da177e4SLinus Torvalds 
3741da177e4SLinus Torvalds extern void tasklet_kill(struct tasklet_struct *t);
3751da177e4SLinus Torvalds extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
3761da177e4SLinus Torvalds extern void tasklet_init(struct tasklet_struct *t,
3771da177e4SLinus Torvalds 			 void (*func)(unsigned long), unsigned long data);
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds /*
3801da177e4SLinus Torvalds  * Autoprobing for irqs:
3811da177e4SLinus Torvalds  *
3821da177e4SLinus Torvalds  * probe_irq_on() and probe_irq_off() provide robust primitives
3831da177e4SLinus Torvalds  * for accurate IRQ probing during kernel initialization.  They are
3841da177e4SLinus Torvalds  * reasonably simple to use, are not "fooled" by spurious interrupts,
3851da177e4SLinus Torvalds  * and, unlike other attempts at IRQ probing, they do not get hung on
3861da177e4SLinus Torvalds  * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
3871da177e4SLinus Torvalds  *
3881da177e4SLinus Torvalds  * For reasonably foolproof probing, use them as follows:
3891da177e4SLinus Torvalds  *
3901da177e4SLinus Torvalds  * 1. clear and/or mask the device's internal interrupt.
3911da177e4SLinus Torvalds  * 2. sti();
3921da177e4SLinus Torvalds  * 3. irqs = probe_irq_on();      // "take over" all unassigned idle IRQs
3931da177e4SLinus Torvalds  * 4. enable the device and cause it to trigger an interrupt.
3941da177e4SLinus Torvalds  * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
3951da177e4SLinus Torvalds  * 6. irq = probe_irq_off(irqs);  // get IRQ number, 0=none, negative=multiple
3961da177e4SLinus Torvalds  * 7. service the device to clear its pending interrupt.
3971da177e4SLinus Torvalds  * 8. loop again if paranoia is required.
3981da177e4SLinus Torvalds  *
3991da177e4SLinus Torvalds  * probe_irq_on() returns a mask of allocated irq's.
4001da177e4SLinus Torvalds  *
4011da177e4SLinus Torvalds  * probe_irq_off() takes the mask as a parameter,
4021da177e4SLinus Torvalds  * and returns the irq number which occurred,
4031da177e4SLinus Torvalds  * or zero if none occurred, or a negative irq number
4041da177e4SLinus Torvalds  * if more than one irq occurred.
4051da177e4SLinus Torvalds  */
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
4081da177e4SLinus Torvalds static inline unsigned long probe_irq_on(void)
4091da177e4SLinus Torvalds {
4101da177e4SLinus Torvalds 	return 0;
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds static inline int probe_irq_off(unsigned long val)
4131da177e4SLinus Torvalds {
4141da177e4SLinus Torvalds 	return 0;
4151da177e4SLinus Torvalds }
4161da177e4SLinus Torvalds static inline unsigned int probe_irq_mask(unsigned long val)
4171da177e4SLinus Torvalds {
4181da177e4SLinus Torvalds 	return 0;
4191da177e4SLinus Torvalds }
4201da177e4SLinus Torvalds #else
4211da177e4SLinus Torvalds extern unsigned long probe_irq_on(void);	/* returns 0 on failure */
4221da177e4SLinus Torvalds extern int probe_irq_off(unsigned long);	/* returns 0 or negative on failure */
4231da177e4SLinus Torvalds extern unsigned int probe_irq_mask(unsigned long);	/* returns mask of ISA interrupts */
4241da177e4SLinus Torvalds #endif
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds #endif
427