blob: a6368db2618be2250378b007dad17c194e5910d3 [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 Lu85ac16d2009-04-27 18:00:38 -070084void init_kstat_irqs(struct irq_desc *desc, int node, int nr)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080085{
Yinghai Lu005bf0e62009-02-08 16:18:03 -080086 void *ptr;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080087
Yinghai Lu005bf0e62009-02-08 16:18:03 -080088 ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080089
Yinghai Lu005bf0e62009-02-08 16:18:03 -080090 /*
91 * don't overwite if can not get new one
92 * init_copy_kstat_irqs() could still use old one
93 */
94 if (ptr) {
Yinghai Lu85ac16d2009-04-27 18:00:38 -070095 printk(KERN_DEBUG " alloc kstat_irqs on node %d\n", node);
Yinghai Lu005bf0e62009-02-08 16:18:03 -080096 desc->kstat_irqs = ptr;
97 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080098}
99
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700100static void init_one_irq_desc(int irq, struct irq_desc *desc, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800101{
102 memcpy(desc, &irq_desc_init, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +0100103
104 spin_lock_init(&desc->lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800105 desc->irq = irq;
106#ifdef CONFIG_SMP
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700107 desc->node = node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800108#endif
109 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700110 init_kstat_irqs(desc, node, nr_cpu_ids);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800111 if (!desc->kstat_irqs) {
112 printk(KERN_ERR "can not alloc kstat_irqs\n");
113 BUG_ON(1);
114 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700115 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800116 printk(KERN_ERR "can not alloc irq_desc cpumasks\n");
117 BUG_ON(1);
118 }
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700119 init_desc_masks(desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700120 arch_init_chip_data(desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800121}
122
123/*
124 * Protect the sparse_irqs:
125 */
Yinghai Lu48a1b102008-12-11 00:15:01 -0800126DEFINE_SPINLOCK(sparse_irq_lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800127
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800128struct irq_desc **irq_desc_ptrs __read_mostly;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800129
Yinghai Lu99d093d2008-12-05 18:58:32 -0800130static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = {
131 [0 ... NR_IRQS_LEGACY-1] = {
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800132 .irq = -1,
133 .status = IRQ_DISABLED,
134 .chip = &no_irq_chip,
135 .handle_irq = handle_bad_irq,
136 .depth = 1,
137 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800138 }
139};
140
Mike Travis542d8652009-01-10 22:24:07 -0800141static unsigned int *kstat_irqs_legacy;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800142
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800143int __init early_irq_init(void)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800144{
145 struct irq_desc *desc;
146 int legacy_count;
147 int i;
148
David Daney97179fd2009-01-27 09:53:22 -0800149 init_irq_default_affinity();
150
Yinghai Lu4a046d12009-01-12 17:39:24 -0800151 /* initialize nr_irqs based on nr_cpu_ids */
152 arch_probe_nr_irqs();
Mike Travis95949492009-01-10 22:24:06 -0800153 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
154
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800155 desc = irq_desc_legacy;
156 legacy_count = ARRAY_SIZE(irq_desc_legacy);
157
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800158 /* allocate irq_desc_ptrs array based on nr_irqs */
159 irq_desc_ptrs = alloc_bootmem(nr_irqs * sizeof(void *));
160
Mike Travis542d8652009-01-10 22:24:07 -0800161 /* allocate based on nr_cpu_ids */
162 /* FIXME: invert kstat_irgs, and it'd be a per_cpu_alloc'd thing */
163 kstat_irqs_legacy = alloc_bootmem(NR_IRQS_LEGACY * nr_cpu_ids *
164 sizeof(int));
165
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800166 for (i = 0; i < legacy_count; i++) {
167 desc[i].irq = i;
Mike Travis542d8652009-01-10 22:24:07 -0800168 desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;
Yinghai Lufa6beb32008-12-22 20:24:09 -0800169 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700170 alloc_desc_masks(&desc[i], 0, true);
171 init_desc_masks(&desc[i]);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800172 irq_desc_ptrs[i] = desc + i;
173 }
174
Mike Travis95949492009-01-10 22:24:06 -0800175 for (i = legacy_count; i < nr_irqs; i++)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800176 irq_desc_ptrs[i] = NULL;
177
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800178 return arch_early_irq_init();
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800179}
180
181struct irq_desc *irq_to_desc(unsigned int irq)
182{
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800183 if (irq_desc_ptrs && irq < nr_irqs)
184 return irq_desc_ptrs[irq];
185
186 return NULL;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800187}
188
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700189struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800190{
191 struct irq_desc *desc;
192 unsigned long flags;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800193
Mike Travis95949492009-01-10 22:24:06 -0800194 if (irq >= nr_irqs) {
Mike Travise2f4d062009-01-10 22:24:06 -0800195 WARN(1, "irq (%d) >= nr_irqs (%d) in irq_to_desc_alloc\n",
196 irq, nr_irqs);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800197 return NULL;
198 }
199
200 desc = irq_desc_ptrs[irq];
201 if (desc)
202 return desc;
203
204 spin_lock_irqsave(&sparse_irq_lock, flags);
205
206 /* We have to check it to avoid races with another CPU */
207 desc = irq_desc_ptrs[irq];
208 if (desc)
209 goto out_unlock;
210
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800211 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700212 printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800213 if (!desc) {
214 printk(KERN_ERR "can not alloc irq_desc\n");
215 BUG_ON(1);
216 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700217 init_one_irq_desc(irq, desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800218
219 irq_desc_ptrs[irq] = desc;
220
221out_unlock:
222 spin_unlock_irqrestore(&sparse_irq_lock, flags);
223
224 return desc;
225}
226
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900227#else /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800228
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -0700229struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -0700231 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -0700232 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -0700233 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -0700234 .depth = 1,
Yinghai Luaac3f2b2008-09-24 19:04:35 -0700235 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237};
Yinghai Lu08678b02008-08-19 20:50:05 -0700238
Yinghai Lud7e51e62009-01-07 15:03:13 -0800239static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
Yinghai Lu12026ea2008-12-26 22:38:15 -0800240int __init early_irq_init(void)
241{
242 struct irq_desc *desc;
243 int count;
244 int i;
245
David Daney97179fd2009-01-27 09:53:22 -0800246 init_irq_default_affinity();
247
Mike Travis95949492009-01-10 22:24:06 -0800248 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
249
Yinghai Lu12026ea2008-12-26 22:38:15 -0800250 desc = irq_desc;
251 count = ARRAY_SIZE(irq_desc);
252
Yinghai Lud7e51e62009-01-07 15:03:13 -0800253 for (i = 0; i < count; i++) {
Yinghai Lu12026ea2008-12-26 22:38:15 -0800254 desc[i].irq = i;
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700255 alloc_desc_masks(&desc[i], 0, true);
256 init_desc_masks(&desc[i]);
Yinghai Lud7e51e62009-01-07 15:03:13 -0800257 desc[i].kstat_irqs = kstat_irqs_all[i];
258 }
Yinghai Lu12026ea2008-12-26 22:38:15 -0800259 return arch_early_irq_init();
260}
261
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900262struct irq_desc *irq_to_desc(unsigned int irq)
263{
264 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
265}
266
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700267struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900268{
269 return irq_to_desc(irq);
270}
271#endif /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800272
Yinghai Lu0f3c2a82009-02-08 16:18:03 -0800273void clear_kstat_irqs(struct irq_desc *desc)
274{
275 memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
276}
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700279 * What should we do if we get a hw irq event on an illegal vector?
280 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700282static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200284 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700285
Yinghai Lu08678b02008-08-19 20:50:05 -0700286 print_irq_desc(irq, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ack_bad_irq(irq);
288}
289
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700290/*
291 * NOP functions
292 */
293static void noop(unsigned int irq)
294{
295}
296
297static unsigned int noop_ret(unsigned int irq)
298{
299 return 0;
300}
301
302/*
303 * Generic no controller implementation
304 */
Ingo Molnarf1c26622006-06-29 02:24:57 -0700305struct irq_chip no_irq_chip = {
306 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700307 .startup = noop_ret,
308 .shutdown = noop,
309 .enable = noop,
310 .disable = noop,
311 .ack = ack_bad,
312 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313};
314
315/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100316 * Generic dummy implementation which can be used for
317 * real dumb interrupt sources
318 */
319struct irq_chip dummy_irq_chip = {
320 .name = "dummy",
321 .startup = noop_ret,
322 .shutdown = noop,
323 .enable = noop,
324 .disable = noop,
325 .ack = noop,
326 .mask = noop,
327 .unmask = noop,
328 .end = noop,
329};
330
331/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 * Special, empty irq handler:
333 */
David Howells7d12e782006-10-05 14:55:46 +0100334irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 return IRQ_NONE;
337}
338
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100339static void warn_no_thread(unsigned int irq, struct irqaction *action)
340{
341 if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
342 return;
343
344 printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
345 "but no thread function available.", irq, action->name);
346}
347
Jason Baronaf392412009-02-26 10:11:05 -0500348DEFINE_TRACE(irq_handler_entry);
349DEFINE_TRACE(irq_handler_exit);
350
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700351/**
352 * handle_IRQ_event - irq action chain handler
353 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700354 * @action: the interrupt action chain for this irq
355 *
356 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 */
David Howells7d12e782006-10-05 14:55:46 +0100358irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Jan Beulich908dcec2006-06-23 02:06:00 -0700360 irqreturn_t ret, retval = IRQ_NONE;
361 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Peter Zijlstra044d4082009-03-02 16:13:32 +0100363 WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!");
364
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700365 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700366 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 do {
Jason Baronaf392412009-02-26 10:11:05 -0500369 trace_irq_handler_entry(irq, action);
David Howells7d12e782006-10-05 14:55:46 +0100370 ret = action->handler(irq, action->dev_id);
Jason Baronaf392412009-02-26 10:11:05 -0500371 trace_irq_handler_exit(irq, action, ret);
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100372
373 switch (ret) {
374 case IRQ_WAKE_THREAD:
375 /*
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100376 * Set result to handled so the spurious check
377 * does not trigger.
378 */
379 ret = IRQ_HANDLED;
380
381 /*
382 * Catch drivers which return WAKE_THREAD but
383 * did not set up a thread function
384 */
385 if (unlikely(!action->thread_fn)) {
386 warn_no_thread(irq, action);
387 break;
388 }
389
390 /*
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100391 * Wake up the handler thread for this
392 * action. In case the thread crashed and was
393 * killed we just pretend that we handled the
394 * interrupt. The hardirq handler above has
395 * disabled the device interrupt, so no irq
396 * storm is lurking.
397 */
398 if (likely(!test_bit(IRQTF_DIED,
399 &action->thread_flags))) {
400 set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
401 wake_up_process(action->thread);
402 }
403
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100404 /* Fall through to add to randomness */
405 case IRQ_HANDLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 status |= action->flags;
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100407 break;
408
409 default:
410 break;
411 }
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 retval |= ret;
414 action = action->next;
415 } while (action);
416
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700417 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 add_interrupt_randomness(irq);
419 local_irq_disable();
420
421 return retval;
422}
423
David Howellsaf8c65b2006-09-25 23:32:07 -0700424#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Thomas Gleixner0e57aa12009-03-13 14:34:05 +0100425
426#ifdef CONFIG_ENABLE_WARN_DEPRECATED
427# warning __do_IRQ is deprecated. Please convert to proper flow handlers
428#endif
429
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700430/**
431 * __do_IRQ - original all in one highlevel IRQ handler
432 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700433 *
434 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * SMP cross-CPU interrupts have their own specific
436 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700437 *
438 * This is the original x86 implementation which is used for every
439 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800441unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Yinghai Lu08678b02008-08-19 20:50:05 -0700443 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700444 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 unsigned int status;
446
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200447 kstat_incr_irqs_this_cpu(irq, desc);
448
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700449 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 irqreturn_t action_ret;
451
452 /*
453 * No locking required for CPU-local interrupts:
454 */
Yinghai Lufcef5912009-04-27 17:58:23 -0700455 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700456 desc->chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800457 if (likely(!(desc->status & IRQ_DISABLED))) {
458 action_ret = handle_IRQ_event(irq, desc->action);
459 if (!noirqdebug)
460 note_interrupt(irq, desc, action_ret);
461 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700462 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 return 1;
464 }
465
466 spin_lock(&desc->lock);
Yinghai Lufcef5912009-04-27 17:58:23 -0700467 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700468 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /*
470 * REPLAY is when Linux resends an IRQ that was dropped earlier
471 * WAITING is used by probe to mark irqs that are being tested
472 */
473 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
474 status |= IRQ_PENDING; /* we _want_ to handle it */
475
476 /*
477 * If the IRQ is disabled for whatever reason, we cannot
478 * use the action we have.
479 */
480 action = NULL;
481 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
482 action = desc->action;
483 status &= ~IRQ_PENDING; /* we commit to handling */
484 status |= IRQ_INPROGRESS; /* we are handling it */
485 }
486 desc->status = status;
487
488 /*
489 * If there is no IRQ handler or it was disabled, exit early.
490 * Since we set PENDING, if another processor is handling
491 * a different instance of this same irq, the other processor
492 * will take care of it.
493 */
494 if (unlikely(!action))
495 goto out;
496
497 /*
498 * Edge triggered interrupts need to remember
499 * pending events.
500 * This applies to any hw interrupts that allow a second
501 * instance of the same irq to arrive while we are in do_IRQ
502 * or in the handler. But the code here only handles the _second_
503 * instance of the irq, not the third or fourth. So it is mostly
504 * useful for irq hardware that does not mask cleanly in an
505 * SMP environment.
506 */
507 for (;;) {
508 irqreturn_t action_ret;
509
510 spin_unlock(&desc->lock);
511
David Howells7d12e782006-10-05 14:55:46 +0100512 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100514 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800515
516 spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (likely(!(desc->status & IRQ_PENDING)))
518 break;
519 desc->status &= ~IRQ_PENDING;
520 }
521 desc->status &= ~IRQ_INPROGRESS;
522
523out:
524 /*
525 * The ->end() handler has to deal with interrupts which got
526 * disabled while the handler was running.
527 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700528 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 spin_unlock(&desc->lock);
530
531 return 1;
532}
David Howellsaf8c65b2006-09-25 23:32:07 -0700533#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Ingo Molnar243c7622006-07-03 00:25:06 -0700535void early_init_irq_lock_class(void)
536{
Thomas Gleixner10e58082008-10-16 14:19:04 +0200537 struct irq_desc *desc;
Ingo Molnar243c7622006-07-03 00:25:06 -0700538 int i;
539
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800540 for_each_irq_desc(i, desc) {
Thomas Gleixner10e58082008-10-16 14:19:04 +0200541 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800542 }
Yinghai Lu08678b02008-08-19 20:50:05 -0700543}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800544
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800545unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
546{
547 struct irq_desc *desc = irq_to_desc(irq);
KOSAKI Motohiro26ddd8d2008-12-26 14:24:10 +0900548 return desc ? desc->kstat_irqs[cpu] : 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800549}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800550EXPORT_SYMBOL(kstat_irqs_cpu);
551