blob: 4ef555c50db8da27f02106e1ca50e656ad47e6bb [file] [log] [blame]
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -07001/*
2 * linux/kernel/irq/chip.c
3 *
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
6 *
7 * This file contains the core interrupt handling code, for irq-chip
8 * based architectures.
9 *
10 * Detailed information is available in Documentation/DocBook/genericirq
11 */
12
13#include <linux/irq.h>
Michael Ellerman7fe37302007-04-18 19:39:21 +100014#include <linux/msi.h>
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070015#include <linux/module.h>
16#include <linux/interrupt.h>
17#include <linux/kernel_stat.h>
18
19#include "internals.h"
20
21/**
Eric W. Biederman3a16d712006-10-04 02:16:37 -070022 * dynamic_irq_init - initialize a dynamically allocated irq
23 * @irq: irq number to initialize
24 */
25void dynamic_irq_init(unsigned int irq)
26{
27 struct irq_desc *desc;
28 unsigned long flags;
29
Yinghai Lucb5bc832008-08-19 20:50:17 -070030 /* first time to use this irq_desc */
31 desc = irq_to_desc_alloc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070032 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070033 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070034 return;
35 }
36
37 /* Ensure we don't have left over values from a previous use of this irq */
Eric W. Biederman3a16d712006-10-04 02:16:37 -070038 spin_lock_irqsave(&desc->lock, flags);
39 desc->status = IRQ_DISABLED;
40 desc->chip = &no_irq_chip;
41 desc->handle_irq = handle_bad_irq;
42 desc->depth = 1;
Eric W. Biederman5b912c12007-01-28 12:52:03 -070043 desc->msi_desc = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070044 desc->handler_data = NULL;
45 desc->chip_data = NULL;
46 desc->action = NULL;
47 desc->irq_count = 0;
48 desc->irqs_unhandled = 0;
49#ifdef CONFIG_SMP
Mike Travisd366f8c2008-04-04 18:11:12 -070050 cpus_setall(desc->affinity);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070051#endif
52 spin_unlock_irqrestore(&desc->lock, flags);
53}
54
55/**
56 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
57 * @irq: irq number to initialize
58 */
59void dynamic_irq_cleanup(unsigned int irq)
60{
61 struct irq_desc *desc;
62 unsigned long flags;
63
Yinghai Lucb5bc832008-08-19 20:50:17 -070064 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070065 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070066 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070067 return;
68 }
69
Eric W. Biederman3a16d712006-10-04 02:16:37 -070070 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070071 if (desc->action) {
72 spin_unlock_irqrestore(&desc->lock, flags);
Arjan van de Ven261c40c2008-07-25 19:45:37 -070073 WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
Eric W. Biederman1f800252006-10-04 02:16:56 -070074 irq);
Eric W. Biederman1f800252006-10-04 02:16:56 -070075 return;
76 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070077 desc->msi_desc = NULL;
78 desc->handler_data = NULL;
79 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070080 desc->handle_irq = handle_bad_irq;
81 desc->chip = &no_irq_chip;
82 spin_unlock_irqrestore(&desc->lock, flags);
83}
84
85
86/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070087 * set_irq_chip - set the irq chip for an irq
88 * @irq: irq number
89 * @chip: pointer to irq chip description structure
90 */
91int set_irq_chip(unsigned int irq, struct irq_chip *chip)
92{
93 struct irq_desc *desc;
94 unsigned long flags;
95
Yinghai Lucb5bc832008-08-19 20:50:17 -070096 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070097 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070098 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070099 return -EINVAL;
100 }
101
102 if (!chip)
103 chip = &no_irq_chip;
104
Yinghai Lu08678b02008-08-19 20:50:05 -0700105 desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700106 spin_lock_irqsave(&desc->lock, flags);
107 irq_chip_set_defaults(chip);
108 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700109 spin_unlock_irqrestore(&desc->lock, flags);
110
111 return 0;
112}
113EXPORT_SYMBOL(set_irq_chip);
114
115/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700116 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700117 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700118 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700119 */
120int set_irq_type(unsigned int irq, unsigned int type)
121{
122 struct irq_desc *desc;
123 unsigned long flags;
124 int ret = -ENXIO;
125
Yinghai Lucb5bc832008-08-19 20:50:17 -0700126 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700127 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700128 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
129 return -ENODEV;
130 }
131
David Brownell0c5d1eb2008-10-01 14:46:18 -0700132 if (type == IRQ_TYPE_NONE)
133 return 0;
134
135 spin_lock_irqsave(&desc->lock, flags);
136 ret = __irq_set_trigger(desc, irq, flags);
137 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700138 return ret;
139}
140EXPORT_SYMBOL(set_irq_type);
141
142/**
143 * set_irq_data - set irq type data for an irq
144 * @irq: Interrupt number
145 * @data: Pointer to interrupt specific data
146 *
147 * Set the hardware irq controller data for an irq
148 */
149int set_irq_data(unsigned int irq, void *data)
150{
151 struct irq_desc *desc;
152 unsigned long flags;
153
Yinghai Lucb5bc832008-08-19 20:50:17 -0700154 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700155 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700156 printk(KERN_ERR
157 "Trying to install controller data for IRQ%d\n", irq);
158 return -EINVAL;
159 }
160
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700161 spin_lock_irqsave(&desc->lock, flags);
162 desc->handler_data = data;
163 spin_unlock_irqrestore(&desc->lock, flags);
164 return 0;
165}
166EXPORT_SYMBOL(set_irq_data);
167
168/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700169 * set_irq_data - set irq type data for an irq
170 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800171 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700172 *
173 * Set the hardware irq controller data for an irq
174 */
175int set_irq_msi(unsigned int irq, struct msi_desc *entry)
176{
177 struct irq_desc *desc;
178 unsigned long flags;
179
Yinghai Lucb5bc832008-08-19 20:50:17 -0700180 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700181 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700182 printk(KERN_ERR
183 "Trying to install msi data for IRQ%d\n", irq);
184 return -EINVAL;
185 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700186
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700187 spin_lock_irqsave(&desc->lock, flags);
188 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000189 if (entry)
190 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700191 spin_unlock_irqrestore(&desc->lock, flags);
192 return 0;
193}
194
195/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700196 * set_irq_chip_data - set irq chip data for an irq
197 * @irq: Interrupt number
198 * @data: Pointer to chip specific data
199 *
200 * Set the hardware irq chip data for an irq
201 */
202int set_irq_chip_data(unsigned int irq, void *data)
203{
Yinghai Lu08678b02008-08-19 20:50:05 -0700204 struct irq_desc *desc;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700205 unsigned long flags;
206
Yinghai Lucb5bc832008-08-19 20:50:17 -0700207 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700208 if (!desc) {
209 printk(KERN_ERR
210 "Trying to install chip data for IRQ%d\n", irq);
211 return -EINVAL;
212 }
213
214 if (!desc->chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700215 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
216 return -EINVAL;
217 }
218
219 spin_lock_irqsave(&desc->lock, flags);
220 desc->chip_data = data;
221 spin_unlock_irqrestore(&desc->lock, flags);
222
223 return 0;
224}
225EXPORT_SYMBOL(set_irq_chip_data);
226
227/*
228 * default enable function
229 */
230static void default_enable(unsigned int irq)
231{
Yinghai Lu08678b02008-08-19 20:50:05 -0700232 struct irq_desc *desc;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700233
Yinghai Lu08678b02008-08-19 20:50:05 -0700234 desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700235 desc->chip->unmask(irq);
236 desc->status &= ~IRQ_MASKED;
237}
238
239/*
240 * default disable function
241 */
242static void default_disable(unsigned int irq)
243{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700244}
245
246/*
247 * default startup function
248 */
249static unsigned int default_startup(unsigned int irq)
250{
Yinghai Lu08678b02008-08-19 20:50:05 -0700251 struct irq_desc *desc;
252
253 desc = irq_to_desc(irq);
254 desc->chip->enable(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700255
256 return 0;
257}
258
259/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100260 * default shutdown function
261 */
262static void default_shutdown(unsigned int irq)
263{
Yinghai Lu08678b02008-08-19 20:50:05 -0700264 struct irq_desc *desc;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100265
Yinghai Lu08678b02008-08-19 20:50:05 -0700266 desc = irq_to_desc(irq);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100267 desc->chip->mask(irq);
268 desc->status |= IRQ_MASKED;
269}
270
271/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700272 * Fixup enable/disable function pointers
273 */
274void irq_chip_set_defaults(struct irq_chip *chip)
275{
276 if (!chip->enable)
277 chip->enable = default_enable;
278 if (!chip->disable)
279 chip->disable = default_disable;
280 if (!chip->startup)
281 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100282 /*
283 * We use chip->disable, when the user provided its own. When
284 * we have default_disable set for chip->disable, then we need
285 * to use default_shutdown, otherwise the irq line is not
286 * disabled on free_irq():
287 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700288 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100289 chip->shutdown = chip->disable != default_disable ?
290 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700291 if (!chip->name)
292 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800293 if (!chip->end)
294 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700295}
296
297static inline void mask_ack_irq(struct irq_desc *desc, int irq)
298{
299 if (desc->chip->mask_ack)
300 desc->chip->mask_ack(irq);
301 else {
302 desc->chip->mask(irq);
303 desc->chip->ack(irq);
304 }
305}
306
307/**
308 * handle_simple_irq - Simple and software-decoded IRQs.
309 * @irq: the interrupt number
310 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700311 *
312 * Simple interrupts are either sent from a demultiplexing interrupt
313 * handler or come from hardware, where no interrupt hardware control
314 * is necessary.
315 *
316 * Note: The caller is expected to handle the ack, clear, mask and
317 * unmask issues if necessary.
318 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800319void
David Howells7d12e782006-10-05 14:55:46 +0100320handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700321{
322 struct irqaction *action;
323 irqreturn_t action_ret;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700324
325 spin_lock(&desc->lock);
326
327 if (unlikely(desc->status & IRQ_INPROGRESS))
328 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100329 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700330#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700331 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700332#else
333 kstat_irqs_this_cpu(irq)++;
334#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700335
336 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100337 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700338 goto out_unlock;
339
340 desc->status |= IRQ_INPROGRESS;
341 spin_unlock(&desc->lock);
342
David Howells7d12e782006-10-05 14:55:46 +0100343 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700344 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100345 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700346
347 spin_lock(&desc->lock);
348 desc->status &= ~IRQ_INPROGRESS;
349out_unlock:
350 spin_unlock(&desc->lock);
351}
352
353/**
354 * handle_level_irq - Level type irq handler
355 * @irq: the interrupt number
356 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700357 *
358 * Level type interrupts are active as long as the hardware line has
359 * the active level. This may require to mask the interrupt and unmask
360 * it after the associated handler has acknowledged the device, so the
361 * interrupt line is back to inactive.
362 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800363void
David Howells7d12e782006-10-05 14:55:46 +0100364handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700365{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700366 struct irqaction *action;
367 irqreturn_t action_ret;
368
369 spin_lock(&desc->lock);
370 mask_ack_irq(desc, irq);
371
372 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200373 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700374 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700375#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700376 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700377#else
378 kstat_irqs_this_cpu(irq)++;
379#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700380
381 /*
382 * If its disabled or no action available
383 * keep it masked and get out of here
384 */
385 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000386 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200387 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700388
389 desc->status |= IRQ_INPROGRESS;
390 spin_unlock(&desc->lock);
391
David Howells7d12e782006-10-05 14:55:46 +0100392 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700393 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100394 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700395
396 spin_lock(&desc->lock);
397 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
399 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200400out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700401 spin_unlock(&desc->lock);
402}
403
404/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700405 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700406 * @irq: the interrupt number
407 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700408 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700409 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700410 * call when the interrupt has been serviced. This enables support
411 * for modern forms of interrupt handlers, which handle the flow
412 * details in hardware, transparently.
413 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800414void
David Howells7d12e782006-10-05 14:55:46 +0100415handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700416{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700417 struct irqaction *action;
418 irqreturn_t action_ret;
419
420 spin_lock(&desc->lock);
421
422 if (unlikely(desc->status & IRQ_INPROGRESS))
423 goto out;
424
425 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700426#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700427 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700428#else
429 kstat_irqs_this_cpu(irq)++;
430#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700431
432 /*
433 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800434 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700435 */
436 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700437 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
438 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800439 if (desc->chip->mask)
440 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700441 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700442 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700443
444 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700445 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700446 spin_unlock(&desc->lock);
447
David Howells7d12e782006-10-05 14:55:46 +0100448 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700449 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100450 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700451
452 spin_lock(&desc->lock);
453 desc->status &= ~IRQ_INPROGRESS;
454out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700455 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700456
457 spin_unlock(&desc->lock);
458}
459
460/**
461 * handle_edge_irq - edge type IRQ handler
462 * @irq: the interrupt number
463 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700464 *
465 * Interrupt occures on the falling and/or rising edge of a hardware
466 * signal. The occurence is latched into the irq controller hardware
467 * and must be acked in order to be reenabled. After the ack another
468 * interrupt can happen on the same source even before the first one
469 * is handled by the assosiacted event handler. If this happens it
470 * might be necessary to disable (mask) the interrupt depending on the
471 * controller hardware. This requires to reenable the interrupt inside
472 * of the loop which handles the interrupts which have arrived while
473 * the handler was running. If all pending interrupts are handled, the
474 * loop is left.
475 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800476void
David Howells7d12e782006-10-05 14:55:46 +0100477handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700478{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700479 spin_lock(&desc->lock);
480
481 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
482
483 /*
484 * If we're currently running this IRQ, or its disabled,
485 * we shouldn't process the IRQ. Mark it pending, handle
486 * the necessary masking and go out
487 */
488 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
489 !desc->action)) {
490 desc->status |= (IRQ_PENDING | IRQ_MASKED);
491 mask_ack_irq(desc, irq);
492 goto out_unlock;
493 }
Yinghai Lu8c464a42008-08-25 12:41:19 -0700494#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700495 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700496#else
497 kstat_irqs_this_cpu(irq)++;
498#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700499
500 /* Start handling the irq */
501 desc->chip->ack(irq);
502
503 /* Mark the IRQ currently in progress.*/
504 desc->status |= IRQ_INPROGRESS;
505
506 do {
507 struct irqaction *action = desc->action;
508 irqreturn_t action_ret;
509
510 if (unlikely(!action)) {
511 desc->chip->mask(irq);
512 goto out_unlock;
513 }
514
515 /*
516 * When another irq arrived while we were handling
517 * one, we could have masked the irq.
518 * Renable it, if it was not disabled in meantime.
519 */
520 if (unlikely((desc->status &
521 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
522 (IRQ_PENDING | IRQ_MASKED))) {
523 desc->chip->unmask(irq);
524 desc->status &= ~IRQ_MASKED;
525 }
526
527 desc->status &= ~IRQ_PENDING;
528 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100529 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700530 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100531 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700532 spin_lock(&desc->lock);
533
534 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
535
536 desc->status &= ~IRQ_INPROGRESS;
537out_unlock:
538 spin_unlock(&desc->lock);
539}
540
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700541/**
542 * handle_percpu_IRQ - Per CPU local irq handler
543 * @irq: the interrupt number
544 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700545 *
546 * Per CPU interrupts on SMP machines without locking requirements
547 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800548void
David Howells7d12e782006-10-05 14:55:46 +0100549handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700550{
551 irqreturn_t action_ret;
552
Yinghai Lu8c464a42008-08-25 12:41:19 -0700553#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700554 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700555#else
556 kstat_irqs_this_cpu(irq)++;
557#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700558
559 if (desc->chip->ack)
560 desc->chip->ack(irq);
561
David Howells7d12e782006-10-05 14:55:46 +0100562 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700563 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100564 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700565
566 if (desc->chip->eoi)
567 desc->chip->eoi(irq);
568}
569
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700570void
Ingo Molnara460e742006-10-17 00:10:03 -0700571__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
572 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700573{
574 struct irq_desc *desc;
575 unsigned long flags;
576
Yinghai Lucb5bc832008-08-19 20:50:17 -0700577 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700578 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700579 printk(KERN_ERR
580 "Trying to install type control for IRQ%d\n", irq);
581 return;
582 }
583
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700584 if (!handle)
585 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800586 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100587 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100588 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100589 /*
590 * Some ARM implementations install a handler for really dumb
591 * interrupt hardware without setting an irq_chip. This worked
592 * with the ARM no_irq_chip but the check in setup_irq would
593 * prevent us to setup the interrupt at all. Switch it to
594 * dummy_irq_chip for easy transition.
595 */
596 desc->chip = &dummy_irq_chip;
597 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700598
599 spin_lock_irqsave(&desc->lock, flags);
600
601 /* Uninstall? */
602 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800603 if (desc->chip != &no_irq_chip)
604 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700605 desc->status |= IRQ_DISABLED;
606 desc->depth = 1;
607 }
608 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700609 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700610
611 if (handle != handle_bad_irq && is_chained) {
612 desc->status &= ~IRQ_DISABLED;
613 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
614 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100615 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700616 }
617 spin_unlock_irqrestore(&desc->lock, flags);
618}
619
620void
621set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100622 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700623{
624 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700625 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700626}
627
Ingo Molnara460e742006-10-17 00:10:03 -0700628void
629set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
630 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700631{
Ingo Molnara460e742006-10-17 00:10:03 -0700632 set_irq_chip(irq, chip);
633 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700634}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800635
636void __init set_irq_noprobe(unsigned int irq)
637{
638 struct irq_desc *desc;
639 unsigned long flags;
640
Yinghai Lucb5bc832008-08-19 20:50:17 -0700641 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700642 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800643 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
644
645 return;
646 }
647
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800648 spin_lock_irqsave(&desc->lock, flags);
649 desc->status |= IRQ_NOPROBE;
650 spin_unlock_irqrestore(&desc->lock, flags);
651}
652
653void __init set_irq_probe(unsigned int irq)
654{
655 struct irq_desc *desc;
656 unsigned long flags;
657
Yinghai Lucb5bc832008-08-19 20:50:17 -0700658 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700659 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800660 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
661
662 return;
663 }
664
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800665 spin_lock_irqsave(&desc->lock, flags);
666 desc->status &= ~IRQ_NOPROBE;
667 spin_unlock_irqrestore(&desc->lock, flags);
668}