blob: 964964baefa23c2a8bdee504aa053d078ba29ad9 [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
30 if (irq >= NR_IRQS) {
31 printk(KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
32 WARN_ON(1);
33 return;
34 }
35
36 /* Ensure we don't have left over values from a previous use of this irq */
37 desc = irq_desc + irq;
38 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
64 if (irq >= NR_IRQS) {
65 printk(KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
66 WARN_ON(1);
67 return;
68 }
69
70 desc = irq_desc + irq;
71 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070072 if (desc->action) {
73 spin_unlock_irqrestore(&desc->lock, flags);
74 printk(KERN_ERR "Destroying IRQ%d without calling free_irq\n",
75 irq);
76 WARN_ON(1);
77 return;
78 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070079 desc->msi_desc = NULL;
80 desc->handler_data = NULL;
81 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070082 desc->handle_irq = handle_bad_irq;
83 desc->chip = &no_irq_chip;
84 spin_unlock_irqrestore(&desc->lock, flags);
85}
86
87
88/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070089 * set_irq_chip - set the irq chip for an irq
90 * @irq: irq number
91 * @chip: pointer to irq chip description structure
92 */
93int set_irq_chip(unsigned int irq, struct irq_chip *chip)
94{
95 struct irq_desc *desc;
96 unsigned long flags;
97
98 if (irq >= NR_IRQS) {
99 printk(KERN_ERR "Trying to install chip for IRQ%d\n", irq);
100 WARN_ON(1);
101 return -EINVAL;
102 }
103
104 if (!chip)
105 chip = &no_irq_chip;
106
107 desc = irq_desc + irq;
108 spin_lock_irqsave(&desc->lock, flags);
109 irq_chip_set_defaults(chip);
110 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700111 spin_unlock_irqrestore(&desc->lock, flags);
112
113 return 0;
114}
115EXPORT_SYMBOL(set_irq_chip);
116
117/**
118 * set_irq_type - set the irq type for an irq
119 * @irq: irq number
120 * @type: interrupt type - see include/linux/interrupt.h
121 */
122int set_irq_type(unsigned int irq, unsigned int type)
123{
124 struct irq_desc *desc;
125 unsigned long flags;
126 int ret = -ENXIO;
127
128 if (irq >= NR_IRQS) {
129 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
130 return -ENODEV;
131 }
132
133 desc = irq_desc + irq;
134 if (desc->chip->set_type) {
135 spin_lock_irqsave(&desc->lock, flags);
136 ret = desc->chip->set_type(irq, type);
137 spin_unlock_irqrestore(&desc->lock, flags);
138 }
139 return ret;
140}
141EXPORT_SYMBOL(set_irq_type);
142
143/**
144 * set_irq_data - set irq type data for an irq
145 * @irq: Interrupt number
146 * @data: Pointer to interrupt specific data
147 *
148 * Set the hardware irq controller data for an irq
149 */
150int set_irq_data(unsigned int irq, void *data)
151{
152 struct irq_desc *desc;
153 unsigned long flags;
154
155 if (irq >= NR_IRQS) {
156 printk(KERN_ERR
157 "Trying to install controller data for IRQ%d\n", irq);
158 return -EINVAL;
159 }
160
161 desc = irq_desc + irq;
162 spin_lock_irqsave(&desc->lock, flags);
163 desc->handler_data = data;
164 spin_unlock_irqrestore(&desc->lock, flags);
165 return 0;
166}
167EXPORT_SYMBOL(set_irq_data);
168
169/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700170 * set_irq_data - set irq type data for an irq
171 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800172 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700173 *
174 * Set the hardware irq controller data for an irq
175 */
176int set_irq_msi(unsigned int irq, struct msi_desc *entry)
177{
178 struct irq_desc *desc;
179 unsigned long flags;
180
181 if (irq >= NR_IRQS) {
182 printk(KERN_ERR
183 "Trying to install msi data for IRQ%d\n", irq);
184 return -EINVAL;
185 }
186 desc = irq_desc + irq;
187 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{
204 struct irq_desc *desc = irq_desc + irq;
205 unsigned long flags;
206
207 if (irq >= NR_IRQS || !desc->chip) {
208 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
209 return -EINVAL;
210 }
211
212 spin_lock_irqsave(&desc->lock, flags);
213 desc->chip_data = data;
214 spin_unlock_irqrestore(&desc->lock, flags);
215
216 return 0;
217}
218EXPORT_SYMBOL(set_irq_chip_data);
219
220/*
221 * default enable function
222 */
223static void default_enable(unsigned int irq)
224{
225 struct irq_desc *desc = irq_desc + irq;
226
227 desc->chip->unmask(irq);
228 desc->status &= ~IRQ_MASKED;
229}
230
231/*
232 * default disable function
233 */
234static void default_disable(unsigned int irq)
235{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700236}
237
238/*
239 * default startup function
240 */
241static unsigned int default_startup(unsigned int irq)
242{
243 irq_desc[irq].chip->enable(irq);
244
245 return 0;
246}
247
248/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100249 * default shutdown function
250 */
251static void default_shutdown(unsigned int irq)
252{
253 struct irq_desc *desc = irq_desc + irq;
254
255 desc->chip->mask(irq);
256 desc->status |= IRQ_MASKED;
257}
258
259/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700260 * Fixup enable/disable function pointers
261 */
262void irq_chip_set_defaults(struct irq_chip *chip)
263{
264 if (!chip->enable)
265 chip->enable = default_enable;
266 if (!chip->disable)
267 chip->disable = default_disable;
268 if (!chip->startup)
269 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100270 /*
271 * We use chip->disable, when the user provided its own. When
272 * we have default_disable set for chip->disable, then we need
273 * to use default_shutdown, otherwise the irq line is not
274 * disabled on free_irq():
275 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700276 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100277 chip->shutdown = chip->disable != default_disable ?
278 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700279 if (!chip->name)
280 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800281 if (!chip->end)
282 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700283}
284
285static inline void mask_ack_irq(struct irq_desc *desc, int irq)
286{
287 if (desc->chip->mask_ack)
288 desc->chip->mask_ack(irq);
289 else {
290 desc->chip->mask(irq);
291 desc->chip->ack(irq);
292 }
293}
294
295/**
296 * handle_simple_irq - Simple and software-decoded IRQs.
297 * @irq: the interrupt number
298 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700299 *
300 * Simple interrupts are either sent from a demultiplexing interrupt
301 * handler or come from hardware, where no interrupt hardware control
302 * is necessary.
303 *
304 * Note: The caller is expected to handle the ack, clear, mask and
305 * unmask issues if necessary.
306 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800307void
David Howells7d12e782006-10-05 14:55:46 +0100308handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700309{
310 struct irqaction *action;
311 irqreturn_t action_ret;
312 const unsigned int cpu = smp_processor_id();
313
314 spin_lock(&desc->lock);
315
316 if (unlikely(desc->status & IRQ_INPROGRESS))
317 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100318 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700319 kstat_cpu(cpu).irqs[irq]++;
320
321 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100322 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700323 goto out_unlock;
324
325 desc->status |= IRQ_INPROGRESS;
326 spin_unlock(&desc->lock);
327
David Howells7d12e782006-10-05 14:55:46 +0100328 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700329 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100330 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700331
332 spin_lock(&desc->lock);
333 desc->status &= ~IRQ_INPROGRESS;
334out_unlock:
335 spin_unlock(&desc->lock);
336}
337
338/**
339 * handle_level_irq - Level type irq handler
340 * @irq: the interrupt number
341 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700342 *
343 * Level type interrupts are active as long as the hardware line has
344 * the active level. This may require to mask the interrupt and unmask
345 * it after the associated handler has acknowledged the device, so the
346 * interrupt line is back to inactive.
347 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800348void
David Howells7d12e782006-10-05 14:55:46 +0100349handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700350{
351 unsigned int cpu = smp_processor_id();
352 struct irqaction *action;
353 irqreturn_t action_ret;
354
355 spin_lock(&desc->lock);
356 mask_ack_irq(desc, irq);
357
358 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200359 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700360 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
361 kstat_cpu(cpu).irqs[irq]++;
362
363 /*
364 * If its disabled or no action available
365 * keep it masked and get out of here
366 */
367 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000368 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200369 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700370
371 desc->status |= IRQ_INPROGRESS;
372 spin_unlock(&desc->lock);
373
David Howells7d12e782006-10-05 14:55:46 +0100374 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700375 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100376 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700377
378 spin_lock(&desc->lock);
379 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700380 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
381 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200382out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700383 spin_unlock(&desc->lock);
384}
385
386/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700387 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700388 * @irq: the interrupt number
389 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700390 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700391 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700392 * call when the interrupt has been serviced. This enables support
393 * for modern forms of interrupt handlers, which handle the flow
394 * details in hardware, transparently.
395 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800396void
David Howells7d12e782006-10-05 14:55:46 +0100397handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398{
399 unsigned int cpu = smp_processor_id();
400 struct irqaction *action;
401 irqreturn_t action_ret;
402
403 spin_lock(&desc->lock);
404
405 if (unlikely(desc->status & IRQ_INPROGRESS))
406 goto out;
407
408 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
409 kstat_cpu(cpu).irqs[irq]++;
410
411 /*
412 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800413 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700414 */
415 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700416 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
417 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800418 if (desc->chip->mask)
419 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700420 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700421 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700422
423 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700424 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700425 spin_unlock(&desc->lock);
426
David Howells7d12e782006-10-05 14:55:46 +0100427 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700428 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100429 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700430
431 spin_lock(&desc->lock);
432 desc->status &= ~IRQ_INPROGRESS;
433out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700434 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700435
436 spin_unlock(&desc->lock);
437}
438
439/**
440 * handle_edge_irq - edge type IRQ handler
441 * @irq: the interrupt number
442 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700443 *
444 * Interrupt occures on the falling and/or rising edge of a hardware
445 * signal. The occurence is latched into the irq controller hardware
446 * and must be acked in order to be reenabled. After the ack another
447 * interrupt can happen on the same source even before the first one
448 * is handled by the assosiacted event handler. If this happens it
449 * might be necessary to disable (mask) the interrupt depending on the
450 * controller hardware. This requires to reenable the interrupt inside
451 * of the loop which handles the interrupts which have arrived while
452 * the handler was running. If all pending interrupts are handled, the
453 * loop is left.
454 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800455void
David Howells7d12e782006-10-05 14:55:46 +0100456handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700457{
458 const unsigned int cpu = smp_processor_id();
459
460 spin_lock(&desc->lock);
461
462 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
463
464 /*
465 * If we're currently running this IRQ, or its disabled,
466 * we shouldn't process the IRQ. Mark it pending, handle
467 * the necessary masking and go out
468 */
469 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
470 !desc->action)) {
471 desc->status |= (IRQ_PENDING | IRQ_MASKED);
472 mask_ack_irq(desc, irq);
473 goto out_unlock;
474 }
475
476 kstat_cpu(cpu).irqs[irq]++;
477
478 /* Start handling the irq */
479 desc->chip->ack(irq);
480
481 /* Mark the IRQ currently in progress.*/
482 desc->status |= IRQ_INPROGRESS;
483
484 do {
485 struct irqaction *action = desc->action;
486 irqreturn_t action_ret;
487
488 if (unlikely(!action)) {
489 desc->chip->mask(irq);
490 goto out_unlock;
491 }
492
493 /*
494 * When another irq arrived while we were handling
495 * one, we could have masked the irq.
496 * Renable it, if it was not disabled in meantime.
497 */
498 if (unlikely((desc->status &
499 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
500 (IRQ_PENDING | IRQ_MASKED))) {
501 desc->chip->unmask(irq);
502 desc->status &= ~IRQ_MASKED;
503 }
504
505 desc->status &= ~IRQ_PENDING;
506 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100507 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700508 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100509 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700510 spin_lock(&desc->lock);
511
512 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
513
514 desc->status &= ~IRQ_INPROGRESS;
515out_unlock:
516 spin_unlock(&desc->lock);
517}
518
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700519/**
520 * handle_percpu_IRQ - Per CPU local irq handler
521 * @irq: the interrupt number
522 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700523 *
524 * Per CPU interrupts on SMP machines without locking requirements
525 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800526void
David Howells7d12e782006-10-05 14:55:46 +0100527handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700528{
529 irqreturn_t action_ret;
530
531 kstat_this_cpu.irqs[irq]++;
532
533 if (desc->chip->ack)
534 desc->chip->ack(irq);
535
David Howells7d12e782006-10-05 14:55:46 +0100536 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700537 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100538 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700539
540 if (desc->chip->eoi)
541 desc->chip->eoi(irq);
542}
543
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544void
Ingo Molnara460e742006-10-17 00:10:03 -0700545__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
546 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700547{
548 struct irq_desc *desc;
549 unsigned long flags;
550
551 if (irq >= NR_IRQS) {
552 printk(KERN_ERR
553 "Trying to install type control for IRQ%d\n", irq);
554 return;
555 }
556
557 desc = irq_desc + irq;
558
559 if (!handle)
560 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800561 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100562 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100563 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100564 /*
565 * Some ARM implementations install a handler for really dumb
566 * interrupt hardware without setting an irq_chip. This worked
567 * with the ARM no_irq_chip but the check in setup_irq would
568 * prevent us to setup the interrupt at all. Switch it to
569 * dummy_irq_chip for easy transition.
570 */
571 desc->chip = &dummy_irq_chip;
572 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700573
574 spin_lock_irqsave(&desc->lock, flags);
575
576 /* Uninstall? */
577 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800578 if (desc->chip != &no_irq_chip)
579 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700580 desc->status |= IRQ_DISABLED;
581 desc->depth = 1;
582 }
583 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700584 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700585
586 if (handle != handle_bad_irq && is_chained) {
587 desc->status &= ~IRQ_DISABLED;
588 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
589 desc->depth = 0;
590 desc->chip->unmask(irq);
591 }
592 spin_unlock_irqrestore(&desc->lock, flags);
593}
594
595void
596set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100597 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700598{
599 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700600 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700601}
602
Ingo Molnara460e742006-10-17 00:10:03 -0700603void
604set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
605 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700606{
Ingo Molnara460e742006-10-17 00:10:03 -0700607 set_irq_chip(irq, chip);
608 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800610
611void __init set_irq_noprobe(unsigned int irq)
612{
613 struct irq_desc *desc;
614 unsigned long flags;
615
616 if (irq >= NR_IRQS) {
617 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
618
619 return;
620 }
621
622 desc = irq_desc + irq;
623
624 spin_lock_irqsave(&desc->lock, flags);
625 desc->status |= IRQ_NOPROBE;
626 spin_unlock_irqrestore(&desc->lock, flags);
627}
628
629void __init set_irq_probe(unsigned int irq)
630{
631 struct irq_desc *desc;
632 unsigned long flags;
633
634 if (irq >= NR_IRQS) {
635 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
636
637 return;
638 }
639
640 desc = irq_desc + irq;
641
642 spin_lock_irqsave(&desc->lock, flags);
643 desc->status &= ~IRQ_NOPROBE;
644 spin_unlock_irqrestore(&desc->lock, flags);
645}