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