David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 1 | /* |
| 2 | * arch/powerpc/platforms/pseries/xics.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2000 IBM Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 11 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | #include <linux/threads.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/irq.h> |
| 17 | #include <linux/smp.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/signal.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/gfp.h> |
| 22 | #include <linux/radix-tree.h> |
| 23 | #include <linux/cpu.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 24 | |
Michael Ellerman | 57cfb81 | 2006-03-21 20:45:59 +1100 | [diff] [blame] | 25 | #include <asm/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/prom.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/pgtable.h> |
| 29 | #include <asm/smp.h> |
| 30 | #include <asm/rtas.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/hvcall.h> |
| 32 | #include <asm/machdep.h> |
Paul Mackerras | 2227718 | 2005-10-28 11:47:17 +1000 | [diff] [blame] | 33 | #include <asm/i8259.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 35 | #include "xics.h" |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 36 | #include "plpar_wrappers.h" |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define XICS_IPI 2 |
| 39 | #define XICS_IRQ_SPURIOUS 0 |
| 40 | |
| 41 | /* Want a priority other than 0. Various HW issues require this. */ |
| 42 | #define DEFAULT_PRIORITY 5 |
| 43 | |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 44 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * Mark IPIs as higher priority so we can take them inside interrupts that |
Thomas Gleixner | 6714465 | 2006-07-01 19:29:22 -0700 | [diff] [blame] | 46 | * arent marked IRQF_DISABLED |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | */ |
| 48 | #define IPI_PRIORITY 4 |
| 49 | |
| 50 | struct xics_ipl { |
| 51 | union { |
| 52 | u32 word; |
| 53 | u8 bytes[4]; |
| 54 | } xirr_poll; |
| 55 | union { |
| 56 | u32 word; |
| 57 | u8 bytes[4]; |
| 58 | } xirr; |
| 59 | u32 dummy; |
| 60 | union { |
| 61 | u32 word; |
| 62 | u8 bytes[4]; |
| 63 | } qirr; |
| 64 | }; |
| 65 | |
| 66 | static struct xics_ipl __iomem *xics_per_cpu[NR_CPUS]; |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static unsigned int default_server = 0xFF; |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 69 | static unsigned int default_distrib_server = 0; |
| 70 | static unsigned int interrupt_server_size = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 72 | static struct irq_host *xics_host; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* RTAS service tokens */ |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 75 | static int ibm_get_xive; |
| 76 | static int ibm_set_xive; |
| 77 | static int ibm_int_on; |
| 78 | static int ibm_int_off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 80 | |
| 81 | /* Direct HW low level accessors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 84 | static inline unsigned int direct_xirr_info_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 86 | int cpu = smp_processor_id(); |
| 87 | |
| 88 | return in_be32(&xics_per_cpu[cpu]->xirr.word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 91 | static inline void direct_xirr_info_set(int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 93 | int cpu = smp_processor_id(); |
| 94 | |
| 95 | out_be32(&xics_per_cpu[cpu]->xirr.word, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 98 | static inline void direct_cppr_info(u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 100 | int cpu = smp_processor_id(); |
| 101 | |
| 102 | out_8(&xics_per_cpu[cpu]->xirr.bytes[0], value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 105 | static inline void direct_qirr_info(int n_cpu, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | out_8(&xics_per_cpu[n_cpu]->qirr.bytes[0], value); |
| 108 | } |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 111 | /* LPAR low level accessors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 114 | static inline unsigned int lpar_xirr_info_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | unsigned long lpar_rc; |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 117 | unsigned long return_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | lpar_rc = plpar_xirr(&return_value); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 120 | if (lpar_rc != H_SUCCESS) |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 121 | panic(" bad return code xirr - rc = %lx \n", lpar_rc); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 122 | return (unsigned int)return_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 125 | static inline void lpar_xirr_info_set(int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | unsigned long lpar_rc; |
| 128 | unsigned long val64 = value & 0xffffffff; |
| 129 | |
| 130 | lpar_rc = plpar_eoi(val64); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 131 | if (lpar_rc != H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | panic("bad return code EOI - rc = %ld, value=%lx\n", lpar_rc, |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 133 | val64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 136 | static inline void lpar_cppr_info(u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | unsigned long lpar_rc; |
| 139 | |
| 140 | lpar_rc = plpar_cppr(value); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 141 | if (lpar_rc != H_SUCCESS) |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 142 | panic("bad return code cppr - rc = %lx\n", lpar_rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 145 | static inline void lpar_qirr_info(int n_cpu , u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | unsigned long lpar_rc; |
| 148 | |
| 149 | lpar_rc = plpar_ipi(get_hard_smp_processor_id(n_cpu), value); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 150 | if (lpar_rc != H_SUCCESS) |
David Gibson | 007e8f5 | 2005-10-28 15:35:50 +1000 | [diff] [blame] | 151 | panic("bad return code qirr - rc = %lx\n", lpar_rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 155 | /* High level handlers and init code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Nathan Fontenot | de0723d | 2008-02-07 07:37:40 +1100 | [diff] [blame] | 157 | static void xics_update_irq_servers(void) |
| 158 | { |
| 159 | int i, j; |
| 160 | struct device_node *np; |
| 161 | u32 ilen; |
| 162 | const u32 *ireg, *isize; |
| 163 | u32 hcpuid; |
| 164 | |
| 165 | /* Find the server numbers for the boot cpu. */ |
| 166 | np = of_get_cpu_node(boot_cpuid, NULL); |
| 167 | BUG_ON(!np); |
| 168 | |
| 169 | ireg = of_get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen); |
| 170 | if (!ireg) { |
| 171 | of_node_put(np); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | i = ilen / sizeof(int); |
| 176 | hcpuid = get_hard_smp_processor_id(boot_cpuid); |
| 177 | |
| 178 | /* Global interrupt distribution server is specified in the last |
| 179 | * entry of "ibm,ppc-interrupt-gserver#s" property. Get the last |
| 180 | * entry fom this property for current boot cpu id and use it as |
| 181 | * default distribution server |
| 182 | */ |
| 183 | for (j = 0; j < i; j += 2) { |
| 184 | if (ireg[j] == hcpuid) { |
| 185 | default_server = hcpuid; |
| 186 | default_distrib_server = ireg[j+1]; |
| 187 | |
| 188 | isize = of_get_property(np, |
| 189 | "ibm,interrupt-server#-size", NULL); |
| 190 | if (isize) |
| 191 | interrupt_server_size = *isize; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | of_node_put(np); |
| 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | #ifdef CONFIG_SMP |
Milton Miller | d13f720 | 2008-10-10 01:56:29 +0000 | [diff] [blame^] | 199 | /* |
| 200 | * XICS only has a single IPI, so encode the messages per CPU |
| 201 | */ |
| 202 | struct xics_ipi_struct { |
| 203 | unsigned long value; |
| 204 | } ____cacheline_aligned; |
| 205 | |
| 206 | static struct xics_ipi_struct xics_ipi_message[NR_CPUS] __cacheline_aligned; |
| 207 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 208 | static int get_irq_server(unsigned int virq, unsigned int strict_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 210 | int server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* For the moment only implement delivery to all cpus or one cpu */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 212 | cpumask_t cpumask = irq_desc[virq].affinity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | cpumask_t tmp = CPU_MASK_NONE; |
| 214 | |
| 215 | if (!distribute_irqs) |
| 216 | return default_server; |
| 217 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 218 | if (!cpus_equal(cpumask, CPU_MASK_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | cpus_and(tmp, cpu_online_map, cpumask); |
| 220 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 221 | server = first_cpu(tmp); |
| 222 | |
| 223 | if (server < NR_CPUS) |
| 224 | return get_hard_smp_processor_id(server); |
| 225 | |
| 226 | if (strict_check) |
| 227 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 230 | if (cpus_equal(cpu_online_map, cpu_present_map)) |
| 231 | return default_distrib_server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 233 | return default_server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | #else |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 236 | static int get_irq_server(unsigned int virq, unsigned int strict_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
| 238 | return default_server; |
| 239 | } |
| 240 | #endif |
| 241 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 242 | |
| 243 | static void xics_unmask_irq(unsigned int virq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | unsigned int irq; |
| 246 | int call_status; |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 247 | int server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 249 | pr_debug("xics: unmask virq %d\n", virq); |
| 250 | |
| 251 | irq = (unsigned int)irq_map[virq].hwirq; |
| 252 | pr_debug(" -> map to hwirq 0x%x\n", irq); |
| 253 | if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return; |
| 255 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 256 | server = get_irq_server(virq, 0); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, server, |
| 259 | DEFAULT_PRIORITY); |
| 260 | if (call_status != 0) { |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 261 | printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_set_xive " |
| 262 | "returned %d\n", irq, call_status); |
| 263 | printk("set_xive %x, server %x\n", ibm_set_xive, server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
| 267 | /* Now unmask the interrupt (often a no-op) */ |
| 268 | call_status = rtas_call(ibm_int_on, 1, 1, NULL, irq); |
| 269 | if (call_status != 0) { |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 270 | printk(KERN_ERR "xics_enable_irq: irq=%u: ibm_int_on " |
| 271 | "returned %d\n", irq, call_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | } |
| 275 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 276 | static void xics_mask_real_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | int call_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | if (irq == XICS_IPI) |
| 281 | return; |
| 282 | |
| 283 | call_status = rtas_call(ibm_int_off, 1, 1, NULL, irq); |
| 284 | if (call_status != 0) { |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 285 | printk(KERN_ERR "xics_disable_real_irq: irq=%u: " |
| 286 | "ibm_int_off returned %d\n", irq, call_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return; |
| 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* Have to set XIVE to 0xff to be able to remove a slot */ |
Michal Ostrowski | 673aeb7 | 2006-12-20 07:29:40 -0600 | [diff] [blame] | 291 | call_status = rtas_call(ibm_set_xive, 3, 1, NULL, irq, |
| 292 | default_server, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | if (call_status != 0) { |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 294 | printk(KERN_ERR "xics_disable_irq: irq=%u: ibm_set_xive(0xff)" |
| 295 | " returned %d\n", irq, call_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | } |
| 299 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 300 | static void xics_mask_irq(unsigned int virq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
| 302 | unsigned int irq; |
| 303 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 304 | pr_debug("xics: mask virq %d\n", virq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 306 | irq = (unsigned int)irq_map[virq].hwirq; |
| 307 | if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS) |
| 308 | return; |
| 309 | xics_mask_real_irq(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static unsigned int xics_startup(unsigned int virq) |
| 313 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 314 | /* unmask it */ |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 315 | xics_unmask_irq(virq); |
| 316 | return 0; |
| 317 | } |
| 318 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 319 | static void xics_eoi_direct(unsigned int virq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 321 | unsigned int irq = (unsigned int)irq_map[virq].hwirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | iosync(); |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 324 | direct_xirr_info_set((0xff << 24) | irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 328 | static void xics_eoi_lpar(unsigned int virq) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 329 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 330 | unsigned int irq = (unsigned int)irq_map[virq].hwirq; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 331 | |
| 332 | iosync(); |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 333 | lpar_xirr_info_set((0xff << 24) | irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Milton Miller | 8767e9b | 2008-10-10 01:56:23 +0000 | [diff] [blame] | 336 | static inline unsigned int xics_xirr_vector(unsigned int xirr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Milton Miller | 8767e9b | 2008-10-10 01:56:23 +0000 | [diff] [blame] | 338 | /* |
| 339 | * The top byte is the old cppr, to be restored on EOI. |
| 340 | * The remaining 24 bits are the vector. |
| 341 | */ |
| 342 | return xirr & 0x00ffffff; |
| 343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Milton Miller | 8767e9b | 2008-10-10 01:56:23 +0000 | [diff] [blame] | 345 | static void xics_mask_unknown_vec(unsigned int vec) |
| 346 | { |
| 347 | printk(KERN_ERR "Interrupt %u (real) is invalid, disabling it.\n", vec); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 348 | xics_mask_real_irq(vec); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 349 | } |
| 350 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 351 | static unsigned int xics_get_irq_direct(void) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 352 | { |
Milton Miller | 8767e9b | 2008-10-10 01:56:23 +0000 | [diff] [blame] | 353 | unsigned int xirr = direct_xirr_info_get(); |
| 354 | unsigned int vec = xics_xirr_vector(xirr); |
| 355 | unsigned int irq; |
| 356 | |
| 357 | if (vec == XICS_IRQ_SPURIOUS) |
| 358 | return NO_IRQ; |
| 359 | |
| 360 | irq = irq_radix_revmap_lookup(xics_host, vec); |
| 361 | if (likely(irq != NO_IRQ)) |
| 362 | return irq; |
| 363 | |
| 364 | /* We don't have a linux mapping, so have rtas mask it. */ |
| 365 | xics_mask_unknown_vec(vec); |
| 366 | |
| 367 | /* We might learn about it later, so EOI it */ |
| 368 | direct_xirr_info_set(xirr); |
| 369 | return NO_IRQ; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 370 | } |
| 371 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 372 | static unsigned int xics_get_irq_lpar(void) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 373 | { |
Milton Miller | 8767e9b | 2008-10-10 01:56:23 +0000 | [diff] [blame] | 374 | unsigned int xirr = lpar_xirr_info_get(); |
| 375 | unsigned int vec = xics_xirr_vector(xirr); |
| 376 | unsigned int irq; |
| 377 | |
| 378 | if (vec == XICS_IRQ_SPURIOUS) |
| 379 | return NO_IRQ; |
| 380 | |
| 381 | irq = irq_radix_revmap_lookup(xics_host, vec); |
| 382 | if (likely(irq != NO_IRQ)) |
| 383 | return irq; |
| 384 | |
| 385 | /* We don't have a linux mapping, so have RTAS mask it. */ |
| 386 | xics_mask_unknown_vec(vec); |
| 387 | |
| 388 | /* We might learn about it later, so EOI it */ |
| 389 | lpar_xirr_info_set(xirr); |
| 390 | return NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | #ifdef CONFIG_SMP |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 394 | static irqreturn_t xics_ipi_dispatch(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | WARN_ON(cpu_is_offline(cpu)); |
| 397 | |
| 398 | while (xics_ipi_message[cpu].value) { |
| 399 | if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION, |
| 400 | &xics_ipi_message[cpu].value)) { |
| 401 | mb(); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 402 | smp_message_recv(PPC_MSG_CALL_FUNCTION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | if (test_and_clear_bit(PPC_MSG_RESCHEDULE, |
| 405 | &xics_ipi_message[cpu].value)) { |
| 406 | mb(); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 407 | smp_message_recv(PPC_MSG_RESCHEDULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
Jens Axboe | b7d7a24 | 2008-06-26 11:22:13 +0200 | [diff] [blame] | 409 | if (test_and_clear_bit(PPC_MSG_CALL_FUNC_SINGLE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | &xics_ipi_message[cpu].value)) { |
| 411 | mb(); |
Jens Axboe | b7d7a24 | 2008-06-26 11:22:13 +0200 | [diff] [blame] | 412 | smp_message_recv(PPC_MSG_CALL_FUNC_SINGLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 414 | #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (test_and_clear_bit(PPC_MSG_DEBUGGER_BREAK, |
| 416 | &xics_ipi_message[cpu].value)) { |
| 417 | mb(); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 418 | smp_message_recv(PPC_MSG_DEBUGGER_BREAK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | #endif |
| 421 | } |
| 422 | return IRQ_HANDLED; |
| 423 | } |
| 424 | |
Milton Miller | d13f720 | 2008-10-10 01:56:29 +0000 | [diff] [blame^] | 425 | static inline void smp_xics_do_message(int cpu, int msg) |
| 426 | { |
| 427 | set_bit(msg, &xics_ipi_message[cpu].value); |
| 428 | mb(); |
| 429 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
| 430 | lpar_qirr_info(cpu, IPI_PRIORITY); |
| 431 | else |
| 432 | direct_qirr_info(cpu, IPI_PRIORITY); |
| 433 | } |
| 434 | |
| 435 | void smp_xics_message_pass(int target, int msg) |
| 436 | { |
| 437 | unsigned int i; |
| 438 | |
| 439 | if (target < NR_CPUS) { |
| 440 | smp_xics_do_message(target, msg); |
| 441 | } else { |
| 442 | for_each_online_cpu(i) { |
| 443 | if (target == MSG_ALL_BUT_SELF |
| 444 | && i == smp_processor_id()) |
| 445 | continue; |
| 446 | smp_xics_do_message(i, msg); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 452 | static irqreturn_t xics_ipi_action_direct(int irq, void *dev_id) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 453 | { |
| 454 | int cpu = smp_processor_id(); |
| 455 | |
| 456 | direct_qirr_info(cpu, 0xff); |
| 457 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 458 | return xics_ipi_dispatch(cpu); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 459 | } |
| 460 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 461 | static irqreturn_t xics_ipi_action_lpar(int irq, void *dev_id) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 462 | { |
| 463 | int cpu = smp_processor_id(); |
| 464 | |
| 465 | lpar_qirr_info(cpu, 0xff); |
| 466 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 467 | return xics_ipi_dispatch(cpu); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 468 | } |
Paul Mackerras | 6c80a21 | 2005-05-06 16:28:56 +1000 | [diff] [blame] | 469 | #endif /* CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 471 | static void xics_set_cpu_priority(unsigned char cppr) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 472 | { |
| 473 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 474 | lpar_cppr_info(cppr); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 475 | else |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 476 | direct_cppr_info(cppr); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 477 | iosync(); |
| 478 | } |
| 479 | |
| 480 | static void xics_set_affinity(unsigned int virq, cpumask_t cpumask) |
| 481 | { |
| 482 | unsigned int irq; |
| 483 | int status; |
| 484 | int xics_status[2]; |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 485 | int irq_server; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 486 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 487 | irq = (unsigned int)irq_map[virq].hwirq; |
| 488 | if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 489 | return; |
| 490 | |
| 491 | status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq); |
| 492 | |
| 493 | if (status) { |
| 494 | printk(KERN_ERR "xics_set_affinity: irq=%u ibm,get-xive " |
| 495 | "returns %d\n", irq, status); |
| 496 | return; |
| 497 | } |
| 498 | |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 499 | /* |
| 500 | * For the moment only implement delivery to all cpus or one cpu. |
| 501 | * Get current irq_server for the given irq |
| 502 | */ |
Anton Blanchard | e48395f | 2007-10-01 07:45:55 +1000 | [diff] [blame] | 503 | irq_server = get_irq_server(virq, 1); |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 504 | if (irq_server == -1) { |
| 505 | char cpulist[128]; |
| 506 | cpumask_scnprintf(cpulist, sizeof(cpulist), cpumask); |
| 507 | printk(KERN_WARNING "xics_set_affinity: No online cpus in " |
| 508 | "the mask %s for irq %d\n", cpulist, virq); |
| 509 | return; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | status = rtas_call(ibm_set_xive, 3, 1, NULL, |
Mohan Kumar M | 7ccb4a6 | 2007-06-13 00:51:57 +1000 | [diff] [blame] | 513 | irq, irq_server, xics_status[1]); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 514 | |
| 515 | if (status) { |
| 516 | printk(KERN_ERR "xics_set_affinity: irq=%u ibm,set-xive " |
| 517 | "returns %d\n", irq, status); |
| 518 | return; |
| 519 | } |
| 520 | } |
| 521 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 522 | void xics_setup_cpu(void) |
| 523 | { |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 524 | xics_set_cpu_priority(0xff); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * Put the calling processor into the GIQ. This is really only |
| 528 | * necessary from a secondary thread as the OF start-cpu interface |
| 529 | * performs this function for us on primary threads. |
| 530 | * |
| 531 | * XXX: undo of teardown on kexec needs this too, as may hotplug |
| 532 | */ |
Haren Myneni | 81b73dd | 2006-07-27 14:29:00 -0700 | [diff] [blame] | 533 | rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 534 | (1UL << interrupt_server_size) - 1 - default_distrib_server, 1); |
| 535 | } |
| 536 | |
| 537 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 538 | static struct irq_chip xics_pic_direct = { |
| 539 | .typename = " XICS ", |
| 540 | .startup = xics_startup, |
| 541 | .mask = xics_mask_irq, |
| 542 | .unmask = xics_unmask_irq, |
| 543 | .eoi = xics_eoi_direct, |
| 544 | .set_affinity = xics_set_affinity |
| 545 | }; |
| 546 | |
| 547 | |
| 548 | static struct irq_chip xics_pic_lpar = { |
| 549 | .typename = " XICS ", |
| 550 | .startup = xics_startup, |
| 551 | .mask = xics_mask_irq, |
| 552 | .unmask = xics_unmask_irq, |
| 553 | .eoi = xics_eoi_lpar, |
| 554 | .set_affinity = xics_set_affinity |
| 555 | }; |
| 556 | |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 557 | /* Points to the irq_chip we're actually using */ |
| 558 | static struct irq_chip *xics_irq_chip; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 559 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 560 | static int xics_host_match(struct irq_host *h, struct device_node *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 562 | /* IBM machines have interrupt parents of various funky types for things |
| 563 | * like vdevices, events, etc... The trick we use here is to match |
| 564 | * everything here except the legacy 8259 which is compatible "chrp,iic" |
Paul Mackerras | 6c80a21 | 2005-05-06 16:28:56 +1000 | [diff] [blame] | 565 | */ |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 566 | return !of_device_is_compatible(node, "chrp,iic"); |
Paul Mackerras | 6c80a21 | 2005-05-06 16:28:56 +1000 | [diff] [blame] | 567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 569 | static int xics_host_map(struct irq_host *h, unsigned int virq, |
| 570 | irq_hw_number_t hw) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 571 | { |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 572 | pr_debug("xics: map virq %d, hwirq 0x%lx\n", virq, hw); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 573 | |
Sebastien Dugue | 967e012 | 2008-09-04 22:37:07 +1000 | [diff] [blame] | 574 | /* Insert the interrupt mapping into the radix tree for fast lookup */ |
| 575 | irq_radix_revmap_insert(xics_host, virq, hw); |
| 576 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 577 | get_irq_desc(virq)->status |= IRQ_LEVEL; |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 578 | set_irq_chip_and_handler(virq, xics_irq_chip, handle_fasteoi_irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | static int xics_host_xlate(struct irq_host *h, struct device_node *ct, |
| 583 | u32 *intspec, unsigned int intsize, |
| 584 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 585 | |
| 586 | { |
| 587 | /* Current xics implementation translates everything |
| 588 | * to level. It is not technically right for MSIs but this |
| 589 | * is irrelevant at this point. We might get smarter in the future |
| 590 | */ |
| 591 | *out_hwirq = intspec[0]; |
| 592 | *out_flags = IRQ_TYPE_LEVEL_LOW; |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 597 | static struct irq_host_ops xics_host_ops = { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 598 | .match = xics_host_match, |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 599 | .map = xics_host_map, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 600 | .xlate = xics_host_xlate, |
| 601 | }; |
| 602 | |
| 603 | static void __init xics_init_host(void) |
| 604 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 605 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 606 | xics_irq_chip = &xics_pic_lpar; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 607 | else |
Michael Ellerman | 1af9fa8 | 2008-04-01 17:42:27 +1100 | [diff] [blame] | 608 | xics_irq_chip = &xics_pic_direct; |
| 609 | |
| 610 | xics_host = irq_alloc_host(NULL, IRQ_HOST_MAP_TREE, 0, &xics_host_ops, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 611 | XICS_IRQ_SPURIOUS); |
| 612 | BUG_ON(xics_host == NULL); |
| 613 | irq_set_default_host(xics_host); |
| 614 | } |
| 615 | |
| 616 | static void __init xics_map_one_cpu(int hw_id, unsigned long addr, |
| 617 | unsigned long size) |
| 618 | { |
| 619 | #ifdef CONFIG_SMP |
| 620 | int i; |
| 621 | |
| 622 | /* This may look gross but it's good enough for now, we don't quite |
| 623 | * have a hard -> linux processor id matching. |
| 624 | */ |
| 625 | for_each_possible_cpu(i) { |
| 626 | if (!cpu_present(i)) |
| 627 | continue; |
| 628 | if (hw_id == get_hard_smp_processor_id(i)) { |
| 629 | xics_per_cpu[i] = ioremap(addr, size); |
| 630 | return; |
| 631 | } |
| 632 | } |
| 633 | #else |
| 634 | if (hw_id != 0) |
| 635 | return; |
| 636 | xics_per_cpu[0] = ioremap(addr, size); |
| 637 | #endif /* CONFIG_SMP */ |
| 638 | } |
| 639 | |
| 640 | static void __init xics_init_one_node(struct device_node *np, |
| 641 | unsigned int *indx) |
| 642 | { |
| 643 | unsigned int ilen; |
Jeremy Kerr | 954a46e | 2006-07-12 15:39:43 +1000 | [diff] [blame] | 644 | const u32 *ireg; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 645 | |
| 646 | /* This code does the theorically broken assumption that the interrupt |
| 647 | * server numbers are the same as the hard CPU numbers. |
| 648 | * This happens to be the case so far but we are playing with fire... |
| 649 | * should be fixed one of these days. -BenH. |
| 650 | */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 651 | ireg = of_get_property(np, "ibm,interrupt-server-ranges", NULL); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 652 | |
| 653 | /* Do that ever happen ? we'll know soon enough... but even good'old |
| 654 | * f80 does have that property .. |
| 655 | */ |
| 656 | WARN_ON(ireg == NULL); |
| 657 | if (ireg) { |
| 658 | /* |
| 659 | * set node starting index for this node |
| 660 | */ |
| 661 | *indx = *ireg; |
| 662 | } |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 663 | ireg = of_get_property(np, "reg", &ilen); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 664 | if (!ireg) |
| 665 | panic("xics_init_IRQ: can't find interrupt reg property"); |
| 666 | |
| 667 | while (ilen >= (4 * sizeof(u32))) { |
| 668 | unsigned long addr, size; |
| 669 | |
| 670 | /* XXX Use proper OF parsing code here !!! */ |
| 671 | addr = (unsigned long)*ireg++ << 32; |
| 672 | ilen -= sizeof(u32); |
| 673 | addr |= *ireg++; |
| 674 | ilen -= sizeof(u32); |
| 675 | size = (unsigned long)*ireg++ << 32; |
| 676 | ilen -= sizeof(u32); |
| 677 | size |= *ireg++; |
| 678 | ilen -= sizeof(u32); |
| 679 | xics_map_one_cpu(*indx, addr, size); |
| 680 | (*indx)++; |
| 681 | } |
| 682 | } |
| 683 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 684 | void __init xics_init_IRQ(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | struct device_node *np; |
Nathan Fontenot | de0723d | 2008-02-07 07:37:40 +1100 | [diff] [blame] | 687 | u32 indx = 0; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 688 | int found = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | ppc64_boot_msg(0x20, "XICS Init"); |
| 691 | |
| 692 | ibm_get_xive = rtas_token("ibm,get-xive"); |
| 693 | ibm_set_xive = rtas_token("ibm,set-xive"); |
| 694 | ibm_int_on = rtas_token("ibm,int-on"); |
| 695 | ibm_int_off = rtas_token("ibm,int-off"); |
| 696 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 697 | for_each_node_by_type(np, "PowerPC-External-Interrupt-Presentation") { |
| 698 | found = 1; |
| 699 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
| 700 | break; |
| 701 | xics_init_one_node(np, &indx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 703 | if (found == 0) |
| 704 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Nathan Fontenot | de0723d | 2008-02-07 07:37:40 +1100 | [diff] [blame] | 706 | xics_update_irq_servers(); |
Milton Miller | 302905a | 2008-10-10 01:56:28 +0000 | [diff] [blame] | 707 | xics_init_host(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 709 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
| 710 | ppc_md.get_irq = xics_get_irq_lpar; |
| 711 | else |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 712 | ppc_md.get_irq = xics_get_irq_direct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Paul Mackerras | 6c80a21 | 2005-05-06 16:28:56 +1000 | [diff] [blame] | 714 | xics_setup_cpu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | ppc64_boot_msg(0x21, "XICS Done"); |
| 717 | } |
| 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | #ifdef CONFIG_SMP |
Milton Miller | d13f720 | 2008-10-10 01:56:29 +0000 | [diff] [blame^] | 721 | static void xics_request_ipi(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 723 | unsigned int ipi; |
Michael Neuling | 66b3092 | 2007-05-29 17:01:52 +1000 | [diff] [blame] | 724 | int rc; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 725 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 726 | ipi = irq_create_mapping(xics_host, XICS_IPI); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 727 | BUG_ON(ipi == NO_IRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Thomas Gleixner | 6714465 | 2006-07-01 19:29:22 -0700 | [diff] [blame] | 729 | /* |
| 730 | * IPIs are marked IRQF_DISABLED as they must run with irqs |
| 731 | * disabled |
| 732 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 733 | set_irq_handler(ipi, handle_percpu_irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 734 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
Michael Neuling | 66b3092 | 2007-05-29 17:01:52 +1000 | [diff] [blame] | 735 | rc = request_irq(ipi, xics_ipi_action_lpar, IRQF_DISABLED, |
| 736 | "IPI", NULL); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 737 | else |
Michael Neuling | 66b3092 | 2007-05-29 17:01:52 +1000 | [diff] [blame] | 738 | rc = request_irq(ipi, xics_ipi_action_direct, IRQF_DISABLED, |
| 739 | "IPI", NULL); |
| 740 | BUG_ON(rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
Milton Miller | d13f720 | 2008-10-10 01:56:29 +0000 | [diff] [blame^] | 742 | |
| 743 | int __init smp_xics_probe(void) |
| 744 | { |
| 745 | xics_request_ipi(); |
| 746 | |
| 747 | return cpus_weight(cpu_possible_map); |
| 748 | } |
| 749 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 750 | #endif /* CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Al Viro | f10095c | 2008-03-29 03:10:38 +0000 | [diff] [blame] | 752 | void xics_teardown_cpu(void) |
R Sharada | fce0d57 | 2005-06-25 14:58:10 -0700 | [diff] [blame] | 753 | { |
| 754 | int cpu = smp_processor_id(); |
R Sharada | fce0d57 | 2005-06-25 14:58:10 -0700 | [diff] [blame] | 755 | |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 756 | xics_set_cpu_priority(0); |
Haren Myneni | 81bbbe9 | 2006-04-05 21:10:18 -0600 | [diff] [blame] | 757 | |
| 758 | /* |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 759 | * Clear IPI |
| 760 | */ |
| 761 | if (firmware_has_feature(FW_FEATURE_LPAR)) |
| 762 | lpar_qirr_info(cpu, 0xff); |
| 763 | else |
| 764 | direct_qirr_info(cpu, 0xff); |
Nathan Fontenot | c3e8506 | 2008-02-07 07:37:31 +1100 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | void xics_kexec_teardown_cpu(int secondary) |
| 768 | { |
| 769 | unsigned int ipi; |
| 770 | struct irq_desc *desc; |
| 771 | |
| 772 | xics_teardown_cpu(); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 773 | |
| 774 | /* |
Nathan Fontenot | c3e8506 | 2008-02-07 07:37:31 +1100 | [diff] [blame] | 775 | * we need to EOI the IPI |
Haren Myneni | 81bbbe9 | 2006-04-05 21:10:18 -0600 | [diff] [blame] | 776 | * |
| 777 | * probably need to check all the other interrupts too |
| 778 | * should we be flagging idle loop instead? |
| 779 | * or creating some task to be scheduled? |
| 780 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 781 | |
| 782 | ipi = irq_find_mapping(xics_host, XICS_IPI); |
| 783 | if (ipi == XICS_IRQ_SPURIOUS) |
| 784 | return; |
| 785 | desc = get_irq_desc(ipi); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 786 | if (desc->chip && desc->chip->eoi) |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 787 | desc->chip->eoi(ipi); |
Haren Myneni | 81bbbe9 | 2006-04-05 21:10:18 -0600 | [diff] [blame] | 788 | |
R Sharada | fce0d57 | 2005-06-25 14:58:10 -0700 | [diff] [blame] | 789 | /* |
Paul Mackerras | 6d22d85 | 2005-08-04 12:53:37 -0700 | [diff] [blame] | 790 | * Some machines need to have at least one cpu in the GIQ, |
| 791 | * so leave the master cpu in the group. |
R Sharada | fce0d57 | 2005-06-25 14:58:10 -0700 | [diff] [blame] | 792 | */ |
Haren Myneni | 81bbbe9 | 2006-04-05 21:10:18 -0600 | [diff] [blame] | 793 | if (secondary) |
Haren Myneni | 81b73dd | 2006-07-27 14:29:00 -0700 | [diff] [blame] | 794 | rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 795 | (1UL << interrupt_server_size) - 1 - |
| 796 | default_distrib_server, 0); |
R Sharada | fce0d57 | 2005-06-25 14:58:10 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | #ifdef CONFIG_HOTPLUG_CPU |
| 800 | |
| 801 | /* Interrupts are disabled. */ |
| 802 | void xics_migrate_irqs_away(void) |
| 803 | { |
| 804 | int status; |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 805 | int cpu = smp_processor_id(), hw_cpu = hard_smp_processor_id(); |
| 806 | unsigned int irq, virq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Milton Miller | 302905a | 2008-10-10 01:56:28 +0000 | [diff] [blame] | 808 | /* If we used to be the default server, move to the new "boot_cpuid" */ |
| 809 | if (hw_cpu == default_server) |
| 810 | xics_update_irq_servers(); |
| 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | /* Reject any interrupt that was queued to us... */ |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 813 | xics_set_cpu_priority(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | /* remove ourselves from the global interrupt queue */ |
Haren Myneni | 81b73dd | 2006-07-27 14:29:00 -0700 | [diff] [blame] | 816 | status = rtas_set_indicator_fast(GLOBAL_INTERRUPT_QUEUE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | (1UL << interrupt_server_size) - 1 - default_distrib_server, 0); |
| 818 | WARN_ON(status < 0); |
| 819 | |
| 820 | /* Allow IPIs again... */ |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 821 | xics_set_cpu_priority(DEFAULT_PRIORITY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | for_each_irq(virq) { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 824 | struct irq_desc *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | int xics_status[2]; |
| 826 | unsigned long flags; |
| 827 | |
| 828 | /* We cant set affinity on ISA interrupts */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 829 | if (virq < NUM_ISA_INTERRUPTS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | continue; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 831 | if (irq_map[virq].host != xics_host) |
| 832 | continue; |
| 833 | irq = (unsigned int)irq_map[virq].hwirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* We need to get IPIs still. */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 835 | if (irq == XICS_IPI || irq == XICS_IRQ_SPURIOUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | continue; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 837 | desc = get_irq_desc(virq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | /* We only need to migrate enabled IRQS */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 840 | if (desc == NULL || desc->chip == NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | || desc->action == NULL |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 842 | || desc->chip->set_affinity == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | continue; |
| 844 | |
| 845 | spin_lock_irqsave(&desc->lock, flags); |
| 846 | |
| 847 | status = rtas_call(ibm_get_xive, 1, 3, xics_status, irq); |
| 848 | if (status) { |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 849 | printk(KERN_ERR "migrate_irqs_away: irq=%u " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | "ibm,get-xive returns %d\n", |
| 851 | virq, status); |
| 852 | goto unlock; |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * We only support delivery to all cpus or to one cpu. |
| 857 | * The irq has to be migrated only in the single cpu |
| 858 | * case. |
| 859 | */ |
Milton Miller | d7cf0ed | 2007-12-14 15:52:09 +1100 | [diff] [blame] | 860 | if (xics_status[0] != hw_cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | goto unlock; |
| 862 | |
Anton Blanchard | 2637032 | 2005-09-12 13:12:11 +1000 | [diff] [blame] | 863 | printk(KERN_WARNING "IRQ %u affinity broken off cpu %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | virq, cpu); |
| 865 | |
| 866 | /* Reset affinity to all cpus */ |
Nathan Fontenot | a52572d | 2008-02-07 07:37:26 +1100 | [diff] [blame] | 867 | irq_desc[virq].affinity = CPU_MASK_ALL; |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 868 | desc->chip->set_affinity(virq, CPU_MASK_ALL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | unlock: |
| 870 | spin_unlock_irqrestore(&desc->lock, flags); |
| 871 | } |
| 872 | } |
| 873 | #endif |