blob: a81cf80554dbf4da46c53cada05fc747f7c8eeff [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>
Paul Mundt948cd522009-05-22 10:40:09 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/random.h>
17#include <linux/interrupt.h>
18#include <linux/kernel_stat.h>
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080019#include <linux/rculist.h>
20#include <linux/hash.h>
Mike Travis0fa0ebb2009-01-10 22:24:06 -080021#include <linux/bootmem.h>
Steven Rostedtad8d75f2009-04-14 19:39:12 -040022#include <trace/events/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "internals.h"
25
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080026/*
27 * lockdep: we want to handle all irq_desc locks as a single lock-class:
28 */
Yinghai Lu48a1b102008-12-11 00:15:01 -080029struct lock_class_key irq_desc_lock_class;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080030
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070031/**
32 * handle_bad_irq - handle spurious and unhandled irqs
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070033 * @irq: the interrupt number
34 * @desc: description of the interrupt
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070035 *
36 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070037 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020038void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070039{
Ingo Molnar43f77752006-06-29 02:24:58 -070040 print_irq_desc(irq, desc);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020041 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070042 ack_bad_irq(irq);
43}
44
David Daney97179fd2009-01-27 09:53:22 -080045#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
46static void __init init_irq_default_affinity(void)
47{
Yinghai Lu28be2252009-06-12 11:33:02 +030048 alloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
David Daney97179fd2009-01-27 09:53:22 -080049 cpumask_setall(irq_default_affinity);
50}
51#else
52static void __init init_irq_default_affinity(void)
53{
54}
55#endif
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Linux has a controller-independent interrupt architecture.
59 * Every controller has a 'controller-template', that is used
60 * by the main code to do the right thing. Each driver-visible
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070061 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * controller. Thus drivers need not be aware of the
63 * interrupt-controller.
64 *
65 * The code is designed to be easily extended with new/different
66 * interrupt controllers, without having to do assembly magic or
67 * having to touch the generic code.
68 *
69 * Controller mappings for all interrupt sources:
70 */
Yinghai Lu85c0f902008-08-19 20:49:47 -070071int nr_irqs = NR_IRQS;
Ingo Molnarfa42d102008-08-19 20:50:30 -070072EXPORT_SYMBOL_GPL(nr_irqs);
Yinghai Lud60458b2008-08-19 20:50:00 -070073
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080074#ifdef CONFIG_SPARSE_IRQ
Mike Travis92296c62009-01-11 09:22:58 -080075
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080076static struct irq_desc irq_desc_init = {
77 .irq = -1,
78 .status = IRQ_DISABLED,
79 .chip = &no_irq_chip,
80 .handle_irq = handle_bad_irq,
81 .depth = 1,
82 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080083};
84
Paul Mundt948cd522009-05-22 10:40:09 +090085void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080086{
Yinghai Lu005bf0e62009-02-08 16:18:03 -080087 void *ptr;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080088
Paul Mundt948cd522009-05-22 10:40:09 +090089 if (slab_is_available())
90 ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs),
91 GFP_ATOMIC, node);
92 else
93 ptr = alloc_bootmem_node(NODE_DATA(node),
94 nr * sizeof(*desc->kstat_irqs));
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080095
Yinghai Lu005bf0e62009-02-08 16:18:03 -080096 /*
97 * don't overwite if can not get new one
98 * init_copy_kstat_irqs() could still use old one
99 */
100 if (ptr) {
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700101 printk(KERN_DEBUG " alloc kstat_irqs on node %d\n", node);
Yinghai Lu005bf0e62009-02-08 16:18:03 -0800102 desc->kstat_irqs = ptr;
103 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800104}
105
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700106static void init_one_irq_desc(int irq, struct irq_desc *desc, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800107{
108 memcpy(desc, &irq_desc_init, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +0100109
110 spin_lock_init(&desc->lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800111 desc->irq = irq;
112#ifdef CONFIG_SMP
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700113 desc->node = node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800114#endif
115 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700116 init_kstat_irqs(desc, node, nr_cpu_ids);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800117 if (!desc->kstat_irqs) {
118 printk(KERN_ERR "can not alloc kstat_irqs\n");
119 BUG_ON(1);
120 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700121 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800122 printk(KERN_ERR "can not alloc irq_desc cpumasks\n");
123 BUG_ON(1);
124 }
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700125 init_desc_masks(desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700126 arch_init_chip_data(desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800127}
128
129/*
130 * Protect the sparse_irqs:
131 */
Yinghai Lu48a1b102008-12-11 00:15:01 -0800132DEFINE_SPINLOCK(sparse_irq_lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800133
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800134struct irq_desc **irq_desc_ptrs __read_mostly;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800135
Yinghai Lu99d093d2008-12-05 18:58:32 -0800136static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = {
137 [0 ... NR_IRQS_LEGACY-1] = {
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800138 .irq = -1,
139 .status = IRQ_DISABLED,
140 .chip = &no_irq_chip,
141 .handle_irq = handle_bad_irq,
142 .depth = 1,
143 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800144 }
145};
146
Mike Travis542d8652009-01-10 22:24:07 -0800147static unsigned int *kstat_irqs_legacy;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800148
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800149int __init early_irq_init(void)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800150{
151 struct irq_desc *desc;
152 int legacy_count;
Yinghai Ludad213a2009-05-28 18:14:40 -0700153 int node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800154 int i;
155
David Daney97179fd2009-01-27 09:53:22 -0800156 init_irq_default_affinity();
157
Yinghai Lu4a046d12009-01-12 17:39:24 -0800158 /* initialize nr_irqs based on nr_cpu_ids */
159 arch_probe_nr_irqs();
Mike Travis95949492009-01-10 22:24:06 -0800160 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
161
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800162 desc = irq_desc_legacy;
163 legacy_count = ARRAY_SIZE(irq_desc_legacy);
Yinghai Lu372e24b2009-08-26 16:20:13 -0700164 node = first_online_node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800165
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800166 /* allocate irq_desc_ptrs array based on nr_irqs */
Pekka Enberg22fb4e72009-06-11 14:46:49 +0300167 irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT);
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800168
Mike Travis542d8652009-01-10 22:24:07 -0800169 /* allocate based on nr_cpu_ids */
Yinghai Ludad213a2009-05-28 18:14:40 -0700170 kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids *
171 sizeof(int), GFP_NOWAIT, node);
Mike Travis542d8652009-01-10 22:24:07 -0800172
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800173 for (i = 0; i < legacy_count; i++) {
174 desc[i].irq = i;
Yinghai Lu372e24b2009-08-26 16:20:13 -0700175#ifdef CONFIG_SMP
176 desc[i].node = node;
177#endif
Mike Travis542d8652009-01-10 22:24:07 -0800178 desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;
Yinghai Lufa6beb32008-12-22 20:24:09 -0800179 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Yinghai Ludad213a2009-05-28 18:14:40 -0700180 alloc_desc_masks(&desc[i], node, true);
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700181 init_desc_masks(&desc[i]);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800182 irq_desc_ptrs[i] = desc + i;
183 }
184
Mike Travis95949492009-01-10 22:24:06 -0800185 for (i = legacy_count; i < nr_irqs; i++)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800186 irq_desc_ptrs[i] = NULL;
187
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800188 return arch_early_irq_init();
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800189}
190
191struct irq_desc *irq_to_desc(unsigned int irq)
192{
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800193 if (irq_desc_ptrs && irq < nr_irqs)
194 return irq_desc_ptrs[irq];
195
196 return NULL;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800197}
198
Paul Mundt948cd522009-05-22 10:40:09 +0900199struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800200{
201 struct irq_desc *desc;
202 unsigned long flags;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800203
Mike Travis95949492009-01-10 22:24:06 -0800204 if (irq >= nr_irqs) {
Mike Travise2f4d062009-01-10 22:24:06 -0800205 WARN(1, "irq (%d) >= nr_irqs (%d) in irq_to_desc_alloc\n",
206 irq, nr_irqs);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800207 return NULL;
208 }
209
210 desc = irq_desc_ptrs[irq];
211 if (desc)
212 return desc;
213
214 spin_lock_irqsave(&sparse_irq_lock, flags);
215
216 /* We have to check it to avoid races with another CPU */
217 desc = irq_desc_ptrs[irq];
218 if (desc)
219 goto out_unlock;
220
Paul Mundt948cd522009-05-22 10:40:09 +0900221 if (slab_is_available())
222 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
223 else
224 desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc));
225
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700226 printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800227 if (!desc) {
228 printk(KERN_ERR "can not alloc irq_desc\n");
229 BUG_ON(1);
230 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700231 init_one_irq_desc(irq, desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800232
233 irq_desc_ptrs[irq] = desc;
234
235out_unlock:
236 spin_unlock_irqrestore(&sparse_irq_lock, flags);
237
238 return desc;
239}
240
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900241#else /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800242
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -0700243struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -0700245 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -0700246 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -0700247 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -0700248 .depth = 1,
Yinghai Luaac3f2b2008-09-24 19:04:35 -0700249 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251};
Yinghai Lu08678b02008-08-19 20:50:05 -0700252
Yinghai Lud7e51e62009-01-07 15:03:13 -0800253static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
Yinghai Lu12026ea2008-12-26 22:38:15 -0800254int __init early_irq_init(void)
255{
256 struct irq_desc *desc;
257 int count;
258 int i;
259
David Daney97179fd2009-01-27 09:53:22 -0800260 init_irq_default_affinity();
261
Mike Travis95949492009-01-10 22:24:06 -0800262 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
263
Yinghai Lu12026ea2008-12-26 22:38:15 -0800264 desc = irq_desc;
265 count = ARRAY_SIZE(irq_desc);
266
Yinghai Lud7e51e62009-01-07 15:03:13 -0800267 for (i = 0; i < count; i++) {
Yinghai Lu12026ea2008-12-26 22:38:15 -0800268 desc[i].irq = i;
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700269 alloc_desc_masks(&desc[i], 0, true);
270 init_desc_masks(&desc[i]);
Yinghai Lud7e51e62009-01-07 15:03:13 -0800271 desc[i].kstat_irqs = kstat_irqs_all[i];
272 }
Yinghai Lu12026ea2008-12-26 22:38:15 -0800273 return arch_early_irq_init();
274}
275
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900276struct irq_desc *irq_to_desc(unsigned int irq)
277{
278 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
279}
280
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700281struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900282{
283 return irq_to_desc(irq);
284}
285#endif /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800286
Yinghai Lu0f3c2a82009-02-08 16:18:03 -0800287void clear_kstat_irqs(struct irq_desc *desc)
288{
289 memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
290}
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700293 * What should we do if we get a hw irq event on an illegal vector?
294 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700296static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200298 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700299
Yinghai Lu08678b02008-08-19 20:50:05 -0700300 print_irq_desc(irq, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 ack_bad_irq(irq);
302}
303
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700304/*
305 * NOP functions
306 */
307static void noop(unsigned int irq)
308{
309}
310
311static unsigned int noop_ret(unsigned int irq)
312{
313 return 0;
314}
315
316/*
317 * Generic no controller implementation
318 */
Ingo Molnarf1c26622006-06-29 02:24:57 -0700319struct irq_chip no_irq_chip = {
320 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700321 .startup = noop_ret,
322 .shutdown = noop,
323 .enable = noop,
324 .disable = noop,
325 .ack = ack_bad,
326 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327};
328
329/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100330 * Generic dummy implementation which can be used for
331 * real dumb interrupt sources
332 */
333struct irq_chip dummy_irq_chip = {
334 .name = "dummy",
335 .startup = noop_ret,
336 .shutdown = noop,
337 .enable = noop,
338 .disable = noop,
339 .ack = noop,
340 .mask = noop,
341 .unmask = noop,
342 .end = noop,
343};
344
345/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 * Special, empty irq handler:
347 */
David Howells7d12e782006-10-05 14:55:46 +0100348irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 return IRQ_NONE;
351}
352
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100353static void warn_no_thread(unsigned int irq, struct irqaction *action)
354{
355 if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
356 return;
357
358 printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
359 "but no thread function available.", irq, action->name);
360}
361
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700362/**
363 * handle_IRQ_event - irq action chain handler
364 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700365 * @action: the interrupt action chain for this irq
366 *
367 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 */
David Howells7d12e782006-10-05 14:55:46 +0100369irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Jan Beulich908dcec2006-06-23 02:06:00 -0700371 irqreturn_t ret, retval = IRQ_NONE;
372 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700374 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700375 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 do {
Jason Baronaf392412009-02-26 10:11:05 -0500378 trace_irq_handler_entry(irq, action);
David Howells7d12e782006-10-05 14:55:46 +0100379 ret = action->handler(irq, action->dev_id);
Jason Baronaf392412009-02-26 10:11:05 -0500380 trace_irq_handler_exit(irq, action, ret);
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100381
382 switch (ret) {
383 case IRQ_WAKE_THREAD:
384 /*
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100385 * Set result to handled so the spurious check
386 * does not trigger.
387 */
388 ret = IRQ_HANDLED;
389
390 /*
391 * Catch drivers which return WAKE_THREAD but
392 * did not set up a thread function
393 */
394 if (unlikely(!action->thread_fn)) {
395 warn_no_thread(irq, action);
396 break;
397 }
398
399 /*
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100400 * Wake up the handler thread for this
401 * action. In case the thread crashed and was
402 * killed we just pretend that we handled the
403 * interrupt. The hardirq handler above has
404 * disabled the device interrupt, so no irq
405 * storm is lurking.
406 */
407 if (likely(!test_bit(IRQTF_DIED,
408 &action->thread_flags))) {
409 set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
410 wake_up_process(action->thread);
411 }
412
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100413 /* Fall through to add to randomness */
414 case IRQ_HANDLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 status |= action->flags;
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100416 break;
417
418 default:
419 break;
420 }
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 retval |= ret;
423 action = action->next;
424 } while (action);
425
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700426 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 add_interrupt_randomness(irq);
428 local_irq_disable();
429
430 return retval;
431}
432
David Howellsaf8c65b2006-09-25 23:32:07 -0700433#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Thomas Gleixner0e57aa12009-03-13 14:34:05 +0100434
435#ifdef CONFIG_ENABLE_WARN_DEPRECATED
436# warning __do_IRQ is deprecated. Please convert to proper flow handlers
437#endif
438
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700439/**
440 * __do_IRQ - original all in one highlevel IRQ handler
441 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700442 *
443 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 * SMP cross-CPU interrupts have their own specific
445 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700446 *
447 * This is the original x86 implementation which is used for every
448 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800450unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Yinghai Lu08678b02008-08-19 20:50:05 -0700452 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700453 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 unsigned int status;
455
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200456 kstat_incr_irqs_this_cpu(irq, desc);
457
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700458 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 irqreturn_t action_ret;
460
461 /*
462 * No locking required for CPU-local interrupts:
463 */
Yinghai Lufcef5912009-04-27 17:58:23 -0700464 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700465 desc->chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800466 if (likely(!(desc->status & IRQ_DISABLED))) {
467 action_ret = handle_IRQ_event(irq, desc->action);
468 if (!noirqdebug)
469 note_interrupt(irq, desc, action_ret);
470 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700471 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return 1;
473 }
474
475 spin_lock(&desc->lock);
Yinghai Lufcef5912009-04-27 17:58:23 -0700476 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700477 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 /*
479 * REPLAY is when Linux resends an IRQ that was dropped earlier
480 * WAITING is used by probe to mark irqs that are being tested
481 */
482 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
483 status |= IRQ_PENDING; /* we _want_ to handle it */
484
485 /*
486 * If the IRQ is disabled for whatever reason, we cannot
487 * use the action we have.
488 */
489 action = NULL;
490 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
491 action = desc->action;
492 status &= ~IRQ_PENDING; /* we commit to handling */
493 status |= IRQ_INPROGRESS; /* we are handling it */
494 }
495 desc->status = status;
496
497 /*
498 * If there is no IRQ handler or it was disabled, exit early.
499 * Since we set PENDING, if another processor is handling
500 * a different instance of this same irq, the other processor
501 * will take care of it.
502 */
503 if (unlikely(!action))
504 goto out;
505
506 /*
507 * Edge triggered interrupts need to remember
508 * pending events.
509 * This applies to any hw interrupts that allow a second
510 * instance of the same irq to arrive while we are in do_IRQ
511 * or in the handler. But the code here only handles the _second_
512 * instance of the irq, not the third or fourth. So it is mostly
513 * useful for irq hardware that does not mask cleanly in an
514 * SMP environment.
515 */
516 for (;;) {
517 irqreturn_t action_ret;
518
519 spin_unlock(&desc->lock);
520
David Howells7d12e782006-10-05 14:55:46 +0100521 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100523 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800524
525 spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (likely(!(desc->status & IRQ_PENDING)))
527 break;
528 desc->status &= ~IRQ_PENDING;
529 }
530 desc->status &= ~IRQ_INPROGRESS;
531
532out:
533 /*
534 * The ->end() handler has to deal with interrupts which got
535 * disabled while the handler was running.
536 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700537 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 spin_unlock(&desc->lock);
539
540 return 1;
541}
David Howellsaf8c65b2006-09-25 23:32:07 -0700542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Ingo Molnar243c7622006-07-03 00:25:06 -0700544void early_init_irq_lock_class(void)
545{
Thomas Gleixner10e58082008-10-16 14:19:04 +0200546 struct irq_desc *desc;
Ingo Molnar243c7622006-07-03 00:25:06 -0700547 int i;
548
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800549 for_each_irq_desc(i, desc) {
Thomas Gleixner10e58082008-10-16 14:19:04 +0200550 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800551 }
Yinghai Lu08678b02008-08-19 20:50:05 -0700552}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800553
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800554unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
555{
556 struct irq_desc *desc = irq_to_desc(irq);
KOSAKI Motohiro26ddd8d2008-12-26 14:24:10 +0900557 return desc ? desc->kstat_irqs[cpu] : 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800558}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800559EXPORT_SYMBOL(kstat_irqs_cpu);
560