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> |
Andrew Bresticker | fb8f7be1 | 2014-10-20 12:03:55 -0700 | [diff] [blame] | 10 | #include <linux/clocksource.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 11 | #include <linux/init.h> |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Andrew Bresticker | fb8f7be1 | 2014-10-20 12:03:55 -0700 | [diff] [blame] | 13 | #include <linux/irq.h> |
Joel Porquet | 41a83e0 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 14 | #include <linux/irqchip.h> |
Andrew Bresticker | 4060bbe | 2014-10-20 12:03:53 -0700 | [diff] [blame] | 15 | #include <linux/irqchip/mips-gic.h> |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 16 | #include <linux/of_address.h> |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 17 | #include <linux/sched.h> |
Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 18 | #include <linux/smp.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 19 | |
Paul Burton | e83f7e0 | 2017-08-12 19:49:41 -0700 | [diff] [blame] | 20 | #include <asm/mips-cps.h> |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 21 | #include <asm/setup.h> |
| 22 | #include <asm/traps.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 23 | |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 24 | #include <dt-bindings/interrupt-controller/mips-gic.h> |
| 25 | |
Steven J. Hill | ff86714 | 2013-04-10 16:27:04 -0500 | [diff] [blame] | 26 | unsigned int gic_present; |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 27 | void __iomem *mips_gic_base; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 28 | |
Jeffrey Deans | 822350b | 2014-07-17 09:20:53 +0100 | [diff] [blame] | 29 | struct gic_pcpu_mask { |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 30 | DECLARE_BITMAP(pcpu_mask, GIC_MAX_INTRS); |
Jeffrey Deans | 822350b | 2014-07-17 09:20:53 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
Alex Smith | c0a9f72 | 2015-10-12 10:40:43 +0100 | [diff] [blame] | 33 | static unsigned long __gic_base_addr; |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 34 | static struct gic_pcpu_mask pcpu_masks[NR_CPUS]; |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 35 | static DEFINE_SPINLOCK(gic_lock); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 36 | static struct irq_domain *gic_irq_domain; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 37 | static struct irq_domain *gic_ipi_domain; |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 38 | static int gic_shared_intrs; |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 39 | static int gic_vpes; |
Andrew Bresticker | 3263d08 | 2014-09-18 14:47:28 -0700 | [diff] [blame] | 40 | static unsigned int gic_cpu_pin; |
James Hogan | 1b6af71 | 2015-01-19 15:38:24 +0000 | [diff] [blame] | 41 | static unsigned int timer_cpu_pin; |
Andrew Bresticker | 4a6a3ea3 | 2014-09-18 14:47:26 -0700 | [diff] [blame] | 42 | static struct irq_chip gic_level_irq_controller, gic_edge_irq_controller; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 43 | DECLARE_BITMAP(ipi_resrv, GIC_MAX_INTRS); |
Paul Burton | f8dcd9e | 2017-04-20 10:07:34 +0100 | [diff] [blame] | 44 | DECLARE_BITMAP(ipi_available, GIC_MAX_INTRS); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 45 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 46 | static void __gic_irq_dispatch(void); |
| 47 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 48 | static inline u32 gic_read32(unsigned int reg) |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 49 | { |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 50 | return __raw_readl(mips_gic_base + reg); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 53 | static inline u64 gic_read64(unsigned int reg) |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 54 | { |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 55 | return __raw_readq(mips_gic_base + reg); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 58 | static inline unsigned long gic_read(unsigned int reg) |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 59 | { |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 60 | if (!mips_cm_is64) |
| 61 | return gic_read32(reg); |
| 62 | else |
| 63 | return gic_read64(reg); |
| 64 | } |
| 65 | |
| 66 | static inline void gic_write32(unsigned int reg, u32 val) |
| 67 | { |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 68 | return __raw_writel(val, mips_gic_base + reg); |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void gic_write64(unsigned int reg, u64 val) |
| 72 | { |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 73 | return __raw_writeq(val, mips_gic_base + reg); |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline void gic_write(unsigned int reg, unsigned long val) |
| 77 | { |
| 78 | if (!mips_cm_is64) |
| 79 | return gic_write32(reg, (u32)val); |
| 80 | else |
| 81 | return gic_write64(reg, (u64)val); |
| 82 | } |
| 83 | |
| 84 | static inline void gic_update_bits(unsigned int reg, unsigned long mask, |
| 85 | unsigned long val) |
| 86 | { |
| 87 | unsigned long regval; |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 88 | |
| 89 | regval = gic_read(reg); |
| 90 | regval &= ~mask; |
| 91 | regval |= val; |
| 92 | gic_write(reg, regval); |
| 93 | } |
| 94 | |
| 95 | static inline void gic_reset_mask(unsigned int intr) |
| 96 | { |
| 97 | gic_write(GIC_REG(SHARED, GIC_SH_RMASK) + GIC_INTR_OFS(intr), |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 98 | 1ul << GIC_INTR_BIT(intr)); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static inline void gic_set_mask(unsigned int intr) |
| 102 | { |
| 103 | gic_write(GIC_REG(SHARED, GIC_SH_SMASK) + GIC_INTR_OFS(intr), |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 104 | 1ul << GIC_INTR_BIT(intr)); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static inline void gic_set_polarity(unsigned int intr, unsigned int pol) |
| 108 | { |
| 109 | gic_update_bits(GIC_REG(SHARED, GIC_SH_SET_POLARITY) + |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 110 | GIC_INTR_OFS(intr), 1ul << GIC_INTR_BIT(intr), |
| 111 | (unsigned long)pol << GIC_INTR_BIT(intr)); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static inline void gic_set_trigger(unsigned int intr, unsigned int trig) |
| 115 | { |
| 116 | gic_update_bits(GIC_REG(SHARED, GIC_SH_SET_TRIGGER) + |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 117 | GIC_INTR_OFS(intr), 1ul << GIC_INTR_BIT(intr), |
| 118 | (unsigned long)trig << GIC_INTR_BIT(intr)); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static inline void gic_set_dual_edge(unsigned int intr, unsigned int dual) |
| 122 | { |
| 123 | gic_update_bits(GIC_REG(SHARED, GIC_SH_SET_DUAL) + GIC_INTR_OFS(intr), |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 124 | 1ul << GIC_INTR_BIT(intr), |
| 125 | (unsigned long)dual << GIC_INTR_BIT(intr)); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static inline void gic_map_to_pin(unsigned int intr, unsigned int pin) |
| 129 | { |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 130 | gic_write32(GIC_REG(SHARED, GIC_SH_INTR_MAP_TO_PIN_BASE) + |
| 131 | GIC_SH_MAP_TO_PIN(intr), GIC_MAP_TO_PIN_MSK | pin); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static inline void gic_map_to_vpe(unsigned int intr, unsigned int vpe) |
| 135 | { |
| 136 | gic_write(GIC_REG(SHARED, GIC_SH_INTR_MAP_TO_VPE_BASE) + |
| 137 | GIC_SH_MAP_TO_VPE_REG_OFF(intr, vpe), |
| 138 | GIC_SH_MAP_TO_VPE_REG_BIT(vpe)); |
| 139 | } |
| 140 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 141 | static bool gic_local_irq_is_routable(int intr) |
| 142 | { |
| 143 | u32 vpe_ctl; |
| 144 | |
| 145 | /* All local interrupts are routable in EIC mode. */ |
| 146 | if (cpu_has_veic) |
| 147 | return true; |
| 148 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 149 | vpe_ctl = gic_read32(GIC_REG(VPE_LOCAL, GIC_VPE_CTL)); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 150 | switch (intr) { |
| 151 | case GIC_LOCAL_INT_TIMER: |
| 152 | return vpe_ctl & GIC_VPE_CTL_TIMER_RTBL_MSK; |
| 153 | case GIC_LOCAL_INT_PERFCTR: |
| 154 | return vpe_ctl & GIC_VPE_CTL_PERFCNT_RTBL_MSK; |
| 155 | case GIC_LOCAL_INT_FDC: |
| 156 | return vpe_ctl & GIC_VPE_CTL_FDC_RTBL_MSK; |
| 157 | case GIC_LOCAL_INT_SWINT0: |
| 158 | case GIC_LOCAL_INT_SWINT1: |
| 159 | return vpe_ctl & GIC_VPE_CTL_SWINT_RTBL_MSK; |
| 160 | default: |
| 161 | return true; |
| 162 | } |
| 163 | } |
| 164 | |
Andrew Bresticker | 3263d08 | 2014-09-18 14:47:28 -0700 | [diff] [blame] | 165 | static void gic_bind_eic_interrupt(int irq, int set) |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 166 | { |
| 167 | /* Convert irq vector # to hw int # */ |
| 168 | irq -= GIC_PIN_TO_VEC_OFFSET; |
| 169 | |
| 170 | /* Set irq to use shadow set */ |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 171 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_EIC_SHADOW_SET_BASE) + |
| 172 | GIC_VPE_EIC_SS(irq), set); |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Qais Yousef | bb11cff | 2015-12-08 13:20:28 +0000 | [diff] [blame] | 175 | static void gic_send_ipi(struct irq_data *d, unsigned int cpu) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 176 | { |
Qais Yousef | bb11cff | 2015-12-08 13:20:28 +0000 | [diff] [blame] | 177 | irq_hw_number_t hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(d)); |
| 178 | |
| 179 | gic_write(GIC_REG(SHARED, GIC_SH_WEDGE), GIC_SH_WEDGE_SET(hwirq)); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 182 | int gic_get_c0_compare_int(void) |
| 183 | { |
| 184 | if (!gic_local_irq_is_routable(GIC_LOCAL_INT_TIMER)) |
| 185 | return MIPS_CPU_IRQ_BASE + cp0_compare_irq; |
| 186 | return irq_create_mapping(gic_irq_domain, |
| 187 | GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_TIMER)); |
| 188 | } |
| 189 | |
| 190 | int gic_get_c0_perfcount_int(void) |
| 191 | { |
| 192 | if (!gic_local_irq_is_routable(GIC_LOCAL_INT_PERFCTR)) { |
James Hogan | 7e3e6cb | 2015-01-27 21:45:50 +0000 | [diff] [blame] | 193 | /* Is the performance counter shared with the timer? */ |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 194 | if (cp0_perfcount_irq < 0) |
| 195 | return -1; |
| 196 | return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq; |
| 197 | } |
| 198 | return irq_create_mapping(gic_irq_domain, |
| 199 | GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_PERFCTR)); |
| 200 | } |
| 201 | |
James Hogan | 6429e2b | 2015-01-29 11:14:09 +0000 | [diff] [blame] | 202 | int gic_get_c0_fdc_int(void) |
| 203 | { |
| 204 | if (!gic_local_irq_is_routable(GIC_LOCAL_INT_FDC)) { |
| 205 | /* Is the FDC IRQ even present? */ |
| 206 | if (cp0_fdc_irq < 0) |
| 207 | return -1; |
| 208 | return MIPS_CPU_IRQ_BASE + cp0_fdc_irq; |
| 209 | } |
| 210 | |
James Hogan | 6429e2b | 2015-01-29 11:14:09 +0000 | [diff] [blame] | 211 | return irq_create_mapping(gic_irq_domain, |
| 212 | GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_FDC)); |
| 213 | } |
| 214 | |
Alex Smith | c0a9f72 | 2015-10-12 10:40:43 +0100 | [diff] [blame] | 215 | int gic_get_usm_range(struct resource *gic_usm_res) |
| 216 | { |
| 217 | if (!gic_present) |
| 218 | return -1; |
| 219 | |
| 220 | gic_usm_res->start = __gic_base_addr + USM_VISIBLE_SECTION_OFS; |
| 221 | gic_usm_res->end = gic_usm_res->start + (USM_VISIBLE_SECTION_SIZE - 1); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 226 | static void gic_handle_shared_int(bool chained) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 227 | { |
Paul Burton | e98fcb2 | 2017-08-12 21:36:16 -0700 | [diff] [blame^] | 228 | unsigned int intr, virq; |
Andrew Bresticker | 8f5ee79 | 2014-10-20 12:03:56 -0700 | [diff] [blame] | 229 | unsigned long *pcpu_mask; |
Andrew Bresticker | 8f5ee79 | 2014-10-20 12:03:56 -0700 | [diff] [blame] | 230 | DECLARE_BITMAP(pending, GIC_MAX_INTRS); |
| 231 | DECLARE_BITMAP(intrmask, GIC_MAX_INTRS); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 232 | |
| 233 | /* Get per-cpu bitmaps */ |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 234 | pcpu_mask = pcpu_masks[smp_processor_id()].pcpu_mask; |
| 235 | |
Paul Burton | e98fcb2 | 2017-08-12 21:36:16 -0700 | [diff] [blame^] | 236 | if (mips_cm_is64) { |
| 237 | __ioread64_copy(pending, addr_gic_pend(), |
| 238 | DIV_ROUND_UP(gic_shared_intrs, 64)); |
| 239 | __ioread64_copy(intrmask, addr_gic_mask(), |
| 240 | DIV_ROUND_UP(gic_shared_intrs, 64)); |
| 241 | } else { |
| 242 | __ioread32_copy(pending, addr_gic_pend(), |
| 243 | DIV_ROUND_UP(gic_shared_intrs, 32)); |
| 244 | __ioread32_copy(intrmask, addr_gic_mask(), |
| 245 | DIV_ROUND_UP(gic_shared_intrs, 32)); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 248 | bitmap_and(pending, pending, intrmask, gic_shared_intrs); |
| 249 | bitmap_and(pending, pending, pcpu_mask, gic_shared_intrs); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 250 | |
Paul Burton | cae750b | 2016-08-19 18:11:19 +0100 | [diff] [blame] | 251 | for_each_set_bit(intr, pending, gic_shared_intrs) { |
Qais Yousef | d7eb4f2 | 2015-01-19 11:51:29 +0000 | [diff] [blame] | 252 | virq = irq_linear_revmap(gic_irq_domain, |
| 253 | GIC_SHARED_TO_HWIRQ(intr)); |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 254 | if (chained) |
| 255 | generic_handle_irq(virq); |
| 256 | else |
| 257 | do_IRQ(virq); |
Qais Yousef | d7eb4f2 | 2015-01-19 11:51:29 +0000 | [diff] [blame] | 258 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 261 | static void gic_mask_irq(struct irq_data *d) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 262 | { |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 263 | gic_reset_mask(GIC_HWIRQ_TO_SHARED(d->hwirq)); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 266 | static void gic_unmask_irq(struct irq_data *d) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 267 | { |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 268 | gic_set_mask(GIC_HWIRQ_TO_SHARED(d->hwirq)); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 271 | static void gic_ack_irq(struct irq_data *d) |
| 272 | { |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 273 | unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 274 | |
Andrew Bresticker | 53a7bc8 | 2014-10-20 12:03:57 -0700 | [diff] [blame] | 275 | gic_write(GIC_REG(SHARED, GIC_SH_WEDGE), GIC_SH_WEDGE_CLR(irq)); |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 278 | static int gic_set_type(struct irq_data *d, unsigned int type) |
| 279 | { |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 280 | unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 281 | unsigned long flags; |
| 282 | bool is_edge; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 283 | |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 284 | spin_lock_irqsave(&gic_lock, flags); |
| 285 | switch (type & IRQ_TYPE_SENSE_MASK) { |
| 286 | case IRQ_TYPE_EDGE_FALLING: |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 287 | gic_set_polarity(irq, GIC_POL_NEG); |
| 288 | gic_set_trigger(irq, GIC_TRIG_EDGE); |
| 289 | gic_set_dual_edge(irq, GIC_TRIG_DUAL_DISABLE); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 290 | is_edge = true; |
| 291 | break; |
| 292 | case IRQ_TYPE_EDGE_RISING: |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 293 | gic_set_polarity(irq, GIC_POL_POS); |
| 294 | gic_set_trigger(irq, GIC_TRIG_EDGE); |
| 295 | gic_set_dual_edge(irq, GIC_TRIG_DUAL_DISABLE); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 296 | is_edge = true; |
| 297 | break; |
| 298 | case IRQ_TYPE_EDGE_BOTH: |
| 299 | /* polarity is irrelevant in this case */ |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 300 | gic_set_trigger(irq, GIC_TRIG_EDGE); |
| 301 | gic_set_dual_edge(irq, GIC_TRIG_DUAL_ENABLE); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 302 | is_edge = true; |
| 303 | break; |
| 304 | case IRQ_TYPE_LEVEL_LOW: |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 305 | gic_set_polarity(irq, GIC_POL_NEG); |
| 306 | gic_set_trigger(irq, GIC_TRIG_LEVEL); |
| 307 | gic_set_dual_edge(irq, GIC_TRIG_DUAL_DISABLE); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 308 | is_edge = false; |
| 309 | break; |
| 310 | case IRQ_TYPE_LEVEL_HIGH: |
| 311 | default: |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 312 | gic_set_polarity(irq, GIC_POL_POS); |
| 313 | gic_set_trigger(irq, GIC_TRIG_LEVEL); |
| 314 | gic_set_dual_edge(irq, GIC_TRIG_DUAL_DISABLE); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 315 | is_edge = false; |
| 316 | break; |
| 317 | } |
| 318 | |
Thomas Gleixner | a595fc5 | 2015-06-23 14:41:25 +0200 | [diff] [blame] | 319 | if (is_edge) |
| 320 | irq_set_chip_handler_name_locked(d, &gic_edge_irq_controller, |
| 321 | handle_edge_irq, NULL); |
| 322 | else |
| 323 | irq_set_chip_handler_name_locked(d, &gic_level_irq_controller, |
| 324 | handle_level_irq, NULL); |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 325 | spin_unlock_irqrestore(&gic_lock, flags); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | #ifdef CONFIG_SMP |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 331 | static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask, |
| 332 | bool force) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 333 | { |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 334 | unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 335 | cpumask_t tmp = CPU_MASK_NONE; |
| 336 | unsigned long flags; |
| 337 | int i; |
| 338 | |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 339 | cpumask_and(&tmp, cpumask, cpu_online_mask); |
Rusty Russell | f9b531f | 2015-03-05 10:49:16 +1030 | [diff] [blame] | 340 | if (cpumask_empty(&tmp)) |
Andrew Bresticker | 14d160a | 2014-09-18 14:47:22 -0700 | [diff] [blame] | 341 | return -EINVAL; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 342 | |
| 343 | /* Assumption : cpumask refers to a single CPU */ |
| 344 | spin_lock_irqsave(&gic_lock, flags); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 345 | |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 346 | /* Re-route this IRQ */ |
Paul Burton | ab41f6c | 2015-09-22 11:29:10 -0700 | [diff] [blame] | 347 | gic_map_to_vpe(irq, mips_cm_vp_id(cpumask_first(&tmp))); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 348 | |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 349 | /* Update the pcpu_masks */ |
Paul Burton | 91951f9 | 2016-04-21 11:31:54 +0100 | [diff] [blame] | 350 | for (i = 0; i < min(gic_vpes, NR_CPUS); i++) |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 351 | clear_bit(irq, pcpu_masks[i].pcpu_mask); |
Rusty Russell | f9b531f | 2015-03-05 10:49:16 +1030 | [diff] [blame] | 352 | set_bit(irq, pcpu_masks[cpumask_first(&tmp)].pcpu_mask); |
Tony Wu | c214c03 | 2013-06-21 10:13:08 +0000 | [diff] [blame] | 353 | |
Jiang Liu | 72f86db | 2015-06-01 16:05:38 +0800 | [diff] [blame] | 354 | cpumask_copy(irq_data_get_affinity_mask(d), cpumask); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 355 | spin_unlock_irqrestore(&gic_lock, flags); |
| 356 | |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 357 | return IRQ_SET_MASK_OK_NOCOPY; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
Andrew Bresticker | 4a6a3ea3 | 2014-09-18 14:47:26 -0700 | [diff] [blame] | 361 | static struct irq_chip gic_level_irq_controller = { |
| 362 | .name = "MIPS GIC", |
| 363 | .irq_mask = gic_mask_irq, |
| 364 | .irq_unmask = gic_unmask_irq, |
| 365 | .irq_set_type = gic_set_type, |
| 366 | #ifdef CONFIG_SMP |
| 367 | .irq_set_affinity = gic_set_affinity, |
| 368 | #endif |
| 369 | }; |
| 370 | |
| 371 | static struct irq_chip gic_edge_irq_controller = { |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 372 | .name = "MIPS GIC", |
Andrew Bresticker | 5561c9e | 2014-09-18 14:47:20 -0700 | [diff] [blame] | 373 | .irq_ack = gic_ack_irq, |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 374 | .irq_mask = gic_mask_irq, |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 375 | .irq_unmask = gic_unmask_irq, |
Andrew Bresticker | 95150ae | 2014-09-18 14:47:21 -0700 | [diff] [blame] | 376 | .irq_set_type = gic_set_type, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 377 | #ifdef CONFIG_SMP |
Thomas Gleixner | 161d049 | 2011-03-23 21:08:58 +0000 | [diff] [blame] | 378 | .irq_set_affinity = gic_set_affinity, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 379 | #endif |
Qais Yousef | bb11cff | 2015-12-08 13:20:28 +0000 | [diff] [blame] | 380 | .ipi_send_single = gic_send_ipi, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 381 | }; |
| 382 | |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 383 | static void gic_handle_local_int(bool chained) |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 384 | { |
| 385 | unsigned long pending, masked; |
Qais Yousef | d7eb4f2 | 2015-01-19 11:51:29 +0000 | [diff] [blame] | 386 | unsigned int intr, virq; |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 387 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 388 | pending = gic_read32(GIC_REG(VPE_LOCAL, GIC_VPE_PEND)); |
| 389 | masked = gic_read32(GIC_REG(VPE_LOCAL, GIC_VPE_MASK)); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 390 | |
| 391 | bitmap_and(&pending, &pending, &masked, GIC_NUM_LOCAL_INTRS); |
| 392 | |
Paul Burton | 0f4ed15 | 2016-09-13 17:54:27 +0100 | [diff] [blame] | 393 | for_each_set_bit(intr, &pending, GIC_NUM_LOCAL_INTRS) { |
Qais Yousef | d7eb4f2 | 2015-01-19 11:51:29 +0000 | [diff] [blame] | 394 | virq = irq_linear_revmap(gic_irq_domain, |
| 395 | GIC_LOCAL_TO_HWIRQ(intr)); |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 396 | if (chained) |
| 397 | generic_handle_irq(virq); |
| 398 | else |
| 399 | do_IRQ(virq); |
Qais Yousef | d7eb4f2 | 2015-01-19 11:51:29 +0000 | [diff] [blame] | 400 | } |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static void gic_mask_local_irq(struct irq_data *d) |
| 404 | { |
| 405 | int intr = GIC_HWIRQ_TO_LOCAL(d->hwirq); |
| 406 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 407 | gic_write32(GIC_REG(VPE_LOCAL, GIC_VPE_RMASK), 1 << intr); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static void gic_unmask_local_irq(struct irq_data *d) |
| 411 | { |
| 412 | int intr = GIC_HWIRQ_TO_LOCAL(d->hwirq); |
| 413 | |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 414 | gic_write32(GIC_REG(VPE_LOCAL, GIC_VPE_SMASK), 1 << intr); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static struct irq_chip gic_local_irq_controller = { |
| 418 | .name = "MIPS GIC Local", |
| 419 | .irq_mask = gic_mask_local_irq, |
| 420 | .irq_unmask = gic_unmask_local_irq, |
| 421 | }; |
| 422 | |
| 423 | static void gic_mask_local_irq_all_vpes(struct irq_data *d) |
| 424 | { |
| 425 | int intr = GIC_HWIRQ_TO_LOCAL(d->hwirq); |
| 426 | int i; |
| 427 | unsigned long flags; |
| 428 | |
| 429 | spin_lock_irqsave(&gic_lock, flags); |
| 430 | for (i = 0; i < gic_vpes; i++) { |
Paul Burton | d46812b | 2016-02-03 03:15:27 +0000 | [diff] [blame] | 431 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), |
| 432 | mips_cm_vp_id(i)); |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 433 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_RMASK), 1 << intr); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 434 | } |
| 435 | spin_unlock_irqrestore(&gic_lock, flags); |
| 436 | } |
| 437 | |
| 438 | static void gic_unmask_local_irq_all_vpes(struct irq_data *d) |
| 439 | { |
| 440 | int intr = GIC_HWIRQ_TO_LOCAL(d->hwirq); |
| 441 | int i; |
| 442 | unsigned long flags; |
| 443 | |
| 444 | spin_lock_irqsave(&gic_lock, flags); |
| 445 | for (i = 0; i < gic_vpes; i++) { |
Paul Burton | d46812b | 2016-02-03 03:15:27 +0000 | [diff] [blame] | 446 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), |
| 447 | mips_cm_vp_id(i)); |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 448 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_SMASK), 1 << intr); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 449 | } |
| 450 | spin_unlock_irqrestore(&gic_lock, flags); |
| 451 | } |
| 452 | |
| 453 | static struct irq_chip gic_all_vpes_local_irq_controller = { |
| 454 | .name = "MIPS GIC Local", |
| 455 | .irq_mask = gic_mask_local_irq_all_vpes, |
| 456 | .irq_unmask = gic_unmask_local_irq_all_vpes, |
| 457 | }; |
| 458 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 459 | static void __gic_irq_dispatch(void) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 460 | { |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 461 | gic_handle_local_int(false); |
| 462 | gic_handle_shared_int(false); |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 465 | static void gic_irq_dispatch(struct irq_desc *desc) |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 466 | { |
Rabin Vincent | 1b3ed36 | 2015-06-12 10:01:56 +0200 | [diff] [blame] | 467 | gic_handle_local_int(true); |
| 468 | gic_handle_shared_int(true); |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 471 | static void __init gic_basic_init(void) |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 472 | { |
| 473 | unsigned int i; |
Steven J. Hill | 98b67c3 | 2012-08-31 16:18:49 -0500 | [diff] [blame] | 474 | |
| 475 | board_bind_eic_interrupt = &gic_bind_eic_interrupt; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 476 | |
| 477 | /* Setup defaults */ |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 478 | for (i = 0; i < gic_shared_intrs; i++) { |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 479 | gic_set_polarity(i, GIC_POL_POS); |
| 480 | gic_set_trigger(i, GIC_TRIG_LEVEL); |
| 481 | gic_reset_mask(i); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 482 | } |
| 483 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 484 | for (i = 0; i < gic_vpes; i++) { |
| 485 | unsigned int j; |
| 486 | |
Paul Burton | d46812b | 2016-02-03 03:15:27 +0000 | [diff] [blame] | 487 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), |
| 488 | mips_cm_vp_id(i)); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 489 | for (j = 0; j < GIC_NUM_LOCAL_INTRS; j++) { |
| 490 | if (!gic_local_irq_is_routable(j)) |
| 491 | continue; |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 492 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_RMASK), 1 << j); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 497 | static int gic_local_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 498 | irq_hw_number_t hw) |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 499 | { |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 500 | int intr = GIC_HWIRQ_TO_LOCAL(hw); |
| 501 | int ret = 0; |
| 502 | int i; |
| 503 | unsigned long flags; |
| 504 | |
| 505 | if (!gic_local_irq_is_routable(intr)) |
| 506 | return -EPERM; |
| 507 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 508 | spin_lock_irqsave(&gic_lock, flags); |
| 509 | for (i = 0; i < gic_vpes; i++) { |
| 510 | u32 val = GIC_MAP_TO_PIN_MSK | gic_cpu_pin; |
| 511 | |
Paul Burton | d46812b | 2016-02-03 03:15:27 +0000 | [diff] [blame] | 512 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), |
| 513 | mips_cm_vp_id(i)); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 514 | |
| 515 | switch (intr) { |
| 516 | case GIC_LOCAL_INT_WD: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 517 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_WD_MAP), val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 518 | break; |
| 519 | case GIC_LOCAL_INT_COMPARE: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 520 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_MAP), |
| 521 | val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 522 | break; |
| 523 | case GIC_LOCAL_INT_TIMER: |
James Hogan | 1b6af71 | 2015-01-19 15:38:24 +0000 | [diff] [blame] | 524 | /* CONFIG_MIPS_CMP workaround (see __gic_init) */ |
| 525 | val = GIC_MAP_TO_PIN_MSK | timer_cpu_pin; |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 526 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_TIMER_MAP), |
| 527 | val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 528 | break; |
| 529 | case GIC_LOCAL_INT_PERFCTR: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 530 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_PERFCTR_MAP), |
| 531 | val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 532 | break; |
| 533 | case GIC_LOCAL_INT_SWINT0: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 534 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_SWINT0_MAP), |
| 535 | val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 536 | break; |
| 537 | case GIC_LOCAL_INT_SWINT1: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 538 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_SWINT1_MAP), |
| 539 | val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 540 | break; |
| 541 | case GIC_LOCAL_INT_FDC: |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 542 | gic_write32(GIC_REG(VPE_OTHER, GIC_VPE_FDC_MAP), val); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 543 | break; |
| 544 | default: |
| 545 | pr_err("Invalid local IRQ %d\n", intr); |
| 546 | ret = -EINVAL; |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | spin_unlock_irqrestore(&gic_lock, flags); |
| 551 | |
| 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq, |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 556 | irq_hw_number_t hw, unsigned int vpe) |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 557 | { |
| 558 | int intr = GIC_HWIRQ_TO_SHARED(hw); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 559 | unsigned long flags; |
Qais Yousef | 78930f0 | 2015-12-08 13:20:26 +0000 | [diff] [blame] | 560 | int i; |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 561 | |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 562 | spin_lock_irqsave(&gic_lock, flags); |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 563 | gic_map_to_pin(intr, gic_cpu_pin); |
Paul Burton | 99ec8a3 | 2016-07-05 14:25:59 +0100 | [diff] [blame] | 564 | gic_map_to_vpe(intr, mips_cm_vp_id(vpe)); |
Paul Burton | 91951f9 | 2016-04-21 11:31:54 +0100 | [diff] [blame] | 565 | for (i = 0; i < min(gic_vpes, NR_CPUS); i++) |
Qais Yousef | 78930f0 | 2015-12-08 13:20:26 +0000 | [diff] [blame] | 566 | clear_bit(intr, pcpu_masks[i].pcpu_mask); |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 567 | set_bit(intr, pcpu_masks[vpe].pcpu_mask); |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 568 | spin_unlock_irqrestore(&gic_lock, flags); |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 573 | static int gic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 574 | const u32 *intspec, unsigned int intsize, |
| 575 | irq_hw_number_t *out_hwirq, |
| 576 | unsigned int *out_type) |
| 577 | { |
| 578 | if (intsize != 3) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | if (intspec[0] == GIC_SHARED) |
| 582 | *out_hwirq = GIC_SHARED_TO_HWIRQ(intspec[1]); |
| 583 | else if (intspec[0] == GIC_LOCAL) |
| 584 | *out_hwirq = GIC_LOCAL_TO_HWIRQ(intspec[1]); |
| 585 | else |
| 586 | return -EINVAL; |
| 587 | *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK; |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
Matt Redfearn | 8ada00a | 2017-04-20 10:07:36 +0100 | [diff] [blame] | 592 | static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 593 | irq_hw_number_t hwirq) |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 594 | { |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 595 | int err; |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 596 | |
Matt Redfearn | 8ada00a | 2017-04-20 10:07:36 +0100 | [diff] [blame] | 597 | if (hwirq >= GIC_SHARED_HWIRQ_BASE) { |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 598 | /* verify that shared irqs don't conflict with an IPI irq */ |
| 599 | if (test_bit(GIC_HWIRQ_TO_SHARED(hwirq), ipi_resrv)) |
| 600 | return -EBUSY; |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 601 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 602 | err = irq_domain_set_hwirq_and_chip(d, virq, hwirq, |
| 603 | &gic_level_irq_controller, |
| 604 | NULL); |
| 605 | if (err) |
| 606 | return err; |
| 607 | |
| 608 | return gic_shared_irq_domain_map(d, virq, hwirq, 0); |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 611 | switch (GIC_HWIRQ_TO_LOCAL(hwirq)) { |
| 612 | case GIC_LOCAL_INT_TIMER: |
| 613 | case GIC_LOCAL_INT_PERFCTR: |
| 614 | case GIC_LOCAL_INT_FDC: |
| 615 | /* |
| 616 | * HACK: These are all really percpu interrupts, but |
| 617 | * the rest of the MIPS kernel code does not use the |
| 618 | * percpu IRQ API for them. |
| 619 | */ |
| 620 | err = irq_domain_set_hwirq_and_chip(d, virq, hwirq, |
| 621 | &gic_all_vpes_local_irq_controller, |
| 622 | NULL); |
| 623 | if (err) |
| 624 | return err; |
| 625 | |
| 626 | irq_set_handler(virq, handle_percpu_irq); |
| 627 | break; |
| 628 | |
| 629 | default: |
| 630 | err = irq_domain_set_hwirq_and_chip(d, virq, hwirq, |
| 631 | &gic_local_irq_controller, |
| 632 | NULL); |
| 633 | if (err) |
| 634 | return err; |
| 635 | |
| 636 | irq_set_handler(virq, handle_percpu_devid_irq); |
| 637 | irq_set_percpu_devid(virq); |
| 638 | break; |
| 639 | } |
| 640 | |
| 641 | return gic_local_irq_domain_map(d, virq, hwirq); |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Matt Redfearn | 8ada00a | 2017-04-20 10:07:36 +0100 | [diff] [blame] | 644 | static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq, |
| 645 | unsigned int nr_irqs, void *arg) |
| 646 | { |
| 647 | struct irq_fwspec *fwspec = arg; |
| 648 | irq_hw_number_t hwirq; |
| 649 | |
| 650 | if (fwspec->param[0] == GIC_SHARED) |
| 651 | hwirq = GIC_SHARED_TO_HWIRQ(fwspec->param[1]); |
| 652 | else |
| 653 | hwirq = GIC_LOCAL_TO_HWIRQ(fwspec->param[1]); |
| 654 | |
| 655 | return gic_irq_domain_map(d, virq, hwirq); |
| 656 | } |
| 657 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 658 | void gic_irq_domain_free(struct irq_domain *d, unsigned int virq, |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 659 | unsigned int nr_irqs) |
| 660 | { |
Qais Yousef | c98c1822 | 2015-12-08 13:20:24 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 663 | static const struct irq_domain_ops gic_irq_domain_ops = { |
| 664 | .xlate = gic_irq_domain_xlate, |
| 665 | .alloc = gic_irq_domain_alloc, |
| 666 | .free = gic_irq_domain_free, |
Matt Redfearn | 8ada00a | 2017-04-20 10:07:36 +0100 | [diff] [blame] | 667 | .map = gic_irq_domain_map, |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, |
| 671 | const u32 *intspec, unsigned int intsize, |
| 672 | irq_hw_number_t *out_hwirq, |
| 673 | unsigned int *out_type) |
| 674 | { |
| 675 | /* |
| 676 | * There's nothing to translate here. hwirq is dynamically allocated and |
| 677 | * the irq type is always edge triggered. |
| 678 | * */ |
| 679 | *out_hwirq = 0; |
| 680 | *out_type = IRQ_TYPE_EDGE_RISING; |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | static int gic_ipi_domain_alloc(struct irq_domain *d, unsigned int virq, |
| 686 | unsigned int nr_irqs, void *arg) |
| 687 | { |
| 688 | struct cpumask *ipimask = arg; |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 689 | irq_hw_number_t hwirq, base_hwirq; |
| 690 | int cpu, ret, i; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 691 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 692 | base_hwirq = find_first_bit(ipi_available, gic_shared_intrs); |
| 693 | if (base_hwirq == gic_shared_intrs) |
| 694 | return -ENOMEM; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 695 | |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 696 | /* check that we have enough space */ |
| 697 | for (i = base_hwirq; i < nr_irqs; i++) { |
| 698 | if (!test_bit(i, ipi_available)) |
| 699 | return -EBUSY; |
| 700 | } |
| 701 | bitmap_clear(ipi_available, base_hwirq, nr_irqs); |
| 702 | |
| 703 | /* map the hwirq for each cpu consecutively */ |
| 704 | i = 0; |
| 705 | for_each_cpu(cpu, ipimask) { |
| 706 | hwirq = GIC_SHARED_TO_HWIRQ(base_hwirq + i); |
| 707 | |
| 708 | ret = irq_domain_set_hwirq_and_chip(d, virq + i, hwirq, |
| 709 | &gic_edge_irq_controller, |
| 710 | NULL); |
| 711 | if (ret) |
| 712 | goto error; |
| 713 | |
| 714 | ret = irq_domain_set_hwirq_and_chip(d->parent, virq + i, hwirq, |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 715 | &gic_edge_irq_controller, |
| 716 | NULL); |
| 717 | if (ret) |
| 718 | goto error; |
| 719 | |
| 720 | ret = irq_set_irq_type(virq + i, IRQ_TYPE_EDGE_RISING); |
| 721 | if (ret) |
| 722 | goto error; |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 723 | |
| 724 | ret = gic_shared_irq_domain_map(d, virq + i, hwirq, cpu); |
| 725 | if (ret) |
| 726 | goto error; |
| 727 | |
| 728 | i++; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | error: |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 733 | bitmap_set(ipi_available, base_hwirq, nr_irqs); |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq, |
| 738 | unsigned int nr_irqs) |
| 739 | { |
Paul Burton | b87281e | 2017-04-20 10:07:35 +0100 | [diff] [blame] | 740 | irq_hw_number_t base_hwirq; |
| 741 | struct irq_data *data; |
| 742 | |
| 743 | data = irq_get_irq_data(virq); |
| 744 | if (!data) |
| 745 | return; |
| 746 | |
| 747 | base_hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(data)); |
| 748 | bitmap_set(ipi_available, base_hwirq, nr_irqs); |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node, |
| 752 | enum irq_domain_bus_token bus_token) |
| 753 | { |
| 754 | bool is_ipi; |
| 755 | |
| 756 | switch (bus_token) { |
| 757 | case DOMAIN_BUS_IPI: |
| 758 | is_ipi = d->bus_token == bus_token; |
Paul Burton | 547aefc | 2016-07-05 14:26:00 +0100 | [diff] [blame] | 759 | return (!node || to_of_node(d->fwnode) == node) && is_ipi; |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 760 | break; |
| 761 | default: |
| 762 | return 0; |
| 763 | } |
| 764 | } |
| 765 | |
Tobias Klauser | 0b7e815 | 2017-06-02 10:20:56 +0200 | [diff] [blame] | 766 | static const struct irq_domain_ops gic_ipi_domain_ops = { |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 767 | .xlate = gic_ipi_domain_xlate, |
| 768 | .alloc = gic_ipi_domain_alloc, |
| 769 | .free = gic_ipi_domain_free, |
| 770 | .match = gic_ipi_domain_match, |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 771 | }; |
| 772 | |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 773 | static void __init __gic_init(unsigned long gic_base_addr, |
| 774 | unsigned long gic_addrspace_size, |
| 775 | unsigned int cpu_vec, unsigned int irqbase, |
| 776 | struct device_node *node) |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 777 | { |
Paul Burton | ba01cf0 | 2016-05-17 15:31:06 +0100 | [diff] [blame] | 778 | unsigned int gicconfig, cpu; |
Qais Yousef | 16a8083 | 2015-12-08 13:20:30 +0000 | [diff] [blame] | 779 | unsigned int v[2]; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 780 | |
Alex Smith | c0a9f72 | 2015-10-12 10:40:43 +0100 | [diff] [blame] | 781 | __gic_base_addr = gic_base_addr; |
| 782 | |
Paul Burton | 582e2b4 | 2017-08-12 21:36:10 -0700 | [diff] [blame] | 783 | mips_gic_base = ioremap_nocache(gic_base_addr, gic_addrspace_size); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 784 | |
Andrew Bresticker | 5f68fea | 2014-10-20 12:03:52 -0700 | [diff] [blame] | 785 | gicconfig = gic_read(GIC_REG(SHARED, GIC_SH_CONFIG)); |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 786 | gic_shared_intrs = (gicconfig & GIC_SH_CONFIG_NUMINTRS_MSK) >> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 787 | GIC_SH_CONFIG_NUMINTRS_SHF; |
Andrew Bresticker | fbd5524 | 2014-09-18 14:47:25 -0700 | [diff] [blame] | 788 | gic_shared_intrs = ((gic_shared_intrs + 1) * 8); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 789 | |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 790 | gic_vpes = (gicconfig & GIC_SH_CONFIG_NUMVPES_MSK) >> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 791 | GIC_SH_CONFIG_NUMVPES_SHF; |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 792 | gic_vpes = gic_vpes + 1; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 793 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 794 | if (cpu_has_veic) { |
Paul Burton | ba01cf0 | 2016-05-17 15:31:06 +0100 | [diff] [blame] | 795 | /* Set EIC mode for all VPEs */ |
| 796 | for_each_present_cpu(cpu) { |
| 797 | gic_write(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), |
| 798 | mips_cm_vp_id(cpu)); |
| 799 | gic_write(GIC_REG(VPE_OTHER, GIC_VPE_CTL), |
| 800 | GIC_VPE_CTL_EIC_MODE_MSK); |
| 801 | } |
| 802 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 803 | /* Always use vector 1 in EIC mode */ |
| 804 | gic_cpu_pin = 0; |
James Hogan | 1b6af71 | 2015-01-19 15:38:24 +0000 | [diff] [blame] | 805 | timer_cpu_pin = gic_cpu_pin; |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 806 | set_vi_handler(gic_cpu_pin + GIC_PIN_TO_VEC_OFFSET, |
| 807 | __gic_irq_dispatch); |
| 808 | } else { |
| 809 | gic_cpu_pin = cpu_vec - GIC_CPU_PIN_OFFSET; |
| 810 | irq_set_chained_handler(MIPS_CPU_IRQ_BASE + cpu_vec, |
| 811 | gic_irq_dispatch); |
James Hogan | 1b6af71 | 2015-01-19 15:38:24 +0000 | [diff] [blame] | 812 | /* |
| 813 | * With the CMP implementation of SMP (deprecated), other CPUs |
| 814 | * are started by the bootloader and put into a timer based |
| 815 | * waiting poll loop. We must not re-route those CPU's local |
| 816 | * timer interrupts as the wait instruction will never finish, |
| 817 | * so just handle whatever CPU interrupt it is routed to by |
| 818 | * default. |
| 819 | * |
| 820 | * This workaround should be removed when CMP support is |
| 821 | * dropped. |
| 822 | */ |
| 823 | if (IS_ENABLED(CONFIG_MIPS_CMP) && |
| 824 | gic_local_irq_is_routable(GIC_LOCAL_INT_TIMER)) { |
Markos Chandras | c3f57f0 | 2015-07-14 10:26:09 +0100 | [diff] [blame] | 825 | timer_cpu_pin = gic_read32(GIC_REG(VPE_LOCAL, |
James Hogan | 1b6af71 | 2015-01-19 15:38:24 +0000 | [diff] [blame] | 826 | GIC_VPE_TIMER_MAP)) & |
| 827 | GIC_MAP_MSK; |
| 828 | irq_set_chained_handler(MIPS_CPU_IRQ_BASE + |
| 829 | GIC_CPU_PIN_OFFSET + |
| 830 | timer_cpu_pin, |
| 831 | gic_irq_dispatch); |
| 832 | } else { |
| 833 | timer_cpu_pin = gic_cpu_pin; |
| 834 | } |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 837 | gic_irq_domain = irq_domain_add_simple(node, GIC_NUM_LOCAL_INTRS + |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 838 | gic_shared_intrs, irqbase, |
Andrew Bresticker | c49581a | 2014-09-18 14:47:23 -0700 | [diff] [blame] | 839 | &gic_irq_domain_ops, NULL); |
| 840 | if (!gic_irq_domain) |
| 841 | panic("Failed to add GIC IRQ domain"); |
Steven J. Hill | 0b271f5 | 2012-08-31 16:05:37 -0500 | [diff] [blame] | 842 | |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 843 | gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain, |
| 844 | IRQ_DOMAIN_FLAG_IPI_PER_CPU, |
| 845 | GIC_NUM_LOCAL_INTRS + gic_shared_intrs, |
| 846 | node, &gic_ipi_domain_ops, NULL); |
| 847 | if (!gic_ipi_domain) |
| 848 | panic("Failed to add GIC IPI domain"); |
| 849 | |
Marc Zyngier | 96f0d93 | 2017-06-22 11:42:50 +0100 | [diff] [blame] | 850 | irq_domain_update_bus_token(gic_ipi_domain, DOMAIN_BUS_IPI); |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 851 | |
Qais Yousef | 16a8083 | 2015-12-08 13:20:30 +0000 | [diff] [blame] | 852 | if (node && |
| 853 | !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", v, 2)) { |
| 854 | bitmap_set(ipi_resrv, v[0], v[1]); |
| 855 | } else { |
| 856 | /* Make the last 2 * gic_vpes available for IPIs */ |
| 857 | bitmap_set(ipi_resrv, |
| 858 | gic_shared_intrs - 2 * gic_vpes, |
| 859 | 2 * gic_vpes); |
| 860 | } |
Qais Yousef | 2af70a9 | 2015-12-08 13:20:23 +0000 | [diff] [blame] | 861 | |
Paul Burton | f8dcd9e | 2017-04-20 10:07:34 +0100 | [diff] [blame] | 862 | bitmap_copy(ipi_available, ipi_resrv, GIC_MAX_INTRS); |
Andrew Bresticker | e9de688 | 2014-09-18 14:47:27 -0700 | [diff] [blame] | 863 | gic_basic_init(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 864 | } |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 865 | |
| 866 | void __init gic_init(unsigned long gic_base_addr, |
| 867 | unsigned long gic_addrspace_size, |
| 868 | unsigned int cpu_vec, unsigned int irqbase) |
| 869 | { |
| 870 | __gic_init(gic_base_addr, gic_addrspace_size, cpu_vec, irqbase, NULL); |
| 871 | } |
| 872 | |
| 873 | static int __init gic_of_init(struct device_node *node, |
| 874 | struct device_node *parent) |
| 875 | { |
| 876 | struct resource res; |
| 877 | unsigned int cpu_vec, i = 0, reserved = 0; |
| 878 | phys_addr_t gic_base; |
| 879 | size_t gic_len; |
| 880 | |
| 881 | /* Find the first available CPU vector. */ |
| 882 | while (!of_property_read_u32_index(node, "mti,reserved-cpu-vectors", |
| 883 | i++, &cpu_vec)) |
| 884 | reserved |= BIT(cpu_vec); |
| 885 | for (cpu_vec = 2; cpu_vec < 8; cpu_vec++) { |
| 886 | if (!(reserved & BIT(cpu_vec))) |
| 887 | break; |
| 888 | } |
| 889 | if (cpu_vec == 8) { |
| 890 | pr_err("No CPU vectors available for GIC\n"); |
| 891 | return -ENODEV; |
| 892 | } |
| 893 | |
| 894 | if (of_address_to_resource(node, 0, &res)) { |
| 895 | /* |
| 896 | * Probe the CM for the GIC base address if not specified |
| 897 | * in the device-tree. |
| 898 | */ |
| 899 | if (mips_cm_present()) { |
| 900 | gic_base = read_gcr_gic_base() & |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 901 | ~CM_GCR_GIC_BASE_GICEN; |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 902 | gic_len = 0x20000; |
| 903 | } else { |
| 904 | pr_err("Failed to get GIC memory range\n"); |
| 905 | return -ENODEV; |
| 906 | } |
| 907 | } else { |
| 908 | gic_base = res.start; |
| 909 | gic_len = resource_size(&res); |
| 910 | } |
| 911 | |
James Hogan | a0ffec3 | 2017-08-12 21:36:09 -0700 | [diff] [blame] | 912 | if (mips_cm_present()) { |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 913 | write_gcr_gic_base(gic_base | CM_GCR_GIC_BASE_GICEN); |
James Hogan | a0ffec3 | 2017-08-12 21:36:09 -0700 | [diff] [blame] | 914 | /* Ensure GIC region is enabled before trying to access it */ |
| 915 | __sync(); |
| 916 | } |
Andrew Bresticker | a705727 | 2014-11-12 11:43:38 -0800 | [diff] [blame] | 917 | gic_present = true; |
| 918 | |
| 919 | __gic_init(gic_base, gic_len, cpu_vec, 0, node); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | IRQCHIP_DECLARE(mips_gic, "mti,gic", gic_of_init); |