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/irqnr.h>
12#include <linux/hardirq.h>
13#include <linux/irqflags.h>
14#include <linux/smp.h>
15#include <linux/percpu.h>
16#include <linux/hrtimer.h>
17
18#include <asm/atomic.h>
19#include <asm/ptrace.h>
20#include <asm/system.h>
21
22
23
24
25
26
27
28
29#define IRQF_TRIGGER_NONE 0x00000000
30#define IRQF_TRIGGER_RISING 0x00000001
31#define IRQF_TRIGGER_FALLING 0x00000002
32#define IRQF_TRIGGER_HIGH 0x00000004
33#define IRQF_TRIGGER_LOW 0x00000008
34#define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
35 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
36#define IRQF_TRIGGER_PROBE 0x00000010
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#define IRQF_DISABLED 0x00000020
57#define IRQF_SAMPLE_RANDOM 0x00000040
58#define IRQF_SHARED 0x00000080
59#define IRQF_PROBE_SHARED 0x00000100
60#define IRQF_TIMER 0x00000200
61#define IRQF_PERCPU 0x00000400
62#define IRQF_NOBALANCING 0x00000800
63#define IRQF_IRQPOLL 0x00001000
64#define IRQF_ONESHOT 0x00002000
65
66
67
68
69
70
71
72
73enum {
74 IRQTF_RUNTHREAD,
75 IRQTF_DIED,
76 IRQTF_WARNED,
77 IRQTF_AFFINITY,
78};
79
80typedef irqreturn_t (*irq_handler_t)(int, void *);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95struct irqaction {
96 irq_handler_t handler;
97 unsigned long flags;
98 const char *name;
99 void *dev_id;
100 struct irqaction *next;
101 int irq;
102 struct proc_dir_entry *dir;
103 irq_handler_t thread_fn;
104 struct task_struct *thread;
105 unsigned long thread_flags;
106};
107
108extern irqreturn_t no_action(int cpl, void *dev_id);
109
110#ifdef CONFIG_GENERIC_HARDIRQS
111extern int __must_check
112request_threaded_irq(unsigned int irq, irq_handler_t handler,
113 irq_handler_t thread_fn,
114 unsigned long flags, const char *name, void *dev);
115
116static inline int __must_check
117request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
118 const char *name, void *dev)
119{
120 return request_threaded_irq(irq, handler, NULL, flags, name, dev);
121}
122
123extern void exit_irq_thread(void);
124#else
125
126extern int __must_check
127request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
128 const char *name, void *dev);
129
130
131
132
133
134
135
136static inline int __must_check
137request_threaded_irq(unsigned int irq, irq_handler_t handler,
138 irq_handler_t thread_fn,
139 unsigned long flags, const char *name, void *dev)
140{
141 return request_irq(irq, handler, flags, name, dev);
142}
143
144static inline void exit_irq_thread(void) { }
145#endif
146
147extern void free_irq(unsigned int, void *);
148
149struct device;
150
151extern int __must_check
152devm_request_threaded_irq(struct device *dev, unsigned int irq,
153 irq_handler_t handler, irq_handler_t thread_fn,
154 unsigned long irqflags, const char *devname,
155 void *dev_id);
156
157static inline int __must_check
158devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
159 unsigned long irqflags, const char *devname, void *dev_id)
160{
161 return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
162 devname, dev_id);
163}
164
165extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
166
167
168
169
170
171
172
173
174
175
176
177
178
179#ifdef CONFIG_LOCKDEP
180# define local_irq_enable_in_hardirq() do { } while (0)
181#else
182# define local_irq_enable_in_hardirq() local_irq_enable()
183#endif
184
185extern void disable_irq_nosync(unsigned int irq);
186extern void disable_irq(unsigned int irq);
187extern void enable_irq(unsigned int irq);
188
189
190#ifdef CONFIG_GENERIC_HARDIRQS
191extern void suspend_device_irqs(void);
192extern void resume_device_irqs(void);
193#ifdef CONFIG_PM_SLEEP
194extern int check_wakeup_irqs(void);
195#else
196static inline int check_wakeup_irqs(void) { return 0; }
197#endif
198#else
199static inline void suspend_device_irqs(void) { };
200static inline void resume_device_irqs(void) { };
201static inline int check_wakeup_irqs(void) { return 0; }
202#endif
203
204#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
205
206extern cpumask_var_t irq_default_affinity;
207
208extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
209extern int irq_can_set_affinity(unsigned int irq);
210extern int irq_select_affinity(unsigned int irq);
211
212#else
213
214static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
215{
216 return -EINVAL;
217}
218
219static inline int irq_can_set_affinity(unsigned int irq)
220{
221 return 0;
222}
223
224static inline int irq_select_affinity(unsigned int irq) { return 0; }
225
226#endif
227
228#ifdef CONFIG_GENERIC_HARDIRQS
229
230
231
232
233
234
235
236
237
238
239
240static inline void disable_irq_nosync_lockdep(unsigned int irq)
241{
242 disable_irq_nosync(irq);
243#ifdef CONFIG_LOCKDEP
244 local_irq_disable();
245#endif
246}
247
248static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
249{
250 disable_irq_nosync(irq);
251#ifdef CONFIG_LOCKDEP
252 local_irq_save(*flags);
253#endif
254}
255
256static inline void disable_irq_lockdep(unsigned int irq)
257{
258 disable_irq(irq);
259#ifdef CONFIG_LOCKDEP
260 local_irq_disable();
261#endif
262}
263
264static inline void enable_irq_lockdep(unsigned int irq)
265{
266#ifdef CONFIG_LOCKDEP
267 local_irq_enable();
268#endif
269 enable_irq(irq);
270}
271
272static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
273{
274#ifdef CONFIG_LOCKDEP
275 local_irq_restore(*flags);
276#endif
277 enable_irq(irq);
278}
279
280
281extern int set_irq_wake(unsigned int irq, unsigned int on);
282
283static inline int enable_irq_wake(unsigned int irq)
284{
285 return set_irq_wake(irq, 1);
286}
287
288static inline int disable_irq_wake(unsigned int irq)
289{
290 return set_irq_wake(irq, 0);
291}
292
293#else
294
295
296
297
298
299#ifndef CONFIG_LOCKDEP
300# define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq)
301# define disable_irq_nosync_lockdep_irqsave(irq, flags) \
302 disable_irq_nosync(irq)
303# define disable_irq_lockdep(irq) disable_irq(irq)
304# define enable_irq_lockdep(irq) enable_irq(irq)
305# define enable_irq_lockdep_irqrestore(irq, flags) \
306 enable_irq(irq)
307# endif
308
309static inline int enable_irq_wake(unsigned int irq)
310{
311 return 0;
312}
313
314static inline int disable_irq_wake(unsigned int irq)
315{
316 return 0;
317}
318#endif
319
320#ifndef __ARCH_SET_SOFTIRQ_PENDING
321#define set_softirq_pending(x) (local_softirq_pending() = (x))
322#define or_softirq_pending(x) (local_softirq_pending() |= (x))
323#endif
324
325
326
327
328
329
330
331#ifndef hard_irq_disable
332#define hard_irq_disable() do { } while(0)
333#endif
334
335
336
337
338
339
340
341enum
342{
343 HI_SOFTIRQ=0,
344 TIMER_SOFTIRQ,
345 NET_TX_SOFTIRQ,
346 NET_RX_SOFTIRQ,
347 BLOCK_SOFTIRQ,
348 BLOCK_IOPOLL_SOFTIRQ,
349 TASKLET_SOFTIRQ,
350 SCHED_SOFTIRQ,
351 HRTIMER_SOFTIRQ,
352 RCU_SOFTIRQ,
353
354 NR_SOFTIRQS
355};
356
357
358
359
360extern char *softirq_to_name[NR_SOFTIRQS];
361
362
363
364
365
366struct softirq_action
367{
368 void (*action)(struct softirq_action *);
369};
370
371asmlinkage void do_softirq(void);
372asmlinkage void __do_softirq(void);
373extern void open_softirq(int nr, void (*action)(struct softirq_action *));
374extern void softirq_init(void);
375#define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
376extern void raise_softirq_irqoff(unsigned int nr);
377extern void raise_softirq(unsigned int nr);
378extern void wakeup_softirqd(void);
379
380
381
382
383
384
385
386
387DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list);
388
389
390
391
392extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq);
393
394
395
396
397extern void __send_remote_softirq(struct call_single_data *cp, int cpu,
398 int this_cpu, int softirq);
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420struct tasklet_struct
421{
422 struct tasklet_struct *next;
423 unsigned long state;
424 atomic_t count;
425 void (*func)(unsigned long);
426 unsigned long data;
427};
428
429#define DECLARE_TASKLET(name, func, data) \
430struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
431
432#define DECLARE_TASKLET_DISABLED(name, func, data) \
433struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
434
435
436enum
437{
438 TASKLET_STATE_SCHED,
439 TASKLET_STATE_RUN
440};
441
442#ifdef CONFIG_SMP
443static inline int tasklet_trylock(struct tasklet_struct *t)
444{
445 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
446}
447
448static inline void tasklet_unlock(struct tasklet_struct *t)
449{
450 smp_mb__before_clear_bit();
451 clear_bit(TASKLET_STATE_RUN, &(t)->state);
452}
453
454static inline void tasklet_unlock_wait(struct tasklet_struct *t)
455{
456 while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
457}
458#else
459#define tasklet_trylock(t) 1
460#define tasklet_unlock_wait(t) do { } while (0)
461#define tasklet_unlock(t) do { } while (0)
462#endif
463
464extern void __tasklet_schedule(struct tasklet_struct *t);
465
466static inline void tasklet_schedule(struct tasklet_struct *t)
467{
468 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
469 __tasklet_schedule(t);
470}
471
472extern void __tasklet_hi_schedule(struct tasklet_struct *t);
473
474static inline void tasklet_hi_schedule(struct tasklet_struct *t)
475{
476 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
477 __tasklet_hi_schedule(t);
478}
479
480extern void __tasklet_hi_schedule_first(struct tasklet_struct *t);
481
482
483
484
485
486
487
488static inline void tasklet_hi_schedule_first(struct tasklet_struct *t)
489{
490 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
491 __tasklet_hi_schedule_first(t);
492}
493
494
495static inline void tasklet_disable_nosync(struct tasklet_struct *t)
496{
497 atomic_inc(&t->count);
498 smp_mb__after_atomic_inc();
499}
500
501static inline void tasklet_disable(struct tasklet_struct *t)
502{
503 tasklet_disable_nosync(t);
504 tasklet_unlock_wait(t);
505 smp_mb();
506}
507
508static inline void tasklet_enable(struct tasklet_struct *t)
509{
510 smp_mb__before_atomic_dec();
511 atomic_dec(&t->count);
512}
513
514static inline void tasklet_hi_enable(struct tasklet_struct *t)
515{
516 smp_mb__before_atomic_dec();
517 atomic_dec(&t->count);
518}
519
520extern void tasklet_kill(struct tasklet_struct *t);
521extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
522extern void tasklet_init(struct tasklet_struct *t,
523 void (*func)(unsigned long), unsigned long data);
524
525struct tasklet_hrtimer {
526 struct hrtimer timer;
527 struct tasklet_struct tasklet;
528 enum hrtimer_restart (*function)(struct hrtimer *);
529};
530
531extern void
532tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
533 enum hrtimer_restart (*function)(struct hrtimer *),
534 clockid_t which_clock, enum hrtimer_mode mode);
535
536static inline
537int tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time,
538 const enum hrtimer_mode mode)
539{
540 return hrtimer_start(&ttimer->timer, time, mode);
541}
542
543static inline
544void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer)
545{
546 hrtimer_cancel(&ttimer->timer);
547 tasklet_kill(&ttimer->tasklet);
548}
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578#if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE)
579static inline unsigned long probe_irq_on(void)
580{
581 return 0;
582}
583static inline int probe_irq_off(unsigned long val)
584{
585 return 0;
586}
587static inline unsigned int probe_irq_mask(unsigned long val)
588{
589 return 0;
590}
591#else
592extern unsigned long probe_irq_on(void);
593extern int probe_irq_off(unsigned long);
594extern unsigned int probe_irq_mask(unsigned long);
595#endif
596
597#ifdef CONFIG_PROC_FS
598
599extern void init_irq_proc(void);
600#else
601static inline void init_irq_proc(void)
602{
603}
604#endif
605
606#if defined(CONFIG_GENERIC_HARDIRQS) && defined(CONFIG_DEBUG_SHIRQ)
607extern void debug_poll_all_shared_irqs(void);
608#else
609static inline void debug_poll_all_shared_irqs(void) { }
610#endif
611
612struct seq_file;
613int show_interrupts(struct seq_file *p, void *v);
614
615struct irq_desc;
616
617extern int early_irq_init(void);
618extern int arch_probe_nr_irqs(void);
619extern int arch_early_irq_init(void);
620extern int arch_init_chip_data(struct irq_desc *desc, int node);
621
622#endif
623