blob: e6f73dbfcc3deb946e51e13eac194754675b76a2 [file] [log] [blame]
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -07001/*
2 * linux/kernel/irq/chip.c
3 *
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
6 *
7 * This file contains the core interrupt handling code, for irq-chip
8 * based architectures.
9 *
10 * Detailed information is available in Documentation/DocBook/genericirq
11 */
12
13#include <linux/irq.h>
Michael Ellerman7fe37302007-04-18 19:39:21 +100014#include <linux/msi.h>
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070015#include <linux/module.h>
16#include <linux/interrupt.h>
17#include <linux/kernel_stat.h>
18
19#include "internals.h"
20
21/**
Eric W. Biederman3a16d712006-10-04 02:16:37 -070022 * dynamic_irq_init - initialize a dynamically allocated irq
23 * @irq: irq number to initialize
24 */
25void dynamic_irq_init(unsigned int irq)
26{
27 struct irq_desc *desc;
28 unsigned long flags;
29
Yinghai Lucb5bc832008-08-19 20:50:17 -070030 /* first time to use this irq_desc */
Thomas Gleixneree32c972008-10-15 14:34:09 +020031 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070032 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070033 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070034 return;
35 }
36
37 /* Ensure we don't have left over values from a previous use of this irq */
Eric W. Biederman3a16d712006-10-04 02:16:37 -070038 spin_lock_irqsave(&desc->lock, flags);
39 desc->status = IRQ_DISABLED;
40 desc->chip = &no_irq_chip;
41 desc->handle_irq = handle_bad_irq;
42 desc->depth = 1;
Eric W. Biederman5b912c12007-01-28 12:52:03 -070043 desc->msi_desc = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070044 desc->handler_data = NULL;
45 desc->chip_data = NULL;
46 desc->action = NULL;
47 desc->irq_count = 0;
48 desc->irqs_unhandled = 0;
49#ifdef CONFIG_SMP
Mike Travisd366f8c2008-04-04 18:11:12 -070050 cpus_setall(desc->affinity);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070051#endif
52 spin_unlock_irqrestore(&desc->lock, flags);
53}
54
55/**
56 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
57 * @irq: irq number to initialize
58 */
59void dynamic_irq_cleanup(unsigned int irq)
60{
61 struct irq_desc *desc;
62 unsigned long flags;
63
Yinghai Lucb5bc832008-08-19 20:50:17 -070064 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070065 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070066 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070067 return;
68 }
69
Eric W. Biederman3a16d712006-10-04 02:16:37 -070070 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070071 if (desc->action) {
72 spin_unlock_irqrestore(&desc->lock, flags);
Arjan van de Ven261c40c2008-07-25 19:45:37 -070073 WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
Eric W. Biederman1f800252006-10-04 02:16:56 -070074 irq);
Eric W. Biederman1f800252006-10-04 02:16:56 -070075 return;
76 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070077 desc->msi_desc = NULL;
78 desc->handler_data = NULL;
79 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070080 desc->handle_irq = handle_bad_irq;
81 desc->chip = &no_irq_chip;
82 spin_unlock_irqrestore(&desc->lock, flags);
83}
84
85
86/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070087 * set_irq_chip - set the irq chip for an irq
88 * @irq: irq number
89 * @chip: pointer to irq chip description structure
90 */
91int set_irq_chip(unsigned int irq, struct irq_chip *chip)
92{
93 struct irq_desc *desc;
94 unsigned long flags;
95
Yinghai Lucb5bc832008-08-19 20:50:17 -070096 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070097 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070098 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070099 return -EINVAL;
100 }
101
102 if (!chip)
103 chip = &no_irq_chip;
104
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700105 spin_lock_irqsave(&desc->lock, flags);
106 irq_chip_set_defaults(chip);
107 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700108 spin_unlock_irqrestore(&desc->lock, flags);
109
110 return 0;
111}
112EXPORT_SYMBOL(set_irq_chip);
113
114/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700115 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700116 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700117 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700118 */
119int set_irq_type(unsigned int irq, unsigned int type)
120{
121 struct irq_desc *desc;
122 unsigned long flags;
123 int ret = -ENXIO;
124
Yinghai Lucb5bc832008-08-19 20:50:17 -0700125 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700126 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700127 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
128 return -ENODEV;
129 }
130
David Brownell0c5d1eb2008-10-01 14:46:18 -0700131 if (type == IRQ_TYPE_NONE)
132 return 0;
133
134 spin_lock_irqsave(&desc->lock, flags);
135 ret = __irq_set_trigger(desc, irq, flags);
136 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700137 return ret;
138}
139EXPORT_SYMBOL(set_irq_type);
140
141/**
142 * set_irq_data - set irq type data for an irq
143 * @irq: Interrupt number
144 * @data: Pointer to interrupt specific data
145 *
146 * Set the hardware irq controller data for an irq
147 */
148int set_irq_data(unsigned int irq, void *data)
149{
150 struct irq_desc *desc;
151 unsigned long flags;
152
Yinghai Lucb5bc832008-08-19 20:50:17 -0700153 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700154 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700155 printk(KERN_ERR
156 "Trying to install controller data for IRQ%d\n", irq);
157 return -EINVAL;
158 }
159
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700160 spin_lock_irqsave(&desc->lock, flags);
161 desc->handler_data = data;
162 spin_unlock_irqrestore(&desc->lock, flags);
163 return 0;
164}
165EXPORT_SYMBOL(set_irq_data);
166
167/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700168 * set_irq_data - set irq type data for an irq
169 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800170 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700171 *
172 * Set the hardware irq controller data for an irq
173 */
174int set_irq_msi(unsigned int irq, struct msi_desc *entry)
175{
176 struct irq_desc *desc;
177 unsigned long flags;
178
Yinghai Lucb5bc832008-08-19 20:50:17 -0700179 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700180 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700181 printk(KERN_ERR
182 "Trying to install msi data for IRQ%d\n", irq);
183 return -EINVAL;
184 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700185
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700186 spin_lock_irqsave(&desc->lock, flags);
187 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000188 if (entry)
189 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700190 spin_unlock_irqrestore(&desc->lock, flags);
191 return 0;
192}
193
194/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700195 * set_irq_chip_data - set irq chip data for an irq
196 * @irq: Interrupt number
197 * @data: Pointer to chip specific data
198 *
199 * Set the hardware irq chip data for an irq
200 */
201int set_irq_chip_data(unsigned int irq, void *data)
202{
Yinghai Lu08678b02008-08-19 20:50:05 -0700203 struct irq_desc *desc;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700204 unsigned long flags;
205
Yinghai Lucb5bc832008-08-19 20:50:17 -0700206 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700207 if (!desc) {
208 printk(KERN_ERR
209 "Trying to install chip data for IRQ%d\n", irq);
210 return -EINVAL;
211 }
212
213 if (!desc->chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700214 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
215 return -EINVAL;
216 }
217
218 spin_lock_irqsave(&desc->lock, flags);
219 desc->chip_data = data;
220 spin_unlock_irqrestore(&desc->lock, flags);
221
222 return 0;
223}
224EXPORT_SYMBOL(set_irq_chip_data);
225
226/*
227 * default enable function
228 */
229static void default_enable(unsigned int irq)
230{
Yinghai Lu08678b02008-08-19 20:50:05 -0700231 struct irq_desc *desc;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700232
Yinghai Lu08678b02008-08-19 20:50:05 -0700233 desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700234 desc->chip->unmask(irq);
235 desc->status &= ~IRQ_MASKED;
236}
237
238/*
239 * default disable function
240 */
241static void default_disable(unsigned int irq)
242{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700243}
244
245/*
246 * default startup function
247 */
248static unsigned int default_startup(unsigned int irq)
249{
Yinghai Lu08678b02008-08-19 20:50:05 -0700250 struct irq_desc *desc;
251
252 desc = irq_to_desc(irq);
253 desc->chip->enable(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700254
255 return 0;
256}
257
258/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100259 * default shutdown function
260 */
261static void default_shutdown(unsigned int irq)
262{
Yinghai Lu08678b02008-08-19 20:50:05 -0700263 struct irq_desc *desc;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100264
Yinghai Lu08678b02008-08-19 20:50:05 -0700265 desc = irq_to_desc(irq);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100266 desc->chip->mask(irq);
267 desc->status |= IRQ_MASKED;
268}
269
270/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700271 * Fixup enable/disable function pointers
272 */
273void irq_chip_set_defaults(struct irq_chip *chip)
274{
275 if (!chip->enable)
276 chip->enable = default_enable;
277 if (!chip->disable)
278 chip->disable = default_disable;
279 if (!chip->startup)
280 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100281 /*
282 * We use chip->disable, when the user provided its own. When
283 * we have default_disable set for chip->disable, then we need
284 * to use default_shutdown, otherwise the irq line is not
285 * disabled on free_irq():
286 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700287 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100288 chip->shutdown = chip->disable != default_disable ?
289 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700290 if (!chip->name)
291 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800292 if (!chip->end)
293 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700294}
295
296static inline void mask_ack_irq(struct irq_desc *desc, int irq)
297{
298 if (desc->chip->mask_ack)
299 desc->chip->mask_ack(irq);
300 else {
301 desc->chip->mask(irq);
302 desc->chip->ack(irq);
303 }
304}
305
306/**
307 * handle_simple_irq - Simple and software-decoded IRQs.
308 * @irq: the interrupt number
309 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700310 *
311 * Simple interrupts are either sent from a demultiplexing interrupt
312 * handler or come from hardware, where no interrupt hardware control
313 * is necessary.
314 *
315 * Note: The caller is expected to handle the ack, clear, mask and
316 * unmask issues if necessary.
317 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800318void
David Howells7d12e782006-10-05 14:55:46 +0100319handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700320{
321 struct irqaction *action;
322 irqreturn_t action_ret;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700323
324 spin_lock(&desc->lock);
325
326 if (unlikely(desc->status & IRQ_INPROGRESS))
327 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100328 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700329#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700330 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700331#else
332 kstat_irqs_this_cpu(irq)++;
333#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700334
335 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100336 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700337 goto out_unlock;
338
339 desc->status |= IRQ_INPROGRESS;
340 spin_unlock(&desc->lock);
341
David Howells7d12e782006-10-05 14:55:46 +0100342 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700343 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100344 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700345
346 spin_lock(&desc->lock);
347 desc->status &= ~IRQ_INPROGRESS;
348out_unlock:
349 spin_unlock(&desc->lock);
350}
351
352/**
353 * handle_level_irq - Level type irq handler
354 * @irq: the interrupt number
355 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700356 *
357 * Level type interrupts are active as long as the hardware line has
358 * the active level. This may require to mask the interrupt and unmask
359 * it after the associated handler has acknowledged the device, so the
360 * interrupt line is back to inactive.
361 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800362void
David Howells7d12e782006-10-05 14:55:46 +0100363handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700364{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700365 struct irqaction *action;
366 irqreturn_t action_ret;
367
368 spin_lock(&desc->lock);
369 mask_ack_irq(desc, irq);
370
371 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200372 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700373 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700374#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700375 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700376#else
377 kstat_irqs_this_cpu(irq)++;
378#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700379
380 /*
381 * If its disabled or no action available
382 * keep it masked and get out of here
383 */
384 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000385 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200386 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700387
388 desc->status |= IRQ_INPROGRESS;
389 spin_unlock(&desc->lock);
390
David Howells7d12e782006-10-05 14:55:46 +0100391 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700392 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100393 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700394
395 spin_lock(&desc->lock);
396 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700397 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
398 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200399out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700400 spin_unlock(&desc->lock);
401}
402
403/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700404 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700405 * @irq: the interrupt number
406 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700407 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700408 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700409 * call when the interrupt has been serviced. This enables support
410 * for modern forms of interrupt handlers, which handle the flow
411 * details in hardware, transparently.
412 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800413void
David Howells7d12e782006-10-05 14:55:46 +0100414handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700415{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700416 struct irqaction *action;
417 irqreturn_t action_ret;
418
419 spin_lock(&desc->lock);
420
421 if (unlikely(desc->status & IRQ_INPROGRESS))
422 goto out;
423
424 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Yinghai Lu8c464a42008-08-25 12:41:19 -0700425#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700426 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700427#else
428 kstat_irqs_this_cpu(irq)++;
429#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700430
431 /*
432 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800433 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700434 */
435 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700436 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
437 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800438 if (desc->chip->mask)
439 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700440 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700441 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700442
443 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700444 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700445 spin_unlock(&desc->lock);
446
David Howells7d12e782006-10-05 14:55:46 +0100447 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700448 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100449 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700450
451 spin_lock(&desc->lock);
452 desc->status &= ~IRQ_INPROGRESS;
453out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700454 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700455
456 spin_unlock(&desc->lock);
457}
458
459/**
460 * handle_edge_irq - edge type IRQ handler
461 * @irq: the interrupt number
462 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700463 *
464 * Interrupt occures on the falling and/or rising edge of a hardware
465 * signal. The occurence is latched into the irq controller hardware
466 * and must be acked in order to be reenabled. After the ack another
467 * interrupt can happen on the same source even before the first one
468 * is handled by the assosiacted event handler. If this happens it
469 * might be necessary to disable (mask) the interrupt depending on the
470 * controller hardware. This requires to reenable the interrupt inside
471 * of the loop which handles the interrupts which have arrived while
472 * the handler was running. If all pending interrupts are handled, the
473 * loop is left.
474 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800475void
David Howells7d12e782006-10-05 14:55:46 +0100476handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700477{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700478 spin_lock(&desc->lock);
479
480 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
481
482 /*
483 * If we're currently running this IRQ, or its disabled,
484 * we shouldn't process the IRQ. Mark it pending, handle
485 * the necessary masking and go out
486 */
487 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
488 !desc->action)) {
489 desc->status |= (IRQ_PENDING | IRQ_MASKED);
490 mask_ack_irq(desc, irq);
491 goto out_unlock;
492 }
Yinghai Lu8c464a42008-08-25 12:41:19 -0700493#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700494 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700495#else
496 kstat_irqs_this_cpu(irq)++;
497#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700498
499 /* Start handling the irq */
500 desc->chip->ack(irq);
501
502 /* Mark the IRQ currently in progress.*/
503 desc->status |= IRQ_INPROGRESS;
504
505 do {
506 struct irqaction *action = desc->action;
507 irqreturn_t action_ret;
508
509 if (unlikely(!action)) {
510 desc->chip->mask(irq);
511 goto out_unlock;
512 }
513
514 /*
515 * When another irq arrived while we were handling
516 * one, we could have masked the irq.
517 * Renable it, if it was not disabled in meantime.
518 */
519 if (unlikely((desc->status &
520 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
521 (IRQ_PENDING | IRQ_MASKED))) {
522 desc->chip->unmask(irq);
523 desc->status &= ~IRQ_MASKED;
524 }
525
526 desc->status &= ~IRQ_PENDING;
527 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100528 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700529 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100530 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700531 spin_lock(&desc->lock);
532
533 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
534
535 desc->status &= ~IRQ_INPROGRESS;
536out_unlock:
537 spin_unlock(&desc->lock);
538}
539
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700540/**
541 * handle_percpu_IRQ - Per CPU local irq handler
542 * @irq: the interrupt number
543 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544 *
545 * Per CPU interrupts on SMP machines without locking requirements
546 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800547void
David Howells7d12e782006-10-05 14:55:46 +0100548handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700549{
550 irqreturn_t action_ret;
551
Yinghai Lu8c464a42008-08-25 12:41:19 -0700552#ifdef CONFIG_HAVE_DYN_ARRAY
Yinghai Lu7f95ec92008-08-19 20:50:09 -0700553 kstat_irqs_this_cpu(desc)++;
Yinghai Lu8c464a42008-08-25 12:41:19 -0700554#else
555 kstat_irqs_this_cpu(irq)++;
556#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700557
558 if (desc->chip->ack)
559 desc->chip->ack(irq);
560
David Howells7d12e782006-10-05 14:55:46 +0100561 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700562 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100563 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700564
565 if (desc->chip->eoi)
566 desc->chip->eoi(irq);
567}
568
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700569void
Ingo Molnara460e742006-10-17 00:10:03 -0700570__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
571 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700572{
573 struct irq_desc *desc;
574 unsigned long flags;
575
Yinghai Lucb5bc832008-08-19 20:50:17 -0700576 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700577 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700578 printk(KERN_ERR
579 "Trying to install type control for IRQ%d\n", irq);
580 return;
581 }
582
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700583 if (!handle)
584 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800585 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100586 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100587 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100588 /*
589 * Some ARM implementations install a handler for really dumb
590 * interrupt hardware without setting an irq_chip. This worked
591 * with the ARM no_irq_chip but the check in setup_irq would
592 * prevent us to setup the interrupt at all. Switch it to
593 * dummy_irq_chip for easy transition.
594 */
595 desc->chip = &dummy_irq_chip;
596 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700597
598 spin_lock_irqsave(&desc->lock, flags);
599
600 /* Uninstall? */
601 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800602 if (desc->chip != &no_irq_chip)
603 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700604 desc->status |= IRQ_DISABLED;
605 desc->depth = 1;
606 }
607 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700608 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609
610 if (handle != handle_bad_irq && is_chained) {
611 desc->status &= ~IRQ_DISABLED;
612 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
613 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100614 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700615 }
616 spin_unlock_irqrestore(&desc->lock, flags);
617}
618
619void
620set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100621 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700622{
623 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700624 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700625}
626
Ingo Molnara460e742006-10-17 00:10:03 -0700627void
628set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
629 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700630{
Ingo Molnara460e742006-10-17 00:10:03 -0700631 set_irq_chip(irq, chip);
632 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700633}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800634
635void __init set_irq_noprobe(unsigned int irq)
636{
637 struct irq_desc *desc;
638 unsigned long flags;
639
Yinghai Lucb5bc832008-08-19 20:50:17 -0700640 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700641 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800642 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
643
644 return;
645 }
646
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800647 spin_lock_irqsave(&desc->lock, flags);
648 desc->status |= IRQ_NOPROBE;
649 spin_unlock_irqrestore(&desc->lock, flags);
650}
651
652void __init set_irq_probe(unsigned int irq)
653{
654 struct irq_desc *desc;
655 unsigned long flags;
656
Yinghai Lucb5bc832008-08-19 20:50:17 -0700657 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700658 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800659 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
660
661 return;
662 }
663
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800664 spin_lock_irqsave(&desc->lock, flags);
665 desc->status &= ~IRQ_NOPROBE;
666 spin_unlock_irqrestore(&desc->lock, flags);
667}