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