1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/irq.h>
16#include <linux/module.h>
17#include <linux/random.h>
18#include <linux/interrupt.h>
19
20#include "internals.h"
21
22#ifdef CONFIG_HARDIRQS_SW_RESEND
23
24
25static DECLARE_BITMAP(irqs_resend, IRQ_BITMAP_BITS);
26
27
28
29
30static void resend_irqs(unsigned long arg)
31{
32 struct irq_desc *desc;
33 int irq;
34
35 while (!bitmap_empty(irqs_resend, nr_irqs)) {
36 irq = find_first_bit(irqs_resend, nr_irqs);
37 clear_bit(irq, irqs_resend);
38 desc = irq_to_desc(irq);
39 if (!desc)
40 continue;
41 local_irq_disable();
42 desc->handle_irq(desc);
43 local_irq_enable();
44 }
45}
46
47
48static DECLARE_TASKLET(resend_tasklet, resend_irqs, 0);
49
50static int irq_sw_resend(struct irq_desc *desc)
51{
52 unsigned int irq = irq_desc_get_irq(desc);
53
54
55
56
57
58 if (handle_enforce_irqctx(&desc->irq_data))
59 return -EINVAL;
60
61
62
63
64
65
66 if (irq_settings_is_nested_thread(desc)) {
67
68
69
70
71 if (!desc->parent_irq)
72 return -EINVAL;
73 irq = desc->parent_irq;
74 }
75
76
77 set_bit(irq, irqs_resend);
78 tasklet_schedule(&resend_tasklet);
79 return 0;
80}
81
82#else
83static int irq_sw_resend(struct irq_desc *desc)
84{
85 return -EINVAL;
86}
87#endif
88
89
90
91
92
93
94int check_irq_resend(struct irq_desc *desc, bool inject)
95{
96 int err = 0;
97
98
99
100
101
102
103 if (irq_settings_is_level(desc)) {
104 desc->istate &= ~IRQS_PENDING;
105 return -EINVAL;
106 }
107
108 if (desc->istate & IRQS_REPLAY)
109 return -EBUSY;
110
111 if (!(desc->istate & IRQS_PENDING) && !inject)
112 return 0;
113
114 desc->istate &= ~IRQS_PENDING;
115
116 if (!desc->irq_data.chip->irq_retrigger ||
117 !desc->irq_data.chip->irq_retrigger(&desc->irq_data))
118 err = irq_sw_resend(desc);
119
120
121 if (!err)
122 desc->istate |= IRQS_REPLAY;
123 return err;
124}
125
126#ifdef CONFIG_GENERIC_IRQ_INJECTION
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144int irq_inject_interrupt(unsigned int irq)
145{
146 struct irq_desc *desc;
147 unsigned long flags;
148 int err;
149
150
151 if (!irq_set_irqchip_state(irq, IRQCHIP_STATE_PENDING, true))
152 return 0;
153
154
155 desc = irq_get_desc_buslock(irq, &flags, 0);
156 if (!desc)
157 return -EINVAL;
158
159
160
161
162
163
164 if ((desc->istate & IRQS_NMI) || !irqd_is_activated(&desc->irq_data))
165 err = -EINVAL;
166 else
167 err = check_irq_resend(desc, true);
168
169 irq_put_desc_busunlock(desc, flags);
170 return err;
171}
172EXPORT_SYMBOL_GPL(irq_inject_interrupt);
173#endif
174