1
2#ifndef _LINUX_INTERRUPT_H
3#define _LINUX_INTERRUPT_H
4
5#include <linux/kernel.h>
6#include <linux/linkage.h>
7#include <linux/bitops.h>
8#include <linux/preempt.h>
9#include <linux/cpumask.h>
10#include <linux/irqreturn.h>
11#include <linux/hardirq.h>
12#include <linux/sched.h>
13#include <linux/irqflags.h>
14#include <linux/bottom_half.h>
15#include <linux/device.h>
16#include <asm/atomic.h>
17#include <asm/ptrace.h>
18#include <asm/system.h>
19
20
21
22
23
24
25
26
27#define IRQF_TRIGGER_NONE 0x00000000
28#define IRQF_TRIGGER_RISING 0x00000001
29#define IRQF_TRIGGER_FALLING 0x00000002
30#define IRQF_TRIGGER_HIGH 0x00000004
31#define IRQF_TRIGGER_LOW 0x00000008
32#define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
33 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
34#define IRQF_TRIGGER_PROBE 0x00000010
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#define IRQF_DISABLED 0x00000020
52#define IRQF_SAMPLE_RANDOM 0x00000040
53#define IRQF_SHARED 0x00000080
54#define IRQF_PROBE_SHARED 0x00000100
55#define IRQF_TIMER 0x00000200
56#define IRQF_PERCPU 0x00000400
57#define IRQF_NOBALANCING 0x00000800
58#define IRQF_IRQPOLL 0x00001000
59
60
61
62
63
64static inline
65unsigned long __deprecated deprecated_irq_flag(unsigned long flag)
66{
67 return flag;
68}
69
70#define SA_INTERRUPT deprecated_irq_flag(IRQF_DISABLED)
71#define SA_SAMPLE_RANDOM deprecated_irq_flag(IRQF_SAMPLE_RANDOM)
72#define SA_SHIRQ deprecated_irq_flag(IRQF_SHARED)
73#define SA_PROBEIRQ deprecated_irq_flag(IRQF_PROBE_SHARED)
74#define SA_PERCPU deprecated_irq_flag(IRQF_PERCPU)
75
76#define SA_TRIGGER_LOW deprecated_irq_flag(IRQF_TRIGGER_LOW)
77#define SA_TRIGGER_HIGH deprecated_irq_flag(IRQF_TRIGGER_HIGH)
78#define SA_TRIGGER_FALLING deprecated_irq_flag(IRQF_TRIGGER_FALLING)
79#define SA_TRIGGER_RISING deprecated_irq_flag(IRQF_TRIGGER_RISING)
80#define SA_TRIGGER_MASK deprecated_irq_flag(IRQF_TRIGGER_MASK)
81
82typedef irqreturn_t (*irq_handler_t)(int, void *);
83
84struct irqaction {
85 irq_handler_t handler;
86 unsigned long flags;
87 cpumask_t mask;
88 const char *name;
89 void *dev_id;
90 struct irqaction *next;
91 int irq;
92 struct proc_dir_entry *dir;
93};
94
95extern irqreturn_t no_action(int cpl, void *dev_id);
96extern int __must_check request_irq(unsigned int, irq_handler_t handler,
97 unsigned long, const char *, void *);
98extern void free_irq(unsigned int, void *);
99
100extern int __must_check devm_request_irq(struct device *dev, unsigned int irq,
101 irq_handler_t handler, unsigned long irqflags,
102 const char *devname, void *dev_id);
103extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
104
105
106
107
108
109
110
111
112
113
114
115
116
117#ifdef CONFIG_LOCKDEP
118# define local_irq_enable_in_hardirq() do { } while (0)
119#else
120# define local_irq_enable_in_hardirq() local_irq_enable()
121#endif
122
123#ifdef CONFIG_GENERIC_HARDIRQS
124extern void disable_irq_nosync(unsigned int irq);
125extern void disable_irq(unsigned int irq);
126extern void enable_irq(unsigned int irq);
127
128
129
130
131
132
133
134
135
136
137
138
139static inline void disable_irq_nosync_lockdep(unsigned int irq)
140{
141 disable_irq_nosync(irq);
142#ifdef CONFIG_LOCKDEP
143 local_irq_disable();
144#endif
145}
146
147static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
148{
149 disable_irq_nosync(irq);
150#ifdef CONFIG_LOCKDEP
151 local_irq_save(*flags);
152#endif
153}
154
155static inline void disable_irq_lockdep(unsigned int irq)
156{
157 disable_irq(irq);
158#ifdef CONFIG_LOCKDEP
159 local_irq_disable();
160#endif
161}
162
163static inline void enable_irq_lockdep(unsigned int irq)
164{
165#ifdef CONFIG_LOCKDEP
166 local_irq_enable();
167#endif
168 enable_irq(irq);
169}
170
171static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
172{
173#ifdef CONFIG_LOCKDEP
174 local_irq_restore(*flags);
175#endif
176 enable_irq(irq);
177}
178
179
180extern int set_irq_wake(unsigned int irq, unsigned int on);
181
182static inline int enable_irq_wake(unsigned int irq)
183{
184 return set_irq_wake(irq, 1);
185}
186
187static inline int disable_irq_wake(unsigned int irq)
188{
189 return set_irq_wake(irq, 0);
190}
191
192#else
193
194
195
196
197
198#ifndef CONFIG_LOCKDEP
199# define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq)
200# define disable_irq_nosync_lockdep_irqsave(irq, flags) \
201 disable_irq_nosync(irq)
202# define disable_irq_lockdep(irq) disable_irq(irq)
203# define enable_irq_lockdep(irq) enable_irq(irq)
204# define enable_irq_lockdep_irqrestore(irq, flags) \
205 enable_irq(irq)
206# endif
207
208#endif
209
210#ifndef __ARCH_SET_SOFTIRQ_PENDING
211#define set_softirq_pending(x) (local_softirq_pending() = (x))
212#define or_softirq_pending(x) (local_softirq_pending() |= (x))
213#endif
214
215
216
217
218#ifndef CONFIG_SMP
219static inline void __deprecated cli(void)
220{
221 local_irq_disable();
222}
223static inline void __deprecated sti(void)
224{
225 local_irq_enable();
226}
227static inline void __deprecated save_flags(unsigned long *x)
228{
229 local_save_flags(*x);
230}
231#define save_flags(x) save_flags(&x)
232static inline void __deprecated restore_flags(unsigned long x)
233{
234 local_irq_restore(x);
235}
236
237static inline void __deprecated save_and_cli(unsigned long *x)
238{
239 local_irq_save(*x);
240}
241#define save_and_cli(x) save_and_cli(&x)
242#endif
243
244
245
246
247
248
249
250#ifndef hard_irq_disable
251#define hard_irq_disable() do { } while(0)
252#endif
253
254
255
256
257
258
259
260enum
261{
262 HI_SOFTIRQ=0,
263 TIMER_SOFTIRQ,
264 NET_TX_SOFTIRQ,
265 NET_RX_SOFTIRQ,
266 BLOCK_SOFTIRQ,
267 TASKLET_SOFTIRQ,
268 SCHED_SOFTIRQ,
269#ifdef CONFIG_HIGH_RES_TIMERS
270 HRTIMER_SOFTIRQ,
271#endif
272};
273
274
275
276
277
278struct softirq_action
279{
280 void (*action)(struct softirq_action *);
281 void *data;
282};
283
284asmlinkage void do_softirq(void);
285extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
286extern void softirq_init(void);
287#define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
288extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
289extern void FASTCALL(raise_softirq(unsigned int nr));
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312struct tasklet_struct
313{
314 struct tasklet_struct *next;
315 unsigned long state;
316 atomic_t count;
317 void (*func)(unsigned long);
318 unsigned long data;
319};
320
321#define DECLARE_TASKLET(name, func, data) \
322struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
323
324#define DECLARE_TASKLET_DISABLED(name, func, data) \
325struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
326
327
328enum
329{
330 TASKLET_STATE_SCHED,
331 TASKLET_STATE_RUN
332};
333
334#ifdef CONFIG_SMP
335static inline int tasklet_trylock(struct tasklet_struct *t)
336{
337 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
338}
339
340static inline void tasklet_unlock(struct tasklet_struct *t)
341{
342 smp_mb__before_clear_bit();
343 clear_bit(TASKLET_STATE_RUN, &(t)->state);
344}
345
346static inline void tasklet_unlock_wait(struct tasklet_struct *t)
347{
348 while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
349}
350#else
351#define tasklet_trylock(t) 1
352#define tasklet_unlock_wait(t) do { } while (0)
353#define tasklet_unlock(t) do { } while (0)
354#endif
355
356extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
357
358static inline void tasklet_schedule(struct tasklet_struct *t)
359{
360 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
361 __tasklet_schedule(t);
362}
363
364extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
365
366static inline void tasklet_hi_schedule(struct tasklet_struct *t)
367{
368 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
369 __tasklet_hi_schedule(t);
370}
371
372
373static inline void tasklet_disable_nosync(struct tasklet_struct *t)
374{
375 atomic_inc(&t->count);
376 smp_mb__after_atomic_inc();
377}
378
379static inline void tasklet_disable(struct tasklet_struct *t)
380{
381 tasklet_disable_nosync(t);
382 tasklet_unlock_wait(t);
383 smp_mb();
384}
385
386static inline void tasklet_enable(struct tasklet_struct *t)
387{
388 smp_mb__before_atomic_dec();
389 atomic_dec(&t->count);
390}
391
392static inline void tasklet_hi_enable(struct tasklet_struct *t)
393{
394 smp_mb__before_atomic_dec();
395 atomic_dec(&t->count);
396}
397
398extern void tasklet_kill(struct tasklet_struct *t);
399extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
400extern void tasklet_init(struct tasklet_struct *t,
401 void (*func)(unsigned long), unsigned long data);
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431#if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
432static inline unsigned long probe_irq_on(void)
433{
434 return 0;
435}
436static inline int probe_irq_off(unsigned long val)
437{
438 return 0;
439}
440static inline unsigned int probe_irq_mask(unsigned long val)
441{
442 return 0;
443}
444#else
445extern unsigned long probe_irq_on(void);
446extern int probe_irq_off(unsigned long);
447extern unsigned int probe_irq_mask(unsigned long);
448#endif
449
450#ifdef CONFIG_PROC_FS
451
452extern void init_irq_proc(void);
453#else
454static inline void init_irq_proc(void)
455{
456}
457#endif
458
459#endif
460