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