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