1
2
3#ifndef _LINUX_INTERRUPT_H
4#define _LINUX_INTERRUPT_H
5
6#include <linux/kernel.h>
7#include <linux/bitops.h>
8#include <linux/cpumask.h>
9#include <linux/irqreturn.h>
10#include <linux/irqnr.h>
11#include <linux/hardirq.h>
12#include <linux/irqflags.h>
13#include <linux/hrtimer.h>
14#include <linux/kref.h>
15#include <linux/workqueue.h>
16#include <linux/jump_label.h>
17
18#include <linux/atomic.h>
19#include <asm/ptrace.h>
20#include <asm/irq.h>
21#include <asm/sections.h>
22
23
24
25
26
27
28
29
30#define IRQF_TRIGGER_NONE 0x00000000
31#define IRQF_TRIGGER_RISING 0x00000001
32#define IRQF_TRIGGER_FALLING 0x00000002
33#define IRQF_TRIGGER_HIGH 0x00000004
34#define IRQF_TRIGGER_LOW 0x00000008
35#define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
36 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
37#define IRQF_TRIGGER_PROBE 0x00000010
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71#define IRQF_SHARED 0x00000080
72#define IRQF_PROBE_SHARED 0x00000100
73#define __IRQF_TIMER 0x00000200
74#define IRQF_PERCPU 0x00000400
75#define IRQF_NOBALANCING 0x00000800
76#define IRQF_IRQPOLL 0x00001000
77#define IRQF_ONESHOT 0x00002000
78#define IRQF_NO_SUSPEND 0x00004000
79#define IRQF_FORCE_RESUME 0x00008000
80#define IRQF_NO_THREAD 0x00010000
81#define IRQF_EARLY_RESUME 0x00020000
82#define IRQF_COND_SUSPEND 0x00040000
83#define IRQF_NO_AUTOEN 0x00080000
84#define IRQF_NO_DEBUG 0x00100000
85
86#define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
87
88
89
90
91
92
93
94
95enum {
96 IRQC_IS_HARDIRQ = 0,
97 IRQC_IS_NESTED,
98};
99
100typedef irqreturn_t (*irq_handler_t)(int, void *);
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118struct irqaction {
119 irq_handler_t handler;
120 void *dev_id;
121 void __percpu *percpu_dev_id;
122 struct irqaction *next;
123 irq_handler_t thread_fn;
124 struct task_struct *thread;
125 struct irqaction *secondary;
126 unsigned int irq;
127 unsigned int flags;
128 unsigned long thread_flags;
129 unsigned long thread_mask;
130 const char *name;
131 struct proc_dir_entry *dir;
132} ____cacheline_internodealigned_in_smp;
133
134extern irqreturn_t no_action(int cpl, void *dev_id);
135
136
137
138
139
140
141
142
143
144#define IRQ_NOTCONNECTED (1U << 31)
145
146extern int __must_check
147request_threaded_irq(unsigned int irq, irq_handler_t handler,
148 irq_handler_t thread_fn,
149 unsigned long flags, const char *name, void *dev);
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164static inline int __must_check
165request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
166 const char *name, void *dev)
167{
168 return request_threaded_irq(irq, handler, NULL, flags, name, dev);
169}
170
171extern int __must_check
172request_any_context_irq(unsigned int irq, irq_handler_t handler,
173 unsigned long flags, const char *name, void *dev_id);
174
175extern int __must_check
176__request_percpu_irq(unsigned int irq, irq_handler_t handler,
177 unsigned long flags, const char *devname,
178 void __percpu *percpu_dev_id);
179
180extern int __must_check
181request_nmi(unsigned int irq, irq_handler_t handler, unsigned long flags,
182 const char *name, void *dev);
183
184static inline int __must_check
185request_percpu_irq(unsigned int irq, irq_handler_t handler,
186 const char *devname, void __percpu *percpu_dev_id)
187{
188 return __request_percpu_irq(irq, handler, 0,
189 devname, percpu_dev_id);
190}
191
192extern int __must_check
193request_percpu_nmi(unsigned int irq, irq_handler_t handler,
194 const char *devname, void __percpu *dev);
195
196extern const void *free_irq(unsigned int, void *);
197extern void free_percpu_irq(unsigned int, void __percpu *);
198
199extern const void *free_nmi(unsigned int irq, void *dev_id);
200extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);
201
202struct device;
203
204extern int __must_check
205devm_request_threaded_irq(struct device *dev, unsigned int irq,
206 irq_handler_t handler, irq_handler_t thread_fn,
207 unsigned long irqflags, const char *devname,
208 void *dev_id);
209
210static inline int __must_check
211devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
212 unsigned long irqflags, const char *devname, void *dev_id)
213{
214 return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
215 devname, dev_id);
216}
217
218extern int __must_check
219devm_request_any_context_irq(struct device *dev, unsigned int irq,
220 irq_handler_t handler, unsigned long irqflags,
221 const char *devname, void *dev_id);
222
223extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
224
225
226
227
228
229
230
231
232
233
234
235
236
237#ifdef CONFIG_LOCKDEP
238# define local_irq_enable_in_hardirq() do { } while (0)
239#else
240# define local_irq_enable_in_hardirq() local_irq_enable()
241#endif
242
243bool irq_has_action(unsigned int irq);
244extern void disable_irq_nosync(unsigned int irq);
245extern bool disable_hardirq(unsigned int irq);
246extern void disable_irq(unsigned int irq);
247extern void disable_percpu_irq(unsigned int irq);
248extern void enable_irq(unsigned int irq);
249extern void enable_percpu_irq(unsigned int irq, unsigned int type);
250extern bool irq_percpu_is_enabled(unsigned int irq);
251extern void irq_wake_thread(unsigned int irq, void *dev_id);
252
253extern void disable_nmi_nosync(unsigned int irq);
254extern void disable_percpu_nmi(unsigned int irq);
255extern void enable_nmi(unsigned int irq);
256extern void enable_percpu_nmi(unsigned int irq, unsigned int type);
257extern int prepare_percpu_nmi(unsigned int irq);
258extern void teardown_percpu_nmi(unsigned int irq);
259
260extern int irq_inject_interrupt(unsigned int irq);
261
262
263extern void suspend_device_irqs(void);
264extern void resume_device_irqs(void);
265extern void rearm_wake_irq(unsigned int irq);
266
267
268
269
270
271
272
273
274
275
276
277
278
279struct irq_affinity_notify {
280 unsigned int irq;
281 struct kref kref;
282 struct work_struct work;
283 void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
284 void (*release)(struct kref *ref);
285};
286
287#define IRQ_AFFINITY_MAX_SETS 4
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303struct irq_affinity {
304 unsigned int pre_vectors;
305 unsigned int post_vectors;
306 unsigned int nr_sets;
307 unsigned int set_size[IRQ_AFFINITY_MAX_SETS];
308 void (*calc_sets)(struct irq_affinity *, unsigned int nvecs);
309 void *priv;
310};
311
312
313
314
315
316
317struct irq_affinity_desc {
318 struct cpumask mask;
319 unsigned int is_managed : 1;
320};
321
322#if defined(CONFIG_SMP)
323
324extern cpumask_var_t irq_default_affinity;
325
326extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
327extern int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask);
328
329extern int irq_can_set_affinity(unsigned int irq);
330extern int irq_select_affinity(unsigned int irq);
331
332extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
333extern int irq_update_affinity_desc(unsigned int irq,
334 struct irq_affinity_desc *affinity);
335
336extern int
337irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
338
339struct irq_affinity_desc *
340irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd);
341
342unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
343 const struct irq_affinity *affd);
344
345#else
346
347static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
348{
349 return -EINVAL;
350}
351
352static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
353{
354 return 0;
355}
356
357static inline int irq_can_set_affinity(unsigned int irq)
358{
359 return 0;
360}
361
362static inline int irq_select_affinity(unsigned int irq) { return 0; }
363
364static inline int irq_set_affinity_hint(unsigned int irq,
365 const struct cpumask *m)
366{
367 return -EINVAL;
368}
369
370static inline int irq_update_affinity_desc(unsigned int irq,
371 struct irq_affinity_desc *affinity)
372{
373 return -EINVAL;
374}
375
376static inline int
377irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
378{
379 return 0;
380}
381
382static inline struct irq_affinity_desc *
383irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd)
384{
385 return NULL;
386}
387
388static inline unsigned int
389irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
390 const struct irq_affinity *affd)
391{
392 return maxvec;
393}
394
395#endif
396
397
398
399
400
401
402
403
404
405
406
407
408static inline void disable_irq_nosync_lockdep(unsigned int irq)
409{
410 disable_irq_nosync(irq);
411#ifdef CONFIG_LOCKDEP
412 local_irq_disable();
413#endif
414}
415
416static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
417{
418 disable_irq_nosync(irq);
419#ifdef CONFIG_LOCKDEP
420 local_irq_save(*flags);
421#endif
422}
423
424static inline void disable_irq_lockdep(unsigned int irq)
425{
426 disable_irq(irq);
427#ifdef CONFIG_LOCKDEP
428 local_irq_disable();
429#endif
430}
431
432static inline void enable_irq_lockdep(unsigned int irq)
433{
434#ifdef CONFIG_LOCKDEP
435 local_irq_enable();
436#endif
437 enable_irq(irq);
438}
439
440static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
441{
442#ifdef CONFIG_LOCKDEP
443 local_irq_restore(*flags);
444#endif
445 enable_irq(irq);
446}
447
448
449extern int irq_set_irq_wake(unsigned int irq, unsigned int on);
450
451static inline int enable_irq_wake(unsigned int irq)
452{
453 return irq_set_irq_wake(irq, 1);
454}
455
456static inline int disable_irq_wake(unsigned int irq)
457{
458 return irq_set_irq_wake(irq, 0);
459}
460
461
462
463
464enum irqchip_irq_state {
465 IRQCHIP_STATE_PENDING,
466 IRQCHIP_STATE_ACTIVE,
467 IRQCHIP_STATE_MASKED,
468 IRQCHIP_STATE_LINE_LEVEL,
469};
470
471extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
472 bool *state);
473extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
474 bool state);
475
476#ifdef CONFIG_IRQ_FORCED_THREADING
477# ifdef CONFIG_PREEMPT_RT
478# define force_irqthreads() (true)
479# else
480DECLARE_STATIC_KEY_FALSE(force_irqthreads_key);
481# define force_irqthreads() (static_branch_unlikely(&force_irqthreads_key))
482# endif
483#else
484#define force_irqthreads() (false)
485#endif
486
487#ifndef local_softirq_pending
488
489#ifndef local_softirq_pending_ref
490#define local_softirq_pending_ref irq_stat.__softirq_pending
491#endif
492
493#define local_softirq_pending() (__this_cpu_read(local_softirq_pending_ref))
494#define set_softirq_pending(x) (__this_cpu_write(local_softirq_pending_ref, (x)))
495#define or_softirq_pending(x) (__this_cpu_or(local_softirq_pending_ref, (x)))
496
497#endif
498
499
500
501
502
503
504
505#ifndef hard_irq_disable
506#define hard_irq_disable() do { } while(0)
507#endif
508
509
510
511
512
513
514
515enum
516{
517 HI_SOFTIRQ=0,
518 TIMER_SOFTIRQ,
519 NET_TX_SOFTIRQ,
520 NET_RX_SOFTIRQ,
521 BLOCK_SOFTIRQ,
522 IRQ_POLL_SOFTIRQ,
523 TASKLET_SOFTIRQ,
524 SCHED_SOFTIRQ,
525 HRTIMER_SOFTIRQ,
526 RCU_SOFTIRQ,
527
528 NR_SOFTIRQS
529};
530
531#define SOFTIRQ_STOP_IDLE_MASK (~(1 << RCU_SOFTIRQ))
532
533
534
535
536extern const char * const softirq_to_name[NR_SOFTIRQS];
537
538
539
540
541
542struct softirq_action
543{
544 void (*action)(struct softirq_action *);
545};
546
547asmlinkage void do_softirq(void);
548asmlinkage void __do_softirq(void);
549
550extern void open_softirq(int nr, void (*action)(struct softirq_action *));
551extern void softirq_init(void);
552extern void __raise_softirq_irqoff(unsigned int nr);
553
554extern void raise_softirq_irqoff(unsigned int nr);
555extern void raise_softirq(unsigned int nr);
556
557DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
558
559static inline struct task_struct *this_cpu_ksoftirqd(void)
560{
561 return this_cpu_read(ksoftirqd);
562}
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587struct tasklet_struct
588{
589 struct tasklet_struct *next;
590 unsigned long state;
591 atomic_t count;
592 bool use_callback;
593 union {
594 void (*func)(unsigned long data);
595 void (*callback)(struct tasklet_struct *t);
596 };
597 unsigned long data;
598};
599
600#define DECLARE_TASKLET(name, _callback) \
601struct tasklet_struct name = { \
602 .count = ATOMIC_INIT(0), \
603 .callback = _callback, \
604 .use_callback = true, \
605}
606
607#define DECLARE_TASKLET_DISABLED(name, _callback) \
608struct tasklet_struct name = { \
609 .count = ATOMIC_INIT(1), \
610 .callback = _callback, \
611 .use_callback = true, \
612}
613
614#define from_tasklet(var, callback_tasklet, tasklet_fieldname) \
615 container_of(callback_tasklet, typeof(*var), tasklet_fieldname)
616
617#define DECLARE_TASKLET_OLD(name, _func) \
618struct tasklet_struct name = { \
619 .count = ATOMIC_INIT(0), \
620 .func = _func, \
621}
622
623#define DECLARE_TASKLET_DISABLED_OLD(name, _func) \
624struct tasklet_struct name = { \
625 .count = ATOMIC_INIT(1), \
626 .func = _func, \
627}
628
629enum
630{
631 TASKLET_STATE_SCHED,
632 TASKLET_STATE_RUN
633};
634
635#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
636static inline int tasklet_trylock(struct tasklet_struct *t)
637{
638 return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
639}
640
641void tasklet_unlock(struct tasklet_struct *t);
642void tasklet_unlock_wait(struct tasklet_struct *t);
643void tasklet_unlock_spin_wait(struct tasklet_struct *t);
644
645#else
646static inline int tasklet_trylock(struct tasklet_struct *t) { return 1; }
647static inline void tasklet_unlock(struct tasklet_struct *t) { }
648static inline void tasklet_unlock_wait(struct tasklet_struct *t) { }
649static inline void tasklet_unlock_spin_wait(struct tasklet_struct *t) { }
650#endif
651
652extern void __tasklet_schedule(struct tasklet_struct *t);
653
654static inline void tasklet_schedule(struct tasklet_struct *t)
655{
656 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
657 __tasklet_schedule(t);
658}
659
660extern void __tasklet_hi_schedule(struct tasklet_struct *t);
661
662static inline void tasklet_hi_schedule(struct tasklet_struct *t)
663{
664 if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
665 __tasklet_hi_schedule(t);
666}
667
668static inline void tasklet_disable_nosync(struct tasklet_struct *t)
669{
670 atomic_inc(&t->count);
671 smp_mb__after_atomic();
672}
673
674
675
676
677
678static inline void tasklet_disable_in_atomic(struct tasklet_struct *t)
679{
680 tasklet_disable_nosync(t);
681 tasklet_unlock_spin_wait(t);
682 smp_mb();
683}
684
685static inline void tasklet_disable(struct tasklet_struct *t)
686{
687 tasklet_disable_nosync(t);
688 tasklet_unlock_wait(t);
689 smp_mb();
690}
691
692static inline void tasklet_enable(struct tasklet_struct *t)
693{
694 smp_mb__before_atomic();
695 atomic_dec(&t->count);
696}
697
698extern void tasklet_kill(struct tasklet_struct *t);
699extern void tasklet_init(struct tasklet_struct *t,
700 void (*func)(unsigned long), unsigned long data);
701extern void tasklet_setup(struct tasklet_struct *t,
702 void (*callback)(struct tasklet_struct *));
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732#if !defined(CONFIG_GENERIC_IRQ_PROBE)
733static inline unsigned long probe_irq_on(void)
734{
735 return 0;
736}
737static inline int probe_irq_off(unsigned long val)
738{
739 return 0;
740}
741static inline unsigned int probe_irq_mask(unsigned long val)
742{
743 return 0;
744}
745#else
746extern unsigned long probe_irq_on(void);
747extern int probe_irq_off(unsigned long);
748extern unsigned int probe_irq_mask(unsigned long);
749#endif
750
751#ifdef CONFIG_PROC_FS
752
753extern void init_irq_proc(void);
754#else
755static inline void init_irq_proc(void)
756{
757}
758#endif
759
760#ifdef CONFIG_IRQ_TIMINGS
761void irq_timings_enable(void);
762void irq_timings_disable(void);
763u64 irq_timings_next_event(u64 now);
764#endif
765
766struct seq_file;
767int show_interrupts(struct seq_file *p, void *v);
768int arch_show_interrupts(struct seq_file *p, int prec);
769
770extern int early_irq_init(void);
771extern int arch_probe_nr_irqs(void);
772extern int arch_early_irq_init(void);
773
774
775
776
777#ifndef __irq_entry
778# define __irq_entry __section(".irqentry.text")
779#endif
780
781#define __softirq_entry __section(".softirqentry.text")
782
783#endif
784