blob: 8e4fce4a1b1fbb3491094b6615b26a4ee0c4fe07 [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{
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080027 struct irq_desc *desc;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070028 unsigned long flags;
29
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080030 desc = irq_to_desc(irq);
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070031 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070032 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070033 return;
34 }
35
36 /* Ensure we don't have left over values from a previous use of this irq */
Eric W. Biederman3a16d712006-10-04 02:16:37 -070037 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{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020060 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman3a16d712006-10-04 02:16:37 -070061 unsigned long flags;
62
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070063 if (!desc) {
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
Eric W. Biederman3a16d712006-10-04 02:16:37 -070068 spin_lock_irqsave(&desc->lock, flags);
Eric W. Biederman1f800252006-10-04 02:16:56 -070069 if (desc->action) {
70 spin_unlock_irqrestore(&desc->lock, flags);
Arjan van de Ven261c40c2008-07-25 19:45:37 -070071 WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
Eric W. Biederman1f800252006-10-04 02:16:56 -070072 irq);
Eric W. Biederman1f800252006-10-04 02:16:56 -070073 return;
74 }
Eric W. Biederman5b912c12007-01-28 12:52:03 -070075 desc->msi_desc = NULL;
76 desc->handler_data = NULL;
77 desc->chip_data = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070078 desc->handle_irq = handle_bad_irq;
79 desc->chip = &no_irq_chip;
Dean Nelsonb6f3b782008-10-18 16:06:56 -070080 desc->name = NULL;
Eric W. Biederman3a16d712006-10-04 02:16:37 -070081 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{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020092 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070093 unsigned long flags;
94
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070095 if (!desc) {
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
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700103 spin_lock_irqsave(&desc->lock, flags);
104 irq_chip_set_defaults(chip);
105 desc->chip = chip;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700106 spin_unlock_irqrestore(&desc->lock, flags);
107
108 return 0;
109}
110EXPORT_SYMBOL(set_irq_chip);
111
112/**
David Brownell0c5d1eb2008-10-01 14:46:18 -0700113 * set_irq_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700114 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -0700115 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700116 */
117int set_irq_type(unsigned int irq, unsigned int type)
118{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200119 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700120 unsigned long flags;
121 int ret = -ENXIO;
122
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700123 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700124 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
125 return -ENODEV;
126 }
127
David Brownell0c5d1eb2008-10-01 14:46:18 -0700128 if (type == IRQ_TYPE_NONE)
129 return 0;
130
131 spin_lock_irqsave(&desc->lock, flags);
Chris Friesen0b3682ba32008-10-20 12:41:58 -0600132 ret = __irq_set_trigger(desc, irq, type);
David Brownell0c5d1eb2008-10-01 14:46:18 -0700133 spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700134 return ret;
135}
136EXPORT_SYMBOL(set_irq_type);
137
138/**
139 * set_irq_data - set irq type data for an irq
140 * @irq: Interrupt number
141 * @data: Pointer to interrupt specific data
142 *
143 * Set the hardware irq controller data for an irq
144 */
145int set_irq_data(unsigned int irq, void *data)
146{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200147 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700148 unsigned long flags;
149
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700150 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700151 printk(KERN_ERR
152 "Trying to install controller data for IRQ%d\n", irq);
153 return -EINVAL;
154 }
155
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700156 spin_lock_irqsave(&desc->lock, flags);
157 desc->handler_data = data;
158 spin_unlock_irqrestore(&desc->lock, flags);
159 return 0;
160}
161EXPORT_SYMBOL(set_irq_data);
162
163/**
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700164 * set_irq_data - set irq type data for an irq
165 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800166 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700167 *
168 * Set the hardware irq controller data for an irq
169 */
170int set_irq_msi(unsigned int irq, struct msi_desc *entry)
171{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200172 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700173 unsigned long flags;
174
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700175 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700176 printk(KERN_ERR
177 "Trying to install msi data for IRQ%d\n", irq);
178 return -EINVAL;
179 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700180
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700181 spin_lock_irqsave(&desc->lock, flags);
182 desc->msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000183 if (entry)
184 entry->irq = irq;
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700185 spin_unlock_irqrestore(&desc->lock, flags);
186 return 0;
187}
188
189/**
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700190 * set_irq_chip_data - set irq chip data for an irq
191 * @irq: Interrupt number
192 * @data: Pointer to chip specific data
193 *
194 * Set the hardware irq chip data for an irq
195 */
196int set_irq_chip_data(unsigned int irq, void *data)
197{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200198 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700199 unsigned long flags;
200
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700201 if (!desc) {
202 printk(KERN_ERR
203 "Trying to install chip data for IRQ%d\n", irq);
204 return -EINVAL;
205 }
206
207 if (!desc->chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700208 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
209 return -EINVAL;
210 }
211
212 spin_lock_irqsave(&desc->lock, flags);
213 desc->chip_data = data;
214 spin_unlock_irqrestore(&desc->lock, flags);
215
216 return 0;
217}
218EXPORT_SYMBOL(set_irq_chip_data);
219
220/*
221 * default enable function
222 */
223static void default_enable(unsigned int irq)
224{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200225 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700226
227 desc->chip->unmask(irq);
228 desc->status &= ~IRQ_MASKED;
229}
230
231/*
232 * default disable function
233 */
234static void default_disable(unsigned int irq)
235{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700236}
237
238/*
239 * default startup function
240 */
241static unsigned int default_startup(unsigned int irq)
242{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200243 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700244
Yinghai Lu08678b02008-08-19 20:50:05 -0700245 desc->chip->enable(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700246 return 0;
247}
248
249/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100250 * default shutdown function
251 */
252static void default_shutdown(unsigned int irq)
253{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200254 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100255
256 desc->chip->mask(irq);
257 desc->status |= IRQ_MASKED;
258}
259
260/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700261 * Fixup enable/disable function pointers
262 */
263void irq_chip_set_defaults(struct irq_chip *chip)
264{
265 if (!chip->enable)
266 chip->enable = default_enable;
267 if (!chip->disable)
268 chip->disable = default_disable;
269 if (!chip->startup)
270 chip->startup = default_startup;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100271 /*
272 * We use chip->disable, when the user provided its own. When
273 * we have default_disable set for chip->disable, then we need
274 * to use default_shutdown, otherwise the irq line is not
275 * disabled on free_irq():
276 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700277 if (!chip->shutdown)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100278 chip->shutdown = chip->disable != default_disable ?
279 chip->disable : default_shutdown;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700280 if (!chip->name)
281 chip->name = chip->typename;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800282 if (!chip->end)
283 chip->end = dummy_irq_chip.end;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700284}
285
286static inline void mask_ack_irq(struct irq_desc *desc, int irq)
287{
288 if (desc->chip->mask_ack)
289 desc->chip->mask_ack(irq);
290 else {
291 desc->chip->mask(irq);
292 desc->chip->ack(irq);
293 }
294}
295
296/**
297 * handle_simple_irq - Simple and software-decoded IRQs.
298 * @irq: the interrupt number
299 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700300 *
301 * Simple interrupts are either sent from a demultiplexing interrupt
302 * handler or come from hardware, where no interrupt hardware control
303 * is necessary.
304 *
305 * Note: The caller is expected to handle the ack, clear, mask and
306 * unmask issues if necessary.
307 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800308void
David Howells7d12e782006-10-05 14:55:46 +0100309handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700310{
311 struct irqaction *action;
312 irqreturn_t action_ret;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700313
314 spin_lock(&desc->lock);
315
316 if (unlikely(desc->status & IRQ_INPROGRESS))
317 goto out_unlock;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100318 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200319 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700320
321 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100322 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700323 goto out_unlock;
324
325 desc->status |= IRQ_INPROGRESS;
326 spin_unlock(&desc->lock);
327
David Howells7d12e782006-10-05 14:55:46 +0100328 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700329 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100330 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700331
332 spin_lock(&desc->lock);
333 desc->status &= ~IRQ_INPROGRESS;
334out_unlock:
335 spin_unlock(&desc->lock);
336}
337
338/**
339 * handle_level_irq - Level type irq handler
340 * @irq: the interrupt number
341 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700342 *
343 * Level type interrupts are active as long as the hardware line has
344 * the active level. This may require to mask the interrupt and unmask
345 * it after the associated handler has acknowledged the device, so the
346 * interrupt line is back to inactive.
347 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800348void
David Howells7d12e782006-10-05 14:55:46 +0100349handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700350{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700351 struct irqaction *action;
352 irqreturn_t action_ret;
353
354 spin_lock(&desc->lock);
355 mask_ack_irq(desc, irq);
356
357 if (unlikely(desc->status & IRQ_INPROGRESS))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200358 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700359 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200360 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700361
362 /*
363 * If its disabled or no action available
364 * keep it masked and get out of here
365 */
366 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000367 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200368 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700369
370 desc->status |= IRQ_INPROGRESS;
371 spin_unlock(&desc->lock);
372
David Howells7d12e782006-10-05 14:55:46 +0100373 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700374 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100375 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700376
377 spin_lock(&desc->lock);
378 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700379 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
380 desc->chip->unmask(irq);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200381out_unlock:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700382 spin_unlock(&desc->lock);
383}
384
385/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700386 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700387 * @irq: the interrupt number
388 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700389 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700390 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700391 * call when the interrupt has been serviced. This enables support
392 * for modern forms of interrupt handlers, which handle the flow
393 * details in hardware, transparently.
394 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800395void
David Howells7d12e782006-10-05 14:55:46 +0100396handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700397{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398 struct irqaction *action;
399 irqreturn_t action_ret;
400
401 spin_lock(&desc->lock);
402
403 if (unlikely(desc->status & IRQ_INPROGRESS))
404 goto out;
405
406 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200407 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700408
409 /*
410 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800411 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700412 */
413 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700414 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
415 desc->status |= IRQ_PENDING;
Ingo Molnar76d21602007-02-16 01:28:24 -0800416 if (desc->chip->mask)
417 desc->chip->mask(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700418 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700419 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700420
421 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700422 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700423 spin_unlock(&desc->lock);
424
David Howells7d12e782006-10-05 14:55:46 +0100425 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700426 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100427 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700428
429 spin_lock(&desc->lock);
430 desc->status &= ~IRQ_INPROGRESS;
431out:
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700432 desc->chip->eoi(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700433
434 spin_unlock(&desc->lock);
435}
436
437/**
438 * handle_edge_irq - edge type IRQ handler
439 * @irq: the interrupt number
440 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700441 *
442 * Interrupt occures on the falling and/or rising edge of a hardware
443 * signal. The occurence is latched into the irq controller hardware
444 * and must be acked in order to be reenabled. After the ack another
445 * interrupt can happen on the same source even before the first one
446 * is handled by the assosiacted event handler. If this happens it
447 * might be necessary to disable (mask) the interrupt depending on the
448 * controller hardware. This requires to reenable the interrupt inside
449 * of the loop which handles the interrupts which have arrived while
450 * the handler was running. If all pending interrupts are handled, the
451 * loop is left.
452 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800453void
David Howells7d12e782006-10-05 14:55:46 +0100454handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700455{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700456 spin_lock(&desc->lock);
457
458 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
459
460 /*
461 * If we're currently running this IRQ, or its disabled,
462 * we shouldn't process the IRQ. Mark it pending, handle
463 * the necessary masking and go out
464 */
465 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
466 !desc->action)) {
467 desc->status |= (IRQ_PENDING | IRQ_MASKED);
468 mask_ack_irq(desc, irq);
469 goto out_unlock;
470 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200471 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700472
473 /* Start handling the irq */
474 desc->chip->ack(irq);
475
476 /* Mark the IRQ currently in progress.*/
477 desc->status |= IRQ_INPROGRESS;
478
479 do {
480 struct irqaction *action = desc->action;
481 irqreturn_t action_ret;
482
483 if (unlikely(!action)) {
484 desc->chip->mask(irq);
485 goto out_unlock;
486 }
487
488 /*
489 * When another irq arrived while we were handling
490 * one, we could have masked the irq.
491 * Renable it, if it was not disabled in meantime.
492 */
493 if (unlikely((desc->status &
494 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
495 (IRQ_PENDING | IRQ_MASKED))) {
496 desc->chip->unmask(irq);
497 desc->status &= ~IRQ_MASKED;
498 }
499
500 desc->status &= ~IRQ_PENDING;
501 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100502 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700503 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100504 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700505 spin_lock(&desc->lock);
506
507 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
508
509 desc->status &= ~IRQ_INPROGRESS;
510out_unlock:
511 spin_unlock(&desc->lock);
512}
513
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700514/**
515 * handle_percpu_IRQ - Per CPU local irq handler
516 * @irq: the interrupt number
517 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700518 *
519 * Per CPU interrupts on SMP machines without locking requirements
520 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800521void
David Howells7d12e782006-10-05 14:55:46 +0100522handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700523{
524 irqreturn_t action_ret;
525
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200526 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700527
528 if (desc->chip->ack)
529 desc->chip->ack(irq);
530
David Howells7d12e782006-10-05 14:55:46 +0100531 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700532 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100533 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700534
535 if (desc->chip->eoi)
536 desc->chip->eoi(irq);
537}
538
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700539void
Ingo Molnara460e742006-10-17 00:10:03 -0700540__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
541 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700542{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200543 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544 unsigned long flags;
545
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700546 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700547 printk(KERN_ERR
548 "Trying to install type control for IRQ%d\n", irq);
549 return;
550 }
551
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700552 if (!handle)
553 handle = handle_bad_irq;
Thomas Gleixner9d7ac8b2006-12-22 01:08:14 -0800554 else if (desc->chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100555 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100556 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100557 /*
558 * Some ARM implementations install a handler for really dumb
559 * interrupt hardware without setting an irq_chip. This worked
560 * with the ARM no_irq_chip but the check in setup_irq would
561 * prevent us to setup the interrupt at all. Switch it to
562 * dummy_irq_chip for easy transition.
563 */
564 desc->chip = &dummy_irq_chip;
565 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700566
567 spin_lock_irqsave(&desc->lock, flags);
568
569 /* Uninstall? */
570 if (handle == handle_bad_irq) {
Jan Beulich5575ddf2007-02-16 01:28:26 -0800571 if (desc->chip != &no_irq_chip)
572 mask_ack_irq(desc, irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700573 desc->status |= IRQ_DISABLED;
574 desc->depth = 1;
575 }
576 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700577 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700578
579 if (handle != handle_bad_irq && is_chained) {
580 desc->status &= ~IRQ_DISABLED;
581 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
582 desc->depth = 0;
Pawel MOLL7e6e1782008-09-01 10:12:11 +0100583 desc->chip->startup(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700584 }
585 spin_unlock_irqrestore(&desc->lock, flags);
586}
587
588void
589set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100590 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700591{
592 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700593 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700594}
595
Ingo Molnara460e742006-10-17 00:10:03 -0700596void
597set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
598 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700599{
Ingo Molnara460e742006-10-17 00:10:03 -0700600 set_irq_chip(irq, chip);
601 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700602}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800603
604void __init set_irq_noprobe(unsigned int irq)
605{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200606 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800607 unsigned long flags;
608
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700609 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800610 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800611 return;
612 }
613
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800614 spin_lock_irqsave(&desc->lock, flags);
615 desc->status |= IRQ_NOPROBE;
616 spin_unlock_irqrestore(&desc->lock, flags);
617}
618
619void __init set_irq_probe(unsigned int irq)
620{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200621 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800622 unsigned long flags;
623
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700624 if (!desc) {
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800625 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800626 return;
627 }
628
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800629 spin_lock_irqsave(&desc->lock, flags);
630 desc->status &= ~IRQ_NOPROBE;
631 spin_unlock_irqrestore(&desc->lock, flags);
632}