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