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