1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/irq.h>
14#include <linux/random.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/kernel_stat.h>
18
19#include <trace/events/irq.h>
20
21#include "internals.h"
22
23
24
25
26
27
28
29void handle_bad_irq(struct irq_desc *desc)
30{
31 unsigned int irq = irq_desc_get_irq(desc);
32
33 print_irq_desc(irq, desc);
34 kstat_incr_irqs_this_cpu(desc);
35 ack_bad_irq(irq);
36}
37EXPORT_SYMBOL_GPL(handle_bad_irq);
38
39
40
41
42irqreturn_t no_action(int cpl, void *dev_id)
43{
44 return IRQ_NONE;
45}
46EXPORT_SYMBOL_GPL(no_action);
47
48static void warn_no_thread(unsigned int irq, struct irqaction *action)
49{
50 if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
51 return;
52
53 printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
54 "but no thread function available.", irq, action->name);
55}
56
57void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
58{
59
60
61
62
63
64 if (action->thread->flags & PF_EXITING)
65 return;
66
67
68
69
70
71 if (test_and_set_bit(IRQTF_RUNTHREAD, &action->thread_flags))
72 return;
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 desc->threads_oneshot |= action->thread_mask;
120
121
122
123
124
125
126
127
128
129
130 atomic_inc(&desc->threads_active);
131
132 wake_up_process(action->thread);
133}
134
135irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags)
136{
137 irqreturn_t retval = IRQ_NONE;
138 unsigned int irq = desc->irq_data.irq;
139 struct irqaction *action;
140
141 for_each_action_of_desc(desc, action) {
142 irqreturn_t res;
143
144 trace_irq_handler_entry(irq, action);
145 res = action->handler(irq, action->dev_id);
146 trace_irq_handler_exit(irq, action, res);
147
148 if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pF enabled interrupts\n",
149 irq, action->handler))
150 local_irq_disable();
151
152 switch (res) {
153 case IRQ_WAKE_THREAD:
154
155
156
157
158 if (unlikely(!action->thread_fn)) {
159 warn_no_thread(irq, action);
160 break;
161 }
162
163 __irq_wake_thread(desc, action);
164
165
166 case IRQ_HANDLED:
167 *flags |= action->flags;
168 break;
169
170 default:
171 break;
172 }
173
174 retval |= res;
175 }
176
177 return retval;
178}
179
180irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
181{
182 irqreturn_t retval;
183 unsigned int flags = 0;
184
185 retval = __handle_irq_event_percpu(desc, &flags);
186
187 add_interrupt_randomness(desc->irq_data.irq, flags);
188
189 if (!noirqdebug)
190 note_interrupt(desc, retval);
191 return retval;
192}
193
194irqreturn_t handle_irq_event(struct irq_desc *desc)
195{
196 irqreturn_t ret;
197
198 desc->istate &= ~IRQS_PENDING;
199 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
200 raw_spin_unlock(&desc->lock);
201
202 ret = handle_irq_event_percpu(desc);
203
204 raw_spin_lock(&desc->lock);
205 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
206 return ret;
207}
208