blob: 343acecae629ff37c32013daede12da10b21f7fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/kernel/irq/handle.c
3 *
Ingo Molnara34db9b2006-06-29 02:24:50 -07004 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file contains the core interrupt handling code.
Ingo Molnara34db9b2006-06-29 02:24:50 -07008 *
9 * Detailed information is available in Documentation/DocBook/genericirq
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
13#include <linux/irq.h>
14#include <linux/module.h>
15#include <linux/random.h>
16#include <linux/interrupt.h>
17#include <linux/kernel_stat.h>
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080018#include <linux/rculist.h>
19#include <linux/hash.h>
Jason Baronaf392412009-02-26 10:11:05 -050020#include <trace/irq.h>
Mike Travis0fa0ebb2009-01-10 22:24:06 -080021#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "internals.h"
24
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080025/*
26 * lockdep: we want to handle all irq_desc locks as a single lock-class:
27 */
Yinghai Lu48a1b102008-12-11 00:15:01 -080028struct lock_class_key irq_desc_lock_class;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080029
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070030/**
31 * handle_bad_irq - handle spurious and unhandled irqs
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070032 * @irq: the interrupt number
33 * @desc: description of the interrupt
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070034 *
35 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070036 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020037void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070038{
Ingo Molnar43f77752006-06-29 02:24:58 -070039 print_irq_desc(irq, desc);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020040 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070041 ack_bad_irq(irq);
42}
43
David Daney97179fd2009-01-27 09:53:22 -080044#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
45static void __init init_irq_default_affinity(void)
46{
47 alloc_bootmem_cpumask_var(&irq_default_affinity);
48 cpumask_setall(irq_default_affinity);
49}
50#else
51static void __init init_irq_default_affinity(void)
52{
53}
54#endif
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Linux has a controller-independent interrupt architecture.
58 * Every controller has a 'controller-template', that is used
59 * by the main code to do the right thing. Each driver-visible
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070060 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * controller. Thus drivers need not be aware of the
62 * interrupt-controller.
63 *
64 * The code is designed to be easily extended with new/different
65 * interrupt controllers, without having to do assembly magic or
66 * having to touch the generic code.
67 *
68 * Controller mappings for all interrupt sources:
69 */
Yinghai Lu85c0f902008-08-19 20:49:47 -070070int nr_irqs = NR_IRQS;
Ingo Molnarfa42d102008-08-19 20:50:30 -070071EXPORT_SYMBOL_GPL(nr_irqs);
Yinghai Lud60458b2008-08-19 20:50:00 -070072
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080073#ifdef CONFIG_SPARSE_IRQ
Mike Travis92296c62009-01-11 09:22:58 -080074
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080075static struct irq_desc irq_desc_init = {
76 .irq = -1,
77 .status = IRQ_DISABLED,
78 .chip = &no_irq_chip,
79 .handle_irq = handle_bad_irq,
80 .depth = 1,
81 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080082};
83
Yinghai Lu48a1b102008-12-11 00:15:01 -080084void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080085{
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080086 int node;
Yinghai Lu005bf0e62009-02-08 16:18:03 -080087 void *ptr;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080088
89 node = cpu_to_node(cpu);
Yinghai Lu005bf0e62009-02-08 16:18:03 -080090 ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080091
Yinghai Lu005bf0e62009-02-08 16:18:03 -080092 /*
93 * don't overwite if can not get new one
94 * init_copy_kstat_irqs() could still use old one
95 */
96 if (ptr) {
97 printk(KERN_DEBUG " alloc kstat_irqs on cpu %d node %d\n",
98 cpu, node);
99 desc->kstat_irqs = ptr;
100 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800101}
102
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800103static void init_one_irq_desc(int irq, struct irq_desc *desc, int cpu)
104{
105 memcpy(desc, &irq_desc_init, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +0100106
107 spin_lock_init(&desc->lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800108 desc->irq = irq;
109#ifdef CONFIG_SMP
110 desc->cpu = cpu;
111#endif
112 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
113 init_kstat_irqs(desc, cpu, nr_cpu_ids);
114 if (!desc->kstat_irqs) {
115 printk(KERN_ERR "can not alloc kstat_irqs\n");
116 BUG_ON(1);
117 }
Mike Travis802bf932009-01-10 21:58:09 -0800118 if (!init_alloc_desc_masks(desc, cpu, false)) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800119 printk(KERN_ERR "can not alloc irq_desc cpumasks\n");
120 BUG_ON(1);
121 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800122 arch_init_chip_data(desc, cpu);
123}
124
125/*
126 * Protect the sparse_irqs:
127 */
Yinghai Lu48a1b102008-12-11 00:15:01 -0800128DEFINE_SPINLOCK(sparse_irq_lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800129
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800130struct irq_desc **irq_desc_ptrs __read_mostly;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800131
Yinghai Lu99d093d2008-12-05 18:58:32 -0800132static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = {
133 [0 ... NR_IRQS_LEGACY-1] = {
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800134 .irq = -1,
135 .status = IRQ_DISABLED,
136 .chip = &no_irq_chip,
137 .handle_irq = handle_bad_irq,
138 .depth = 1,
139 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800140 }
141};
142
Mike Travis542d8652009-01-10 22:24:07 -0800143static unsigned int *kstat_irqs_legacy;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800144
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800145int __init early_irq_init(void)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800146{
147 struct irq_desc *desc;
148 int legacy_count;
149 int i;
150
David Daney97179fd2009-01-27 09:53:22 -0800151 init_irq_default_affinity();
152
Yinghai Lu4a046d12009-01-12 17:39:24 -0800153 /* initialize nr_irqs based on nr_cpu_ids */
154 arch_probe_nr_irqs();
Mike Travis95949492009-01-10 22:24:06 -0800155 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
156
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800157 desc = irq_desc_legacy;
158 legacy_count = ARRAY_SIZE(irq_desc_legacy);
159
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800160 /* allocate irq_desc_ptrs array based on nr_irqs */
161 irq_desc_ptrs = alloc_bootmem(nr_irqs * sizeof(void *));
162
Mike Travis542d8652009-01-10 22:24:07 -0800163 /* allocate based on nr_cpu_ids */
164 /* FIXME: invert kstat_irgs, and it'd be a per_cpu_alloc'd thing */
165 kstat_irqs_legacy = alloc_bootmem(NR_IRQS_LEGACY * nr_cpu_ids *
166 sizeof(int));
167
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800168 for (i = 0; i < legacy_count; i++) {
169 desc[i].irq = i;
Mike Travis542d8652009-01-10 22:24:07 -0800170 desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;
Yinghai Lufa6beb32008-12-22 20:24:09 -0800171 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Mike Travis7f7ace02009-01-10 21:58:08 -0800172 init_alloc_desc_masks(&desc[i], 0, true);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800173 irq_desc_ptrs[i] = desc + i;
174 }
175
Mike Travis95949492009-01-10 22:24:06 -0800176 for (i = legacy_count; i < nr_irqs; i++)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800177 irq_desc_ptrs[i] = NULL;
178
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800179 return arch_early_irq_init();
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800180}
181
182struct irq_desc *irq_to_desc(unsigned int irq)
183{
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800184 if (irq_desc_ptrs && irq < nr_irqs)
185 return irq_desc_ptrs[irq];
186
187 return NULL;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800188}
189
190struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
191{
192 struct irq_desc *desc;
193 unsigned long flags;
194 int node;
195
Mike Travis95949492009-01-10 22:24:06 -0800196 if (irq >= nr_irqs) {
Mike Travise2f4d062009-01-10 22:24:06 -0800197 WARN(1, "irq (%d) >= nr_irqs (%d) in irq_to_desc_alloc\n",
198 irq, nr_irqs);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800199 return NULL;
200 }
201
202 desc = irq_desc_ptrs[irq];
203 if (desc)
204 return desc;
205
206 spin_lock_irqsave(&sparse_irq_lock, flags);
207
208 /* We have to check it to avoid races with another CPU */
209 desc = irq_desc_ptrs[irq];
210 if (desc)
211 goto out_unlock;
212
213 node = cpu_to_node(cpu);
214 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
215 printk(KERN_DEBUG " alloc irq_desc for %d on cpu %d node %d\n",
216 irq, cpu, node);
217 if (!desc) {
218 printk(KERN_ERR "can not alloc irq_desc\n");
219 BUG_ON(1);
220 }
221 init_one_irq_desc(irq, desc, cpu);
222
223 irq_desc_ptrs[irq] = desc;
224
225out_unlock:
226 spin_unlock_irqrestore(&sparse_irq_lock, flags);
227
228 return desc;
229}
230
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900231#else /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800232
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -0700233struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -0700235 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -0700236 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -0700237 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -0700238 .depth = 1,
Yinghai Luaac3f2b2008-09-24 19:04:35 -0700239 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241};
Yinghai Lu08678b02008-08-19 20:50:05 -0700242
Yinghai Lud7e51e62009-01-07 15:03:13 -0800243static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
Yinghai Lu12026ea2008-12-26 22:38:15 -0800244int __init early_irq_init(void)
245{
246 struct irq_desc *desc;
247 int count;
248 int i;
249
David Daney97179fd2009-01-27 09:53:22 -0800250 init_irq_default_affinity();
251
Mike Travis95949492009-01-10 22:24:06 -0800252 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
253
Yinghai Lu12026ea2008-12-26 22:38:15 -0800254 desc = irq_desc;
255 count = ARRAY_SIZE(irq_desc);
256
Yinghai Lud7e51e62009-01-07 15:03:13 -0800257 for (i = 0; i < count; i++) {
Yinghai Lu12026ea2008-12-26 22:38:15 -0800258 desc[i].irq = i;
Mike Travis7f7ace02009-01-10 21:58:08 -0800259 init_alloc_desc_masks(&desc[i], 0, true);
Yinghai Lud7e51e62009-01-07 15:03:13 -0800260 desc[i].kstat_irqs = kstat_irqs_all[i];
261 }
Yinghai Lu12026ea2008-12-26 22:38:15 -0800262 return arch_early_irq_init();
263}
264
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900265struct irq_desc *irq_to_desc(unsigned int irq)
266{
267 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
268}
269
270struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
271{
272 return irq_to_desc(irq);
273}
274#endif /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800275
Yinghai Lu0f3c2a82009-02-08 16:18:03 -0800276void clear_kstat_irqs(struct irq_desc *desc)
277{
278 memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
279}
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700282 * What should we do if we get a hw irq event on an illegal vector?
283 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700285static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200287 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700288
Yinghai Lu08678b02008-08-19 20:50:05 -0700289 print_irq_desc(irq, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 ack_bad_irq(irq);
291}
292
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700293/*
294 * NOP functions
295 */
296static void noop(unsigned int irq)
297{
298}
299
300static unsigned int noop_ret(unsigned int irq)
301{
302 return 0;
303}
304
305/*
306 * Generic no controller implementation
307 */
Ingo Molnarf1c26622006-06-29 02:24:57 -0700308struct irq_chip no_irq_chip = {
309 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700310 .startup = noop_ret,
311 .shutdown = noop,
312 .enable = noop,
313 .disable = noop,
314 .ack = ack_bad,
315 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316};
317
318/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100319 * Generic dummy implementation which can be used for
320 * real dumb interrupt sources
321 */
322struct irq_chip dummy_irq_chip = {
323 .name = "dummy",
324 .startup = noop_ret,
325 .shutdown = noop,
326 .enable = noop,
327 .disable = noop,
328 .ack = noop,
329 .mask = noop,
330 .unmask = noop,
331 .end = noop,
332};
333
334/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 * Special, empty irq handler:
336 */
David Howells7d12e782006-10-05 14:55:46 +0100337irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 return IRQ_NONE;
340}
341
Jason Baronaf392412009-02-26 10:11:05 -0500342DEFINE_TRACE(irq_handler_entry);
343DEFINE_TRACE(irq_handler_exit);
344
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700345/**
346 * handle_IRQ_event - irq action chain handler
347 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700348 * @action: the interrupt action chain for this irq
349 *
350 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 */
David Howells7d12e782006-10-05 14:55:46 +0100352irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Jan Beulich908dcec2006-06-23 02:06:00 -0700354 irqreturn_t ret, retval = IRQ_NONE;
355 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Peter Zijlstra044d4082009-03-02 16:13:32 +0100357 WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!");
358
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700359 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700360 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 do {
Jason Baronaf392412009-02-26 10:11:05 -0500363 trace_irq_handler_entry(irq, action);
David Howells7d12e782006-10-05 14:55:46 +0100364 ret = action->handler(irq, action->dev_id);
Jason Baronaf392412009-02-26 10:11:05 -0500365 trace_irq_handler_exit(irq, action, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (ret == IRQ_HANDLED)
367 status |= action->flags;
368 retval |= ret;
369 action = action->next;
370 } while (action);
371
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700372 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 add_interrupt_randomness(irq);
374 local_irq_disable();
375
376 return retval;
377}
378
David Howellsaf8c65b2006-09-25 23:32:07 -0700379#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Thomas Gleixner0e57aa12009-03-13 14:34:05 +0100380
381#ifdef CONFIG_ENABLE_WARN_DEPRECATED
382# warning __do_IRQ is deprecated. Please convert to proper flow handlers
383#endif
384
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700385/**
386 * __do_IRQ - original all in one highlevel IRQ handler
387 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700388 *
389 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 * SMP cross-CPU interrupts have their own specific
391 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700392 *
393 * This is the original x86 implementation which is used for every
394 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800396unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Yinghai Lu08678b02008-08-19 20:50:05 -0700398 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700399 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 unsigned int status;
401
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200402 kstat_incr_irqs_this_cpu(irq, desc);
403
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700404 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 irqreturn_t action_ret;
406
407 /*
408 * No locking required for CPU-local interrupts:
409 */
Yinghai Lu48a1b102008-12-11 00:15:01 -0800410 if (desc->chip->ack) {
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700411 desc->chip->ack(irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800412 /* get new one */
413 desc = irq_remap_to_desc(irq, desc);
414 }
Russ Andersonc642b832007-11-14 17:00:15 -0800415 if (likely(!(desc->status & IRQ_DISABLED))) {
416 action_ret = handle_IRQ_event(irq, desc->action);
417 if (!noirqdebug)
418 note_interrupt(irq, desc, action_ret);
419 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700420 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return 1;
422 }
423
424 spin_lock(&desc->lock);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800425 if (desc->chip->ack) {
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700426 desc->chip->ack(irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800427 desc = irq_remap_to_desc(irq, desc);
428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /*
430 * REPLAY is when Linux resends an IRQ that was dropped earlier
431 * WAITING is used by probe to mark irqs that are being tested
432 */
433 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
434 status |= IRQ_PENDING; /* we _want_ to handle it */
435
436 /*
437 * If the IRQ is disabled for whatever reason, we cannot
438 * use the action we have.
439 */
440 action = NULL;
441 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
442 action = desc->action;
443 status &= ~IRQ_PENDING; /* we commit to handling */
444 status |= IRQ_INPROGRESS; /* we are handling it */
445 }
446 desc->status = status;
447
448 /*
449 * If there is no IRQ handler or it was disabled, exit early.
450 * Since we set PENDING, if another processor is handling
451 * a different instance of this same irq, the other processor
452 * will take care of it.
453 */
454 if (unlikely(!action))
455 goto out;
456
457 /*
458 * Edge triggered interrupts need to remember
459 * pending events.
460 * This applies to any hw interrupts that allow a second
461 * instance of the same irq to arrive while we are in do_IRQ
462 * or in the handler. But the code here only handles the _second_
463 * instance of the irq, not the third or fourth. So it is mostly
464 * useful for irq hardware that does not mask cleanly in an
465 * SMP environment.
466 */
467 for (;;) {
468 irqreturn_t action_ret;
469
470 spin_unlock(&desc->lock);
471
David Howells7d12e782006-10-05 14:55:46 +0100472 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100474 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800475
476 spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (likely(!(desc->status & IRQ_PENDING)))
478 break;
479 desc->status &= ~IRQ_PENDING;
480 }
481 desc->status &= ~IRQ_INPROGRESS;
482
483out:
484 /*
485 * The ->end() handler has to deal with interrupts which got
486 * disabled while the handler was running.
487 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700488 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 spin_unlock(&desc->lock);
490
491 return 1;
492}
David Howellsaf8c65b2006-09-25 23:32:07 -0700493#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Ingo Molnar243c7622006-07-03 00:25:06 -0700495void early_init_irq_lock_class(void)
496{
Thomas Gleixner10e58082008-10-16 14:19:04 +0200497 struct irq_desc *desc;
Ingo Molnar243c7622006-07-03 00:25:06 -0700498 int i;
499
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800500 for_each_irq_desc(i, desc) {
Thomas Gleixner10e58082008-10-16 14:19:04 +0200501 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800502 }
Yinghai Lu08678b02008-08-19 20:50:05 -0700503}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800504
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800505unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
506{
507 struct irq_desc *desc = irq_to_desc(irq);
KOSAKI Motohiro26ddd8d2008-12-26 14:24:10 +0900508 return desc ? desc->kstat_irqs[cpu] : 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800509}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800510EXPORT_SYMBOL(kstat_irqs_cpu);
511