blob: 266f7986aa08459f4b8a28176e5c11e83ad89d45 [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>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040014#include <linux/sched.h>
Paul Mundt948cd522009-05-22 10:40:09 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/module.h>
17#include <linux/random.h>
18#include <linux/interrupt.h>
19#include <linux/kernel_stat.h>
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080020#include <linux/rculist.h>
21#include <linux/hash.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,
Thomas Gleixner239007b2009-11-17 16:46:45 +010082 .lock = __RAW_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
Yinghai Lufebcb0c2010-02-10 01:20:32 -080089 ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs),
90 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) {
Yinghai Lu85ac16d2009-04-27 18:00:38 -070097 printk(KERN_DEBUG " alloc kstat_irqs on node %d\n", node);
Yinghai Lu005bf0e62009-02-08 16:18:03 -080098 desc->kstat_irqs = ptr;
99 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800100}
101
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700102static void init_one_irq_desc(int irq, struct irq_desc *desc, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800103{
104 memcpy(desc, &irq_desc_init, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +0100105
Thomas Gleixner239007b2009-11-17 16:46:45 +0100106 raw_spin_lock_init(&desc->lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800107 desc->irq = irq;
108#ifdef CONFIG_SMP
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700109 desc->node = node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800110#endif
111 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700112 init_kstat_irqs(desc, node, nr_cpu_ids);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800113 if (!desc->kstat_irqs) {
114 printk(KERN_ERR "can not alloc kstat_irqs\n");
115 BUG_ON(1);
116 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700117 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800118 printk(KERN_ERR "can not alloc irq_desc cpumasks\n");
119 BUG_ON(1);
120 }
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700121 init_desc_masks(desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700122 arch_init_chip_data(desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800123}
124
125/*
126 * Protect the sparse_irqs:
127 */
Thomas Gleixner239007b2009-11-17 16:46:45 +0100128DEFINE_RAW_SPINLOCK(sparse_irq_lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800129
Yinghai Lu99558f02010-02-10 01:20:34 -0800130static struct 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,
Thomas Gleixner239007b2009-11-17 16:46:45 +0100139 .lock = __RAW_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;
Yinghai Ludad213a2009-05-28 18:14:40 -0700149 int node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800150 int i;
151
David Daney97179fd2009-01-27 09:53:22 -0800152 init_irq_default_affinity();
153
Yinghai Lu4a046d12009-01-12 17:39:24 -0800154 /* initialize nr_irqs based on nr_cpu_ids */
155 arch_probe_nr_irqs();
Mike Travis95949492009-01-10 22:24:06 -0800156 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
157
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800158 desc = irq_desc_legacy;
159 legacy_count = ARRAY_SIZE(irq_desc_legacy);
Yinghai Lu372e24b2009-08-26 16:20:13 -0700160 node = first_online_node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800161
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800162 /* allocate irq_desc_ptrs array based on nr_irqs */
Pekka Enberg22fb4e72009-06-11 14:46:49 +0300163 irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT);
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800164
Mike Travis542d8652009-01-10 22:24:07 -0800165 /* allocate based on nr_cpu_ids */
Yinghai Ludad213a2009-05-28 18:14:40 -0700166 kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids *
167 sizeof(int), GFP_NOWAIT, node);
Mike Travis542d8652009-01-10 22:24:07 -0800168
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800169 for (i = 0; i < legacy_count; i++) {
170 desc[i].irq = i;
Yinghai Lu372e24b2009-08-26 16:20:13 -0700171#ifdef CONFIG_SMP
172 desc[i].node = node;
173#endif
Mike Travis542d8652009-01-10 22:24:07 -0800174 desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;
Yinghai Lufa6beb32008-12-22 20:24:09 -0800175 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Yinghai Ludad213a2009-05-28 18:14:40 -0700176 alloc_desc_masks(&desc[i], node, true);
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700177 init_desc_masks(&desc[i]);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800178 irq_desc_ptrs[i] = desc + i;
179 }
180
Mike Travis95949492009-01-10 22:24:06 -0800181 for (i = legacy_count; i < nr_irqs; i++)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800182 irq_desc_ptrs[i] = NULL;
183
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800184 return arch_early_irq_init();
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800185}
186
187struct irq_desc *irq_to_desc(unsigned int irq)
188{
Mike Travis0fa0ebb2009-01-10 22:24:06 -0800189 if (irq_desc_ptrs && irq < nr_irqs)
190 return irq_desc_ptrs[irq];
191
192 return NULL;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800193}
194
Yinghai Lu99558f02010-02-10 01:20:34 -0800195void replace_irq_desc(unsigned int irq, struct irq_desc *desc)
196{
197 irq_desc_ptrs[irq] = desc;
198}
199
Paul Mundt948cd522009-05-22 10:40:09 +0900200struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800201{
202 struct irq_desc *desc;
203 unsigned long flags;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800204
Mike Travis95949492009-01-10 22:24:06 -0800205 if (irq >= nr_irqs) {
Mike Travise2f4d062009-01-10 22:24:06 -0800206 WARN(1, "irq (%d) >= nr_irqs (%d) in irq_to_desc_alloc\n",
207 irq, nr_irqs);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800208 return NULL;
209 }
210
211 desc = irq_desc_ptrs[irq];
212 if (desc)
213 return desc;
214
Thomas Gleixner239007b2009-11-17 16:46:45 +0100215 raw_spin_lock_irqsave(&sparse_irq_lock, flags);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800216
217 /* We have to check it to avoid races with another CPU */
218 desc = irq_desc_ptrs[irq];
219 if (desc)
220 goto out_unlock;
221
Yinghai Lufebcb0c2010-02-10 01:20:32 -0800222 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
Paul Mundt948cd522009-05-22 10:40:09 +0900223
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700224 printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800225 if (!desc) {
226 printk(KERN_ERR "can not alloc irq_desc\n");
227 BUG_ON(1);
228 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700229 init_one_irq_desc(irq, desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800230
231 irq_desc_ptrs[irq] = desc;
232
233out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100234 raw_spin_unlock_irqrestore(&sparse_irq_lock, flags);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800235
236 return desc;
237}
238
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900239#else /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800240
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -0700241struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -0700243 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -0700244 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -0700245 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -0700246 .depth = 1,
Thomas Gleixner239007b2009-11-17 16:46:45 +0100247 .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249};
Yinghai Lu08678b02008-08-19 20:50:05 -0700250
Yinghai Lud7e51e62009-01-07 15:03:13 -0800251static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
Yinghai Lu12026ea2008-12-26 22:38:15 -0800252int __init early_irq_init(void)
253{
254 struct irq_desc *desc;
255 int count;
256 int i;
257
David Daney97179fd2009-01-27 09:53:22 -0800258 init_irq_default_affinity();
259
Mike Travis95949492009-01-10 22:24:06 -0800260 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
261
Yinghai Lu12026ea2008-12-26 22:38:15 -0800262 desc = irq_desc;
263 count = ARRAY_SIZE(irq_desc);
264
Yinghai Lud7e51e62009-01-07 15:03:13 -0800265 for (i = 0; i < count; i++) {
Yinghai Lu12026ea2008-12-26 22:38:15 -0800266 desc[i].irq = i;
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700267 alloc_desc_masks(&desc[i], 0, true);
268 init_desc_masks(&desc[i]);
Yinghai Lud7e51e62009-01-07 15:03:13 -0800269 desc[i].kstat_irqs = kstat_irqs_all[i];
270 }
Yinghai Lu12026ea2008-12-26 22:38:15 -0800271 return arch_early_irq_init();
272}
273
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900274struct irq_desc *irq_to_desc(unsigned int irq)
275{
276 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
277}
278
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700279struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
KOSAKI Motohirof9af0e72008-12-26 12:24:24 +0900280{
281 return irq_to_desc(irq);
282}
283#endif /* !CONFIG_SPARSE_IRQ */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800284
Yinghai Lu0f3c2a82009-02-08 16:18:03 -0800285void clear_kstat_irqs(struct irq_desc *desc)
286{
287 memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700291 * What should we do if we get a hw irq event on an illegal vector?
292 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700294static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200296 struct irq_desc *desc = irq_to_desc(irq);
Yinghai Lu08678b02008-08-19 20:50:05 -0700297
Yinghai Lu08678b02008-08-19 20:50:05 -0700298 print_irq_desc(irq, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 ack_bad_irq(irq);
300}
301
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700302/*
303 * NOP functions
304 */
305static void noop(unsigned int irq)
306{
307}
308
309static unsigned int noop_ret(unsigned int irq)
310{
311 return 0;
312}
313
314/*
315 * Generic no controller implementation
316 */
Ingo Molnarf1c26622006-06-29 02:24:57 -0700317struct irq_chip no_irq_chip = {
318 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -0700319 .startup = noop_ret,
320 .shutdown = noop,
321 .enable = noop,
322 .disable = noop,
323 .ack = ack_bad,
324 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325};
326
327/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100328 * Generic dummy implementation which can be used for
329 * real dumb interrupt sources
330 */
331struct irq_chip dummy_irq_chip = {
332 .name = "dummy",
333 .startup = noop_ret,
334 .shutdown = noop,
335 .enable = noop,
336 .disable = noop,
337 .ack = noop,
338 .mask = noop,
339 .unmask = noop,
340 .end = noop,
341};
342
343/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * Special, empty irq handler:
345 */
David Howells7d12e782006-10-05 14:55:46 +0100346irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 return IRQ_NONE;
349}
350
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100351static void warn_no_thread(unsigned int irq, struct irqaction *action)
352{
353 if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
354 return;
355
356 printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
357 "but no thread function available.", irq, action->name);
358}
359
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700360/**
361 * handle_IRQ_event - irq action chain handler
362 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700363 * @action: the interrupt action chain for this irq
364 *
365 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 */
David Howells7d12e782006-10-05 14:55:46 +0100367irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Jan Beulich908dcec2006-06-23 02:06:00 -0700369 irqreturn_t ret, retval = IRQ_NONE;
370 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700372 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700373 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 do {
Jason Baronaf392412009-02-26 10:11:05 -0500376 trace_irq_handler_entry(irq, action);
David Howells7d12e782006-10-05 14:55:46 +0100377 ret = action->handler(irq, action->dev_id);
Jason Baronaf392412009-02-26 10:11:05 -0500378 trace_irq_handler_exit(irq, action, ret);
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100379
380 switch (ret) {
381 case IRQ_WAKE_THREAD:
382 /*
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100383 * Set result to handled so the spurious check
384 * does not trigger.
385 */
386 ret = IRQ_HANDLED;
387
388 /*
389 * Catch drivers which return WAKE_THREAD but
390 * did not set up a thread function
391 */
392 if (unlikely(!action->thread_fn)) {
393 warn_no_thread(irq, action);
394 break;
395 }
396
397 /*
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100398 * Wake up the handler thread for this
399 * action. In case the thread crashed and was
400 * killed we just pretend that we handled the
401 * interrupt. The hardirq handler above has
402 * disabled the device interrupt, so no irq
403 * storm is lurking.
404 */
405 if (likely(!test_bit(IRQTF_DIED,
406 &action->thread_flags))) {
407 set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
408 wake_up_process(action->thread);
409 }
410
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100411 /* Fall through to add to randomness */
412 case IRQ_HANDLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 status |= action->flags;
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100414 break;
415
416 default:
417 break;
418 }
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 retval |= ret;
421 action = action->next;
422 } while (action);
423
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700424 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 add_interrupt_randomness(irq);
426 local_irq_disable();
427
428 return retval;
429}
430
David Howellsaf8c65b2006-09-25 23:32:07 -0700431#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Thomas Gleixner0e57aa12009-03-13 14:34:05 +0100432
433#ifdef CONFIG_ENABLE_WARN_DEPRECATED
434# warning __do_IRQ is deprecated. Please convert to proper flow handlers
435#endif
436
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700437/**
438 * __do_IRQ - original all in one highlevel IRQ handler
439 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700440 *
441 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * SMP cross-CPU interrupts have their own specific
443 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700444 *
445 * This is the original x86 implementation which is used for every
446 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800448unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Yinghai Lu08678b02008-08-19 20:50:05 -0700450 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700451 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 unsigned int status;
453
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200454 kstat_incr_irqs_this_cpu(irq, desc);
455
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700456 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 irqreturn_t action_ret;
458
459 /*
460 * No locking required for CPU-local interrupts:
461 */
Yinghai Lufcef5912009-04-27 17:58:23 -0700462 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700463 desc->chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800464 if (likely(!(desc->status & IRQ_DISABLED))) {
465 action_ret = handle_IRQ_event(irq, desc->action);
466 if (!noirqdebug)
467 note_interrupt(irq, desc, action_ret);
468 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700469 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return 1;
471 }
472
Thomas Gleixner239007b2009-11-17 16:46:45 +0100473 raw_spin_lock(&desc->lock);
Yinghai Lufcef5912009-04-27 17:58:23 -0700474 if (desc->chip->ack)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700475 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /*
477 * REPLAY is when Linux resends an IRQ that was dropped earlier
478 * WAITING is used by probe to mark irqs that are being tested
479 */
480 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
481 status |= IRQ_PENDING; /* we _want_ to handle it */
482
483 /*
484 * If the IRQ is disabled for whatever reason, we cannot
485 * use the action we have.
486 */
487 action = NULL;
488 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
489 action = desc->action;
490 status &= ~IRQ_PENDING; /* we commit to handling */
491 status |= IRQ_INPROGRESS; /* we are handling it */
492 }
493 desc->status = status;
494
495 /*
496 * If there is no IRQ handler or it was disabled, exit early.
497 * Since we set PENDING, if another processor is handling
498 * a different instance of this same irq, the other processor
499 * will take care of it.
500 */
501 if (unlikely(!action))
502 goto out;
503
504 /*
505 * Edge triggered interrupts need to remember
506 * pending events.
507 * This applies to any hw interrupts that allow a second
508 * instance of the same irq to arrive while we are in do_IRQ
509 * or in the handler. But the code here only handles the _second_
510 * instance of the irq, not the third or fourth. So it is mostly
511 * useful for irq hardware that does not mask cleanly in an
512 * SMP environment.
513 */
514 for (;;) {
515 irqreturn_t action_ret;
516
Thomas Gleixner239007b2009-11-17 16:46:45 +0100517 raw_spin_unlock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
David Howells7d12e782006-10-05 14:55:46 +0100519 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100521 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800522
Thomas Gleixner239007b2009-11-17 16:46:45 +0100523 raw_spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (likely(!(desc->status & IRQ_PENDING)))
525 break;
526 desc->status &= ~IRQ_PENDING;
527 }
528 desc->status &= ~IRQ_INPROGRESS;
529
530out:
531 /*
532 * The ->end() handler has to deal with interrupts which got
533 * disabled while the handler was running.
534 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700535 desc->chip->end(irq);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100536 raw_spin_unlock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 return 1;
539}
David Howellsaf8c65b2006-09-25 23:32:07 -0700540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Ingo Molnar243c7622006-07-03 00:25:06 -0700542void early_init_irq_lock_class(void)
543{
Thomas Gleixner10e58082008-10-16 14:19:04 +0200544 struct irq_desc *desc;
Ingo Molnar243c7622006-07-03 00:25:06 -0700545 int i;
546
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800547 for_each_irq_desc(i, desc) {
Thomas Gleixner10e58082008-10-16 14:19:04 +0200548 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800549 }
Yinghai Lu08678b02008-08-19 20:50:05 -0700550}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800551
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800552unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
553{
554 struct irq_desc *desc = irq_to_desc(irq);
KOSAKI Motohiro26ddd8d2008-12-26 14:24:10 +0900555 return desc ? desc->kstat_irqs[cpu] : 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800556}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800557EXPORT_SYMBOL(kstat_irqs_cpu);
558