blob: 5feb004aaea685ac1df3f94b8157e874058882b2 [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;
Rob Herring7fb7d8a2012-11-20 19:55:27 -0600238 set_handle_irq(vic_handle_irq);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100239 vic_id++;
Linus Walleij07c92492012-10-16 18:50:00 +0100240 v->domain = irq_domain_add_simple(node, fls(valid_sources), irq,
Linus Walleijfa943be2012-04-20 08:02:03 +0100241 &vic_irqdomain_ops, v);
Linus Walleij5ced33b2012-12-26 01:39:16 +0100242 /* create an IRQ mapping for each valid IRQ */
243 for (i = 0; i < fls(valid_sources); i++)
244 if (valid_sources & (1 << i))
245 irq_create_mapping(v->domain, i);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100246}
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100247
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100248static void vic_ack_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100249{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100250 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100251 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100252 writel(1 << irq, base + VIC_INT_ENABLE_CLEAR);
253 /* moreover, clear the soft-triggered, in case it was the reason */
254 writel(1 << irq, base + VIC_INT_SOFT_CLEAR);
255}
256
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100257static void vic_mask_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100258{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100259 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100260 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100261 writel(1 << irq, base + VIC_INT_ENABLE_CLEAR);
262}
263
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100264static void vic_unmask_irq(struct irq_data *d)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100265{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100266 void __iomem *base = irq_data_get_irq_chip_data(d);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100267 unsigned int irq = d->hwirq;
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100268 writel(1 << irq, base + VIC_INT_ENABLE);
269}
270
271#if defined(CONFIG_PM)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000272static struct vic_device *vic_from_irq(unsigned int irq)
273{
274 struct vic_device *v = vic_devices;
275 unsigned int base_irq = irq & ~31;
276 int id;
277
278 for (id = 0; id < vic_id; id++, v++) {
279 if (v->irq == base_irq)
280 return v;
281 }
282
283 return NULL;
284}
285
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100286static int vic_set_wake(struct irq_data *d, unsigned int on)
Ben Dooksc07f87f2009-03-24 15:30:07 +0000287{
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100288 struct vic_device *v = vic_from_irq(d->irq);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100289 unsigned int off = d->hwirq;
Ben Dooks3f1a5672009-06-02 09:31:03 +0100290 u32 bit = 1 << off;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000291
292 if (!v)
293 return -EINVAL;
294
Ben Dooks3f1a5672009-06-02 09:31:03 +0100295 if (!(bit & v->resume_sources))
296 return -EINVAL;
297
Ben Dooksc07f87f2009-03-24 15:30:07 +0000298 if (on)
Ben Dooks3f1a5672009-06-02 09:31:03 +0100299 v->resume_irqs |= bit;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000300 else
Ben Dooks3f1a5672009-06-02 09:31:03 +0100301 v->resume_irqs &= ~bit;
Ben Dooksc07f87f2009-03-24 15:30:07 +0000302
303 return 0;
304}
Ben Dooksc07f87f2009-03-24 15:30:07 +0000305#else
Ben Dooksc07f87f2009-03-24 15:30:07 +0000306#define vic_set_wake NULL
307#endif /* CONFIG_PM */
308
David Brownell38c677c2006-08-01 22:26:25 +0100309static struct irq_chip vic_chip = {
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100310 .name = "VIC",
Lennert Buytenhekf013c982010-11-29 10:20:21 +0100311 .irq_ack = vic_ack_irq,
312 .irq_mask = vic_mask_irq,
313 .irq_unmask = vic_unmask_irq,
314 .irq_set_wake = vic_set_wake,
Russell Kingfa0fe482006-01-13 21:30:48 +0000315};
316
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100317static void __init vic_disable(void __iomem *base)
318{
319 writel(0, base + VIC_INT_SELECT);
320 writel(0, base + VIC_INT_ENABLE);
321 writel(~0, base + VIC_INT_ENABLE_CLEAR);
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100322 writel(0, base + VIC_ITCR);
323 writel(~0, base + VIC_INT_SOFT_CLEAR);
324}
325
326static void __init vic_clear_interrupts(void __iomem *base)
327{
328 unsigned int i;
329
330 writel(0, base + VIC_PL190_VECT_ADDR);
331 for (i = 0; i < 19; i++) {
332 unsigned int value;
333
334 value = readl(base + VIC_PL190_VECT_ADDR);
335 writel(value, base + VIC_PL190_VECT_ADDR);
336 }
337}
338
Alessandro Rubini87e88242009-07-02 15:28:41 +0100339/*
340 * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
341 * The original cell has 32 interrupts, while the modified one has 64,
342 * replocating two blocks 0x00..0x1f in 0x20..0x3f. In that case
343 * the probe function is called twice, with base set to offset 000
344 * and 020 within the page. We call this "second block".
345 */
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100346static void __init vic_init_st(void __iomem *base, unsigned int irq_start,
Jamie Ilesad622672011-12-01 11:16:46 +0100347 u32 vic_sources, struct device_node *node)
Alessandro Rubini87e88242009-07-02 15:28:41 +0100348{
349 unsigned int i;
350 int vic_2nd_block = ((unsigned long)base & ~PAGE_MASK) != 0;
351
352 /* Disable all interrupts initially. */
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100353 vic_disable(base);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100354
355 /*
356 * Make sure we clear all existing interrupts. The vector registers
357 * in this cell are after the second block of general registers,
358 * so we can address them using standard offsets, but only from
359 * the second base address, which is 0x20 in the page
360 */
361 if (vic_2nd_block) {
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100362 vic_clear_interrupts(base);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100363
Alessandro Rubini87e88242009-07-02 15:28:41 +0100364 /* ST has 16 vectors as well, but we don't enable them by now */
365 for (i = 0; i < 16; i++) {
366 void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4);
367 writel(0, reg);
368 }
369
370 writel(32, base + VIC_PL190_DEF_VECT_ADDR);
371 }
372
Linus Walleijfa943be2012-04-20 08:02:03 +0100373 vic_register(base, irq_start, vic_sources, 0, node);
Alessandro Rubini87e88242009-07-02 15:28:41 +0100374}
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100375
Linus Walleij07c92492012-10-16 18:50:00 +0100376void __init __vic_init(void __iomem *base, int irq_start,
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100377 u32 vic_sources, u32 resume_sources,
378 struct device_node *node)
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100379{
380 unsigned int i;
381 u32 cellid = 0;
382 enum amba_vendor vendor;
383
384 /* Identify which VIC cell this one is, by reading the ID */
385 for (i = 0; i < 4; i++) {
Arnd Bergmannd4f3add2011-09-23 10:13:49 +0200386 void __iomem *addr;
387 addr = (void __iomem *)((u32)base & PAGE_MASK) + 0xfe0 + (i * 4);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100388 cellid |= (readl(addr) & 0xff) << (8 * i);
389 }
390 vendor = (cellid >> 12) & 0xff;
391 printk(KERN_INFO "VIC @%p: id 0x%08x, vendor 0x%02x\n",
392 base, cellid, vendor);
393
394 switch(vendor) {
395 case AMBA_VENDOR_ST:
Jamie Ilesad622672011-12-01 11:16:46 +0100396 vic_init_st(base, irq_start, vic_sources, node);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100397 return;
398 default:
399 printk(KERN_WARNING "VIC: unknown vendor, continuing anyways\n");
400 /* fall through */
401 case AMBA_VENDOR_ARM:
402 break;
403 }
404
405 /* Disable all interrupts initially. */
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100406 vic_disable(base);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100407
Hartley Sweetenb0c4c892010-04-02 18:04:47 +0100408 /* Make sure we clear all existing interrupts */
409 vic_clear_interrupts(base);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100410
411 vic_init2(base);
412
Linus Walleijfa943be2012-04-20 08:02:03 +0100413 vic_register(base, irq_start, vic_sources, resume_sources, node);
Hartley Sweetenbb06b732010-01-12 19:09:12 +0100414}
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100415
416/**
417 * vic_init() - initialise a vectored interrupt controller
418 * @base: iomem base address
419 * @irq_start: starting interrupt number, must be muliple of 32
420 * @vic_sources: bitmask of interrupt sources to allow
421 * @resume_sources: bitmask of interrupt sources to allow for resume
422 */
423void __init vic_init(void __iomem *base, unsigned int irq_start,
424 u32 vic_sources, u32 resume_sources)
425{
426 __vic_init(base, irq_start, vic_sources, resume_sources, NULL);
427}
428
429#ifdef CONFIG_OF
430int __init vic_of_init(struct device_node *node, struct device_node *parent)
431{
432 void __iomem *regs;
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100433
434 if (WARN(parent, "non-root VICs are not supported"))
435 return -EINVAL;
436
437 regs = of_iomap(node, 0);
438 if (WARN_ON(!regs))
439 return -EIO;
440
Linus Walleij07c92492012-10-16 18:50:00 +0100441 /*
Linus Walleij5ced33b2012-12-26 01:39:16 +0100442 * Passing 0 as first IRQ makes the simple domain allocate descriptors
Linus Walleij07c92492012-10-16 18:50:00 +0100443 */
Linus Walleij5ced33b2012-12-26 01:39:16 +0100444 __vic_init(regs, 0, ~0, ~0, node);
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100445
446 return 0;
Jamie Ilesf9b28cc2011-09-27 11:00:46 +0100447}
448#endif /* CONFIG OF */
Jamie Iles15583682011-09-28 09:40:11 +0100449
Jamie Iles15583682011-09-28 09:40:11 +0100450/*
451 * Handle each interrupt in a single VIC. Returns non-zero if we've
Will Deacon34af65792012-04-05 19:42:10 +0100452 * handled at least one interrupt. This reads the status register
453 * before handling each interrupt, which is necessary given that
454 * handle_IRQ may briefly re-enable interrupts for soft IRQ handling.
Jamie Iles15583682011-09-28 09:40:11 +0100455 */
456static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
457{
458 u32 stat, irq;
459 int handled = 0;
460
Will Deacon34af65792012-04-05 19:42:10 +0100461 while ((stat = readl_relaxed(vic->base + VIC_IRQ_STATUS))) {
Jamie Iles15583682011-09-28 09:40:11 +0100462 irq = ffs(stat) - 1;
Grant Likely75294952012-02-14 14:06:57 -0700463 handle_IRQ(irq_find_mapping(vic->domain, irq), regs);
Jamie Iles15583682011-09-28 09:40:11 +0100464 handled = 1;
465 }
466
467 return handled;
468}
469
470/*
471 * Keep iterating over all registered VIC's until there are no pending
472 * interrupts.
473 */
474asmlinkage void __exception_irq_entry vic_handle_irq(struct pt_regs *regs)
475{
476 int i, handled;
477
478 do {
479 for (i = 0, handled = 0; i < vic_id; ++i)
480 handled |= handle_one_vic(&vic_devices[i], regs);
481 } while (handled);
482}