blob: 5203a599d211ad03a4fca470506df7785ae57783 [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) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070031 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070032 return;
33 }
34
35 /* Ensure we don't have left over values from a previous use of this irq */
36 desc = irq_desc + irq;
37 spin_lock_irqsave(&desc->lock, flags);
38 desc->status = IRQ_DISABLED;
39 desc->chip = &no_irq_chip;
40 desc->handle_irq = handle_bad_irq;
41 desc->depth = 1;
Eric W. Biederman5b912c12007-01-28 12:52:03 -070042 desc->msi_desc = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070043 desc->handler_data = NULL;
44 desc->chip_data = NULL;
45 desc->action = NULL;
46 desc->irq_count = 0;
47 desc->irqs_unhandled = 0;
48#ifdef CONFIG_SMP
Mike Travisd366f8c2008-04-04 18:11:12 -070049 cpus_setall(desc->affinity);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070050#endif
51 spin_unlock_irqrestore(&desc->lock, flags);
52}
53
54/**
55 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
56 * @irq: irq number to initialize
57 */
58void dynamic_irq_cleanup(unsigned int irq)
59{
60 struct irq_desc *desc;
61 unsigned long flags;
62
63 if (irq >= NR_IRQS) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070064 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070065 return;
66 }
67
68 desc = irq_desc + irq;
69 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070070 if (desc->action) {
71 spin_unlock_irqrestore(&desc->lock, flags);
Arjan van de Ven261c40c2008-07-25 19:45:37 -070072 WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
Eric W. Biederman1f800252006-10-04 02:16:56 -070073 irq);
Eric W. Biederman1f800252006-10-04 02:16:56 -070074 return;
75 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070076 desc->msi_desc = NULL;
77 desc->handler_data = NULL;
78 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070079 desc->handle_irq = handle_bad_irq;
80 desc->chip = &no_irq_chip;
81 spin_unlock_irqrestore(&desc->lock, flags);
82}
83
84
85/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070086 * set_irq_chip - set the irq chip for an irq
87 * @irq: irq number
88 * @chip: pointer to irq chip description structure
89 */
90int set_irq_chip(unsigned int irq, struct irq_chip *chip)
91{
92 struct irq_desc *desc;
93 unsigned long flags;
94
95 if (irq >= NR_IRQS) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070096 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070097 return -EINVAL;
98 }
99
100 if (!chip)
101 chip = &no_irq_chip;
102
103 desc = irq_desc + irq;
104 spin_lock_irqsave(&desc->lock, flags);
105 irq_chip_set_defaults(chip);
106 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700107 spin_unlock_irqrestore(&desc->lock, flags);
108
109 return 0;
110}
111EXPORT_SYMBOL(set_irq_chip);
112
113/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700114 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700115 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700116 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700117 */
118int set_irq_type(unsigned int irq, unsigned int type)
119{
120 struct irq_desc *desc;
121 unsigned long flags;
122 int ret = -ENXIO;
123
124 if (irq >= NR_IRQS) {
125 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
126 return -ENODEV;
127 }
128
129 desc = irq_desc + irq;
David Brownell0c5d1eb2008-10-01 14:46:18 -0700130 if (type == IRQ_TYPE_NONE)
131 return 0;
132
133 spin_lock_irqsave(&desc->lock, flags);
134 ret = __irq_set_trigger(desc, irq, flags);
135 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700136 return ret;
137}
138EXPORT_SYMBOL(set_irq_type);
139
140/**
141 * set_irq_data - set irq type data for an irq
142 * @irq: Interrupt number
143 * @data: Pointer to interrupt specific data
144 *
145 * Set the hardware irq controller data for an irq
146 */
147int set_irq_data(unsigned int irq, void *data)
148{
149 struct irq_desc *desc;
150 unsigned long flags;
151
152 if (irq >= NR_IRQS) {
153 printk(KERN_ERR
154 "Trying to install controller data for IRQ%d\n", irq);
155 return -EINVAL;
156 }
157
158 desc = irq_desc + irq;
159 spin_lock_irqsave(&desc->lock, flags);
160 desc->handler_data = data;
161 spin_unlock_irqrestore(&desc->lock, flags);
162 return 0;
163}
164EXPORT_SYMBOL(set_irq_data);
165
166/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700167 * set_irq_data - set irq type data for an irq
168 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800169 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700170 *
171 * Set the hardware irq controller data for an irq
172 */
173int set_irq_msi(unsigned int irq, struct msi_desc *entry)
174{
175 struct irq_desc *desc;
176 unsigned long flags;
177
178 if (irq >= NR_IRQS) {
179 printk(KERN_ERR
180 "Trying to install msi data for IRQ%d\n", irq);
181 return -EINVAL;
182 }
183 desc = irq_desc + irq;
184 spin_lock_irqsave(&desc->lock, flags);
185 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000186 if (entry)
187 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700188 spin_unlock_irqrestore(&desc->lock, flags);
189 return 0;
190}
191
192/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700193 * set_irq_chip_data - set irq chip data for an irq
194 * @irq: Interrupt number
195 * @data: Pointer to chip specific data
196 *
197 * Set the hardware irq chip data for an irq
198 */
199int set_irq_chip_data(unsigned int irq, void *data)
200{
201 struct irq_desc *desc = irq_desc + irq;
202 unsigned long flags;
203
204 if (irq >= NR_IRQS || !desc->chip) {
205 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
206 return -EINVAL;
207 }
208
209 spin_lock_irqsave(&desc->lock, flags);
210 desc->chip_data = data;
211 spin_unlock_irqrestore(&desc->lock, flags);
212
213 return 0;
214}
215EXPORT_SYMBOL(set_irq_chip_data);
216
217/*
218 * default enable function
219 */
220static void default_enable(unsigned int irq)
221{
222 struct irq_desc *desc = irq_desc + irq;
223
224 desc->chip->unmask(irq);
225 desc->status &= ~IRQ_MASKED;
226}
227
228/*
229 * default disable function
230 */
231static void default_disable(unsigned int irq)
232{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700233}
234
235/*
236 * default startup function
237 */
238static unsigned int default_startup(unsigned int irq)
239{
240 irq_desc[irq].chip->enable(irq);
241
242 return 0;
243}
244
245/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100246 * default shutdown function
247 */
248static void default_shutdown(unsigned int irq)
249{
250 struct irq_desc *desc = irq_desc + irq;
251
252 desc->chip->mask(irq);
253 desc->status |= IRQ_MASKED;
254}
255
256/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700257 * Fixup enable/disable function pointers
258 */
259void irq_chip_set_defaults(struct irq_chip *chip)
260{
261 if (!chip->enable)
262 chip->enable = default_enable;
263 if (!chip->disable)
264 chip->disable = default_disable;
265 if (!chip->startup)
266 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100267 /*
268 * We use chip->disable, when the user provided its own. When
269 * we have default_disable set for chip->disable, then we need
270 * to use default_shutdown, otherwise the irq line is not
271 * disabled on free_irq():
272 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700273 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100274 chip->shutdown = chip->disable != default_disable ?
275 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700276 if (!chip->name)
277 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800278 if (!chip->end)
279 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700280}
281
282static inline void mask_ack_irq(struct irq_desc *desc, int irq)
283{
284 if (desc->chip->mask_ack)
285 desc->chip->mask_ack(irq);
286 else {
287 desc->chip->mask(irq);
288 desc->chip->ack(irq);
289 }
290}
291
292/**
293 * handle_simple_irq - Simple and software-decoded IRQs.
294 * @irq: the interrupt number
295 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700296 *
297 * Simple interrupts are either sent from a demultiplexing interrupt
298 * handler or come from hardware, where no interrupt hardware control
299 * is necessary.
300 *
301 * Note: The caller is expected to handle the ack, clear, mask and
302 * unmask issues if necessary.
303 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800304void
David Howells7d12e782006-10-05 14:55:46 +0100305handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700306{
307 struct irqaction *action;
308 irqreturn_t action_ret;
309 const unsigned int cpu = smp_processor_id();
310
311 spin_lock(&desc->lock);
312
313 if (unlikely(desc->status & IRQ_INPROGRESS))
314 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100315 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700316 kstat_cpu(cpu).irqs[irq]++;
317
318 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100319 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700320 goto out_unlock;
321
322 desc->status |= IRQ_INPROGRESS;
323 spin_unlock(&desc->lock);
324
David Howells7d12e782006-10-05 14:55:46 +0100325 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700326 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100327 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700328
329 spin_lock(&desc->lock);
330 desc->status &= ~IRQ_INPROGRESS;
331out_unlock:
332 spin_unlock(&desc->lock);
333}
334
335/**
336 * handle_level_irq - Level type irq handler
337 * @irq: the interrupt number
338 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700339 *
340 * Level type interrupts are active as long as the hardware line has
341 * the active level. This may require to mask the interrupt and unmask
342 * it after the associated handler has acknowledged the device, so the
343 * interrupt line is back to inactive.
344 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800345void
David Howells7d12e782006-10-05 14:55:46 +0100346handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700347{
348 unsigned int cpu = smp_processor_id();
349 struct irqaction *action;
350 irqreturn_t action_ret;
351
352 spin_lock(&desc->lock);
353 mask_ack_irq(desc, irq);
354
355 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200356 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700357 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
358 kstat_cpu(cpu).irqs[irq]++;
359
360 /*
361 * If its disabled or no action available
362 * keep it masked and get out of here
363 */
364 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000365 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200366 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700367
368 desc->status |= IRQ_INPROGRESS;
369 spin_unlock(&desc->lock);
370
David Howells7d12e782006-10-05 14:55:46 +0100371 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700372 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100373 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700374
375 spin_lock(&desc->lock);
376 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700377 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
378 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200379out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700380 spin_unlock(&desc->lock);
381}
382
383/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700384 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700385 * @irq: the interrupt number
386 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700387 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700388 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700389 * call when the interrupt has been serviced. This enables support
390 * for modern forms of interrupt handlers, which handle the flow
391 * details in hardware, transparently.
392 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800393void
David Howells7d12e782006-10-05 14:55:46 +0100394handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700395{
396 unsigned int cpu = smp_processor_id();
397 struct irqaction *action;
398 irqreturn_t action_ret;
399
400 spin_lock(&desc->lock);
401
402 if (unlikely(desc->status & IRQ_INPROGRESS))
403 goto out;
404
405 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
406 kstat_cpu(cpu).irqs[irq]++;
407
408 /*
409 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800410 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700411 */
412 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700413 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
414 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800415 if (desc->chip->mask)
416 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700417 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700418 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700419
420 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700421 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700422 spin_unlock(&desc->lock);
423
David Howells7d12e782006-10-05 14:55:46 +0100424 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700425 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100426 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700427
428 spin_lock(&desc->lock);
429 desc->status &= ~IRQ_INPROGRESS;
430out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700431 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700432
433 spin_unlock(&desc->lock);
434}
435
436/**
437 * handle_edge_irq - edge type IRQ handler
438 * @irq: the interrupt number
439 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700440 *
441 * Interrupt occures on the falling and/or rising edge of a hardware
442 * signal. The occurence is latched into the irq controller hardware
443 * and must be acked in order to be reenabled. After the ack another
444 * interrupt can happen on the same source even before the first one
445 * is handled by the assosiacted event handler. If this happens it
446 * might be necessary to disable (mask) the interrupt depending on the
447 * controller hardware. This requires to reenable the interrupt inside
448 * of the loop which handles the interrupts which have arrived while
449 * the handler was running. If all pending interrupts are handled, the
450 * loop is left.
451 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800452void
David Howells7d12e782006-10-05 14:55:46 +0100453handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700454{
455 const unsigned int cpu = smp_processor_id();
456
457 spin_lock(&desc->lock);
458
459 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
460
461 /*
462 * If we're currently running this IRQ, or its disabled,
463 * we shouldn't process the IRQ. Mark it pending, handle
464 * the necessary masking and go out
465 */
466 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
467 !desc->action)) {
468 desc->status |= (IRQ_PENDING | IRQ_MASKED);
469 mask_ack_irq(desc, irq);
470 goto out_unlock;
471 }
472
473 kstat_cpu(cpu).irqs[irq]++;
474
475 /* Start handling the irq */
476 desc->chip->ack(irq);
477
478 /* Mark the IRQ currently in progress.*/
479 desc->status |= IRQ_INPROGRESS;
480
481 do {
482 struct irqaction *action = desc->action;
483 irqreturn_t action_ret;
484
485 if (unlikely(!action)) {
486 desc->chip->mask(irq);
487 goto out_unlock;
488 }
489
490 /*
491 * When another irq arrived while we were handling
492 * one, we could have masked the irq.
493 * Renable it, if it was not disabled in meantime.
494 */
495 if (unlikely((desc->status &
496 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
497 (IRQ_PENDING | IRQ_MASKED))) {
498 desc->chip->unmask(irq);
499 desc->status &= ~IRQ_MASKED;
500 }
501
502 desc->status &= ~IRQ_PENDING;
503 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100504 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700505 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100506 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700507 spin_lock(&desc->lock);
508
509 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
510
511 desc->status &= ~IRQ_INPROGRESS;
512out_unlock:
513 spin_unlock(&desc->lock);
514}
515
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700516/**
517 * handle_percpu_IRQ - Per CPU local irq handler
518 * @irq: the interrupt number
519 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700520 *
521 * Per CPU interrupts on SMP machines without locking requirements
522 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800523void
David Howells7d12e782006-10-05 14:55:46 +0100524handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700525{
526 irqreturn_t action_ret;
527
528 kstat_this_cpu.irqs[irq]++;
529
530 if (desc->chip->ack)
531 desc->chip->ack(irq);
532
David Howells7d12e782006-10-05 14:55:46 +0100533 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700534 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100535 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700536
537 if (desc->chip->eoi)
538 desc->chip->eoi(irq);
539}
540
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700541void
Ingo Molnara460e742006-10-17 00:10:03 -0700542__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
543 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544{
545 struct irq_desc *desc;
546 unsigned long flags;
547
548 if (irq >= NR_IRQS) {
549 printk(KERN_ERR
550 "Trying to install type control for IRQ%d\n", irq);
551 return;
552 }
553
554 desc = irq_desc + irq;
555
556 if (!handle)
557 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800558 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100559 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100560 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100561 /*
562 * Some ARM implementations install a handler for really dumb
563 * interrupt hardware without setting an irq_chip. This worked
564 * with the ARM no_irq_chip but the check in setup_irq would
565 * prevent us to setup the interrupt at all. Switch it to
566 * dummy_irq_chip for easy transition.
567 */
568 desc->chip = &dummy_irq_chip;
569 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700570
571 spin_lock_irqsave(&desc->lock, flags);
572
573 /* Uninstall? */
574 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800575 if (desc->chip != &no_irq_chip)
576 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700577 desc->status |= IRQ_DISABLED;
578 desc->depth = 1;
579 }
580 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700581 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700582
583 if (handle != handle_bad_irq && is_chained) {
584 desc->status &= ~IRQ_DISABLED;
585 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
586 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100587 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700588 }
589 spin_unlock_irqrestore(&desc->lock, flags);
590}
591
592void
593set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100594 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700595{
596 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700597 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700598}
599
Ingo Molnara460e742006-10-17 00:10:03 -0700600void
601set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
602 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700603{
Ingo Molnara460e742006-10-17 00:10:03 -0700604 set_irq_chip(irq, chip);
605 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700606}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800607
608void __init set_irq_noprobe(unsigned int irq)
609{
610 struct irq_desc *desc;
611 unsigned long flags;
612
613 if (irq >= NR_IRQS) {
614 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
615
616 return;
617 }
618
619 desc = irq_desc + irq;
620
621 spin_lock_irqsave(&desc->lock, flags);
622 desc->status |= IRQ_NOPROBE;
623 spin_unlock_irqrestore(&desc->lock, flags);
624}
625
626void __init set_irq_probe(unsigned int irq)
627{
628 struct irq_desc *desc;
629 unsigned long flags;
630
631 if (irq >= NR_IRQS) {
632 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
633
634 return;
635 }
636
637 desc = irq_desc + irq;
638
639 spin_lock_irqsave(&desc->lock, flags);
640 desc->status &= ~IRQ_NOPROBE;
641 spin_unlock_irqrestore(&desc->lock, flags);
642}