blob: eaab40ef6c5393b9601922d2135f60dfce4647f1 [file] [log] [blame]
Russell Kingfa0fe482006-01-13 21:30:48 +00001/*
2 * linux/arch/arm/common/vic.c
3 *
4 * Copyright (C) 1999 - 2003 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
Hartley Sweetenbb06b732010-01-12 19:09:12 +010021
Jamie Ilesf9b28cc2011-09-27 11:00:46 +010022#include <linux/export.h>
Russell Kingfa0fe482006-01-13 21:30:48 +000023#include <linux/init.h>
24#include <linux/list.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Jamie Ilesf9b28cc2011-09-27 11:00:46 +010026#include <linux/irqdomain.h>
27#include <linux/of.h>
28#include <linux/of_address.h>
29#include <linux/of_irq.h>
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +020030#include <linux/syscore_ops.h>
Linus Walleij59fcf482009-09-14 12:25:34 +010031#include <linux/device.h>
Linus Walleijf17a1f02009-08-04 01:01:02 +010032#include <linux/amba/bus.h>
Russell Kingfa0fe482006-01-13 21:30:48 +000033
Jamie Iles15583682011-09-28 09:40:11 +010034#include <asm/exception.h>
Russell Kingfa0fe482006-01-13 21:30:48 +000035#include <asm/mach/irq.h>
36#include <asm/hardware/vic.h>
37
Rob Herringcf21af52012-11-06 13:14:26 -060038#define VIC_IRQ_STATUS 0x00
39#define VIC_FIQ_STATUS 0x04
40#define VIC_INT_SELECT 0x0c /* 1 = FIQ, 0 = IRQ */
41#define VIC_INT_SOFT 0x18
42#define VIC_INT_SOFT_CLEAR 0x1c
43#define VIC_PROTECT 0x20
44#define VIC_PL190_VECT_ADDR 0x30 /* PL190 only */
45#define VIC_PL190_DEF_VECT_ADDR 0x34 /* PL190 only */
46
47#define VIC_VECT_ADDR0 0x100 /* 0 to 15 (0..31 PL192) */
48#define VIC_VECT_CNTL0 0x200 /* 0 to 15 (0..31 PL192) */
49#define VIC_ITCR 0x300 /* VIC test control register */
50
51#define VIC_VECT_CNTL_ENABLE (1 << 5)
52
53#define VIC_PL192_VECT_ADDR 0xF00
54
Ben Dooksc07f87f2009-03-24 15:30:07 +000055/**
56 * struct vic_device - VIC PM device
Ben Dooksc07f87f2009-03-24 15:30:07 +000057 * @irq: The IRQ number for the base of the VIC.
58 * @base: The register base for the VIC.
Linus Walleijce94df92012-04-20 08:02:36 +010059 * @valid_sources: A bitmask of valid interrupts
Ben Dooksc07f87f2009-03-24 15:30:07 +000060 * @resume_sources: A bitmask of interrupts for resume.
61 * @resume_irqs: The IRQs enabled for resume.
62 * @int_select: Save for VIC_INT_SELECT.
63 * @int_enable: Save for VIC_INT_ENABLE.
64 * @soft_int: Save for VIC_INT_SOFT.
65 * @protect: Save for VIC_PROTECT.
Jamie Ilesf9b28cc2011-09-27 11:00:46 +010066 * @domain: The IRQ domain for the VIC.
Ben Dooksc07f87f2009-03-24 15:30:07 +000067 */
68struct vic_device {
Ben Dooksc07f87f2009-03-24 15:30:07 +000069 void __iomem *base;
70 int irq;
Linus Walleijce94df92012-04-20 08:02:36 +010071 u32 valid_sources;
Ben Dooksc07f87f2009-03-24 15:30:07 +000072 u32 resume_sources;
73 u32 resume_irqs;
74 u32 int_select;
75 u32 int_enable;
76 u32 soft_int;
77 u32 protect;
Grant Likely75294952012-02-14 14:06:57 -070078 struct irq_domain *domain;
Ben Dooksc07f87f2009-03-24 15:30:07 +000079};
80
81/* we cannot allocate memory when VICs are initially registered */
82static struct vic_device vic_devices[CONFIG_ARM_VIC_NR];
83
Hartley Sweetenbb06b732010-01-12 19:09:12 +010084static int vic_id;
Ben Dooksc07f87f2009-03-24 15:30:07 +000085
Hartley Sweetenbb06b732010-01-12 19:09:12 +010086/**
87 * vic_init2 - common initialisation code
88 * @base: Base of the VIC.
89 *
Uwe Kleine-Königb5950762010-11-01 15:38:34 -040090 * Common initialisation code for registration
Hartley Sweetenbb06b732010-01-12 19:09:12 +010091 * and resume.
92*/
93static void vic_init2(void __iomem *base)
94{
95 int i;
Ben Dooksc07f87f2009-03-24 15:30:07 +000096
Hartley Sweetenbb06b732010-01-12 19:09:12 +010097 for (i = 0; i < 16; i++) {
98 void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4);
99 writel(VIC_VECT_CNTL_ENABLE | i, reg);
100 }
101
102 writel(32, base + VIC_PL190_DEF_VECT_ADDR);
103}
104
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200105#ifdef CONFIG_PM
106static void resume_one_vic(struct vic_device *vic)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000107{
Ben Dooksc07f87f2009-03-24 15:30:07 +0000108 void __iomem *base = vic->base;
109
110 printk(KERN_DEBUG "%s: resuming vic at %p\n", __func__, base);
111
112 /* re-initialise static settings */
113 vic_init2(base);
114
115 writel(vic->int_select, base + VIC_INT_SELECT);
116 writel(vic->protect, base + VIC_PROTECT);
117
118 /* set the enabled ints and then clear the non-enabled */
119 writel(vic->int_enable, base + VIC_INT_ENABLE);
120 writel(~vic->int_enable, base + VIC_INT_ENABLE_CLEAR);
121
122 /* and the same for the soft-int register */
123
124 writel(vic->soft_int, base + VIC_INT_SOFT);
125 writel(~vic->soft_int, base + VIC_INT_SOFT_CLEAR);
Ben Dooksc07f87f2009-03-24 15:30:07 +0000126}
127
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200128static void vic_resume(void)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000129{
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200130 int id;
131
132 for (id = vic_id - 1; id >= 0; id--)
133 resume_one_vic(vic_devices + id);
134}
135
136static void suspend_one_vic(struct vic_device *vic)
137{
Ben Dooksc07f87f2009-03-24 15:30:07 +0000138 void __iomem *base = vic->base;
139
140 printk(KERN_DEBUG "%s: suspending vic at %p\n", __func__, base);
141
142 vic->int_select = readl(base + VIC_INT_SELECT);
143 vic->int_enable = readl(base + VIC_INT_ENABLE);
144 vic->soft_int = readl(base + VIC_INT_SOFT);
145 vic->protect = readl(base + VIC_PROTECT);
146
147 /* set the interrupts (if any) that are used for
148 * resuming the system */
149
150 writel(vic->resume_irqs, base + VIC_INT_ENABLE);
151 writel(~vic->resume_irqs, base + VIC_INT_ENABLE_CLEAR);
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200152}
153
154static int vic_suspend(void)
155{
156 int id;
157
158 for (id = 0; id < vic_id; id++)
159 suspend_one_vic(vic_devices + id);
Ben Dooksc07f87f2009-03-24 15:30:07 +0000160
161 return 0;
162}
163
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200164struct syscore_ops vic_syscore_ops = {
165 .suspend = vic_suspend,
166 .resume = vic_resume,
Ben Dooksc07f87f2009-03-24 15:30:07 +0000167};
168
169/**
Ben Dooksc07f87f2009-03-24 15:30:07 +0000170 * vic_pm_init - initicall to register VIC pm
171 *
172 * This is called via late_initcall() to register
173 * the resources for the VICs due to the early
174 * nature of the VIC's registration.
175*/
176static int __init vic_pm_init(void)
177{
Rafael J. Wysocki328f5cc2011-04-22 22:02:33 +0200178 if (vic_id > 0)
179 register_syscore_ops(&vic_syscore_ops);
Ben Dooksc07f87f2009-03-24 15:30:07 +0000180
181 return 0;
182}
Ben Dooksc07f87f2009-03-24 15:30:07 +0000183late_initcall(vic_pm_init);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100184#endif /* CONFIG_PM */
Ben Dooksc07f87f2009-03-24 15:30:07 +0000185
Linus Walleijce94df92012-04-20 08:02:36 +0100186static struct irq_chip vic_chip;
187
188static int vic_irqdomain_map(struct irq_domain *d, unsigned int irq,
189 irq_hw_number_t hwirq)
190{
191 struct vic_device *v = d->host_data;
192
193 /* Skip invalid IRQs, only register handlers for the real ones */
194 if (!(v->valid_sources & (1 << hwirq)))
195 return -ENOTSUPP;
196 irq_set_chip_and_handler(irq, &vic_chip, handle_level_irq);
197 irq_set_chip_data(irq, v->base);
198 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
199 return 0;
200}
201
202static struct irq_domain_ops vic_irqdomain_ops = {
203 .map = vic_irqdomain_map,
204 .xlate = irq_domain_xlate_onetwocell,
205};
206
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100207/**
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100208 * vic_register() - Register a VIC.
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100209 * @base: The base address of the VIC.
210 * @irq: The base IRQ for the VIC.
Linus Walleijfa943be2012-04-20 08:02:03 +0100211 * @valid_sources: bitmask of valid interrupts
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100212 * @resume_sources: bitmask of interrupts allowed for resume sources.
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100213 * @node: The device tree node associated with the VIC.
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100214 *
215 * Register the VIC with the system device tree so that it can be notified
216 * of suspend and resume requests and ensure that the correct actions are
217 * taken to re-instate the settings on resume.
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100218 *
219 * This also configures the IRQ domain for the VIC.
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100220 */
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100221static void __init vic_register(void __iomem *base, unsigned int irq,
Linus Walleijfa943be2012-04-20 08:02:03 +0100222 u32 valid_sources, u32 resume_sources,
223 struct device_node *node)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100224{
225 struct vic_device *v;
Linus Walleij5ced33b2012-12-26 01:39:16 +0100226 int i;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100227
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100228 if (vic_id >= ARRAY_SIZE(vic_devices)) {
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100229 printk(KERN_ERR "%s: too few VICs, increase CONFIG_ARM_VIC_NR\n", __func__);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100230 return;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100231 }
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100232
233 v = &vic_devices[vic_id];
234 v->base = base;
Linus Walleijce94df92012-04-20 08:02:36 +0100235 v->valid_sources = valid_sources;
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100236 v->resume_sources = resume_sources;
237 v->irq = irq;
238 vic_id++;
Linus Walleij07c92492012-10-16 18:50:00 +0100239 v->domain = irq_domain_add_simple(node, fls(valid_sources), irq,
Linus Walleijfa943be2012-04-20 08:02:03 +0100240 &vic_irqdomain_ops, v);
Linus Walleij5ced33b2012-12-26 01:39:16 +0100241 /* create an IRQ mapping for each valid IRQ */
242 for (i = 0; i < fls(valid_sources); i++)
243 if (valid_sources & (1 << i))
244 irq_create_mapping(v->domain, i);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100245}
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100246
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100247static void vic_ack_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100248{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100249 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100250 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100251 writel(1 << irq, base + VIC_INT_ENABLE_CLEAR);
252 /* moreover, clear the soft-triggered, in case it was the reason */
253 writel(1 << irq, base + VIC_INT_SOFT_CLEAR);
254}
255
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100256static void vic_mask_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100257{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100258 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100259 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100260 writel(1 << irq, base + VIC_INT_ENABLE_CLEAR);
261}
262
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100263static void vic_unmask_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100264{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100265 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100266 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100267 writel(1 << irq, base + VIC_INT_ENABLE);
268}
269
270#if defined(CONFIG_PM)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000271static struct vic_device *vic_from_irq(unsigned int irq)
272{
273 struct vic_device *v = vic_devices;
274 unsigned int base_irq = irq & ~31;
275 int id;
276
277 for (id = 0; id < vic_id; id++, v++) {
278 if (v->irq == base_irq)
279 return v;
280 }
281
282 return NULL;
283}
284
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100285static int vic_set_wake(struct irq_data *d, unsigned int on)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000286{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100287 struct vic_device *v = vic_from_irq(d->irq);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100288 unsigned int off = d->hwirq;
Ben Dooks3f1a5672009-06-02 09:31:03 +0100289 u32 bit = 1 << off;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000290
291 if (!v)
292 return -EINVAL;
293
Ben Dooks3f1a5672009-06-02 09:31:03 +0100294 if (!(bit & v->resume_sources))
295 return -EINVAL;
296
Ben Dooksc07f87f2009-03-24 15:30:07 +0000297 if (on)
Ben Dooks3f1a5672009-06-02 09:31:03 +0100298 v->resume_irqs |= bit;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000299 else
Ben Dooks3f1a5672009-06-02 09:31:03 +0100300 v->resume_irqs &= ~bit;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000301
302 return 0;
303}
Ben Dooksc07f87f2009-03-24 15:30:07 +0000304#else
Ben Dooksc07f87f2009-03-24 15:30:07 +0000305#define vic_set_wake NULL
306#endif /* CONFIG_PM */
307
David Brownell38c677c2006-08-01 22:26:25 +0100308static struct irq_chip vic_chip = {
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100309 .name = "VIC",
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100310 .irq_ack = vic_ack_irq,
311 .irq_mask = vic_mask_irq,
312 .irq_unmask = vic_unmask_irq,
313 .irq_set_wake = vic_set_wake,
Russell Kingfa0fe482006-01-13 21:30:48 +0000314};
315
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100316static void __init vic_disable(void __iomem *base)
317{
318 writel(0, base + VIC_INT_SELECT);
319 writel(0, base + VIC_INT_ENABLE);
320 writel(~0, base + VIC_INT_ENABLE_CLEAR);
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100321 writel(0, base + VIC_ITCR);
322 writel(~0, base + VIC_INT_SOFT_CLEAR);
323}
324
325static void __init vic_clear_interrupts(void __iomem *base)
326{
327 unsigned int i;
328
329 writel(0, base + VIC_PL190_VECT_ADDR);
330 for (i = 0; i < 19; i++) {
331 unsigned int value;
332
333 value = readl(base + VIC_PL190_VECT_ADDR);
334 writel(value, base + VIC_PL190_VECT_ADDR);
335 }
336}
337
Alessandro Rubini87e88242009-07-02 15:28:41 +0100338/*
339 * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
340 * The original cell has 32 interrupts, while the modified one has 64,
341 * replocating two blocks 0x00..0x1f in 0x20..0x3f. In that case
342 * the probe function is called twice, with base set to offset 000
343 * and 020 within the page. We call this "second block".
344 */
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100345static void __init vic_init_st(void __iomem *base, unsigned int irq_start,
Jamie Ilesad622672011-12-01 11:16:46 +0100346 u32 vic_sources, struct device_node *node)
Alessandro Rubini87e88242009-07-02 15:28:41 +0100347{
348 unsigned int i;
349 int vic_2nd_block = ((unsigned long)base & ~PAGE_MASK) != 0;
350
351 /* Disable all interrupts initially. */
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100352 vic_disable(base);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100353
354 /*
355 * Make sure we clear all existing interrupts. The vector registers
356 * in this cell are after the second block of general registers,
357 * so we can address them using standard offsets, but only from
358 * the second base address, which is 0x20 in the page
359 */
360 if (vic_2nd_block) {
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100361 vic_clear_interrupts(base);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100362
Alessandro Rubini87e88242009-07-02 15:28:41 +0100363 /* ST has 16 vectors as well, but we don't enable them by now */
364 for (i = 0; i < 16; i++) {
365 void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4);
366 writel(0, reg);
367 }
368
369 writel(32, base + VIC_PL190_DEF_VECT_ADDR);
370 }
371
Linus Walleijfa943be2012-04-20 08:02:03 +0100372 vic_register(base, irq_start, vic_sources, 0, node);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100373}
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100374
Linus Walleij07c92492012-10-16 18:50:00 +0100375void __init __vic_init(void __iomem *base, int irq_start,
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100376 u32 vic_sources, u32 resume_sources,
377 struct device_node *node)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100378{
379 unsigned int i;
380 u32 cellid = 0;
381 enum amba_vendor vendor;
382
383 /* Identify which VIC cell this one is, by reading the ID */
384 for (i = 0; i < 4; i++) {
Arnd Bergmannd4f3add2011-09-23 10:13:49 +0200385 void __iomem *addr;
386 addr = (void __iomem *)((u32)base & PAGE_MASK) + 0xfe0 + (i * 4);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100387 cellid |= (readl(addr) & 0xff) << (8 * i);
388 }
389 vendor = (cellid >> 12) & 0xff;
390 printk(KERN_INFO "VIC @%p: id 0x%08x, vendor 0x%02x\n",
391 base, cellid, vendor);
392
393 switch(vendor) {
394 case AMBA_VENDOR_ST:
Jamie Ilesad622672011-12-01 11:16:46 +0100395 vic_init_st(base, irq_start, vic_sources, node);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100396 return;
397 default:
398 printk(KERN_WARNING "VIC: unknown vendor, continuing anyways\n");
399 /* fall through */
400 case AMBA_VENDOR_ARM:
401 break;
402 }
403
404 /* Disable all interrupts initially. */
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100405 vic_disable(base);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100406
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100407 /* Make sure we clear all existing interrupts */
408 vic_clear_interrupts(base);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100409
410 vic_init2(base);
411
Linus Walleijfa943be2012-04-20 08:02:03 +0100412 vic_register(base, irq_start, vic_sources, resume_sources, node);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100413}
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100414
415/**
416 * vic_init() - initialise a vectored interrupt controller
417 * @base: iomem base address
418 * @irq_start: starting interrupt number, must be muliple of 32
419 * @vic_sources: bitmask of interrupt sources to allow
420 * @resume_sources: bitmask of interrupt sources to allow for resume
421 */
422void __init vic_init(void __iomem *base, unsigned int irq_start,
423 u32 vic_sources, u32 resume_sources)
424{
425 __vic_init(base, irq_start, vic_sources, resume_sources, NULL);
426}
427
428#ifdef CONFIG_OF
429int __init vic_of_init(struct device_node *node, struct device_node *parent)
430{
431 void __iomem *regs;
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100432
433 if (WARN(parent, "non-root VICs are not supported"))
434 return -EINVAL;
435
436 regs = of_iomap(node, 0);
437 if (WARN_ON(!regs))
438 return -EIO;
439
Linus Walleij07c92492012-10-16 18:50:00 +0100440 /*
Linus Walleij5ced33b2012-12-26 01:39:16 +0100441 * Passing 0 as first IRQ makes the simple domain allocate descriptors
Linus Walleij07c92492012-10-16 18:50:00 +0100442 */
Linus Walleij5ced33b2012-12-26 01:39:16 +0100443 __vic_init(regs, 0, ~0, ~0, node);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100444
445 return 0;
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100446}
447#endif /* CONFIG OF */
Jamie Iles15583682011-09-28 09:40:11 +0100448
Jamie Iles15583682011-09-28 09:40:11 +0100449/*
450 * Handle each interrupt in a single VIC. Returns non-zero if we've
Will Deacon34af65792012-04-05 19:42:10 +0100451 * handled at least one interrupt. This reads the status register
452 * before handling each interrupt, which is necessary given that
453 * handle_IRQ may briefly re-enable interrupts for soft IRQ handling.
Jamie Iles15583682011-09-28 09:40:11 +0100454 */
455static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
456{
457 u32 stat, irq;
458 int handled = 0;
459
Will Deacon34af65792012-04-05 19:42:10 +0100460 while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
Jamie Iles15583682011-09-28 09:40:11 +0100461 irq = ffs(stat) - 1;
Grant Likely75294952012-02-14 14:06:57 -0700462 handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
Jamie Iles15583682011-09-28 09:40:11 +0100463 handled = 1;
464 }
465
466 return handled;
467}
468
469/*
470 * Keep iterating over all registered VIC's until there are no pending
471 * interrupts.
472 */
473asmlinkage void __exception_irq_entry vic_handle_irq(struct pt_regs *regs)
474{
475 int i, handled;
476
477 do {
478 for (i = 0, handled = 0; i < vic_id; ++i)
479 handled |= handle_one_vic(&vic_devices[i], regs);
480 } while (handled);
481}