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