blob: 463c235acbdcdc1758329205e3c79e380b5fa7a6 [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>
Thomas Petazzoni0f077eb2014-11-21 17:00:00 +010029#include <linux/syscore_ops.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020030#include <linux/msi.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020031#include <asm/mach/arch.h>
32#include <asm/exception.h>
Gregory CLEMENT344e8732012-08-02 11:19:12 +030033#include <asm/smp_plat.h>
Thomas Petazzoni9339d432013-04-09 23:26:15 +020034#include <asm/mach/irq.h>
35
36#include "irqchip.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020037
38/* Interrupt Controller Registers Map */
39#define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
40#define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
41
Ben Dooksf3e16cc2012-06-04 18:50:12 +020042#define ARMADA_370_XP_INT_CONTROL (0x00)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020043#define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
44#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010045#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +000046#define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF
Grzegorz Jaszczyk758e8362014-09-25 13:17:19 +020047#define ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid) ((BIT(0) | BIT(8)) << cpuid)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020048
49#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030050#define ARMADA_375_PPI_CAUSE (0x10)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020051
Gregory CLEMENT344e8732012-08-02 11:19:12 +030052#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
53#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
54#define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
55
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010056#define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
57
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010058#define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5)
59
Thomas Petazzoni5ec69012013-04-09 23:26:17 +020060#define IPI_DOORBELL_START (0)
61#define IPI_DOORBELL_END (8)
62#define IPI_DOORBELL_MASK 0xFF
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020063#define PCI_MSI_DOORBELL_START (16)
64#define PCI_MSI_DOORBELL_NR (16)
65#define PCI_MSI_DOORBELL_END (32)
66#define PCI_MSI_DOORBELL_MASK 0xFFFF0000
Gregory CLEMENT344e8732012-08-02 11:19:12 +030067
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020068static void __iomem *per_cpu_int_base;
69static void __iomem *main_int_base;
70static struct irq_domain *armada_370_xp_mpic_domain;
Thomas Petazzoni0f077eb2014-11-21 17:00:00 +010071static u32 doorbell_mask_reg;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020072#ifdef CONFIG_PCI_MSI
73static struct irq_domain *armada_370_xp_msi_domain;
74static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR);
75static DEFINE_MUTEX(msi_used_lock);
76static phys_addr_t msi_doorbell_addr;
77#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020078
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010079/*
80 * In SMP mode:
81 * For shared global interrupts, mask/unmask global enable bit
Marek Belisko097ef182013-03-15 23:34:04 +010082 * For CPU interrupts, mask/unmask the calling CPU's bit
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010083 */
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020084static void armada_370_xp_irq_mask(struct irq_data *d)
85{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010086 irq_hw_number_t hwirq = irqd_to_hwirq(d);
87
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010088 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010089 writel(hwirq, main_int_base +
90 ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
91 else
92 writel(hwirq, per_cpu_int_base +
93 ARMADA_370_XP_INT_SET_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020094}
95
96static void armada_370_xp_irq_unmask(struct irq_data *d)
97{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010098 irq_hw_number_t hwirq = irqd_to_hwirq(d);
99
Gregory CLEMENT7f23f622013-03-20 16:09:35 +0100100 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100101 writel(hwirq, main_int_base +
102 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
103 else
104 writel(hwirq, per_cpu_int_base +
105 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200106}
107
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200108#ifdef CONFIG_PCI_MSI
109
110static int armada_370_xp_alloc_msi(void)
111{
112 int hwirq;
113
114 mutex_lock(&msi_used_lock);
115 hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR);
116 if (hwirq >= PCI_MSI_DOORBELL_NR)
117 hwirq = -ENOSPC;
118 else
119 set_bit(hwirq, msi_used);
120 mutex_unlock(&msi_used_lock);
121
122 return hwirq;
123}
124
125static void armada_370_xp_free_msi(int hwirq)
126{
127 mutex_lock(&msi_used_lock);
128 if (!test_bit(hwirq, msi_used))
129 pr_err("trying to free unused MSI#%d\n", hwirq);
130 else
131 clear_bit(hwirq, msi_used);
132 mutex_unlock(&msi_used_lock);
133}
134
Yijing Wangc2791b82014-11-11 17:45:45 -0700135static int armada_370_xp_setup_msi_irq(struct msi_controller *chip,
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200136 struct pci_dev *pdev,
137 struct msi_desc *desc)
138{
139 struct msi_msg msg;
Thomas Petazzonida343fc2014-04-18 14:19:47 +0200140 int virq, hwirq;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200141
Alexander Gordeev39301152014-09-07 20:57:54 +0200142 /* We support MSI, but not MSI-X */
143 if (desc->msi_attrib.is_msix)
144 return -EINVAL;
145
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200146 hwirq = armada_370_xp_alloc_msi();
147 if (hwirq < 0)
148 return hwirq;
149
150 virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq);
151 if (!virq) {
152 armada_370_xp_free_msi(hwirq);
153 return -EINVAL;
154 }
155
156 irq_set_msi_desc(virq, desc);
157
158 msg.address_lo = msi_doorbell_addr;
159 msg.address_hi = 0;
160 msg.data = 0xf00 | (hwirq + 16);
161
Jiang Liu83a18912014-11-09 23:10:34 +0800162 pci_write_msi_msg(virq, &msg);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200163 return 0;
164}
165
Yijing Wangc2791b82014-11-11 17:45:45 -0700166static void armada_370_xp_teardown_msi_irq(struct msi_controller *chip,
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200167 unsigned int irq)
168{
169 struct irq_data *d = irq_get_irq_data(irq);
Neil Greatorexff3c6642014-04-18 14:19:49 +0200170 unsigned long hwirq = d->hwirq;
171
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200172 irq_dispose_mapping(irq);
Neil Greatorexff3c6642014-04-18 14:19:49 +0200173 armada_370_xp_free_msi(hwirq);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200174}
175
176static struct irq_chip armada_370_xp_msi_irq_chip = {
177 .name = "armada_370_xp_msi_irq",
Thomas Gleixner280510f2014-11-23 12:23:20 +0100178 .irq_enable = pci_msi_unmask_irq,
179 .irq_disable = pci_msi_mask_irq,
180 .irq_mask = pci_msi_mask_irq,
181 .irq_unmask = pci_msi_unmask_irq,
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200182};
183
184static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq,
185 irq_hw_number_t hw)
186{
187 irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip,
188 handle_simple_irq);
189 set_irq_flags(virq, IRQF_VALID);
190
191 return 0;
192}
193
194static const struct irq_domain_ops armada_370_xp_msi_irq_ops = {
195 .map = armada_370_xp_msi_map,
196};
197
198static int armada_370_xp_msi_init(struct device_node *node,
199 phys_addr_t main_int_phys_base)
200{
Yijing Wangc2791b82014-11-11 17:45:45 -0700201 struct msi_controller *msi_chip;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200202 u32 reg;
203 int ret;
204
205 msi_doorbell_addr = main_int_phys_base +
206 ARMADA_370_XP_SW_TRIG_INT_OFFS;
207
208 msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL);
209 if (!msi_chip)
210 return -ENOMEM;
211
212 msi_chip->setup_irq = armada_370_xp_setup_msi_irq;
213 msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq;
214 msi_chip->of_node = node;
215
216 armada_370_xp_msi_domain =
217 irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR,
218 &armada_370_xp_msi_irq_ops,
219 NULL);
220 if (!armada_370_xp_msi_domain) {
221 kfree(msi_chip);
222 return -ENOMEM;
223 }
224
225 ret = of_pci_msi_chip_add(msi_chip);
226 if (ret < 0) {
227 irq_domain_remove(armada_370_xp_msi_domain);
228 kfree(msi_chip);
229 return ret;
230 }
231
232 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS)
233 | PCI_MSI_DOORBELL_MASK;
234
235 writel(reg, per_cpu_int_base +
236 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
237
238 /* Unmask IPI interrupt */
239 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
240
241 return 0;
242}
243#else
244static inline int armada_370_xp_msi_init(struct device_node *node,
245 phys_addr_t main_int_phys_base)
246{
247 return 0;
248}
249#endif
250
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300251#ifdef CONFIG_SMP
Arnaud Ebalard19e61d42014-01-20 22:52:05 +0100252static DEFINE_RAW_SPINLOCK(irq_controller_lock);
253
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300254static int armada_xp_set_affinity(struct irq_data *d,
255 const struct cpumask *mask_val, bool force)
256{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100257 irq_hw_number_t hwirq = irqd_to_hwirq(d);
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000258 unsigned long reg, mask;
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100259 int cpu;
260
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000261 /* Select a single core from the affinity mask which is online */
262 cpu = cpumask_any_and(mask_val, cpu_online_mask);
263 mask = 1UL << cpu_logical_map(cpu);
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100264
265 raw_spin_lock(&irq_controller_lock);
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100266 reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000267 reg = (reg & (~ARMADA_370_XP_INT_SOURCE_CPU_MASK)) | mask;
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100268 writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100269 raw_spin_unlock(&irq_controller_lock);
270
Thomas Petazzoni1dacf192014-10-24 13:59:16 +0200271 return IRQ_SET_MASK_OK;
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300272}
273#endif
274
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200275static struct irq_chip armada_370_xp_irq_chip = {
276 .name = "armada_370_xp_irq",
277 .irq_mask = armada_370_xp_irq_mask,
278 .irq_mask_ack = armada_370_xp_irq_mask,
279 .irq_unmask = armada_370_xp_irq_unmask,
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300280#ifdef CONFIG_SMP
281 .irq_set_affinity = armada_xp_set_affinity,
282#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200283};
284
285static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
286 unsigned int virq, irq_hw_number_t hw)
287{
288 armada_370_xp_irq_mask(irq_get_irq_data(virq));
Gregory CLEMENT600468d2013-04-05 14:32:52 +0200289 if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
290 writel(hw, per_cpu_int_base +
291 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
292 else
293 writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200294 irq_set_status_flags(virq, IRQ_LEVEL);
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100295
Gregory CLEMENT7f23f622013-03-20 16:09:35 +0100296 if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) {
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100297 irq_set_percpu_devid(virq);
298 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
299 handle_percpu_devid_irq);
300
301 } else {
302 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
303 handle_level_irq);
304 }
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200305 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
306
307 return 0;
308}
309
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300310#ifdef CONFIG_SMP
Thomas Petazzonief37d332014-04-14 15:54:01 +0200311static void armada_mpic_send_doorbell(const struct cpumask *mask,
312 unsigned int irq)
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300313{
314 int cpu;
315 unsigned long map = 0;
316
317 /* Convert our logical CPU mask into a physical one. */
318 for_each_cpu(cpu, mask)
319 map |= 1 << cpu_logical_map(cpu);
320
321 /*
322 * Ensure that stores to Normal memory are visible to the
323 * other CPUs before issuing the IPI.
324 */
325 dsb();
326
327 /* submit softirq */
328 writel((map << 8) | irq, main_int_base +
329 ARMADA_370_XP_SW_TRIG_INT_OFFS);
330}
331
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200332static void armada_xp_mpic_smp_cpu_init(void)
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300333{
Thomas Petazzonib73842b2014-05-30 22:18:18 +0200334 u32 control;
335 int nr_irqs, i;
336
337 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
338 nr_irqs = (control >> 2) & 0x3ff;
339
340 for (i = 0; i < nr_irqs; i++)
341 writel(i, per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS);
342
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300343 /* Clear pending IPIs */
344 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
345
346 /* Enable first 8 IPIs */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200347 writel(IPI_DOORBELL_MASK, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300348 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
349
350 /* Unmask IPI interrupt */
351 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
352}
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200353
354static int armada_xp_mpic_secondary_init(struct notifier_block *nfb,
355 unsigned long action, void *hcpu)
356{
357 if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
358 armada_xp_mpic_smp_cpu_init();
359 return NOTIFY_OK;
360}
361
362static struct notifier_block armada_370_xp_mpic_cpu_notifier = {
363 .notifier_call = armada_xp_mpic_secondary_init,
364 .priority = 100,
365};
366
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300367#endif /* CONFIG_SMP */
368
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200369static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
370 .map = armada_370_xp_mpic_irq_map,
371 .xlate = irq_domain_xlate_onecell,
372};
373
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300374#ifdef CONFIG_PCI_MSI
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300375static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300376{
377 u32 msimask, msinr;
378
379 msimask = readl_relaxed(per_cpu_int_base +
380 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
381 & PCI_MSI_DOORBELL_MASK;
382
383 writel(~msimask, per_cpu_int_base +
384 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
385
386 for (msinr = PCI_MSI_DOORBELL_START;
387 msinr < PCI_MSI_DOORBELL_END; msinr++) {
388 int irq;
389
390 if (!(msimask & BIT(msinr)))
391 continue;
392
Marc Zyngiere89c6a02014-08-26 11:03:21 +0100393 if (is_chained) {
394 irq = irq_find_mapping(armada_370_xp_msi_domain,
395 msinr - 16);
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300396 generic_handle_irq(irq);
Marc Zyngiere89c6a02014-08-26 11:03:21 +0100397 } else {
398 irq = msinr - 16;
399 handle_domain_irq(armada_370_xp_msi_domain,
400 irq, regs);
401 }
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300402 }
403}
404#else
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300405static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300406#endif
407
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300408static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
409 struct irq_desc *desc)
410{
411 struct irq_chip *chip = irq_get_chip(irq);
Grzegorz Jaszczyk758e8362014-09-25 13:17:19 +0200412 unsigned long irqmap, irqn, irqsrc, cpuid;
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300413 unsigned int cascade_irq;
414
415 chained_irq_enter(chip, desc);
416
417 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
Grzegorz Jaszczyk758e8362014-09-25 13:17:19 +0200418 cpuid = cpu_logical_map(smp_processor_id());
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300419
420 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
Grzegorz Jaszczyk758e8362014-09-25 13:17:19 +0200421 irqsrc = readl_relaxed(main_int_base +
422 ARMADA_370_XP_INT_SOURCE_CTL(irqn));
423
424 /* Check if the interrupt is not masked on current CPU.
425 * Test IRQ (0-1) and FIQ (8-9) mask bits.
426 */
427 if (!(irqsrc & ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid)))
428 continue;
429
430 if (irqn == 1) {
431 armada_370_xp_handle_msi_irq(NULL, true);
432 continue;
433 }
434
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300435 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
436 generic_handle_irq(cascade_irq);
437 }
438
439 chained_irq_exit(chip, desc);
440}
441
Stephen Boyd8783dd32014-03-04 16:40:30 -0800442static void __exception_irq_entry
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200443armada_370_xp_handle_irq(struct pt_regs *regs)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200444{
445 u32 irqstat, irqnr;
446
447 do {
448 irqstat = readl_relaxed(per_cpu_int_base +
449 ARMADA_370_XP_CPU_INTACK_OFFS);
450 irqnr = irqstat & 0x3FF;
451
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300452 if (irqnr > 1022)
453 break;
454
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200455 if (irqnr > 1) {
Marc Zyngiere89c6a02014-08-26 11:03:21 +0100456 handle_domain_irq(armada_370_xp_mpic_domain,
457 irqnr, regs);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200458 continue;
459 }
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200460
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200461 /* MSI handling */
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300462 if (irqnr == 1)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300463 armada_370_xp_handle_msi_irq(regs, false);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200464
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300465#ifdef CONFIG_SMP
466 /* IPI Handling */
467 if (irqnr == 0) {
468 u32 ipimask, ipinr;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200469
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300470 ipimask = readl_relaxed(per_cpu_int_base +
471 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200472 & IPI_DOORBELL_MASK;
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300473
Lior Amsalema6f089e2013-11-25 17:26:44 +0100474 writel(~ipimask, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300475 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
476
477 /* Handle all pending doorbells */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200478 for (ipinr = IPI_DOORBELL_START;
479 ipinr < IPI_DOORBELL_END; ipinr++) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300480 if (ipimask & (0x1 << ipinr))
481 handle_IPI(ipinr, regs);
482 }
483 continue;
484 }
485#endif
486
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200487 } while (1);
488}
489
Thomas Petazzoni0f077eb2014-11-21 17:00:00 +0100490static int armada_370_xp_mpic_suspend(void)
491{
492 doorbell_mask_reg = readl(per_cpu_int_base +
493 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
494 return 0;
495}
496
497static void armada_370_xp_mpic_resume(void)
498{
499 int nirqs;
500 irq_hw_number_t irq;
501
502 /* Re-enable interrupts */
503 nirqs = (readl(main_int_base + ARMADA_370_XP_INT_CONTROL) >> 2) & 0x3ff;
504 for (irq = 0; irq < nirqs; irq++) {
505 struct irq_data *data;
506 int virq;
507
508 virq = irq_linear_revmap(armada_370_xp_mpic_domain, irq);
509 if (virq == 0)
510 continue;
511
512 if (irq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
513 writel(irq, per_cpu_int_base +
514 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
515 else
516 writel(irq, main_int_base +
517 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
518
519 data = irq_get_irq_data(virq);
520 if (!irqd_irq_disabled(data))
521 armada_370_xp_irq_unmask(data);
522 }
523
524 /* Reconfigure doorbells for IPIs and MSIs */
525 writel(doorbell_mask_reg,
526 per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
527 if (doorbell_mask_reg & IPI_DOORBELL_MASK)
528 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
529 if (doorbell_mask_reg & PCI_MSI_DOORBELL_MASK)
530 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
531}
532
533struct syscore_ops armada_370_xp_mpic_syscore_ops = {
534 .suspend = armada_370_xp_mpic_suspend,
535 .resume = armada_370_xp_mpic_resume,
536};
537
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200538static int __init armada_370_xp_mpic_of_init(struct device_node *node,
539 struct device_node *parent)
540{
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200541 struct resource main_int_res, per_cpu_int_res;
Thomas Petazzonib73842b2014-05-30 22:18:18 +0200542 int parent_irq, nr_irqs, i;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200543 u32 control;
544
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200545 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
546 BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200547
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200548 BUG_ON(!request_mem_region(main_int_res.start,
549 resource_size(&main_int_res),
550 node->full_name));
551 BUG_ON(!request_mem_region(per_cpu_int_res.start,
552 resource_size(&per_cpu_int_res),
553 node->full_name));
554
555 main_int_base = ioremap(main_int_res.start,
556 resource_size(&main_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200557 BUG_ON(!main_int_base);
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200558
559 per_cpu_int_base = ioremap(per_cpu_int_res.start,
560 resource_size(&per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200561 BUG_ON(!per_cpu_int_base);
Gregory CLEMENTd792b1e2012-09-26 18:02:48 +0200562
563 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
Thomas Petazzonib73842b2014-05-30 22:18:18 +0200564 nr_irqs = (control >> 2) & 0x3ff;
565
566 for (i = 0; i < nr_irqs; i++)
567 writel(i, main_int_base + ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
Gregory CLEMENTd792b1e2012-09-26 18:02:48 +0200568
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200569 armada_370_xp_mpic_domain =
Thomas Petazzonib73842b2014-05-30 22:18:18 +0200570 irq_domain_add_linear(node, nr_irqs,
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200571 &armada_370_xp_mpic_irq_ops, NULL);
572
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200573 BUG_ON(!armada_370_xp_mpic_domain);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200574
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200575#ifdef CONFIG_SMP
576 armada_xp_mpic_smp_cpu_init();
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200577#endif
578
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200579 armada_370_xp_msi_init(node, main_int_res.start);
580
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300581 parent_irq = irq_of_parse_and_map(node, 0);
582 if (parent_irq <= 0) {
583 irq_set_default_host(armada_370_xp_mpic_domain);
584 set_handle_irq(armada_370_xp_handle_irq);
Thomas Petazzonief37d332014-04-14 15:54:01 +0200585#ifdef CONFIG_SMP
586 set_smp_cross_call(armada_mpic_send_doorbell);
Thomas Petazzonid7df84b2014-04-14 15:54:02 +0200587 register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier);
Thomas Petazzonief37d332014-04-14 15:54:01 +0200588#endif
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300589 } else {
590 irq_set_chained_handler(parent_irq,
591 armada_370_xp_mpic_handle_cascade_irq);
592 }
Thomas Petazzonib313ada2013-04-09 23:26:16 +0200593
Thomas Petazzoni0f077eb2014-11-21 17:00:00 +0100594 register_syscore_ops(&armada_370_xp_mpic_syscore_ops);
595
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200596 return 0;
597}
598
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200599IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);