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 <linux/sched.h>
13 #include <asm/atomic.h>
14 #include <asm/ptrace.h>
15 #include <asm/system.h>
18 * For 2.4.x compatibility, 2.4.x can use
20 * typedef void irqreturn_t;
23 * #define IRQ_RETVAL(x)
25 * To mix old-style and new-style irq handler returns.
27 * IRQ_NONE means we didn't handle it.
28 * IRQ_HANDLED means that we did have a valid interrupt and handled it.
29 * IRQ_RETVAL(x) selects on the two depending on x being non-zero (for handled)
31 typedef int irqreturn_t;
34 #define IRQ_HANDLED (1)
35 #define IRQ_RETVAL(x) ((x) != 0)
38 irqreturn_t (*handler)(int, void *, struct pt_regs *);
43 struct irqaction *next;
45 struct proc_dir_entry *dir;
48 extern irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs);
49 extern int request_irq(unsigned int,
50 irqreturn_t (*handler)(int, void *, struct pt_regs *),
51 unsigned long, const char *, void *);
52 extern void free_irq(unsigned int, void *);
55 #ifdef CONFIG_GENERIC_HARDIRQS
56 extern void disable_irq_nosync(unsigned int irq);
57 extern void disable_irq(unsigned int irq);
58 extern void enable_irq(unsigned int irq);
61 #ifdef CONFIG_HAVE_IRQ_IGNORE_UNHANDLED
62 int irq_ignore_unhandled(unsigned int irq);
64 #define irq_ignore_unhandled(irq) 0
67 #ifndef __ARCH_SET_SOFTIRQ_PENDING
68 #define set_softirq_pending(x) (local_softirq_pending() = (x))
69 #define or_softirq_pending(x) (local_softirq_pending() |= (x))
73 * Temporary defines for UP kernels, until all code gets fixed.
76 static inline void __deprecated cli(void)
80 static inline void __deprecated sti(void)
84 static inline void __deprecated save_flags(unsigned long *x)
88 #define save_flags(x) save_flags(&x)
89 static inline void __deprecated restore_flags(unsigned long x)
94 static inline void __deprecated save_and_cli(unsigned long *x)
98 #define save_and_cli(x) save_and_cli(&x)
99 #endif /* CONFIG_SMP */
101 /* SoftIRQ primitives. */
102 #define local_bh_disable() \
103 do { add_preempt_count(SOFTIRQ_OFFSET); barrier(); } while (0)
104 #define __local_bh_enable() \
105 do { barrier(); sub_preempt_count(SOFTIRQ_OFFSET); } while (0)
107 extern void local_bh_enable(void);
109 /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
110 frequency threaded job scheduling. For almost all the purposes
111 tasklets are more than enough. F.e. all serial device BHs et
112 al. should be converted to tasklets, not to softirqs.
125 /* softirq mask and active fields moved to irq_cpustat_t in
126 * asm/hardirq.h to get better cache usage. KAO
129 struct softirq_action
131 void (*action)(struct softirq_action *);
135 asmlinkage void do_softirq(void);
136 extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
137 extern void softirq_init(void);
138 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
139 extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
140 extern void FASTCALL(raise_softirq(unsigned int nr));
143 /* Tasklets --- multithreaded analogue of BHs.
145 Main feature differing them of generic softirqs: tasklet
146 is running only on one CPU simultaneously.
148 Main feature differing them of BHs: different tasklets
149 may be run simultaneously on different CPUs.
152 * If tasklet_schedule() is called, then tasklet is guaranteed
153 to be executed on some cpu at least once after this.
154 * If the tasklet is already scheduled, but its excecution is still not
155 started, it will be executed only once.
156 * If this tasklet is already running on another CPU (or schedule is called
157 from tasklet itself), it is rescheduled for later.
158 * Tasklet is strictly serialized wrt itself, but not
159 wrt another tasklets. If client needs some intertask synchronization,
160 he makes it with spinlocks.
163 struct tasklet_struct
165 struct tasklet_struct *next;
168 void (*func)(unsigned long);
172 #define DECLARE_TASKLET(name, func, data) \
173 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
175 #define DECLARE_TASKLET_DISABLED(name, func, data) \
176 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
181 TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
182 TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
186 static inline int tasklet_trylock(struct tasklet_struct *t)
188 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
191 static inline void tasklet_unlock(struct tasklet_struct *t)
193 smp_mb__before_clear_bit();
194 clear_bit(TASKLET_STATE_RUN, &(t)->state);
197 static inline void tasklet_unlock_wait(struct tasklet_struct *t)
199 while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
202 #define tasklet_trylock(t) 1
203 #define tasklet_unlock_wait(t) do { } while (0)
204 #define tasklet_unlock(t) do { } while (0)
207 extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
209 static inline void tasklet_schedule(struct tasklet_struct *t)
211 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
212 __tasklet_schedule(t);
215 extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
217 static inline void tasklet_hi_schedule(struct tasklet_struct *t)
219 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
220 __tasklet_hi_schedule(t);
224 static inline void tasklet_disable_nosync(struct tasklet_struct *t)
226 atomic_inc(&t->count);
227 smp_mb__after_atomic_inc();
230 static inline void tasklet_disable(struct tasklet_struct *t)
232 tasklet_disable_nosync(t);
233 tasklet_unlock_wait(t);
237 static inline void tasklet_enable(struct tasklet_struct *t)
239 smp_mb__before_atomic_dec();
240 atomic_dec(&t->count);
243 static inline void tasklet_hi_enable(struct tasklet_struct *t)
245 smp_mb__before_atomic_dec();
246 atomic_dec(&t->count);
249 extern void tasklet_kill(struct tasklet_struct *t);
250 extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
251 extern void tasklet_init(struct tasklet_struct *t,
252 void (*func)(unsigned long), unsigned long data);
255 * Autoprobing for irqs:
257 * probe_irq_on() and probe_irq_off() provide robust primitives
258 * for accurate IRQ probing during kernel initialization. They are
259 * reasonably simple to use, are not "fooled" by spurious interrupts,
260 * and, unlike other attempts at IRQ probing, they do not get hung on
261 * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
263 * For reasonably foolproof probing, use them as follows:
265 * 1. clear and/or mask the device's internal interrupt.
267 * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
268 * 4. enable the device and cause it to trigger an interrupt.
269 * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
270 * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
271 * 7. service the device to clear its pending interrupt.
272 * 8. loop again if paranoia is required.
274 * probe_irq_on() returns a mask of allocated irq's.
276 * probe_irq_off() takes the mask as a parameter,
277 * and returns the irq number which occurred,
278 * or zero if none occurred, or a negative irq number
279 * if more than one irq occurred.
282 #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
283 static inline unsigned long probe_irq_on(void)
287 static inline int probe_irq_off(unsigned long val)
291 static inline unsigned int probe_irq_mask(unsigned long val)
296 extern unsigned long probe_irq_on(void); /* returns 0 on failure */
297 extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
298 extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */