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