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 | 227c331 | 2008-04-26 02:19:18 -0700 | [diff] [blame] | 3 | * Copyright (C) 1997, 2007, 2008 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/sched.h> |
David S. Miller | 9843099 | 2008-09-16 11:44:00 -0700 | [diff] [blame] | 9 | #include <linux/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 22 | #include <linux/ftrace.h> |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 23 | #include <linux/irq.h> |
Frederic Weisbecker | 2e2dc1d | 2010-04-13 14:28:24 -0700 | [diff] [blame] | 24 | #include <linux/kmemleak.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include <asm/ptrace.h> |
| 27 | #include <asm/processor.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 28 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/iommu.h> |
| 32 | #include <asm/upa.h> |
| 33 | #include <asm/oplib.h> |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 34 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/timer.h> |
| 36 | #include <asm/smp.h> |
| 37 | #include <asm/starfire.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | #include <asm/cache.h> |
| 40 | #include <asm/cpudata.h> |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 41 | #include <asm/auxio.h> |
David S. Miller | 92704a1 | 2006-02-26 23:27:19 -0800 | [diff] [blame] | 42 | #include <asm/head.h> |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 43 | #include <asm/hypervisor.h> |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 44 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
David S. Miller | d91aa12 | 2008-03-26 00:37:51 -0700 | [diff] [blame] | 46 | #include "entry.h" |
Hong H. Pham | 280ff97 | 2009-06-04 02:10:11 -0700 | [diff] [blame] | 47 | #include "cpumap.h" |
David S. Miller | ec68788 | 2010-04-14 02:04:29 -0700 | [diff] [blame] | 48 | #include "kstack.h" |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 49 | |
David S. Miller | 10397e4 | 2007-10-13 21:43:31 -0700 | [diff] [blame] | 50 | struct ino_bucket *ivector_table; |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 51 | unsigned long ivector_table_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 53 | /* On several sun4u processors, it is illegal to mix bypass and |
| 54 | * non-bypass accesses. Therefore we access all INO buckets |
| 55 | * using bypass accesses only. |
| 56 | */ |
| 57 | static unsigned long bucket_get_chain_pa(unsigned long bucket_pa) |
| 58 | { |
| 59 | unsigned long ret; |
| 60 | |
| 61 | __asm__ __volatile__("ldxa [%1] %2, %0" |
| 62 | : "=&r" (ret) |
| 63 | : "r" (bucket_pa + |
| 64 | offsetof(struct ino_bucket, |
| 65 | __irq_chain_pa)), |
| 66 | "i" (ASI_PHYS_USE_EC)); |
| 67 | |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | static void bucket_clear_chain_pa(unsigned long bucket_pa) |
| 72 | { |
| 73 | __asm__ __volatile__("stxa %%g0, [%0] %1" |
| 74 | : /* no outputs */ |
| 75 | : "r" (bucket_pa + |
| 76 | offsetof(struct ino_bucket, |
| 77 | __irq_chain_pa)), |
| 78 | "i" (ASI_PHYS_USE_EC)); |
| 79 | } |
| 80 | |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 81 | static unsigned int bucket_get_irq(unsigned long bucket_pa) |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 82 | { |
| 83 | unsigned int ret; |
| 84 | |
| 85 | __asm__ __volatile__("lduwa [%1] %2, %0" |
| 86 | : "=&r" (ret) |
| 87 | : "r" (bucket_pa + |
| 88 | offsetof(struct ino_bucket, |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 89 | __irq)), |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 90 | "i" (ASI_PHYS_USE_EC)); |
| 91 | |
| 92 | return ret; |
| 93 | } |
| 94 | |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 95 | static void bucket_set_irq(unsigned long bucket_pa, unsigned int irq) |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 96 | { |
| 97 | __asm__ __volatile__("stwa %0, [%1] %2" |
| 98 | : /* no outputs */ |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 99 | : "r" (irq), |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 100 | "r" (bucket_pa + |
| 101 | offsetof(struct ino_bucket, |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 102 | __irq)), |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 103 | "i" (ASI_PHYS_USE_EC)); |
| 104 | } |
| 105 | |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 106 | #define irq_work_pa(__cpu) &(trap_block[(__cpu)].irq_worklist_pa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 108 | static unsigned long hvirq_major __initdata; |
| 109 | static int __init early_hvirq_major(char *p) |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 110 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 111 | int rc = kstrtoul(p, 10, &hvirq_major); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 112 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 113 | return rc; |
| 114 | } |
| 115 | early_param("hvirq", early_hvirq_major); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 116 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 117 | static int hv_irq_version; |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame] | 118 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 119 | /* Major version 2.0 of HV_GRP_INTR added support for the VIRQ cookie |
| 120 | * based interfaces, but: |
| 121 | * |
| 122 | * 1) Several OSs, Solaris and Linux included, use them even when only |
| 123 | * negotiating version 1.0 (or failing to negotiate at all). So the |
| 124 | * hypervisor has a workaround that provides the VIRQ interfaces even |
| 125 | * when only verion 1.0 of the API is in use. |
| 126 | * |
| 127 | * 2) Second, and more importantly, with major version 2.0 these VIRQ |
| 128 | * interfaces only were actually hooked up for LDC interrupts, even |
| 129 | * though the Hypervisor specification clearly stated: |
| 130 | * |
| 131 | * The new interrupt API functions will be available to a guest |
| 132 | * when it negotiates version 2.0 in the interrupt API group 0x2. When |
| 133 | * a guest negotiates version 2.0, all interrupt sources will only |
| 134 | * support using the cookie interface, and any attempt to use the |
| 135 | * version 1.0 interrupt APIs numbered 0xa0 to 0xa6 will result in the |
| 136 | * ENOTSUPPORTED error being returned. |
| 137 | * |
| 138 | * with an emphasis on "all interrupt sources". |
| 139 | * |
| 140 | * To correct this, major version 3.0 was created which does actually |
| 141 | * support VIRQs for all interrupt sources (not just LDC devices). So |
| 142 | * if we want to move completely over the cookie based VIRQs we must |
| 143 | * negotiate major version 3.0 or later of HV_GRP_INTR. |
| 144 | */ |
| 145 | static bool sun4v_cookie_only_virqs(void) |
| 146 | { |
| 147 | if (hv_irq_version >= 3) |
| 148 | return true; |
| 149 | return false; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 150 | } |
| 151 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 152 | static void __init irq_init_hv(void) |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 153 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 154 | unsigned long hv_error, major, minor = 0; |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 155 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 156 | if (tlb_type != hypervisor) |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 157 | return; |
| 158 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 159 | if (hvirq_major) |
| 160 | major = hvirq_major; |
| 161 | else |
| 162 | major = 3; |
David S. Miller | 759f89e | 2007-10-11 03:16:13 -0700 | [diff] [blame] | 163 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 164 | hv_error = sun4v_hvapi_register(HV_GRP_INTR, major, &minor); |
| 165 | if (!hv_error) |
| 166 | hv_irq_version = major; |
| 167 | else |
| 168 | hv_irq_version = 1; |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 169 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 170 | pr_info("SUN4V: Using IRQ API major %d, cookie only virqs %s\n", |
| 171 | hv_irq_version, |
| 172 | sun4v_cookie_only_virqs() ? "enabled" : "disabled"); |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 173 | } |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 174 | |
| 175 | /* This function is for the timer interrupt.*/ |
| 176 | int __init arch_probe_nr_irqs(void) |
| 177 | { |
| 178 | return 1; |
| 179 | } |
| 180 | |
| 181 | #define DEFAULT_NUM_IVECS (0xfffU) |
| 182 | static unsigned int nr_ivec = DEFAULT_NUM_IVECS; |
| 183 | #define NUM_IVECS (nr_ivec) |
| 184 | |
| 185 | static unsigned int __init size_nr_ivec(void) |
| 186 | { |
| 187 | if (tlb_type == hypervisor) { |
| 188 | switch (sun4v_chip_type) { |
| 189 | /* Athena's devhandle|devino is large.*/ |
| 190 | case SUN4V_CHIP_SPARC64X: |
| 191 | nr_ivec = 0xffff; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | return nr_ivec; |
| 196 | } |
| 197 | |
| 198 | struct irq_handler_data { |
| 199 | union { |
| 200 | struct { |
| 201 | unsigned int dev_handle; |
| 202 | unsigned int dev_ino; |
| 203 | }; |
| 204 | unsigned long sysino; |
| 205 | }; |
| 206 | struct ino_bucket bucket; |
| 207 | unsigned long iclr; |
| 208 | unsigned long imap; |
| 209 | }; |
| 210 | |
| 211 | static inline unsigned int irq_data_to_handle(struct irq_data *data) |
| 212 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 213 | struct irq_handler_data *ihd = irq_data_get_irq_handler_data(data); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 214 | |
| 215 | return ihd->dev_handle; |
| 216 | } |
| 217 | |
| 218 | static inline unsigned int irq_data_to_ino(struct irq_data *data) |
| 219 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 220 | struct irq_handler_data *ihd = irq_data_get_irq_handler_data(data); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 221 | |
| 222 | return ihd->dev_ino; |
| 223 | } |
| 224 | |
| 225 | static inline unsigned long irq_data_to_sysino(struct irq_data *data) |
| 226 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 227 | struct irq_handler_data *ihd = irq_data_get_irq_handler_data(data); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 228 | |
| 229 | return ihd->sysino; |
| 230 | } |
| 231 | |
| 232 | void irq_free(unsigned int irq) |
| 233 | { |
| 234 | void *data = irq_get_handler_data(irq); |
| 235 | |
| 236 | kfree(data); |
| 237 | irq_set_handler_data(irq, NULL); |
| 238 | irq_free_descs(irq, 1); |
| 239 | } |
| 240 | |
| 241 | unsigned int irq_alloc(unsigned int dev_handle, unsigned int dev_ino) |
| 242 | { |
| 243 | int irq; |
| 244 | |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 245 | irq = __irq_alloc_descs(-1, 1, 1, numa_node_id(), NULL, NULL); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 246 | if (irq <= 0) |
| 247 | goto out; |
| 248 | |
| 249 | return irq; |
| 250 | out: |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static unsigned int cookie_exists(u32 devhandle, unsigned int devino) |
| 255 | { |
| 256 | unsigned long hv_err, cookie; |
| 257 | struct ino_bucket *bucket; |
| 258 | unsigned int irq = 0U; |
| 259 | |
| 260 | hv_err = sun4v_vintr_get_cookie(devhandle, devino, &cookie); |
| 261 | if (hv_err) { |
| 262 | pr_err("HV get cookie failed hv_err = %ld\n", hv_err); |
| 263 | goto out; |
| 264 | } |
| 265 | |
| 266 | if (cookie & ((1UL << 63UL))) { |
| 267 | cookie = ~cookie; |
| 268 | bucket = (struct ino_bucket *) __va(cookie); |
| 269 | irq = bucket->__irq; |
| 270 | } |
| 271 | out: |
| 272 | return irq; |
| 273 | } |
| 274 | |
| 275 | static unsigned int sysino_exists(u32 devhandle, unsigned int devino) |
| 276 | { |
| 277 | unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino); |
| 278 | struct ino_bucket *bucket; |
| 279 | unsigned int irq; |
| 280 | |
| 281 | bucket = &ivector_table[sysino]; |
| 282 | irq = bucket_get_irq(__pa(bucket)); |
| 283 | |
| 284 | return irq; |
| 285 | } |
| 286 | |
| 287 | void ack_bad_irq(unsigned int irq) |
| 288 | { |
| 289 | pr_crit("BAD IRQ ack %d\n", irq); |
| 290 | } |
| 291 | |
| 292 | void irq_install_pre_handler(int irq, |
| 293 | void (*func)(unsigned int, void *, void *), |
| 294 | void *arg1, void *arg2) |
| 295 | { |
| 296 | pr_warn("IRQ pre handler NOT supported.\n"); |
| 297 | } |
David S. Miller | 8047e24 | 2006-06-20 01:22:35 -0700 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 300 | * /proc/interrupts printing: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | */ |
Thomas Gleixner | fa680c7 | 2011-03-24 18:03:13 +0100 | [diff] [blame] | 302 | int arch_show_interrupts(struct seq_file *p, int prec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Thomas Gleixner | fa680c7 | 2011-03-24 18:03:13 +0100 | [diff] [blame] | 304 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Thomas Gleixner | fa680c7 | 2011-03-24 18:03:13 +0100 | [diff] [blame] | 306 | seq_printf(p, "NMI: "); |
| 307 | for_each_online_cpu(j) |
| 308 | seq_printf(p, "%10u ", cpu_data(j).__nmi_count); |
| 309 | seq_printf(p, " Non-maskable interrupts\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
David S. Miller | ebd8c56 | 2006-02-17 08:38:06 -0800 | [diff] [blame] | 313 | static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid) |
| 314 | { |
| 315 | unsigned int tid; |
| 316 | |
| 317 | if (this_is_starfire) { |
| 318 | tid = starfire_translate(imap, cpuid); |
| 319 | tid <<= IMAP_TID_SHIFT; |
| 320 | tid &= IMAP_TID_UPA; |
| 321 | } else { |
| 322 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 323 | unsigned long ver; |
| 324 | |
| 325 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); |
| 326 | if ((ver >> 32UL) == __JALAPENO_ID || |
| 327 | (ver >> 32UL) == __SERRANO_ID) { |
| 328 | tid = cpuid << IMAP_TID_SHIFT; |
| 329 | tid &= IMAP_TID_JBUS; |
| 330 | } else { |
| 331 | unsigned int a = cpuid & 0x1f; |
| 332 | unsigned int n = (cpuid >> 5) & 0x1f; |
| 333 | |
| 334 | tid = ((a << IMAP_AID_SHIFT) | |
| 335 | (n << IMAP_NID_SHIFT)); |
| 336 | tid &= (IMAP_AID_SAFARI | |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 337 | IMAP_NID_SAFARI); |
David S. Miller | ebd8c56 | 2006-02-17 08:38:06 -0800 | [diff] [blame] | 338 | } |
| 339 | } else { |
| 340 | tid = cpuid << IMAP_TID_SHIFT; |
| 341 | tid &= IMAP_TID_UPA; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return tid; |
| 346 | } |
| 347 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 348 | #ifdef CONFIG_SMP |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 349 | static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 350 | { |
Mike Travis | e65e49d | 2009-01-12 15:27:13 -0800 | [diff] [blame] | 351 | cpumask_t mask; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 352 | int cpuid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
David S. Miller | 1091ce6 | 2010-01-20 19:30:49 -0800 | [diff] [blame] | 354 | cpumask_copy(&mask, affinity); |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 355 | if (cpumask_equal(&mask, cpu_online_mask)) { |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 356 | cpuid = map_to_cpu(irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 357 | } else { |
| 358 | cpumask_t tmp; |
| 359 | |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 360 | cpumask_and(&tmp, cpu_online_mask, &mask); |
| 361 | cpuid = cpumask_empty(&tmp) ? map_to_cpu(irq) : cpumask_first(&tmp); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return cpuid; |
| 365 | } |
| 366 | #else |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 367 | #define irq_choose_cpu(irq, affinity) \ |
David S. Miller | 6abce77 | 2010-01-26 04:16:49 -0800 | [diff] [blame] | 368 | real_hard_smp_processor_id() |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 369 | #endif |
| 370 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 371 | static void sun4u_irq_enable(struct irq_data *data) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 372 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 373 | struct irq_handler_data *handler_data; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 374 | |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 375 | handler_data = irq_data_get_irq_handler_data(data); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 376 | if (likely(handler_data)) { |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 377 | unsigned long cpuid, imap, val; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 378 | unsigned int tid; |
| 379 | |
Jiang Liu | d7185a9 | 2015-06-01 16:05:35 +0800 | [diff] [blame] | 380 | cpuid = irq_choose_cpu(data->irq, |
| 381 | irq_data_get_affinity_mask(data)); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 382 | imap = handler_data->imap; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 383 | |
| 384 | tid = sun4u_compute_tid(imap, cpuid); |
| 385 | |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 386 | val = upa_readq(imap); |
| 387 | val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS | |
| 388 | IMAP_AID_SAFARI | IMAP_NID_SAFARI); |
| 389 | val |= tid | IMAP_VALID; |
| 390 | upa_writeq(val, imap); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 391 | upa_writeq(ICLR_IDLE, handler_data->iclr); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 395 | static int sun4u_set_affinity(struct irq_data *data, |
| 396 | const struct cpumask *mask, bool force) |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 397 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 398 | struct irq_handler_data *handler_data; |
David S. Miller | 1091ce6 | 2010-01-20 19:30:49 -0800 | [diff] [blame] | 399 | |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 400 | handler_data = irq_data_get_irq_handler_data(data); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 401 | if (likely(handler_data)) { |
David S. Miller | 1091ce6 | 2010-01-20 19:30:49 -0800 | [diff] [blame] | 402 | unsigned long cpuid, imap, val; |
| 403 | unsigned int tid; |
| 404 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 405 | cpuid = irq_choose_cpu(data->irq, mask); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 406 | imap = handler_data->imap; |
David S. Miller | 1091ce6 | 2010-01-20 19:30:49 -0800 | [diff] [blame] | 407 | |
| 408 | tid = sun4u_compute_tid(imap, cpuid); |
| 409 | |
| 410 | val = upa_readq(imap); |
| 411 | val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS | |
| 412 | IMAP_AID_SAFARI | IMAP_NID_SAFARI); |
| 413 | val |= tid | IMAP_VALID; |
| 414 | upa_writeq(val, imap); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 415 | upa_writeq(ICLR_IDLE, handler_data->iclr); |
David S. Miller | 1091ce6 | 2010-01-20 19:30:49 -0800 | [diff] [blame] | 416 | } |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 417 | |
| 418 | return 0; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 419 | } |
| 420 | |
David S. Miller | d0cac39 | 2009-03-04 14:43:47 -0800 | [diff] [blame] | 421 | /* Don't do anything. The desc->status check for IRQ_DISABLED in |
| 422 | * handler_irq() will skip the handler call and that will leave the |
| 423 | * interrupt in the sent state. The next ->enable() call will hit the |
| 424 | * ICLR register to reset the state machine. |
| 425 | * |
| 426 | * This scheme is necessary, instead of clearing the Valid bit in the |
| 427 | * IMAP register, to handle the case of IMAP registers being shared by |
| 428 | * multiple INOs (and thus ICLR registers). Since we use a different |
| 429 | * virtual IRQ for each shared IMAP instance, the generic code thinks |
| 430 | * there is only one user so it prematurely calls ->disable() on |
| 431 | * free_irq(). |
| 432 | * |
| 433 | * We have to provide an explicit ->disable() method instead of using |
| 434 | * NULL to get the default. The reason is that if the generic code |
| 435 | * sees that, it also hooks up a default ->shutdown method which |
| 436 | * invokes ->mask() which we do not want. See irq_chip_set_defaults(). |
| 437 | */ |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 438 | static void sun4u_irq_disable(struct irq_data *data) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 439 | { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 442 | static void sun4u_irq_eoi(struct irq_data *data) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 443 | { |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 444 | struct irq_handler_data *handler_data; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 445 | |
Jiang Liu | 6a4a5b3 | 2015-06-01 16:05:17 +0800 | [diff] [blame] | 446 | handler_data = irq_data_get_irq_handler_data(data); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 447 | if (likely(handler_data)) |
| 448 | upa_writeq(ICLR_IDLE, handler_data->iclr); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 451 | static void sun4v_irq_enable(struct irq_data *data) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 452 | { |
Jiang Liu | d7185a9 | 2015-06-01 16:05:35 +0800 | [diff] [blame] | 453 | unsigned long cpuid = irq_choose_cpu(data->irq, |
| 454 | irq_data_get_affinity_mask(data)); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 455 | unsigned int ino = irq_data_to_sysino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 456 | int err; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 457 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 458 | err = sun4v_intr_settarget(ino, cpuid); |
| 459 | if (err != HV_EOK) |
| 460 | printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): " |
| 461 | "err(%d)\n", ino, cpuid, err); |
| 462 | err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
| 463 | if (err != HV_EOK) |
| 464 | printk(KERN_ERR "sun4v_intr_setstate(%x): " |
| 465 | "err(%d)\n", ino, err); |
| 466 | err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED); |
| 467 | if (err != HV_EOK) |
| 468 | printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n", |
| 469 | ino, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 472 | static int sun4v_set_affinity(struct irq_data *data, |
| 473 | const struct cpumask *mask, bool force) |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 474 | { |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 475 | unsigned long cpuid = irq_choose_cpu(data->irq, mask); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 476 | unsigned int ino = irq_data_to_sysino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 477 | int err; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 478 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 479 | err = sun4v_intr_settarget(ino, cpuid); |
| 480 | if (err != HV_EOK) |
| 481 | printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): " |
| 482 | "err(%d)\n", ino, cpuid, err); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 483 | |
| 484 | return 0; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 487 | static void sun4v_irq_disable(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 489 | unsigned int ino = irq_data_to_sysino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 490 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 492 | err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED); |
| 493 | if (err != HV_EOK) |
| 494 | printk(KERN_ERR "sun4v_intr_setenabled(%x): " |
| 495 | "err(%d)\n", ino, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 498 | static void sun4v_irq_eoi(struct irq_data *data) |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 499 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 500 | unsigned int ino = irq_data_to_sysino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 501 | int err; |
David S. Miller | 5a606b7 | 2007-07-09 22:40:36 -0700 | [diff] [blame] | 502 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 503 | err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
| 504 | if (err != HV_EOK) |
| 505 | printk(KERN_ERR "sun4v_intr_setstate(%x): " |
| 506 | "err(%d)\n", ino, err); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 509 | static void sun4v_virq_enable(struct irq_data *data) |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 510 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 511 | unsigned long dev_handle = irq_data_to_handle(data); |
| 512 | unsigned long dev_ino = irq_data_to_ino(data); |
| 513 | unsigned long cpuid; |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 514 | int err; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 515 | |
Jiang Liu | d7185a9 | 2015-06-01 16:05:35 +0800 | [diff] [blame] | 516 | cpuid = irq_choose_cpu(data->irq, irq_data_get_affinity_mask(data)); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 517 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 518 | err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid); |
| 519 | if (err != HV_EOK) |
| 520 | printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): " |
| 521 | "err(%d)\n", |
| 522 | dev_handle, dev_ino, cpuid, err); |
| 523 | err = sun4v_vintr_set_state(dev_handle, dev_ino, |
| 524 | HV_INTR_STATE_IDLE); |
| 525 | if (err != HV_EOK) |
| 526 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
| 527 | "HV_INTR_STATE_IDLE): err(%d)\n", |
| 528 | dev_handle, dev_ino, err); |
| 529 | err = sun4v_vintr_set_valid(dev_handle, dev_ino, |
| 530 | HV_INTR_ENABLED); |
| 531 | if (err != HV_EOK) |
| 532 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
| 533 | "HV_INTR_ENABLED): err(%d)\n", |
| 534 | dev_handle, dev_ino, err); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 537 | static int sun4v_virt_set_affinity(struct irq_data *data, |
| 538 | const struct cpumask *mask, bool force) |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 539 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 540 | unsigned long dev_handle = irq_data_to_handle(data); |
| 541 | unsigned long dev_ino = irq_data_to_ino(data); |
| 542 | unsigned long cpuid; |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 543 | int err; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 544 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 545 | cpuid = irq_choose_cpu(data->irq, mask); |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 546 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 547 | err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid); |
| 548 | if (err != HV_EOK) |
| 549 | printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): " |
| 550 | "err(%d)\n", |
| 551 | dev_handle, dev_ino, cpuid, err); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 552 | |
| 553 | return 0; |
David S. Miller | b53bcb6 | 2007-07-14 03:16:13 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 556 | static void sun4v_virq_disable(struct irq_data *data) |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 557 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 558 | unsigned long dev_handle = irq_data_to_handle(data); |
| 559 | unsigned long dev_ino = irq_data_to_ino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 560 | int err; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 561 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 562 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 563 | err = sun4v_vintr_set_valid(dev_handle, dev_ino, |
| 564 | HV_INTR_DISABLED); |
| 565 | if (err != HV_EOK) |
| 566 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
| 567 | "HV_INTR_DISABLED): err(%d)\n", |
| 568 | dev_handle, dev_ino, err); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 571 | static void sun4v_virq_eoi(struct irq_data *data) |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 572 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 573 | unsigned long dev_handle = irq_data_to_handle(data); |
| 574 | unsigned long dev_ino = irq_data_to_ino(data); |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 575 | int err; |
David S. Miller | 5a606b7 | 2007-07-09 22:40:36 -0700 | [diff] [blame] | 576 | |
David S. Miller | 77182300 | 2007-10-13 23:41:28 -0700 | [diff] [blame] | 577 | err = sun4v_vintr_set_state(dev_handle, dev_ino, |
| 578 | HV_INTR_STATE_IDLE); |
| 579 | if (err != HV_EOK) |
| 580 | printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx," |
| 581 | "HV_INTR_STATE_IDLE): err(%d)\n", |
| 582 | dev_handle, dev_ino, err); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 583 | } |
| 584 | |
David S. Miller | 729e7d7 | 2006-12-12 00:59:12 -0800 | [diff] [blame] | 585 | static struct irq_chip sun4u_irq = { |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 586 | .name = "sun4u", |
| 587 | .irq_enable = sun4u_irq_enable, |
| 588 | .irq_disable = sun4u_irq_disable, |
| 589 | .irq_eoi = sun4u_irq_eoi, |
| 590 | .irq_set_affinity = sun4u_set_affinity, |
Thomas Gleixner | fcd8d4f | 2011-03-24 09:03:45 +0100 | [diff] [blame] | 591 | .flags = IRQCHIP_EOI_IF_HANDLED, |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 592 | }; |
| 593 | |
David S. Miller | 729e7d7 | 2006-12-12 00:59:12 -0800 | [diff] [blame] | 594 | static struct irq_chip sun4v_irq = { |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 595 | .name = "sun4v", |
| 596 | .irq_enable = sun4v_irq_enable, |
| 597 | .irq_disable = sun4v_irq_disable, |
| 598 | .irq_eoi = sun4v_irq_eoi, |
| 599 | .irq_set_affinity = sun4v_set_affinity, |
Thomas Gleixner | fcd8d4f | 2011-03-24 09:03:45 +0100 | [diff] [blame] | 600 | .flags = IRQCHIP_EOI_IF_HANDLED, |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 601 | }; |
| 602 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 603 | static struct irq_chip sun4v_virq = { |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 604 | .name = "vsun4v", |
| 605 | .irq_enable = sun4v_virq_enable, |
| 606 | .irq_disable = sun4v_virq_disable, |
| 607 | .irq_eoi = sun4v_virq_eoi, |
| 608 | .irq_set_affinity = sun4v_virt_set_affinity, |
Thomas Gleixner | fcd8d4f | 2011-03-24 09:03:45 +0100 | [diff] [blame] | 609 | .flags = IRQCHIP_EOI_IF_HANDLED, |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 610 | }; |
| 611 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 612 | unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | { |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 614 | struct irq_handler_data *handler_data; |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 615 | struct ino_bucket *bucket; |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 616 | unsigned int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | int ino; |
| 618 | |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 619 | BUG_ON(tlb_type == hypervisor); |
| 620 | |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 621 | ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 622 | bucket = &ivector_table[ino]; |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 623 | irq = bucket_get_irq(__pa(bucket)); |
| 624 | if (!irq) { |
| 625 | irq = irq_alloc(0, ino); |
| 626 | bucket_set_irq(__pa(bucket), irq); |
Thomas Gleixner | 394d441 | 2011-03-24 17:52:54 +0100 | [diff] [blame] | 627 | irq_set_chip_and_handler_name(irq, &sun4u_irq, |
| 628 | handle_fasteoi_irq, "IVEC"); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Thomas Gleixner | 394d441 | 2011-03-24 17:52:54 +0100 | [diff] [blame] | 631 | handler_data = irq_get_handler_data(irq); |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 632 | if (unlikely(handler_data)) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 633 | goto out; |
| 634 | |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 635 | handler_data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC); |
| 636 | if (unlikely(!handler_data)) { |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 637 | prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n"); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 638 | prom_halt(); |
| 639 | } |
Thomas Gleixner | 394d441 | 2011-03-24 17:52:54 +0100 | [diff] [blame] | 640 | irq_set_handler_data(irq, handler_data); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 641 | |
Sam Ravnborg | cae78728 | 2011-01-22 11:32:16 +0000 | [diff] [blame] | 642 | handler_data->imap = imap; |
| 643 | handler_data->iclr = iclr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 645 | out: |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 646 | return irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 649 | static unsigned int sun4v_build_common(u32 devhandle, unsigned int devino, |
| 650 | void (*handler_data_init)(struct irq_handler_data *data, |
| 651 | u32 devhandle, unsigned int devino), |
| 652 | struct irq_chip *chip) |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 653 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 654 | struct irq_handler_data *data; |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 655 | unsigned int irq; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 656 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 657 | irq = irq_alloc(devhandle, devino); |
| 658 | if (!irq) |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 659 | goto out; |
| 660 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 661 | data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC); |
| 662 | if (unlikely(!data)) { |
| 663 | pr_err("IRQ handler data allocation failed.\n"); |
| 664 | irq_free(irq); |
| 665 | irq = 0; |
| 666 | goto out; |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 667 | } |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 668 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 669 | irq_set_handler_data(irq, data); |
| 670 | handler_data_init(data, devhandle, devino); |
| 671 | irq_set_chip_and_handler_name(irq, chip, handle_fasteoi_irq, "IVEC"); |
| 672 | data->imap = ~0UL; |
| 673 | data->iclr = ~0UL; |
| 674 | out: |
| 675 | return irq; |
| 676 | } |
| 677 | |
| 678 | static unsigned long cookie_assign(unsigned int irq, u32 devhandle, |
| 679 | unsigned int devino) |
| 680 | { |
| 681 | struct irq_handler_data *ihd = irq_get_handler_data(irq); |
| 682 | unsigned long hv_error, cookie; |
| 683 | |
| 684 | /* handler_irq needs to find the irq. cookie is seen signed in |
| 685 | * sun4v_dev_mondo and treated as a non ivector_table delivery. |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 686 | */ |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 687 | ihd->bucket.__irq = irq; |
| 688 | cookie = ~__pa(&ihd->bucket); |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 689 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 690 | hv_error = sun4v_vintr_set_cookie(devhandle, devino, cookie); |
| 691 | if (hv_error) |
| 692 | pr_err("HV vintr set cookie failed = %ld\n", hv_error); |
| 693 | |
| 694 | return hv_error; |
| 695 | } |
| 696 | |
| 697 | static void cookie_handler_data(struct irq_handler_data *data, |
| 698 | u32 devhandle, unsigned int devino) |
| 699 | { |
| 700 | data->dev_handle = devhandle; |
| 701 | data->dev_ino = devino; |
| 702 | } |
| 703 | |
| 704 | static unsigned int cookie_build_irq(u32 devhandle, unsigned int devino, |
| 705 | struct irq_chip *chip) |
| 706 | { |
| 707 | unsigned long hv_error; |
| 708 | unsigned int irq; |
| 709 | |
| 710 | irq = sun4v_build_common(devhandle, devino, cookie_handler_data, chip); |
| 711 | |
| 712 | hv_error = cookie_assign(irq, devhandle, devino); |
| 713 | if (hv_error) { |
| 714 | irq_free(irq); |
| 715 | irq = 0; |
| 716 | } |
| 717 | |
| 718 | return irq; |
| 719 | } |
| 720 | |
| 721 | static unsigned int sun4v_build_cookie(u32 devhandle, unsigned int devino) |
| 722 | { |
| 723 | unsigned int irq; |
| 724 | |
| 725 | irq = cookie_exists(devhandle, devino); |
| 726 | if (irq) |
| 727 | goto out; |
| 728 | |
| 729 | irq = cookie_build_irq(devhandle, devino, &sun4v_virq); |
| 730 | |
| 731 | out: |
| 732 | return irq; |
| 733 | } |
| 734 | |
| 735 | static void sysino_set_bucket(unsigned int irq) |
| 736 | { |
| 737 | struct irq_handler_data *ihd = irq_get_handler_data(irq); |
| 738 | struct ino_bucket *bucket; |
| 739 | unsigned long sysino; |
| 740 | |
| 741 | sysino = sun4v_devino_to_sysino(ihd->dev_handle, ihd->dev_ino); |
| 742 | BUG_ON(sysino >= nr_ivec); |
| 743 | bucket = &ivector_table[sysino]; |
| 744 | bucket_set_irq(__pa(bucket), irq); |
| 745 | } |
| 746 | |
| 747 | static void sysino_handler_data(struct irq_handler_data *data, |
| 748 | u32 devhandle, unsigned int devino) |
| 749 | { |
| 750 | unsigned long sysino; |
| 751 | |
| 752 | sysino = sun4v_devino_to_sysino(devhandle, devino); |
| 753 | data->sysino = sysino; |
| 754 | } |
| 755 | |
| 756 | static unsigned int sysino_build_irq(u32 devhandle, unsigned int devino, |
| 757 | struct irq_chip *chip) |
| 758 | { |
| 759 | unsigned int irq; |
| 760 | |
| 761 | irq = sun4v_build_common(devhandle, devino, sysino_handler_data, chip); |
| 762 | if (!irq) |
| 763 | goto out; |
| 764 | |
| 765 | sysino_set_bucket(irq); |
| 766 | out: |
| 767 | return irq; |
| 768 | } |
| 769 | |
| 770 | static int sun4v_build_sysino(u32 devhandle, unsigned int devino) |
| 771 | { |
| 772 | int irq; |
| 773 | |
| 774 | irq = sysino_exists(devhandle, devino); |
| 775 | if (irq) |
| 776 | goto out; |
| 777 | |
| 778 | irq = sysino_build_irq(devhandle, devino, &sun4v_irq); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 779 | out: |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 780 | return irq; |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 781 | } |
| 782 | |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 783 | unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino) |
| 784 | { |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 785 | unsigned int irq; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 786 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 787 | if (sun4v_cookie_only_virqs()) |
| 788 | irq = sun4v_build_cookie(devhandle, devino); |
| 789 | else |
| 790 | irq = sun4v_build_sysino(devhandle, devino); |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 791 | |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 792 | return irq; |
David S. Miller | 4a907de | 2007-06-13 00:01:04 -0700 | [diff] [blame] | 793 | } |
| 794 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 795 | unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino) |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 796 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 797 | int irq; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 798 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 799 | irq = cookie_build_irq(devhandle, devino, &sun4v_virq); |
| 800 | if (!irq) |
| 801 | goto out; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 802 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 803 | /* This is borrowed from the original function. |
| 804 | */ |
| 805 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 806 | |
| 807 | out: |
| 808 | return irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 811 | void *hardirq_stack[NR_CPUS]; |
| 812 | void *softirq_stack[NR_CPUS]; |
| 813 | |
Sam Ravnborg | d4d1ec4 | 2011-01-22 11:32:15 +0000 | [diff] [blame] | 814 | void __irq_entry handler_irq(int pil, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 816 | unsigned long pstate, bucket_pa; |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 817 | struct pt_regs *old_regs; |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 818 | void *orig_sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Sam Ravnborg | d4d1ec4 | 2011-01-22 11:32:15 +0000 | [diff] [blame] | 820 | clear_softint(1 << pil); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 822 | old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | irq_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
David S. Miller | a650d38 | 2007-10-12 02:59:40 -0700 | [diff] [blame] | 825 | /* Grab an atomic snapshot of the pending IVECs. */ |
| 826 | __asm__ __volatile__("rdpr %%pstate, %0\n\t" |
| 827 | "wrpr %0, %3, %%pstate\n\t" |
| 828 | "ldx [%2], %1\n\t" |
| 829 | "stx %%g0, [%2]\n\t" |
| 830 | "wrpr %0, 0x0, %%pstate\n\t" |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 831 | : "=&r" (pstate), "=&r" (bucket_pa) |
| 832 | : "r" (irq_work_pa(smp_processor_id())), |
David S. Miller | a650d38 | 2007-10-12 02:59:40 -0700 | [diff] [blame] | 833 | "i" (PSTATE_IE) |
| 834 | : "memory"); |
| 835 | |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 836 | orig_sp = set_hardirq_stack(); |
| 837 | |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 838 | while (bucket_pa) { |
| 839 | unsigned long next_pa; |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 840 | unsigned int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 842 | next_pa = bucket_get_chain_pa(bucket_pa); |
Sam Ravnborg | fe41493 | 2011-01-22 11:32:19 +0000 | [diff] [blame] | 843 | irq = bucket_get_irq(bucket_pa); |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 844 | bucket_clear_chain_pa(bucket_pa); |
David S. Miller | fd0504c3 | 2006-06-20 01:20:00 -0700 | [diff] [blame] | 845 | |
Thomas Gleixner | fcd8d4f | 2011-03-24 09:03:45 +0100 | [diff] [blame] | 846 | generic_handle_irq(irq); |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 847 | |
| 848 | bucket_pa = next_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 850 | |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 851 | restore_hardirq_stack(orig_sp); |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | irq_exit(); |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 854 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Frederic Weisbecker | 7d65f4a | 2013-09-05 15:49:45 +0200 | [diff] [blame] | 857 | void do_softirq_own_stack(void) |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 858 | { |
Frederic Weisbecker | 7d65f4a | 2013-09-05 15:49:45 +0200 | [diff] [blame] | 859 | void *orig_sp, *sp = softirq_stack[smp_processor_id()]; |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 860 | |
Frederic Weisbecker | 7d65f4a | 2013-09-05 15:49:45 +0200 | [diff] [blame] | 861 | sp += THREAD_SIZE - 192 - STACK_BIAS; |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 862 | |
Frederic Weisbecker | 7d65f4a | 2013-09-05 15:49:45 +0200 | [diff] [blame] | 863 | __asm__ __volatile__("mov %%sp, %0\n\t" |
| 864 | "mov %1, %%sp" |
| 865 | : "=&r" (orig_sp) |
| 866 | : "r" (sp)); |
| 867 | __do_softirq(); |
| 868 | __asm__ __volatile__("mov %0, %%sp" |
| 869 | : : "r" (orig_sp)); |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 870 | } |
| 871 | |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 872 | #ifdef CONFIG_HOTPLUG_CPU |
| 873 | void fixup_irqs(void) |
| 874 | { |
| 875 | unsigned int irq; |
| 876 | |
| 877 | for (irq = 0; irq < NR_IRQS; irq++) { |
Thomas Gleixner | 16741ea | 2011-03-24 17:57:12 +0100 | [diff] [blame] | 878 | struct irq_desc *desc = irq_to_desc(irq); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 879 | struct irq_data *data; |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 880 | unsigned long flags; |
| 881 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 882 | if (!desc) |
| 883 | continue; |
| 884 | data = irq_desc_get_irq_data(desc); |
Thomas Gleixner | 16741ea | 2011-03-24 17:57:12 +0100 | [diff] [blame] | 885 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 886 | if (desc->action && !irqd_is_per_cpu(data)) { |
Sam Ravnborg | 4832b99 | 2011-01-22 11:32:18 +0000 | [diff] [blame] | 887 | if (data->chip->irq_set_affinity) |
| 888 | data->chip->irq_set_affinity(data, |
Jiang Liu | d7185a9 | 2015-06-01 16:05:35 +0800 | [diff] [blame] | 889 | irq_data_get_affinity_mask(data), |
| 890 | false); |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 891 | } |
Thomas Gleixner | 16741ea | 2011-03-24 17:57:12 +0100 | [diff] [blame] | 892 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 893 | } |
David S. Miller | 2eb2f77 | 2008-09-08 17:21:07 -0700 | [diff] [blame] | 894 | |
| 895 | tick_ops->disable_irq(); |
David S. Miller | e0204409 | 2007-07-16 03:49:40 -0700 | [diff] [blame] | 896 | } |
| 897 | #endif |
| 898 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 899 | struct sun5_timer { |
| 900 | u64 count0; |
| 901 | u64 limit0; |
| 902 | u64 count1; |
| 903 | u64 limit1; |
| 904 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 906 | static struct sun5_timer *prom_timers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | static u64 prom_limit0, prom_limit1; |
| 908 | |
| 909 | static void map_prom_timers(void) |
| 910 | { |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 911 | struct device_node *dp; |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 912 | const unsigned int *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | /* 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] | 915 | dp = of_find_node_by_path("/"); |
| 916 | dp = dp->child; |
| 917 | while (dp) { |
| 918 | if (!strcmp(dp->name, "counter-timer")) |
| 919 | break; |
| 920 | dp = dp->sibling; |
| 921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
| 923 | /* Assume if node is not present, PROM uses different tick mechanism |
| 924 | * which we should not care about. |
| 925 | */ |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 926 | if (!dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | prom_timers = (struct sun5_timer *) 0; |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | /* 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] | 932 | addr = of_get_property(dp, "address", NULL); |
| 933 | if (!addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | prom_printf("PROM does not have timer mapped, trying to continue.\n"); |
| 935 | prom_timers = (struct sun5_timer *) 0; |
| 936 | return; |
| 937 | } |
| 938 | prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]); |
| 939 | } |
| 940 | |
| 941 | static void kill_prom_timer(void) |
| 942 | { |
| 943 | if (!prom_timers) |
| 944 | return; |
| 945 | |
| 946 | /* Save them away for later. */ |
| 947 | prom_limit0 = prom_timers->limit0; |
| 948 | prom_limit1 = prom_timers->limit1; |
| 949 | |
David S. Miller | ee906c9 | 2012-05-12 00:35:45 -0700 | [diff] [blame] | 950 | /* Just as in sun4c PROM uses timer which ticks at IRQ 14. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | * We turn both off here just to be paranoid. |
| 952 | */ |
| 953 | prom_timers->limit0 = 0; |
| 954 | prom_timers->limit1 = 0; |
| 955 | |
| 956 | /* Wheee, eat the interrupt packet too... */ |
| 957 | __asm__ __volatile__( |
| 958 | " mov 0x40, %%g2\n" |
| 959 | " ldxa [%%g0] %0, %%g1\n" |
| 960 | " ldxa [%%g2] %1, %%g1\n" |
| 961 | " stxa %%g0, [%%g0] %0\n" |
| 962 | " membar #Sync\n" |
| 963 | : /* no outputs */ |
| 964 | : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R) |
| 965 | : "g1", "g2"); |
| 966 | } |
| 967 | |
David S. Miller | 9843099 | 2008-09-16 11:44:00 -0700 | [diff] [blame] | 968 | void notrace init_irqwork_curcpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | int cpu = hard_smp_processor_id(); |
| 971 | |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 972 | trap_block[cpu].irq_worklist_pa = 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 975 | /* Please be very careful with register_one_mondo() and |
| 976 | * sun4v_register_mondo_queues(). |
| 977 | * |
| 978 | * On SMP this gets invoked from the CPU trampoline before |
| 979 | * the cpu has fully taken over the trap table from OBP, |
| 980 | * and it's kernel stack + %g6 thread register state is |
| 981 | * not fully cooked yet. |
| 982 | * |
| 983 | * Therefore you cannot make any OBP calls, not even prom_printf, |
| 984 | * from these two routines. |
| 985 | */ |
Paul Gortmaker | 2066aad | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 986 | static void notrace register_one_mondo(unsigned long paddr, unsigned long type, |
| 987 | unsigned long qmask) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 988 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 989 | unsigned long num_entries = (qmask + 1) / 64; |
David S. Miller | 94f8762 | 2006-02-16 14:26:53 -0800 | [diff] [blame] | 990 | unsigned long status; |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 991 | |
David S. Miller | 94f8762 | 2006-02-16 14:26:53 -0800 | [diff] [blame] | 992 | status = sun4v_cpu_qconf(type, paddr, num_entries); |
| 993 | if (status != HV_EOK) { |
| 994 | prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, " |
| 995 | "err %lu\n", type, paddr, num_entries, status); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 996 | prom_halt(); |
| 997 | } |
| 998 | } |
| 999 | |
Paul Gortmaker | 2066aad | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 1000 | void notrace sun4v_register_mondo_queues(int this_cpu) |
David S. Miller | 5b0c0572 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 1001 | { |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1002 | struct trap_per_cpu *tb = &trap_block[this_cpu]; |
| 1003 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 1004 | register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO, |
| 1005 | tb->cpu_mondo_qmask); |
| 1006 | register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO, |
| 1007 | tb->dev_mondo_qmask); |
| 1008 | register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR, |
| 1009 | tb->resum_qmask); |
| 1010 | register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR, |
| 1011 | tb->nonresum_qmask); |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1014 | /* Each queue region must be a power of 2 multiple of 64 bytes in |
| 1015 | * size. The base real address must be aligned to the size of the |
| 1016 | * region. Thus, an 8KB queue must be 8KB aligned, for example. |
| 1017 | */ |
| 1018 | static void __init alloc_one_queue(unsigned long *pa_ptr, unsigned long qmask) |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1019 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 1020 | unsigned long size = PAGE_ALIGN(qmask + 1); |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1021 | unsigned long order = get_order(size); |
| 1022 | unsigned long p; |
| 1023 | |
| 1024 | p = __get_free_pages(GFP_KERNEL, order); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 1025 | if (!p) { |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1026 | prom_printf("SUN4V: Error, cannot allocate queue.\n"); |
David S. Miller | 5b0c0572 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 1027 | prom_halt(); |
| 1028 | } |
| 1029 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 1030 | *pa_ptr = __pa(p); |
David S. Miller | 5b0c0572 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1033 | 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] | 1034 | { |
| 1035 | #ifdef CONFIG_SMP |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1036 | unsigned long page; |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1037 | |
| 1038 | BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64)); |
| 1039 | |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1040 | page = get_zeroed_page(GFP_KERNEL); |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1041 | if (!page) { |
| 1042 | prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n"); |
| 1043 | prom_halt(); |
| 1044 | } |
| 1045 | |
| 1046 | tb->cpu_mondo_block_pa = __pa(page); |
| 1047 | tb->cpu_list_pa = __pa(page + 64); |
| 1048 | #endif |
| 1049 | } |
| 1050 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1051 | /* Allocate mondo and error queues for all possible cpus. */ |
| 1052 | static void __init sun4v_init_mondo_queues(void) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1053 | { |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1054 | int cpu; |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1055 | |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1056 | for_each_possible_cpu(cpu) { |
| 1057 | struct trap_per_cpu *tb = &trap_block[cpu]; |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1058 | |
David S. Miller | 14a2ff6 | 2009-06-25 19:00:47 -0700 | [diff] [blame] | 1059 | alloc_one_queue(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask); |
| 1060 | alloc_one_queue(&tb->dev_mondo_pa, tb->dev_mondo_qmask); |
| 1061 | alloc_one_queue(&tb->resum_mondo_pa, tb->resum_qmask); |
| 1062 | alloc_one_queue(&tb->resum_kernel_buf_pa, tb->resum_qmask); |
| 1063 | alloc_one_queue(&tb->nonresum_mondo_pa, tb->nonresum_qmask); |
| 1064 | alloc_one_queue(&tb->nonresum_kernel_buf_pa, |
| 1065 | tb->nonresum_qmask); |
David S. Miller | 43f5892 | 2008-08-04 16:13:51 -0700 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | static void __init init_send_mondo_info(void) |
| 1070 | { |
| 1071 | int cpu; |
| 1072 | |
| 1073 | for_each_possible_cpu(cpu) { |
| 1074 | struct trap_per_cpu *tb = &trap_block[cpu]; |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1075 | |
| 1076 | init_cpu_send_mondo_info(tb); |
David S. Miller | 72aff53 | 2006-02-17 01:29:17 -0800 | [diff] [blame] | 1077 | } |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 1080 | static struct irqaction timer_irq_action = { |
| 1081 | .name = "timer", |
| 1082 | }; |
| 1083 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 1084 | static void __init irq_ivector_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | { |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 1086 | unsigned long size, order; |
| 1087 | unsigned int ivecs; |
David S. Miller | 10397e4 | 2007-10-13 21:43:31 -0700 | [diff] [blame] | 1088 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 1089 | /* If we are doing cookie only VIRQs then we do not need the ivector |
| 1090 | * table to process interrupts. |
| 1091 | */ |
| 1092 | if (sun4v_cookie_only_virqs()) |
| 1093 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 1095 | ivecs = size_nr_ivec(); |
| 1096 | size = sizeof(struct ino_bucket) * ivecs; |
| 1097 | order = get_order(size); |
| 1098 | ivector_table = (struct ino_bucket *) |
| 1099 | __get_free_pages(GFP_KERNEL | __GFP_ZERO, order); |
David S. Miller | 10397e4 | 2007-10-13 21:43:31 -0700 | [diff] [blame] | 1100 | if (!ivector_table) { |
| 1101 | prom_printf("Fatal error, cannot allocate ivector_table\n"); |
| 1102 | prom_halt(); |
| 1103 | } |
David S. Miller | 42d5f99 | 2007-10-13 23:03:21 -0700 | [diff] [blame] | 1104 | __flush_dcache_range((unsigned long) ivector_table, |
| 1105 | ((unsigned long) ivector_table) + size); |
David S. Miller | 10397e4 | 2007-10-13 21:43:31 -0700 | [diff] [blame] | 1106 | |
| 1107 | ivector_table_pa = __pa(ivector_table); |
bob picco | ee6a933 | 2014-09-25 12:25:03 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /* Only invoked on boot processor.*/ |
| 1111 | void __init init_IRQ(void) |
| 1112 | { |
| 1113 | irq_init_hv(); |
| 1114 | irq_ivector_init(); |
| 1115 | map_prom_timers(); |
| 1116 | kill_prom_timer(); |
David S. Miller | eb2d8d6 | 2007-10-13 21:42:46 -0700 | [diff] [blame] | 1117 | |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1118 | if (tlb_type == hypervisor) |
David S. Miller | b434e71 | 2007-08-08 17:32:33 -0700 | [diff] [blame] | 1119 | sun4v_init_mondo_queues(); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1120 | |
David S. Miller | 43f5892 | 2008-08-04 16:13:51 -0700 | [diff] [blame] | 1121 | init_send_mondo_info(); |
| 1122 | |
| 1123 | if (tlb_type == hypervisor) { |
| 1124 | /* Load up the boot cpu's entries. */ |
| 1125 | sun4v_register_mondo_queues(hard_smp_processor_id()); |
| 1126 | } |
| 1127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | /* We need to clear any IRQ's pending in the soft interrupt |
| 1129 | * registers, a spurious one could be left around from the |
| 1130 | * PROM timer which we just disabled. |
| 1131 | */ |
| 1132 | clear_softint(get_softint()); |
| 1133 | |
| 1134 | /* Now that ivector table is initialized, it is safe |
| 1135 | * to receive IRQ vector traps. We will normally take |
| 1136 | * one or two right now, in case some device PROM used |
| 1137 | * to boot us wants to speak to us. We just ignore them. |
| 1138 | */ |
| 1139 | __asm__ __volatile__("rdpr %%pstate, %%g1\n\t" |
| 1140 | "or %%g1, %0, %%g1\n\t" |
| 1141 | "wrpr %%g1, 0x0, %%pstate" |
| 1142 | : /* No outputs */ |
| 1143 | : "i" (PSTATE_IE) |
| 1144 | : "g1"); |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 1145 | |
Thomas Gleixner | 16741ea | 2011-03-24 17:57:12 +0100 | [diff] [blame] | 1146 | irq_to_desc(0)->action = &timer_irq_action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |