]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/kernel/irq/handle.c | |
3 | * | |
a34db9b2 IM |
4 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
5 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King | |
1da177e4 LT |
6 | * |
7 | * This file contains the core interrupt handling code. | |
a34db9b2 IM |
8 | * |
9 | * Detailed information is available in Documentation/DocBook/genericirq | |
10 | * | |
1da177e4 LT |
11 | */ |
12 | ||
13 | #include <linux/irq.h> | |
14 | #include <linux/module.h> | |
15 | #include <linux/random.h> | |
16 | #include <linux/interrupt.h> | |
17 | #include <linux/kernel_stat.h> | |
18 | ||
19 | #include "internals.h" | |
20 | ||
6a6de9ef TG |
21 | /** |
22 | * handle_bad_irq - handle spurious and unhandled irqs | |
43a1dd50 HK |
23 | * @irq: the interrupt number |
24 | * @desc: description of the interrupt | |
43a1dd50 HK |
25 | * |
26 | * Handles spurious and unhandled IRQ's. It also prints a debugmessage. | |
6a6de9ef | 27 | */ |
7ad5b3a5 | 28 | void |
7d12e780 | 29 | handle_bad_irq(unsigned int irq, struct irq_desc *desc) |
6a6de9ef | 30 | { |
43f77759 | 31 | print_irq_desc(irq, desc); |
6a6de9ef TG |
32 | kstat_this_cpu.irqs[irq]++; |
33 | ack_bad_irq(irq); | |
34 | } | |
35 | ||
1da177e4 LT |
36 | /* |
37 | * Linux has a controller-independent interrupt architecture. | |
38 | * Every controller has a 'controller-template', that is used | |
39 | * by the main code to do the right thing. Each driver-visible | |
06fcb0c6 | 40 | * interrupt source is transparently wired to the appropriate |
1da177e4 LT |
41 | * controller. Thus drivers need not be aware of the |
42 | * interrupt-controller. | |
43 | * | |
44 | * The code is designed to be easily extended with new/different | |
45 | * interrupt controllers, without having to do assembly magic or | |
46 | * having to touch the generic code. | |
47 | * | |
48 | * Controller mappings for all interrupt sources: | |
49 | */ | |
85c0f909 | 50 | int nr_irqs = NR_IRQS; |
d60458b2 YL |
51 | |
52 | #ifdef CONFIG_HAVE_DYN_ARRAY | |
53 | static struct irq_desc irq_desc_init __initdata = { | |
54 | .status = IRQ_DISABLED, | |
55 | .chip = &no_irq_chip, | |
56 | .handle_irq = handle_bad_irq, | |
57 | .depth = 1, | |
58 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), | |
59 | #ifdef CONFIG_SMP | |
60 | .affinity = CPU_MASK_ALL | |
61 | #endif | |
62 | }; | |
63 | ||
64 | static void __init init_work(void *data) | |
65 | { | |
66 | struct dyn_array *da = data; | |
67 | int i; | |
68 | struct irq_desc *desc; | |
69 | ||
70 | desc = *da->name; | |
71 | ||
72 | for (i = 0; i < *da->nr; i++) | |
73 | memcpy(&desc[i], &irq_desc_init, sizeof(struct irq_desc)); | |
74 | } | |
75 | ||
76 | struct irq_desc *irq_desc; | |
77 | DEFINE_DYN_ARRAY(irq_desc, sizeof(struct irq_desc), nr_irqs, PAGE_SIZE, init_work); | |
78 | ||
79 | #else | |
80 | ||
e729aa16 | 81 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { |
1da177e4 | 82 | [0 ... NR_IRQS-1] = { |
4f167fb4 | 83 | .status = IRQ_DISABLED, |
f1c2662c | 84 | .chip = &no_irq_chip, |
7a55713a | 85 | .handle_irq = handle_bad_irq, |
94d39e1f | 86 | .depth = 1, |
6cfd76a2 | 87 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), |
a53da52f IM |
88 | #ifdef CONFIG_SMP |
89 | .affinity = CPU_MASK_ALL | |
90 | #endif | |
1da177e4 LT |
91 | } |
92 | }; | |
d60458b2 | 93 | #endif |
1da177e4 LT |
94 | |
95 | /* | |
77a5afec IM |
96 | * What should we do if we get a hw irq event on an illegal vector? |
97 | * Each architecture has to answer this themself. | |
1da177e4 | 98 | */ |
77a5afec | 99 | static void ack_bad(unsigned int irq) |
1da177e4 | 100 | { |
43f77759 | 101 | print_irq_desc(irq, irq_desc + irq); |
1da177e4 LT |
102 | ack_bad_irq(irq); |
103 | } | |
104 | ||
77a5afec IM |
105 | /* |
106 | * NOP functions | |
107 | */ | |
108 | static void noop(unsigned int irq) | |
109 | { | |
110 | } | |
111 | ||
112 | static unsigned int noop_ret(unsigned int irq) | |
113 | { | |
114 | return 0; | |
115 | } | |
116 | ||
117 | /* | |
118 | * Generic no controller implementation | |
119 | */ | |
f1c2662c IM |
120 | struct irq_chip no_irq_chip = { |
121 | .name = "none", | |
77a5afec IM |
122 | .startup = noop_ret, |
123 | .shutdown = noop, | |
124 | .enable = noop, | |
125 | .disable = noop, | |
126 | .ack = ack_bad, | |
127 | .end = noop, | |
1da177e4 LT |
128 | }; |
129 | ||
f8b5473f TG |
130 | /* |
131 | * Generic dummy implementation which can be used for | |
132 | * real dumb interrupt sources | |
133 | */ | |
134 | struct irq_chip dummy_irq_chip = { | |
135 | .name = "dummy", | |
136 | .startup = noop_ret, | |
137 | .shutdown = noop, | |
138 | .enable = noop, | |
139 | .disable = noop, | |
140 | .ack = noop, | |
141 | .mask = noop, | |
142 | .unmask = noop, | |
143 | .end = noop, | |
144 | }; | |
145 | ||
1da177e4 LT |
146 | /* |
147 | * Special, empty irq handler: | |
148 | */ | |
7d12e780 | 149 | irqreturn_t no_action(int cpl, void *dev_id) |
1da177e4 LT |
150 | { |
151 | return IRQ_NONE; | |
152 | } | |
153 | ||
8d28bc75 IM |
154 | /** |
155 | * handle_IRQ_event - irq action chain handler | |
156 | * @irq: the interrupt number | |
8d28bc75 IM |
157 | * @action: the interrupt action chain for this irq |
158 | * | |
159 | * Handles the action chain of an irq event | |
1da177e4 | 160 | */ |
7d12e780 | 161 | irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action) |
1da177e4 | 162 | { |
908dcecd JB |
163 | irqreturn_t ret, retval = IRQ_NONE; |
164 | unsigned int status = 0; | |
1da177e4 | 165 | |
3cca53b0 | 166 | if (!(action->flags & IRQF_DISABLED)) |
366c7f55 | 167 | local_irq_enable_in_hardirq(); |
1da177e4 LT |
168 | |
169 | do { | |
7d12e780 | 170 | ret = action->handler(irq, action->dev_id); |
1da177e4 LT |
171 | if (ret == IRQ_HANDLED) |
172 | status |= action->flags; | |
173 | retval |= ret; | |
174 | action = action->next; | |
175 | } while (action); | |
176 | ||
3cca53b0 | 177 | if (status & IRQF_SAMPLE_RANDOM) |
1da177e4 LT |
178 | add_interrupt_randomness(irq); |
179 | local_irq_disable(); | |
180 | ||
181 | return retval; | |
182 | } | |
183 | ||
af8c65b5 | 184 | #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ |
8d28bc75 IM |
185 | /** |
186 | * __do_IRQ - original all in one highlevel IRQ handler | |
187 | * @irq: the interrupt number | |
8d28bc75 IM |
188 | * |
189 | * __do_IRQ handles all normal device IRQ's (the special | |
1da177e4 LT |
190 | * SMP cross-CPU interrupts have their own specific |
191 | * handlers). | |
8d28bc75 IM |
192 | * |
193 | * This is the original x86 implementation which is used for every | |
194 | * interrupt type. | |
1da177e4 | 195 | */ |
7ad5b3a5 | 196 | unsigned int __do_IRQ(unsigned int irq) |
1da177e4 | 197 | { |
34ffdb72 | 198 | struct irq_desc *desc = irq_desc + irq; |
06fcb0c6 | 199 | struct irqaction *action; |
1da177e4 LT |
200 | unsigned int status; |
201 | ||
202 | kstat_this_cpu.irqs[irq]++; | |
f26fdd59 | 203 | if (CHECK_IRQ_PER_CPU(desc->status)) { |
1da177e4 LT |
204 | irqreturn_t action_ret; |
205 | ||
206 | /* | |
207 | * No locking required for CPU-local interrupts: | |
208 | */ | |
d1bef4ed IM |
209 | if (desc->chip->ack) |
210 | desc->chip->ack(irq); | |
c642b839 RA |
211 | if (likely(!(desc->status & IRQ_DISABLED))) { |
212 | action_ret = handle_IRQ_event(irq, desc->action); | |
213 | if (!noirqdebug) | |
214 | note_interrupt(irq, desc, action_ret); | |
215 | } | |
d1bef4ed | 216 | desc->chip->end(irq); |
1da177e4 LT |
217 | return 1; |
218 | } | |
219 | ||
220 | spin_lock(&desc->lock); | |
d1bef4ed IM |
221 | if (desc->chip->ack) |
222 | desc->chip->ack(irq); | |
1da177e4 LT |
223 | /* |
224 | * REPLAY is when Linux resends an IRQ that was dropped earlier | |
225 | * WAITING is used by probe to mark irqs that are being tested | |
226 | */ | |
227 | status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); | |
228 | status |= IRQ_PENDING; /* we _want_ to handle it */ | |
229 | ||
230 | /* | |
231 | * If the IRQ is disabled for whatever reason, we cannot | |
232 | * use the action we have. | |
233 | */ | |
234 | action = NULL; | |
235 | if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { | |
236 | action = desc->action; | |
237 | status &= ~IRQ_PENDING; /* we commit to handling */ | |
238 | status |= IRQ_INPROGRESS; /* we are handling it */ | |
239 | } | |
240 | desc->status = status; | |
241 | ||
242 | /* | |
243 | * If there is no IRQ handler or it was disabled, exit early. | |
244 | * Since we set PENDING, if another processor is handling | |
245 | * a different instance of this same irq, the other processor | |
246 | * will take care of it. | |
247 | */ | |
248 | if (unlikely(!action)) | |
249 | goto out; | |
250 | ||
251 | /* | |
252 | * Edge triggered interrupts need to remember | |
253 | * pending events. | |
254 | * This applies to any hw interrupts that allow a second | |
255 | * instance of the same irq to arrive while we are in do_IRQ | |
256 | * or in the handler. But the code here only handles the _second_ | |
257 | * instance of the irq, not the third or fourth. So it is mostly | |
258 | * useful for irq hardware that does not mask cleanly in an | |
259 | * SMP environment. | |
260 | */ | |
261 | for (;;) { | |
262 | irqreturn_t action_ret; | |
263 | ||
264 | spin_unlock(&desc->lock); | |
265 | ||
7d12e780 | 266 | action_ret = handle_IRQ_event(irq, action); |
1da177e4 | 267 | if (!noirqdebug) |
7d12e780 | 268 | note_interrupt(irq, desc, action_ret); |
b42172fc LT |
269 | |
270 | spin_lock(&desc->lock); | |
1da177e4 LT |
271 | if (likely(!(desc->status & IRQ_PENDING))) |
272 | break; | |
273 | desc->status &= ~IRQ_PENDING; | |
274 | } | |
275 | desc->status &= ~IRQ_INPROGRESS; | |
276 | ||
277 | out: | |
278 | /* | |
279 | * The ->end() handler has to deal with interrupts which got | |
280 | * disabled while the handler was running. | |
281 | */ | |
d1bef4ed | 282 | desc->chip->end(irq); |
1da177e4 LT |
283 | spin_unlock(&desc->lock); |
284 | ||
285 | return 1; | |
286 | } | |
af8c65b5 | 287 | #endif |
1da177e4 | 288 | |
243c7621 IM |
289 | #ifdef CONFIG_TRACE_IRQFLAGS |
290 | ||
291 | /* | |
292 | * lockdep: we want to handle all irq_desc locks as a single lock-class: | |
293 | */ | |
294 | static struct lock_class_key irq_desc_lock_class; | |
295 | ||
296 | void early_init_irq_lock_class(void) | |
297 | { | |
298 | int i; | |
299 | ||
85c0f909 | 300 | for (i = 0; i < nr_irqs; i++) |
243c7621 IM |
301 | lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class); |
302 | } | |
303 | ||
304 | #endif |