Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * arch/powerpc/kernel/mpic.c |
| 3 | * |
| 4 | * Driver for interrupt controllers following the OpenPIC standard, the |
| 5 | * common implementation beeing IBM's MPIC. This driver also can deal |
| 6 | * with various broken implementations of this HW. |
| 7 | * |
| 8 | * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp. |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file COPYING in the main directory of this archive |
| 12 | * for more details. |
| 13 | */ |
| 14 | |
| 15 | #undef DEBUG |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 16 | #undef DEBUG_IPI |
| 17 | #undef DEBUG_IRQ |
| 18 | #undef DEBUG_LOW |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 19 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 20 | #include <linux/types.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/smp.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/bootmem.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/pci.h> |
| 29 | |
| 30 | #include <asm/ptrace.h> |
| 31 | #include <asm/signal.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/irq.h> |
| 35 | #include <asm/machdep.h> |
| 36 | #include <asm/mpic.h> |
| 37 | #include <asm/smp.h> |
| 38 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 39 | #include "mpic.h" |
| 40 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 41 | #ifdef DEBUG |
| 42 | #define DBG(fmt...) printk(fmt) |
| 43 | #else |
| 44 | #define DBG(fmt...) |
| 45 | #endif |
| 46 | |
| 47 | static struct mpic *mpics; |
| 48 | static struct mpic *mpic_primary; |
| 49 | static DEFINE_SPINLOCK(mpic_lock); |
| 50 | |
Paul Mackerras | c0c0d99 | 2005-10-01 13:49:08 +1000 | [diff] [blame] | 51 | #ifdef CONFIG_PPC32 /* XXX for now */ |
Andy Whitcroft | e40c7f0 | 2005-11-29 19:25:54 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_IRQ_ALL_CPUS |
| 53 | #define distribute_irqs (1) |
| 54 | #else |
| 55 | #define distribute_irqs (0) |
| 56 | #endif |
Paul Mackerras | c0c0d99 | 2005-10-01 13:49:08 +1000 | [diff] [blame] | 57 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 58 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 59 | #ifdef CONFIG_MPIC_WEIRD |
| 60 | static u32 mpic_infos[][MPIC_IDX_END] = { |
| 61 | [0] = { /* Original OpenPIC compatible MPIC */ |
| 62 | MPIC_GREG_BASE, |
| 63 | MPIC_GREG_FEATURE_0, |
| 64 | MPIC_GREG_GLOBAL_CONF_0, |
| 65 | MPIC_GREG_VENDOR_ID, |
| 66 | MPIC_GREG_IPI_VECTOR_PRI_0, |
| 67 | MPIC_GREG_IPI_STRIDE, |
| 68 | MPIC_GREG_SPURIOUS, |
| 69 | MPIC_GREG_TIMER_FREQ, |
| 70 | |
| 71 | MPIC_TIMER_BASE, |
| 72 | MPIC_TIMER_STRIDE, |
| 73 | MPIC_TIMER_CURRENT_CNT, |
| 74 | MPIC_TIMER_BASE_CNT, |
| 75 | MPIC_TIMER_VECTOR_PRI, |
| 76 | MPIC_TIMER_DESTINATION, |
| 77 | |
| 78 | MPIC_CPU_BASE, |
| 79 | MPIC_CPU_STRIDE, |
| 80 | MPIC_CPU_IPI_DISPATCH_0, |
| 81 | MPIC_CPU_IPI_DISPATCH_STRIDE, |
| 82 | MPIC_CPU_CURRENT_TASK_PRI, |
| 83 | MPIC_CPU_WHOAMI, |
| 84 | MPIC_CPU_INTACK, |
| 85 | MPIC_CPU_EOI, |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 86 | MPIC_CPU_MCACK, |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 87 | |
| 88 | MPIC_IRQ_BASE, |
| 89 | MPIC_IRQ_STRIDE, |
| 90 | MPIC_IRQ_VECTOR_PRI, |
| 91 | MPIC_VECPRI_VECTOR_MASK, |
| 92 | MPIC_VECPRI_POLARITY_POSITIVE, |
| 93 | MPIC_VECPRI_POLARITY_NEGATIVE, |
| 94 | MPIC_VECPRI_SENSE_LEVEL, |
| 95 | MPIC_VECPRI_SENSE_EDGE, |
| 96 | MPIC_VECPRI_POLARITY_MASK, |
| 97 | MPIC_VECPRI_SENSE_MASK, |
| 98 | MPIC_IRQ_DESTINATION |
| 99 | }, |
| 100 | [1] = { /* Tsi108/109 PIC */ |
| 101 | TSI108_GREG_BASE, |
| 102 | TSI108_GREG_FEATURE_0, |
| 103 | TSI108_GREG_GLOBAL_CONF_0, |
| 104 | TSI108_GREG_VENDOR_ID, |
| 105 | TSI108_GREG_IPI_VECTOR_PRI_0, |
| 106 | TSI108_GREG_IPI_STRIDE, |
| 107 | TSI108_GREG_SPURIOUS, |
| 108 | TSI108_GREG_TIMER_FREQ, |
| 109 | |
| 110 | TSI108_TIMER_BASE, |
| 111 | TSI108_TIMER_STRIDE, |
| 112 | TSI108_TIMER_CURRENT_CNT, |
| 113 | TSI108_TIMER_BASE_CNT, |
| 114 | TSI108_TIMER_VECTOR_PRI, |
| 115 | TSI108_TIMER_DESTINATION, |
| 116 | |
| 117 | TSI108_CPU_BASE, |
| 118 | TSI108_CPU_STRIDE, |
| 119 | TSI108_CPU_IPI_DISPATCH_0, |
| 120 | TSI108_CPU_IPI_DISPATCH_STRIDE, |
| 121 | TSI108_CPU_CURRENT_TASK_PRI, |
| 122 | TSI108_CPU_WHOAMI, |
| 123 | TSI108_CPU_INTACK, |
| 124 | TSI108_CPU_EOI, |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 125 | TSI108_CPU_MCACK, |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 126 | |
| 127 | TSI108_IRQ_BASE, |
| 128 | TSI108_IRQ_STRIDE, |
| 129 | TSI108_IRQ_VECTOR_PRI, |
| 130 | TSI108_VECPRI_VECTOR_MASK, |
| 131 | TSI108_VECPRI_POLARITY_POSITIVE, |
| 132 | TSI108_VECPRI_POLARITY_NEGATIVE, |
| 133 | TSI108_VECPRI_SENSE_LEVEL, |
| 134 | TSI108_VECPRI_SENSE_EDGE, |
| 135 | TSI108_VECPRI_POLARITY_MASK, |
| 136 | TSI108_VECPRI_SENSE_MASK, |
| 137 | TSI108_IRQ_DESTINATION |
| 138 | }, |
| 139 | }; |
| 140 | |
| 141 | #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name] |
| 142 | |
| 143 | #else /* CONFIG_MPIC_WEIRD */ |
| 144 | |
| 145 | #define MPIC_INFO(name) MPIC_##name |
| 146 | |
| 147 | #endif /* CONFIG_MPIC_WEIRD */ |
| 148 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 149 | /* |
| 150 | * Register accessor functions |
| 151 | */ |
| 152 | |
| 153 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 154 | static inline u32 _mpic_read(enum mpic_reg_type type, |
| 155 | struct mpic_reg_bank *rb, |
| 156 | unsigned int reg) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 157 | { |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 158 | switch(type) { |
| 159 | #ifdef CONFIG_PPC_DCR |
| 160 | case mpic_access_dcr: |
Michael Ellerman | 83f34df | 2007-10-15 19:34:36 +1000 | [diff] [blame] | 161 | return dcr_read(rb->dhost, reg); |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 162 | #endif |
| 163 | case mpic_access_mmio_be: |
| 164 | return in_be32(rb->base + (reg >> 2)); |
| 165 | case mpic_access_mmio_le: |
| 166 | default: |
| 167 | return in_le32(rb->base + (reg >> 2)); |
| 168 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 169 | } |
| 170 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 171 | static inline void _mpic_write(enum mpic_reg_type type, |
| 172 | struct mpic_reg_bank *rb, |
| 173 | unsigned int reg, u32 value) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 174 | { |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 175 | switch(type) { |
| 176 | #ifdef CONFIG_PPC_DCR |
| 177 | case mpic_access_dcr: |
Michael Ellerman | 83f34df | 2007-10-15 19:34:36 +1000 | [diff] [blame] | 178 | return dcr_write(rb->dhost, reg, value); |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 179 | #endif |
| 180 | case mpic_access_mmio_be: |
| 181 | return out_be32(rb->base + (reg >> 2), value); |
| 182 | case mpic_access_mmio_le: |
| 183 | default: |
| 184 | return out_le32(rb->base + (reg >> 2), value); |
| 185 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi) |
| 189 | { |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 190 | enum mpic_reg_type type = mpic->reg_type; |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 191 | unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) + |
| 192 | (ipi * MPIC_INFO(GREG_IPI_STRIDE)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 193 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 194 | if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le) |
| 195 | type = mpic_access_mmio_be; |
| 196 | return _mpic_read(type, &mpic->gregs, offset); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value) |
| 200 | { |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 201 | unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) + |
| 202 | (ipi * MPIC_INFO(GREG_IPI_STRIDE)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 203 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 204 | _mpic_write(mpic->reg_type, &mpic->gregs, offset, value); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg) |
| 208 | { |
| 209 | unsigned int cpu = 0; |
| 210 | |
| 211 | if (mpic->flags & MPIC_PRIMARY) |
| 212 | cpu = hard_smp_processor_id(); |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 213 | return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value) |
| 217 | { |
| 218 | unsigned int cpu = 0; |
| 219 | |
| 220 | if (mpic->flags & MPIC_PRIMARY) |
| 221 | cpu = hard_smp_processor_id(); |
| 222 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 223 | _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg) |
| 227 | { |
| 228 | unsigned int isu = src_no >> mpic->isu_shift; |
| 229 | unsigned int idx = src_no & mpic->isu_mask; |
| 230 | |
Olof Johansson | 0d72ba9 | 2007-09-08 05:13:19 +1000 | [diff] [blame] | 231 | #ifdef CONFIG_MPIC_BROKEN_REGREAD |
| 232 | if (reg == 0) |
| 233 | return mpic->isu_reg0_shadow[idx]; |
| 234 | else |
| 235 | #endif |
| 236 | return _mpic_read(mpic->reg_type, &mpic->isus[isu], |
| 237 | reg + (idx * MPIC_INFO(IRQ_STRIDE))); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no, |
| 241 | unsigned int reg, u32 value) |
| 242 | { |
| 243 | unsigned int isu = src_no >> mpic->isu_shift; |
| 244 | unsigned int idx = src_no & mpic->isu_mask; |
| 245 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 246 | _mpic_write(mpic->reg_type, &mpic->isus[isu], |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 247 | reg + (idx * MPIC_INFO(IRQ_STRIDE)), value); |
Olof Johansson | 0d72ba9 | 2007-09-08 05:13:19 +1000 | [diff] [blame] | 248 | |
| 249 | #ifdef CONFIG_MPIC_BROKEN_REGREAD |
| 250 | if (reg == 0) |
| 251 | mpic->isu_reg0_shadow[idx] = value; |
| 252 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 253 | } |
| 254 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 255 | #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r)) |
| 256 | #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 257 | #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i)) |
| 258 | #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v)) |
| 259 | #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i)) |
| 260 | #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v)) |
| 261 | #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r)) |
| 262 | #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v)) |
| 263 | |
| 264 | |
| 265 | /* |
| 266 | * Low level utility functions |
| 267 | */ |
| 268 | |
| 269 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 270 | static void _mpic_map_mmio(struct mpic *mpic, unsigned long phys_addr, |
| 271 | struct mpic_reg_bank *rb, unsigned int offset, |
| 272 | unsigned int size) |
| 273 | { |
| 274 | rb->base = ioremap(phys_addr + offset, size); |
| 275 | BUG_ON(rb->base == NULL); |
| 276 | } |
| 277 | |
| 278 | #ifdef CONFIG_PPC_DCR |
| 279 | static void _mpic_map_dcr(struct mpic *mpic, struct mpic_reg_bank *rb, |
| 280 | unsigned int offset, unsigned int size) |
| 281 | { |
Michael Ellerman | 0411a5e | 2007-09-17 16:05:01 +1000 | [diff] [blame] | 282 | const u32 *dbasep; |
| 283 | |
| 284 | dbasep = of_get_property(mpic->irqhost->of_node, "dcr-reg", NULL); |
| 285 | |
| 286 | rb->dhost = dcr_map(mpic->irqhost->of_node, *dbasep + offset, size); |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 287 | BUG_ON(!DCR_MAP_OK(rb->dhost)); |
| 288 | } |
| 289 | |
| 290 | static inline void mpic_map(struct mpic *mpic, unsigned long phys_addr, |
| 291 | struct mpic_reg_bank *rb, unsigned int offset, |
| 292 | unsigned int size) |
| 293 | { |
| 294 | if (mpic->flags & MPIC_USES_DCR) |
| 295 | _mpic_map_dcr(mpic, rb, offset, size); |
| 296 | else |
| 297 | _mpic_map_mmio(mpic, phys_addr, rb, offset, size); |
| 298 | } |
| 299 | #else /* CONFIG_PPC_DCR */ |
| 300 | #define mpic_map(m,p,b,o,s) _mpic_map_mmio(m,p,b,o,s) |
| 301 | #endif /* !CONFIG_PPC_DCR */ |
| 302 | |
| 303 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 304 | |
| 305 | /* Check if we have one of those nice broken MPICs with a flipped endian on |
| 306 | * reads from IPI registers |
| 307 | */ |
| 308 | static void __init mpic_test_broken_ipi(struct mpic *mpic) |
| 309 | { |
| 310 | u32 r; |
| 311 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 312 | mpic_write(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0), MPIC_VECPRI_MASK); |
| 313 | r = mpic_read(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 314 | |
| 315 | if (r == le32_to_cpu(MPIC_VECPRI_MASK)) { |
| 316 | printk(KERN_INFO "mpic: Detected reversed IPI registers\n"); |
| 317 | mpic->flags |= MPIC_BROKEN_IPI; |
| 318 | } |
| 319 | } |
| 320 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 321 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 322 | |
| 323 | /* Test if an interrupt is sourced from HyperTransport (used on broken U3s) |
| 324 | * to force the edge setting on the MPIC and do the ack workaround. |
| 325 | */ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 326 | static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 327 | { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 328 | if (source >= 128 || !mpic->fixups) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 329 | return 0; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 330 | return mpic->fixups[source].base != NULL; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 331 | } |
| 332 | |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 333 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 334 | static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 335 | { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 336 | struct mpic_irq_fixup *fixup = &mpic->fixups[source]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 337 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 338 | if (fixup->applebase) { |
| 339 | unsigned int soff = (fixup->index >> 3) & ~3; |
| 340 | unsigned int mask = 1U << (fixup->index & 0x1f); |
| 341 | writel(mask, fixup->applebase + soff); |
| 342 | } else { |
| 343 | spin_lock(&mpic->fixup_lock); |
| 344 | writeb(0x11 + 2 * fixup->index, fixup->base + 2); |
| 345 | writel(fixup->data, fixup->base + 4); |
| 346 | spin_unlock(&mpic->fixup_lock); |
| 347 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 348 | } |
| 349 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 350 | static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source, |
| 351 | unsigned int irqflags) |
| 352 | { |
| 353 | struct mpic_irq_fixup *fixup = &mpic->fixups[source]; |
| 354 | unsigned long flags; |
| 355 | u32 tmp; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 356 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 357 | if (fixup->base == NULL) |
| 358 | return; |
| 359 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 360 | DBG("startup_ht_interrupt(0x%x, 0x%x) index: %d\n", |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 361 | source, irqflags, fixup->index); |
| 362 | spin_lock_irqsave(&mpic->fixup_lock, flags); |
| 363 | /* Enable and configure */ |
| 364 | writeb(0x10 + 2 * fixup->index, fixup->base + 2); |
| 365 | tmp = readl(fixup->base + 4); |
| 366 | tmp &= ~(0x23U); |
| 367 | if (irqflags & IRQ_LEVEL) |
| 368 | tmp |= 0x22; |
| 369 | writel(tmp, fixup->base + 4); |
| 370 | spin_unlock_irqrestore(&mpic->fixup_lock, flags); |
Johannes Berg | 3669e93 | 2007-05-02 16:33:41 +1000 | [diff] [blame] | 371 | |
| 372 | #ifdef CONFIG_PM |
| 373 | /* use the lowest bit inverted to the actual HW, |
| 374 | * set if this fixup was enabled, clear otherwise */ |
| 375 | mpic->save_data[source].fixup_data = tmp | 1; |
| 376 | #endif |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source, |
| 380 | unsigned int irqflags) |
| 381 | { |
| 382 | struct mpic_irq_fixup *fixup = &mpic->fixups[source]; |
| 383 | unsigned long flags; |
| 384 | u32 tmp; |
| 385 | |
| 386 | if (fixup->base == NULL) |
| 387 | return; |
| 388 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 389 | DBG("shutdown_ht_interrupt(0x%x, 0x%x)\n", source, irqflags); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 390 | |
| 391 | /* Disable */ |
| 392 | spin_lock_irqsave(&mpic->fixup_lock, flags); |
| 393 | writeb(0x10 + 2 * fixup->index, fixup->base + 2); |
| 394 | tmp = readl(fixup->base + 4); |
Segher Boessenkool | 72b1381 | 2006-02-17 11:25:42 +0100 | [diff] [blame] | 395 | tmp |= 1; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 396 | writel(tmp, fixup->base + 4); |
| 397 | spin_unlock_irqrestore(&mpic->fixup_lock, flags); |
Johannes Berg | 3669e93 | 2007-05-02 16:33:41 +1000 | [diff] [blame] | 398 | |
| 399 | #ifdef CONFIG_PM |
| 400 | /* use the lowest bit inverted to the actual HW, |
| 401 | * set if this fixup was enabled, clear otherwise */ |
| 402 | mpic->save_data[source].fixup_data = tmp & ~1; |
| 403 | #endif |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 404 | } |
| 405 | |
Michael Ellerman | 812fd1f | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 406 | #ifdef CONFIG_PCI_MSI |
| 407 | static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase, |
| 408 | unsigned int devfn) |
| 409 | { |
| 410 | u8 __iomem *base; |
| 411 | u8 pos, flags; |
| 412 | u64 addr = 0; |
| 413 | |
| 414 | for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0; |
| 415 | pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) { |
| 416 | u8 id = readb(devbase + pos + PCI_CAP_LIST_ID); |
| 417 | if (id == PCI_CAP_ID_HT) { |
| 418 | id = readb(devbase + pos + 3); |
| 419 | if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_MSI_MAPPING) |
| 420 | break; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | if (pos == 0) |
| 425 | return; |
| 426 | |
| 427 | base = devbase + pos; |
| 428 | |
| 429 | flags = readb(base + HT_MSI_FLAGS); |
| 430 | if (!(flags & HT_MSI_FLAGS_FIXED)) { |
| 431 | addr = readl(base + HT_MSI_ADDR_LO) & HT_MSI_ADDR_LO_MASK; |
| 432 | addr = addr | ((u64)readl(base + HT_MSI_ADDR_HI) << 32); |
| 433 | } |
| 434 | |
| 435 | printk(KERN_DEBUG "mpic: - HT:%02x.%x %s MSI mapping found @ 0x%lx\n", |
| 436 | PCI_SLOT(devfn), PCI_FUNC(devfn), |
| 437 | flags & HT_MSI_FLAGS_ENABLE ? "enabled" : "disabled", addr); |
| 438 | |
| 439 | if (!(flags & HT_MSI_FLAGS_ENABLE)) |
| 440 | writeb(flags | HT_MSI_FLAGS_ENABLE, base + HT_MSI_FLAGS); |
| 441 | } |
| 442 | #else |
| 443 | static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase, |
| 444 | unsigned int devfn) |
| 445 | { |
| 446 | return; |
| 447 | } |
| 448 | #endif |
| 449 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 450 | static void __init mpic_scan_ht_pic(struct mpic *mpic, u8 __iomem *devbase, |
| 451 | unsigned int devfn, u32 vdid) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 452 | { |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 453 | int i, irq, n; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 454 | u8 __iomem *base; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 455 | u32 tmp; |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 456 | u8 pos; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 457 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 458 | for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0; |
| 459 | pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) { |
| 460 | u8 id = readb(devbase + pos + PCI_CAP_LIST_ID); |
Brice Goglin | 46ff346 | 2006-08-31 01:55:24 -0400 | [diff] [blame] | 461 | if (id == PCI_CAP_ID_HT) { |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 462 | id = readb(devbase + pos + 3); |
Michael Ellerman | beb7cc8 | 2006-11-22 18:26:22 +1100 | [diff] [blame] | 463 | if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_IRQ) |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | } |
| 467 | if (pos == 0) |
| 468 | return; |
| 469 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 470 | base = devbase + pos; |
| 471 | writeb(0x01, base + 2); |
| 472 | n = (readl(base + 4) >> 16) & 0xff; |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 473 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 474 | printk(KERN_INFO "mpic: - HT:%02x.%x [0x%02x] vendor %04x device %04x" |
| 475 | " has %d irqs\n", |
| 476 | devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1); |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 477 | |
| 478 | for (i = 0; i <= n; i++) { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 479 | writeb(0x10 + 2 * i, base + 2); |
| 480 | tmp = readl(base + 4); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 481 | irq = (tmp >> 16) & 0xff; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 482 | DBG("HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp); |
| 483 | /* mask it , will be unmasked later */ |
| 484 | tmp |= 0x1; |
| 485 | writel(tmp, base + 4); |
| 486 | mpic->fixups[irq].index = i; |
| 487 | mpic->fixups[irq].base = base; |
| 488 | /* Apple HT PIC has a non-standard way of doing EOIs */ |
| 489 | if ((vdid & 0xffff) == 0x106b) |
| 490 | mpic->fixups[irq].applebase = devbase + 0x60; |
| 491 | else |
| 492 | mpic->fixups[irq].applebase = NULL; |
| 493 | writeb(0x11 + 2 * i, base + 2); |
| 494 | mpic->fixups[irq].data = readl(base + 4) | 0x80000000; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 498 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 499 | static void __init mpic_scan_ht_pics(struct mpic *mpic) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 500 | { |
| 501 | unsigned int devfn; |
| 502 | u8 __iomem *cfgspace; |
| 503 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 504 | printk(KERN_INFO "mpic: Setting up HT PICs workarounds for U3/U4\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 505 | |
| 506 | /* Allocate fixups array */ |
| 507 | mpic->fixups = alloc_bootmem(128 * sizeof(struct mpic_irq_fixup)); |
| 508 | BUG_ON(mpic->fixups == NULL); |
| 509 | memset(mpic->fixups, 0, 128 * sizeof(struct mpic_irq_fixup)); |
| 510 | |
| 511 | /* Init spinlock */ |
| 512 | spin_lock_init(&mpic->fixup_lock); |
| 513 | |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 514 | /* Map U3 config space. We assume all IO-APICs are on the primary bus |
| 515 | * so we only need to map 64kB. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 516 | */ |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 517 | cfgspace = ioremap(0xf2000000, 0x10000); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 518 | BUG_ON(cfgspace == NULL); |
| 519 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 520 | /* Now we scan all slots. We do a very quick scan, we read the header |
| 521 | * type, vendor ID and device ID only, that's plenty enough |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 522 | */ |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 523 | for (devfn = 0; devfn < 0x100; devfn++) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 524 | u8 __iomem *devbase = cfgspace + (devfn << 8); |
| 525 | u8 hdr_type = readb(devbase + PCI_HEADER_TYPE); |
| 526 | u32 l = readl(devbase + PCI_VENDOR_ID); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 527 | u16 s; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 528 | |
| 529 | DBG("devfn %x, l: %x\n", devfn, l); |
| 530 | |
| 531 | /* If no device, skip */ |
| 532 | if (l == 0xffffffff || l == 0x00000000 || |
| 533 | l == 0x0000ffff || l == 0xffff0000) |
| 534 | goto next; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 535 | /* Check if is supports capability lists */ |
| 536 | s = readw(devbase + PCI_STATUS); |
| 537 | if (!(s & PCI_STATUS_CAP_LIST)) |
| 538 | goto next; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 539 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 540 | mpic_scan_ht_pic(mpic, devbase, devfn, l); |
Michael Ellerman | 812fd1f | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 541 | mpic_scan_ht_msi(mpic, devbase, devfn); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 542 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 543 | next: |
| 544 | /* next device, if function 0 */ |
Segher Boessenkool | c4b22f2 | 2005-12-13 18:04:29 +1100 | [diff] [blame] | 545 | if (PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 546 | devfn += 7; |
| 547 | } |
| 548 | } |
| 549 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 550 | #else /* CONFIG_MPIC_U3_HT_IRQS */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 551 | |
| 552 | static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source) |
| 553 | { |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static void __init mpic_scan_ht_pics(struct mpic *mpic) |
| 558 | { |
| 559 | } |
| 560 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 561 | #endif /* CONFIG_MPIC_U3_HT_IRQS */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 562 | |
| 563 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 564 | #define mpic_irq_to_hw(virq) ((unsigned int)irq_map[virq].hwirq) |
| 565 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 566 | /* Find an mpic associated with a given linux interrupt */ |
| 567 | static struct mpic *mpic_find(unsigned int irq, unsigned int *is_ipi) |
| 568 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 569 | unsigned int src = mpic_irq_to_hw(irq); |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 570 | struct mpic *mpic; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 571 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 572 | if (irq < NUM_ISA_INTERRUPTS) |
| 573 | return NULL; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 574 | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 575 | mpic = irq_desc[irq].chip_data; |
| 576 | |
| 577 | if (is_ipi) |
| 578 | *is_ipi = (src >= mpic->ipi_vecs[0] && |
| 579 | src <= mpic->ipi_vecs[3]); |
| 580 | |
| 581 | return mpic; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /* Convert a cpu mask from logical to physical cpu numbers. */ |
| 585 | static inline u32 mpic_physmask(u32 cpumask) |
| 586 | { |
| 587 | int i; |
| 588 | u32 mask = 0; |
| 589 | |
| 590 | for (i = 0; i < NR_CPUS; ++i, cpumask >>= 1) |
| 591 | mask |= (cpumask & 1) << get_hard_smp_processor_id(i); |
| 592 | return mask; |
| 593 | } |
| 594 | |
| 595 | #ifdef CONFIG_SMP |
| 596 | /* Get the mpic structure from the IPI number */ |
| 597 | static inline struct mpic * mpic_from_ipi(unsigned int ipi) |
| 598 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 599 | return irq_desc[ipi].chip_data; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 600 | } |
| 601 | #endif |
| 602 | |
| 603 | /* Get the mpic structure from the irq number */ |
| 604 | static inline struct mpic * mpic_from_irq(unsigned int irq) |
| 605 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 606 | return irq_desc[irq].chip_data; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /* Send an EOI */ |
| 610 | static inline void mpic_eoi(struct mpic *mpic) |
| 611 | { |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 612 | mpic_cpu_write(MPIC_INFO(CPU_EOI), 0); |
| 613 | (void)mpic_cpu_read(MPIC_INFO(CPU_WHOAMI)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | #ifdef CONFIG_SMP |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 617 | static irqreturn_t mpic_ipi_action(int irq, void *data) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 618 | { |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 619 | long ipi = (long)data; |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 620 | |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 621 | smp_message_recv(ipi); |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 622 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 623 | return IRQ_HANDLED; |
| 624 | } |
| 625 | #endif /* CONFIG_SMP */ |
| 626 | |
| 627 | /* |
| 628 | * Linux descriptor level callbacks |
| 629 | */ |
| 630 | |
| 631 | |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 632 | void mpic_unmask_irq(unsigned int irq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 633 | { |
| 634 | unsigned int loops = 100000; |
| 635 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 636 | unsigned int src = mpic_irq_to_hw(irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 637 | |
Paul Mackerras | bd561c7 | 2005-10-26 21:55:33 +1000 | [diff] [blame] | 638 | DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, irq, src); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 639 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 640 | mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), |
| 641 | mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & |
Benjamin Herrenschmidt | e535664 | 2005-11-18 17:18:15 +1100 | [diff] [blame] | 642 | ~MPIC_VECPRI_MASK); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 643 | /* make sure mask gets to controller before we return to user */ |
| 644 | do { |
| 645 | if (!loops--) { |
| 646 | printk(KERN_ERR "mpic_enable_irq timeout\n"); |
| 647 | break; |
| 648 | } |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 649 | } while(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 650 | } |
| 651 | |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 652 | void mpic_mask_irq(unsigned int irq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 653 | { |
| 654 | unsigned int loops = 100000; |
| 655 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 656 | unsigned int src = mpic_irq_to_hw(irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 657 | |
| 658 | DBG("%s: disable_irq: %d (src %d)\n", mpic->name, irq, src); |
| 659 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 660 | mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), |
| 661 | mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) | |
Benjamin Herrenschmidt | e535664 | 2005-11-18 17:18:15 +1100 | [diff] [blame] | 662 | MPIC_VECPRI_MASK); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 663 | |
| 664 | /* make sure mask gets to controller before we return to user */ |
| 665 | do { |
| 666 | if (!loops--) { |
| 667 | printk(KERN_ERR "mpic_enable_irq timeout\n"); |
| 668 | break; |
| 669 | } |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 670 | } while(!(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 671 | } |
| 672 | |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 673 | void mpic_end_irq(unsigned int irq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 674 | { |
| 675 | struct mpic *mpic = mpic_from_irq(irq); |
| 676 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 677 | #ifdef DEBUG_IRQ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 678 | DBG("%s: end_irq: %d\n", mpic->name, irq); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 679 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 680 | /* We always EOI on end_irq() even for edge interrupts since that |
| 681 | * should only lower the priority, the MPIC should have properly |
| 682 | * latched another edge interrupt coming in anyway |
| 683 | */ |
| 684 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 685 | mpic_eoi(mpic); |
| 686 | } |
| 687 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 688 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 689 | |
| 690 | static void mpic_unmask_ht_irq(unsigned int irq) |
| 691 | { |
| 692 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 693 | unsigned int src = mpic_irq_to_hw(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 694 | |
| 695 | mpic_unmask_irq(irq); |
| 696 | |
| 697 | if (irq_desc[irq].status & IRQ_LEVEL) |
| 698 | mpic_ht_end_irq(mpic, src); |
| 699 | } |
| 700 | |
| 701 | static unsigned int mpic_startup_ht_irq(unsigned int irq) |
| 702 | { |
| 703 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 704 | unsigned int src = mpic_irq_to_hw(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 705 | |
| 706 | mpic_unmask_irq(irq); |
| 707 | mpic_startup_ht_interrupt(mpic, src, irq_desc[irq].status); |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static void mpic_shutdown_ht_irq(unsigned int irq) |
| 713 | { |
| 714 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 715 | unsigned int src = mpic_irq_to_hw(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 716 | |
| 717 | mpic_shutdown_ht_interrupt(mpic, src, irq_desc[irq].status); |
| 718 | mpic_mask_irq(irq); |
| 719 | } |
| 720 | |
| 721 | static void mpic_end_ht_irq(unsigned int irq) |
| 722 | { |
| 723 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 724 | unsigned int src = mpic_irq_to_hw(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 725 | |
| 726 | #ifdef DEBUG_IRQ |
| 727 | DBG("%s: end_irq: %d\n", mpic->name, irq); |
| 728 | #endif |
| 729 | /* We always EOI on end_irq() even for edge interrupts since that |
| 730 | * should only lower the priority, the MPIC should have properly |
| 731 | * latched another edge interrupt coming in anyway |
| 732 | */ |
| 733 | |
| 734 | if (irq_desc[irq].status & IRQ_LEVEL) |
| 735 | mpic_ht_end_irq(mpic, src); |
| 736 | mpic_eoi(mpic); |
| 737 | } |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 738 | #endif /* !CONFIG_MPIC_U3_HT_IRQS */ |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 739 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 740 | #ifdef CONFIG_SMP |
| 741 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 742 | static void mpic_unmask_ipi(unsigned int irq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 743 | { |
| 744 | struct mpic *mpic = mpic_from_ipi(irq); |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 745 | unsigned int src = mpic_irq_to_hw(irq) - mpic->ipi_vecs[0]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 746 | |
| 747 | DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, irq, src); |
| 748 | mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK); |
| 749 | } |
| 750 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 751 | static void mpic_mask_ipi(unsigned int irq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 752 | { |
| 753 | /* NEVER disable an IPI... that's just plain wrong! */ |
| 754 | } |
| 755 | |
| 756 | static void mpic_end_ipi(unsigned int irq) |
| 757 | { |
| 758 | struct mpic *mpic = mpic_from_ipi(irq); |
| 759 | |
| 760 | /* |
| 761 | * IPIs are marked IRQ_PER_CPU. This has the side effect of |
| 762 | * preventing the IRQ_PENDING/IRQ_INPROGRESS logic from |
| 763 | * applying to them. We EOI them late to avoid re-entering. |
Thomas Gleixner | 6714465 | 2006-07-01 19:29:22 -0700 | [diff] [blame] | 764 | * We mark IPI's with IRQF_DISABLED as they must run with |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 765 | * irqs disabled. |
| 766 | */ |
| 767 | mpic_eoi(mpic); |
| 768 | } |
| 769 | |
| 770 | #endif /* CONFIG_SMP */ |
| 771 | |
Olof Johansson | 17b5ee0 | 2007-09-18 06:12:29 +1000 | [diff] [blame] | 772 | void mpic_set_affinity(unsigned int irq, cpumask_t cpumask) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 773 | { |
| 774 | struct mpic *mpic = mpic_from_irq(irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 775 | unsigned int src = mpic_irq_to_hw(irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 776 | |
| 777 | cpumask_t tmp; |
| 778 | |
| 779 | cpus_and(tmp, cpumask, cpu_online_map); |
| 780 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 781 | mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 782 | mpic_physmask(cpus_addr(tmp)[0])); |
| 783 | } |
| 784 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 785 | static unsigned int mpic_type_to_vecpri(struct mpic *mpic, unsigned int type) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 786 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 787 | /* Now convert sense value */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 788 | switch(type & IRQ_TYPE_SENSE_MASK) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 789 | case IRQ_TYPE_EDGE_RISING: |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 790 | return MPIC_INFO(VECPRI_SENSE_EDGE) | |
| 791 | MPIC_INFO(VECPRI_POLARITY_POSITIVE); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 792 | case IRQ_TYPE_EDGE_FALLING: |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 793 | case IRQ_TYPE_EDGE_BOTH: |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 794 | return MPIC_INFO(VECPRI_SENSE_EDGE) | |
| 795 | MPIC_INFO(VECPRI_POLARITY_NEGATIVE); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 796 | case IRQ_TYPE_LEVEL_HIGH: |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 797 | return MPIC_INFO(VECPRI_SENSE_LEVEL) | |
| 798 | MPIC_INFO(VECPRI_POLARITY_POSITIVE); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 799 | case IRQ_TYPE_LEVEL_LOW: |
| 800 | default: |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 801 | return MPIC_INFO(VECPRI_SENSE_LEVEL) | |
| 802 | MPIC_INFO(VECPRI_POLARITY_NEGATIVE); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 803 | } |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 806 | int mpic_set_irq_type(unsigned int virq, unsigned int flow_type) |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 807 | { |
| 808 | struct mpic *mpic = mpic_from_irq(virq); |
| 809 | unsigned int src = mpic_irq_to_hw(virq); |
| 810 | struct irq_desc *desc = get_irq_desc(virq); |
| 811 | unsigned int vecpri, vold, vnew; |
| 812 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 813 | DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n", |
| 814 | mpic, virq, src, flow_type); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 815 | |
| 816 | if (src >= mpic->irq_count) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | if (flow_type == IRQ_TYPE_NONE) |
| 820 | if (mpic->senses && src < mpic->senses_count) |
| 821 | flow_type = mpic->senses[src]; |
| 822 | if (flow_type == IRQ_TYPE_NONE) |
| 823 | flow_type = IRQ_TYPE_LEVEL_LOW; |
| 824 | |
| 825 | desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL); |
| 826 | desc->status |= flow_type & IRQ_TYPE_SENSE_MASK; |
| 827 | if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) |
| 828 | desc->status |= IRQ_LEVEL; |
| 829 | |
| 830 | if (mpic_is_ht_interrupt(mpic, src)) |
| 831 | vecpri = MPIC_VECPRI_POLARITY_POSITIVE | |
| 832 | MPIC_VECPRI_SENSE_EDGE; |
| 833 | else |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 834 | vecpri = mpic_type_to_vecpri(mpic, flow_type); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 835 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 836 | vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)); |
| 837 | vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) | |
| 838 | MPIC_INFO(VECPRI_SENSE_MASK)); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 839 | vnew |= vecpri; |
| 840 | if (vold != vnew) |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 841 | mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vnew); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 842 | |
| 843 | return 0; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 844 | } |
| 845 | |
Olof Johansson | 38958dd | 2007-12-12 17:44:46 +1100 | [diff] [blame] | 846 | void mpic_set_vector(unsigned int virq, unsigned int vector) |
| 847 | { |
| 848 | struct mpic *mpic = mpic_from_irq(virq); |
| 849 | unsigned int src = mpic_irq_to_hw(virq); |
| 850 | unsigned int vecpri; |
| 851 | |
| 852 | DBG("mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n", |
| 853 | mpic, virq, src, vector); |
| 854 | |
| 855 | if (src >= mpic->irq_count) |
| 856 | return; |
| 857 | |
| 858 | vecpri = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)); |
| 859 | vecpri = vecpri & ~MPIC_INFO(VECPRI_VECTOR_MASK); |
| 860 | vecpri |= vector; |
| 861 | mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri); |
| 862 | } |
| 863 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 864 | static struct irq_chip mpic_irq_chip = { |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 865 | .mask = mpic_mask_irq, |
| 866 | .unmask = mpic_unmask_irq, |
| 867 | .eoi = mpic_end_irq, |
| 868 | .set_type = mpic_set_irq_type, |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | #ifdef CONFIG_SMP |
| 872 | static struct irq_chip mpic_ipi_chip = { |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 873 | .mask = mpic_mask_ipi, |
| 874 | .unmask = mpic_unmask_ipi, |
| 875 | .eoi = mpic_end_ipi, |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 876 | }; |
| 877 | #endif /* CONFIG_SMP */ |
| 878 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 879 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 880 | static struct irq_chip mpic_irq_ht_chip = { |
| 881 | .startup = mpic_startup_ht_irq, |
| 882 | .shutdown = mpic_shutdown_ht_irq, |
| 883 | .mask = mpic_mask_irq, |
| 884 | .unmask = mpic_unmask_ht_irq, |
| 885 | .eoi = mpic_end_ht_irq, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 886 | .set_type = mpic_set_irq_type, |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 887 | }; |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 888 | #endif /* CONFIG_MPIC_U3_HT_IRQS */ |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 889 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 890 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 891 | static int mpic_host_match(struct irq_host *h, struct device_node *node) |
| 892 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 893 | /* Exact match, unless mpic node is NULL */ |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 894 | return h->of_node == NULL || h->of_node == node; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static int mpic_host_map(struct irq_host *h, unsigned int virq, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 898 | irq_hw_number_t hw) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 899 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 900 | struct mpic *mpic = h->host_data; |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 901 | struct irq_chip *chip; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 902 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 903 | DBG("mpic: map virq %d, hwirq 0x%lx\n", virq, hw); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 904 | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 905 | if (hw == mpic->spurious_vec) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 906 | return -EINVAL; |
Benjamin Herrenschmidt | 7fd7218 | 2007-07-21 09:55:21 +1000 | [diff] [blame] | 907 | if (mpic->protected && test_bit(hw, mpic->protected)) |
| 908 | return -EINVAL; |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 909 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 910 | #ifdef CONFIG_SMP |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 911 | else if (hw >= mpic->ipi_vecs[0]) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 912 | WARN_ON(!(mpic->flags & MPIC_PRIMARY)); |
| 913 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 914 | DBG("mpic: mapping as IPI\n"); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 915 | set_irq_chip_data(virq, mpic); |
| 916 | set_irq_chip_and_handler(virq, &mpic->hc_ipi, |
| 917 | handle_percpu_irq); |
| 918 | return 0; |
| 919 | } |
| 920 | #endif /* CONFIG_SMP */ |
| 921 | |
| 922 | if (hw >= mpic->irq_count) |
| 923 | return -EINVAL; |
| 924 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 925 | mpic_msi_reserve_hwirq(mpic, hw); |
| 926 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 927 | /* Default chip */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 928 | chip = &mpic->hc_irq; |
| 929 | |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 930 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 931 | /* Check for HT interrupts, override vecpri */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 932 | if (mpic_is_ht_interrupt(mpic, hw)) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 933 | chip = &mpic->hc_ht_irq; |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 934 | #endif /* CONFIG_MPIC_U3_HT_IRQS */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 935 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 936 | DBG("mpic: mapping to irq chip @%p\n", chip); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 937 | |
| 938 | set_irq_chip_data(virq, mpic); |
| 939 | set_irq_chip_and_handler(virq, chip, handle_fasteoi_irq); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 940 | |
| 941 | /* Set default irq type */ |
| 942 | set_irq_type(virq, IRQ_TYPE_NONE); |
| 943 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | static int mpic_host_xlate(struct irq_host *h, struct device_node *ct, |
| 948 | u32 *intspec, unsigned int intsize, |
| 949 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 950 | |
| 951 | { |
| 952 | static unsigned char map_mpic_senses[4] = { |
| 953 | IRQ_TYPE_EDGE_RISING, |
| 954 | IRQ_TYPE_LEVEL_LOW, |
| 955 | IRQ_TYPE_LEVEL_HIGH, |
| 956 | IRQ_TYPE_EDGE_FALLING, |
| 957 | }; |
| 958 | |
| 959 | *out_hwirq = intspec[0]; |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 960 | if (intsize > 1) { |
| 961 | u32 mask = 0x3; |
| 962 | |
| 963 | /* Apple invented a new race of encoding on machines with |
| 964 | * an HT APIC. They encode, among others, the index within |
| 965 | * the HT APIC. We don't care about it here since thankfully, |
| 966 | * it appears that they have the APIC already properly |
| 967 | * configured, and thus our current fixup code that reads the |
| 968 | * APIC config works fine. However, we still need to mask out |
| 969 | * bits in the specifier to make sure we only get bit 0 which |
| 970 | * is the level/edge bit (the only sense bit exposed by Apple), |
| 971 | * as their bit 1 means something else. |
| 972 | */ |
| 973 | if (machine_is(powermac)) |
| 974 | mask = 0x1; |
| 975 | *out_flags = map_mpic_senses[intspec[1] & mask]; |
| 976 | } else |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 977 | *out_flags = IRQ_TYPE_NONE; |
| 978 | |
Benjamin Herrenschmidt | 06fe98e | 2006-07-10 04:44:43 -0700 | [diff] [blame] | 979 | DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n", |
| 980 | intsize, intspec[0], intspec[1], *out_hwirq, *out_flags); |
| 981 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | static struct irq_host_ops mpic_host_ops = { |
| 986 | .match = mpic_host_match, |
| 987 | .map = mpic_host_map, |
| 988 | .xlate = mpic_host_xlate, |
| 989 | }; |
| 990 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 991 | /* |
| 992 | * Exported functions |
| 993 | */ |
| 994 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 995 | struct mpic * __init mpic_alloc(struct device_node *node, |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 996 | phys_addr_t phys_addr, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 997 | unsigned int flags, |
| 998 | unsigned int isu_size, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 999 | unsigned int irq_count, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1000 | const char *name) |
| 1001 | { |
| 1002 | struct mpic *mpic; |
| 1003 | u32 reg; |
| 1004 | const char *vers; |
| 1005 | int i; |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1006 | int intvec_top; |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1007 | u64 paddr = phys_addr; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1008 | |
| 1009 | mpic = alloc_bootmem(sizeof(struct mpic)); |
| 1010 | if (mpic == NULL) |
| 1011 | return NULL; |
| 1012 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1013 | memset(mpic, 0, sizeof(struct mpic)); |
| 1014 | mpic->name = name; |
| 1015 | |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 1016 | mpic->irqhost = irq_alloc_host(of_node_get(node), IRQ_HOST_MAP_LINEAR, |
| 1017 | isu_size, &mpic_host_ops, |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1018 | flags & MPIC_LARGE_VECTORS ? 2048 : 256); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1019 | if (mpic->irqhost == NULL) { |
| 1020 | of_node_put(node); |
| 1021 | return NULL; |
| 1022 | } |
| 1023 | |
| 1024 | mpic->irqhost->host_data = mpic; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 1025 | mpic->hc_irq = mpic_irq_chip; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1026 | mpic->hc_irq.typename = name; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1027 | if (flags & MPIC_PRIMARY) |
| 1028 | mpic->hc_irq.set_affinity = mpic_set_affinity; |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 1029 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 1030 | mpic->hc_ht_irq = mpic_irq_ht_chip; |
| 1031 | mpic->hc_ht_irq.typename = name; |
| 1032 | if (flags & MPIC_PRIMARY) |
| 1033 | mpic->hc_ht_irq.set_affinity = mpic_set_affinity; |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 1034 | #endif /* CONFIG_MPIC_U3_HT_IRQS */ |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1035 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1036 | #ifdef CONFIG_SMP |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 1037 | mpic->hc_ipi = mpic_ipi_chip; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1038 | mpic->hc_ipi.typename = name; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1039 | #endif /* CONFIG_SMP */ |
| 1040 | |
| 1041 | mpic->flags = flags; |
| 1042 | mpic->isu_size = isu_size; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1043 | mpic->irq_count = irq_count; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1044 | mpic->num_sources = 0; /* so far */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1045 | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1046 | if (flags & MPIC_LARGE_VECTORS) |
| 1047 | intvec_top = 2047; |
| 1048 | else |
| 1049 | intvec_top = 255; |
| 1050 | |
| 1051 | mpic->timer_vecs[0] = intvec_top - 8; |
| 1052 | mpic->timer_vecs[1] = intvec_top - 7; |
| 1053 | mpic->timer_vecs[2] = intvec_top - 6; |
| 1054 | mpic->timer_vecs[3] = intvec_top - 5; |
| 1055 | mpic->ipi_vecs[0] = intvec_top - 4; |
| 1056 | mpic->ipi_vecs[1] = intvec_top - 3; |
| 1057 | mpic->ipi_vecs[2] = intvec_top - 2; |
| 1058 | mpic->ipi_vecs[3] = intvec_top - 1; |
| 1059 | mpic->spurious_vec = intvec_top; |
| 1060 | |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1061 | /* Check for "big-endian" in device-tree */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1062 | if (node && of_get_property(node, "big-endian", NULL) != NULL) |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1063 | mpic->flags |= MPIC_BIG_ENDIAN; |
| 1064 | |
Benjamin Herrenschmidt | 7fd7218 | 2007-07-21 09:55:21 +1000 | [diff] [blame] | 1065 | /* Look for protected sources */ |
| 1066 | if (node) { |
| 1067 | unsigned int psize, bits, mapsize; |
| 1068 | const u32 *psrc = |
| 1069 | of_get_property(node, "protected-sources", &psize); |
| 1070 | if (psrc) { |
| 1071 | psize /= 4; |
| 1072 | bits = intvec_top + 1; |
| 1073 | mapsize = BITS_TO_LONGS(bits) * sizeof(unsigned long); |
| 1074 | mpic->protected = alloc_bootmem(mapsize); |
| 1075 | BUG_ON(mpic->protected == NULL); |
| 1076 | memset(mpic->protected, 0, mapsize); |
| 1077 | for (i = 0; i < psize; i++) { |
| 1078 | if (psrc[i] > intvec_top) |
| 1079 | continue; |
| 1080 | __set_bit(psrc[i], mpic->protected); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1084 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1085 | #ifdef CONFIG_MPIC_WEIRD |
| 1086 | mpic->hw_set = mpic_infos[MPIC_GET_REGSET(flags)]; |
| 1087 | #endif |
| 1088 | |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1089 | /* default register type */ |
| 1090 | mpic->reg_type = (flags & MPIC_BIG_ENDIAN) ? |
| 1091 | mpic_access_mmio_be : mpic_access_mmio_le; |
| 1092 | |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1093 | /* If no physical address is passed in, a device-node is mandatory */ |
| 1094 | BUG_ON(paddr == 0 && node == NULL); |
| 1095 | |
| 1096 | /* If no physical address passed in, check if it's dcr based */ |
Michael Ellerman | 0411a5e | 2007-09-17 16:05:01 +1000 | [diff] [blame] | 1097 | if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) { |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1098 | #ifdef CONFIG_PPC_DCR |
Michael Ellerman | 0411a5e | 2007-09-17 16:05:01 +1000 | [diff] [blame] | 1099 | mpic->flags |= MPIC_USES_DCR; |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1100 | mpic->reg_type = mpic_access_dcr; |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1101 | #else |
Michael Ellerman | 0411a5e | 2007-09-17 16:05:01 +1000 | [diff] [blame] | 1102 | BUG(); |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1103 | #endif /* CONFIG_PPC_DCR */ |
Michael Ellerman | 0411a5e | 2007-09-17 16:05:01 +1000 | [diff] [blame] | 1104 | } |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1105 | |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1106 | /* If the MPIC is not DCR based, and no physical address was passed |
| 1107 | * in, try to obtain one |
| 1108 | */ |
| 1109 | if (paddr == 0 && !(mpic->flags & MPIC_USES_DCR)) { |
| 1110 | const u32 *reg; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1111 | reg = of_get_property(node, "reg", NULL); |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1112 | BUG_ON(reg == NULL); |
| 1113 | paddr = of_translate_address(node, reg); |
| 1114 | BUG_ON(paddr == OF_BAD_ADDR); |
| 1115 | } |
| 1116 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1117 | /* Map the global registers */ |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1118 | mpic_map(mpic, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000); |
| 1119 | mpic_map(mpic, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1120 | |
| 1121 | /* Reset */ |
| 1122 | if (flags & MPIC_WANTS_RESET) { |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1123 | mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0), |
| 1124 | mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1125 | | MPIC_GREG_GCONF_RESET); |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1126 | while( mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1127 | & MPIC_GREG_GCONF_RESET) |
| 1128 | mb(); |
| 1129 | } |
| 1130 | |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1131 | if (flags & MPIC_ENABLE_MCK) |
| 1132 | mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0), |
| 1133 | mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0)) |
| 1134 | | MPIC_GREG_GCONF_MCK); |
| 1135 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1136 | /* Read feature register, calculate num CPUs and, for non-ISU |
| 1137 | * MPICs, num sources as well. On ISU MPICs, sources are counted |
| 1138 | * as ISUs are added |
| 1139 | */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1140 | reg = mpic_read(mpic->gregs, MPIC_INFO(GREG_FEATURE_0)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1141 | mpic->num_cpus = ((reg & MPIC_GREG_FEATURE_LAST_CPU_MASK) |
| 1142 | >> MPIC_GREG_FEATURE_LAST_CPU_SHIFT) + 1; |
| 1143 | if (isu_size == 0) |
| 1144 | mpic->num_sources = ((reg & MPIC_GREG_FEATURE_LAST_SRC_MASK) |
| 1145 | >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1; |
| 1146 | |
| 1147 | /* Map the per-CPU registers */ |
| 1148 | for (i = 0; i < mpic->num_cpus; i++) { |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1149 | mpic_map(mpic, paddr, &mpic->cpuregs[i], |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1150 | MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE), |
| 1151 | 0x1000); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /* Initialize main ISU if none provided */ |
| 1155 | if (mpic->isu_size == 0) { |
| 1156 | mpic->isu_size = mpic->num_sources; |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1157 | mpic_map(mpic, paddr, &mpic->isus[0], |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1158 | MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1159 | } |
| 1160 | mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1); |
| 1161 | mpic->isu_mask = (1 << mpic->isu_shift) - 1; |
| 1162 | |
| 1163 | /* Display version */ |
| 1164 | switch (reg & MPIC_GREG_FEATURE_VERSION_MASK) { |
| 1165 | case 1: |
| 1166 | vers = "1.0"; |
| 1167 | break; |
| 1168 | case 2: |
| 1169 | vers = "1.2"; |
| 1170 | break; |
| 1171 | case 3: |
| 1172 | vers = "1.3"; |
| 1173 | break; |
| 1174 | default: |
| 1175 | vers = "<unknown>"; |
| 1176 | break; |
| 1177 | } |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1178 | printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %llx," |
| 1179 | " max %d CPUs\n", |
| 1180 | name, vers, (unsigned long long)paddr, mpic->num_cpus); |
| 1181 | printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n", |
| 1182 | mpic->isu_size, mpic->isu_shift, mpic->isu_mask); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1183 | |
| 1184 | mpic->next = mpics; |
| 1185 | mpics = mpic; |
| 1186 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1187 | if (flags & MPIC_PRIMARY) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1188 | mpic_primary = mpic; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1189 | irq_set_default_host(mpic->irqhost); |
| 1190 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1191 | |
| 1192 | return mpic; |
| 1193 | } |
| 1194 | |
| 1195 | void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num, |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1196 | phys_addr_t paddr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1197 | { |
| 1198 | unsigned int isu_first = isu_num * mpic->isu_size; |
| 1199 | |
| 1200 | BUG_ON(isu_num >= MPIC_MAX_ISU); |
| 1201 | |
Benjamin Herrenschmidt | a959ff5 | 2006-11-11 17:24:56 +1100 | [diff] [blame] | 1202 | mpic_map(mpic, paddr, &mpic->isus[isu_num], 0, |
Benjamin Herrenschmidt | fbf0274 | 2006-11-11 17:24:55 +1100 | [diff] [blame] | 1203 | MPIC_INFO(IRQ_STRIDE) * mpic->isu_size); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1204 | if ((isu_first + mpic->isu_size) > mpic->num_sources) |
| 1205 | mpic->num_sources = isu_first + mpic->isu_size; |
| 1206 | } |
| 1207 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1208 | void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count) |
| 1209 | { |
| 1210 | mpic->senses = senses; |
| 1211 | mpic->senses_count = count; |
| 1212 | } |
| 1213 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1214 | void __init mpic_init(struct mpic *mpic) |
| 1215 | { |
| 1216 | int i; |
| 1217 | |
| 1218 | BUG_ON(mpic->num_sources == 0); |
| 1219 | |
| 1220 | printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources); |
| 1221 | |
| 1222 | /* Set current processor priority to max */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1223 | mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1224 | |
| 1225 | /* Initialize timers: just disable them all */ |
| 1226 | for (i = 0; i < 4; i++) { |
| 1227 | mpic_write(mpic->tmregs, |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1228 | i * MPIC_INFO(TIMER_STRIDE) + |
| 1229 | MPIC_INFO(TIMER_DESTINATION), 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1230 | mpic_write(mpic->tmregs, |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1231 | i * MPIC_INFO(TIMER_STRIDE) + |
| 1232 | MPIC_INFO(TIMER_VECTOR_PRI), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1233 | MPIC_VECPRI_MASK | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1234 | (mpic->timer_vecs[0] + i)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | /* Initialize IPIs to our reserved vectors and mark them disabled for now */ |
| 1238 | mpic_test_broken_ipi(mpic); |
| 1239 | for (i = 0; i < 4; i++) { |
| 1240 | mpic_ipi_write(i, |
| 1241 | MPIC_VECPRI_MASK | |
| 1242 | (10 << MPIC_VECPRI_PRIORITY_SHIFT) | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1243 | (mpic->ipi_vecs[0] + i)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /* Initialize interrupt sources */ |
| 1247 | if (mpic->irq_count == 0) |
| 1248 | mpic->irq_count = mpic->num_sources; |
| 1249 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1250 | /* Do the HT PIC fixups on U3 broken mpic */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1251 | DBG("MPIC flags: %x\n", mpic->flags); |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 1252 | if ((mpic->flags & MPIC_U3_HT_IRQS) && (mpic->flags & MPIC_PRIMARY)) { |
Johannes Berg | 3669e93 | 2007-05-02 16:33:41 +1000 | [diff] [blame] | 1253 | mpic_scan_ht_pics(mpic); |
Michael Ellerman | 05af7bd | 2007-05-08 12:58:37 +1000 | [diff] [blame] | 1254 | mpic_u3msi_init(mpic); |
| 1255 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1256 | |
Olof Johansson | 38958dd | 2007-12-12 17:44:46 +1100 | [diff] [blame] | 1257 | mpic_pasemi_msi_init(mpic); |
| 1258 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1259 | for (i = 0; i < mpic->num_sources; i++) { |
| 1260 | /* start with vector = source number, and masked */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 1261 | u32 vecpri = MPIC_VECPRI_MASK | i | |
| 1262 | (8 << MPIC_VECPRI_PRIORITY_SHIFT); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1263 | |
Benjamin Herrenschmidt | 7fd7218 | 2007-07-21 09:55:21 +1000 | [diff] [blame] | 1264 | /* check if protected */ |
| 1265 | if (mpic->protected && test_bit(i, mpic->protected)) |
| 1266 | continue; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1267 | /* init hw */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1268 | mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri); |
| 1269 | mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1270 | 1 << hard_smp_processor_id()); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1271 | } |
| 1272 | |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1273 | /* Init spurious vector */ |
| 1274 | mpic_write(mpic->gregs, MPIC_INFO(GREG_SPURIOUS), mpic->spurious_vec); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1275 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1276 | /* Disable 8259 passthrough, if supported */ |
| 1277 | if (!(mpic->flags & MPIC_NO_PTHROU_DIS)) |
| 1278 | mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0), |
| 1279 | mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0)) |
| 1280 | | MPIC_GREG_GCONF_8259_PTHROU_DIS); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1281 | |
| 1282 | /* Set current processor priority to 0 */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1283 | mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0); |
Johannes Berg | 3669e93 | 2007-05-02 16:33:41 +1000 | [diff] [blame] | 1284 | |
| 1285 | #ifdef CONFIG_PM |
| 1286 | /* allocate memory to save mpic state */ |
| 1287 | mpic->save_data = alloc_bootmem(mpic->num_sources * sizeof(struct mpic_irq_save)); |
| 1288 | BUG_ON(mpic->save_data == NULL); |
| 1289 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1290 | } |
| 1291 | |
Mark A. Greer | 868ea0c | 2006-06-20 14:15:36 -0700 | [diff] [blame] | 1292 | void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio) |
| 1293 | { |
| 1294 | u32 v; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1295 | |
Mark A. Greer | 868ea0c | 2006-06-20 14:15:36 -0700 | [diff] [blame] | 1296 | v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1); |
| 1297 | v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK; |
| 1298 | v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio); |
| 1299 | mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v); |
| 1300 | } |
| 1301 | |
| 1302 | void __init mpic_set_serial_int(struct mpic *mpic, int enable) |
| 1303 | { |
Benjamin Herrenschmidt | ba1826e | 2006-07-05 15:36:15 +1000 | [diff] [blame] | 1304 | unsigned long flags; |
Mark A. Greer | 868ea0c | 2006-06-20 14:15:36 -0700 | [diff] [blame] | 1305 | u32 v; |
| 1306 | |
Benjamin Herrenschmidt | ba1826e | 2006-07-05 15:36:15 +1000 | [diff] [blame] | 1307 | spin_lock_irqsave(&mpic_lock, flags); |
Mark A. Greer | 868ea0c | 2006-06-20 14:15:36 -0700 | [diff] [blame] | 1308 | v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1); |
| 1309 | if (enable) |
| 1310 | v |= MPIC_GREG_GLOBAL_CONF_1_SIE; |
| 1311 | else |
| 1312 | v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE; |
| 1313 | mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v); |
Benjamin Herrenschmidt | ba1826e | 2006-07-05 15:36:15 +1000 | [diff] [blame] | 1314 | spin_unlock_irqrestore(&mpic_lock, flags); |
Mark A. Greer | 868ea0c | 2006-06-20 14:15:36 -0700 | [diff] [blame] | 1315 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1316 | |
| 1317 | void mpic_irq_set_priority(unsigned int irq, unsigned int pri) |
| 1318 | { |
| 1319 | int is_ipi; |
| 1320 | struct mpic *mpic = mpic_find(irq, &is_ipi); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1321 | unsigned int src = mpic_irq_to_hw(irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1322 | unsigned long flags; |
| 1323 | u32 reg; |
| 1324 | |
| 1325 | spin_lock_irqsave(&mpic_lock, flags); |
| 1326 | if (is_ipi) { |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1327 | reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) & |
Benjamin Herrenschmidt | e535664 | 2005-11-18 17:18:15 +1100 | [diff] [blame] | 1328 | ~MPIC_VECPRI_PRIORITY_MASK; |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1329 | mpic_ipi_write(src - mpic->ipi_vecs[0], |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1330 | reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT)); |
| 1331 | } else { |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1332 | reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) |
Benjamin Herrenschmidt | e535664 | 2005-11-18 17:18:15 +1100 | [diff] [blame] | 1333 | & ~MPIC_VECPRI_PRIORITY_MASK; |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1334 | mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1335 | reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT)); |
| 1336 | } |
| 1337 | spin_unlock_irqrestore(&mpic_lock, flags); |
| 1338 | } |
| 1339 | |
| 1340 | unsigned int mpic_irq_get_priority(unsigned int irq) |
| 1341 | { |
| 1342 | int is_ipi; |
| 1343 | struct mpic *mpic = mpic_find(irq, &is_ipi); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1344 | unsigned int src = mpic_irq_to_hw(irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1345 | unsigned long flags; |
| 1346 | u32 reg; |
| 1347 | |
| 1348 | spin_lock_irqsave(&mpic_lock, flags); |
| 1349 | if (is_ipi) |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1350 | reg = mpic_ipi_read(src = mpic->ipi_vecs[0]); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1351 | else |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1352 | reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1353 | spin_unlock_irqrestore(&mpic_lock, flags); |
| 1354 | return (reg & MPIC_VECPRI_PRIORITY_MASK) >> MPIC_VECPRI_PRIORITY_SHIFT; |
| 1355 | } |
| 1356 | |
| 1357 | void mpic_setup_this_cpu(void) |
| 1358 | { |
| 1359 | #ifdef CONFIG_SMP |
| 1360 | struct mpic *mpic = mpic_primary; |
| 1361 | unsigned long flags; |
| 1362 | u32 msk = 1 << hard_smp_processor_id(); |
| 1363 | unsigned int i; |
| 1364 | |
| 1365 | BUG_ON(mpic == NULL); |
| 1366 | |
| 1367 | DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id()); |
| 1368 | |
| 1369 | spin_lock_irqsave(&mpic_lock, flags); |
| 1370 | |
| 1371 | /* let the mpic know we want intrs. default affinity is 0xffffffff |
| 1372 | * until changed via /proc. That's how it's done on x86. If we want |
| 1373 | * it differently, then we should make sure we also change the default |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 1374 | * values of irq_desc[].affinity in irq.c. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1375 | */ |
| 1376 | if (distribute_irqs) { |
| 1377 | for (i = 0; i < mpic->num_sources ; i++) |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1378 | mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), |
| 1379 | mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) | msk); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /* Set current processor priority to 0 */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1383 | mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1384 | |
| 1385 | spin_unlock_irqrestore(&mpic_lock, flags); |
| 1386 | #endif /* CONFIG_SMP */ |
| 1387 | } |
| 1388 | |
| 1389 | int mpic_cpu_get_priority(void) |
| 1390 | { |
| 1391 | struct mpic *mpic = mpic_primary; |
| 1392 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1393 | return mpic_cpu_read(MPIC_INFO(CPU_CURRENT_TASK_PRI)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | void mpic_cpu_set_priority(int prio) |
| 1397 | { |
| 1398 | struct mpic *mpic = mpic_primary; |
| 1399 | |
| 1400 | prio &= MPIC_CPU_TASKPRI_MASK; |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1401 | mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), prio); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /* |
| 1405 | * XXX: someone who knows mpic should check this. |
| 1406 | * do we need to eoi the ipi including for kexec cpu here (see xics comments)? |
| 1407 | * or can we reset the mpic in the new kernel? |
| 1408 | */ |
| 1409 | void mpic_teardown_this_cpu(int secondary) |
| 1410 | { |
| 1411 | struct mpic *mpic = mpic_primary; |
| 1412 | unsigned long flags; |
| 1413 | u32 msk = 1 << hard_smp_processor_id(); |
| 1414 | unsigned int i; |
| 1415 | |
| 1416 | BUG_ON(mpic == NULL); |
| 1417 | |
| 1418 | DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id()); |
| 1419 | spin_lock_irqsave(&mpic_lock, flags); |
| 1420 | |
| 1421 | /* let the mpic know we don't want intrs. */ |
| 1422 | for (i = 0; i < mpic->num_sources ; i++) |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1423 | mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), |
| 1424 | mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) & ~msk); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1425 | |
| 1426 | /* Set current processor priority to max */ |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1427 | mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1428 | |
| 1429 | spin_unlock_irqrestore(&mpic_lock, flags); |
| 1430 | } |
| 1431 | |
| 1432 | |
| 1433 | void mpic_send_ipi(unsigned int ipi_no, unsigned int cpu_mask) |
| 1434 | { |
| 1435 | struct mpic *mpic = mpic_primary; |
| 1436 | |
| 1437 | BUG_ON(mpic == NULL); |
| 1438 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1439 | #ifdef DEBUG_IPI |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1440 | DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1441 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1442 | |
Zang Roy-r61911 | 7233593 | 2006-08-25 14:16:30 +1000 | [diff] [blame] | 1443 | mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) + |
| 1444 | ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1445 | mpic_physmask(cpu_mask & cpus_addr(cpu_online_map)[0])); |
| 1446 | } |
| 1447 | |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1448 | static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1449 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1450 | u32 src; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1451 | |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1452 | src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1453 | #ifdef DEBUG_LOW |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1454 | DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 1455 | #endif |
Josh Boyer | 5cddd2e | 2007-05-01 06:38:11 +1000 | [diff] [blame] | 1456 | if (unlikely(src == mpic->spurious_vec)) { |
| 1457 | if (mpic->flags & MPIC_SPV_EOI) |
| 1458 | mpic_eoi(mpic); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1459 | return NO_IRQ; |
Josh Boyer | 5cddd2e | 2007-05-01 06:38:11 +1000 | [diff] [blame] | 1460 | } |
Benjamin Herrenschmidt | 7fd7218 | 2007-07-21 09:55:21 +1000 | [diff] [blame] | 1461 | if (unlikely(mpic->protected && test_bit(src, mpic->protected))) { |
| 1462 | if (printk_ratelimit()) |
| 1463 | printk(KERN_WARNING "%s: Got protected source %d !\n", |
| 1464 | mpic->name, (int)src); |
| 1465 | mpic_eoi(mpic); |
| 1466 | return NO_IRQ; |
| 1467 | } |
| 1468 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1469 | return irq_linear_revmap(mpic->irqhost, src); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1470 | } |
| 1471 | |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1472 | unsigned int mpic_get_one_irq(struct mpic *mpic) |
| 1473 | { |
| 1474 | return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK)); |
| 1475 | } |
| 1476 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 1477 | unsigned int mpic_get_irq(void) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1478 | { |
| 1479 | struct mpic *mpic = mpic_primary; |
| 1480 | |
| 1481 | BUG_ON(mpic == NULL); |
| 1482 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 1483 | return mpic_get_one_irq(mpic); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1484 | } |
| 1485 | |
Olof Johansson | f365355 | 2007-12-20 13:11:18 -0600 | [diff] [blame^] | 1486 | unsigned int mpic_get_mcirq(void) |
| 1487 | { |
| 1488 | struct mpic *mpic = mpic_primary; |
| 1489 | |
| 1490 | BUG_ON(mpic == NULL); |
| 1491 | |
| 1492 | return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK)); |
| 1493 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1494 | |
| 1495 | #ifdef CONFIG_SMP |
| 1496 | void mpic_request_ipis(void) |
| 1497 | { |
| 1498 | struct mpic *mpic = mpic_primary; |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 1499 | long i, err; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1500 | static char *ipi_names[] = { |
| 1501 | "IPI0 (call function)", |
| 1502 | "IPI1 (reschedule)", |
| 1503 | "IPI2 (unused)", |
| 1504 | "IPI3 (debugger break)", |
| 1505 | }; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1506 | BUG_ON(mpic == NULL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1507 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1508 | printk(KERN_INFO "mpic: requesting IPIs ... \n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1509 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1510 | for (i = 0; i < 4; i++) { |
| 1511 | unsigned int vipi = irq_create_mapping(mpic->irqhost, |
Olof Johansson | 7df2457d | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 1512 | mpic->ipi_vecs[0] + i); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1513 | if (vipi == NO_IRQ) { |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 1514 | printk(KERN_ERR "Failed to map IPI %ld\n", i); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1515 | break; |
| 1516 | } |
Olof Johansson | d16f1b6 | 2007-05-15 06:59:12 +1000 | [diff] [blame] | 1517 | err = request_irq(vipi, mpic_ipi_action, |
| 1518 | IRQF_DISABLED|IRQF_PERCPU, |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 1519 | ipi_names[i], (void *)i); |
Olof Johansson | d16f1b6 | 2007-05-15 06:59:12 +1000 | [diff] [blame] | 1520 | if (err) { |
Olof Johansson | 194046a | 2007-10-20 09:49:50 +1000 | [diff] [blame] | 1521 | printk(KERN_ERR "Request of irq %d for IPI %ld failed\n", |
Olof Johansson | d16f1b6 | 2007-05-15 06:59:12 +1000 | [diff] [blame] | 1522 | vipi, i); |
| 1523 | break; |
| 1524 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1525 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1526 | } |
Paul Mackerras | a9c5926 | 2005-10-20 17:09:51 +1000 | [diff] [blame] | 1527 | |
| 1528 | void smp_mpic_message_pass(int target, int msg) |
| 1529 | { |
| 1530 | /* make sure we're sending something that translates to an IPI */ |
| 1531 | if ((unsigned int)msg > 3) { |
| 1532 | printk("SMP %d: smp_message_pass: unknown msg %d\n", |
| 1533 | smp_processor_id(), msg); |
| 1534 | return; |
| 1535 | } |
| 1536 | switch (target) { |
| 1537 | case MSG_ALL: |
| 1538 | mpic_send_ipi(msg, 0xffffffff); |
| 1539 | break; |
| 1540 | case MSG_ALL_BUT_SELF: |
| 1541 | mpic_send_ipi(msg, 0xffffffff & ~(1 << smp_processor_id())); |
| 1542 | break; |
| 1543 | default: |
| 1544 | mpic_send_ipi(msg, 1 << target); |
| 1545 | break; |
| 1546 | } |
| 1547 | } |
Michael Ellerman | 775aeff | 2007-02-08 18:34:04 +1100 | [diff] [blame] | 1548 | |
| 1549 | int __init smp_mpic_probe(void) |
| 1550 | { |
| 1551 | int nr_cpus; |
| 1552 | |
| 1553 | DBG("smp_mpic_probe()...\n"); |
| 1554 | |
| 1555 | nr_cpus = cpus_weight(cpu_possible_map); |
| 1556 | |
| 1557 | DBG("nr_cpus: %d\n", nr_cpus); |
| 1558 | |
| 1559 | if (nr_cpus > 1) |
| 1560 | mpic_request_ipis(); |
| 1561 | |
| 1562 | return nr_cpus; |
| 1563 | } |
| 1564 | |
| 1565 | void __devinit smp_mpic_setup_cpu(int cpu) |
| 1566 | { |
| 1567 | mpic_setup_this_cpu(); |
| 1568 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1569 | #endif /* CONFIG_SMP */ |
Johannes Berg | 3669e93 | 2007-05-02 16:33:41 +1000 | [diff] [blame] | 1570 | |
| 1571 | #ifdef CONFIG_PM |
| 1572 | static int mpic_suspend(struct sys_device *dev, pm_message_t state) |
| 1573 | { |
| 1574 | struct mpic *mpic = container_of(dev, struct mpic, sysdev); |
| 1575 | int i; |
| 1576 | |
| 1577 | for (i = 0; i < mpic->num_sources; i++) { |
| 1578 | mpic->save_data[i].vecprio = |
| 1579 | mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI)); |
| 1580 | mpic->save_data[i].dest = |
| 1581 | mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)); |
| 1582 | } |
| 1583 | |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
| 1587 | static int mpic_resume(struct sys_device *dev) |
| 1588 | { |
| 1589 | struct mpic *mpic = container_of(dev, struct mpic, sysdev); |
| 1590 | int i; |
| 1591 | |
| 1592 | for (i = 0; i < mpic->num_sources; i++) { |
| 1593 | mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), |
| 1594 | mpic->save_data[i].vecprio); |
| 1595 | mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), |
| 1596 | mpic->save_data[i].dest); |
| 1597 | |
| 1598 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
| 1599 | { |
| 1600 | struct mpic_irq_fixup *fixup = &mpic->fixups[i]; |
| 1601 | |
| 1602 | if (fixup->base) { |
| 1603 | /* we use the lowest bit in an inverted meaning */ |
| 1604 | if ((mpic->save_data[i].fixup_data & 1) == 0) |
| 1605 | continue; |
| 1606 | |
| 1607 | /* Enable and configure */ |
| 1608 | writeb(0x10 + 2 * fixup->index, fixup->base + 2); |
| 1609 | |
| 1610 | writel(mpic->save_data[i].fixup_data & ~1, |
| 1611 | fixup->base + 4); |
| 1612 | } |
| 1613 | } |
| 1614 | #endif |
| 1615 | } /* end for loop */ |
| 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | #endif |
| 1620 | |
| 1621 | static struct sysdev_class mpic_sysclass = { |
| 1622 | #ifdef CONFIG_PM |
| 1623 | .resume = mpic_resume, |
| 1624 | .suspend = mpic_suspend, |
| 1625 | #endif |
| 1626 | set_kset_name("mpic"), |
| 1627 | }; |
| 1628 | |
| 1629 | static int mpic_init_sys(void) |
| 1630 | { |
| 1631 | struct mpic *mpic = mpics; |
| 1632 | int error, id = 0; |
| 1633 | |
| 1634 | error = sysdev_class_register(&mpic_sysclass); |
| 1635 | |
| 1636 | while (mpic && !error) { |
| 1637 | mpic->sysdev.cls = &mpic_sysclass; |
| 1638 | mpic->sysdev.id = id++; |
| 1639 | error = sysdev_register(&mpic->sysdev); |
| 1640 | mpic = mpic->next; |
| 1641 | } |
| 1642 | return error; |
| 1643 | } |
| 1644 | |
| 1645 | device_initcall(mpic_init_sys); |