2 #ifndef _LINUX_INTERRUPT_H
3 #define _LINUX_INTERRUPT_H
5 #include <linux/config.h>
6 #include <linux/kernel.h>
7 #include <linux/linkage.h>
8 #include <linux/bitops.h>
9 #include <linux/preempt.h>
10 #include <linux/cpumask.h>
11 #include <linux/hardirq.h>
12 #include <asm/atomic.h>
13 #include <asm/ptrace.h>
14 #include <asm/system.h>
17 * For 2.4.x compatibility, 2.4.x can use
19 * typedef void irqreturn_t;
22 * #define IRQ_RETVAL(x)
24 * To mix old-style and new-style irq handler returns.
26 * IRQ_NONE means we didn't handle it.
27 * IRQ_HANDLED means that we did have a valid interrupt and handled it.
28 * IRQ_RETVAL(x) selects on the two depending on x being non-zero (for handled)
30 typedef int irqreturn_t;
33 #define IRQ_HANDLED (1)
34 #define IRQ_RETVAL(x) ((x) != 0)
37 irqreturn_t (*handler)(int, void *, struct pt_regs *);
42 struct irqaction *next;
44 struct proc_dir_entry *dir;
47 extern irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs);
48 extern int request_irq(unsigned int,
49 irqreturn_t (*handler)(int, void *, struct pt_regs *),
50 unsigned long, const char *, void *);
51 extern void free_irq(unsigned int, void *);
54 #ifdef CONFIG_GENERIC_HARDIRQS
55 extern void disable_irq_nosync(unsigned int irq);
56 extern void disable_irq(unsigned int irq);
57 extern void enable_irq(unsigned int irq);
60 #ifndef __ARCH_SET_SOFTIRQ_PENDING
61 #define set_softirq_pending(x) (local_softirq_pending() = (x))
62 #define or_softirq_pending(x) (local_softirq_pending() |= (x))
66 * Temporary defines for UP kernels, until all code gets fixed.
69 static inline void __deprecated cli(void)
73 static inline void __deprecated sti(void)
77 static inline void __deprecated save_flags(unsigned long *x)
81 #define save_flags(x) save_flags(&x);
82 static inline void __deprecated restore_flags(unsigned long x)
87 static inline void __deprecated save_and_cli(unsigned long *x)
91 #define save_and_cli(x) save_and_cli(&x)
92 #endif /* CONFIG_SMP */
94 /* SoftIRQ primitives. */
95 #define local_bh_disable() \
96 do { add_preempt_count(SOFTIRQ_OFFSET); barrier(); } while (0)
97 #define __local_bh_enable() \
98 do { barrier(); sub_preempt_count(SOFTIRQ_OFFSET); } while (0)
100 extern void local_bh_enable(void);
102 /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
103 frequency threaded job scheduling. For almost all the purposes
104 tasklets are more than enough. F.e. all serial device BHs et
105 al. should be converted to tasklets, not to softirqs.
118 /* softirq mask and active fields moved to irq_cpustat_t in
119 * asm/hardirq.h to get better cache usage. KAO
122 struct softirq_action
124 void (*action)(struct softirq_action *);
128 asmlinkage void do_softirq(void);
129 extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
130 extern void softirq_init(void);
131 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
132 extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
133 extern void FASTCALL(raise_softirq(unsigned int nr));
136 /* Tasklets --- multithreaded analogue of BHs.
138 Main feature differing them of generic softirqs: tasklet
139 is running only on one CPU simultaneously.
141 Main feature differing them of BHs: different tasklets
142 may be run simultaneously on different CPUs.
145 * If tasklet_schedule() is called, then tasklet is guaranteed
146 to be executed on some cpu at least once after this.
147 * If the tasklet is already scheduled, but its excecution is still not
148 started, it will be executed only once.
149 * If this tasklet is already running on another CPU (or schedule is called
150 from tasklet itself), it is rescheduled for later.
151 * Tasklet is strictly serialized wrt itself, but not
152 wrt another tasklets. If client needs some intertask synchronization,
153 he makes it with spinlocks.
156 struct tasklet_struct
158 struct tasklet_struct *next;
161 void (*func)(unsigned long);
165 #define DECLARE_TASKLET(name, func, data) \
166 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
168 #define DECLARE_TASKLET_DISABLED(name, func, data) \
169 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
174 TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
175 TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
179 static inline int tasklet_trylock(struct tasklet_struct *t)
181 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
184 static inline void tasklet_unlock(struct tasklet_struct *t)
186 smp_mb__before_clear_bit();
187 clear_bit(TASKLET_STATE_RUN, &(t)->state);
190 static inline void tasklet_unlock_wait(struct tasklet_struct *t)
192 while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
195 #define tasklet_trylock(t) 1
196 #define tasklet_unlock_wait(t) do { } while (0)
197 #define tasklet_unlock(t) do { } while (0)
200 extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
202 static inline void tasklet_schedule(struct tasklet_struct *t)
204 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
205 __tasklet_schedule(t);
208 extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
210 static inline void tasklet_hi_schedule(struct tasklet_struct *t)
212 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
213 __tasklet_hi_schedule(t);
217 static inline void tasklet_disable_nosync(struct tasklet_struct *t)
219 atomic_inc(&t->count);
220 smp_mb__after_atomic_inc();
223 static inline void tasklet_disable(struct tasklet_struct *t)
225 tasklet_disable_nosync(t);
226 tasklet_unlock_wait(t);
230 static inline void tasklet_enable(struct tasklet_struct *t)
232 smp_mb__before_atomic_dec();
233 atomic_dec(&t->count);
236 static inline void tasklet_hi_enable(struct tasklet_struct *t)
238 smp_mb__before_atomic_dec();
239 atomic_dec(&t->count);
242 extern void tasklet_kill(struct tasklet_struct *t);
243 extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
244 extern void tasklet_init(struct tasklet_struct *t,
245 void (*func)(unsigned long), unsigned long data);
248 * Autoprobing for irqs:
250 * probe_irq_on() and probe_irq_off() provide robust primitives
251 * for accurate IRQ probing during kernel initialization. They are
252 * reasonably simple to use, are not "fooled" by spurious interrupts,
253 * and, unlike other attempts at IRQ probing, they do not get hung on
254 * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
256 * For reasonably foolproof probing, use them as follows:
258 * 1. clear and/or mask the device's internal interrupt.
260 * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
261 * 4. enable the device and cause it to trigger an interrupt.
262 * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
263 * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
264 * 7. service the device to clear its pending interrupt.
265 * 8. loop again if paranoia is required.
267 * probe_irq_on() returns a mask of allocated irq's.
269 * probe_irq_off() takes the mask as a parameter,
270 * and returns the irq number which occurred,
271 * or zero if none occurred, or a negative irq number
272 * if more than one irq occurred.
275 #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
276 static inline unsigned long probe_irq_on(void)
280 static inline int probe_irq_off(unsigned long val)
284 static inline unsigned int probe_irq_mask(unsigned long val)
289 extern unsigned long probe_irq_on(void); /* returns 0 on failure */
290 extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
291 extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */