blob: 3c8d89b62a211dfa4d5953df47cfa511f0b1a5be [file] [log] [blame]
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +02001/*
2 * Marvell Armada 370 and Armada XP SoC IRQ handling
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Lior Amsalem <alior@marvell.com>
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
9 * Ben Dooks <ben.dooks@codethink.co.uk>
10 *
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/irq.h>
20#include <linux/interrupt.h>
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030021#include <linux/irqchip/chained_irq.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020022#include <linux/io.h>
23#include <linux/of_address.h>
24#include <linux/of_irq.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020025#include <linux/of_pci.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020026#include <linux/irqdomain.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020027#include <linux/slab.h>
28#include <linux/msi.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020029#include <asm/mach/arch.h>
30#include <asm/exception.h>
Gregory CLEMENT344e8732012-08-02 11:19:12 +030031#include <asm/smp_plat.h>
Thomas Petazzoni9339d432013-04-09 23:26:15 +020032#include <asm/mach/irq.h>
33
34#include "irqchip.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020035
36/* Interrupt Controller Registers Map */
37#define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
38#define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
39
Ben Dooksf3e16cc2012-06-04 18:50:12 +020040#define ARMADA_370_XP_INT_CONTROL (0x00)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020041#define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
42#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010043#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020044
45#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030046#define ARMADA_375_PPI_CAUSE (0x10)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020047
Gregory CLEMENT344e8732012-08-02 11:19:12 +030048#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
49#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
50#define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
51
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010052#define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
53
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010054#define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5)
55
Thomas Petazzoni5ec69012013-04-09 23:26:17 +020056#define IPI_DOORBELL_START (0)
57#define IPI_DOORBELL_END (8)
58#define IPI_DOORBELL_MASK 0xFF
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020059#define PCI_MSI_DOORBELL_START (16)
60#define PCI_MSI_DOORBELL_NR (16)
61#define PCI_MSI_DOORBELL_END (32)
62#define PCI_MSI_DOORBELL_MASK 0xFFFF0000
Gregory CLEMENT344e8732012-08-02 11:19:12 +030063
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020064static void __iomem *per_cpu_int_base;
65static void __iomem *main_int_base;
66static struct irq_domain *armada_370_xp_mpic_domain;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020067#ifdef CONFIG_PCI_MSI
68static struct irq_domain *armada_370_xp_msi_domain;
69static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR);
70static DEFINE_MUTEX(msi_used_lock);
71static phys_addr_t msi_doorbell_addr;
72#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020073
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010074/*
75 * In SMP mode:
76 * For shared global interrupts, mask/unmask global enable bit
Marek Belisko097ef182013-03-15 23:34:04 +010077 * For CPU interrupts, mask/unmask the calling CPU's bit
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010078 */
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020079static void armada_370_xp_irq_mask(struct irq_data *d)
80{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010081 irq_hw_number_t hwirq = irqd_to_hwirq(d);
82
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010083 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010084 writel(hwirq, main_int_base +
85 ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
86 else
87 writel(hwirq, per_cpu_int_base +
88 ARMADA_370_XP_INT_SET_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020089}
90
91static void armada_370_xp_irq_unmask(struct irq_data *d)
92{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010093 irq_hw_number_t hwirq = irqd_to_hwirq(d);
94
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010095 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010096 writel(hwirq, main_int_base +
97 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
98 else
99 writel(hwirq, per_cpu_int_base +
100 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200101}
102
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200103#ifdef CONFIG_PCI_MSI
104
105static int armada_370_xp_alloc_msi(void)
106{
107 int hwirq;
108
109 mutex_lock(&msi_used_lock);
110 hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR);
111 if (hwirq >= PCI_MSI_DOORBELL_NR)
112 hwirq = -ENOSPC;
113 else
114 set_bit(hwirq, msi_used);
115 mutex_unlock(&msi_used_lock);
116
117 return hwirq;
118}
119
120static void armada_370_xp_free_msi(int hwirq)
121{
122 mutex_lock(&msi_used_lock);
123 if (!test_bit(hwirq, msi_used))
124 pr_err("trying to free unused MSI#%d\n", hwirq);
125 else
126 clear_bit(hwirq, msi_used);
127 mutex_unlock(&msi_used_lock);
128}
129
130static int armada_370_xp_setup_msi_irq(struct msi_chip *chip,
131 struct pci_dev *pdev,
132 struct msi_desc *desc)
133{
134 struct msi_msg msg;
Thomas Petazzonida343fc2014-04-18 14:19:47 +0200135 int virq, hwirq;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200136
137 hwirq = armada_370_xp_alloc_msi();
138 if (hwirq < 0)
139 return hwirq;
140
141 virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq);
142 if (!virq) {
143 armada_370_xp_free_msi(hwirq);
144 return -EINVAL;
145 }
146
147 irq_set_msi_desc(virq, desc);
148
149 msg.address_lo = msi_doorbell_addr;
150 msg.address_hi = 0;
151 msg.data = 0xf00 | (hwirq + 16);
152
153 write_msi_msg(virq, &msg);
154 return 0;
155}
156
157static void armada_370_xp_teardown_msi_irq(struct msi_chip *chip,
158 unsigned int irq)
159{
160 struct irq_data *d = irq_get_irq_data(irq);
161 irq_dispose_mapping(irq);
162 armada_370_xp_free_msi(d->hwirq);
163}
164
165static struct irq_chip armada_370_xp_msi_irq_chip = {
166 .name = "armada_370_xp_msi_irq",
167 .irq_enable = unmask_msi_irq,
168 .irq_disable = mask_msi_irq,
169 .irq_mask = mask_msi_irq,
170 .irq_unmask = unmask_msi_irq,
171};
172
173static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq,
174 irq_hw_number_t hw)
175{
176 irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip,
177 handle_simple_irq);
178 set_irq_flags(virq, IRQF_VALID);
179
180 return 0;
181}
182
183static const struct irq_domain_ops armada_370_xp_msi_irq_ops = {
184 .map = armada_370_xp_msi_map,
185};
186
187static int armada_370_xp_msi_init(struct device_node *node,
188 phys_addr_t main_int_phys_base)
189{
190 struct msi_chip *msi_chip;
191 u32 reg;
192 int ret;
193
194 msi_doorbell_addr = main_int_phys_base +
195 ARMADA_370_XP_SW_TRIG_INT_OFFS;
196
197 msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL);
198 if (!msi_chip)
199 return -ENOMEM;
200
201 msi_chip->setup_irq = armada_370_xp_setup_msi_irq;
202 msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq;
203 msi_chip->of_node = node;
204
205 armada_370_xp_msi_domain =
206 irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR,
207 &armada_370_xp_msi_irq_ops,
208 NULL);
209 if (!armada_370_xp_msi_domain) {
210 kfree(msi_chip);
211 return -ENOMEM;
212 }
213
214 ret = of_pci_msi_chip_add(msi_chip);
215 if (ret < 0) {
216 irq_domain_remove(armada_370_xp_msi_domain);
217 kfree(msi_chip);
218 return ret;
219 }
220
221 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS)
222 | PCI_MSI_DOORBELL_MASK;
223
224 writel(reg, per_cpu_int_base +
225 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
226
227 /* Unmask IPI interrupt */
228 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
229
230 return 0;
231}
232#else
233static inline int armada_370_xp_msi_init(struct device_node *node,
234 phys_addr_t main_int_phys_base)
235{
236 return 0;
237}
238#endif
239
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300240#ifdef CONFIG_SMP
Arnaud Ebalard19e61d42014-01-20 22:52:05 +0100241static DEFINE_RAW_SPINLOCK(irq_controller_lock);
242
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300243static int armada_xp_set_affinity(struct irq_data *d,
244 const struct cpumask *mask_val, bool force)
245{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100246 unsigned long reg;
247 unsigned long new_mask = 0;
248 unsigned long online_mask = 0;
249 unsigned long count = 0;
250 irq_hw_number_t hwirq = irqd_to_hwirq(d);
251 int cpu;
252
253 for_each_cpu(cpu, mask_val) {
254 new_mask |= 1 << cpu_logical_map(cpu);
255 count++;
256 }
257
258 /*
259 * Forbid mutlicore interrupt affinity
260 * This is required since the MPIC HW doesn't limit
261 * several CPUs from acknowledging the same interrupt.
262 */
263 if (count > 1)
264 return -EINVAL;
265
266 for_each_cpu(cpu, cpu_online_mask)
267 online_mask |= 1 << cpu_logical_map(cpu);
268
269 raw_spin_lock(&irq_controller_lock);
270
271 reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
272 reg = (reg & (~online_mask)) | new_mask;
273 writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
274
275 raw_spin_unlock(&irq_controller_lock);
276
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300277 return 0;
278}
279#endif
280
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200281static struct irq_chip armada_370_xp_irq_chip = {
282 .name = "armada_370_xp_irq",
283 .irq_mask = armada_370_xp_irq_mask,
284 .irq_mask_ack = armada_370_xp_irq_mask,
285 .irq_unmask = armada_370_xp_irq_unmask,
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300286#ifdef CONFIG_SMP
287 .irq_set_affinity = armada_xp_set_affinity,
288#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200289};
290
291static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
292 unsigned int virq, irq_hw_number_t hw)
293{
294 armada_370_xp_irq_mask(irq_get_irq_data(virq));
Gregory CLEMENT600468d2013-04-05 14:32:52 +0200295 if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
296 writel(hw, per_cpu_int_base +
297 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
298 else
299 writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200300 irq_set_status_flags(virq, IRQ_LEVEL);
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100301
Gregory CLEMENT7f23f622013-03-20 16:09:35 +0100302 if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) {
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100303 irq_set_percpu_devid(virq);
304 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
305 handle_percpu_devid_irq);
306
307 } else {
308 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
309 handle_level_irq);
310 }
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200311 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
312
313 return 0;
314}
315
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300316#ifdef CONFIG_SMP
317void armada_mpic_send_doorbell(const struct cpumask *mask, unsigned int irq)
318{
319 int cpu;
320 unsigned long map = 0;
321
322 /* Convert our logical CPU mask into a physical one. */
323 for_each_cpu(cpu, mask)
324 map |= 1 << cpu_logical_map(cpu);
325
326 /*
327 * Ensure that stores to Normal memory are visible to the
328 * other CPUs before issuing the IPI.
329 */
330 dsb();
331
332 /* submit softirq */
333 writel((map << 8) | irq, main_int_base +
334 ARMADA_370_XP_SW_TRIG_INT_OFFS);
335}
336
337void armada_xp_mpic_smp_cpu_init(void)
338{
339 /* Clear pending IPIs */
340 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
341
342 /* Enable first 8 IPIs */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200343 writel(IPI_DOORBELL_MASK, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300344 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
345
346 /* Unmask IPI interrupt */
347 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
348}
349#endif /* CONFIG_SMP */
350
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200351static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
352 .map = armada_370_xp_mpic_irq_map,
353 .xlate = irq_domain_xlate_onecell,
354};
355
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300356#ifdef CONFIG_PCI_MSI
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300357static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300358{
359 u32 msimask, msinr;
360
361 msimask = readl_relaxed(per_cpu_int_base +
362 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
363 & PCI_MSI_DOORBELL_MASK;
364
365 writel(~msimask, per_cpu_int_base +
366 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
367
368 for (msinr = PCI_MSI_DOORBELL_START;
369 msinr < PCI_MSI_DOORBELL_END; msinr++) {
370 int irq;
371
372 if (!(msimask & BIT(msinr)))
373 continue;
374
375 irq = irq_find_mapping(armada_370_xp_msi_domain,
376 msinr - 16);
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300377
378 if (is_chained)
379 generic_handle_irq(irq);
380 else
381 handle_IRQ(irq, regs);
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300382 }
383}
384#else
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300385static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300386#endif
387
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300388static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
389 struct irq_desc *desc)
390{
391 struct irq_chip *chip = irq_get_chip(irq);
392 unsigned long irqmap, irqn;
393 unsigned int cascade_irq;
394
395 chained_irq_enter(chip, desc);
396
397 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
398
399 if (irqmap & BIT(0)) {
400 armada_370_xp_handle_msi_irq(NULL, true);
401 irqmap &= ~BIT(0);
402 }
403
404 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
405 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
406 generic_handle_irq(cascade_irq);
407 }
408
409 chained_irq_exit(chip, desc);
410}
411
Stephen Boyd8783dd32014-03-04 16:40:30 -0800412static void __exception_irq_entry
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200413armada_370_xp_handle_irq(struct pt_regs *regs)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200414{
415 u32 irqstat, irqnr;
416
417 do {
418 irqstat = readl_relaxed(per_cpu_int_base +
419 ARMADA_370_XP_CPU_INTACK_OFFS);
420 irqnr = irqstat & 0x3FF;
421
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300422 if (irqnr > 1022)
423 break;
424
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200425 if (irqnr > 1) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300426 irqnr = irq_find_mapping(armada_370_xp_mpic_domain,
427 irqnr);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200428 handle_IRQ(irqnr, regs);
429 continue;
430 }
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200431
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200432 /* MSI handling */
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300433 if (irqnr == 1)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300434 armada_370_xp_handle_msi_irq(regs, false);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200435
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300436#ifdef CONFIG_SMP
437 /* IPI Handling */
438 if (irqnr == 0) {
439 u32 ipimask, ipinr;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200440
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300441 ipimask = readl_relaxed(per_cpu_int_base +
442 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200443 & IPI_DOORBELL_MASK;
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300444
Lior Amsalema6f089e2013-11-25 17:26:44 +0100445 writel(~ipimask, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300446 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
447
448 /* Handle all pending doorbells */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200449 for (ipinr = IPI_DOORBELL_START;
450 ipinr < IPI_DOORBELL_END; ipinr++) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300451 if (ipimask & (0x1 << ipinr))
452 handle_IPI(ipinr, regs);
453 }
454 continue;
455 }
456#endif
457
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200458 } while (1);
459}
460
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200461static int __init armada_370_xp_mpic_of_init(struct device_node *node,
462 struct device_node *parent)
463{
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200464 struct resource main_int_res, per_cpu_int_res;
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300465 int parent_irq;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200466 u32 control;
467
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200468 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
469 BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200470
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200471 BUG_ON(!request_mem_region(main_int_res.start,
472 resource_size(&main_int_res),
473 node->full_name));
474 BUG_ON(!request_mem_region(per_cpu_int_res.start,
475 resource_size(&per_cpu_int_res),
476 node->full_name));
477
478 main_int_base = ioremap(main_int_res.start,
479 resource_size(&main_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200480 BUG_ON(!main_int_base);
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200481
482 per_cpu_int_base = ioremap(per_cpu_int_res.start,
483 resource_size(&per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200484 BUG_ON(!per_cpu_int_base);
Gregory CLEMENTd792b1e2012-09-26 18:02:48 +0200485
486 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
487
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200488 armada_370_xp_mpic_domain =
489 irq_domain_add_linear(node, (control >> 2) & 0x3ff,
490 &armada_370_xp_mpic_irq_ops, NULL);
491
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200492 BUG_ON(!armada_370_xp_mpic_domain);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200493
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200494#ifdef CONFIG_SMP
495 armada_xp_mpic_smp_cpu_init();
496
497 /*
498 * Set the default affinity from all CPUs to the boot cpu.
499 * This is required since the MPIC doesn't limit several CPUs
500 * from acknowledging the same interrupt.
501 */
502 cpumask_clear(irq_default_affinity);
503 cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
504
505#endif
506
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200507 armada_370_xp_msi_init(node, main_int_res.start);
508
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300509 parent_irq = irq_of_parse_and_map(node, 0);
510 if (parent_irq <= 0) {
511 irq_set_default_host(armada_370_xp_mpic_domain);
512 set_handle_irq(armada_370_xp_handle_irq);
513 } else {
514 irq_set_chained_handler(parent_irq,
515 armada_370_xp_mpic_handle_cascade_irq);
516 }
Thomas Petazzonib313ada2013-04-09 23:26:16 +0200517
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200518 return 0;
519}
520
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200521IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);