blob: 10b5092e9bfe749da57b2ab408e3f6d38ae81d75 [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;
Dean Nelsonb6f3b782008-10-18 16:06:56 -070079 desc->name = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070080 spin_unlock_irqrestore(&desc->lock, flags);
81}
82
83
84/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070085 * set_irq_chip - set the irq chip for an irq
86 * @irq: irq number
87 * @chip: pointer to irq chip description structure
88 */
89int set_irq_chip(unsigned int irq, struct irq_chip *chip)
90{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020091 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070092 unsigned long flags;
93
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070094 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070095 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070096 return -EINVAL;
97 }
98
99 if (!chip)
100 chip = &no_irq_chip;
101
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700102 spin_lock_irqsave(&desc->lock, flags);
103 irq_chip_set_defaults(chip);
104 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700105 spin_unlock_irqrestore(&desc->lock, flags);
106
107 return 0;
108}
109EXPORT_SYMBOL(set_irq_chip);
110
111/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700112 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700113 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700114 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700115 */
116int set_irq_type(unsigned int irq, unsigned int type)
117{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200118 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700119 unsigned long flags;
120 int ret = -ENXIO;
121
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700122 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700123 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
124 return -ENODEV;
125 }
126
David Brownell0c5d1eb2008-10-01 14:46:18 -0700127 if (type == IRQ_TYPE_NONE)
128 return 0;
129
130 spin_lock_irqsave(&desc->lock, flags);
Chris Friesen0b3682ba32008-10-20 12:41:58 -0600131 ret = __irq_set_trigger(desc, irq, type);
David Brownell0c5d1eb2008-10-01 14:46:18 -0700132 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700133 return ret;
134}
135EXPORT_SYMBOL(set_irq_type);
136
137/**
138 * set_irq_data - set irq type data for an irq
139 * @irq: Interrupt number
140 * @data: Pointer to interrupt specific data
141 *
142 * Set the hardware irq controller data for an irq
143 */
144int set_irq_data(unsigned int irq, void *data)
145{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200146 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700147 unsigned long flags;
148
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700149 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700150 printk(KERN_ERR
151 "Trying to install controller data for IRQ%d\n", irq);
152 return -EINVAL;
153 }
154
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700155 spin_lock_irqsave(&desc->lock, flags);
156 desc->handler_data = data;
157 spin_unlock_irqrestore(&desc->lock, flags);
158 return 0;
159}
160EXPORT_SYMBOL(set_irq_data);
161
162/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700163 * set_irq_data - set irq type data for an irq
164 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800165 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700166 *
167 * Set the hardware irq controller data for an irq
168 */
169int set_irq_msi(unsigned int irq, struct msi_desc *entry)
170{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200171 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700172 unsigned long flags;
173
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700174 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700175 printk(KERN_ERR
176 "Trying to install msi data for IRQ%d\n", irq);
177 return -EINVAL;
178 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700179
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700180 spin_lock_irqsave(&desc->lock, flags);
181 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000182 if (entry)
183 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700184 spin_unlock_irqrestore(&desc->lock, flags);
185 return 0;
186}
187
188/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700189 * set_irq_chip_data - set irq chip data for an irq
190 * @irq: Interrupt number
191 * @data: Pointer to chip specific data
192 *
193 * Set the hardware irq chip data for an irq
194 */
195int set_irq_chip_data(unsigned int irq, void *data)
196{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200197 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700198 unsigned long flags;
199
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700200 if (!desc) {
201 printk(KERN_ERR
202 "Trying to install chip data for IRQ%d\n", irq);
203 return -EINVAL;
204 }
205
206 if (!desc->chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700207 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
208 return -EINVAL;
209 }
210
211 spin_lock_irqsave(&desc->lock, flags);
212 desc->chip_data = data;
213 spin_unlock_irqrestore(&desc->lock, flags);
214
215 return 0;
216}
217EXPORT_SYMBOL(set_irq_chip_data);
218
219/*
220 * default enable function
221 */
222static void default_enable(unsigned int irq)
223{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200224 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700225
226 desc->chip->unmask(irq);
227 desc->status &= ~IRQ_MASKED;
228}
229
230/*
231 * default disable function
232 */
233static void default_disable(unsigned int irq)
234{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700235}
236
237/*
238 * default startup function
239 */
240static unsigned int default_startup(unsigned int irq)
241{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200242 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700243
Yinghai Lu08678b02008-08-19 20:50:05 -0700244 desc->chip->enable(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700245 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{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200253 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100254
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;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700312
313 spin_lock(&desc->lock);
314
315 if (unlikely(desc->status & IRQ_INPROGRESS))
316 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100317 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200318 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700319
320 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100321 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700322 goto out_unlock;
323
324 desc->status |= IRQ_INPROGRESS;
325 spin_unlock(&desc->lock);
326
David Howells7d12e782006-10-05 14:55:46 +0100327 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700328 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100329 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700330
331 spin_lock(&desc->lock);
332 desc->status &= ~IRQ_INPROGRESS;
333out_unlock:
334 spin_unlock(&desc->lock);
335}
336
337/**
338 * handle_level_irq - Level type irq handler
339 * @irq: the interrupt number
340 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700341 *
342 * Level type interrupts are active as long as the hardware line has
343 * the active level. This may require to mask the interrupt and unmask
344 * it after the associated handler has acknowledged the device, so the
345 * interrupt line is back to inactive.
346 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800347void
David Howells7d12e782006-10-05 14:55:46 +0100348handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700349{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700350 struct irqaction *action;
351 irqreturn_t action_ret;
352
353 spin_lock(&desc->lock);
354 mask_ack_irq(desc, irq);
355
356 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200357 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700358 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200359 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700360
361 /*
362 * If its disabled or no action available
363 * keep it masked and get out of here
364 */
365 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000366 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200367 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700368
369 desc->status |= IRQ_INPROGRESS;
370 spin_unlock(&desc->lock);
371
David Howells7d12e782006-10-05 14:55:46 +0100372 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700373 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100374 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700375
376 spin_lock(&desc->lock);
377 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700378 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
379 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200380out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700381 spin_unlock(&desc->lock);
382}
383
384/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700385 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700386 * @irq: the interrupt number
387 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700388 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700389 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700390 * call when the interrupt has been serviced. This enables support
391 * for modern forms of interrupt handlers, which handle the flow
392 * details in hardware, transparently.
393 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800394void
David Howells7d12e782006-10-05 14:55:46 +0100395handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700396{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700397 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);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200406 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700407
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{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700455 spin_lock(&desc->lock);
456
457 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
458
459 /*
460 * If we're currently running this IRQ, or its disabled,
461 * we shouldn't process the IRQ. Mark it pending, handle
462 * the necessary masking and go out
463 */
464 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
465 !desc->action)) {
466 desc->status |= (IRQ_PENDING | IRQ_MASKED);
467 mask_ack_irq(desc, irq);
468 goto out_unlock;
469 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200470 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700471
472 /* Start handling the irq */
473 desc->chip->ack(irq);
474
475 /* Mark the IRQ currently in progress.*/
476 desc->status |= IRQ_INPROGRESS;
477
478 do {
479 struct irqaction *action = desc->action;
480 irqreturn_t action_ret;
481
482 if (unlikely(!action)) {
483 desc->chip->mask(irq);
484 goto out_unlock;
485 }
486
487 /*
488 * When another irq arrived while we were handling
489 * one, we could have masked the irq.
490 * Renable it, if it was not disabled in meantime.
491 */
492 if (unlikely((desc->status &
493 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
494 (IRQ_PENDING | IRQ_MASKED))) {
495 desc->chip->unmask(irq);
496 desc->status &= ~IRQ_MASKED;
497 }
498
499 desc->status &= ~IRQ_PENDING;
500 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100501 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700502 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100503 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700504 spin_lock(&desc->lock);
505
506 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
507
508 desc->status &= ~IRQ_INPROGRESS;
509out_unlock:
510 spin_unlock(&desc->lock);
511}
512
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700513/**
514 * handle_percpu_IRQ - Per CPU local irq handler
515 * @irq: the interrupt number
516 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700517 *
518 * Per CPU interrupts on SMP machines without locking requirements
519 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800520void
David Howells7d12e782006-10-05 14:55:46 +0100521handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700522{
523 irqreturn_t action_ret;
524
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200525 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700526
527 if (desc->chip->ack)
528 desc->chip->ack(irq);
529
David Howells7d12e782006-10-05 14:55:46 +0100530 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700531 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100532 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700533
534 if (desc->chip->eoi)
535 desc->chip->eoi(irq);
536}
537
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700538void
Ingo Molnara460e742006-10-17 00:10:03 -0700539__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
540 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700541{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200542 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700543 unsigned long flags;
544
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700545 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700546 printk(KERN_ERR
547 "Trying to install type control for IRQ%d\n", irq);
548 return;
549 }
550
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700551 if (!handle)
552 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800553 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100554 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100555 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100556 /*
557 * Some ARM implementations install a handler for really dumb
558 * interrupt hardware without setting an irq_chip. This worked
559 * with the ARM no_irq_chip but the check in setup_irq would
560 * prevent us to setup the interrupt at all. Switch it to
561 * dummy_irq_chip for easy transition.
562 */
563 desc->chip = &dummy_irq_chip;
564 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700565
566 spin_lock_irqsave(&desc->lock, flags);
567
568 /* Uninstall? */
569 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800570 if (desc->chip != &no_irq_chip)
571 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700572 desc->status |= IRQ_DISABLED;
573 desc->depth = 1;
574 }
575 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700576 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700577
578 if (handle != handle_bad_irq && is_chained) {
579 desc->status &= ~IRQ_DISABLED;
580 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
581 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100582 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700583 }
584 spin_unlock_irqrestore(&desc->lock, flags);
585}
586
587void
588set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100589 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700590{
591 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700592 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700593}
594
Ingo Molnara460e742006-10-17 00:10:03 -0700595void
596set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
597 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700598{
Ingo Molnara460e742006-10-17 00:10:03 -0700599 set_irq_chip(irq, chip);
600 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700601}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800602
603void __init set_irq_noprobe(unsigned int irq)
604{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200605 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800606 unsigned long flags;
607
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700608 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800609 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800610 return;
611 }
612
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800613 spin_lock_irqsave(&desc->lock, flags);
614 desc->status |= IRQ_NOPROBE;
615 spin_unlock_irqrestore(&desc->lock, flags);
616}
617
618void __init set_irq_probe(unsigned int irq)
619{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200620 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800621 unsigned long flags;
622
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700623 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800624 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800625 return;
626 }
627
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800628 spin_lock_irqsave(&desc->lock, flags);
629 desc->status &= ~IRQ_NOPROBE;
630 spin_unlock_irqrestore(&desc->lock, flags);
631}