blob: fc27d76e83ef5f3c45c0eeb2554acb9e81f21af9 [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>
Yinghai Lub5eb78f2010-02-10 01:20:35 -080022#include <linux/radix-tree.h>
Steven Rostedtad8d75f2009-04-14 19:39:12 -040023#include <trace/events/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "internals.h"
26
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080027/*
28 * lockdep: we want to handle all irq_desc locks as a single lock-class:
29 */
Yinghai Lu48a1b102008-12-11 00:15:01 -080030struct lock_class_key irq_desc_lock_class;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080031
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070032/**
33 * handle_bad_irq - handle spurious and unhandled irqs
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070034 * @irq: the interrupt number
35 * @desc: description of the interrupt
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070036 *
37 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070038 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020039void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070040{
Ingo Molnar43f77752006-06-29 02:24:58 -070041 print_irq_desc(irq, desc);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020042 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070043 ack_bad_irq(irq);
44}
45
David Daney97179fd2009-01-27 09:53:22 -080046#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
47static void __init init_irq_default_affinity(void)
48{
Yinghai Lu28be2252009-06-12 11:33:02 +030049 alloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
David Daney97179fd2009-01-27 09:53:22 -080050 cpumask_setall(irq_default_affinity);
51}
52#else
53static void __init init_irq_default_affinity(void)
54{
55}
56#endif
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*
59 * Linux has a controller-independent interrupt architecture.
60 * Every controller has a 'controller-template', that is used
61 * by the main code to do the right thing. Each driver-visible
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070062 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * controller. Thus drivers need not be aware of the
64 * interrupt-controller.
65 *
66 * The code is designed to be easily extended with new/different
67 * interrupt controllers, without having to do assembly magic or
68 * having to touch the generic code.
69 *
70 * Controller mappings for all interrupt sources:
71 */
Yinghai Lu85c0f902008-08-19 20:49:47 -070072int nr_irqs = NR_IRQS;
Ingo Molnarfa42d102008-08-19 20:50:30 -070073EXPORT_SYMBOL_GPL(nr_irqs);
Yinghai Lud60458b2008-08-19 20:50:00 -070074
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080075#ifdef CONFIG_SPARSE_IRQ
Mike Travis92296c62009-01-11 09:22:58 -080076
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080077static struct irq_desc irq_desc_init = {
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +000078 .status = IRQ_DISABLED,
79 .handle_irq = handle_bad_irq,
80 .depth = 1,
81 .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080082};
83
Paul Mundt948cd522009-05-22 10:40:09 +090084void __ref 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 Lufebcb0c2010-02-10 01:20:32 -080088 ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs),
89 GFP_ATOMIC, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080090
Yinghai Lu005bf0e62009-02-08 16:18:03 -080091 /*
92 * don't overwite if can not get new one
93 * init_copy_kstat_irqs() could still use old one
94 */
95 if (ptr) {
Yinghai Lu85ac16d2009-04-27 18:00:38 -070096 printk(KERN_DEBUG " alloc kstat_irqs on node %d\n", node);
Yinghai Lu005bf0e62009-02-08 16:18:03 -080097 desc->kstat_irqs = ptr;
98 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -080099}
100
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700101static void init_one_irq_desc(int irq, struct irq_desc *desc, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800102{
103 memcpy(desc, &irq_desc_init, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +0100104
Thomas Gleixner239007b2009-11-17 16:46:45 +0100105 raw_spin_lock_init(&desc->lock);
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000106 desc->irq_data.irq = irq;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800107#ifdef CONFIG_SMP
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200108 desc->irq_data.node = node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800109#endif
110 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700111 init_kstat_irqs(desc, node, nr_cpu_ids);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800112 if (!desc->kstat_irqs) {
113 printk(KERN_ERR "can not alloc kstat_irqs\n");
114 BUG_ON(1);
115 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700116 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800117 printk(KERN_ERR "can not alloc irq_desc cpumasks\n");
118 BUG_ON(1);
119 }
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700120 init_desc_masks(desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700121 arch_init_chip_data(desc, node);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800122}
123
124/*
125 * Protect the sparse_irqs:
126 */
Thomas Gleixner239007b2009-11-17 16:46:45 +0100127DEFINE_RAW_SPINLOCK(sparse_irq_lock);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800128
Yinghai Lub5eb78f2010-02-10 01:20:35 -0800129static RADIX_TREE(irq_desc_tree, GFP_ATOMIC);
130
131static void set_irq_desc(unsigned int irq, struct irq_desc *desc)
132{
133 radix_tree_insert(&irq_desc_tree, irq, desc);
134}
135
136struct irq_desc *irq_to_desc(unsigned int irq)
137{
138 return radix_tree_lookup(&irq_desc_tree, irq);
139}
140
141void replace_irq_desc(unsigned int irq, struct irq_desc *desc)
142{
143 void **ptr;
144
145 ptr = radix_tree_lookup_slot(&irq_desc_tree, irq);
146 if (ptr)
147 radix_tree_replace_slot(ptr, desc);
148}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800149
Yinghai Lu99d093d2008-12-05 18:58:32 -0800150static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = {
151 [0 ... NR_IRQS_LEGACY-1] = {
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000152 .status = IRQ_DISABLED,
153 .handle_irq = handle_bad_irq,
154 .depth = 1,
155 .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800156 }
157};
158
Mike Travis542d8652009-01-10 22:24:07 -0800159static unsigned int *kstat_irqs_legacy;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800160
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800161int __init early_irq_init(void)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800162{
163 struct irq_desc *desc;
164 int legacy_count;
Yinghai Ludad213a2009-05-28 18:14:40 -0700165 int node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800166 int i;
167
David Daney97179fd2009-01-27 09:53:22 -0800168 init_irq_default_affinity();
169
Yinghai Lu4a046d12009-01-12 17:39:24 -0800170 /* initialize nr_irqs based on nr_cpu_ids */
171 arch_probe_nr_irqs();
Mike Travis95949492009-01-10 22:24:06 -0800172 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
173
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800174 desc = irq_desc_legacy;
175 legacy_count = ARRAY_SIZE(irq_desc_legacy);
Yinghai Lu372e24b2009-08-26 16:20:13 -0700176 node = first_online_node;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800177
Mike Travis542d8652009-01-10 22:24:07 -0800178 /* allocate based on nr_cpu_ids */
Yinghai Ludad213a2009-05-28 18:14:40 -0700179 kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids *
180 sizeof(int), GFP_NOWAIT, node);
Mike Travis542d8652009-01-10 22:24:07 -0800181
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000182 irq_desc_init.irq_data.chip = &no_irq_chip;
183
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800184 for (i = 0; i < legacy_count; i++) {
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000185 desc[i].irq_data.irq = i;
186 desc[i].irq_data.chip = &no_irq_chip;
Yinghai Lu372e24b2009-08-26 16:20:13 -0700187#ifdef CONFIG_SMP
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200188 desc[i].irq_data.node = node;
Yinghai Lu372e24b2009-08-26 16:20:13 -0700189#endif
Mike Travis542d8652009-01-10 22:24:07 -0800190 desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;
Yinghai Lufa6beb32008-12-22 20:24:09 -0800191 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Yinghai Ludad213a2009-05-28 18:14:40 -0700192 alloc_desc_masks(&desc[i], node, true);
Yinghai Lu9ec4fa22009-04-27 17:57:18 -0700193 init_desc_masks(&desc[i]);
Yinghai Lub5eb78f2010-02-10 01:20:35 -0800194 set_irq_desc(i, &desc[i]);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800195 }
196
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800197 return arch_early_irq_init();
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800198}
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
Yinghai Lub5eb78f2010-02-10 01:20:35 -0800211 desc = irq_to_desc(irq);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800212 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 */
Yinghai Lub5eb78f2010-02-10 01:20:35 -0800218 desc = irq_to_desc(irq);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800219 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
Yinghai Lub5eb78f2010-02-10 01:20:35 -0800231 set_irq_desc(irq, desc);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800232
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] = {
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000243 .status = IRQ_DISABLED,
244 .handle_irq = handle_bad_irq,
245 .depth = 1,
246 .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248};
Yinghai Lu08678b02008-08-19 20:50:05 -0700249
Yinghai Lud7e51e62009-01-07 15:03:13 -0800250static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS];
Yinghai Lu12026ea2008-12-26 22:38:15 -0800251int __init early_irq_init(void)
252{
253 struct irq_desc *desc;
254 int count;
255 int i;
256
David Daney97179fd2009-01-27 09:53:22 -0800257 init_irq_default_affinity();
258
Mike Travis95949492009-01-10 22:24:06 -0800259 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
260
Yinghai Lu12026ea2008-12-26 22:38:15 -0800261 desc = irq_desc;
262 count = ARRAY_SIZE(irq_desc);
263
Yinghai Lud7e51e62009-01-07 15:03:13 -0800264 for (i = 0; i < count; i++) {
Thomas Gleixnerff7dcd42010-09-27 12:44:25 +0000265 desc[i].irq_data.irq = i;
266 desc[i].irq_data.chip = &no_irq_chip;
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 do {
Jason Baronaf392412009-02-26 10:11:05 -0500373 trace_irq_handler_entry(irq, action);
David Howells7d12e782006-10-05 14:55:46 +0100374 ret = action->handler(irq, action->dev_id);
Jason Baronaf392412009-02-26 10:11:05 -0500375 trace_irq_handler_exit(irq, action, ret);
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100376
377 switch (ret) {
378 case IRQ_WAKE_THREAD:
379 /*
Thomas Gleixnerf48fe812009-03-24 11:46:22 +0100380 * Set result to handled so the spurious check
381 * does not trigger.
382 */
383 ret = IRQ_HANDLED;
384
385 /*
386 * Catch drivers which return WAKE_THREAD but
387 * did not set up a thread function
388 */
389 if (unlikely(!action->thread_fn)) {
390 warn_no_thread(irq, action);
391 break;
392 }
393
394 /*
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100395 * Wake up the handler thread for this
396 * action. In case the thread crashed and was
397 * killed we just pretend that we handled the
398 * interrupt. The hardirq handler above has
399 * disabled the device interrupt, so no irq
400 * storm is lurking.
401 */
402 if (likely(!test_bit(IRQTF_DIED,
403 &action->thread_flags))) {
404 set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
405 wake_up_process(action->thread);
406 }
407
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100408 /* Fall through to add to randomness */
409 case IRQ_HANDLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 status |= action->flags;
Thomas Gleixner3aa551c2009-03-23 18:28:15 +0100411 break;
412
413 default:
414 break;
415 }
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 retval |= ret;
418 action = action->next;
419 } while (action);
420
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700421 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 add_interrupt_randomness(irq);
423 local_irq_disable();
424
425 return retval;
426}
427
David Howellsaf8c65b2006-09-25 23:32:07 -0700428#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Thomas Gleixner0e57aa12009-03-13 14:34:05 +0100429
430#ifdef CONFIG_ENABLE_WARN_DEPRECATED
431# warning __do_IRQ is deprecated. Please convert to proper flow handlers
432#endif
433
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700434/**
435 * __do_IRQ - original all in one highlevel IRQ handler
436 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700437 *
438 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 * SMP cross-CPU interrupts have their own specific
440 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700441 *
442 * This is the original x86 implementation which is used for every
443 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800445unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Yinghai Lu08678b02008-08-19 20:50:05 -0700447 struct irq_desc *desc = irq_to_desc(irq);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700448 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 unsigned int status;
450
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200451 kstat_incr_irqs_this_cpu(irq, desc);
452
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700453 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 irqreturn_t action_ret;
455
456 /*
457 * No locking required for CPU-local interrupts:
458 */
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200459 if (desc->irq_data.chip->ack)
460 desc->irq_data.chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800461 if (likely(!(desc->status & IRQ_DISABLED))) {
462 action_ret = handle_IRQ_event(irq, desc->action);
463 if (!noirqdebug)
464 note_interrupt(irq, desc, action_ret);
465 }
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200466 desc->irq_data.chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return 1;
468 }
469
Thomas Gleixner239007b2009-11-17 16:46:45 +0100470 raw_spin_lock(&desc->lock);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200471 if (desc->irq_data.chip->ack)
472 desc->irq_data.chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 /*
474 * REPLAY is when Linux resends an IRQ that was dropped earlier
475 * WAITING is used by probe to mark irqs that are being tested
476 */
477 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
478 status |= IRQ_PENDING; /* we _want_ to handle it */
479
480 /*
481 * If the IRQ is disabled for whatever reason, we cannot
482 * use the action we have.
483 */
484 action = NULL;
485 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
486 action = desc->action;
487 status &= ~IRQ_PENDING; /* we commit to handling */
488 status |= IRQ_INPROGRESS; /* we are handling it */
489 }
490 desc->status = status;
491
492 /*
493 * If there is no IRQ handler or it was disabled, exit early.
494 * Since we set PENDING, if another processor is handling
495 * a different instance of this same irq, the other processor
496 * will take care of it.
497 */
498 if (unlikely(!action))
499 goto out;
500
501 /*
502 * Edge triggered interrupts need to remember
503 * pending events.
504 * This applies to any hw interrupts that allow a second
505 * instance of the same irq to arrive while we are in do_IRQ
506 * or in the handler. But the code here only handles the _second_
507 * instance of the irq, not the third or fourth. So it is mostly
508 * useful for irq hardware that does not mask cleanly in an
509 * SMP environment.
510 */
511 for (;;) {
512 irqreturn_t action_ret;
513
Thomas Gleixner239007b2009-11-17 16:46:45 +0100514 raw_spin_unlock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
David Howells7d12e782006-10-05 14:55:46 +0100516 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100518 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800519
Thomas Gleixner239007b2009-11-17 16:46:45 +0100520 raw_spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (likely(!(desc->status & IRQ_PENDING)))
522 break;
523 desc->status &= ~IRQ_PENDING;
524 }
525 desc->status &= ~IRQ_INPROGRESS;
526
527out:
528 /*
529 * The ->end() handler has to deal with interrupts which got
530 * disabled while the handler was running.
531 */
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200532 desc->irq_data.chip->end(irq);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100533 raw_spin_unlock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 return 1;
536}
David Howellsaf8c65b2006-09-25 23:32:07 -0700537#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Ingo Molnar243c7622006-07-03 00:25:06 -0700539void early_init_irq_lock_class(void)
540{
Thomas Gleixner10e58082008-10-16 14:19:04 +0200541 struct irq_desc *desc;
Ingo Molnar243c7622006-07-03 00:25:06 -0700542 int i;
543
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800544 for_each_irq_desc(i, desc) {
Thomas Gleixner10e58082008-10-16 14:19:04 +0200545 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800546 }
Yinghai Lu08678b02008-08-19 20:50:05 -0700547}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800548
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800549unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
550{
551 struct irq_desc *desc = irq_to_desc(irq);
KOSAKI Motohiro26ddd8d2008-12-26 14:24:10 +0900552 return desc ? desc->kstat_irqs[cpu] : 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800553}
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800554EXPORT_SYMBOL(kstat_irqs_cpu);
555