blob: f02204706984b9083437cb5a71e237f59f02d547 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* interrupt.h */
2#ifndef _LINUX_INTERRUPT_H
3#define _LINUX_INTERRUPT_H
4
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>
Al Virof0373602005-11-13 16:06:57 -080012#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/atomic.h>
14#include <asm/ptrace.h>
15#include <asm/system.h>
16
17/*
18 * For 2.4.x compatibility, 2.4.x can use
19 *
20 * typedef void irqreturn_t;
21 * #define IRQ_NONE
22 * #define IRQ_HANDLED
23 * #define IRQ_RETVAL(x)
24 *
25 * To mix old-style and new-style irq handler returns.
26 *
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)
30 */
31typedef int irqreturn_t;
32
33#define IRQ_NONE (0)
34#define IRQ_HANDLED (1)
35#define IRQ_RETVAL(x) ((x) != 0)
36
37struct irqaction {
38 irqreturn_t (*handler)(int, void *, struct pt_regs *);
39 unsigned long flags;
40 cpumask_t mask;
41 const char *name;
42 void *dev_id;
43 struct irqaction *next;
44 int irq;
45 struct proc_dir_entry *dir;
46};
47
48extern irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs);
49extern int request_irq(unsigned int,
50 irqreturn_t (*handler)(int, void *, struct pt_regs *),
51 unsigned long, const char *, void *);
52extern void free_irq(unsigned int, void *);
53
54
55#ifdef CONFIG_GENERIC_HARDIRQS
56extern void disable_irq_nosync(unsigned int irq);
57extern void disable_irq(unsigned int irq);
58extern void enable_irq(unsigned int irq);
59#endif
60
Andi Kleen3f744782005-09-12 18:49:24 +020061#ifndef __ARCH_SET_SOFTIRQ_PENDING
62#define set_softirq_pending(x) (local_softirq_pending() = (x))
63#define or_softirq_pending(x) (local_softirq_pending() |= (x))
64#endif
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/*
67 * Temporary defines for UP kernels, until all code gets fixed.
68 */
69#ifndef CONFIG_SMP
70static inline void __deprecated cli(void)
71{
72 local_irq_disable();
73}
74static inline void __deprecated sti(void)
75{
76 local_irq_enable();
77}
78static inline void __deprecated save_flags(unsigned long *x)
79{
80 local_save_flags(*x);
81}
Andrew Mortonef9ceab2006-01-08 01:05:10 -080082#define save_flags(x) save_flags(&x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static inline void __deprecated restore_flags(unsigned long x)
84{
85 local_irq_restore(x);
86}
87
88static inline void __deprecated save_and_cli(unsigned long *x)
89{
90 local_irq_save(*x);
91}
92#define save_and_cli(x) save_and_cli(&x)
93#endif /* CONFIG_SMP */
94
95/* SoftIRQ primitives. */
96#define local_bh_disable() \
97 do { add_preempt_count(SOFTIRQ_OFFSET); barrier(); } while (0)
98#define __local_bh_enable() \
99 do { barrier(); sub_preempt_count(SOFTIRQ_OFFSET); } while (0)
100
101extern void local_bh_enable(void);
102
103/* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
104 frequency threaded job scheduling. For almost all the purposes
105 tasklets are more than enough. F.e. all serial device BHs et
106 al. should be converted to tasklets, not to softirqs.
107 */
108
109enum
110{
111 HI_SOFTIRQ=0,
112 TIMER_SOFTIRQ,
113 NET_TX_SOFTIRQ,
114 NET_RX_SOFTIRQ,
Jens Axboeff856ba2006-01-09 16:02:34 +0100115 BLOCK_SOFTIRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 SCSI_SOFTIRQ,
117 TASKLET_SOFTIRQ
118};
119
120/* softirq mask and active fields moved to irq_cpustat_t in
121 * asm/hardirq.h to get better cache usage. KAO
122 */
123
124struct softirq_action
125{
126 void (*action)(struct softirq_action *);
127 void *data;
128};
129
130asmlinkage void do_softirq(void);
131extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
132extern void softirq_init(void);
Andi Kleen3f744782005-09-12 18:49:24 +0200133#define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
135extern void FASTCALL(raise_softirq(unsigned int nr));
136
137
138/* Tasklets --- multithreaded analogue of BHs.
139
140 Main feature differing them of generic softirqs: tasklet
141 is running only on one CPU simultaneously.
142
143 Main feature differing them of BHs: different tasklets
144 may be run simultaneously on different CPUs.
145
146 Properties:
147 * If tasklet_schedule() is called, then tasklet is guaranteed
148 to be executed on some cpu at least once after this.
149 * If the tasklet is already scheduled, but its excecution is still not
150 started, it will be executed only once.
151 * If this tasklet is already running on another CPU (or schedule is called
152 from tasklet itself), it is rescheduled for later.
153 * Tasklet is strictly serialized wrt itself, but not
154 wrt another tasklets. If client needs some intertask synchronization,
155 he makes it with spinlocks.
156 */
157
158struct tasklet_struct
159{
160 struct tasklet_struct *next;
161 unsigned long state;
162 atomic_t count;
163 void (*func)(unsigned long);
164 unsigned long data;
165};
166
167#define DECLARE_TASKLET(name, func, data) \
168struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
169
170#define DECLARE_TASKLET_DISABLED(name, func, data) \
171struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
172
173
174enum
175{
176 TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
177 TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
178};
179
180#ifdef CONFIG_SMP
181static inline int tasklet_trylock(struct tasklet_struct *t)
182{
183 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
184}
185
186static inline void tasklet_unlock(struct tasklet_struct *t)
187{
188 smp_mb__before_clear_bit();
189 clear_bit(TASKLET_STATE_RUN, &(t)->state);
190}
191
192static inline void tasklet_unlock_wait(struct tasklet_struct *t)
193{
194 while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
195}
196#else
197#define tasklet_trylock(t) 1
198#define tasklet_unlock_wait(t) do { } while (0)
199#define tasklet_unlock(t) do { } while (0)
200#endif
201
202extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
203
204static inline void tasklet_schedule(struct tasklet_struct *t)
205{
206 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
207 __tasklet_schedule(t);
208}
209
210extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
211
212static inline void tasklet_hi_schedule(struct tasklet_struct *t)
213{
214 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
215 __tasklet_hi_schedule(t);
216}
217
218
219static inline void tasklet_disable_nosync(struct tasklet_struct *t)
220{
221 atomic_inc(&t->count);
222 smp_mb__after_atomic_inc();
223}
224
225static inline void tasklet_disable(struct tasklet_struct *t)
226{
227 tasklet_disable_nosync(t);
228 tasklet_unlock_wait(t);
229 smp_mb();
230}
231
232static inline void tasklet_enable(struct tasklet_struct *t)
233{
234 smp_mb__before_atomic_dec();
235 atomic_dec(&t->count);
236}
237
238static inline void tasklet_hi_enable(struct tasklet_struct *t)
239{
240 smp_mb__before_atomic_dec();
241 atomic_dec(&t->count);
242}
243
244extern void tasklet_kill(struct tasklet_struct *t);
245extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
246extern void tasklet_init(struct tasklet_struct *t,
247 void (*func)(unsigned long), unsigned long data);
248
249/*
250 * Autoprobing for irqs:
251 *
252 * probe_irq_on() and probe_irq_off() provide robust primitives
253 * for accurate IRQ probing during kernel initialization. They are
254 * reasonably simple to use, are not "fooled" by spurious interrupts,
255 * and, unlike other attempts at IRQ probing, they do not get hung on
256 * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
257 *
258 * For reasonably foolproof probing, use them as follows:
259 *
260 * 1. clear and/or mask the device's internal interrupt.
261 * 2. sti();
262 * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
263 * 4. enable the device and cause it to trigger an interrupt.
264 * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
265 * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
266 * 7. service the device to clear its pending interrupt.
267 * 8. loop again if paranoia is required.
268 *
269 * probe_irq_on() returns a mask of allocated irq's.
270 *
271 * probe_irq_off() takes the mask as a parameter,
272 * and returns the irq number which occurred,
273 * or zero if none occurred, or a negative irq number
274 * if more than one irq occurred.
275 */
276
277#if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
278static inline unsigned long probe_irq_on(void)
279{
280 return 0;
281}
282static inline int probe_irq_off(unsigned long val)
283{
284 return 0;
285}
286static inline unsigned int probe_irq_mask(unsigned long val)
287{
288 return 0;
289}
290#else
291extern unsigned long probe_irq_on(void); /* returns 0 on failure */
292extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
293extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */
294#endif
295
296#endif