2 #ifndef _LINUX_INTERRUPT_H
3 #define _LINUX_INTERRUPT_H
5 #include <linux/config.h>
6 #include <linux/kernel.h>
8 #include <linux/cache.h>
10 #include <asm/bitops.h>
11 #include <asm/atomic.h>
12 #include <asm/ptrace.h>
15 void (*handler
)(int, void *, struct pt_regs
*);
20 struct irqaction
*next
;
24 /* Who gets which entry in bh_base. Things which will occur most often
45 #include <asm/hardirq.h>
46 #include <asm/softirq.h>
50 /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
51 frequency threaded job scheduling. For almost all the purposes
52 tasklets are more than enough. F.e. all serial device BHs et
53 al. should be converted to tasklets, not to softirqs.
64 /* softirq mask and active fields moved to irq_cpustat_t in
65 * asm/hardirq.h to get better cache usage. KAO
70 void (*action
)(struct softirq_action
*);
74 asmlinkage
void do_softirq(void);
75 extern void open_softirq(int nr
, void (*action
)(struct softirq_action
*), void *data
);
77 static inline void __cpu_raise_softirq(int cpu
, int nr
)
79 softirq_active(cpu
) |= (1<<nr
);
83 /* I do not want to use atomic variables now, so that cli/sti */
84 static inline void raise_softirq(int nr
)
88 local_irq_save(flags
);
89 __cpu_raise_softirq(smp_processor_id(), nr
);
90 local_irq_restore(flags
);
93 extern void softirq_init(void);
97 /* Tasklets --- multithreaded analogue of BHs.
99 Main feature differing them of generic softirqs: tasklet
100 is running only on one CPU simultaneously.
102 Main feature differing them of BHs: different tasklets
103 may be run simultaneously on different CPUs.
106 * If tasklet_schedule() is called, then tasklet is guaranteed
107 to be executed on some cpu at least once after this.
108 * If the tasklet is already scheduled, but its excecution is still not
109 started, it will be executed only once.
110 * If this tasklet is already running on another CPU (or schedule is called
111 from tasklet itself), it is rescheduled for later.
112 * Tasklet is strictly serialized wrt itself, but not
113 wrt another tasklets. If client needs some intertask synchronization,
114 he makes it with spinlocks.
117 struct tasklet_struct
119 struct tasklet_struct
*next
;
122 void (*func
)(unsigned long);
126 #define DECLARE_TASKLET(name, func, data) \
127 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
129 #define DECLARE_TASKLET_DISABLED(name, func, data) \
130 struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
135 TASKLET_STATE_SCHED
, /* Tasklet is scheduled for execution */
136 TASKLET_STATE_RUN
/* Tasklet is running (SMP only) */
141 struct tasklet_struct
*list
;
142 } __attribute__ ((__aligned__(SMP_CACHE_BYTES
)));
144 extern struct tasklet_head tasklet_vec
[NR_CPUS
];
145 extern struct tasklet_head tasklet_hi_vec
[NR_CPUS
];
148 #define tasklet_trylock(t) (!test_and_set_bit(TASKLET_STATE_RUN, &(t)->state))
149 #define tasklet_unlock_wait(t) while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { /* NOTHING */ }
150 #define tasklet_unlock(t) clear_bit(TASKLET_STATE_RUN, &(t)->state)
152 #define tasklet_trylock(t) 1
153 #define tasklet_unlock_wait(t) do { } while (0)
154 #define tasklet_unlock(t) do { } while (0)
157 static inline void tasklet_schedule(struct tasklet_struct
*t
)
159 if (!test_and_set_bit(TASKLET_STATE_SCHED
, &t
->state
)) {
160 int cpu
= smp_processor_id();
163 local_irq_save(flags
);
164 t
->next
= tasklet_vec
[cpu
].list
;
165 tasklet_vec
[cpu
].list
= t
;
166 __cpu_raise_softirq(cpu
, TASKLET_SOFTIRQ
);
167 local_irq_restore(flags
);
171 static inline void tasklet_hi_schedule(struct tasklet_struct
*t
)
173 if (!test_and_set_bit(TASKLET_STATE_SCHED
, &t
->state
)) {
174 int cpu
= smp_processor_id();
177 local_irq_save(flags
);
178 t
->next
= tasklet_hi_vec
[cpu
].list
;
179 tasklet_hi_vec
[cpu
].list
= t
;
180 __cpu_raise_softirq(cpu
, HI_SOFTIRQ
);
181 local_irq_restore(flags
);
186 static inline void tasklet_disable_nosync(struct tasklet_struct
*t
)
188 atomic_inc(&t
->count
);
191 static inline void tasklet_disable(struct tasklet_struct
*t
)
193 tasklet_disable_nosync(t
);
194 tasklet_unlock_wait(t
);
197 static inline void tasklet_enable(struct tasklet_struct
*t
)
199 atomic_dec(&t
->count
);
202 extern void tasklet_kill(struct tasklet_struct
*t
);
203 extern void tasklet_init(struct tasklet_struct
*t
,
204 void (*func
)(unsigned long), unsigned long data
);
208 #define SMP_TIMER_NAME(name) name##__thr
210 #define SMP_TIMER_DEFINE(name, task) \
211 DECLARE_TASKLET(task, name##__thr, 0); \
212 static void name (unsigned long dummy) \
214 tasklet_schedule(&(task)); \
217 #else /* CONFIG_SMP */
219 #define SMP_TIMER_NAME(name) name
220 #define SMP_TIMER_DEFINE(name, task)
222 #endif /* CONFIG_SMP */
225 /* Old BH definitions */
227 extern struct tasklet_struct bh_task_vec
[];
229 /* It is exported _ONLY_ for wait_on_irq(). */
230 extern spinlock_t global_bh_lock
;
232 static inline void mark_bh(int nr
)
234 tasklet_hi_schedule(bh_task_vec
+nr
);
237 extern void init_bh(int nr
, void (*routine
)(void));
238 extern void remove_bh(int nr
);
242 * Autoprobing for irqs:
244 * probe_irq_on() and probe_irq_off() provide robust primitives
245 * for accurate IRQ probing during kernel initialization. They are
246 * reasonably simple to use, are not "fooled" by spurious interrupts,
247 * and, unlike other attempts at IRQ probing, they do not get hung on
248 * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
250 * For reasonably foolproof probing, use them as follows:
252 * 1. clear and/or mask the device's internal interrupt.
254 * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
255 * 4. enable the device and cause it to trigger an interrupt.
256 * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
257 * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
258 * 7. service the device to clear its pending interrupt.
259 * 8. loop again if paranoia is required.
261 * probe_irq_on() returns a mask of allocated irq's.
263 * probe_irq_off() takes the mask as a parameter,
264 * and returns the irq number which occurred,
265 * or zero if none occurred, or a negative irq number
266 * if more than one irq occurred.
268 extern unsigned long probe_irq_on(void); /* returns 0 on failure */
269 extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
270 extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */