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