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