blob: f02cbf5cd8d6a609eece94a049abf8b089e568e0 [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>
Ralf Baechle631330f2009-06-19 14:05:26 +010011#include <linux/smp.h>
David Howellsca4d3e672010-10-07 14:08:54 +010012#include <linux/irq.h>
Steven J. Hilldfa762e2013-04-10 16:28:36 -050013#include <linux/clocksource.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010014
15#include <asm/io.h>
16#include <asm/gic.h>
Steven J. Hill98b67c32012-08-31 16:18:49 -050017#include <asm/setup.h>
18#include <asm/traps.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010019#include <linux/hardirq.h>
20#include <asm-generic/bitops/find.h>
21
Steven J. Hill28ea2152013-04-10 16:27:50 -050022unsigned int gic_frequency;
Steven J. Hillff867142013-04-10 16:27:04 -050023unsigned int gic_present;
Steven J. Hill0b271f52012-08-31 16:05:37 -050024unsigned long _gic_base;
25unsigned int gic_irq_base;
26unsigned int gic_irq_flags[GIC_NUM_INTRS];
Ralf Baechle39b8d522008-04-28 17:14:26 +010027
Steven J. Hill98b67c32012-08-31 16:18:49 -050028/* The index into this array is the vector # of the interrupt. */
29struct gic_shared_intr_map gic_shared_intr_map[GIC_NUM_INTRS];
30
Jeffrey Deans822350b2014-07-17 09:20:53 +010031struct gic_pcpu_mask {
32 DECLARE_BITMAP(pcpu_mask, GIC_NUM_INTRS);
33};
34
35struct gic_pending_regs {
36 DECLARE_BITMAP(pending, GIC_NUM_INTRS);
37};
38
39struct gic_intrmask_regs {
40 DECLARE_BITMAP(intrmask, GIC_NUM_INTRS);
41};
42
Steven J. Hill0b271f52012-08-31 16:05:37 -050043static struct gic_pcpu_mask pcpu_masks[NR_CPUS];
Ralf Baechle39b8d522008-04-28 17:14:26 +010044static struct gic_pending_regs pending_regs[NR_CPUS];
45static struct gic_intrmask_regs intrmask_regs[NR_CPUS];
Andrew Bresticker95150ae2014-09-18 14:47:21 -070046static DEFINE_SPINLOCK(gic_lock);
Ralf Baechle39b8d522008-04-28 17:14:26 +010047
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050048#if defined(CONFIG_CSRC_GIC) || defined(CONFIG_CEVT_GIC)
Steven J. Hilldfa762e2013-04-10 16:28:36 -050049cycle_t gic_read_count(void)
50{
51 unsigned int hi, hi2, lo;
52
53 do {
54 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi);
55 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_31_00), lo);
56 GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi2);
57 } while (hi2 != hi);
58
59 return (((cycle_t) hi) << 32) + lo;
60}
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050061
62void gic_write_compare(cycle_t cnt)
63{
64 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI),
65 (int)(cnt >> 32));
66 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO),
67 (int)(cnt & 0xffffffff));
68}
69
Paul Burton414408d02014-03-05 11:35:53 +000070void gic_write_cpu_compare(cycle_t cnt, int cpu)
71{
72 unsigned long flags;
73
74 local_irq_save(flags);
75
76 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), cpu);
77 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_HI),
78 (int)(cnt >> 32));
79 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_COMPARE_LO),
80 (int)(cnt & 0xffffffff));
81
82 local_irq_restore(flags);
83}
84
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -050085cycle_t gic_read_compare(void)
86{
87 unsigned int hi, lo;
88
89 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_HI), hi);
90 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_LO), lo);
91
92 return (((cycle_t) hi) << 32) + lo;
93}
Steven J. Hilldfa762e2013-04-10 16:28:36 -050094#endif
95
Steven J. Hill98b67c32012-08-31 16:18:49 -050096unsigned int gic_get_timer_pending(void)
97{
98 unsigned int vpe_pending;
99
100 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
101 GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_PEND), vpe_pending);
Ralf Baechle635c99072014-10-21 14:12:49 +0200102 return vpe_pending & GIC_VPE_PEND_TIMER_MSK;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500103}
104
105void gic_bind_eic_interrupt(int irq, int set)
106{
107 /* Convert irq vector # to hw int # */
108 irq -= GIC_PIN_TO_VEC_OFFSET;
109
110 /* Set irq to use shadow set */
111 GICWRITE(GIC_REG_ADDR(VPE_LOCAL, GIC_VPE_EIC_SS(irq)), set);
112}
113
Ralf Baechle39b8d522008-04-28 17:14:26 +0100114void gic_send_ipi(unsigned int intr)
115{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100116 GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), 0x80000000 | intr);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100117}
118
Steven J. Hill98b67c32012-08-31 16:18:49 -0500119static void gic_eic_irq_dispatch(void)
120{
121 unsigned int cause = read_c0_cause();
122 int irq;
123
124 irq = (cause & ST0_IM) >> STATUSB_IP2;
125 if (irq == 0)
126 irq = -1;
127
128 if (irq >= 0)
129 do_IRQ(gic_irq_base + irq);
130 else
131 spurious_interrupt();
132}
133
Chris Dearman7098f742009-07-10 01:54:09 -0700134static void __init vpe_local_setup(unsigned int numvpes)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100135{
Steven J. Hill98b67c32012-08-31 16:18:49 -0500136 unsigned long timer_intr = GIC_INT_TMR;
137 unsigned long perf_intr = GIC_INT_PERFCTR;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100138 unsigned int vpe_ctl;
Steven J. Hill2299c492012-08-31 16:13:07 -0500139 int i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100140
Steven J. Hill98b67c32012-08-31 16:18:49 -0500141 if (cpu_has_veic) {
142 /*
143 * GIC timer interrupt -> CPU HW Int X (vector X+2) ->
144 * map to pin X+2-1 (since GIC adds 1)
145 */
146 timer_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET);
147 /*
148 * GIC perfcnt interrupt -> CPU HW Int X (vector X+2) ->
149 * map to pin X+2-1 (since GIC adds 1)
150 */
151 perf_intr += (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET);
152 }
153
Ralf Baechle39b8d522008-04-28 17:14:26 +0100154 /*
155 * Setup the default performance counter timer interrupts
156 * for all VPEs
157 */
158 for (i = 0; i < numvpes; i++) {
159 GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), i);
160
161 /* Are Interrupts locally routable? */
162 GICREAD(GIC_REG(VPE_OTHER, GIC_VPE_CTL), vpe_ctl);
163 if (vpe_ctl & GIC_VPE_CTL_TIMER_RTBL_MSK)
164 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_TIMER_MAP),
Steven J. Hill98b67c32012-08-31 16:18:49 -0500165 GIC_MAP_TO_PIN_MSK | timer_intr);
166 if (cpu_has_veic) {
167 set_vi_handler(timer_intr + GIC_PIN_TO_VEC_OFFSET,
168 gic_eic_irq_dispatch);
169 gic_shared_intr_map[timer_intr + GIC_PIN_TO_VEC_OFFSET].local_intr_mask |= GIC_VPE_RMASK_TIMER_MSK;
170 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100171
172 if (vpe_ctl & GIC_VPE_CTL_PERFCNT_RTBL_MSK)
173 GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_PERFCTR_MAP),
Steven J. Hill98b67c32012-08-31 16:18:49 -0500174 GIC_MAP_TO_PIN_MSK | perf_intr);
175 if (cpu_has_veic) {
176 set_vi_handler(perf_intr + GIC_PIN_TO_VEC_OFFSET, gic_eic_irq_dispatch);
177 gic_shared_intr_map[perf_intr + GIC_PIN_TO_VEC_OFFSET].local_intr_mask |= GIC_VPE_RMASK_PERFCNT_MSK;
178 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100179 }
180}
181
Raghu Gandham0ab2b7d2013-04-10 16:30:12 -0500182unsigned int gic_compare_int(void)
183{
184 unsigned int pending;
185
186 GICREAD(GIC_REG(VPE_LOCAL, GIC_VPE_PEND), pending);
187 if (pending & GIC_VPE_PEND_CMP_MSK)
188 return 1;
189 else
190 return 0;
191}
192
Jeffrey Deans31521a72014-07-17 09:20:57 +0100193void gic_get_int_mask(unsigned long *dst, const unsigned long *src)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100194{
195 unsigned int i;
196 unsigned long *pending, *intrmask, *pcpu_mask;
197 unsigned long *pending_abs, *intrmask_abs;
198
199 /* Get per-cpu bitmaps */
200 pending = pending_regs[smp_processor_id()].pending;
201 intrmask = intrmask_regs[smp_processor_id()].intrmask;
202 pcpu_mask = pcpu_masks[smp_processor_id()].pcpu_mask;
203
204 pending_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED,
205 GIC_SH_PEND_31_0_OFS);
206 intrmask_abs = (unsigned long *) GIC_REG_ABS_ADDR(SHARED,
207 GIC_SH_MASK_31_0_OFS);
208
209 for (i = 0; i < BITS_TO_LONGS(GIC_NUM_INTRS); i++) {
210 GICREAD(*pending_abs, pending[i]);
211 GICREAD(*intrmask_abs, intrmask[i]);
212 pending_abs++;
213 intrmask_abs++;
214 }
215
216 bitmap_and(pending, pending, intrmask, GIC_NUM_INTRS);
217 bitmap_and(pending, pending, pcpu_mask, GIC_NUM_INTRS);
Jeffrey Deans31521a72014-07-17 09:20:57 +0100218 bitmap_and(dst, src, pending, GIC_NUM_INTRS);
219}
Ralf Baechle39b8d522008-04-28 17:14:26 +0100220
Jeffrey Deans31521a72014-07-17 09:20:57 +0100221unsigned int gic_get_int(void)
222{
223 DECLARE_BITMAP(interrupts, GIC_NUM_INTRS);
224
225 bitmap_fill(interrupts, GIC_NUM_INTRS);
226 gic_get_int_mask(interrupts, interrupts);
227
228 return find_first_bit(interrupts, GIC_NUM_INTRS);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100229}
230
Thomas Gleixner161d0492011-03-23 21:08:58 +0000231static void gic_mask_irq(struct irq_data *d)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100232{
Steven J. Hill2299c492012-08-31 16:13:07 -0500233 GIC_CLR_INTR_MASK(d->irq - gic_irq_base);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100234}
235
Thomas Gleixner161d0492011-03-23 21:08:58 +0000236static void gic_unmask_irq(struct irq_data *d)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100237{
Steven J. Hill2299c492012-08-31 16:13:07 -0500238 GIC_SET_INTR_MASK(d->irq - gic_irq_base);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100239}
240
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700241static void gic_ack_irq(struct irq_data *d)
242{
243 /* Clear edge detector */
244 if (gic_irq_flags[d->irq - gic_irq_base] & GIC_TRIG_EDGE)
245 GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), d->irq - gic_irq_base);
246}
247
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700248static int gic_set_type(struct irq_data *d, unsigned int type)
249{
250 unsigned int irq = d->irq - gic_irq_base;
251 unsigned long flags;
252 bool is_edge;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100253
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700254 spin_lock_irqsave(&gic_lock, flags);
255 switch (type & IRQ_TYPE_SENSE_MASK) {
256 case IRQ_TYPE_EDGE_FALLING:
257 GIC_SET_POLARITY(irq, GIC_POL_NEG);
258 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
259 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
260 is_edge = true;
261 break;
262 case IRQ_TYPE_EDGE_RISING:
263 GIC_SET_POLARITY(irq, GIC_POL_POS);
264 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
265 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
266 is_edge = true;
267 break;
268 case IRQ_TYPE_EDGE_BOTH:
269 /* polarity is irrelevant in this case */
270 GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
271 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_ENABLE);
272 is_edge = true;
273 break;
274 case IRQ_TYPE_LEVEL_LOW:
275 GIC_SET_POLARITY(irq, GIC_POL_NEG);
276 GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
277 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
278 is_edge = false;
279 break;
280 case IRQ_TYPE_LEVEL_HIGH:
281 default:
282 GIC_SET_POLARITY(irq, GIC_POL_POS);
283 GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
284 GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
285 is_edge = false;
286 break;
287 }
288
289 if (is_edge) {
290 gic_irq_flags[irq] |= GIC_TRIG_EDGE;
291 __irq_set_handler_locked(d->irq, handle_edge_irq);
292 } else {
293 gic_irq_flags[irq] &= ~GIC_TRIG_EDGE;
294 __irq_set_handler_locked(d->irq, handle_level_irq);
295 }
296 spin_unlock_irqrestore(&gic_lock, flags);
297
298 return 0;
299}
300
301#ifdef CONFIG_SMP
Thomas Gleixner161d0492011-03-23 21:08:58 +0000302static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
303 bool force)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100304{
Steven J. Hill2299c492012-08-31 16:13:07 -0500305 unsigned int irq = (d->irq - gic_irq_base);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100306 cpumask_t tmp = CPU_MASK_NONE;
307 unsigned long flags;
308 int i;
309
Rusty Russell0de26522008-12-13 21:20:26 +1030310 cpumask_and(&tmp, cpumask, cpu_online_mask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100311 if (cpus_empty(tmp))
Andrew Bresticker14d160a2014-09-18 14:47:22 -0700312 return -EINVAL;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100313
314 /* Assumption : cpumask refers to a single CPU */
315 spin_lock_irqsave(&gic_lock, flags);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100316
Tony Wuc214c032013-06-21 10:13:08 +0000317 /* Re-route this IRQ */
318 GIC_SH_MAP_TO_VPE_SMASK(irq, first_cpu(tmp));
Ralf Baechle39b8d522008-04-28 17:14:26 +0100319
Tony Wuc214c032013-06-21 10:13:08 +0000320 /* Update the pcpu_masks */
321 for (i = 0; i < NR_CPUS; i++)
322 clear_bit(irq, pcpu_masks[i].pcpu_mask);
323 set_bit(irq, pcpu_masks[first_cpu(tmp)].pcpu_mask);
324
Thomas Gleixner161d0492011-03-23 21:08:58 +0000325 cpumask_copy(d->affinity, cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100326 spin_unlock_irqrestore(&gic_lock, flags);
327
Thomas Gleixner161d0492011-03-23 21:08:58 +0000328 return IRQ_SET_MASK_OK_NOCOPY;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100329}
330#endif
331
332static struct irq_chip gic_irq_controller = {
Thomas Gleixner161d0492011-03-23 21:08:58 +0000333 .name = "MIPS GIC",
Andrew Bresticker5561c9e2014-09-18 14:47:20 -0700334 .irq_ack = gic_ack_irq,
Thomas Gleixner161d0492011-03-23 21:08:58 +0000335 .irq_mask = gic_mask_irq,
Thomas Gleixner161d0492011-03-23 21:08:58 +0000336 .irq_unmask = gic_unmask_irq,
Andrew Bresticker95150ae2014-09-18 14:47:21 -0700337 .irq_set_type = gic_set_type,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100338#ifdef CONFIG_SMP
Thomas Gleixner161d0492011-03-23 21:08:58 +0000339 .irq_set_affinity = gic_set_affinity,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100340#endif
341};
342
Chris Dearman7098f742009-07-10 01:54:09 -0700343static void __init gic_setup_intr(unsigned int intr, unsigned int cpu,
344 unsigned int pin, unsigned int polarity, unsigned int trigtype,
345 unsigned int flags)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100346{
Steven J. Hill98b67c32012-08-31 16:18:49 -0500347 struct gic_shared_intr_map *map_ptr;
348
Ralf Baechle39b8d522008-04-28 17:14:26 +0100349 /* Setup Intr to Pin mapping */
350 if (pin & GIC_MAP_TO_NMI_MSK) {
Jeffrey Deans6096e112014-07-17 09:20:56 +0100351 int i;
352
Ralf Baechle39b8d522008-04-28 17:14:26 +0100353 GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_MAP_TO_PIN(intr)), pin);
354 /* FIXME: hack to route NMI to all cpu's */
Jeffrey Deans6096e112014-07-17 09:20:56 +0100355 for (i = 0; i < NR_CPUS; i += 32) {
Ralf Baechle39b8d522008-04-28 17:14:26 +0100356 GICWRITE(GIC_REG_ADDR(SHARED,
Jeffrey Deans6096e112014-07-17 09:20:56 +0100357 GIC_SH_MAP_TO_VPE_REG_OFF(intr, i)),
Ralf Baechle39b8d522008-04-28 17:14:26 +0100358 0xffffffff);
359 }
360 } else {
361 GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_MAP_TO_PIN(intr)),
362 GIC_MAP_TO_PIN_MSK | pin);
363 /* Setup Intr to CPU mapping */
364 GIC_SH_MAP_TO_VPE_SMASK(intr, cpu);
Steven J. Hill98b67c32012-08-31 16:18:49 -0500365 if (cpu_has_veic) {
366 set_vi_handler(pin + GIC_PIN_TO_VEC_OFFSET,
367 gic_eic_irq_dispatch);
368 map_ptr = &gic_shared_intr_map[pin + GIC_PIN_TO_VEC_OFFSET];
369 if (map_ptr->num_shared_intr >= GIC_MAX_SHARED_INTR)
370 BUG();
371 map_ptr->intr_list[map_ptr->num_shared_intr++] = intr;
372 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100373 }
374
375 /* Setup Intr Polarity */
376 GIC_SET_POLARITY(intr, polarity);
377
378 /* Setup Intr Trigger Type */
379 GIC_SET_TRIGGER(intr, trigtype);
380
381 /* Init Intr Masks */
Chris Dearman7098f742009-07-10 01:54:09 -0700382 GIC_CLR_INTR_MASK(intr);
Jeffrey Deansb0a88ae2014-07-17 09:20:55 +0100383
Chris Dearman7098f742009-07-10 01:54:09 -0700384 /* Initialise per-cpu Interrupt software masks */
Jeffrey Deansb0a88ae2014-07-17 09:20:55 +0100385 set_bit(intr, pcpu_masks[cpu].pcpu_mask);
386
Steven J. Hill98b67c32012-08-31 16:18:49 -0500387 if ((flags & GIC_FLAG_TRANSPARENT) && (cpu_has_veic == 0))
Chris Dearman7098f742009-07-10 01:54:09 -0700388 GIC_SET_INTR_MASK(intr);
389 if (trigtype == GIC_TRIG_EDGE)
Steven J. Hill0b271f52012-08-31 16:05:37 -0500390 gic_irq_flags[intr] |= GIC_TRIG_EDGE;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100391}
392
Chris Dearman7098f742009-07-10 01:54:09 -0700393static void __init gic_basic_init(int numintrs, int numvpes,
394 struct gic_intr_map *intrmap, int mapsize)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100395{
396 unsigned int i, cpu;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500397 unsigned int pin_offset = 0;
398
399 board_bind_eic_interrupt = &gic_bind_eic_interrupt;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100400
401 /* Setup defaults */
Chris Dearman7098f742009-07-10 01:54:09 -0700402 for (i = 0; i < numintrs; i++) {
Ralf Baechle39b8d522008-04-28 17:14:26 +0100403 GIC_SET_POLARITY(i, GIC_POL_POS);
404 GIC_SET_TRIGGER(i, GIC_TRIG_LEVEL);
Chris Dearman7098f742009-07-10 01:54:09 -0700405 GIC_CLR_INTR_MASK(i);
Steven J. Hill98b67c32012-08-31 16:18:49 -0500406 if (i < GIC_NUM_INTRS) {
Chris Dearman7098f742009-07-10 01:54:09 -0700407 gic_irq_flags[i] = 0;
Steven J. Hill98b67c32012-08-31 16:18:49 -0500408 gic_shared_intr_map[i].num_shared_intr = 0;
409 gic_shared_intr_map[i].local_intr_mask = 0;
410 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100411 }
412
Steven J. Hill98b67c32012-08-31 16:18:49 -0500413 /*
414 * In EIC mode, the HW_INT# is offset by (2-1). Need to subtract
415 * one because the GIC will add one (since 0=no intr).
416 */
417 if (cpu_has_veic)
418 pin_offset = (GIC_CPU_TO_VEC_OFFSET - GIC_PIN_TO_VEC_OFFSET);
419
Ralf Baechle39b8d522008-04-28 17:14:26 +0100420 /* Setup specifics */
Chris Dearman7098f742009-07-10 01:54:09 -0700421 for (i = 0; i < mapsize; i++) {
422 cpu = intrmap[i].cpunum;
Ralf Baechle863cb9b2010-09-17 17:07:48 +0100423 if (cpu == GIC_UNUSED)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100424 continue;
Chris Dearman7098f742009-07-10 01:54:09 -0700425 gic_setup_intr(i,
426 intrmap[i].cpunum,
Steven J. Hill98b67c32012-08-31 16:18:49 -0500427 intrmap[i].pin + pin_offset,
Chris Dearman7098f742009-07-10 01:54:09 -0700428 intrmap[i].polarity,
429 intrmap[i].trigtype,
430 intrmap[i].flags);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100431 }
432
433 vpe_local_setup(numvpes);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100434}
435
436void __init gic_init(unsigned long gic_base_addr,
437 unsigned long gic_addrspace_size,
438 struct gic_intr_map *intr_map, unsigned int intr_map_size,
439 unsigned int irqbase)
440{
441 unsigned int gicconfig;
Chris Dearman7098f742009-07-10 01:54:09 -0700442 int numvpes, numintrs;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100443
444 _gic_base = (unsigned long) ioremap_nocache(gic_base_addr,
445 gic_addrspace_size);
Steven J. Hill0b271f52012-08-31 16:05:37 -0500446 gic_irq_base = irqbase;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100447
448 GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), gicconfig);
449 numintrs = (gicconfig & GIC_SH_CONFIG_NUMINTRS_MSK) >>
450 GIC_SH_CONFIG_NUMINTRS_SHF;
451 numintrs = ((numintrs + 1) * 8);
452
453 numvpes = (gicconfig & GIC_SH_CONFIG_NUMVPES_MSK) >>
454 GIC_SH_CONFIG_NUMVPES_SHF;
Steven J. Hill3234f442012-08-31 16:23:49 -0500455 numvpes = numvpes + 1;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100456
Chris Dearman7098f742009-07-10 01:54:09 -0700457 gic_basic_init(numintrs, numvpes, intr_map, intr_map_size);
Steven J. Hill0b271f52012-08-31 16:05:37 -0500458
459 gic_platform_init(numintrs, &gic_irq_controller);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100460}