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
29
30void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
31{
32 print_irq_desc(irq, desc);
33 kstat_incr_irqs_this_cpu(irq, desc);
34 ack_bad_irq(irq);
35}
36
37
38
39
40irqreturn_t no_action(int cpl, void *dev_id)
41{
42 return IRQ_NONE;
43}
44
45static void warn_no_thread(unsigned int irq, struct irqaction *action)
46{
47 if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
48 return;
49
50 printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
51 "but no thread function available.", irq, action->name);
52}
53
54static void irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
55{
56
57
58
59
60
61
62
63 if (test_bit(IRQTF_DIED, &action->thread_flags) ||
64 test_and_set_bit(IRQTF_RUNTHREAD, &action->thread_flags))
65 return;
66
67
68
69
70
71
72
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 desc->threads_oneshot |= action->thread_mask;
113 wake_up_process(action->thread);
114}
115
116irqreturn_t
117handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
118{
119 irqreturn_t retval = IRQ_NONE;
120 unsigned int random = 0, irq = desc->irq_data.irq;
121
122 do {
123 irqreturn_t res;
124
125 trace_irq_handler_entry(irq, action);
126 res = action->handler(irq, action->dev_id);
127 trace_irq_handler_exit(irq, action, res);
128
129 if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pF enabled interrupts\n",
130 irq, action->handler))
131 local_irq_disable();
132
133 switch (res) {
134 case IRQ_WAKE_THREAD:
135
136
137
138
139 if (unlikely(!action->thread_fn)) {
140 warn_no_thread(irq, action);
141 break;
142 }
143
144 irq_wake_thread(desc, action);
145
146
147 case IRQ_HANDLED:
148 random |= action->flags;
149 break;
150
151 default:
152 break;
153 }
154
155 retval |= res;
156 action = action->next;
157 } while (action);
158
159 if (random & IRQF_SAMPLE_RANDOM)
160 add_interrupt_randomness(irq);
161
162 if (!noirqdebug)
163 note_interrupt(irq, desc, retval);
164 return retval;
165}
166
167irqreturn_t handle_irq_event(struct irq_desc *desc)
168{
169 struct irqaction *action = desc->action;
170 irqreturn_t ret;
171
172 desc->istate &= ~IRQS_PENDING;
173 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
174 raw_spin_unlock(&desc->lock);
175
176 ret = handle_irq_event_percpu(desc, action);
177
178 raw_spin_lock(&desc->lock);
179 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
180 return ret;
181}
182