blob: 633a34639388117144021cbd7f3c4adcd3fbd78c [file] [log] [blame]
Steven J. Hill2299c492012-08-31 16:13:07 -05001/*
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 Baechle39b8d522008-04-28 17:14:26 +01009#include <linux/bitmap.h>
10#include <linux/init.h>
Andrew Bresticker18743d22014-09-18 14:47:24 -070011#include <linux/interrupt.h>
12#include <linux/sched.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010013#include <linux/smp.h>
David Howellsca4d3e672010-10-07 14:08:54 +010014#include <linux/irq.h>
Steven J. Hilldfa762e2013-04-10 16:28:36 -050015#include <linux/clocksource.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010016
17#include <asm/io.h>
18#include <asm/gic.h>
Steven J. Hill98b67c32012-08-31 16:18:49 -050019#include <asm/setup.h>
20#include <asm/traps.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010021#include <linux/hardirq.h>
22#include <asm-generic/bitops/find.h>
23
Steven J. Hill28ea2152013-04-10 16:27:50 -050024unsigned int gic_frequency;
Steven J. Hillff867142013-04-10 16:27:04 -050025unsigned int gic_present;
Steven J. Hill0b271f52012-08-31 16:05:37 -050026unsigned long _gic_base;
Steven J. Hill0b271f52012-08-31 16:05:37 -050027unsigned int gic_irq_flags[GIC_NUM_INTRS];
Andrew Bresticker18743d22014-09-18 14:47:24 -070028unsigned int gic_cpu_pin;
Steven J. Hill98b67c32012-08-31 16:18:49 -050029
Jeffrey Deans822350b2014-07-17 09:20:53 +010030struct gic_pcpu_mask {
31 DECLARE_BITMAP(pcpu_mask, GIC_NUM_INTRS);
32};
33
34struct gic_pending_regs {
35 DECLARE_BITMAP(pending, GIC_NUM_INTRS);
36};
37
38struct gic_intrmask_regs {
39 DECLARE_BITMAP(intrmask, GIC_NUM_INTRS);
40};
41
Steven J. Hill0b271f52012-08-31 16:05:37 -050042static struct gic_pcpu_mask pcpu_masks[NR_CPUS];
Ralf Baechle39b8d522008-04-28 17:14:26 +010043static struct gic_pending_regs pending_regs[NR_CPUS];
44static struct gic_intrmask_regs intrmask_regs[NR_CPUS];
Andrew Bresticker95150ae2014-09-18 14:47:21 -070045static DEFINE_SPINLOCK(gic_lock);
Andrew Brestickerc49581a2014-09-18 14:47:23 -070046static struct irq_domain *gic_irq_domain;
Ralf Baechle39b8d522008-04-28 17:14:26 +010047
Andrew Bresticker18743d22014-09-18 14:47:24 -070048static void __gic_irq_dispatch(void);
49
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050050#if defined(CONFIG_CSRC_GIC) || defined(CONFIG_CEVT_GIC)
Steven J. Hilldfa762e2013-04-10 16:28:36 -050051cycle_t gic_read_count(void)
52{
53 unsigned int hi, hi2, lo;
54
55 do {
56 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi);
57 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_31_00), lo);
58 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi2);
59 } while (hi2 != hi);
60
61 return (((cycle_t) hi) << 32) + lo;
62}
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050063
64void gic_write_compare(cycle_t cnt)
65{
66 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI),
67 (int)(cnt >> 32));
68 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO),
69 (int)(cnt & 0xffffffff));
70}
71
Paul Burton414408d02014-03-05 11:35:53 +000072void gic_write_cpu_compare(cycle_t cnt, int cpu)
73{
74 unsigned long flags;
75
76 local_irq_save(flags);
77
78 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), cpu);
79 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_HI),
80 (int)(cnt >> 32));
81 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_LO),
82 (int)(cnt & 0xffffffff));
83
84 local_irq_restore(flags);
85}
86
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050087cycle_t gic_read_compare(void)
88{
89 unsigned int hi, lo;
90
91 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI), hi);
92 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO), lo);
93
94 return (((cycle_t) hi) << 32) + lo;
95}
Steven J. Hilldfa762e2013-04-10 16:28:36 -050096#endif
97
Steven J. Hill98b67c32012-08-31 16:18:49 -050098unsigned int gic_get_timer_pending(void)
99{
100 unsigned int vpe_pending;
101
102 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
103 GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_PEND), vpe_pending);
Ralf Baechle635c99072014-10-21 14:12:49 +0200104 return vpe_pending & GIC_VPE_PEND_TIMER_MSK;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500105}
106
107void gic_bind_eic_interrupt(int irq, int set)
108{
109 /* Convert irq vector # to hw int # */
110 irq -= GIC_PIN_TO_VEC_OFFSET;
111
112 /* Set irq to use shadow set */
113 GICWRITE(GIC_REG_ADDR(VPE_LOCAL, GIC_VPE_EIC_SS(irq)), set);
114}
115
Ralf Baechle39b8d522008-04-28 17:14:26 +0100116void gic_send_ipi(unsigned int intr)
117{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100118 GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), 0x80000000 | intr);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100119}
120
Chris Dearman7098f742009-07-10 01:54:09 -0700121static void __init vpe_local_setup(unsigned int numvpes)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100122{
Steven J. Hill98b67c32012-08-31 16:18:49 -0500123 unsigned long timer_intr = GIC_INT_TMR;
124 unsigned long perf_intr = GIC_INT_PERFCTR;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100125 unsigned int vpe_ctl;
Steven J. Hill2299c492012-08-31 16:13:07 -0500126 int i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100127
Steven J. Hill98b67c32012-08-31 16:18:49 -0500128 if (cpu_has_veic) {
129 /*
130 * GIC timer interrupt -> CPU HW Int X (vector X+2) ->
131 * map to pin X+2-1 (since GIC adds 1)
132 */
133 timer_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET);
134 /*
135 * GIC perfcnt interrupt -> CPU HW Int X (vector X+2) ->
136 * map to pin X+2-1 (since GIC adds 1)
137 */
138 perf_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET);
139 }
140
Ralf Baechle39b8d522008-04-28 17:14:26 +0100141 /*
142 * Setup the default performance counter timer interrupts
143 * for all VPEs
144 */
145 for (i = 0; i < numvpes; i++) {
146 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), i);
147
148 /* Are Interrupts locally routable? */
149 GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_CTL), vpe_ctl);
150 if (vpe_ctl & GIC_VPE_CTL_TIMER_RTBL_MSK)
151 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_TIMER_MAP),
Steven J. Hill98b67c32012-08-31 16:18:49 -0500152 GIC_MAP_TO_PIN_MSK | timer_intr);
153 if (cpu_has_veic) {
154 set_vi_handler(timer_intr + GIC_PIN_TO_VEC_OFFSET,
Andrew Bresticker18743d22014-09-18 14:47:24 -0700155 __gic_irq_dispatch);
Steven J. Hill98b67c32012-08-31 16:18:49 -0500156 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100157
158 if (vpe_ctl & GIC_VPE_CTL_PERFCNT_RTBL_MSK)
159 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_PERFCTR_MAP),
Steven J. Hill98b67c32012-08-31 16:18:49 -0500160 GIC_MAP_TO_PIN_MSK | perf_intr);
161 if (cpu_has_veic) {
Andrew Bresticker18743d22014-09-18 14:47:24 -0700162 set_vi_handler(perf_intr + GIC_PIN_TO_VEC_OFFSET,
163 __gic_irq_dispatch);
Steven J. Hill98b67c32012-08-31 16:18:49 -0500164 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100165 }
166}
167
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -0500168unsigned int gic_compare_int(void)
169{
170 unsigned int pending;
171
172 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_PEND), pending);
173 if (pending & GIC_VPE_PEND_CMP_MSK)
174 return 1;
175 else
176 return 0;
177}
178
Jeffrey Deans31521a72014-07-17 09:20:57 +0100179void gic_get_int_mask(unsigned long *dst, const unsigned long *src)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100180{
181 unsigned int i;
182 unsigned long *pending, *intrmask, *pcpu_mask;
183 unsigned long *pending_abs, *intrmask_abs;
184
185 /* Get per-cpu bitmaps */
186 pending = pending_regs[smp_processor_id()].pending;
187 intrmask = intrmask_regs[smp_processor_id()].intrmask;
188 pcpu_mask = pcpu_masks[smp_processor_id()].pcpu_mask;
189
190 pending_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED,
191 GIC_SH_PEND_31_0_OFS);
192 intrmask_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED,
193 GIC_SH_MASK_31_0_OFS);
194
195 for (i = 0; i < BITS_TO_LONGS(GIC_NUM_INTRS); i++) {
196 GICREAD(*pending_abs, pending[i]);
197 GICREAD(*intrmask_abs, intrmask[i]);
198 pending_abs++;
199 intrmask_abs++;
200 }
201
202 bitmap_and(pending, pending, intrmask, GIC_NUM_INTRS);
203 bitmap_and(pending, pending, pcpu_mask, GIC_NUM_INTRS);
Jeffrey Deans31521a72014-07-17 09:20:57 +0100204 bitmap_and(dst, src, pending, GIC_NUM_INTRS);
205}
Ralf Baechle39b8d522008-04-28 17:14:26 +0100206
Jeffrey Deans31521a72014-07-17 09:20:57 +0100207unsigned int gic_get_int(void)
208{
209 DECLARE_BITMAP(interrupts, GIC_NUM_INTRS);
210
211 bitmap_fill(interrupts, GIC_NUM_INTRS);
212 gic_get_int_mask(interrupts, interrupts);
213
214 return find_first_bit(interrupts, GIC_NUM_INTRS);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100215}
216
Thomas Gleixner161d0492011-03-23 21:08:58 +0000217static void gic_mask_irq(struct irq_data *d)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100218{
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700219 GIC_CLR_INTR_MASK(d->hwirq);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100220}
221
Thomas Gleixner161d0492011-03-23 21:08:58 +0000222static void gic_unmask_irq(struct irq_data *d)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100223{
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700224 GIC_SET_INTR_MASK(d->hwirq);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100225}
226
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700227static void gic_ack_irq(struct irq_data *d)
228{
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700229 unsigned int irq = d->hwirq;
230
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700231 /* Clear edge detector */
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700232 if (gic_irq_flags[irq] & GIC_TRIG_EDGE)
233 GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq);
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700234}
235
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700236static int gic_set_type(struct irq_data *d, unsigned int type)
237{
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700238 unsigned int irq = d->hwirq;
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700239 unsigned long flags;
240 bool is_edge;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100241
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700242 spin_lock_irqsave(&gic_lock, flags);
243 switch (type & IRQ_TYPE_SENSE_MASK) {
244 case IRQ_TYPE_EDGE_FALLING:
245 GIC_SET_POLARITY(irq, GIC_POL_NEG);
246 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
247 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
248 is_edge = true;
249 break;
250 case IRQ_TYPE_EDGE_RISING:
251 GIC_SET_POLARITY(irq, GIC_POL_POS);
252 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
253 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
254 is_edge = true;
255 break;
256 case IRQ_TYPE_EDGE_BOTH:
257 /* polarity is irrelevant in this case */
258 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
259 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_ENABLE);
260 is_edge = true;
261 break;
262 case IRQ_TYPE_LEVEL_LOW:
263 GIC_SET_POLARITY(irq, GIC_POL_NEG);
264 GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
265 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
266 is_edge = false;
267 break;
268 case IRQ_TYPE_LEVEL_HIGH:
269 default:
270 GIC_SET_POLARITY(irq, GIC_POL_POS);
271 GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
272 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
273 is_edge = false;
274 break;
275 }
276
277 if (is_edge) {
278 gic_irq_flags[irq] |= GIC_TRIG_EDGE;
279 __irq_set_handler_locked(d->irq, handle_edge_irq);
280 } else {
281 gic_irq_flags[irq] &= ~GIC_TRIG_EDGE;
282 __irq_set_handler_locked(d->irq, handle_level_irq);
283 }
284 spin_unlock_irqrestore(&gic_lock, flags);
285
286 return 0;
287}
288
289#ifdef CONFIG_SMP
Thomas Gleixner161d0492011-03-23 21:08:58 +0000290static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
291 bool force)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100292{
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700293 unsigned int irq = d->hwirq;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100294 cpumask_t tmp = CPU_MASK_NONE;
295 unsigned long flags;
296 int i;
297
Rusty Russell0de26522008-12-13 21:20:26 +1030298 cpumask_and(&tmp, cpumask, cpu_online_mask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100299 if (cpus_empty(tmp))
Andrew Bresticker14d160a2014-09-18 14:47:22 -0700300 return -EINVAL;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100301
302 /* Assumption : cpumask refers to a single CPU */
303 spin_lock_irqsave(&gic_lock, flags);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100304
Tony Wuc214c032013-06-21 10:13:08 +0000305 /* Re-route this IRQ */
306 GIC_SH_MAP_TO_VPE_SMASK(irq, first_cpu(tmp));
Ralf Baechle39b8d522008-04-28 17:14:26 +0100307
Tony Wuc214c032013-06-21 10:13:08 +0000308 /* Update the pcpu_masks */
309 for (i = 0; i < NR_CPUS; i++)
310 clear_bit(irq, pcpu_masks[i].pcpu_mask);
311 set_bit(irq, pcpu_masks[first_cpu(tmp)].pcpu_mask);
312
Thomas Gleixner161d0492011-03-23 21:08:58 +0000313 cpumask_copy(d->affinity, cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100314 spin_unlock_irqrestore(&gic_lock, flags);
315
Thomas Gleixner161d0492011-03-23 21:08:58 +0000316 return IRQ_SET_MASK_OK_NOCOPY;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100317}
318#endif
319
320static struct irq_chip gic_irq_controller = {
Thomas Gleixner161d0492011-03-23 21:08:58 +0000321 .name = "MIPS GIC",
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700322 .irq_ack = gic_ack_irq,
Thomas Gleixner161d0492011-03-23 21:08:58 +0000323 .irq_mask = gic_mask_irq,
Thomas Gleixner161d0492011-03-23 21:08:58 +0000324 .irq_unmask = gic_unmask_irq,
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700325 .irq_set_type = gic_set_type,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100326#ifdef CONFIG_SMP
Thomas Gleixner161d0492011-03-23 21:08:58 +0000327 .irq_set_affinity = gic_set_affinity,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100328#endif
329};
330
Andrew Bresticker18743d22014-09-18 14:47:24 -0700331static void __gic_irq_dispatch(void)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100332{
Andrew Bresticker18743d22014-09-18 14:47:24 -0700333 unsigned int intr, virq;
334
335 while ((intr = gic_get_int()) != GIC_NUM_INTRS) {
336 virq = irq_linear_revmap(gic_irq_domain, intr);
337 do_IRQ(virq);
338 }
339}
340
341static void gic_irq_dispatch(unsigned int irq, struct irq_desc *desc)
342{
343 __gic_irq_dispatch();
344}
345
346#ifdef CONFIG_MIPS_GIC_IPI
347static int gic_resched_int_base;
348static int gic_call_int_base;
349
350unsigned int plat_ipi_resched_int_xlate(unsigned int cpu)
351{
352 return gic_resched_int_base + cpu;
353}
354
355unsigned int plat_ipi_call_int_xlate(unsigned int cpu)
356{
357 return gic_call_int_base + cpu;
358}
359
360static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
361{
362 scheduler_ipi();
363
364 return IRQ_HANDLED;
365}
366
367static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
368{
369 smp_call_function_interrupt();
370
371 return IRQ_HANDLED;
372}
373
374static struct irqaction irq_resched = {
375 .handler = ipi_resched_interrupt,
376 .flags = IRQF_PERCPU,
377 .name = "IPI resched"
378};
379
380static struct irqaction irq_call = {
381 .handler = ipi_call_interrupt,
382 .flags = IRQF_PERCPU,
383 .name = "IPI call"
384};
385
386static __init void gic_ipi_init_one(unsigned int intr, int cpu,
387 struct irqaction *action)
388{
389 int virq = irq_create_mapping(gic_irq_domain, intr);
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700390 int i;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500391
Andrew Bresticker18743d22014-09-18 14:47:24 -0700392 GIC_SH_MAP_TO_VPE_SMASK(intr, cpu);
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700393 for (i = 0; i < NR_CPUS; i++)
394 clear_bit(intr, pcpu_masks[i].pcpu_mask);
Jeffrey Deansb0a88ae2014-07-17 09:20:55 +0100395 set_bit(intr, pcpu_masks[cpu].pcpu_mask);
396
Andrew Bresticker18743d22014-09-18 14:47:24 -0700397 irq_set_irq_type(virq, IRQ_TYPE_EDGE_RISING);
398
399 irq_set_handler(virq, handle_percpu_irq);
400 setup_irq(virq, action);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100401}
402
Andrew Bresticker18743d22014-09-18 14:47:24 -0700403static __init void gic_ipi_init(void)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100404{
Andrew Bresticker18743d22014-09-18 14:47:24 -0700405 int i;
406
407 /* Use last 2 * NR_CPUS interrupts as IPIs */
408 gic_resched_int_base = GIC_NUM_INTRS - nr_cpu_ids;
409 gic_call_int_base = gic_resched_int_base - nr_cpu_ids;
410
411 for (i = 0; i < nr_cpu_ids; i++) {
412 gic_ipi_init_one(gic_call_int_base + i, i, &irq_call);
413 gic_ipi_init_one(gic_resched_int_base + i, i, &irq_resched);
414 }
415}
416#else
417static inline void gic_ipi_init(void)
418{
419}
420#endif
421
422static void __init gic_basic_init(int numintrs, int numvpes)
423{
424 unsigned int i;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500425
426 board_bind_eic_interrupt = &gic_bind_eic_interrupt;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100427
428 /* Setup defaults */
Chris Dearman7098f742009-07-10 01:54:09 -0700429 for (i = 0; i < numintrs; i++) {
Ralf Baechle39b8d522008-04-28 17:14:26 +0100430 GIC_SET_POLARITY(i, GIC_POL_POS);
431 GIC_SET_TRIGGER(i, GIC_TRIG_LEVEL);
Chris Dearman7098f742009-07-10 01:54:09 -0700432 GIC_CLR_INTR_MASK(i);
Andrew Bresticker18743d22014-09-18 14:47:24 -0700433 if (i < GIC_NUM_INTRS)
Chris Dearman7098f742009-07-10 01:54:09 -0700434 gic_irq_flags[i] = 0;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100435 }
436
437 vpe_local_setup(numvpes);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100438}
439
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700440static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
441 irq_hw_number_t hw)
442{
443 unsigned long flags;
444
445 irq_set_chip_and_handler(virq, &gic_irq_controller, handle_level_irq);
446
447 spin_lock_irqsave(&gic_lock, flags);
448 GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_MAP_TO_PIN(hw)),
Andrew Bresticker18743d22014-09-18 14:47:24 -0700449 GIC_MAP_TO_PIN_MSK | gic_cpu_pin);
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700450 /* Map to VPE 0 by default */
451 GIC_SH_MAP_TO_VPE_SMASK(hw, 0);
452 set_bit(hw, pcpu_masks[0].pcpu_mask);
453 spin_unlock_irqrestore(&gic_lock, flags);
454
455 return 0;
456}
457
458static struct irq_domain_ops gic_irq_domain_ops = {
459 .map = gic_irq_domain_map,
460 .xlate = irq_domain_xlate_twocell,
461};
462
Ralf Baechle39b8d522008-04-28 17:14:26 +0100463void __init gic_init(unsigned long gic_base_addr,
Andrew Bresticker18743d22014-09-18 14:47:24 -0700464 unsigned long gic_addrspace_size, unsigned int cpu_vec,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100465 unsigned int irqbase)
466{
467 unsigned int gicconfig;
Chris Dearman7098f742009-07-10 01:54:09 -0700468 int numvpes, numintrs;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100469
470 _gic_base = (unsigned long) ioremap_nocache(gic_base_addr,
471 gic_addrspace_size);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100472
473 GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), gicconfig);
474 numintrs = (gicconfig & GIC_SH_CONFIG_NUMINTRS_MSK) >>
475 GIC_SH_CONFIG_NUMINTRS_SHF;
476 numintrs = ((numintrs + 1) * 8);
477
478 numvpes = (gicconfig & GIC_SH_CONFIG_NUMVPES_MSK) >>
479 GIC_SH_CONFIG_NUMVPES_SHF;
Steven J. Hill3234f442012-08-31 16:23:49 -0500480 numvpes = numvpes + 1;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100481
Andrew Bresticker18743d22014-09-18 14:47:24 -0700482 if (cpu_has_veic) {
483 /* Always use vector 1 in EIC mode */
484 gic_cpu_pin = 0;
485 set_vi_handler(gic_cpu_pin + GIC_PIN_TO_VEC_OFFSET,
486 __gic_irq_dispatch);
487 } else {
488 gic_cpu_pin = cpu_vec - GIC_CPU_PIN_OFFSET;
489 irq_set_chained_handler(MIPS_CPU_IRQ_BASE + cpu_vec,
490 gic_irq_dispatch);
491 }
492
Andrew Brestickerc49581a2014-09-18 14:47:23 -0700493 gic_irq_domain = irq_domain_add_simple(NULL, GIC_NUM_INTRS, irqbase,
494 &gic_irq_domain_ops, NULL);
495 if (!gic_irq_domain)
496 panic("Failed to add GIC IRQ domain");
Steven J. Hill0b271f52012-08-31 16:05:37 -0500497
Andrew Bresticker18743d22014-09-18 14:47:24 -0700498 gic_basic_init(numintrs, numvpes);
499
500 gic_ipi_init();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100501}