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