Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Derived from arch/i386/kernel/irq.c |
| 3 | * Copyright (C) 1992 Linus Torvalds |
| 4 | * Adapted from arch/i386 by Gary Thomas |
| 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 6 | * Updated and modified by Cort Dougan <cort@fsmlabs.com> |
| 7 | * Copyright (C) 1996-2001 Cort Dougan |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Adapted for Power Macintosh by Paul Mackerras |
| 9 | * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au) |
| 10 | * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk). |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version |
| 15 | * 2 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This file contains the code used by various IRQ handling routines: |
| 18 | * asking for different IRQ's should be done through these routines |
| 19 | * instead of just grabbing them. Thus setups with different IRQ numbers |
| 20 | * shouldn't result in any weird surprises, and installing new handlers |
| 21 | * should be easier. |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 22 | * |
| 23 | * The MPC8xx has an interrupt mask in the SIU. If a bit is set, the |
| 24 | * interrupt is _enabled_. As expected, IRQ0 is bit 0 in the 32-bit |
| 25 | * mask register (of which only 16 are defined), hence the weird shifting |
| 26 | * and complement of the cached_irq_mask. I want to be able to stuff |
| 27 | * this right into the SIU SMASK register. |
| 28 | * Many of the prep/chrp functions are conditional compiled on CONFIG_8xx |
| 29 | * to reduce code space and undefined function references. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 32 | #undef DEBUG |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/threads.h> |
| 36 | #include <linux/kernel_stat.h> |
| 37 | #include <linux/signal.h> |
| 38 | #include <linux/sched.h> |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 39 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/ioport.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | #include <linux/timex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/init.h> |
| 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/delay.h> |
| 46 | #include <linux/irq.h> |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 47 | #include <linux/seq_file.h> |
| 48 | #include <linux/cpumask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/profile.h> |
| 50 | #include <linux/bitops.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 51 | #include <linux/list.h> |
| 52 | #include <linux/radix-tree.h> |
| 53 | #include <linux/mutex.h> |
| 54 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #include <asm/uaccess.h> |
| 57 | #include <asm/system.h> |
| 58 | #include <asm/io.h> |
| 59 | #include <asm/pgtable.h> |
| 60 | #include <asm/irq.h> |
| 61 | #include <asm/cache.h> |
| 62 | #include <asm/prom.h> |
| 63 | #include <asm/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <asm/machdep.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 65 | #include <asm/udbg.h> |
Stephen Rothwell | a50b56d | 2005-11-17 16:14:17 +1100 | [diff] [blame] | 66 | #ifdef CONFIG_PPC_ISERIES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #endif |
| 69 | |
Stephen Rothwell | 868accb | 2005-11-10 18:38:46 +1100 | [diff] [blame] | 70 | int __irq_offset_value; |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 71 | static int ppc_spurious_interrupts; |
| 72 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 73 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 74 | EXPORT_SYMBOL(__irq_offset_value); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 75 | atomic_t ppc_n_lost_interrupts; |
| 76 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 77 | #ifndef CONFIG_PPC_MERGE |
| 78 | #define NR_MASK_WORDS ((NR_IRQS + 31) / 32) |
| 79 | unsigned long ppc_cached_irq_mask[NR_MASK_WORDS]; |
| 80 | #endif |
| 81 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 82 | #ifdef CONFIG_TAU_INT |
| 83 | extern int tau_initialized; |
| 84 | extern int tau_interrupts(int); |
| 85 | #endif |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 86 | #endif /* CONFIG_PPC32 */ |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 87 | |
| 88 | #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE) |
| 89 | extern atomic_t ipi_recv; |
| 90 | extern atomic_t ipi_sent; |
| 91 | #endif |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 92 | |
| 93 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | EXPORT_SYMBOL(irq_desc); |
| 95 | |
| 96 | int distribute_irqs = 1; |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 97 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | int show_interrupts(struct seq_file *p, void *v) |
| 100 | { |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 101 | int i = *(loff_t *)v, j; |
| 102 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | irq_desc_t *desc; |
| 104 | unsigned long flags; |
| 105 | |
| 106 | if (i == 0) { |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 107 | seq_puts(p, " "); |
| 108 | for_each_online_cpu(j) |
| 109 | seq_printf(p, "CPU%d ", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | seq_putc(p, '\n'); |
| 111 | } |
| 112 | |
| 113 | if (i < NR_IRQS) { |
| 114 | desc = get_irq_desc(i); |
| 115 | spin_lock_irqsave(&desc->lock, flags); |
| 116 | action = desc->action; |
| 117 | if (!action || !action->handler) |
| 118 | goto skip; |
| 119 | seq_printf(p, "%3d: ", i); |
| 120 | #ifdef CONFIG_SMP |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 121 | for_each_online_cpu(j) |
| 122 | seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #else |
| 124 | seq_printf(p, "%10u ", kstat_irqs(i)); |
| 125 | #endif /* CONFIG_SMP */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 126 | if (desc->chip) |
| 127 | seq_printf(p, " %s ", desc->chip->typename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | else |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 129 | seq_puts(p, " None "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | seq_printf(p, "%s", (desc->status & IRQ_LEVEL) ? "Level " : "Edge "); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 131 | seq_printf(p, " %s", action->name); |
| 132 | for (action = action->next; action; action = action->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | seq_printf(p, ", %s", action->name); |
| 134 | seq_putc(p, '\n'); |
| 135 | skip: |
| 136 | spin_unlock_irqrestore(&desc->lock, flags); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 137 | } else if (i == NR_IRQS) { |
| 138 | #ifdef CONFIG_PPC32 |
| 139 | #ifdef CONFIG_TAU_INT |
| 140 | if (tau_initialized){ |
| 141 | seq_puts(p, "TAU: "); |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 142 | for_each_online_cpu(j) |
| 143 | seq_printf(p, "%10u ", tau_interrupts(j)); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 144 | seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n"); |
| 145 | } |
| 146 | #endif |
| 147 | #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE) |
| 148 | /* should this be per processor send/receive? */ |
| 149 | seq_printf(p, "IPI (recv/sent): %10u/%u\n", |
| 150 | atomic_read(&ipi_recv), atomic_read(&ipi_sent)); |
| 151 | #endif |
| 152 | #endif /* CONFIG_PPC32 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | seq_printf(p, "BAD: %10u\n", ppc_spurious_interrupts); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | #ifdef CONFIG_HOTPLUG_CPU |
| 159 | void fixup_irqs(cpumask_t map) |
| 160 | { |
| 161 | unsigned int irq; |
| 162 | static int warned; |
| 163 | |
| 164 | for_each_irq(irq) { |
| 165 | cpumask_t mask; |
| 166 | |
| 167 | if (irq_desc[irq].status & IRQ_PER_CPU) |
| 168 | continue; |
| 169 | |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 170 | cpus_and(mask, irq_desc[irq].affinity, map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | if (any_online_cpu(mask) == NR_CPUS) { |
| 172 | printk("Breaking affinity for irq %i\n", irq); |
| 173 | mask = map; |
| 174 | } |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 175 | if (irq_desc[irq].chip->set_affinity) |
| 176 | irq_desc[irq].chip->set_affinity(irq, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | else if (irq_desc[irq].action && !(warned++)) |
| 178 | printk("Cannot set affinity for irq %i\n", irq); |
| 179 | } |
| 180 | |
| 181 | local_irq_enable(); |
| 182 | mdelay(1); |
| 183 | local_irq_disable(); |
| 184 | } |
| 185 | #endif |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | void do_IRQ(struct pt_regs *regs) |
| 188 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 189 | unsigned int irq; |
Stephen Rothwell | b709c08 | 2005-11-09 13:28:33 +1100 | [diff] [blame] | 190 | #ifdef CONFIG_IRQSTACKS |
| 191 | struct thread_info *curtp, *irqtp; |
| 192 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 194 | irq_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
| 197 | /* Debugging check for stack overflow: is there less than 2KB free? */ |
| 198 | { |
| 199 | long sp; |
| 200 | |
| 201 | sp = __get_SP() & (THREAD_SIZE-1); |
| 202 | |
| 203 | if (unlikely(sp < (sizeof(struct thread_info) + 2048))) { |
| 204 | printk("do_IRQ: stack overflow: %ld\n", |
| 205 | sp - sizeof(struct thread_info)); |
| 206 | dump_stack(); |
| 207 | } |
| 208 | } |
| 209 | #endif |
| 210 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 211 | /* |
| 212 | * Every platform is required to implement ppc_md.get_irq. |
| 213 | * This function will either return an irq number or -1 to |
| 214 | * indicate there are no more pending. |
| 215 | * The value -2 is for buggy hardware and means that this IRQ |
| 216 | * has already been handled. -- Tom |
| 217 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | irq = ppc_md.get_irq(regs); |
| 219 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 220 | if (irq != NO_IRQ && irq != NO_IRQ_IGNORE) { |
Stephen Rothwell | b709c08 | 2005-11-09 13:28:33 +1100 | [diff] [blame] | 221 | #ifdef CONFIG_IRQSTACKS |
| 222 | /* Switch to the irq stack to handle this */ |
| 223 | curtp = current_thread_info(); |
| 224 | irqtp = hardirq_ctx[smp_processor_id()]; |
| 225 | if (curtp != irqtp) { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 226 | struct irq_desc *desc = irq_desc + irq; |
| 227 | void *handler = desc->handle_irq; |
| 228 | if (handler == NULL) |
| 229 | handler = &__do_IRQ; |
Stephen Rothwell | b709c08 | 2005-11-09 13:28:33 +1100 | [diff] [blame] | 230 | irqtp->task = curtp->task; |
| 231 | irqtp->flags = 0; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 232 | call_handle_irq(irq, desc, regs, irqtp, handler); |
Stephen Rothwell | b709c08 | 2005-11-09 13:28:33 +1100 | [diff] [blame] | 233 | irqtp->task = NULL; |
| 234 | if (irqtp->flags) |
| 235 | set_bits(irqtp->flags, &curtp->flags); |
| 236 | } else |
| 237 | #endif |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 238 | generic_handle_irq(irq, regs); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 239 | } else if (irq != NO_IRQ_IGNORE) |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 240 | /* That's not SMP safe ... but who cares ? */ |
| 241 | ppc_spurious_interrupts++; |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 242 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 243 | irq_exit(); |
| 244 | |
| 245 | #ifdef CONFIG_PPC_ISERIES |
David Gibson | 3356bb9 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 246 | if (get_lppaca()->int_dword.fields.decr_int) { |
| 247 | get_lppaca()->int_dword.fields.decr_int = 0; |
| 248 | /* Signal a fake decrementer interrupt */ |
| 249 | timer_interrupt(regs); |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 250 | } |
| 251 | #endif |
| 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | void __init init_IRQ(void) |
| 255 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | ppc_md.init_IRQ(); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 257 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | irq_ctx_init(); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 259 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | #ifdef CONFIG_IRQSTACKS |
Andreas Mohr | 2272205 | 2006-06-23 02:05:30 -0700 | [diff] [blame] | 264 | struct thread_info *softirq_ctx[NR_CPUS] __read_mostly; |
| 265 | struct thread_info *hardirq_ctx[NR_CPUS] __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | void irq_ctx_init(void) |
| 268 | { |
| 269 | struct thread_info *tp; |
| 270 | int i; |
| 271 | |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 272 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | memset((void *)softirq_ctx[i], 0, THREAD_SIZE); |
| 274 | tp = softirq_ctx[i]; |
| 275 | tp->cpu = i; |
| 276 | tp->preempt_count = SOFTIRQ_OFFSET; |
| 277 | |
| 278 | memset((void *)hardirq_ctx[i], 0, THREAD_SIZE); |
| 279 | tp = hardirq_ctx[i]; |
| 280 | tp->cpu = i; |
| 281 | tp->preempt_count = HARDIRQ_OFFSET; |
| 282 | } |
| 283 | } |
| 284 | |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 285 | static inline void do_softirq_onstack(void) |
| 286 | { |
| 287 | struct thread_info *curtp, *irqtp; |
| 288 | |
| 289 | curtp = current_thread_info(); |
| 290 | irqtp = softirq_ctx[smp_processor_id()]; |
| 291 | irqtp->task = curtp->task; |
| 292 | call_do_softirq(irqtp); |
| 293 | irqtp->task = NULL; |
| 294 | } |
| 295 | |
| 296 | #else |
| 297 | #define do_softirq_onstack() __do_softirq() |
| 298 | #endif /* CONFIG_IRQSTACKS */ |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | void do_softirq(void) |
| 301 | { |
| 302 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | if (in_interrupt()) |
| 305 | return; |
| 306 | |
| 307 | local_irq_save(flags); |
| 308 | |
Paul Mackerras | 829035f | 2006-07-03 00:25:40 -0700 | [diff] [blame] | 309 | if (local_softirq_pending()) |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 310 | do_softirq_onstack(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | local_irq_restore(flags); |
| 313 | } |
| 314 | EXPORT_SYMBOL(do_softirq); |
| 315 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 316 | |
| 317 | /* |
| 318 | * IRQ controller and virtual interrupts |
| 319 | */ |
| 320 | |
| 321 | #ifdef CONFIG_PPC_MERGE |
| 322 | |
| 323 | static LIST_HEAD(irq_hosts); |
| 324 | static spinlock_t irq_big_lock = SPIN_LOCK_UNLOCKED; |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 325 | static DEFINE_PER_CPU(unsigned int, irq_radix_reader); |
| 326 | static unsigned int irq_radix_writer; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 327 | struct irq_map_entry irq_map[NR_IRQS]; |
| 328 | static unsigned int irq_virq_count = NR_IRQS; |
| 329 | static struct irq_host *irq_default_host; |
| 330 | |
| 331 | struct irq_host *irq_alloc_host(unsigned int revmap_type, |
| 332 | unsigned int revmap_arg, |
| 333 | struct irq_host_ops *ops, |
| 334 | irq_hw_number_t inval_irq) |
| 335 | { |
| 336 | struct irq_host *host; |
| 337 | unsigned int size = sizeof(struct irq_host); |
| 338 | unsigned int i; |
| 339 | unsigned int *rmap; |
| 340 | unsigned long flags; |
| 341 | |
| 342 | /* Allocate structure and revmap table if using linear mapping */ |
| 343 | if (revmap_type == IRQ_HOST_MAP_LINEAR) |
| 344 | size += revmap_arg * sizeof(unsigned int); |
| 345 | if (mem_init_done) |
| 346 | host = kzalloc(size, GFP_KERNEL); |
| 347 | else { |
| 348 | host = alloc_bootmem(size); |
| 349 | if (host) |
| 350 | memset(host, 0, size); |
| 351 | } |
| 352 | if (host == NULL) |
| 353 | return NULL; |
| 354 | |
| 355 | /* Fill structure */ |
| 356 | host->revmap_type = revmap_type; |
| 357 | host->inval_irq = inval_irq; |
| 358 | host->ops = ops; |
| 359 | |
| 360 | spin_lock_irqsave(&irq_big_lock, flags); |
| 361 | |
| 362 | /* If it's a legacy controller, check for duplicates and |
| 363 | * mark it as allocated (we use irq 0 host pointer for that |
| 364 | */ |
| 365 | if (revmap_type == IRQ_HOST_MAP_LEGACY) { |
| 366 | if (irq_map[0].host != NULL) { |
| 367 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 368 | /* If we are early boot, we can't free the structure, |
| 369 | * too bad... |
| 370 | * this will be fixed once slab is made available early |
| 371 | * instead of the current cruft |
| 372 | */ |
| 373 | if (mem_init_done) |
| 374 | kfree(host); |
| 375 | return NULL; |
| 376 | } |
| 377 | irq_map[0].host = host; |
| 378 | } |
| 379 | |
| 380 | list_add(&host->link, &irq_hosts); |
| 381 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 382 | |
| 383 | /* Additional setups per revmap type */ |
| 384 | switch(revmap_type) { |
| 385 | case IRQ_HOST_MAP_LEGACY: |
| 386 | /* 0 is always the invalid number for legacy */ |
| 387 | host->inval_irq = 0; |
| 388 | /* setup us as the host for all legacy interrupts */ |
| 389 | for (i = 1; i < NUM_ISA_INTERRUPTS; i++) { |
| 390 | irq_map[i].hwirq = 0; |
| 391 | smp_wmb(); |
| 392 | irq_map[i].host = host; |
| 393 | smp_wmb(); |
| 394 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 395 | /* Clear norequest flags */ |
| 396 | get_irq_desc(i)->status &= ~IRQ_NOREQUEST; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 397 | |
| 398 | /* Legacy flags are left to default at this point, |
| 399 | * one can then use irq_create_mapping() to |
| 400 | * explicitely change them |
| 401 | */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 402 | ops->map(host, i, i); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 403 | } |
| 404 | break; |
| 405 | case IRQ_HOST_MAP_LINEAR: |
| 406 | rmap = (unsigned int *)(host + 1); |
| 407 | for (i = 0; i < revmap_arg; i++) |
| 408 | rmap[i] = IRQ_NONE; |
| 409 | host->revmap_data.linear.size = revmap_arg; |
| 410 | smp_wmb(); |
| 411 | host->revmap_data.linear.revmap = rmap; |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | pr_debug("irq: Allocated host of type %d @0x%p\n", revmap_type, host); |
| 418 | |
| 419 | return host; |
| 420 | } |
| 421 | |
| 422 | struct irq_host *irq_find_host(struct device_node *node) |
| 423 | { |
| 424 | struct irq_host *h, *found = NULL; |
| 425 | unsigned long flags; |
| 426 | |
| 427 | /* We might want to match the legacy controller last since |
| 428 | * it might potentially be set to match all interrupts in |
| 429 | * the absence of a device node. This isn't a problem so far |
| 430 | * yet though... |
| 431 | */ |
| 432 | spin_lock_irqsave(&irq_big_lock, flags); |
| 433 | list_for_each_entry(h, &irq_hosts, link) |
| 434 | if (h->ops->match == NULL || h->ops->match(h, node)) { |
| 435 | found = h; |
| 436 | break; |
| 437 | } |
| 438 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 439 | return found; |
| 440 | } |
| 441 | EXPORT_SYMBOL_GPL(irq_find_host); |
| 442 | |
| 443 | void irq_set_default_host(struct irq_host *host) |
| 444 | { |
| 445 | pr_debug("irq: Default host set to @0x%p\n", host); |
| 446 | |
| 447 | irq_default_host = host; |
| 448 | } |
| 449 | |
| 450 | void irq_set_virq_count(unsigned int count) |
| 451 | { |
| 452 | pr_debug("irq: Trying to set virq count to %d\n", count); |
| 453 | |
| 454 | BUG_ON(count < NUM_ISA_INTERRUPTS); |
| 455 | if (count < NR_IRQS) |
| 456 | irq_virq_count = count; |
| 457 | } |
| 458 | |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 459 | /* radix tree not lockless safe ! we use a brlock-type mecanism |
| 460 | * for now, until we can use a lockless radix tree |
| 461 | */ |
| 462 | static void irq_radix_wrlock(unsigned long *flags) |
| 463 | { |
| 464 | unsigned int cpu, ok; |
| 465 | |
| 466 | spin_lock_irqsave(&irq_big_lock, *flags); |
| 467 | irq_radix_writer = 1; |
| 468 | smp_mb(); |
| 469 | do { |
| 470 | barrier(); |
| 471 | ok = 1; |
| 472 | for_each_possible_cpu(cpu) { |
| 473 | if (per_cpu(irq_radix_reader, cpu)) { |
| 474 | ok = 0; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | if (!ok) |
| 479 | cpu_relax(); |
| 480 | } while(!ok); |
| 481 | } |
| 482 | |
| 483 | static void irq_radix_wrunlock(unsigned long flags) |
| 484 | { |
| 485 | smp_wmb(); |
| 486 | irq_radix_writer = 0; |
| 487 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 488 | } |
| 489 | |
| 490 | static void irq_radix_rdlock(unsigned long *flags) |
| 491 | { |
| 492 | local_irq_save(*flags); |
| 493 | __get_cpu_var(irq_radix_reader) = 1; |
| 494 | smp_mb(); |
| 495 | if (likely(irq_radix_writer == 0)) |
| 496 | return; |
| 497 | __get_cpu_var(irq_radix_reader) = 0; |
| 498 | smp_wmb(); |
| 499 | spin_lock(&irq_big_lock); |
| 500 | __get_cpu_var(irq_radix_reader) = 1; |
| 501 | spin_unlock(&irq_big_lock); |
| 502 | } |
| 503 | |
| 504 | static void irq_radix_rdunlock(unsigned long flags) |
| 505 | { |
| 506 | __get_cpu_var(irq_radix_reader) = 0; |
| 507 | local_irq_restore(flags); |
| 508 | } |
| 509 | |
| 510 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 511 | unsigned int irq_create_mapping(struct irq_host *host, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 512 | irq_hw_number_t hwirq) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 513 | { |
| 514 | unsigned int virq, hint; |
| 515 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 516 | pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", host, hwirq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 517 | |
| 518 | /* Look for default host if nececssary */ |
| 519 | if (host == NULL) |
| 520 | host = irq_default_host; |
| 521 | if (host == NULL) { |
| 522 | printk(KERN_WARNING "irq_create_mapping called for" |
| 523 | " NULL host, hwirq=%lx\n", hwirq); |
| 524 | WARN_ON(1); |
| 525 | return NO_IRQ; |
| 526 | } |
| 527 | pr_debug("irq: -> using host @%p\n", host); |
| 528 | |
| 529 | /* Check if mapping already exist, if it does, call |
| 530 | * host->ops->map() to update the flags |
| 531 | */ |
| 532 | virq = irq_find_mapping(host, hwirq); |
| 533 | if (virq != IRQ_NONE) { |
| 534 | pr_debug("irq: -> existing mapping on virq %d\n", virq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 535 | return virq; |
| 536 | } |
| 537 | |
| 538 | /* Get a virtual interrupt number */ |
| 539 | if (host->revmap_type == IRQ_HOST_MAP_LEGACY) { |
| 540 | /* Handle legacy */ |
| 541 | virq = (unsigned int)hwirq; |
| 542 | if (virq == 0 || virq >= NUM_ISA_INTERRUPTS) |
| 543 | return NO_IRQ; |
| 544 | return virq; |
| 545 | } else { |
| 546 | /* Allocate a virtual interrupt number */ |
| 547 | hint = hwirq % irq_virq_count; |
| 548 | virq = irq_alloc_virt(host, 1, hint); |
| 549 | if (virq == NO_IRQ) { |
| 550 | pr_debug("irq: -> virq allocation failed\n"); |
| 551 | return NO_IRQ; |
| 552 | } |
| 553 | } |
| 554 | pr_debug("irq: -> obtained virq %d\n", virq); |
| 555 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 556 | /* Clear IRQ_NOREQUEST flag */ |
| 557 | get_irq_desc(virq)->status &= ~IRQ_NOREQUEST; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 558 | |
| 559 | /* map it */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 560 | smp_wmb(); |
| 561 | irq_map[virq].hwirq = hwirq; |
| 562 | smp_mb(); |
| 563 | if (host->ops->map(host, virq, hwirq)) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 564 | pr_debug("irq: -> mapping failed, freeing\n"); |
| 565 | irq_free_virt(virq, 1); |
| 566 | return NO_IRQ; |
| 567 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 568 | return virq; |
| 569 | } |
| 570 | EXPORT_SYMBOL_GPL(irq_create_mapping); |
| 571 | |
| 572 | extern unsigned int irq_create_of_mapping(struct device_node *controller, |
| 573 | u32 *intspec, unsigned int intsize) |
| 574 | { |
| 575 | struct irq_host *host; |
| 576 | irq_hw_number_t hwirq; |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 577 | unsigned int type = IRQ_TYPE_NONE; |
| 578 | unsigned int virq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 579 | |
| 580 | if (controller == NULL) |
| 581 | host = irq_default_host; |
| 582 | else |
| 583 | host = irq_find_host(controller); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 584 | if (host == NULL) { |
| 585 | printk(KERN_WARNING "irq: no irq host found for %s !\n", |
| 586 | controller->full_name); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 587 | return NO_IRQ; |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 588 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 589 | |
| 590 | /* If host has no translation, then we assume interrupt line */ |
| 591 | if (host->ops->xlate == NULL) |
| 592 | hwirq = intspec[0]; |
| 593 | else { |
| 594 | if (host->ops->xlate(host, controller, intspec, intsize, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 595 | &hwirq, &type)) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 596 | return NO_IRQ; |
| 597 | } |
| 598 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 599 | /* Create mapping */ |
| 600 | virq = irq_create_mapping(host, hwirq); |
| 601 | if (virq == NO_IRQ) |
| 602 | return virq; |
| 603 | |
| 604 | /* Set type if specified and different than the current one */ |
| 605 | if (type != IRQ_TYPE_NONE && |
| 606 | type != (get_irq_desc(virq)->status & IRQF_TRIGGER_MASK)) |
| 607 | set_irq_type(virq, type); |
| 608 | return virq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 609 | } |
| 610 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); |
| 611 | |
| 612 | unsigned int irq_of_parse_and_map(struct device_node *dev, int index) |
| 613 | { |
| 614 | struct of_irq oirq; |
| 615 | |
| 616 | if (of_irq_map_one(dev, index, &oirq)) |
| 617 | return NO_IRQ; |
| 618 | |
| 619 | return irq_create_of_mapping(oirq.controller, oirq.specifier, |
| 620 | oirq.size); |
| 621 | } |
| 622 | EXPORT_SYMBOL_GPL(irq_of_parse_and_map); |
| 623 | |
| 624 | void irq_dispose_mapping(unsigned int virq) |
| 625 | { |
| 626 | struct irq_host *host = irq_map[virq].host; |
| 627 | irq_hw_number_t hwirq; |
| 628 | unsigned long flags; |
| 629 | |
| 630 | WARN_ON (host == NULL); |
| 631 | if (host == NULL) |
| 632 | return; |
| 633 | |
| 634 | /* Never unmap legacy interrupts */ |
| 635 | if (host->revmap_type == IRQ_HOST_MAP_LEGACY) |
| 636 | return; |
| 637 | |
| 638 | /* remove chip and handler */ |
| 639 | set_irq_chip_and_handler(virq, NULL, NULL); |
| 640 | |
| 641 | /* Make sure it's completed */ |
| 642 | synchronize_irq(virq); |
| 643 | |
| 644 | /* Tell the PIC about it */ |
| 645 | if (host->ops->unmap) |
| 646 | host->ops->unmap(host, virq); |
| 647 | smp_mb(); |
| 648 | |
| 649 | /* Clear reverse map */ |
| 650 | hwirq = irq_map[virq].hwirq; |
| 651 | switch(host->revmap_type) { |
| 652 | case IRQ_HOST_MAP_LINEAR: |
| 653 | if (hwirq < host->revmap_data.linear.size) |
| 654 | host->revmap_data.linear.revmap[hwirq] = IRQ_NONE; |
| 655 | break; |
| 656 | case IRQ_HOST_MAP_TREE: |
| 657 | /* Check if radix tree allocated yet */ |
| 658 | if (host->revmap_data.tree.gfp_mask == 0) |
| 659 | break; |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 660 | irq_radix_wrlock(&flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 661 | radix_tree_delete(&host->revmap_data.tree, hwirq); |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 662 | irq_radix_wrunlock(flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 663 | break; |
| 664 | } |
| 665 | |
| 666 | /* Destroy map */ |
| 667 | smp_mb(); |
| 668 | irq_map[virq].hwirq = host->inval_irq; |
| 669 | |
| 670 | /* Set some flags */ |
| 671 | get_irq_desc(virq)->status |= IRQ_NOREQUEST; |
| 672 | |
| 673 | /* Free it */ |
| 674 | irq_free_virt(virq, 1); |
| 675 | } |
| 676 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); |
| 677 | |
| 678 | unsigned int irq_find_mapping(struct irq_host *host, |
| 679 | irq_hw_number_t hwirq) |
| 680 | { |
| 681 | unsigned int i; |
| 682 | unsigned int hint = hwirq % irq_virq_count; |
| 683 | |
| 684 | /* Look for default host if nececssary */ |
| 685 | if (host == NULL) |
| 686 | host = irq_default_host; |
| 687 | if (host == NULL) |
| 688 | return NO_IRQ; |
| 689 | |
| 690 | /* legacy -> bail early */ |
| 691 | if (host->revmap_type == IRQ_HOST_MAP_LEGACY) |
| 692 | return hwirq; |
| 693 | |
| 694 | /* Slow path does a linear search of the map */ |
| 695 | if (hint < NUM_ISA_INTERRUPTS) |
| 696 | hint = NUM_ISA_INTERRUPTS; |
| 697 | i = hint; |
| 698 | do { |
| 699 | if (irq_map[i].host == host && |
| 700 | irq_map[i].hwirq == hwirq) |
| 701 | return i; |
| 702 | i++; |
| 703 | if (i >= irq_virq_count) |
| 704 | i = NUM_ISA_INTERRUPTS; |
| 705 | } while(i != hint); |
| 706 | return NO_IRQ; |
| 707 | } |
| 708 | EXPORT_SYMBOL_GPL(irq_find_mapping); |
| 709 | |
| 710 | |
| 711 | unsigned int irq_radix_revmap(struct irq_host *host, |
| 712 | irq_hw_number_t hwirq) |
| 713 | { |
| 714 | struct radix_tree_root *tree; |
| 715 | struct irq_map_entry *ptr; |
| 716 | unsigned int virq; |
| 717 | unsigned long flags; |
| 718 | |
| 719 | WARN_ON(host->revmap_type != IRQ_HOST_MAP_TREE); |
| 720 | |
| 721 | /* Check if the radix tree exist yet. We test the value of |
| 722 | * the gfp_mask for that. Sneaky but saves another int in the |
| 723 | * structure. If not, we fallback to slow mode |
| 724 | */ |
| 725 | tree = &host->revmap_data.tree; |
| 726 | if (tree->gfp_mask == 0) |
| 727 | return irq_find_mapping(host, hwirq); |
| 728 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 729 | /* Now try to resolve */ |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 730 | irq_radix_rdlock(&flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 731 | ptr = radix_tree_lookup(tree, hwirq); |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 732 | irq_radix_rdunlock(flags); |
| 733 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 734 | /* Found it, return */ |
| 735 | if (ptr) { |
| 736 | virq = ptr - irq_map; |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 737 | return virq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* If not there, try to insert it */ |
| 741 | virq = irq_find_mapping(host, hwirq); |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 742 | if (virq != NO_IRQ) { |
| 743 | irq_radix_wrlock(&flags); |
Benjamin Herrenschmidt | e5c14ce | 2006-08-17 03:59:27 +0200 | [diff] [blame] | 744 | radix_tree_insert(tree, hwirq, &irq_map[virq]); |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 745 | irq_radix_wrunlock(flags); |
| 746 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 747 | return virq; |
| 748 | } |
| 749 | |
| 750 | unsigned int irq_linear_revmap(struct irq_host *host, |
| 751 | irq_hw_number_t hwirq) |
| 752 | { |
| 753 | unsigned int *revmap; |
| 754 | |
| 755 | WARN_ON(host->revmap_type != IRQ_HOST_MAP_LINEAR); |
| 756 | |
| 757 | /* Check revmap bounds */ |
| 758 | if (unlikely(hwirq >= host->revmap_data.linear.size)) |
| 759 | return irq_find_mapping(host, hwirq); |
| 760 | |
| 761 | /* Check if revmap was allocated */ |
| 762 | revmap = host->revmap_data.linear.revmap; |
| 763 | if (unlikely(revmap == NULL)) |
| 764 | return irq_find_mapping(host, hwirq); |
| 765 | |
| 766 | /* Fill up revmap with slow path if no mapping found */ |
| 767 | if (unlikely(revmap[hwirq] == NO_IRQ)) |
| 768 | revmap[hwirq] = irq_find_mapping(host, hwirq); |
| 769 | |
| 770 | return revmap[hwirq]; |
| 771 | } |
| 772 | |
| 773 | unsigned int irq_alloc_virt(struct irq_host *host, |
| 774 | unsigned int count, |
| 775 | unsigned int hint) |
| 776 | { |
| 777 | unsigned long flags; |
| 778 | unsigned int i, j, found = NO_IRQ; |
| 779 | unsigned int limit = irq_virq_count - count; |
| 780 | |
| 781 | if (count == 0 || count > (irq_virq_count - NUM_ISA_INTERRUPTS)) |
| 782 | return NO_IRQ; |
| 783 | |
| 784 | spin_lock_irqsave(&irq_big_lock, flags); |
| 785 | |
| 786 | /* Use hint for 1 interrupt if any */ |
| 787 | if (count == 1 && hint >= NUM_ISA_INTERRUPTS && |
| 788 | hint < irq_virq_count && irq_map[hint].host == NULL) { |
| 789 | found = hint; |
| 790 | goto hint_found; |
| 791 | } |
| 792 | |
| 793 | /* Look for count consecutive numbers in the allocatable |
| 794 | * (non-legacy) space |
| 795 | */ |
| 796 | for (i = NUM_ISA_INTERRUPTS; i <= limit; ) { |
| 797 | for (j = i; j < (i + count); j++) |
| 798 | if (irq_map[j].host != NULL) { |
| 799 | i = j + 1; |
| 800 | continue; |
| 801 | } |
| 802 | found = i; |
| 803 | break; |
| 804 | } |
| 805 | if (found == NO_IRQ) { |
| 806 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 807 | return NO_IRQ; |
| 808 | } |
| 809 | hint_found: |
| 810 | for (i = found; i < (found + count); i++) { |
| 811 | irq_map[i].hwirq = host->inval_irq; |
| 812 | smp_wmb(); |
| 813 | irq_map[i].host = host; |
| 814 | } |
| 815 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 816 | return found; |
| 817 | } |
| 818 | |
| 819 | void irq_free_virt(unsigned int virq, unsigned int count) |
| 820 | { |
| 821 | unsigned long flags; |
| 822 | unsigned int i; |
| 823 | |
| 824 | WARN_ON (virq < NUM_ISA_INTERRUPTS); |
| 825 | WARN_ON (count == 0 || (virq + count) > irq_virq_count); |
| 826 | |
| 827 | spin_lock_irqsave(&irq_big_lock, flags); |
| 828 | for (i = virq; i < (virq + count); i++) { |
| 829 | struct irq_host *host; |
| 830 | |
| 831 | if (i < NUM_ISA_INTERRUPTS || |
| 832 | (virq + count) > irq_virq_count) |
| 833 | continue; |
| 834 | |
| 835 | host = irq_map[i].host; |
| 836 | irq_map[i].hwirq = host->inval_irq; |
| 837 | smp_wmb(); |
| 838 | irq_map[i].host = NULL; |
| 839 | } |
| 840 | spin_unlock_irqrestore(&irq_big_lock, flags); |
| 841 | } |
| 842 | |
| 843 | void irq_early_init(void) |
| 844 | { |
| 845 | unsigned int i; |
| 846 | |
| 847 | for (i = 0; i < NR_IRQS; i++) |
| 848 | get_irq_desc(i)->status |= IRQ_NOREQUEST; |
| 849 | } |
| 850 | |
| 851 | /* We need to create the radix trees late */ |
| 852 | static int irq_late_init(void) |
| 853 | { |
| 854 | struct irq_host *h; |
| 855 | unsigned long flags; |
| 856 | |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 857 | irq_radix_wrlock(&flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 858 | list_for_each_entry(h, &irq_hosts, link) { |
| 859 | if (h->revmap_type == IRQ_HOST_MAP_TREE) |
| 860 | INIT_RADIX_TREE(&h->revmap_data.tree, GFP_ATOMIC); |
| 861 | } |
Benjamin Herrenschmidt | 8ec8f2e | 2006-08-28 11:17:37 +1000 | [diff] [blame^] | 862 | irq_radix_wrunlock(flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | arch_initcall(irq_late_init); |
| 867 | |
| 868 | #endif /* CONFIG_PPC_MERGE */ |
| 869 | |
Jake Moilanen | 204face | 2006-06-07 16:15:10 -0500 | [diff] [blame] | 870 | #ifdef CONFIG_PCI_MSI |
| 871 | int pci_enable_msi(struct pci_dev * pdev) |
| 872 | { |
| 873 | if (ppc_md.enable_msi) |
| 874 | return ppc_md.enable_msi(pdev); |
| 875 | else |
| 876 | return -1; |
| 877 | } |
| 878 | |
| 879 | void pci_disable_msi(struct pci_dev * pdev) |
| 880 | { |
| 881 | if (ppc_md.disable_msi) |
| 882 | ppc_md.disable_msi(pdev); |
| 883 | } |
| 884 | |
| 885 | void pci_scan_msi_device(struct pci_dev *dev) {} |
| 886 | int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) {return -1;} |
| 887 | void pci_disable_msix(struct pci_dev *dev) {} |
| 888 | void msi_remove_pci_irq_vectors(struct pci_dev *dev) {} |
| 889 | void disable_msi_mode(struct pci_dev *dev, int pos, int type) {} |
| 890 | void pci_no_msi(void) {} |
| 891 | |
| 892 | #endif |
| 893 | |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 894 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | static int __init setup_noirqdistrib(char *str) |
| 896 | { |
| 897 | distribute_irqs = 0; |
| 898 | return 1; |
| 899 | } |
| 900 | |
| 901 | __setup("noirqdistrib", setup_noirqdistrib); |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 902 | #endif /* CONFIG_PPC64 */ |