David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 1 | /* irq.c: UltraSparc IRQ handling/init/registry. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 3 | * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) |
| 5 | * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz) |
| 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/module.h> |
| 9 | #include <linux/sched.h> |
| 10 | #include <linux/ptrace.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/kernel_stat.h> |
| 13 | #include <linux/signal.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/random.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/proc_fs.h> |
| 21 | #include <linux/seq_file.h> |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 22 | #include <linux/bootmem.h> |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 23 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <asm/ptrace.h> |
| 26 | #include <asm/processor.h> |
| 27 | #include <asm/atomic.h> |
| 28 | #include <asm/system.h> |
| 29 | #include <asm/irq.h> |
Sven Hartge | 2e457ef | 2005-10-08 21:12:04 -0700 | [diff] [blame] | 30 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/sbus.h> |
| 32 | #include <asm/iommu.h> |
| 33 | #include <asm/upa.h> |
| 34 | #include <asm/oplib.h> |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 35 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/timer.h> |
| 37 | #include <asm/smp.h> |
| 38 | #include <asm/starfire.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | #include <asm/cache.h> |
| 41 | #include <asm/cpudata.h> |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 42 | #include <asm/auxio.h> |
David S. Miller | 92704a1 | 2006-02-26 23:27:19 -0800 | [diff] [blame] | 43 | #include <asm/head.h> |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 44 | #include <asm/hypervisor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* UPA nodes send interrupt packet to UltraSparc with first data reg |
| 47 | * value low 5 (7 on Starfire) bits holding the IRQ identifier being |
| 48 | * delivered. We must translate this into a non-vector IRQ so we can |
| 49 | * set the softint on this cpu. |
| 50 | * |
| 51 | * To make processing these packets efficient and race free we use |
| 52 | * an array of irq buckets below. The interrupt vector handler in |
| 53 | * entry.S feeds incoming packets into per-cpu pil-indexed lists. |
| 54 | * The IVEC handler does not need to act atomically, the PIL dispatch |
| 55 | * code uses CAS to get an atomic snapshot of the list and clear it |
| 56 | * at the same time. |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 57 | * |
| 58 | * If you make changes to ino_bucket, please update hand coded assembler |
| 59 | * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | */ |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 61 | struct ino_bucket { |
| 62 | /* Next handler in per-CPU IRQ worklist. We know that |
| 63 | * bucket pointers have the high 32-bits clear, so to |
| 64 | * save space we only store the bits we need. |
| 65 | */ |
| 66 | /*0x00*/unsigned int irq_chain; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 68 | /* Virtual interrupt number assigned to this INO. */ |
| 69 | /*0x04*/unsigned int virt_irq; |
| 70 | }; |
| 71 | |
| 72 | #define NUM_IVECS (IMAP_INR + 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES))); |
| 74 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 75 | #define __irq_ino(irq) \ |
| 76 | (((struct ino_bucket *)(unsigned long)(irq)) - &ivector_table[0]) |
| 77 | #define __bucket(irq) ((struct ino_bucket *)(unsigned long)(irq)) |
| 78 | #define __irq(bucket) ((unsigned int)(unsigned long)(bucket)) |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* This has to be in the main kernel image, it cannot be |
| 81 | * turned into per-cpu data. The reason is that the main |
| 82 | * kernel image is locked into the TLB and this structure |
| 83 | * is accessed from the vectored interrupt trap handler. If |
| 84 | * access to this structure takes a TLB miss it could cause |
| 85 | * the 5-level sparc v9 trap stack to overflow. |
| 86 | */ |
David S. Miller | fd0504c3 | 2006-06-20 01:20:00 -0700 | [diff] [blame] | 87 | #define irq_work(__cpu) &(trap_block[(__cpu)].irq_worklist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 89 | static struct { |
| 90 | unsigned int irq; |
| 91 | unsigned int dev_handle; |
| 92 | unsigned int dev_ino; |
| 93 | } virt_to_real_irq_table[NR_IRQS]; |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 94 | static DEFINE_SPINLOCK(virt_irq_alloc_lock); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 95 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 96 | unsigned char virt_irq_alloc(unsigned int real_irq) |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 97 | { |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 98 | unsigned long flags; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 99 | unsigned char ent; |
| 100 | |
| 101 | BUILD_BUG_ON(NR_IRQS >= 256); |
| 102 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 103 | spin_lock_irqsave(&virt_irq_alloc_lock, flags); |
| 104 | |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 105 | for (ent = 1; ent < NR_IRQS; ent++) { |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 106 | if (!virt_to_real_irq_table[ent].irq) |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 107 | break; |
| 108 | } |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 109 | if (ent >= NR_IRQS) { |
| 110 | printk(KERN_ERR "IRQ: Out of virtual IRQs.\n"); |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 111 | ent = 0; |
| 112 | } else { |
| 113 | virt_to_real_irq_table[ent].irq = real_irq; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 114 | } |
| 115 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 116 | spin_unlock_irqrestore(&virt_irq_alloc_lock, flags); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 117 | |
| 118 | return ent; |
| 119 | } |
| 120 | |
David S. Miller | 5746c99 | 2007-02-20 01:26:48 -0800 | [diff] [blame] | 121 | #ifdef CONFIG_PCI_MSI |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 122 | void virt_irq_free(unsigned int virt_irq) |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 123 | { |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 124 | unsigned long flags; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 125 | |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 126 | if (virt_irq >= NR_IRQS) |
| 127 | return; |
| 128 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 129 | spin_lock_irqsave(&virt_irq_alloc_lock, flags); |
| 130 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 131 | virt_to_real_irq_table[virt_irq].irq = 0; |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 132 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 133 | spin_unlock_irqrestore(&virt_irq_alloc_lock, flags); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 134 | } |
David S. Miller | 5746c99 | 2007-02-20 01:26:48 -0800 | [diff] [blame] | 135 | #endif |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 136 | |
| 137 | static unsigned int virt_to_real_irq(unsigned char virt_irq) |
| 138 | { |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 139 | return virt_to_real_irq_table[virt_irq].irq; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 143 | * /proc/interrupts printing: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | int show_interrupts(struct seq_file *p, void *v) |
| 147 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 148 | int i = *(loff_t *) v, j; |
| 149 | struct irqaction * action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 152 | if (i == 0) { |
| 153 | seq_printf(p, " "); |
| 154 | for_each_online_cpu(j) |
| 155 | seq_printf(p, "CPU%d ",j); |
| 156 | seq_putc(p, '\n'); |
| 157 | } |
| 158 | |
| 159 | if (i < NR_IRQS) { |
| 160 | spin_lock_irqsave(&irq_desc[i].lock, flags); |
| 161 | action = irq_desc[i].action; |
| 162 | if (!action) |
| 163 | goto skip; |
| 164 | seq_printf(p, "%3d: ",i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #ifndef CONFIG_SMP |
| 166 | seq_printf(p, "%10u ", kstat_irqs(i)); |
| 167 | #else |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 168 | for_each_online_cpu(j) |
| 169 | seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #endif |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 171 | seq_printf(p, " %9s", irq_desc[i].chip->typename); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 172 | seq_printf(p, " %s", action->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 174 | for (action=action->next; action; action = action->next) |
| 175 | seq_printf(p, ", %s", action->name); |
| 176 | |
| 177 | seq_putc(p, '\n'); |
| 178 | skip: |
| 179 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
David S. Miller | ebd8c56 | 2006-02-17 08:38:06 -0800 | [diff] [blame] | 184 | static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid) |
| 185 | { |
| 186 | unsigned int tid; |
| 187 | |
| 188 | if (this_is_starfire) { |
| 189 | tid = starfire_translate(imap, cpuid); |
| 190 | tid <<= IMAP_TID_SHIFT; |
| 191 | tid &= IMAP_TID_UPA; |
| 192 | } else { |
| 193 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 194 | unsigned long ver; |
| 195 | |
| 196 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); |
| 197 | if ((ver >> 32UL) == __JALAPENO_ID || |
| 198 | (ver >> 32UL) == __SERRANO_ID) { |
| 199 | tid = cpuid << IMAP_TID_SHIFT; |
| 200 | tid &= IMAP_TID_JBUS; |
| 201 | } else { |
| 202 | unsigned int a = cpuid & 0x1f; |
| 203 | unsigned int n = (cpuid >> 5) & 0x1f; |
| 204 | |
| 205 | tid = ((a << IMAP_AID_SHIFT) | |
| 206 | (n << IMAP_NID_SHIFT)); |
| 207 | tid &= (IMAP_AID_SAFARI | |
| 208 | IMAP_NID_SAFARI);; |
| 209 | } |
| 210 | } else { |
| 211 | tid = cpuid << IMAP_TID_SHIFT; |
| 212 | tid &= IMAP_TID_UPA; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return tid; |
| 217 | } |
| 218 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 219 | struct irq_handler_data { |
| 220 | unsigned long iclr; |
| 221 | unsigned long imap; |
| 222 | |
| 223 | void (*pre_handler)(unsigned int, void *, void *); |
| 224 | void *pre_handler_arg1; |
| 225 | void *pre_handler_arg2; |
| 226 | }; |
| 227 | |
| 228 | static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 230 | unsigned int real_irq = virt_to_real_irq(virt_irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 231 | struct ino_bucket *bucket = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 233 | if (likely(real_irq)) |
| 234 | bucket = __bucket(real_irq); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 235 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 236 | return bucket; |
| 237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 239 | #ifdef CONFIG_SMP |
| 240 | static int irq_choose_cpu(unsigned int virt_irq) |
| 241 | { |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 242 | cpumask_t mask = irq_desc[virt_irq].affinity; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 243 | int cpuid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 245 | if (cpus_equal(mask, CPU_MASK_ALL)) { |
| 246 | static int irq_rover; |
| 247 | static DEFINE_SPINLOCK(irq_rover_lock); |
| 248 | unsigned long flags; |
David S. Miller | ebd8c56 | 2006-02-17 08:38:06 -0800 | [diff] [blame] | 249 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 250 | /* Round-robin distribution... */ |
| 251 | do_round_robin: |
| 252 | spin_lock_irqsave(&irq_rover_lock, flags); |
| 253 | |
| 254 | while (!cpu_online(irq_rover)) { |
| 255 | if (++irq_rover >= NR_CPUS) |
| 256 | irq_rover = 0; |
| 257 | } |
| 258 | cpuid = irq_rover; |
| 259 | do { |
| 260 | if (++irq_rover >= NR_CPUS) |
| 261 | irq_rover = 0; |
| 262 | } while (!cpu_online(irq_rover)); |
| 263 | |
| 264 | spin_unlock_irqrestore(&irq_rover_lock, flags); |
| 265 | } else { |
| 266 | cpumask_t tmp; |
| 267 | |
| 268 | cpus_and(tmp, cpu_online_map, mask); |
| 269 | |
| 270 | if (cpus_empty(tmp)) |
| 271 | goto do_round_robin; |
| 272 | |
| 273 | cpuid = first_cpu(tmp); |
| 274 | } |
| 275 | |
| 276 | return cpuid; |
| 277 | } |
| 278 | #else |
| 279 | static int irq_choose_cpu(unsigned int virt_irq) |
| 280 | { |
| 281 | return real_hard_smp_processor_id(); |
| 282 | } |
| 283 | #endif |
| 284 | |
| 285 | static void sun4u_irq_enable(unsigned int virt_irq) |
| 286 | { |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 287 | struct irq_handler_data *data = get_irq_chip_data(virt_irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 288 | |
| 289 | if (likely(data)) { |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 290 | unsigned long cpuid, imap, val; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 291 | unsigned int tid; |
| 292 | |
| 293 | cpuid = irq_choose_cpu(virt_irq); |
| 294 | imap = data->imap; |
| 295 | |
| 296 | tid = sun4u_compute_tid(imap, cpuid); |
| 297 | |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 298 | val = upa_readq(imap); |
| 299 | val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS | |
| 300 | IMAP_AID_SAFARI | IMAP_NID_SAFARI); |
| 301 | val |= tid | IMAP_VALID; |
| 302 | upa_writeq(val, imap); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 306 | static void sun4u_set_affinity(unsigned int virt_irq, cpumask_t mask) |
| 307 | { |
| 308 | sun4u_irq_enable(virt_irq); |
| 309 | } |
| 310 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 311 | static void sun4u_irq_disable(unsigned int virt_irq) |
| 312 | { |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 313 | struct irq_handler_data *data = get_irq_chip_data(virt_irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 314 | |
| 315 | if (likely(data)) { |
| 316 | unsigned long imap = data->imap; |
David S. Miller | 6e69d60 | 2007-08-28 14:25:32 -0700 | [diff] [blame] | 317 | unsigned long tmp = upa_readq(imap); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 318 | |
| 319 | tmp &= ~IMAP_VALID; |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 320 | upa_writeq(tmp, imap); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | static void sun4u_irq_end(unsigned int virt_irq) |
| 325 | { |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 326 | struct irq_handler_data *data = get_irq_chip_data(virt_irq); |
David S. Miller | 5a606b7 | 2007-07-09 22:40:36 -0700 | [diff] [blame] | 327 | struct irq_desc *desc = irq_desc + virt_irq; |
| 328 | |
| 329 | if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 330 | return; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 331 | |
| 332 | if (likely(data)) |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 333 | upa_writeq(ICLR_IDLE, data->iclr); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void sun4v_irq_enable(unsigned int virt_irq) |
| 337 | { |
| 338 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
| 339 | unsigned int ino = bucket - &ivector_table[0]; |
| 340 | |
| 341 | if (likely(bucket)) { |
| 342 | unsigned long cpuid; |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame] | 343 | int err; |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 344 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 345 | cpuid = irq_choose_cpu(virt_irq); |
| 346 | |
David S. Miller | ebd8c56 | 2006-02-17 08:38:06 -0800 | [diff] [blame] | 347 | err = sun4v_intr_settarget(ino, cpuid); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame] | 348 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 349 | printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): " |
| 350 | "err(%d)\n", ino, cpuid, err); |
David S. Miller | a357b8f | 2007-06-26 00:13:31 -0700 | [diff] [blame] | 351 | err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
| 352 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 353 | printk(KERN_ERR "sun4v_intr_setstate(%x): " |
David S. Miller | a357b8f | 2007-06-26 00:13:31 -0700 | [diff] [blame] | 354 | "err(%d)\n", ino, err); |
David S. Miller | abd92b2 | 2006-02-14 22:20:13 -0800 | [diff] [blame] | 355 | err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame] | 356 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 357 | printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n", |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame] | 358 | ino, err); |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 362 | static void sun4v_set_affinity(unsigned int virt_irq, cpumask_t mask) |
| 363 | { |
| 364 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
| 365 | unsigned int ino = bucket - &ivector_table[0]; |
| 366 | |
| 367 | if (likely(bucket)) { |
| 368 | unsigned long cpuid; |
| 369 | int err; |
| 370 | |
| 371 | cpuid = irq_choose_cpu(virt_irq); |
| 372 | |
| 373 | err = sun4v_intr_settarget(ino, cpuid); |
| 374 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 375 | printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): " |
| 376 | "err(%d)\n", ino, cpuid, err); |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 380 | static void sun4v_irq_disable(unsigned int virt_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 382 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
| 383 | unsigned int ino = bucket - &ivector_table[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 385 | if (likely(bucket)) { |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 386 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 388 | err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED); |
| 389 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 390 | printk(KERN_ERR "sun4v_intr_setenabled(%x): " |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 391 | "err(%d)\n", ino, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 395 | static void sun4v_irq_end(unsigned int virt_irq) |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 396 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 397 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
| 398 | unsigned int ino = bucket - &ivector_table[0]; |
David S. Miller | 5a606b7 | 2007-07-09 22:40:36 -0700 | [diff] [blame] | 399 | struct irq_desc *desc = irq_desc + virt_irq; |
| 400 | |
| 401 | if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 402 | return; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 403 | |
| 404 | if (likely(bucket)) { |
| 405 | int err; |
| 406 | |
| 407 | err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
| 408 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 409 | printk(KERN_ERR "sun4v_intr_setstate(%x): " |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 410 | "err(%d)\n", ino, err); |
| 411 | } |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 412 | } |
| 413 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 414 | static void sun4v_virq_enable(unsigned int virt_irq) |
| 415 | { |
| 416 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 417 | |
| 418 | if (likely(bucket)) { |
| 419 | unsigned long cpuid, dev_handle, dev_ino; |
| 420 | int err; |
| 421 | |
| 422 | cpuid = irq_choose_cpu(virt_irq); |
| 423 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 424 | dev_handle = virt_to_real_irq_table[virt_irq].dev_handle; |
| 425 | dev_ino = virt_to_real_irq_table[virt_irq].dev_ino; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 426 | |
| 427 | err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid); |
| 428 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 429 | printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): " |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 430 | "err(%d)\n", |
| 431 | dev_handle, dev_ino, cpuid, err); |
| 432 | err = sun4v_vintr_set_state(dev_handle, dev_ino, |
David S. Miller | 1245088 | 2007-06-26 00:13:09 -0700 | [diff] [blame] | 433 | HV_INTR_STATE_IDLE); |
| 434 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 435 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
David S. Miller | 1245088 | 2007-06-26 00:13:09 -0700 | [diff] [blame] | 436 | "HV_INTR_STATE_IDLE): err(%d)\n", |
| 437 | dev_handle, dev_ino, err); |
| 438 | err = sun4v_vintr_set_valid(dev_handle, dev_ino, |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 439 | HV_INTR_ENABLED); |
| 440 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 441 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 442 | "HV_INTR_ENABLED): err(%d)\n", |
| 443 | dev_handle, dev_ino, err); |
| 444 | } |
| 445 | } |
| 446 | |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 447 | static void sun4v_virt_set_affinity(unsigned int virt_irq, cpumask_t mask) |
| 448 | { |
| 449 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 450 | |
| 451 | if (likely(bucket)) { |
| 452 | unsigned long cpuid, dev_handle, dev_ino; |
| 453 | int err; |
| 454 | |
| 455 | cpuid = irq_choose_cpu(virt_irq); |
| 456 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 457 | dev_handle = virt_to_real_irq_table[virt_irq].dev_handle; |
| 458 | dev_ino = virt_to_real_irq_table[virt_irq].dev_ino; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 459 | |
| 460 | err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid); |
| 461 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 462 | printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): " |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 463 | "err(%d)\n", |
| 464 | dev_handle, dev_ino, cpuid, err); |
| 465 | } |
| 466 | } |
| 467 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 468 | static void sun4v_virq_disable(unsigned int virt_irq) |
| 469 | { |
| 470 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 471 | |
| 472 | if (likely(bucket)) { |
| 473 | unsigned long dev_handle, dev_ino; |
| 474 | int err; |
| 475 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 476 | dev_handle = virt_to_real_irq_table[virt_irq].dev_handle; |
| 477 | dev_ino = virt_to_real_irq_table[virt_irq].dev_ino; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 478 | |
David S. Miller | 1245088 | 2007-06-26 00:13:09 -0700 | [diff] [blame] | 479 | err = sun4v_vintr_set_valid(dev_handle, dev_ino, |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 480 | HV_INTR_DISABLED); |
| 481 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 482 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 483 | "HV_INTR_DISABLED): err(%d)\n", |
| 484 | dev_handle, dev_ino, err); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | static void sun4v_virq_end(unsigned int virt_irq) |
| 489 | { |
| 490 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
David S. Miller | 5a606b7 | 2007-07-09 22:40:36 -0700 | [diff] [blame] | 491 | struct irq_desc *desc = irq_desc + virt_irq; |
| 492 | |
| 493 | if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 494 | return; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 495 | |
| 496 | if (likely(bucket)) { |
| 497 | unsigned long dev_handle, dev_ino; |
| 498 | int err; |
| 499 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 500 | dev_handle = virt_to_real_irq_table[virt_irq].dev_handle; |
| 501 | dev_ino = virt_to_real_irq_table[virt_irq].dev_ino; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 502 | |
| 503 | err = sun4v_vintr_set_state(dev_handle, dev_ino, |
| 504 | HV_INTR_STATE_IDLE); |
| 505 | if (err != HV_EOK) |
David S. Miller | e83fb17 | 2007-07-20 02:39:04 -0700 | [diff] [blame] | 506 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 507 | "HV_INTR_STATE_IDLE): err(%d)\n", |
| 508 | dev_handle, dev_ino, err); |
| 509 | } |
| 510 | } |
| 511 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 512 | static void run_pre_handler(unsigned int virt_irq) |
| 513 | { |
| 514 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 515 | struct irq_handler_data *data = get_irq_chip_data(virt_irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 516 | |
| 517 | if (likely(data->pre_handler)) { |
| 518 | data->pre_handler(__irq_ino(__irq(bucket)), |
| 519 | data->pre_handler_arg1, |
| 520 | data->pre_handler_arg2); |
| 521 | } |
| 522 | } |
| 523 | |
David S. Miller | 729e7d7 | 2006-12-12 00:59:12 -0800 | [diff] [blame] | 524 | static struct irq_chip sun4u_irq = { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 525 | .typename = "sun4u", |
| 526 | .enable = sun4u_irq_enable, |
| 527 | .disable = sun4u_irq_disable, |
| 528 | .end = sun4u_irq_end, |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 529 | .set_affinity = sun4u_set_affinity, |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 530 | }; |
| 531 | |
David S. Miller | 729e7d7 | 2006-12-12 00:59:12 -0800 | [diff] [blame] | 532 | static struct irq_chip sun4u_irq_ack = { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 533 | .typename = "sun4u+ack", |
| 534 | .enable = sun4u_irq_enable, |
| 535 | .disable = sun4u_irq_disable, |
| 536 | .ack = run_pre_handler, |
| 537 | .end = sun4u_irq_end, |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 538 | .set_affinity = sun4u_set_affinity, |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
David S. Miller | 729e7d7 | 2006-12-12 00:59:12 -0800 | [diff] [blame] | 541 | static struct irq_chip sun4v_irq = { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 542 | .typename = "sun4v", |
| 543 | .enable = sun4v_irq_enable, |
| 544 | .disable = sun4v_irq_disable, |
| 545 | .end = sun4v_irq_end, |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 546 | .set_affinity = sun4v_set_affinity, |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 547 | }; |
| 548 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 549 | static struct irq_chip sun4v_virq = { |
| 550 | .typename = "vsun4v", |
| 551 | .enable = sun4v_virq_enable, |
| 552 | .disable = sun4v_virq_disable, |
| 553 | .end = sun4v_virq_end, |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 554 | .set_affinity = sun4v_virt_set_affinity, |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 555 | }; |
| 556 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 557 | void irq_install_pre_handler(int virt_irq, |
| 558 | void (*func)(unsigned int, void *, void *), |
| 559 | void *arg1, void *arg2) |
| 560 | { |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 561 | struct irq_handler_data *data = get_irq_chip_data(virt_irq); |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 562 | struct irq_chip *chip = get_irq_chip(virt_irq); |
| 563 | |
| 564 | if (WARN_ON(chip == &sun4v_irq || chip == &sun4v_virq)) { |
| 565 | printk(KERN_ERR "IRQ: Trying to install pre-handler on " |
| 566 | "sun4v irq %u\n", virt_irq); |
| 567 | return; |
| 568 | } |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 569 | |
| 570 | data->pre_handler = func; |
| 571 | data->pre_handler_arg1 = arg1; |
| 572 | data->pre_handler_arg2 = arg2; |
| 573 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 574 | if (chip == &sun4u_irq_ack) |
David S. Miller | 24ac26d | 2006-06-29 14:38:21 -0700 | [diff] [blame] | 575 | return; |
| 576 | |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame^] | 577 | set_irq_chip(virt_irq, &sun4u_irq_ack); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | struct ino_bucket *bucket; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 583 | struct irq_handler_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | int ino; |
| 585 | |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 586 | BUG_ON(tlb_type == hypervisor); |
| 587 | |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 588 | ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 589 | bucket = &ivector_table[ino]; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 590 | if (!bucket->virt_irq) { |
| 591 | bucket->virt_irq = virt_irq_alloc(__irq(bucket)); |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 592 | set_irq_chip(bucket->virt_irq, &sun4u_irq); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 593 | } |
| 594 | |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 595 | data = get_irq_chip_data(bucket->virt_irq); |
| 596 | if (unlikely(data)) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 597 | goto out; |
| 598 | |
| 599 | data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC); |
| 600 | if (unlikely(!data)) { |
| 601 | prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n"); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 602 | prom_halt(); |
| 603 | } |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 604 | set_irq_chip_data(bucket->virt_irq, data); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 605 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 606 | data->imap = imap; |
| 607 | data->iclr = iclr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 609 | out: |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 610 | return bucket->virt_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 612 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 613 | static unsigned int sun4v_build_common(unsigned long sysino, |
| 614 | struct irq_chip *chip) |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 615 | { |
| 616 | struct ino_bucket *bucket; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 617 | struct irq_handler_data *data; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 618 | |
| 619 | BUG_ON(tlb_type != hypervisor); |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 620 | |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 621 | bucket = &ivector_table[sysino]; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 622 | if (!bucket->virt_irq) { |
| 623 | bucket->virt_irq = virt_irq_alloc(__irq(bucket)); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 624 | set_irq_chip(bucket->virt_irq, chip); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 625 | } |
| 626 | |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 627 | data = get_irq_chip_data(bucket->virt_irq); |
| 628 | if (unlikely(data)) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 629 | goto out; |
| 630 | |
| 631 | data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC); |
| 632 | if (unlikely(!data)) { |
| 633 | prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n"); |
| 634 | prom_halt(); |
| 635 | } |
David S. Miller | 68c9218 | 2007-01-29 12:12:28 -0800 | [diff] [blame] | 636 | set_irq_chip_data(bucket->virt_irq, data); |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 637 | |
| 638 | /* Catch accidental accesses to these things. IMAP/ICLR handling |
| 639 | * is done by hypervisor calls on sun4v platforms, not by direct |
| 640 | * register accesses. |
| 641 | */ |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 642 | data->imap = ~0UL; |
| 643 | data->iclr = ~0UL; |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 644 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 645 | out: |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 646 | return bucket->virt_irq; |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 647 | } |
| 648 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 649 | unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino) |
| 650 | { |
| 651 | unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino); |
| 652 | |
| 653 | return sun4v_build_common(sysino, &sun4v_irq); |
| 654 | } |
| 655 | |
| 656 | unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino) |
| 657 | { |
| 658 | unsigned long sysino, hv_err; |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 659 | unsigned int virq; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 660 | |
David S. Miller | 5f7426c | 2007-07-18 23:16:51 -0700 | [diff] [blame] | 661 | BUG_ON(devhandle & devino); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 662 | |
| 663 | sysino = devhandle | devino; |
David S. Miller | 5f7426c | 2007-07-18 23:16:51 -0700 | [diff] [blame] | 664 | BUG_ON(sysino & ~(IMAP_IGN | IMAP_INO)); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 665 | |
| 666 | hv_err = sun4v_vintr_set_cookie(devhandle, devino, sysino); |
| 667 | if (hv_err) { |
| 668 | prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] " |
| 669 | "err=%lu\n", devhandle, devino, hv_err); |
| 670 | prom_halt(); |
| 671 | } |
| 672 | |
David S. Miller | 93b3238 | 2007-07-20 02:58:28 -0700 | [diff] [blame] | 673 | virq = sun4v_build_common(sysino, &sun4v_virq); |
| 674 | |
| 675 | virt_to_real_irq_table[virq].dev_handle = devhandle; |
| 676 | virt_to_real_irq_table[virq].dev_ino = devino; |
| 677 | |
| 678 | return virq; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 679 | } |
| 680 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 681 | void ack_bad_irq(unsigned int virt_irq) |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 682 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 683 | struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq); |
| 684 | unsigned int ino = 0xdeadbeef; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 685 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 686 | if (bucket) |
| 687 | ino = bucket - &ivector_table[0]; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 688 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 689 | printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n", |
| 690 | ino, virt_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | void handler_irq(int irq, struct pt_regs *regs) |
| 694 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 695 | struct ino_bucket *bucket; |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 696 | struct pt_regs *old_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | clear_softint(1 << irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 700 | old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | irq_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | /* Sliiiick... */ |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 704 | bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0)); |
| 705 | while (bucket) { |
| 706 | struct ino_bucket *next = __bucket(bucket->irq_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 708 | bucket->irq_chain = 0; |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 709 | __do_IRQ(bucket->virt_irq); |
David S. Miller | fd0504c3 | 2006-06-20 01:20:00 -0700 | [diff] [blame] | 710 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 711 | bucket = next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | irq_exit(); |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 715 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 718 | #ifdef CONFIG_HOTPLUG_CPU |
| 719 | void fixup_irqs(void) |
| 720 | { |
| 721 | unsigned int irq; |
| 722 | |
| 723 | for (irq = 0; irq < NR_IRQS; irq++) { |
| 724 | unsigned long flags; |
| 725 | |
| 726 | spin_lock_irqsave(&irq_desc[irq].lock, flags); |
| 727 | if (irq_desc[irq].action && |
| 728 | !(irq_desc[irq].status & IRQ_PER_CPU)) { |
| 729 | if (irq_desc[irq].chip->set_affinity) |
| 730 | irq_desc[irq].chip->set_affinity(irq, |
| 731 | irq_desc[irq].affinity); |
| 732 | } |
| 733 | spin_unlock_irqrestore(&irq_desc[irq].lock, flags); |
| 734 | } |
| 735 | } |
| 736 | #endif |
| 737 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 738 | struct sun5_timer { |
| 739 | u64 count0; |
| 740 | u64 limit0; |
| 741 | u64 count1; |
| 742 | u64 limit1; |
| 743 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 745 | static struct sun5_timer *prom_timers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | static u64 prom_limit0, prom_limit1; |
| 747 | |
| 748 | static void map_prom_timers(void) |
| 749 | { |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 750 | struct device_node *dp; |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 751 | const unsigned int *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | /* PROM timer node hangs out in the top level of device siblings... */ |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 754 | dp = of_find_node_by_path("/"); |
| 755 | dp = dp->child; |
| 756 | while (dp) { |
| 757 | if (!strcmp(dp->name, "counter-timer")) |
| 758 | break; |
| 759 | dp = dp->sibling; |
| 760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | /* Assume if node is not present, PROM uses different tick mechanism |
| 763 | * which we should not care about. |
| 764 | */ |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 765 | if (!dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | prom_timers = (struct sun5_timer *) 0; |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | /* If PROM is really using this, it must be mapped by him. */ |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 771 | addr = of_get_property(dp, "address", NULL); |
| 772 | if (!addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | prom_printf("PROM does not have timer mapped, trying to continue.\n"); |
| 774 | prom_timers = (struct sun5_timer *) 0; |
| 775 | return; |
| 776 | } |
| 777 | prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]); |
| 778 | } |
| 779 | |
| 780 | static void kill_prom_timer(void) |
| 781 | { |
| 782 | if (!prom_timers) |
| 783 | return; |
| 784 | |
| 785 | /* Save them away for later. */ |
| 786 | prom_limit0 = prom_timers->limit0; |
| 787 | prom_limit1 = prom_timers->limit1; |
| 788 | |
| 789 | /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14. |
| 790 | * We turn both off here just to be paranoid. |
| 791 | */ |
| 792 | prom_timers->limit0 = 0; |
| 793 | prom_timers->limit1 = 0; |
| 794 | |
| 795 | /* Wheee, eat the interrupt packet too... */ |
| 796 | __asm__ __volatile__( |
| 797 | " mov 0x40, %%g2\n" |
| 798 | " ldxa [%%g0] %0, %%g1\n" |
| 799 | " ldxa [%%g2] %1, %%g1\n" |
| 800 | " stxa %%g0, [%%g0] %0\n" |
| 801 | " membar #Sync\n" |
| 802 | : /* no outputs */ |
| 803 | : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R) |
| 804 | : "g1", "g2"); |
| 805 | } |
| 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | void init_irqwork_curcpu(void) |
| 808 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | int cpu = hard_smp_processor_id(); |
| 810 | |
David S. Miller | fd0504c3 | 2006-06-20 01:20:00 -0700 | [diff] [blame] | 811 | trap_block[cpu].irq_worklist = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 814 | /* Please be very careful with register_one_mondo() and |
| 815 | * sun4v_register_mondo_queues(). |
| 816 | * |
| 817 | * On SMP this gets invoked from the CPU trampoline before |
| 818 | * the cpu has fully taken over the trap table from OBP, |
| 819 | * and it's kernel stack + %g6 thread register state is |
| 820 | * not fully cooked yet. |
| 821 | * |
| 822 | * Therefore you cannot make any OBP calls, not even prom_printf, |
| 823 | * from these two routines. |
| 824 | */ |
| 825 | static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type, unsigned long qmask) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 826 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 827 | unsigned long num_entries = (qmask + 1) / 64; |
David S. Miller | 94f8762 | 2006-02-16 14:26:53 -0800 | [diff] [blame] | 828 | unsigned long status; |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 829 | |
David S. Miller | 94f8762 | 2006-02-16 14:26:53 -0800 | [diff] [blame] | 830 | status = sun4v_cpu_qconf(type, paddr, num_entries); |
| 831 | if (status != HV_EOK) { |
| 832 | prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, " |
| 833 | "err %lu\n", type, paddr, num_entries, status); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 834 | prom_halt(); |
| 835 | } |
| 836 | } |
| 837 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 838 | void __cpuinit sun4v_register_mondo_queues(int this_cpu) |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 839 | { |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 840 | struct trap_per_cpu *tb = &trap_block[this_cpu]; |
| 841 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 842 | register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO, |
| 843 | tb->cpu_mondo_qmask); |
| 844 | register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO, |
| 845 | tb->dev_mondo_qmask); |
| 846 | register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR, |
| 847 | tb->resum_qmask); |
| 848 | register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR, |
| 849 | tb->nonresum_qmask); |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 850 | } |
| 851 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 852 | static void __init alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask) |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 853 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 854 | unsigned long size = PAGE_ALIGN(qmask + 1); |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 855 | void *p = __alloc_bootmem_low(size, size, 0); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 856 | if (!p) { |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 857 | prom_printf("SUN4V: Error, cannot allocate mondo queue.\n"); |
| 858 | prom_halt(); |
| 859 | } |
| 860 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 861 | *pa_ptr = __pa(p); |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 862 | } |
| 863 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 864 | static void __init alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask) |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 865 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 866 | unsigned long size = PAGE_ALIGN(qmask + 1); |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 867 | void *p = __alloc_bootmem_low(size, size, 0); |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 868 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 869 | if (!p) { |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 870 | prom_printf("SUN4V: Error, cannot allocate kbuf page.\n"); |
| 871 | prom_halt(); |
| 872 | } |
| 873 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 874 | *pa_ptr = __pa(p); |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 875 | } |
| 876 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 877 | static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb) |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 878 | { |
| 879 | #ifdef CONFIG_SMP |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 880 | void *page; |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 881 | |
| 882 | BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64)); |
| 883 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 884 | page = alloc_bootmem_low_pages(PAGE_SIZE); |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 885 | if (!page) { |
| 886 | prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n"); |
| 887 | prom_halt(); |
| 888 | } |
| 889 | |
| 890 | tb->cpu_mondo_block_pa = __pa(page); |
| 891 | tb->cpu_list_pa = __pa(page + 64); |
| 892 | #endif |
| 893 | } |
| 894 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 895 | /* Allocate mondo and error queues for all possible cpus. */ |
| 896 | static void __init sun4v_init_mondo_queues(void) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 897 | { |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 898 | int cpu; |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 899 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 900 | for_each_possible_cpu(cpu) { |
| 901 | struct trap_per_cpu *tb = &trap_block[cpu]; |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 902 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 903 | alloc_one_mondo(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask); |
| 904 | alloc_one_mondo(&tb->dev_mondo_pa, tb->dev_mondo_qmask); |
| 905 | alloc_one_mondo(&tb->resum_mondo_pa, tb->resum_qmask); |
| 906 | alloc_one_kbuf(&tb->resum_kernel_buf_pa, tb->resum_qmask); |
| 907 | alloc_one_mondo(&tb->nonresum_mondo_pa, tb->nonresum_qmask); |
| 908 | alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, |
| 909 | tb->nonresum_qmask); |
| 910 | |
| 911 | init_cpu_send_mondo_info(tb); |
David S. Miller | 72aff53 | 2006-02-17 01:29:17 -0800 | [diff] [blame] | 912 | } |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 913 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 914 | /* Load up the boot cpu's entries. */ |
| 915 | sun4v_register_mondo_queues(hard_smp_processor_id()); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 916 | } |
| 917 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 918 | static struct irqaction timer_irq_action = { |
| 919 | .name = "timer", |
| 920 | }; |
| 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | /* Only invoked on boot processor. */ |
| 923 | void __init init_IRQ(void) |
| 924 | { |
| 925 | map_prom_timers(); |
| 926 | kill_prom_timer(); |
| 927 | memset(&ivector_table[0], 0, sizeof(ivector_table)); |
| 928 | |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 929 | if (tlb_type == hypervisor) |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 930 | sun4v_init_mondo_queues(); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | /* We need to clear any IRQ's pending in the soft interrupt |
| 933 | * registers, a spurious one could be left around from the |
| 934 | * PROM timer which we just disabled. |
| 935 | */ |
| 936 | clear_softint(get_softint()); |
| 937 | |
| 938 | /* Now that ivector table is initialized, it is safe |
| 939 | * to receive IRQ vector traps. We will normally take |
| 940 | * one or two right now, in case some device PROM used |
| 941 | * to boot us wants to speak to us. We just ignore them. |
| 942 | */ |
| 943 | __asm__ __volatile__("rdpr %%pstate, %%g1\n\t" |
| 944 | "or %%g1, %0, %%g1\n\t" |
| 945 | "wrpr %%g1, 0x0, %%pstate" |
| 946 | : /* No outputs */ |
| 947 | : "i" (PSTATE_IE) |
| 948 | : "g1"); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 949 | |
| 950 | irq_desc[0].action = &timer_irq_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |