blob: 4895fde4eb933c25fe50fbbfabc3fb0a6cd9c742 [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{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020027 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070028 unsigned long flags;
29
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070030 if (!desc) {
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 */
Eric W. Biederman3a16d712006-10-04 02:16:37 -070036 spin_lock_irqsave(&desc->lock, flags);
37 desc->status = IRQ_DISABLED;
38 desc->chip = &no_irq_chip;
39 desc->handle_irq = handle_bad_irq;
40 desc->depth = 1;
Eric W. Biederman5b912c12007-01-28 12:52:03 -070041 desc->msi_desc = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070042 desc->handler_data = NULL;
43 desc->chip_data = NULL;
44 desc->action = NULL;
45 desc->irq_count = 0;
46 desc->irqs_unhandled = 0;
47#ifdef CONFIG_SMP
Mike Travisd366f8c2008-04-04 18:11:12 -070048 cpus_setall(desc->affinity);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070049#endif
50 spin_unlock_irqrestore(&desc->lock, flags);
51}
52
53/**
54 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
55 * @irq: irq number to initialize
56 */
57void dynamic_irq_cleanup(unsigned int irq)
58{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020059 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070060 unsigned long flags;
61
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070062 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070063 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070064 return;
65 }
66
Eric W. Biederman3a16d712006-10-04 02:16:37 -070067 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070068 if (desc->action) {
69 spin_unlock_irqrestore(&desc->lock, flags);
Arjan van de Ven261c40c2008-07-25 19:45:37 -070070 WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
Eric W. Biederman1f800252006-10-04 02:16:56 -070071 irq);
Eric W. Biederman1f800252006-10-04 02:16:56 -070072 return;
73 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070074 desc->msi_desc = NULL;
75 desc->handler_data = NULL;
76 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070077 desc->handle_irq = handle_bad_irq;
78 desc->chip = &no_irq_chip;
79 spin_unlock_irqrestore(&desc->lock, flags);
80}
81
82
83/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070084 * set_irq_chip - set the irq chip for an irq
85 * @irq: irq number
86 * @chip: pointer to irq chip description structure
87 */
88int set_irq_chip(unsigned int irq, struct irq_chip *chip)
89{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020090 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070091 unsigned long flags;
92
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070093 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070094 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070095 return -EINVAL;
96 }
97
98 if (!chip)
99 chip = &no_irq_chip;
100
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700101 spin_lock_irqsave(&desc->lock, flags);
102 irq_chip_set_defaults(chip);
103 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700104 spin_unlock_irqrestore(&desc->lock, flags);
105
106 return 0;
107}
108EXPORT_SYMBOL(set_irq_chip);
109
110/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700111 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700112 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700113 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700114 */
115int set_irq_type(unsigned int irq, unsigned int type)
116{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200117 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700118 unsigned long flags;
119 int ret = -ENXIO;
120
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700121 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700122 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
123 return -ENODEV;
124 }
125
David Brownell0c5d1eb2008-10-01 14:46:18 -0700126 if (type == IRQ_TYPE_NONE)
127 return 0;
128
129 spin_lock_irqsave(&desc->lock, flags);
130 ret = __irq_set_trigger(desc, irq, flags);
131 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700132 return ret;
133}
134EXPORT_SYMBOL(set_irq_type);
135
136/**
137 * set_irq_data - set irq type data for an irq
138 * @irq: Interrupt number
139 * @data: Pointer to interrupt specific data
140 *
141 * Set the hardware irq controller data for an irq
142 */
143int set_irq_data(unsigned int irq, void *data)
144{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200145 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700146 unsigned long flags;
147
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700148 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700149 printk(KERN_ERR
150 "Trying to install controller data for IRQ%d\n", irq);
151 return -EINVAL;
152 }
153
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700154 spin_lock_irqsave(&desc->lock, flags);
155 desc->handler_data = data;
156 spin_unlock_irqrestore(&desc->lock, flags);
157 return 0;
158}
159EXPORT_SYMBOL(set_irq_data);
160
161/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700162 * set_irq_data - set irq type data for an irq
163 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800164 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700165 *
166 * Set the hardware irq controller data for an irq
167 */
168int set_irq_msi(unsigned int irq, struct msi_desc *entry)
169{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200170 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700171 unsigned long flags;
172
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700173 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700174 printk(KERN_ERR
175 "Trying to install msi data for IRQ%d\n", irq);
176 return -EINVAL;
177 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700178
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700179 spin_lock_irqsave(&desc->lock, flags);
180 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000181 if (entry)
182 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700183 spin_unlock_irqrestore(&desc->lock, flags);
184 return 0;
185}
186
187/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700188 * set_irq_chip_data - set irq chip data for an irq
189 * @irq: Interrupt number
190 * @data: Pointer to chip specific data
191 *
192 * Set the hardware irq chip data for an irq
193 */
194int set_irq_chip_data(unsigned int irq, void *data)
195{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200196 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700197 unsigned long flags;
198
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700199 if (!desc) {
200 printk(KERN_ERR
201 "Trying to install chip data for IRQ%d\n", irq);
202 return -EINVAL;
203 }
204
205 if (!desc->chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700206 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
207 return -EINVAL;
208 }
209
210 spin_lock_irqsave(&desc->lock, flags);
211 desc->chip_data = data;
212 spin_unlock_irqrestore(&desc->lock, flags);
213
214 return 0;
215}
216EXPORT_SYMBOL(set_irq_chip_data);
217
218/*
219 * default enable function
220 */
221static void default_enable(unsigned int irq)
222{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200223 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700224
225 desc->chip->unmask(irq);
226 desc->status &= ~IRQ_MASKED;
227}
228
229/*
230 * default disable function
231 */
232static void default_disable(unsigned int irq)
233{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700234}
235
236/*
237 * default startup function
238 */
239static unsigned int default_startup(unsigned int irq)
240{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200241 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700242
Yinghai Lu08678b02008-08-19 20:50:05 -0700243 desc->chip->enable(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700244 return 0;
245}
246
247/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100248 * default shutdown function
249 */
250static void default_shutdown(unsigned int irq)
251{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200252 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100253
254 desc->chip->mask(irq);
255 desc->status |= IRQ_MASKED;
256}
257
258/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700259 * Fixup enable/disable function pointers
260 */
261void irq_chip_set_defaults(struct irq_chip *chip)
262{
263 if (!chip->enable)
264 chip->enable = default_enable;
265 if (!chip->disable)
266 chip->disable = default_disable;
267 if (!chip->startup)
268 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100269 /*
270 * We use chip->disable, when the user provided its own. When
271 * we have default_disable set for chip->disable, then we need
272 * to use default_shutdown, otherwise the irq line is not
273 * disabled on free_irq():
274 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700275 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100276 chip->shutdown = chip->disable != default_disable ?
277 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700278 if (!chip->name)
279 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800280 if (!chip->end)
281 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700282}
283
284static inline void mask_ack_irq(struct irq_desc *desc, int irq)
285{
286 if (desc->chip->mask_ack)
287 desc->chip->mask_ack(irq);
288 else {
289 desc->chip->mask(irq);
290 desc->chip->ack(irq);
291 }
292}
293
294/**
295 * handle_simple_irq - Simple and software-decoded IRQs.
296 * @irq: the interrupt number
297 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700298 *
299 * Simple interrupts are either sent from a demultiplexing interrupt
300 * handler or come from hardware, where no interrupt hardware control
301 * is necessary.
302 *
303 * Note: The caller is expected to handle the ack, clear, mask and
304 * unmask issues if necessary.
305 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800306void
David Howells7d12e782006-10-05 14:55:46 +0100307handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700308{
309 struct irqaction *action;
310 irqreturn_t action_ret;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700311
312 spin_lock(&desc->lock);
313
314 if (unlikely(desc->status & IRQ_INPROGRESS))
315 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100316 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200317 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700318
319 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100320 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700321 goto out_unlock;
322
323 desc->status |= IRQ_INPROGRESS;
324 spin_unlock(&desc->lock);
325
David Howells7d12e782006-10-05 14:55:46 +0100326 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700327 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100328 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700329
330 spin_lock(&desc->lock);
331 desc->status &= ~IRQ_INPROGRESS;
332out_unlock:
333 spin_unlock(&desc->lock);
334}
335
336/**
337 * handle_level_irq - Level type irq handler
338 * @irq: the interrupt number
339 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700340 *
341 * Level type interrupts are active as long as the hardware line has
342 * the active level. This may require to mask the interrupt and unmask
343 * it after the associated handler has acknowledged the device, so the
344 * interrupt line is back to inactive.
345 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800346void
David Howells7d12e782006-10-05 14:55:46 +0100347handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700348{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700349 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);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200358 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700359
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{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700396 struct irqaction *action;
397 irqreturn_t action_ret;
398
399 spin_lock(&desc->lock);
400
401 if (unlikely(desc->status & IRQ_INPROGRESS))
402 goto out;
403
404 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200405 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700406
407 /*
408 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800409 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700410 */
411 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700412 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
413 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800414 if (desc->chip->mask)
415 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700416 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700417 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700418
419 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700420 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700421 spin_unlock(&desc->lock);
422
David Howells7d12e782006-10-05 14:55:46 +0100423 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700424 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100425 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700426
427 spin_lock(&desc->lock);
428 desc->status &= ~IRQ_INPROGRESS;
429out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700430 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700431
432 spin_unlock(&desc->lock);
433}
434
435/**
436 * handle_edge_irq - edge type IRQ handler
437 * @irq: the interrupt number
438 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700439 *
440 * Interrupt occures on the falling and/or rising edge of a hardware
441 * signal. The occurence is latched into the irq controller hardware
442 * and must be acked in order to be reenabled. After the ack another
443 * interrupt can happen on the same source even before the first one
444 * is handled by the assosiacted event handler. If this happens it
445 * might be necessary to disable (mask) the interrupt depending on the
446 * controller hardware. This requires to reenable the interrupt inside
447 * of the loop which handles the interrupts which have arrived while
448 * the handler was running. If all pending interrupts are handled, the
449 * loop is left.
450 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800451void
David Howells7d12e782006-10-05 14:55:46 +0100452handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700453{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700454 spin_lock(&desc->lock);
455
456 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
457
458 /*
459 * If we're currently running this IRQ, or its disabled,
460 * we shouldn't process the IRQ. Mark it pending, handle
461 * the necessary masking and go out
462 */
463 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
464 !desc->action)) {
465 desc->status |= (IRQ_PENDING | IRQ_MASKED);
466 mask_ack_irq(desc, irq);
467 goto out_unlock;
468 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200469 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700470
471 /* Start handling the irq */
472 desc->chip->ack(irq);
473
474 /* Mark the IRQ currently in progress.*/
475 desc->status |= IRQ_INPROGRESS;
476
477 do {
478 struct irqaction *action = desc->action;
479 irqreturn_t action_ret;
480
481 if (unlikely(!action)) {
482 desc->chip->mask(irq);
483 goto out_unlock;
484 }
485
486 /*
487 * When another irq arrived while we were handling
488 * one, we could have masked the irq.
489 * Renable it, if it was not disabled in meantime.
490 */
491 if (unlikely((desc->status &
492 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
493 (IRQ_PENDING | IRQ_MASKED))) {
494 desc->chip->unmask(irq);
495 desc->status &= ~IRQ_MASKED;
496 }
497
498 desc->status &= ~IRQ_PENDING;
499 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100500 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700501 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100502 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700503 spin_lock(&desc->lock);
504
505 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
506
507 desc->status &= ~IRQ_INPROGRESS;
508out_unlock:
509 spin_unlock(&desc->lock);
510}
511
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700512/**
513 * handle_percpu_IRQ - Per CPU local irq handler
514 * @irq: the interrupt number
515 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700516 *
517 * Per CPU interrupts on SMP machines without locking requirements
518 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800519void
David Howells7d12e782006-10-05 14:55:46 +0100520handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700521{
522 irqreturn_t action_ret;
523
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200524 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700525
526 if (desc->chip->ack)
527 desc->chip->ack(irq);
528
David Howells7d12e782006-10-05 14:55:46 +0100529 action_ret = handle_IRQ_event(irq, desc->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
533 if (desc->chip->eoi)
534 desc->chip->eoi(irq);
535}
536
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700537void
Ingo Molnara460e742006-10-17 00:10:03 -0700538__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
539 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700540{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200541 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700542 unsigned long flags;
543
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700544 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700545 printk(KERN_ERR
546 "Trying to install type control for IRQ%d\n", irq);
547 return;
548 }
549
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700550 if (!handle)
551 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800552 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100553 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100554 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100555 /*
556 * Some ARM implementations install a handler for really dumb
557 * interrupt hardware without setting an irq_chip. This worked
558 * with the ARM no_irq_chip but the check in setup_irq would
559 * prevent us to setup the interrupt at all. Switch it to
560 * dummy_irq_chip for easy transition.
561 */
562 desc->chip = &dummy_irq_chip;
563 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700564
565 spin_lock_irqsave(&desc->lock, flags);
566
567 /* Uninstall? */
568 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800569 if (desc->chip != &no_irq_chip)
570 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700571 desc->status |= IRQ_DISABLED;
572 desc->depth = 1;
573 }
574 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700575 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700576
577 if (handle != handle_bad_irq && is_chained) {
578 desc->status &= ~IRQ_DISABLED;
579 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
580 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100581 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700582 }
583 spin_unlock_irqrestore(&desc->lock, flags);
584}
585
586void
587set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100588 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700589{
590 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700591 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700592}
593
Ingo Molnara460e742006-10-17 00:10:03 -0700594void
595set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
596 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700597{
Ingo Molnara460e742006-10-17 00:10:03 -0700598 set_irq_chip(irq, chip);
599 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700600}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800601
602void __init set_irq_noprobe(unsigned int irq)
603{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200604 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800605 unsigned long flags;
606
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700607 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800608 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800609 return;
610 }
611
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800612 spin_lock_irqsave(&desc->lock, flags);
613 desc->status |= IRQ_NOPROBE;
614 spin_unlock_irqrestore(&desc->lock, flags);
615}
616
617void __init set_irq_probe(unsigned int irq)
618{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200619 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800620 unsigned long flags;
621
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700622 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800623 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800624 return;
625 }
626
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800627 spin_lock_irqsave(&desc->lock, flags);
628 desc->status &= ~IRQ_NOPROBE;
629 spin_unlock_irqrestore(&desc->lock, flags);
630}