blob: 71f77848bc230a87ed6122ce75d1960407170cbd [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 Petazzonid7df84b2014-04-14 15:54:02 +020022#include <linux/cpu.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020023#include <linux/io.h>
24#include <linux/of_address.h>
25#include <linux/of_irq.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020026#include <linux/of_pci.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020027#include <linux/irqdomain.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020028#include <linux/slab.h>
29#include <linux/msi.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020030#include <asm/mach/arch.h>
31#include <asm/exception.h>
Gregory CLEMENT344e8732012-08-02 11:19:12 +030032#include <asm/smp_plat.h>
Thomas Petazzoni9339d432013-04-09 23:26:15 +020033#include <asm/mach/irq.h>
34
35#include "irqchip.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020036
37/* Interrupt Controller Registers Map */
38#define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
39#define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
40
Ben Dooksf3e16cc2012-06-04 18:50:12 +020041#define ARMADA_370_XP_INT_CONTROL (0x00)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020042#define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
43#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010044#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020045
46#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030047#define ARMADA_375_PPI_CAUSE (0x10)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020048
Gregory CLEMENT344e8732012-08-02 11:19:12 +030049#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
50#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
51#define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
52
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010053#define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
54
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010055#define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5)
56
Thomas Petazzoni5ec69012013-04-09 23:26:17 +020057#define IPI_DOORBELL_START (0)
58#define IPI_DOORBELL_END (8)
59#define IPI_DOORBELL_MASK 0xFF
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020060#define PCI_MSI_DOORBELL_START (16)
61#define PCI_MSI_DOORBELL_NR (16)
62#define PCI_MSI_DOORBELL_END (32)
63#define PCI_MSI_DOORBELL_MASK 0xFFFF0000
Gregory CLEMENT344e8732012-08-02 11:19:12 +030064
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020065static void __iomem *per_cpu_int_base;
66static void __iomem *main_int_base;
67static struct irq_domain *armada_370_xp_mpic_domain;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020068#ifdef CONFIG_PCI_MSI
69static struct irq_domain *armada_370_xp_msi_domain;
70static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR);
71static DEFINE_MUTEX(msi_used_lock);
72static phys_addr_t msi_doorbell_addr;
73#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020074
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010075/*
76 * In SMP mode:
77 * For shared global interrupts, mask/unmask global enable bit
Marek Belisko097ef182013-03-15 23:34:04 +010078 * For CPU interrupts, mask/unmask the calling CPU's bit
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010079 */
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020080static void armada_370_xp_irq_mask(struct irq_data *d)
81{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010082 irq_hw_number_t hwirq = irqd_to_hwirq(d);
83
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010084 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010085 writel(hwirq, main_int_base +
86 ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
87 else
88 writel(hwirq, per_cpu_int_base +
89 ARMADA_370_XP_INT_SET_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020090}
91
92static void armada_370_xp_irq_unmask(struct irq_data *d)
93{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010094 irq_hw_number_t hwirq = irqd_to_hwirq(d);
95
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010096 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010097 writel(hwirq, main_int_base +
98 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
99 else
100 writel(hwirq, per_cpu_int_base +
101 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200102}
103
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200104#ifdef CONFIG_PCI_MSI
105
106static int armada_370_xp_alloc_msi(void)
107{
108 int hwirq;
109
110 mutex_lock(&msi_used_lock);
111 hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR);
112 if (hwirq >= PCI_MSI_DOORBELL_NR)
113 hwirq = -ENOSPC;
114 else
115 set_bit(hwirq, msi_used);
116 mutex_unlock(&msi_used_lock);
117
118 return hwirq;
119}
120
121static void armada_370_xp_free_msi(int hwirq)
122{
123 mutex_lock(&msi_used_lock);
124 if (!test_bit(hwirq, msi_used))
125 pr_err("trying to free unused MSI#%d\n", hwirq);
126 else
127 clear_bit(hwirq, msi_used);
128 mutex_unlock(&msi_used_lock);
129}
130
131static int armada_370_xp_setup_msi_irq(struct msi_chip *chip,
132 struct pci_dev *pdev,
133 struct msi_desc *desc)
134{
135 struct msi_msg msg;
136 irq_hw_number_t hwirq;
137 int virq;
138
139 hwirq = armada_370_xp_alloc_msi();
140 if (hwirq < 0)
141 return hwirq;
142
143 virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq);
144 if (!virq) {
145 armada_370_xp_free_msi(hwirq);
146 return -EINVAL;
147 }
148
149 irq_set_msi_desc(virq, desc);
150
151 msg.address_lo = msi_doorbell_addr;
152 msg.address_hi = 0;
153 msg.data = 0xf00 | (hwirq + 16);
154
155 write_msi_msg(virq, &msg);
156 return 0;
157}
158
159static void armada_370_xp_teardown_msi_irq(struct msi_chip *chip,
160 unsigned int irq)
161{
162 struct irq_data *d = irq_get_irq_data(irq);
163 irq_dispose_mapping(irq);
164 armada_370_xp_free_msi(d->hwirq);
165}
166
167static struct irq_chip armada_370_xp_msi_irq_chip = {
168 .name = "armada_370_xp_msi_irq",
169 .irq_enable = unmask_msi_irq,
170 .irq_disable = mask_msi_irq,
171 .irq_mask = mask_msi_irq,
172 .irq_unmask = unmask_msi_irq,
173};
174
175static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq,
176 irq_hw_number_t hw)
177{
178 irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip,
179 handle_simple_irq);
180 set_irq_flags(virq, IRQF_VALID);
181
182 return 0;
183}
184
185static const struct irq_domain_ops armada_370_xp_msi_irq_ops = {
186 .map = armada_370_xp_msi_map,
187};
188
189static int armada_370_xp_msi_init(struct device_node *node,
190 phys_addr_t main_int_phys_base)
191{
192 struct msi_chip *msi_chip;
193 u32 reg;
194 int ret;
195
196 msi_doorbell_addr = main_int_phys_base +
197 ARMADA_370_XP_SW_TRIG_INT_OFFS;
198
199 msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL);
200 if (!msi_chip)
201 return -ENOMEM;
202
203 msi_chip->setup_irq = armada_370_xp_setup_msi_irq;
204 msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq;
205 msi_chip->of_node = node;
206
207 armada_370_xp_msi_domain =
208 irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR,
209 &armada_370_xp_msi_irq_ops,
210 NULL);
211 if (!armada_370_xp_msi_domain) {
212 kfree(msi_chip);
213 return -ENOMEM;
214 }
215
216 ret = of_pci_msi_chip_add(msi_chip);
217 if (ret < 0) {
218 irq_domain_remove(armada_370_xp_msi_domain);
219 kfree(msi_chip);
220 return ret;
221 }
222
223 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS)
224 | PCI_MSI_DOORBELL_MASK;
225
226 writel(reg, per_cpu_int_base +
227 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
228
229 /* Unmask IPI interrupt */
230 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
231
232 return 0;
233}
234#else
235static inline int armada_370_xp_msi_init(struct device_node *node,
236 phys_addr_t main_int_phys_base)
237{
238 return 0;
239}
240#endif
241
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300242#ifdef CONFIG_SMP
Arnaud Ebalard19e61d42014-01-20 22:52:05 +0100243static DEFINE_RAW_SPINLOCK(irq_controller_lock);
244
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300245static int armada_xp_set_affinity(struct irq_data *d,
246 const struct cpumask *mask_val, bool force)
247{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100248 unsigned long reg;
249 unsigned long new_mask = 0;
250 unsigned long online_mask = 0;
251 unsigned long count = 0;
252 irq_hw_number_t hwirq = irqd_to_hwirq(d);
253 int cpu;
254
255 for_each_cpu(cpu, mask_val) {
256 new_mask |= 1 << cpu_logical_map(cpu);
257 count++;
258 }
259
260 /*
261 * Forbid mutlicore interrupt affinity
262 * This is required since the MPIC HW doesn't limit
263 * several CPUs from acknowledging the same interrupt.
264 */
265 if (count > 1)
266 return -EINVAL;
267
268 for_each_cpu(cpu, cpu_online_mask)
269 online_mask |= 1 << cpu_logical_map(cpu);
270
271 raw_spin_lock(&irq_controller_lock);
272
273 reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
274 reg = (reg & (~online_mask)) | new_mask;
275 writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
276
277 raw_spin_unlock(&irq_controller_lock);
278
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300279 return 0;
280}
281#endif
282
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200283static struct irq_chip armada_370_xp_irq_chip = {
284 .name = "armada_370_xp_irq",
285 .irq_mask = armada_370_xp_irq_mask,
286 .irq_mask_ack = armada_370_xp_irq_mask,
287 .irq_unmask = armada_370_xp_irq_unmask,
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300288#ifdef CONFIG_SMP
289 .irq_set_affinity = armada_xp_set_affinity,
290#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200291};
292
293static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
294 unsigned int virq, irq_hw_number_t hw)
295{
296 armada_370_xp_irq_mask(irq_get_irq_data(virq));
Gregory CLEMENT600468d2013-04-05 14:32:52 +0200297 if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
298 writel(hw, per_cpu_int_base +
299 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
300 else
301 writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200302 irq_set_status_flags(virq, IRQ_LEVEL);
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100303
Gregory CLEMENT7f23f622013-03-20 16:09:35 +0100304 if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) {
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100305 irq_set_percpu_devid(virq);
306 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
307 handle_percpu_devid_irq);
308
309 } else {
310 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
311 handle_level_irq);
312 }
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200313 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
314
315 return 0;
316}
317
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300318#ifdef CONFIG_SMP
Thomas Petazzonief37d332014-04-14 15:54:01 +0200319static void armada_mpic_send_doorbell(const struct cpumask *mask,
320 unsigned int irq)
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300321{
322 int cpu;
323 unsigned long map = 0;
324
325 /* Convert our logical CPU mask into a physical one. */
326 for_each_cpu(cpu, mask)
327 map |= 1 << cpu_logical_map(cpu);
328
329 /*
330 * Ensure that stores to Normal memory are visible to the
331 * other CPUs before issuing the IPI.
332 */
333 dsb();
334
335 /* submit softirq */
336 writel((map << 8) | irq, main_int_base +
337 ARMADA_370_XP_SW_TRIG_INT_OFFS);
338}
339
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200340static void armada_xp_mpic_smp_cpu_init(void)
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300341{
342 /* Clear pending IPIs */
343 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
344
345 /* Enable first 8 IPIs */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200346 writel(IPI_DOORBELL_MASK, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300347 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
348
349 /* Unmask IPI interrupt */
350 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
351}
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200352
353static int armada_xp_mpic_secondary_init(struct notifier_block *nfb,
354 unsigned long action, void *hcpu)
355{
356 if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
357 armada_xp_mpic_smp_cpu_init();
358 return NOTIFY_OK;
359}
360
361static struct notifier_block armada_370_xp_mpic_cpu_notifier = {
362 .notifier_call = armada_xp_mpic_secondary_init,
363 .priority = 100,
364};
365
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300366#endif /* CONFIG_SMP */
367
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200368static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
369 .map = armada_370_xp_mpic_irq_map,
370 .xlate = irq_domain_xlate_onecell,
371};
372
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300373#ifdef CONFIG_PCI_MSI
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300374static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300375{
376 u32 msimask, msinr;
377
378 msimask = readl_relaxed(per_cpu_int_base +
379 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
380 & PCI_MSI_DOORBELL_MASK;
381
382 writel(~msimask, per_cpu_int_base +
383 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
384
385 for (msinr = PCI_MSI_DOORBELL_START;
386 msinr < PCI_MSI_DOORBELL_END; msinr++) {
387 int irq;
388
389 if (!(msimask & BIT(msinr)))
390 continue;
391
392 irq = irq_find_mapping(armada_370_xp_msi_domain,
393 msinr - 16);
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300394
395 if (is_chained)
396 generic_handle_irq(irq);
397 else
398 handle_IRQ(irq, regs);
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300399 }
400}
401#else
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300402static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300403#endif
404
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300405static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
406 struct irq_desc *desc)
407{
408 struct irq_chip *chip = irq_get_chip(irq);
409 unsigned long irqmap, irqn;
410 unsigned int cascade_irq;
411
412 chained_irq_enter(chip, desc);
413
414 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
415
416 if (irqmap & BIT(0)) {
417 armada_370_xp_handle_msi_irq(NULL, true);
418 irqmap &= ~BIT(0);
419 }
420
421 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
422 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
423 generic_handle_irq(cascade_irq);
424 }
425
426 chained_irq_exit(chip, desc);
427}
428
Stephen Boyd8783dd32014-03-04 16:40:30 -0800429static void __exception_irq_entry
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200430armada_370_xp_handle_irq(struct pt_regs *regs)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200431{
432 u32 irqstat, irqnr;
433
434 do {
435 irqstat = readl_relaxed(per_cpu_int_base +
436 ARMADA_370_XP_CPU_INTACK_OFFS);
437 irqnr = irqstat & 0x3FF;
438
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300439 if (irqnr > 1022)
440 break;
441
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200442 if (irqnr > 1) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300443 irqnr = irq_find_mapping(armada_370_xp_mpic_domain,
444 irqnr);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200445 handle_IRQ(irqnr, regs);
446 continue;
447 }
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200448
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200449 /* MSI handling */
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300450 if (irqnr == 1)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300451 armada_370_xp_handle_msi_irq(regs, false);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200452
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300453#ifdef CONFIG_SMP
454 /* IPI Handling */
455 if (irqnr == 0) {
456 u32 ipimask, ipinr;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200457
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300458 ipimask = readl_relaxed(per_cpu_int_base +
459 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200460 & IPI_DOORBELL_MASK;
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300461
Lior Amsalema6f089e2013-11-25 17:26:44 +0100462 writel(~ipimask, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300463 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
464
465 /* Handle all pending doorbells */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200466 for (ipinr = IPI_DOORBELL_START;
467 ipinr < IPI_DOORBELL_END; ipinr++) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300468 if (ipimask & (0x1 << ipinr))
469 handle_IPI(ipinr, regs);
470 }
471 continue;
472 }
473#endif
474
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200475 } while (1);
476}
477
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200478static int __init armada_370_xp_mpic_of_init(struct device_node *node,
479 struct device_node *parent)
480{
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200481 struct resource main_int_res, per_cpu_int_res;
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300482 int parent_irq;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200483 u32 control;
484
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200485 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
486 BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200487
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200488 BUG_ON(!request_mem_region(main_int_res.start,
489 resource_size(&main_int_res),
490 node->full_name));
491 BUG_ON(!request_mem_region(per_cpu_int_res.start,
492 resource_size(&per_cpu_int_res),
493 node->full_name));
494
495 main_int_base = ioremap(main_int_res.start,
496 resource_size(&main_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200497 BUG_ON(!main_int_base);
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200498
499 per_cpu_int_base = ioremap(per_cpu_int_res.start,
500 resource_size(&per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200501 BUG_ON(!per_cpu_int_base);
Gregory CLEMENTd792b1e2012-09-26 18:02:48 +0200502
503 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
504
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200505 armada_370_xp_mpic_domain =
506 irq_domain_add_linear(node, (control >> 2) & 0x3ff,
507 &armada_370_xp_mpic_irq_ops, NULL);
508
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200509 BUG_ON(!armada_370_xp_mpic_domain);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200510
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200511#ifdef CONFIG_SMP
512 armada_xp_mpic_smp_cpu_init();
513
514 /*
515 * Set the default affinity from all CPUs to the boot cpu.
516 * This is required since the MPIC doesn't limit several CPUs
517 * from acknowledging the same interrupt.
518 */
519 cpumask_clear(irq_default_affinity);
520 cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
521
522#endif
523
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200524 armada_370_xp_msi_init(node, main_int_res.start);
525
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300526 parent_irq = irq_of_parse_and_map(node, 0);
527 if (parent_irq <= 0) {
528 irq_set_default_host(armada_370_xp_mpic_domain);
529 set_handle_irq(armada_370_xp_handle_irq);
Thomas Petazzonief37d332014-04-14 15:54:01 +0200530#ifdef CONFIG_SMP
531 set_smp_cross_call(armada_mpic_send_doorbell);
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200532 register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier);
Thomas Petazzonief37d332014-04-14 15:54:01 +0200533#endif
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300534 } else {
535 irq_set_chained_handler(parent_irq,
536 armada_370_xp_mpic_handle_cascade_irq);
537 }
Thomas Petazzonib313ada2013-04-09 23:26:16 +0200538
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200539 return 0;
540}
541
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200542IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);