blob: 666b278e56d7c6bf4610e05f0afd25de06646944 [file] [log] [blame]
Russell Kingf27ecac2005-08-18 21:31:00 +01001/*
2 * linux/arch/arm/common/gic.c
3 *
4 * Copyright (C) 2002 ARM Limited, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Interrupt architecture for the GIC:
11 *
12 * o There is one Interrupt Distributor, which receives interrupts
13 * from system devices and sends them to the Interrupt Controllers.
14 *
15 * o There is one CPU Interface per CPU, which sends interrupts sent
16 * by the Distributor, and interrupts generated locally, to the
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010017 * associated CPU. The base address of the CPU interface is usually
18 * aliased so that the same address points to different chips depending
19 * on the CPU it is accessed from.
Russell Kingf27ecac2005-08-18 21:31:00 +010020 *
21 * Note that IRQs 0-31 are special - they are local to each CPU.
22 * As such, the enable set/clear, pending set/clear and active bit
23 * registers are banked per-cpu for these sources.
24 */
25#include <linux/init.h>
26#include <linux/kernel.h>
27#include <linux/list.h>
28#include <linux/smp.h>
Catalin Marinasdcb86e82005-08-31 21:45:14 +010029#include <linux/cpumask.h>
Russell Kingfced80c2008-09-06 12:10:45 +010030#include <linux/io.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010031
32#include <asm/irq.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010033#include <asm/mach/irq.h>
34#include <asm/hardware/gic.h>
35
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +010036static DEFINE_SPINLOCK(irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +010037
Russell Kingff2e27a2010-12-04 16:13:29 +000038/* Address of GIC 0 CPU interface */
Russell Kingbef8f9e2010-12-04 16:50:58 +000039void __iomem *gic_cpu_base_addr __read_mostly;
Russell Kingff2e27a2010-12-04 16:13:29 +000040
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010041/*
42 * Supported arch specific GIC irq extension.
43 * Default make them NULL.
44 */
45struct irq_chip gic_arch_extn = {
Will Deacon1a017532011-02-09 12:01:12 +000046 .irq_eoi = NULL,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010047 .irq_mask = NULL,
48 .irq_unmask = NULL,
49 .irq_retrigger = NULL,
50 .irq_set_type = NULL,
51 .irq_set_wake = NULL,
52};
53
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010054#ifndef MAX_GIC_NR
55#define MAX_GIC_NR 1
56#endif
57
Russell Kingbef8f9e2010-12-04 16:50:58 +000058static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010059
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010060static inline void __iomem *gic_dist_base(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010061{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010062 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010063 return gic_data->dist_base;
64}
65
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010066static inline void __iomem *gic_cpu_base(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010067{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010068 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010069 return gic_data->cpu_base;
70}
71
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010072static inline unsigned int gic_irq(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010073{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010074 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
75 return d->irq - gic_data->irq_offset;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010076}
77
Russell Kingf27ecac2005-08-18 21:31:00 +010078/*
79 * Routines to acknowledge, disable and enable interrupts
Russell Kingf27ecac2005-08-18 21:31:00 +010080 */
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010081static void gic_mask_irq(struct irq_data *d)
Russell Kingf27ecac2005-08-18 21:31:00 +010082{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010083 u32 mask = 1 << (d->irq % 32);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +010084
85 spin_lock(&irq_controller_lock);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +053086 writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4);
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010087 if (gic_arch_extn.irq_mask)
88 gic_arch_extn.irq_mask(d);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +010089 spin_unlock(&irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +010090}
91
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010092static void gic_unmask_irq(struct irq_data *d)
Russell Kingf27ecac2005-08-18 21:31:00 +010093{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +010094 u32 mask = 1 << (d->irq % 32);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +010095
96 spin_lock(&irq_controller_lock);
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010097 if (gic_arch_extn.irq_unmask)
98 gic_arch_extn.irq_unmask(d);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +053099 writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +0100100 spin_unlock(&irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +0100101}
102
Will Deacon1a017532011-02-09 12:01:12 +0000103static void gic_eoi_irq(struct irq_data *d)
104{
105 if (gic_arch_extn.irq_eoi) {
106 spin_lock(&irq_controller_lock);
107 gic_arch_extn.irq_eoi(d);
108 spin_unlock(&irq_controller_lock);
109 }
110
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530111 writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI);
Will Deacon1a017532011-02-09 12:01:12 +0000112}
113
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100114static int gic_set_type(struct irq_data *d, unsigned int type)
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100115{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100116 void __iomem *base = gic_dist_base(d);
117 unsigned int gicirq = gic_irq(d);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100118 u32 enablemask = 1 << (gicirq % 32);
119 u32 enableoff = (gicirq / 32) * 4;
120 u32 confmask = 0x2 << ((gicirq % 16) * 2);
121 u32 confoff = (gicirq / 16) * 4;
122 bool enabled = false;
123 u32 val;
124
125 /* Interrupt configuration for SGIs can't be changed */
126 if (gicirq < 16)
127 return -EINVAL;
128
129 if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING)
130 return -EINVAL;
131
132 spin_lock(&irq_controller_lock);
133
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100134 if (gic_arch_extn.irq_set_type)
135 gic_arch_extn.irq_set_type(d, type);
136
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530137 val = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100138 if (type == IRQ_TYPE_LEVEL_HIGH)
139 val &= ~confmask;
140 else if (type == IRQ_TYPE_EDGE_RISING)
141 val |= confmask;
142
143 /*
144 * As recommended by the spec, disable the interrupt before changing
145 * the configuration
146 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530147 if (readl_relaxed(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) {
148 writel_relaxed(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100149 enabled = true;
150 }
151
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530152 writel_relaxed(val, base + GIC_DIST_CONFIG + confoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100153
154 if (enabled)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530155 writel_relaxed(enablemask, base + GIC_DIST_ENABLE_SET + enableoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100156
157 spin_unlock(&irq_controller_lock);
158
159 return 0;
160}
161
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100162static int gic_retrigger(struct irq_data *d)
163{
164 if (gic_arch_extn.irq_retrigger)
165 return gic_arch_extn.irq_retrigger(d);
166
167 return -ENXIO;
168}
169
Catalin Marinasa06f5462005-09-30 16:07:05 +0100170#ifdef CONFIG_SMP
Russell Kingc1917892011-01-23 12:12:01 +0000171static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
172 bool force)
Russell Kingf27ecac2005-08-18 21:31:00 +0100173{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100174 void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3);
175 unsigned int shift = (d->irq % 4) * 8;
Russell King5dfc54e2011-07-21 15:00:57 +0100176 unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask);
Russell Kingc1917892011-01-23 12:12:01 +0000177 u32 val, mask, bit;
178
Russell King5dfc54e2011-07-21 15:00:57 +0100179 if (cpu >= 8 || cpu >= nr_cpu_ids)
Russell Kingc1917892011-01-23 12:12:01 +0000180 return -EINVAL;
181
182 mask = 0xff << shift;
Will Deacon267840f2011-08-23 22:20:03 +0100183 bit = 1 << (cpu_logical_map(cpu) + shift);
Russell Kingf27ecac2005-08-18 21:31:00 +0100184
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +0100185 spin_lock(&irq_controller_lock);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530186 val = readl_relaxed(reg) & ~mask;
187 writel_relaxed(val | bit, reg);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +0100188 spin_unlock(&irq_controller_lock);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700189
Russell King5dfc54e2011-07-21 15:00:57 +0100190 return IRQ_SET_MASK_OK;
Russell Kingf27ecac2005-08-18 21:31:00 +0100191}
Catalin Marinasa06f5462005-09-30 16:07:05 +0100192#endif
Russell Kingf27ecac2005-08-18 21:31:00 +0100193
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100194#ifdef CONFIG_PM
195static int gic_set_wake(struct irq_data *d, unsigned int on)
196{
197 int ret = -ENXIO;
198
199 if (gic_arch_extn.irq_set_wake)
200 ret = gic_arch_extn.irq_set_wake(d, on);
201
202 return ret;
203}
204
205#else
206#define gic_set_wake NULL
207#endif
208
Russell King0f347bb2007-05-17 10:11:34 +0100209static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100210{
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100211 struct gic_chip_data *chip_data = irq_get_handler_data(irq);
212 struct irq_chip *chip = irq_get_chip(irq);
Russell King0f347bb2007-05-17 10:11:34 +0100213 unsigned int cascade_irq, gic_irq;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100214 unsigned long status;
215
Will Deacon1a017532011-02-09 12:01:12 +0000216 chained_irq_enter(chip, desc);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100217
218 spin_lock(&irq_controller_lock);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530219 status = readl_relaxed(chip_data->cpu_base + GIC_CPU_INTACK);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100220 spin_unlock(&irq_controller_lock);
221
Russell King0f347bb2007-05-17 10:11:34 +0100222 gic_irq = (status & 0x3ff);
223 if (gic_irq == 1023)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100224 goto out;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100225
Russell King0f347bb2007-05-17 10:11:34 +0100226 cascade_irq = gic_irq + chip_data->irq_offset;
227 if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS))
228 do_bad_IRQ(cascade_irq, desc);
229 else
230 generic_handle_irq(cascade_irq);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100231
232 out:
Will Deacon1a017532011-02-09 12:01:12 +0000233 chained_irq_exit(chip, desc);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100234}
235
David Brownell38c677c2006-08-01 22:26:25 +0100236static struct irq_chip gic_chip = {
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100237 .name = "GIC",
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100238 .irq_mask = gic_mask_irq,
239 .irq_unmask = gic_unmask_irq,
Will Deacon1a017532011-02-09 12:01:12 +0000240 .irq_eoi = gic_eoi_irq,
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100241 .irq_set_type = gic_set_type,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100242 .irq_retrigger = gic_retrigger,
Russell Kingf27ecac2005-08-18 21:31:00 +0100243#ifdef CONFIG_SMP
Russell Kingc1917892011-01-23 12:12:01 +0000244 .irq_set_affinity = gic_set_affinity,
Russell Kingf27ecac2005-08-18 21:31:00 +0100245#endif
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100246 .irq_set_wake = gic_set_wake,
Russell Kingf27ecac2005-08-18 21:31:00 +0100247};
248
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100249void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
250{
251 if (gic_nr >= MAX_GIC_NR)
252 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100253 if (irq_set_handler_data(irq, &gic_data[gic_nr]) != 0)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100254 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100255 irq_set_chained_handler(irq, gic_handle_cascade_irq);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100256}
257
Russell Kingbef8f9e2010-12-04 16:50:58 +0000258static void __init gic_dist_init(struct gic_chip_data *gic,
Russell Kingb580b892010-12-04 15:55:14 +0000259 unsigned int irq_start)
Russell Kingf27ecac2005-08-18 21:31:00 +0100260{
Pawel Molle6afec92010-11-26 13:45:43 +0100261 unsigned int gic_irqs, irq_limit, i;
Will Deacon267840f2011-08-23 22:20:03 +0100262 u32 cpumask;
Russell Kingbef8f9e2010-12-04 16:50:58 +0000263 void __iomem *base = gic->dist_base;
Will Deacon267840f2011-08-23 22:20:03 +0100264 u32 cpu = 0;
Russell Kingf27ecac2005-08-18 21:31:00 +0100265
Will Deacon267840f2011-08-23 22:20:03 +0100266#ifdef CONFIG_SMP
267 cpu = cpu_logical_map(smp_processor_id());
268#endif
269
270 cpumask = 1 << cpu;
Russell Kingf27ecac2005-08-18 21:31:00 +0100271 cpumask |= cpumask << 8;
272 cpumask |= cpumask << 16;
273
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530274 writel_relaxed(0, base + GIC_DIST_CTRL);
Russell Kingf27ecac2005-08-18 21:31:00 +0100275
276 /*
277 * Find out how many interrupts are supported.
Russell Kingf27ecac2005-08-18 21:31:00 +0100278 * The GIC only supports up to 1020 interrupt sources.
Russell Kingf27ecac2005-08-18 21:31:00 +0100279 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530280 gic_irqs = readl_relaxed(base + GIC_DIST_CTR) & 0x1f;
Pawel Molle6afec92010-11-26 13:45:43 +0100281 gic_irqs = (gic_irqs + 1) * 32;
282 if (gic_irqs > 1020)
283 gic_irqs = 1020;
Russell Kingf27ecac2005-08-18 21:31:00 +0100284
285 /*
286 * Set all global interrupts to be level triggered, active low.
287 */
Pawel Molle6afec92010-11-26 13:45:43 +0100288 for (i = 32; i < gic_irqs; i += 16)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530289 writel_relaxed(0, base + GIC_DIST_CONFIG + i * 4 / 16);
Russell Kingf27ecac2005-08-18 21:31:00 +0100290
291 /*
292 * Set all global interrupts to this CPU only.
293 */
Pawel Molle6afec92010-11-26 13:45:43 +0100294 for (i = 32; i < gic_irqs; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530295 writel_relaxed(cpumask, base + GIC_DIST_TARGET + i * 4 / 4);
Russell Kingf27ecac2005-08-18 21:31:00 +0100296
297 /*
Russell King9395f6e2010-11-11 23:10:30 +0000298 * Set priority on all global interrupts.
Russell Kingf27ecac2005-08-18 21:31:00 +0100299 */
Pawel Molle6afec92010-11-26 13:45:43 +0100300 for (i = 32; i < gic_irqs; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530301 writel_relaxed(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4);
Russell Kingf27ecac2005-08-18 21:31:00 +0100302
303 /*
Russell King9395f6e2010-11-11 23:10:30 +0000304 * Disable all interrupts. Leave the PPI and SGIs alone
305 * as these enables are banked registers.
Russell Kingf27ecac2005-08-18 21:31:00 +0100306 */
Pawel Molle6afec92010-11-26 13:45:43 +0100307 for (i = 32; i < gic_irqs; i += 32)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530308 writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32);
Russell Kingf27ecac2005-08-18 21:31:00 +0100309
310 /*
Pawel Molle6afec92010-11-26 13:45:43 +0100311 * Limit number of interrupts registered to the platform maximum
312 */
Russell Kingbef8f9e2010-12-04 16:50:58 +0000313 irq_limit = gic->irq_offset + gic_irqs;
Pawel Molle6afec92010-11-26 13:45:43 +0100314 if (WARN_ON(irq_limit > NR_IRQS))
315 irq_limit = NR_IRQS;
316
317 /*
Russell Kingf27ecac2005-08-18 21:31:00 +0100318 * Setup the Linux IRQ subsystem.
319 */
Pawel Molle6afec92010-11-26 13:45:43 +0100320 for (i = irq_start; i < irq_limit; i++) {
Will Deacon1a017532011-02-09 12:01:12 +0000321 irq_set_chip_and_handler(i, &gic_chip, handle_fasteoi_irq);
Thomas Gleixner9323f2612011-03-24 13:29:39 +0100322 irq_set_chip_data(i, gic);
Russell Kingf27ecac2005-08-18 21:31:00 +0100323 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
324 }
325
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530326 writel_relaxed(1, base + GIC_DIST_CTRL);
Russell Kingf27ecac2005-08-18 21:31:00 +0100327}
328
Russell Kingbef8f9e2010-12-04 16:50:58 +0000329static void __cpuinit gic_cpu_init(struct gic_chip_data *gic)
Russell Kingf27ecac2005-08-18 21:31:00 +0100330{
Russell Kingbef8f9e2010-12-04 16:50:58 +0000331 void __iomem *dist_base = gic->dist_base;
332 void __iomem *base = gic->cpu_base;
Russell King9395f6e2010-11-11 23:10:30 +0000333 int i;
334
Russell King9395f6e2010-11-11 23:10:30 +0000335 /*
336 * Deal with the banked PPI and SGI interrupts - disable all
337 * PPI interrupts, ensure all SGI interrupts are enabled.
338 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530339 writel_relaxed(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR);
340 writel_relaxed(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET);
Russell King9395f6e2010-11-11 23:10:30 +0000341
342 /*
343 * Set priority on PPI and SGI interrupts
344 */
345 for (i = 0; i < 32; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530346 writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4);
Russell King9395f6e2010-11-11 23:10:30 +0000347
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530348 writel_relaxed(0xf0, base + GIC_CPU_PRIMASK);
349 writel_relaxed(1, base + GIC_CPU_CTRL);
Russell Kingf27ecac2005-08-18 21:31:00 +0100350}
351
Russell Kingb580b892010-12-04 15:55:14 +0000352void __init gic_init(unsigned int gic_nr, unsigned int irq_start,
353 void __iomem *dist_base, void __iomem *cpu_base)
354{
Russell Kingbef8f9e2010-12-04 16:50:58 +0000355 struct gic_chip_data *gic;
356
357 BUG_ON(gic_nr >= MAX_GIC_NR);
358
359 gic = &gic_data[gic_nr];
360 gic->dist_base = dist_base;
361 gic->cpu_base = cpu_base;
362 gic->irq_offset = (irq_start - 1) & ~31;
363
Russell Kingff2e27a2010-12-04 16:13:29 +0000364 if (gic_nr == 0)
365 gic_cpu_base_addr = cpu_base;
Russell Kingbef8f9e2010-12-04 16:50:58 +0000366
367 gic_dist_init(gic, irq_start);
368 gic_cpu_init(gic);
Russell Kingb580b892010-12-04 15:55:14 +0000369}
370
Russell King38489532010-12-04 16:01:03 +0000371void __cpuinit gic_secondary_init(unsigned int gic_nr)
372{
Russell Kingbef8f9e2010-12-04 16:50:58 +0000373 BUG_ON(gic_nr >= MAX_GIC_NR);
374
375 gic_cpu_init(&gic_data[gic_nr]);
Russell King38489532010-12-04 16:01:03 +0000376}
377
Russell Kingac61d142010-12-06 10:38:14 +0000378void __cpuinit gic_enable_ppi(unsigned int irq)
379{
380 unsigned long flags;
381
382 local_irq_save(flags);
Thomas Gleixnerfdea77b2011-03-24 12:48:54 +0100383 irq_set_status_flags(irq, IRQ_NOPROBE);
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100384 gic_unmask_irq(irq_get_irq_data(irq));
Russell Kingac61d142010-12-06 10:38:14 +0000385 local_irq_restore(flags);
386}
387
Russell Kingf27ecac2005-08-18 21:31:00 +0100388#ifdef CONFIG_SMP
Russell King82668102009-05-17 16:20:18 +0100389void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
Russell Kingf27ecac2005-08-18 21:31:00 +0100390{
Will Deacon267840f2011-08-23 22:20:03 +0100391 int cpu;
392 unsigned long map = 0;
393
394 /* Convert our logical CPU mask into a physical one. */
395 for_each_cpu(cpu, mask)
396 map |= 1 << cpu_logical_map(cpu);
Russell Kingf27ecac2005-08-18 21:31:00 +0100397
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530398 /*
399 * Ensure that stores to Normal memory are visible to the
400 * other CPUs before issuing the IPI.
401 */
402 dsb();
403
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100404 /* this always happens on GIC0 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530405 writel_relaxed(map << 16 | irq, gic_data[0].dist_base + GIC_DIST_SOFTINT);
Russell Kingf27ecac2005-08-18 21:31:00 +0100406}
407#endif