Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/irq/handle.c |
| 3 | * |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 4 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
| 5 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file contains the core interrupt handling code. |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 8 | * |
| 9 | * Detailed information is available in Documentation/DocBook/genericirq |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 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> |
| 18 | |
| 19 | #include "internals.h" |
| 20 | |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 21 | /** |
| 22 | * handle_bad_irq - handle spurious and unhandled irqs |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 23 | * @irq: the interrupt number |
| 24 | * @desc: description of the interrupt |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 25 | * |
| 26 | * Handles spurious and unhandled IRQ's. It also prints a debugmessage. |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 27 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 28 | void handle_bad_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 29 | { |
Ingo Molnar | 43f7775 | 2006-06-29 02:24:58 -0700 | [diff] [blame] | 30 | print_irq_desc(irq, desc); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 31 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 32 | ack_bad_irq(irq); |
| 33 | } |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Linux has a controller-independent interrupt architecture. |
| 37 | * Every controller has a 'controller-template', that is used |
| 38 | * by the main code to do the right thing. Each driver-visible |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 39 | * interrupt source is transparently wired to the appropriate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * controller. Thus drivers need not be aware of the |
| 41 | * interrupt-controller. |
| 42 | * |
| 43 | * The code is designed to be easily extended with new/different |
| 44 | * interrupt controllers, without having to do assembly magic or |
| 45 | * having to touch the generic code. |
| 46 | * |
| 47 | * Controller mappings for all interrupt sources: |
| 48 | */ |
Yinghai Lu | 85c0f90 | 2008-08-19 20:49:47 -0700 | [diff] [blame] | 49 | int nr_irqs = NR_IRQS; |
Ingo Molnar | fa42d10 | 2008-08-19 20:50:30 -0700 | [diff] [blame] | 50 | EXPORT_SYMBOL_GPL(nr_irqs); |
Yinghai Lu | d60458b | 2008-08-19 20:50:00 -0700 | [diff] [blame] | 51 | |
Ravikiran G Thirumalai | e729aa1 | 2007-05-08 00:29:13 -0700 | [diff] [blame] | 52 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | [0 ... NR_IRQS-1] = { |
Zhang, Yanmin | 4f167fb | 2005-05-16 21:53:43 -0700 | [diff] [blame] | 54 | .status = IRQ_DISABLED, |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 55 | .chip = &no_irq_chip, |
Ingo Molnar | 7a55713 | 2006-06-29 02:24:54 -0700 | [diff] [blame] | 56 | .handle_irq = handle_bad_irq, |
Thomas Gleixner | 94d39e1 | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 57 | .depth = 1, |
Yinghai Lu | aac3f2b | 2008-09-24 19:04:35 -0700 | [diff] [blame] | 58 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 59 | #ifdef CONFIG_SMP |
| 60 | .affinity = CPU_MASK_ALL |
| 61 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | }; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 66 | * What should we do if we get a hw irq event on an illegal vector? |
| 67 | * Each architecture has to answer this themself. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 69 | static void ack_bad(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 71 | struct irq_desc *desc = irq_to_desc(irq); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 72 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 73 | print_irq_desc(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | ack_bad_irq(irq); |
| 75 | } |
| 76 | |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 77 | /* |
| 78 | * NOP functions |
| 79 | */ |
| 80 | static void noop(unsigned int irq) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | static unsigned int noop_ret(unsigned int irq) |
| 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Generic no controller implementation |
| 91 | */ |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 92 | struct irq_chip no_irq_chip = { |
| 93 | .name = "none", |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 94 | .startup = noop_ret, |
| 95 | .shutdown = noop, |
| 96 | .enable = noop, |
| 97 | .disable = noop, |
| 98 | .ack = ack_bad, |
| 99 | .end = noop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /* |
Thomas Gleixner | f8b5473 | 2006-07-01 22:30:08 +0100 | [diff] [blame] | 103 | * Generic dummy implementation which can be used for |
| 104 | * real dumb interrupt sources |
| 105 | */ |
| 106 | struct irq_chip dummy_irq_chip = { |
| 107 | .name = "dummy", |
| 108 | .startup = noop_ret, |
| 109 | .shutdown = noop, |
| 110 | .enable = noop, |
| 111 | .disable = noop, |
| 112 | .ack = noop, |
| 113 | .mask = noop, |
| 114 | .unmask = noop, |
| 115 | .end = noop, |
| 116 | }; |
| 117 | |
| 118 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | * Special, empty irq handler: |
| 120 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 121 | irqreturn_t no_action(int cpl, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | return IRQ_NONE; |
| 124 | } |
| 125 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 126 | /** |
| 127 | * handle_IRQ_event - irq action chain handler |
| 128 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 129 | * @action: the interrupt action chain for this irq |
| 130 | * |
| 131 | * Handles the action chain of an irq event |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 133 | irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Jan Beulich | 908dcec | 2006-06-23 02:06:00 -0700 | [diff] [blame] | 135 | irqreturn_t ret, retval = IRQ_NONE; |
| 136 | unsigned int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 138 | if (!(action->flags & IRQF_DISABLED)) |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 139 | local_irq_enable_in_hardirq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | do { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 142 | ret = action->handler(irq, action->dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (ret == IRQ_HANDLED) |
| 144 | status |= action->flags; |
| 145 | retval |= ret; |
| 146 | action = action->next; |
| 147 | } while (action); |
| 148 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 149 | if (status & IRQF_SAMPLE_RANDOM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | add_interrupt_randomness(irq); |
| 151 | local_irq_disable(); |
| 152 | |
| 153 | return retval; |
| 154 | } |
| 155 | |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 156 | #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 157 | /** |
| 158 | * __do_IRQ - original all in one highlevel IRQ handler |
| 159 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 160 | * |
| 161 | * __do_IRQ handles all normal device IRQ's (the special |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * SMP cross-CPU interrupts have their own specific |
| 163 | * handlers). |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 164 | * |
| 165 | * This is the original x86 implementation which is used for every |
| 166 | * interrupt type. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 168 | unsigned int __do_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 170 | struct irq_desc *desc = irq_to_desc(irq); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 171 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | unsigned int status; |
| 173 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 174 | kstat_incr_irqs_this_cpu(irq, desc); |
| 175 | |
Karsten Wiese | f26fdd5 | 2005-09-06 15:17:25 -0700 | [diff] [blame] | 176 | if (CHECK_IRQ_PER_CPU(desc->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | irqreturn_t action_ret; |
| 178 | |
| 179 | /* |
| 180 | * No locking required for CPU-local interrupts: |
| 181 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 182 | if (desc->chip->ack) |
| 183 | desc->chip->ack(irq); |
Russ Anderson | c642b83 | 2007-11-14 17:00:15 -0800 | [diff] [blame] | 184 | if (likely(!(desc->status & IRQ_DISABLED))) { |
| 185 | action_ret = handle_IRQ_event(irq, desc->action); |
| 186 | if (!noirqdebug) |
| 187 | note_interrupt(irq, desc, action_ret); |
| 188 | } |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 189 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | spin_lock(&desc->lock); |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 194 | if (desc->chip->ack) |
| 195 | desc->chip->ack(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | /* |
| 197 | * REPLAY is when Linux resends an IRQ that was dropped earlier |
| 198 | * WAITING is used by probe to mark irqs that are being tested |
| 199 | */ |
| 200 | status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); |
| 201 | status |= IRQ_PENDING; /* we _want_ to handle it */ |
| 202 | |
| 203 | /* |
| 204 | * If the IRQ is disabled for whatever reason, we cannot |
| 205 | * use the action we have. |
| 206 | */ |
| 207 | action = NULL; |
| 208 | if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { |
| 209 | action = desc->action; |
| 210 | status &= ~IRQ_PENDING; /* we commit to handling */ |
| 211 | status |= IRQ_INPROGRESS; /* we are handling it */ |
| 212 | } |
| 213 | desc->status = status; |
| 214 | |
| 215 | /* |
| 216 | * If there is no IRQ handler or it was disabled, exit early. |
| 217 | * Since we set PENDING, if another processor is handling |
| 218 | * a different instance of this same irq, the other processor |
| 219 | * will take care of it. |
| 220 | */ |
| 221 | if (unlikely(!action)) |
| 222 | goto out; |
| 223 | |
| 224 | /* |
| 225 | * Edge triggered interrupts need to remember |
| 226 | * pending events. |
| 227 | * This applies to any hw interrupts that allow a second |
| 228 | * instance of the same irq to arrive while we are in do_IRQ |
| 229 | * or in the handler. But the code here only handles the _second_ |
| 230 | * instance of the irq, not the third or fourth. So it is mostly |
| 231 | * useful for irq hardware that does not mask cleanly in an |
| 232 | * SMP environment. |
| 233 | */ |
| 234 | for (;;) { |
| 235 | irqreturn_t action_ret; |
| 236 | |
| 237 | spin_unlock(&desc->lock); |
| 238 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 239 | action_ret = handle_IRQ_event(irq, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | if (!noirqdebug) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 241 | note_interrupt(irq, desc, action_ret); |
Linus Torvalds | b42172f | 2006-11-22 09:32:06 -0800 | [diff] [blame] | 242 | |
| 243 | spin_lock(&desc->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if (likely(!(desc->status & IRQ_PENDING))) |
| 245 | break; |
| 246 | desc->status &= ~IRQ_PENDING; |
| 247 | } |
| 248 | desc->status &= ~IRQ_INPROGRESS; |
| 249 | |
| 250 | out: |
| 251 | /* |
| 252 | * The ->end() handler has to deal with interrupts which got |
| 253 | * disabled while the handler was running. |
| 254 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 255 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | spin_unlock(&desc->lock); |
| 257 | |
| 258 | return 1; |
| 259 | } |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 260 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 262 | |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 263 | #ifdef CONFIG_TRACE_IRQFLAGS |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 264 | /* |
| 265 | * lockdep: we want to handle all irq_desc locks as a single lock-class: |
| 266 | */ |
| 267 | static struct lock_class_key irq_desc_lock_class; |
| 268 | |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 269 | void early_init_irq_lock_class(void) |
| 270 | { |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame^] | 271 | struct irq_desc *desc; |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 272 | int i; |
| 273 | |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame^] | 274 | for_each_irq_desc(i, desc) |
| 275 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 276 | } |
| 277 | #endif |