blob: 7790510700e7297b7a6a3b86f4c2740a0b334338 [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>
Rob Herring050113e2011-10-21 17:14:27 -050027#include <linux/err.h>
Arnd Bergmann4f874102011-11-01 00:28:37 +010028#include <linux/module.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010029#include <linux/list.h>
30#include <linux/smp.h>
Colin Cross692c3e252011-02-10 12:54:10 -080031#include <linux/cpu_pm.h>
Catalin Marinasdcb86e82005-08-31 21:45:14 +010032#include <linux/cpumask.h>
Russell Kingfced80c2008-09-06 12:10:45 +010033#include <linux/io.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034#include <linux/syscore_ops.h>
Rob Herring0fc0d942011-09-28 21:27:52 -050035#include <linux/of.h>
36#include <linux/of_address.h>
37#include <linux/of_irq.h>
Rob Herringc383e042011-09-28 21:25:31 -050038#include <linux/irqdomain.h>
Trilok Sonieecb28c2011-07-20 16:24:14 +010039#include <linux/interrupt.h>
40#include <linux/percpu.h>
41#include <linux/slab.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010042
43#include <asm/irq.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010044#include <asm/mach/irq.h>
45#include <asm/hardware/gic.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046#include <asm/system.h>
Trilok Sonieecb28c2011-07-20 16:24:14 +010047#include <asm/localtimer.h>
Russell Kingf27ecac2005-08-18 21:31:00 +010048
Marc Zyngier680392b2011-11-12 16:09:49 +000049union gic_base {
50 void __iomem *common_base;
51 void __percpu __iomem **percpu_base;
52};
53
54struct gic_chip_data {
55 unsigned int irq_offset;
56 union gic_base dist_base;
57 union gic_base cpu_base;
58 unsigned int max_irq;
59#ifdef CONFIG_PM
60 unsigned int wakeup_irqs[32];
61 unsigned int enabled_irqs[32];
62#endif
63#ifdef CONFIG_CPU_PM
64 u32 saved_spi_enable[DIV_ROUND_UP(1020, 32)];
65 u32 saved_spi_conf[DIV_ROUND_UP(1020, 16)];
66 u32 saved_spi_target[DIV_ROUND_UP(1020, 4)];
67 u32 __percpu *saved_ppi_enable;
68 u32 __percpu *saved_ppi_conf;
69#endif
70#ifdef CONFIG_IRQ_DOMAIN
71 struct irq_domain domain;
72#endif
73 unsigned int gic_irqs;
74#ifdef CONFIG_GIC_NON_BANKED
75 void __iomem *(*get_base)(union gic_base *);
76#endif
77};
78
Thomas Gleixner450ea482009-07-03 08:44:46 -050079static DEFINE_RAW_SPINLOCK(irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +010080
Russell Kingff2e27a2010-12-04 16:13:29 +000081/* Address of GIC 0 CPU interface */
Russell Kingbef8f9e2010-12-04 16:50:58 +000082void __iomem *gic_cpu_base_addr __read_mostly;
Russell Kingff2e27a2010-12-04 16:13:29 +000083
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010084/*
85 * Supported arch specific GIC irq extension.
86 * Default make them NULL.
87 */
88struct irq_chip gic_arch_extn = {
Will Deacon1a017532011-02-09 12:01:12 +000089 .irq_eoi = NULL,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010090 .irq_mask = NULL,
91 .irq_unmask = NULL,
92 .irq_retrigger = NULL,
93 .irq_set_type = NULL,
94 .irq_set_wake = NULL,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095 .irq_disable = NULL,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +010096};
97
Catalin Marinasb3a1bde2007-02-14 19:14:56 +010098#ifndef MAX_GIC_NR
99#define MAX_GIC_NR 1
100#endif
101
Russell Kingbef8f9e2010-12-04 16:50:58 +0000102static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100103
Marc Zyngier680392b2011-11-12 16:09:49 +0000104#ifdef CONFIG_GIC_NON_BANKED
105static void __iomem *gic_get_percpu_base(union gic_base *base)
106{
107 return *__this_cpu_ptr(base->percpu_base);
108}
109
110static void __iomem *gic_get_common_base(union gic_base *base)
111{
112 return base->common_base;
113}
114
115static inline void __iomem *gic_data_dist_base(struct gic_chip_data *data)
116{
117 return data->get_base(&data->dist_base);
118}
119
120static inline void __iomem *gic_data_cpu_base(struct gic_chip_data *data)
121{
122 return data->get_base(&data->cpu_base);
123}
124
125static inline void gic_set_base_accessor(struct gic_chip_data *data,
126 void __iomem *(*f)(union gic_base *))
127{
128 data->get_base = f;
129}
130#else
131#define gic_data_dist_base(d) ((d)->dist_base.common_base)
132#define gic_data_cpu_base(d) ((d)->cpu_base.common_base)
133#define gic_set_base_accessor(d,f)
134#endif
135
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100136static inline void __iomem *gic_dist_base(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100137{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100138 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
Marc Zyngier680392b2011-11-12 16:09:49 +0000139 return gic_data_dist_base(gic_data);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100140}
141
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100142static inline void __iomem *gic_cpu_base(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100143{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100144 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
Marc Zyngier680392b2011-11-12 16:09:49 +0000145 return gic_data_cpu_base(gic_data);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100146}
147
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100148static inline unsigned int gic_irq(struct irq_data *d)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100149{
Rob Herringc383e042011-09-28 21:25:31 -0500150 return d->hwirq;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100151}
152
Russell Kingf27ecac2005-08-18 21:31:00 +0100153/*
154 * Routines to acknowledge, disable and enable interrupts
Russell Kingf27ecac2005-08-18 21:31:00 +0100155 */
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100156static void gic_mask_irq(struct irq_data *d)
Russell Kingf27ecac2005-08-18 21:31:00 +0100157{
Rob Herringc383e042011-09-28 21:25:31 -0500158 u32 mask = 1 << (gic_irq(d) % 32);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +0100159
Thomas Gleixner450ea482009-07-03 08:44:46 -0500160 raw_spin_lock(&irq_controller_lock);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530161 writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4);
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100162 if (gic_arch_extn.irq_mask)
163 gic_arch_extn.irq_mask(d);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500164 raw_spin_unlock(&irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +0100165}
166
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100167static void gic_unmask_irq(struct irq_data *d)
Russell Kingf27ecac2005-08-18 21:31:00 +0100168{
Rob Herringc383e042011-09-28 21:25:31 -0500169 u32 mask = 1 << (gic_irq(d) % 32);
Thomas Gleixnerc4bfa282006-07-01 22:32:14 +0100170
Thomas Gleixner450ea482009-07-03 08:44:46 -0500171 raw_spin_lock(&irq_controller_lock);
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100172 if (gic_arch_extn.irq_unmask)
173 gic_arch_extn.irq_unmask(d);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530174 writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500175 raw_spin_unlock(&irq_controller_lock);
Russell Kingf27ecac2005-08-18 21:31:00 +0100176}
177
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178static void gic_disable_irq(struct irq_data *d)
179{
180 if (gic_arch_extn.irq_disable)
181 gic_arch_extn.irq_disable(d);
182}
183
184#ifdef CONFIG_PM
185static int gic_suspend_one(struct gic_chip_data *gic)
186{
187 unsigned int i;
Marc Zyngier680392b2011-11-12 16:09:49 +0000188 void __iomem *base = gic_data_dist_base(gic);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189
190 for (i = 0; i * 32 < gic->max_irq; i++) {
191 gic->enabled_irqs[i]
192 = readl_relaxed(base + GIC_DIST_ENABLE_SET + i * 4);
193 /* disable all of them */
194 writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4);
195 /* enable the wakeup set */
196 writel_relaxed(gic->wakeup_irqs[i],
197 base + GIC_DIST_ENABLE_SET + i * 4);
198 }
199 mb();
200 return 0;
201}
202
203static int gic_suspend(void)
204{
205 int i;
206 for (i = 0; i < MAX_GIC_NR; i++)
207 gic_suspend_one(&gic_data[i]);
208 return 0;
209}
210
211extern int msm_show_resume_irq_mask;
212
213static void gic_show_resume_irq(struct gic_chip_data *gic)
214{
215 unsigned int i;
216 u32 enabled;
217 unsigned long pending[32];
Marc Zyngier680392b2011-11-12 16:09:49 +0000218 void __iomem *base = gic_data_dist_base(gic);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219
220 if (!msm_show_resume_irq_mask)
221 return;
222
Thomas Gleixner450ea482009-07-03 08:44:46 -0500223 raw_spin_lock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224 for (i = 0; i * 32 < gic->max_irq; i++) {
225 enabled = readl_relaxed(base + GIC_DIST_ENABLE_CLEAR + i * 4);
226 pending[i] = readl_relaxed(base + GIC_DIST_PENDING_SET + i * 4);
227 pending[i] &= enabled;
228 }
Thomas Gleixner450ea482009-07-03 08:44:46 -0500229 raw_spin_unlock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230
231 for (i = find_first_bit(pending, gic->max_irq);
232 i < gic->max_irq;
233 i = find_next_bit(pending, gic->max_irq, i+1)) {
234 pr_warning("%s: %d triggered", __func__,
235 i + gic->irq_offset);
236 }
237}
238
239static void gic_resume_one(struct gic_chip_data *gic)
240{
241 unsigned int i;
Marc Zyngier680392b2011-11-12 16:09:49 +0000242 void __iomem *base = gic_data_dist_base(gic);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243
244 gic_show_resume_irq(gic);
245 for (i = 0; i * 32 < gic->max_irq; i++) {
246 /* disable all of them */
247 writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4);
248 /* enable the enabled set */
249 writel_relaxed(gic->enabled_irqs[i],
250 base + GIC_DIST_ENABLE_SET + i * 4);
251 }
252 mb();
253}
254
255static void gic_resume(void)
256{
257 int i;
258 for (i = 0; i < MAX_GIC_NR; i++)
259 gic_resume_one(&gic_data[i]);
260}
261
262static struct syscore_ops gic_syscore_ops = {
263 .suspend = gic_suspend,
264 .resume = gic_resume,
265};
266
267static int __init gic_init_sys(void)
268{
269 register_syscore_ops(&gic_syscore_ops);
270 return 0;
271}
272arch_initcall(gic_init_sys);
273
274#endif
275
Will Deacon1a017532011-02-09 12:01:12 +0000276static void gic_eoi_irq(struct irq_data *d)
277{
278 if (gic_arch_extn.irq_eoi) {
Thomas Gleixner450ea482009-07-03 08:44:46 -0500279 raw_spin_lock(&irq_controller_lock);
Will Deacon1a017532011-02-09 12:01:12 +0000280 gic_arch_extn.irq_eoi(d);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500281 raw_spin_unlock(&irq_controller_lock);
Will Deacon1a017532011-02-09 12:01:12 +0000282 }
283
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530284 writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI);
Will Deacon1a017532011-02-09 12:01:12 +0000285}
286
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100287static int gic_set_type(struct irq_data *d, unsigned int type)
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100288{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100289 void __iomem *base = gic_dist_base(d);
290 unsigned int gicirq = gic_irq(d);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100291 u32 enablemask = 1 << (gicirq % 32);
292 u32 enableoff = (gicirq / 32) * 4;
293 u32 confmask = 0x2 << ((gicirq % 16) * 2);
294 u32 confoff = (gicirq / 16) * 4;
295 bool enabled = false;
296 u32 val;
297
298 /* Interrupt configuration for SGIs can't be changed */
299 if (gicirq < 16)
300 return -EINVAL;
301
302 if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING)
303 return -EINVAL;
304
Thomas Gleixner450ea482009-07-03 08:44:46 -0500305 raw_spin_lock(&irq_controller_lock);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100306
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100307 if (gic_arch_extn.irq_set_type)
308 gic_arch_extn.irq_set_type(d, type);
309
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530310 val = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100311 if (type == IRQ_TYPE_LEVEL_HIGH)
312 val &= ~confmask;
313 else if (type == IRQ_TYPE_EDGE_RISING)
314 val |= confmask;
315
316 /*
317 * As recommended by the spec, disable the interrupt before changing
318 * the configuration
319 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530320 if (readl_relaxed(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) {
321 writel_relaxed(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100322 enabled = true;
323 }
324
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530325 writel_relaxed(val, base + GIC_DIST_CONFIG + confoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100326
327 if (enabled)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530328 writel_relaxed(enablemask, base + GIC_DIST_ENABLE_SET + enableoff);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100329
Thomas Gleixner450ea482009-07-03 08:44:46 -0500330 raw_spin_unlock(&irq_controller_lock);
Rabin Vincent5c0c1f02010-05-28 04:37:38 +0100331
332 return 0;
333}
334
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100335static int gic_retrigger(struct irq_data *d)
336{
337 if (gic_arch_extn.irq_retrigger)
338 return gic_arch_extn.irq_retrigger(d);
339
Abhijeet Dharmapurikar9d44ea02011-10-30 16:47:19 -0700340 /* the retrigger expects 0 for failure */
341 return 0;
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100342}
343
Catalin Marinasa06f5462005-09-30 16:07:05 +0100344#ifdef CONFIG_SMP
Russell Kingc1917892011-01-23 12:12:01 +0000345static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
346 bool force)
Russell Kingf27ecac2005-08-18 21:31:00 +0100347{
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100348 void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3);
Rob Herringc383e042011-09-28 21:25:31 -0500349 unsigned int shift = (gic_irq(d) % 4) * 8;
Russell Kingf3c52e22011-07-21 15:00:57 +0100350 unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask);
Russell Kingc1917892011-01-23 12:12:01 +0000351 u32 val, mask, bit;
352
Russell Kingf3c52e22011-07-21 15:00:57 +0100353 if (cpu >= 8 || cpu >= nr_cpu_ids)
Russell Kingc1917892011-01-23 12:12:01 +0000354 return -EINVAL;
355
356 mask = 0xff << shift;
Will Deacona803a8d2011-08-23 22:20:03 +0100357 bit = 1 << (cpu_logical_map(cpu) + shift);
Russell Kingf27ecac2005-08-18 21:31:00 +0100358
Thomas Gleixner450ea482009-07-03 08:44:46 -0500359 raw_spin_lock(&irq_controller_lock);
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530360 val = readl_relaxed(reg) & ~mask;
361 writel_relaxed(val | bit, reg);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500362 raw_spin_unlock(&irq_controller_lock);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700363
Russell Kingf3c52e22011-07-21 15:00:57 +0100364 return IRQ_SET_MASK_OK;
Russell Kingf27ecac2005-08-18 21:31:00 +0100365}
Catalin Marinasa06f5462005-09-30 16:07:05 +0100366#endif
Russell Kingf27ecac2005-08-18 21:31:00 +0100367
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100368#ifdef CONFIG_PM
369static int gic_set_wake(struct irq_data *d, unsigned int on)
370{
371 int ret = -ENXIO;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700372 unsigned int reg_offset, bit_offset;
373 unsigned int gicirq = gic_irq(d);
374 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
375
376 /* per-cpu interrupts cannot be wakeup interrupts */
377 WARN_ON(gicirq < 32);
378
379 reg_offset = gicirq / 32;
380 bit_offset = gicirq % 32;
381
382 if (on)
383 gic_data->wakeup_irqs[reg_offset] |= 1 << bit_offset;
384 else
385 gic_data->wakeup_irqs[reg_offset] &= ~(1 << bit_offset);
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100386
387 if (gic_arch_extn.irq_set_wake)
388 ret = gic_arch_extn.irq_set_wake(d, on);
389
390 return ret;
391}
392
393#else
Rohit Vaswani550aa1a2011-10-06 21:15:37 -0700394static int gic_set_wake(struct irq_data *d, unsigned int on)
395{
396 return 0;
397}
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100398#endif
399
Russell King0f347bb2007-05-17 10:11:34 +0100400static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100401{
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100402 struct gic_chip_data *chip_data = irq_get_handler_data(irq);
403 struct irq_chip *chip = irq_get_chip(irq);
Russell King0f347bb2007-05-17 10:11:34 +0100404 unsigned int cascade_irq, gic_irq;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100405 unsigned long status;
406
Will Deacon1a017532011-02-09 12:01:12 +0000407 chained_irq_enter(chip, desc);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100408
Thomas Gleixner450ea482009-07-03 08:44:46 -0500409 raw_spin_lock(&irq_controller_lock);
Marc Zyngier680392b2011-11-12 16:09:49 +0000410 status = readl_relaxed(gic_data_cpu_base(chip_data) + GIC_CPU_INTACK);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500411 raw_spin_unlock(&irq_controller_lock);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100412
Russell King0f347bb2007-05-17 10:11:34 +0100413 gic_irq = (status & 0x3ff);
414 if (gic_irq == 1023)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100415 goto out;
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100416
Rob Herringc383e042011-09-28 21:25:31 -0500417 cascade_irq = irq_domain_to_irq(&chip_data->domain, gic_irq);
Russell King0f347bb2007-05-17 10:11:34 +0100418 if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS))
419 do_bad_IRQ(cascade_irq, desc);
420 else
421 generic_handle_irq(cascade_irq);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100422
423 out:
Will Deacon1a017532011-02-09 12:01:12 +0000424 chained_irq_exit(chip, desc);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100425}
426
David Brownell38c677c2006-08-01 22:26:25 +0100427static struct irq_chip gic_chip = {
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100428 .name = "GIC",
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100429 .irq_mask = gic_mask_irq,
430 .irq_unmask = gic_unmask_irq,
Will Deacon1a017532011-02-09 12:01:12 +0000431 .irq_eoi = gic_eoi_irq,
Lennert Buytenhek7d1f4282010-11-29 10:18:20 +0100432 .irq_set_type = gic_set_type,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100433 .irq_retrigger = gic_retrigger,
Russell Kingf27ecac2005-08-18 21:31:00 +0100434#ifdef CONFIG_SMP
Russell Kingc1917892011-01-23 12:12:01 +0000435 .irq_set_affinity = gic_set_affinity,
Russell Kingf27ecac2005-08-18 21:31:00 +0100436#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437 .irq_disable = gic_disable_irq,
Santosh Shilimkard7ed36a2011-03-02 08:03:22 +0100438 .irq_set_wake = gic_set_wake,
Russell Kingf27ecac2005-08-18 21:31:00 +0100439};
440
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100441void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
442{
443 if (gic_nr >= MAX_GIC_NR)
444 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100445 if (irq_set_handler_data(irq, &gic_data[gic_nr]) != 0)
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100446 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100447 irq_set_chained_handler(irq, gic_handle_cascade_irq);
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100448}
449
Rob Herringc383e042011-09-28 21:25:31 -0500450static void __init gic_dist_init(struct gic_chip_data *gic)
Russell Kingf27ecac2005-08-18 21:31:00 +0100451{
Rob Herringc383e042011-09-28 21:25:31 -0500452 unsigned int i, irq;
Will Deacona803a8d2011-08-23 22:20:03 +0100453 u32 cpumask;
Rob Herringc383e042011-09-28 21:25:31 -0500454 unsigned int gic_irqs = gic->gic_irqs;
455 struct irq_domain *domain = &gic->domain;
Marc Zyngier680392b2011-11-12 16:09:49 +0000456 void __iomem *base = gic_data_dist_base(gic);
Will Deacona803a8d2011-08-23 22:20:03 +0100457 u32 cpu = 0;
Russell Kingf27ecac2005-08-18 21:31:00 +0100458
Will Deacona803a8d2011-08-23 22:20:03 +0100459#ifdef CONFIG_SMP
460 cpu = cpu_logical_map(smp_processor_id());
461#endif
462
463 cpumask = 1 << cpu;
Russell Kingf27ecac2005-08-18 21:31:00 +0100464 cpumask |= cpumask << 8;
465 cpumask |= cpumask << 16;
466
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530467 writel_relaxed(0, base + GIC_DIST_CTRL);
Russell Kingf27ecac2005-08-18 21:31:00 +0100468
469 /*
Russell Kingf27ecac2005-08-18 21:31:00 +0100470 * Set all global interrupts to be level triggered, active low.
471 */
Pawel Molle6afec92010-11-26 13:45:43 +0100472 for (i = 32; i < gic_irqs; i += 16)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530473 writel_relaxed(0, base + GIC_DIST_CONFIG + i * 4 / 16);
Russell Kingf27ecac2005-08-18 21:31:00 +0100474
475 /*
476 * Set all global interrupts to this CPU only.
477 */
Pawel Molle6afec92010-11-26 13:45:43 +0100478 for (i = 32; i < gic_irqs; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530479 writel_relaxed(cpumask, base + GIC_DIST_TARGET + i * 4 / 4);
Russell Kingf27ecac2005-08-18 21:31:00 +0100480
481 /*
Russell King9395f6e2010-11-11 23:10:30 +0000482 * Set priority on all global interrupts.
Russell Kingf27ecac2005-08-18 21:31:00 +0100483 */
Pawel Molle6afec92010-11-26 13:45:43 +0100484 for (i = 32; i < gic_irqs; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530485 writel_relaxed(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4);
Russell Kingf27ecac2005-08-18 21:31:00 +0100486
487 /*
Russell King9395f6e2010-11-11 23:10:30 +0000488 * Disable all interrupts. Leave the PPI and SGIs alone
489 * as these enables are banked registers.
Russell Kingf27ecac2005-08-18 21:31:00 +0100490 */
Pawel Molle6afec92010-11-26 13:45:43 +0100491 for (i = 32; i < gic_irqs; i += 32)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530492 writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32);
Russell Kingf27ecac2005-08-18 21:31:00 +0100493
494 /*
495 * Setup the Linux IRQ subsystem.
496 */
Rob Herringc383e042011-09-28 21:25:31 -0500497 irq_domain_for_each_irq(domain, i, irq) {
498 if (i < 32) {
499 irq_set_percpu_devid(irq);
500 irq_set_chip_and_handler(irq, &gic_chip,
501 handle_percpu_devid_irq);
502 set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN);
503 } else {
504 irq_set_chip_and_handler(irq, &gic_chip,
505 handle_fasteoi_irq);
506 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
507 }
508 irq_set_chip_data(irq, gic);
Russell Kingf27ecac2005-08-18 21:31:00 +0100509 }
510
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700511 gic->max_irq = gic_irqs;
512
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530513 writel_relaxed(1, base + GIC_DIST_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700514 mb();
Russell Kingf27ecac2005-08-18 21:31:00 +0100515}
516
Russell Kingbef8f9e2010-12-04 16:50:58 +0000517static void __cpuinit gic_cpu_init(struct gic_chip_data *gic)
Russell Kingf27ecac2005-08-18 21:31:00 +0100518{
Marc Zyngier680392b2011-11-12 16:09:49 +0000519 void __iomem *dist_base = gic_data_dist_base(gic);
520 void __iomem *base = gic_data_cpu_base(gic);
Russell King9395f6e2010-11-11 23:10:30 +0000521 int i;
522
Russell King9395f6e2010-11-11 23:10:30 +0000523 /*
524 * Deal with the banked PPI and SGI interrupts - disable all
525 * PPI interrupts, ensure all SGI interrupts are enabled.
526 */
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530527 writel_relaxed(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR);
528 writel_relaxed(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET);
Russell King9395f6e2010-11-11 23:10:30 +0000529
530 /*
531 * Set priority on PPI and SGI interrupts
532 */
533 for (i = 0; i < 32; i += 4)
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530534 writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4);
Russell King9395f6e2010-11-11 23:10:30 +0000535
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530536 writel_relaxed(0xf0, base + GIC_CPU_PRIMASK);
537 writel_relaxed(1, base + GIC_CPU_CTRL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700538 mb();
Russell Kingf27ecac2005-08-18 21:31:00 +0100539}
540
Colin Cross692c3e252011-02-10 12:54:10 -0800541#ifdef CONFIG_CPU_PM
542/*
543 * Saves the GIC distributor registers during suspend or idle. Must be called
544 * with interrupts disabled but before powering down the GIC. After calling
545 * this function, no interrupts will be delivered by the GIC, and another
546 * platform-specific wakeup source must be enabled.
547 */
548static void gic_dist_save(unsigned int gic_nr)
549{
550 unsigned int gic_irqs;
551 void __iomem *dist_base;
552 int i;
553
554 if (gic_nr >= MAX_GIC_NR)
555 BUG();
556
557 gic_irqs = gic_data[gic_nr].gic_irqs;
Marc Zyngier680392b2011-11-12 16:09:49 +0000558 dist_base = gic_data_dist_base(&gic_data[gic_nr]);
Colin Cross692c3e252011-02-10 12:54:10 -0800559
560 if (!dist_base)
561 return;
562
563 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++)
564 gic_data[gic_nr].saved_spi_conf[i] =
565 readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4);
566
567 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
568 gic_data[gic_nr].saved_spi_target[i] =
569 readl_relaxed(dist_base + GIC_DIST_TARGET + i * 4);
570
571 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++)
572 gic_data[gic_nr].saved_spi_enable[i] =
573 readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
574}
575
576/*
577 * Restores the GIC distributor registers during resume or when coming out of
578 * idle. Must be called before enabling interrupts. If a level interrupt
579 * that occured while the GIC was suspended is still present, it will be
580 * handled normally, but any edge interrupts that occured will not be seen by
581 * the GIC and need to be handled by the platform-specific wakeup source.
582 */
583static void gic_dist_restore(unsigned int gic_nr)
584{
585 unsigned int gic_irqs;
586 unsigned int i;
587 void __iomem *dist_base;
588
589 if (gic_nr >= MAX_GIC_NR)
590 BUG();
591
592 gic_irqs = gic_data[gic_nr].gic_irqs;
Marc Zyngier680392b2011-11-12 16:09:49 +0000593 dist_base = gic_data_dist_base(&gic_data[gic_nr]);
Colin Cross692c3e252011-02-10 12:54:10 -0800594
595 if (!dist_base)
596 return;
597
598 writel_relaxed(0, dist_base + GIC_DIST_CTRL);
599
600 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++)
601 writel_relaxed(gic_data[gic_nr].saved_spi_conf[i],
602 dist_base + GIC_DIST_CONFIG + i * 4);
603
604 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
605 writel_relaxed(0xa0a0a0a0,
606 dist_base + GIC_DIST_PRI + i * 4);
607
608 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
609 writel_relaxed(gic_data[gic_nr].saved_spi_target[i],
610 dist_base + GIC_DIST_TARGET + i * 4);
611
612 for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++)
613 writel_relaxed(gic_data[gic_nr].saved_spi_enable[i],
614 dist_base + GIC_DIST_ENABLE_SET + i * 4);
615
616 writel_relaxed(1, dist_base + GIC_DIST_CTRL);
617}
618
619static void gic_cpu_save(unsigned int gic_nr)
620{
621 int i;
622 u32 *ptr;
623 void __iomem *dist_base;
624 void __iomem *cpu_base;
625
626 if (gic_nr >= MAX_GIC_NR)
627 BUG();
628
Marc Zyngier680392b2011-11-12 16:09:49 +0000629 dist_base = gic_data_dist_base(&gic_data[gic_nr]);
630 cpu_base = gic_data_cpu_base(&gic_data[gic_nr]);
Colin Cross692c3e252011-02-10 12:54:10 -0800631
632 if (!dist_base || !cpu_base)
633 return;
634
635 ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable);
636 for (i = 0; i < DIV_ROUND_UP(32, 32); i++)
637 ptr[i] = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
638
639 ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf);
640 for (i = 0; i < DIV_ROUND_UP(32, 16); i++)
641 ptr[i] = readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4);
642
643}
644
645static void gic_cpu_restore(unsigned int gic_nr)
646{
647 int i;
648 u32 *ptr;
649 void __iomem *dist_base;
650 void __iomem *cpu_base;
651
652 if (gic_nr >= MAX_GIC_NR)
653 BUG();
654
Marc Zyngier680392b2011-11-12 16:09:49 +0000655 dist_base = gic_data_dist_base(&gic_data[gic_nr]);
656 cpu_base = gic_data_cpu_base(&gic_data[gic_nr]);
Colin Cross692c3e252011-02-10 12:54:10 -0800657
658 if (!dist_base || !cpu_base)
659 return;
660
661 ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable);
662 for (i = 0; i < DIV_ROUND_UP(32, 32); i++)
663 writel_relaxed(ptr[i], dist_base + GIC_DIST_ENABLE_SET + i * 4);
664
665 ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf);
666 for (i = 0; i < DIV_ROUND_UP(32, 16); i++)
667 writel_relaxed(ptr[i], dist_base + GIC_DIST_CONFIG + i * 4);
668
669 for (i = 0; i < DIV_ROUND_UP(32, 4); i++)
670 writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4);
671
672 writel_relaxed(0xf0, cpu_base + GIC_CPU_PRIMASK);
673 writel_relaxed(1, cpu_base + GIC_CPU_CTRL);
674}
675
676static int gic_notifier(struct notifier_block *self, unsigned long cmd, void *v)
677{
678 int i;
679
680 for (i = 0; i < MAX_GIC_NR; i++) {
Marc Zyngier680392b2011-11-12 16:09:49 +0000681#ifdef CONFIG_GIC_NON_BANKED
682 /* Skip over unused GICs */
683 if (!gic_data[i].get_base)
684 continue;
685#endif
Colin Cross692c3e252011-02-10 12:54:10 -0800686 switch (cmd) {
687 case CPU_PM_ENTER:
688 gic_cpu_save(i);
689 break;
690 case CPU_PM_ENTER_FAILED:
691 case CPU_PM_EXIT:
692 gic_cpu_restore(i);
693 break;
694 case CPU_CLUSTER_PM_ENTER:
695 gic_dist_save(i);
696 break;
697 case CPU_CLUSTER_PM_ENTER_FAILED:
698 case CPU_CLUSTER_PM_EXIT:
699 gic_dist_restore(i);
700 break;
701 }
702 }
703
704 return NOTIFY_OK;
705}
706
707static struct notifier_block gic_notifier_block = {
708 .notifier_call = gic_notifier,
709};
710
711static void __init gic_pm_init(struct gic_chip_data *gic)
712{
713 gic->saved_ppi_enable = __alloc_percpu(DIV_ROUND_UP(32, 32) * 4,
714 sizeof(u32));
715 BUG_ON(!gic->saved_ppi_enable);
716
717 gic->saved_ppi_conf = __alloc_percpu(DIV_ROUND_UP(32, 16) * 4,
718 sizeof(u32));
719 BUG_ON(!gic->saved_ppi_conf);
720
721 cpu_pm_register_notifier(&gic_notifier_block);
722}
723#else
724static void __init gic_pm_init(struct gic_chip_data *gic)
725{
726}
727#endif
728
Rob Herring0fc0d942011-09-28 21:27:52 -0500729#ifdef CONFIG_OF
730static int gic_irq_domain_dt_translate(struct irq_domain *d,
731 struct device_node *controller,
732 const u32 *intspec, unsigned int intsize,
733 unsigned long *out_hwirq, unsigned int *out_type)
734{
735 if (d->of_node != controller)
736 return -EINVAL;
737 if (intsize < 3)
738 return -EINVAL;
739
740 /* Get the interrupt number and add 16 to skip over SGIs */
741 *out_hwirq = intspec[1] + 16;
742
743 /* For SPIs, we need to add 16 more to get the GIC irq ID number */
744 if (!intspec[0])
745 *out_hwirq += 16;
746
747 *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK;
748 return 0;
749}
750#endif
751
Rob Herringc383e042011-09-28 21:25:31 -0500752const struct irq_domain_ops gic_irq_domain_ops = {
Rob Herring0fc0d942011-09-28 21:27:52 -0500753#ifdef CONFIG_OF
754 .dt_translate = gic_irq_domain_dt_translate,
755#endif
Rob Herringc383e042011-09-28 21:25:31 -0500756};
757
Marc Zyngier680392b2011-11-12 16:09:49 +0000758void __init gic_init_bases(unsigned int gic_nr, int irq_start,
759 void __iomem *dist_base, void __iomem *cpu_base,
760 u32 percpu_offset)
Russell Kingb580b892010-12-04 15:55:14 +0000761{
Russell Kingbef8f9e2010-12-04 16:50:58 +0000762 struct gic_chip_data *gic;
Rob Herringc383e042011-09-28 21:25:31 -0500763 struct irq_domain *domain;
764 int gic_irqs;
Russell Kingbef8f9e2010-12-04 16:50:58 +0000765
766 BUG_ON(gic_nr >= MAX_GIC_NR);
767
768 gic = &gic_data[gic_nr];
Rob Herringc383e042011-09-28 21:25:31 -0500769 domain = &gic->domain;
Marc Zyngier680392b2011-11-12 16:09:49 +0000770#ifdef CONFIG_GIC_NON_BANKED
771 if (percpu_offset) { /* Frankein-GIC without banked registers... */
772 unsigned int cpu;
773
774 gic->dist_base.percpu_base = alloc_percpu(void __iomem *);
775 gic->cpu_base.percpu_base = alloc_percpu(void __iomem *);
776 if (WARN_ON(!gic->dist_base.percpu_base ||
777 !gic->cpu_base.percpu_base)) {
778 free_percpu(gic->dist_base.percpu_base);
779 free_percpu(gic->cpu_base.percpu_base);
780 return;
781 }
782
783 for_each_possible_cpu(cpu) {
784 unsigned long offset = percpu_offset * cpu_logical_map(cpu);
785 *per_cpu_ptr(gic->dist_base.percpu_base, cpu) = dist_base + offset;
786 *per_cpu_ptr(gic->cpu_base.percpu_base, cpu) = cpu_base + offset;
787 }
788
789 gic_set_base_accessor(gic, gic_get_percpu_base);
790 } else
791#endif
792 { /* Normal, sane GIC... */
793 WARN(percpu_offset,
794 "GIC_NON_BANKED not enabled, ignoring %08x offset!",
795 percpu_offset);
796 gic->dist_base.common_base = dist_base;
797 gic->cpu_base.common_base = cpu_base;
798 gic_set_base_accessor(gic, gic_get_common_base);
799 }
Russell Kingbef8f9e2010-12-04 16:50:58 +0000800
Rob Herringc383e042011-09-28 21:25:31 -0500801 /*
802 * For primary GICs, skip over SGIs.
803 * For secondary GICs, skip over PPIs, too.
804 */
805 if (gic_nr == 0) {
Russell Kingff2e27a2010-12-04 16:13:29 +0000806 gic_cpu_base_addr = cpu_base;
Rob Herringc383e042011-09-28 21:25:31 -0500807 domain->hwirq_base = 16;
Rob Herring050113e2011-10-21 17:14:27 -0500808 if (irq_start > 0)
809 irq_start = (irq_start & ~31) + 16;
Rob Herringc383e042011-09-28 21:25:31 -0500810 } else
811 domain->hwirq_base = 32;
812
813 /*
814 * Find out how many interrupts are supported.
815 * The GIC only supports up to 1020 interrupt sources.
816 */
Marc Zyngier680392b2011-11-12 16:09:49 +0000817 gic_irqs = readl_relaxed(gic_data_dist_base(gic) + GIC_DIST_CTR) & 0x1f;
Rob Herringc383e042011-09-28 21:25:31 -0500818 gic_irqs = (gic_irqs + 1) * 32;
819 if (gic_irqs > 1020)
820 gic_irqs = 1020;
821 gic->gic_irqs = gic_irqs;
822
823 domain->nr_irq = gic_irqs - domain->hwirq_base;
Rob Herring050113e2011-10-21 17:14:27 -0500824 domain->irq_base = irq_alloc_descs(irq_start, 16, domain->nr_irq,
Rob Herringc383e042011-09-28 21:25:31 -0500825 numa_node_id());
Rob Herring050113e2011-10-21 17:14:27 -0500826 if (IS_ERR_VALUE(domain->irq_base)) {
827 WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
828 irq_start);
829 domain->irq_base = irq_start;
830 }
Rob Herringc383e042011-09-28 21:25:31 -0500831 domain->priv = gic;
832 domain->ops = &gic_irq_domain_ops;
833 irq_domain_add(domain);
Russell Kingbef8f9e2010-12-04 16:50:58 +0000834
Colin Cross692c3e252011-02-10 12:54:10 -0800835 gic_chip.flags |= gic_arch_extn.flags;
Rob Herringc383e042011-09-28 21:25:31 -0500836 gic_dist_init(gic);
Russell Kingbef8f9e2010-12-04 16:50:58 +0000837 gic_cpu_init(gic);
Colin Cross692c3e252011-02-10 12:54:10 -0800838 gic_pm_init(gic);
Russell Kingb580b892010-12-04 15:55:14 +0000839}
840
Russell King38489532010-12-04 16:01:03 +0000841void __cpuinit gic_secondary_init(unsigned int gic_nr)
842{
Russell Kingbef8f9e2010-12-04 16:50:58 +0000843 BUG_ON(gic_nr >= MAX_GIC_NR);
844
845 gic_cpu_init(&gic_data[gic_nr]);
Russell King38489532010-12-04 16:01:03 +0000846}
847
Russell Kingf27ecac2005-08-18 21:31:00 +0100848#ifdef CONFIG_SMP
Russell King82668102009-05-17 16:20:18 +0100849void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
Russell Kingf27ecac2005-08-18 21:31:00 +0100850{
Will Deacona803a8d2011-08-23 22:20:03 +0100851 int cpu;
852 unsigned long map = 0;
853
854 /* Convert our logical CPU mask into a physical one. */
855 for_each_cpu(cpu, mask)
856 map |= 1 << cpu_logical_map(cpu);
Russell Kingf27ecac2005-08-18 21:31:00 +0100857
Santosh Shilimkar6ac77e42011-03-28 19:27:46 +0530858 /*
859 * Ensure that stores to Normal memory are visible to the
860 * other CPUs before issuing the IPI.
861 */
862 dsb();
863
Catalin Marinasb3a1bde2007-02-14 19:14:56 +0100864 /* this always happens on GIC0 */
Marc Zyngier680392b2011-11-12 16:09:49 +0000865 writel_relaxed(map << 16 | irq, gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 mb();
Russell Kingf27ecac2005-08-18 21:31:00 +0100867}
868#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700869
870/* before calling this function the interrupts should be disabled
871 * and the irq must be disabled at gic to avoid spurious interrupts */
872bool gic_is_spi_pending(unsigned int irq)
873{
874 struct irq_data *d = irq_get_irq_data(irq);
875 struct gic_chip_data *gic_data = &gic_data[0];
876 u32 mask, val;
877
878 WARN_ON(!irqs_disabled());
Thomas Gleixner450ea482009-07-03 08:44:46 -0500879 raw_spin_lock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 mask = 1 << (gic_irq(d) % 32);
881 val = readl(gic_dist_base(d) +
882 GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
883 /* warn if the interrupt is enabled */
884 WARN_ON(val & mask);
885 val = readl(gic_dist_base(d) +
886 GIC_DIST_PENDING_SET + (gic_irq(d) / 32) * 4);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500887 raw_spin_unlock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888 return (bool) (val & mask);
889}
890
891/* before calling this function the interrupts should be disabled
892 * and the irq must be disabled at gic to avoid spurious interrupts */
893void gic_clear_spi_pending(unsigned int irq)
894{
895 struct gic_chip_data *gic_data = &gic_data[0];
896 struct irq_data *d = irq_get_irq_data(irq);
897
898 u32 mask, val;
899 WARN_ON(!irqs_disabled());
Thomas Gleixner450ea482009-07-03 08:44:46 -0500900 raw_spin_lock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 mask = 1 << (gic_irq(d) % 32);
902 val = readl(gic_dist_base(d) +
903 GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
904 /* warn if the interrupt is enabled */
905 WARN_ON(val & mask);
906 writel(mask, gic_dist_base(d) +
907 GIC_DIST_PENDING_CLEAR + (gic_irq(d) / 32) * 4);
Thomas Gleixner450ea482009-07-03 08:44:46 -0500908 raw_spin_unlock(&irq_controller_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909}
Rob Herring0fc0d942011-09-28 21:27:52 -0500910#ifdef CONFIG_OF
911static int gic_cnt __initdata = 0;
912
913int __init gic_of_init(struct device_node *node, struct device_node *parent)
914{
915 void __iomem *cpu_base;
916 void __iomem *dist_base;
Marc Zyngier680392b2011-11-12 16:09:49 +0000917 u32 percpu_offset;
Rob Herring0fc0d942011-09-28 21:27:52 -0500918 int irq;
919 struct irq_domain *domain = &gic_data[gic_cnt].domain;
920
921 if (WARN_ON(!node))
922 return -ENODEV;
923
924 dist_base = of_iomap(node, 0);
925 WARN(!dist_base, "unable to map gic dist registers\n");
926
927 cpu_base = of_iomap(node, 1);
928 WARN(!cpu_base, "unable to map gic cpu registers\n");
929
Marc Zyngier680392b2011-11-12 16:09:49 +0000930 if (of_property_read_u32(node, "cpu-offset", &percpu_offset))
931 percpu_offset = 0;
932
Rob Herring0fc0d942011-09-28 21:27:52 -0500933 domain->of_node = of_node_get(node);
934
Marc Zyngier680392b2011-11-12 16:09:49 +0000935 gic_init_bases(gic_cnt, -1, dist_base, cpu_base, percpu_offset);
Rob Herring0fc0d942011-09-28 21:27:52 -0500936
937 if (parent) {
938 irq = irq_of_parse_and_map(node, 0);
939 gic_cascade_irq(gic_cnt, irq);
940 }
941 gic_cnt++;
942 return 0;
943}
944#endif