Steven J. Hill | 2299c49 | 2012-08-31 16:13:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2008 Ralf Baechle (ralf@linux-mips.org) |
| 7 | * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. |
| 8 | */ |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 9 | #include <linux/bitmap.h> |
| 10 | #include <linux/init.h> |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/sched.h> |
Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 13 | #include <linux/smp.h> |
David Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 14 | #include <linux/irq.h> |
Steven J. Hill | dfa762e | 2013-04-10 16:28:36 -0500 | [diff] [blame] | 15 | #include <linux/clocksource.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 16 | |
| 17 | #include <asm/io.h> |
| 18 | #include <asm/gic.h> |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 19 | #include <asm/setup.h> |
| 20 | #include <asm/traps.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 21 | #include <linux/hardirq.h> |
| 22 | #include <asm-generic/bitops/find.h> |
| 23 | |
Steven J. Hill | 28ea215 | 2013-04-10 16:27:50 -0500 | [diff] [blame] | 24 | unsigned int gic_frequency; |
Steven J. Hill | ff86714 | 2013-04-10 16:27:04 -0500 | [diff] [blame] | 25 | unsigned int gic_present; |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 26 | unsigned long _gic_base; |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 27 | unsigned int gic_irq_flags[GIC_NUM_INTRS]; |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 28 | unsigned int gic_cpu_pin; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 29 | |
Jeffrey Deans | 822350b | 2014-07-17 09:20:53 +0100 | [diff] [blame] | 30 | struct gic_pcpu_mask { |
| 31 | DECLARE_BITMAP(pcpu_mask, GIC_NUM_INTRS); |
| 32 | }; |
| 33 | |
| 34 | struct gic_pending_regs { |
| 35 | DECLARE_BITMAP(pending, GIC_NUM_INTRS); |
| 36 | }; |
| 37 | |
| 38 | struct gic_intrmask_regs { |
| 39 | DECLARE_BITMAP(intrmask, GIC_NUM_INTRS); |
| 40 | }; |
| 41 | |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 42 | static struct gic_pcpu_mask pcpu_masks[NR_CPUS]; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 43 | static struct gic_pending_regs pending_regs[NR_CPUS]; |
| 44 | static struct gic_intrmask_regs intrmask_regs[NR_CPUS]; |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 45 | static DEFINE_SPINLOCK(gic_lock); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 46 | static struct irq_domain *gic_irq_domain; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 47 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 48 | static void __gic_irq_dispatch(void); |
| 49 | |
Raghu Gandham | 0ab2b7d | 2013-04-10 16:30:12 -0500 | [diff] [blame] | 50 | #if defined(CONFIG_CSRC_GIC) || defined(CONFIG_CEVT_GIC) |
Steven J. Hill | dfa762e | 2013-04-10 16:28:36 -0500 | [diff] [blame] | 51 | cycle_t gic_read_count(void) |
| 52 | { |
| 53 | unsigned int hi, hi2, lo; |
| 54 | |
| 55 | do { |
| 56 | GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi); |
| 57 | GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_31_00), lo); |
| 58 | GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi2); |
| 59 | } while (hi2 != hi); |
| 60 | |
| 61 | return (((cycle_t) hi) << 32) + lo; |
| 62 | } |
Raghu Gandham | 0ab2b7d | 2013-04-10 16:30:12 -0500 | [diff] [blame] | 63 | |
| 64 | void gic_write_compare(cycle_t cnt) |
| 65 | { |
| 66 | GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI), |
| 67 | (int)(cnt >> 32)); |
| 68 | GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO), |
| 69 | (int)(cnt & 0xffffffff)); |
| 70 | } |
| 71 | |
Paul Burton | 414408d0 | 2014-03-05 11:35:53 +0000 | [diff] [blame] | 72 | void gic_write_cpu_compare(cycle_t cnt, int cpu) |
| 73 | { |
| 74 | unsigned long flags; |
| 75 | |
| 76 | local_irq_save(flags); |
| 77 | |
| 78 | GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), cpu); |
| 79 | GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_HI), |
| 80 | (int)(cnt >> 32)); |
| 81 | GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_LO), |
| 82 | (int)(cnt & 0xffffffff)); |
| 83 | |
| 84 | local_irq_restore(flags); |
| 85 | } |
| 86 | |
Raghu Gandham | 0ab2b7d | 2013-04-10 16:30:12 -0500 | [diff] [blame] | 87 | cycle_t gic_read_compare(void) |
| 88 | { |
| 89 | unsigned int hi, lo; |
| 90 | |
| 91 | GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI), hi); |
| 92 | GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO), lo); |
| 93 | |
| 94 | return (((cycle_t) hi) << 32) + lo; |
| 95 | } |
Steven J. Hill | dfa762e | 2013-04-10 16:28:36 -0500 | [diff] [blame] | 96 | #endif |
| 97 | |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 98 | unsigned int gic_get_timer_pending(void) |
| 99 | { |
| 100 | unsigned int vpe_pending; |
| 101 | |
| 102 | GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0); |
| 103 | GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_PEND), vpe_pending); |
Ralf Baechle | 635c9907 | 2014-10-21 14:12:49 +0200 | [diff] [blame] | 104 | return vpe_pending & GIC_VPE_PEND_TIMER_MSK; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void gic_bind_eic_interrupt(int irq, int set) |
| 108 | { |
| 109 | /* Convert irq vector # to hw int # */ |
| 110 | irq -= GIC_PIN_TO_VEC_OFFSET; |
| 111 | |
| 112 | /* Set irq to use shadow set */ |
| 113 | GICWRITE(GIC_REG_ADDR(VPE_LOCAL, GIC_VPE_EIC_SS(irq)), set); |
| 114 | } |
| 115 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 116 | void gic_send_ipi(unsigned int intr) |
| 117 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 118 | GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), 0x80000000 | intr); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 121 | static void __init vpe_local_setup(unsigned int numvpes) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 122 | { |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 123 | unsigned long timer_intr = GIC_INT_TMR; |
| 124 | unsigned long perf_intr = GIC_INT_PERFCTR; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 125 | unsigned int vpe_ctl; |
Steven J. Hill | 2299c49 | 2012-08-31 16:13:07 -0500 | [diff] [blame] | 126 | int i; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 127 | |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 128 | if (cpu_has_veic) { |
| 129 | /* |
| 130 | * GIC timer interrupt -> CPU HW Int X (vector X+2) -> |
| 131 | * map to pin X+2-1 (since GIC adds 1) |
| 132 | */ |
| 133 | timer_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET); |
| 134 | /* |
| 135 | * GIC perfcnt interrupt -> CPU HW Int X (vector X+2) -> |
| 136 | * map to pin X+2-1 (since GIC adds 1) |
| 137 | */ |
| 138 | perf_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET); |
| 139 | } |
| 140 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 141 | /* |
| 142 | * Setup the default performance counter timer interrupts |
| 143 | * for all VPEs |
| 144 | */ |
| 145 | for (i = 0; i < numvpes; i++) { |
| 146 | GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), i); |
| 147 | |
| 148 | /* Are Interrupts locally routable? */ |
| 149 | GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_CTL), vpe_ctl); |
| 150 | if (vpe_ctl & GIC_VPE_CTL_TIMER_RTBL_MSK) |
| 151 | GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_TIMER_MAP), |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 152 | GIC_MAP_TO_PIN_MSK | timer_intr); |
| 153 | if (cpu_has_veic) { |
| 154 | set_vi_handler(timer_intr + GIC_PIN_TO_VEC_OFFSET, |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 155 | __gic_irq_dispatch); |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 156 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 157 | |
| 158 | if (vpe_ctl & GIC_VPE_CTL_PERFCNT_RTBL_MSK) |
| 159 | GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_PERFCTR_MAP), |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 160 | GIC_MAP_TO_PIN_MSK | perf_intr); |
| 161 | if (cpu_has_veic) { |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 162 | set_vi_handler(perf_intr + GIC_PIN_TO_VEC_OFFSET, |
| 163 | __gic_irq_dispatch); |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 164 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Raghu Gandham | 0ab2b7d | 2013-04-10 16:30:12 -0500 | [diff] [blame] | 168 | unsigned int gic_compare_int(void) |
| 169 | { |
| 170 | unsigned int pending; |
| 171 | |
| 172 | GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_PEND), pending); |
| 173 | if (pending & GIC_VPE_PEND_CMP_MSK) |
| 174 | return 1; |
| 175 | else |
| 176 | return 0; |
| 177 | } |
| 178 | |
Jeffrey Deans | 31521a7 | 2014-07-17 09:20:57 +0100 | [diff] [blame] | 179 | void gic_get_int_mask(unsigned long *dst, const unsigned long *src) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 180 | { |
| 181 | unsigned int i; |
| 182 | unsigned long *pending, *intrmask, *pcpu_mask; |
| 183 | unsigned long *pending_abs, *intrmask_abs; |
| 184 | |
| 185 | /* Get per-cpu bitmaps */ |
| 186 | pending = pending_regs[smp_processor_id()].pending; |
| 187 | intrmask = intrmask_regs[smp_processor_id()].intrmask; |
| 188 | pcpu_mask = pcpu_masks[smp_processor_id()].pcpu_mask; |
| 189 | |
| 190 | pending_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED, |
| 191 | GIC_SH_PEND_31_0_OFS); |
| 192 | intrmask_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED, |
| 193 | GIC_SH_MASK_31_0_OFS); |
| 194 | |
| 195 | for (i = 0; i < BITS_TO_LONGS(GIC_NUM_INTRS); i++) { |
| 196 | GICREAD(*pending_abs, pending[i]); |
| 197 | GICREAD(*intrmask_abs, intrmask[i]); |
| 198 | pending_abs++; |
| 199 | intrmask_abs++; |
| 200 | } |
| 201 | |
| 202 | bitmap_and(pending, pending, intrmask, GIC_NUM_INTRS); |
| 203 | bitmap_and(pending, pending, pcpu_mask, GIC_NUM_INTRS); |
Jeffrey Deans | 31521a7 | 2014-07-17 09:20:57 +0100 | [diff] [blame] | 204 | bitmap_and(dst, src, pending, GIC_NUM_INTRS); |
| 205 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 206 | |
Jeffrey Deans | 31521a7 | 2014-07-17 09:20:57 +0100 | [diff] [blame] | 207 | unsigned int gic_get_int(void) |
| 208 | { |
| 209 | DECLARE_BITMAP(interrupts, GIC_NUM_INTRS); |
| 210 | |
| 211 | bitmap_fill(interrupts, GIC_NUM_INTRS); |
| 212 | gic_get_int_mask(interrupts, interrupts); |
| 213 | |
| 214 | return find_first_bit(interrupts, GIC_NUM_INTRS); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 217 | static void gic_mask_irq(struct irq_data *d) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 218 | { |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 219 | GIC_CLR_INTR_MASK(d->hwirq); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 222 | static void gic_unmask_irq(struct irq_data *d) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 223 | { |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 224 | GIC_SET_INTR_MASK(d->hwirq); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 227 | static void gic_ack_irq(struct irq_data *d) |
| 228 | { |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 229 | unsigned int irq = d->hwirq; |
| 230 | |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 231 | /* Clear edge detector */ |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 232 | if (gic_irq_flags[irq] & GIC_TRIG_EDGE) |
| 233 | GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq); |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 236 | static int gic_set_type(struct irq_data *d, unsigned int type) |
| 237 | { |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 238 | unsigned int irq = d->hwirq; |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 239 | unsigned long flags; |
| 240 | bool is_edge; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 241 | |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 242 | spin_lock_irqsave(&gic_lock, flags); |
| 243 | switch (type & IRQ_TYPE_SENSE_MASK) { |
| 244 | case IRQ_TYPE_EDGE_FALLING: |
| 245 | GIC_SET_POLARITY(irq, GIC_POL_NEG); |
| 246 | GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE); |
| 247 | GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE); |
| 248 | is_edge = true; |
| 249 | break; |
| 250 | case IRQ_TYPE_EDGE_RISING: |
| 251 | GIC_SET_POLARITY(irq, GIC_POL_POS); |
| 252 | GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE); |
| 253 | GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE); |
| 254 | is_edge = true; |
| 255 | break; |
| 256 | case IRQ_TYPE_EDGE_BOTH: |
| 257 | /* polarity is irrelevant in this case */ |
| 258 | GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE); |
| 259 | GIC_SET_DUAL(irq, GIC_TRIG_DUAL_ENABLE); |
| 260 | is_edge = true; |
| 261 | break; |
| 262 | case IRQ_TYPE_LEVEL_LOW: |
| 263 | GIC_SET_POLARITY(irq, GIC_POL_NEG); |
| 264 | GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL); |
| 265 | GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE); |
| 266 | is_edge = false; |
| 267 | break; |
| 268 | case IRQ_TYPE_LEVEL_HIGH: |
| 269 | default: |
| 270 | GIC_SET_POLARITY(irq, GIC_POL_POS); |
| 271 | GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL); |
| 272 | GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE); |
| 273 | is_edge = false; |
| 274 | break; |
| 275 | } |
| 276 | |
| 277 | if (is_edge) { |
| 278 | gic_irq_flags[irq] |= GIC_TRIG_EDGE; |
| 279 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
| 280 | } else { |
| 281 | gic_irq_flags[irq] &= ~GIC_TRIG_EDGE; |
| 282 | __irq_set_handler_locked(d->irq, handle_level_irq); |
| 283 | } |
| 284 | spin_unlock_irqrestore(&gic_lock, flags); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | #ifdef CONFIG_SMP |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 290 | static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask, |
| 291 | bool force) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 292 | { |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 293 | unsigned int irq = d->hwirq; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 294 | cpumask_t tmp = CPU_MASK_NONE; |
| 295 | unsigned long flags; |
| 296 | int i; |
| 297 | |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 298 | cpumask_and(&tmp, cpumask, cpu_online_mask); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 299 | if (cpus_empty(tmp)) |
Andrew Bresticker | 14d160a | 2014-09-18 14:47:22 -0700 | [diff] [blame] | 300 | return -EINVAL; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 301 | |
| 302 | /* Assumption : cpumask refers to a single CPU */ |
| 303 | spin_lock_irqsave(&gic_lock, flags); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 304 | |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 305 | /* Re-route this IRQ */ |
| 306 | GIC_SH_MAP_TO_VPE_SMASK(irq, first_cpu(tmp)); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 307 | |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 308 | /* Update the pcpu_masks */ |
| 309 | for (i = 0; i < NR_CPUS; i++) |
| 310 | clear_bit(irq, pcpu_masks[i].pcpu_mask); |
| 311 | set_bit(irq, pcpu_masks[first_cpu(tmp)].pcpu_mask); |
| 312 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 313 | cpumask_copy(d->affinity, cpumask); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 314 | spin_unlock_irqrestore(&gic_lock, flags); |
| 315 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 316 | return IRQ_SET_MASK_OK_NOCOPY; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 317 | } |
| 318 | #endif |
| 319 | |
| 320 | static struct irq_chip gic_irq_controller = { |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 321 | .name = "MIPS GIC", |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 322 | .irq_ack = gic_ack_irq, |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 323 | .irq_mask = gic_mask_irq, |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 324 | .irq_unmask = gic_unmask_irq, |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 325 | .irq_set_type = gic_set_type, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 326 | #ifdef CONFIG_SMP |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 327 | .irq_set_affinity = gic_set_affinity, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 328 | #endif |
| 329 | }; |
| 330 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 331 | static void __gic_irq_dispatch(void) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 332 | { |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 333 | unsigned int intr, virq; |
| 334 | |
| 335 | while ((intr = gic_get_int()) != GIC_NUM_INTRS) { |
| 336 | virq = irq_linear_revmap(gic_irq_domain, intr); |
| 337 | do_IRQ(virq); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static void gic_irq_dispatch(unsigned int irq, struct irq_desc *desc) |
| 342 | { |
| 343 | __gic_irq_dispatch(); |
| 344 | } |
| 345 | |
| 346 | #ifdef CONFIG_MIPS_GIC_IPI |
| 347 | static int gic_resched_int_base; |
| 348 | static int gic_call_int_base; |
| 349 | |
| 350 | unsigned int plat_ipi_resched_int_xlate(unsigned int cpu) |
| 351 | { |
| 352 | return gic_resched_int_base + cpu; |
| 353 | } |
| 354 | |
| 355 | unsigned int plat_ipi_call_int_xlate(unsigned int cpu) |
| 356 | { |
| 357 | return gic_call_int_base + cpu; |
| 358 | } |
| 359 | |
| 360 | static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id) |
| 361 | { |
| 362 | scheduler_ipi(); |
| 363 | |
| 364 | return IRQ_HANDLED; |
| 365 | } |
| 366 | |
| 367 | static irqreturn_t ipi_call_interrupt(int irq, void *dev_id) |
| 368 | { |
| 369 | smp_call_function_interrupt(); |
| 370 | |
| 371 | return IRQ_HANDLED; |
| 372 | } |
| 373 | |
| 374 | static struct irqaction irq_resched = { |
| 375 | .handler = ipi_resched_interrupt, |
| 376 | .flags = IRQF_PERCPU, |
| 377 | .name = "IPI resched" |
| 378 | }; |
| 379 | |
| 380 | static struct irqaction irq_call = { |
| 381 | .handler = ipi_call_interrupt, |
| 382 | .flags = IRQF_PERCPU, |
| 383 | .name = "IPI call" |
| 384 | }; |
| 385 | |
| 386 | static __init void gic_ipi_init_one(unsigned int intr, int cpu, |
| 387 | struct irqaction *action) |
| 388 | { |
| 389 | int virq = irq_create_mapping(gic_irq_domain, intr); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 390 | int i; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 391 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 392 | GIC_SH_MAP_TO_VPE_SMASK(intr, cpu); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 393 | for (i = 0; i < NR_CPUS; i++) |
| 394 | clear_bit(intr, pcpu_masks[i].pcpu_mask); |
Jeffrey Deans | b0a88ae | 2014-07-17 09:20:55 +0100 | [diff] [blame] | 395 | set_bit(intr, pcpu_masks[cpu].pcpu_mask); |
| 396 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 397 | irq_set_irq_type(virq, IRQ_TYPE_EDGE_RISING); |
| 398 | |
| 399 | irq_set_handler(virq, handle_percpu_irq); |
| 400 | setup_irq(virq, action); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 403 | static __init void gic_ipi_init(void) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 404 | { |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 405 | int i; |
| 406 | |
| 407 | /* Use last 2 * NR_CPUS interrupts as IPIs */ |
| 408 | gic_resched_int_base = GIC_NUM_INTRS - nr_cpu_ids; |
| 409 | gic_call_int_base = gic_resched_int_base - nr_cpu_ids; |
| 410 | |
| 411 | for (i = 0; i < nr_cpu_ids; i++) { |
| 412 | gic_ipi_init_one(gic_call_int_base + i, i, &irq_call); |
| 413 | gic_ipi_init_one(gic_resched_int_base + i, i, &irq_resched); |
| 414 | } |
| 415 | } |
| 416 | #else |
| 417 | static inline void gic_ipi_init(void) |
| 418 | { |
| 419 | } |
| 420 | #endif |
| 421 | |
| 422 | static void __init gic_basic_init(int numintrs, int numvpes) |
| 423 | { |
| 424 | unsigned int i; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 425 | |
| 426 | board_bind_eic_interrupt = &gic_bind_eic_interrupt; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 427 | |
| 428 | /* Setup defaults */ |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 429 | for (i = 0; i < numintrs; i++) { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 430 | GIC_SET_POLARITY(i, GIC_POL_POS); |
| 431 | GIC_SET_TRIGGER(i, GIC_TRIG_LEVEL); |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 432 | GIC_CLR_INTR_MASK(i); |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 433 | if (i < GIC_NUM_INTRS) |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 434 | gic_irq_flags[i] = 0; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | vpe_local_setup(numvpes); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 440 | static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 441 | irq_hw_number_t hw) |
| 442 | { |
| 443 | unsigned long flags; |
| 444 | |
| 445 | irq_set_chip_and_handler(virq, &gic_irq_controller, handle_level_irq); |
| 446 | |
| 447 | spin_lock_irqsave(&gic_lock, flags); |
| 448 | GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_MAP_TO_PIN(hw)), |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 449 | GIC_MAP_TO_PIN_MSK | gic_cpu_pin); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 450 | /* Map to VPE 0 by default */ |
| 451 | GIC_SH_MAP_TO_VPE_SMASK(hw, 0); |
| 452 | set_bit(hw, pcpu_masks[0].pcpu_mask); |
| 453 | spin_unlock_irqrestore(&gic_lock, flags); |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static struct irq_domain_ops gic_irq_domain_ops = { |
| 459 | .map = gic_irq_domain_map, |
| 460 | .xlate = irq_domain_xlate_twocell, |
| 461 | }; |
| 462 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 463 | void __init gic_init(unsigned long gic_base_addr, |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 464 | unsigned long gic_addrspace_size, unsigned int cpu_vec, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 465 | unsigned int irqbase) |
| 466 | { |
| 467 | unsigned int gicconfig; |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 468 | int numvpes, numintrs; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 469 | |
| 470 | _gic_base = (unsigned long) ioremap_nocache(gic_base_addr, |
| 471 | gic_addrspace_size); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 472 | |
| 473 | GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), gicconfig); |
| 474 | numintrs = (gicconfig & GIC_SH_CONFIG_NUMINTRS_MSK) >> |
| 475 | GIC_SH_CONFIG_NUMINTRS_SHF; |
| 476 | numintrs = ((numintrs + 1) * 8); |
| 477 | |
| 478 | numvpes = (gicconfig & GIC_SH_CONFIG_NUMVPES_MSK) >> |
| 479 | GIC_SH_CONFIG_NUMVPES_SHF; |
Steven J. Hill | 3234f44 | 2012-08-31 16:23:49 -0500 | [diff] [blame] | 480 | numvpes = numvpes + 1; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 481 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 482 | if (cpu_has_veic) { |
| 483 | /* Always use vector 1 in EIC mode */ |
| 484 | gic_cpu_pin = 0; |
| 485 | set_vi_handler(gic_cpu_pin + GIC_PIN_TO_VEC_OFFSET, |
| 486 | __gic_irq_dispatch); |
| 487 | } else { |
| 488 | gic_cpu_pin = cpu_vec - GIC_CPU_PIN_OFFSET; |
| 489 | irq_set_chained_handler(MIPS_CPU_IRQ_BASE + cpu_vec, |
| 490 | gic_irq_dispatch); |
| 491 | } |
| 492 | |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 493 | gic_irq_domain = irq_domain_add_simple(NULL, GIC_NUM_INTRS, irqbase, |
| 494 | &gic_irq_domain_ops, NULL); |
| 495 | if (!gic_irq_domain) |
| 496 | panic("Failed to add GIC IRQ domain"); |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 497 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame^] | 498 | gic_basic_init(numintrs, numvpes); |
| 499 | |
| 500 | gic_ipi_init(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 501 | } |