2 * Marvell Armada 370 and Armada XP SoC IRQ handling
4 * Copyright (C) 2012 Marvell
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.
16 #include <linux/bits.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/irq.h>
21 #include <linux/interrupt.h>
22 #include <linux/irqchip.h>
23 #include <linux/irqchip/chained_irq.h>
24 #include <linux/cpu.h>
26 #include <linux/of_address.h>
27 #include <linux/of_irq.h>
28 #include <linux/of_pci.h>
29 #include <linux/irqdomain.h>
30 #include <linux/slab.h>
31 #include <linux/syscore_ops.h>
32 #include <linux/msi.h>
33 #include <linux/types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/exception.h>
36 #include <asm/smp_plat.h>
37 #include <asm/mach/irq.h>
40 * Overall diagram of the Armada XP interrupt controller:
46 * +---------------+ +---------------+
48 * | per-CPU | | per-CPU |
49 * | mask/unmask | | mask/unmask |
52 * +---------------+ +---------------+
55 * \\_______________________//
57 * +-------------------+
59 * | Global interrupt |
62 * +-------------------+
68 * The "global interrupt mask/unmask" is modified using the
69 * ARMADA_370_XP_INT_SET_ENABLE_OFFS and
70 * ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS registers, which are relative
73 * The "per-CPU mask/unmask" is modified using the
74 * ARMADA_370_XP_INT_SET_MASK_OFFS and
75 * ARMADA_370_XP_INT_CLEAR_MASK_OFFS registers, which are relative to
76 * "per_cpu_int_base". This base address points to a special address,
77 * which automatically accesses the registers of the current CPU.
79 * The per-CPU mask/unmask can also be adjusted using the global
80 * per-interrupt ARMADA_370_XP_INT_SOURCE_CTL register, which we use
81 * to configure interrupt affinity.
83 * Due to this model, all interrupts need to be mask/unmasked at two
84 * different levels: at the global level and at the per-CPU level.
86 * This driver takes the following approach to deal with this:
88 * - For global interrupts:
90 * At ->map() time, a global interrupt is unmasked at the per-CPU
91 * mask/unmask level. It is therefore unmasked at this level for
92 * the current CPU, running the ->map() code. This allows to have
93 * the interrupt unmasked at this level in non-SMP
94 * configurations. In SMP configurations, the ->set_affinity()
95 * callback is called, which using the
96 * ARMADA_370_XP_INT_SOURCE_CTL() readjusts the per-CPU mask/unmask
99 * The ->mask() and ->unmask() operations only mask/unmask the
100 * interrupt at the "global" level.
102 * So, a global interrupt is enabled at the per-CPU level as soon
103 * as it is mapped. At run time, the masking/unmasking takes place
104 * at the global level.
106 * - For per-CPU interrupts
108 * At ->map() time, a per-CPU interrupt is unmasked at the global
111 * The ->mask() and ->unmask() operations mask/unmask the interrupt
112 * at the per-CPU level.
114 * So, a per-CPU interrupt is enabled at the global level as soon
115 * as it is mapped. At run time, the masking/unmasking takes place
116 * at the per-CPU level.
119 /* Registers relative to main_int_base */
120 #define ARMADA_370_XP_INT_CONTROL (0x00)
121 #define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x04)
122 #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
123 #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
124 #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
125 #define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF
126 #define ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid) ((BIT(0) | BIT(8)) << cpuid)
128 /* Registers relative to per_cpu_int_base */
129 #define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x08)
130 #define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0x0c)
131 #define ARMADA_375_PPI_CAUSE (0x10)
132 #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
133 #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
134 #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
135 #define ARMADA_370_XP_INT_FABRIC_MASK_OFFS (0x54)
136 #define ARMADA_370_XP_INT_CAUSE_PERF(cpu) (1 << cpu)
138 #define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
140 /* IPI and MSI interrupt definitions for IPI platforms */
141 #define IPI_DOORBELL_START (0)
142 #define IPI_DOORBELL_END (8)
143 #define IPI_DOORBELL_MASK 0xFF
144 #define PCI_MSI_DOORBELL_START (16)
145 #define PCI_MSI_DOORBELL_NR (16)
146 #define PCI_MSI_DOORBELL_END (32)
147 #define PCI_MSI_DOORBELL_MASK 0xFFFF0000
149 /* MSI interrupt definitions for non-IPI platforms */
150 #define PCI_MSI_FULL_DOORBELL_START 0
151 #define PCI_MSI_FULL_DOORBELL_NR 32
152 #define PCI_MSI_FULL_DOORBELL_END 32
153 #define PCI_MSI_FULL_DOORBELL_MASK GENMASK(31, 0)
154 #define PCI_MSI_FULL_DOORBELL_SRC0_MASK GENMASK(15, 0)
155 #define PCI_MSI_FULL_DOORBELL_SRC1_MASK GENMASK(31, 16)
157 static void __iomem *per_cpu_int_base;
158 static void __iomem *main_int_base;
159 static struct irq_domain *armada_370_xp_mpic_domain;
160 static u32 doorbell_mask_reg;
161 static int parent_irq;
162 #ifdef CONFIG_PCI_MSI
163 static struct irq_domain *armada_370_xp_msi_domain;
164 static struct irq_domain *armada_370_xp_msi_inner_domain;
165 static DECLARE_BITMAP(msi_used, PCI_MSI_FULL_DOORBELL_NR);
166 static DEFINE_MUTEX(msi_used_lock);
167 static phys_addr_t msi_doorbell_addr;
170 static inline bool is_ipi_available(void)
173 * We distinguish IPI availability in the IC by the IC not having a
174 * parent irq defined. If a parent irq is defined, there is a parent
175 * interrupt controller (e.g. GIC) that takes care of inter-processor
178 return parent_irq <= 0;
181 static inline u32 msi_doorbell_mask(void)
183 return is_ipi_available() ? PCI_MSI_DOORBELL_MASK :
184 PCI_MSI_FULL_DOORBELL_MASK;
187 static inline unsigned int msi_doorbell_start(void)
189 return is_ipi_available() ? PCI_MSI_DOORBELL_START :
190 PCI_MSI_FULL_DOORBELL_START;
193 static inline unsigned int msi_doorbell_size(void)
195 return is_ipi_available() ? PCI_MSI_DOORBELL_NR :
196 PCI_MSI_FULL_DOORBELL_NR;
199 static inline unsigned int msi_doorbell_end(void)
201 return is_ipi_available() ? PCI_MSI_DOORBELL_END :
202 PCI_MSI_FULL_DOORBELL_END;
205 static inline bool is_percpu_irq(irq_hw_number_t irq)
207 if (irq <= ARMADA_370_XP_MAX_PER_CPU_IRQS)
215 * For shared global interrupts, mask/unmask global enable bit
216 * For CPU interrupts, mask/unmask the calling CPU's bit
218 static void armada_370_xp_irq_mask(struct irq_data *d)
220 irq_hw_number_t hwirq = irqd_to_hwirq(d);
222 if (!is_percpu_irq(hwirq))
223 writel(hwirq, main_int_base +
224 ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
226 writel(hwirq, per_cpu_int_base +
227 ARMADA_370_XP_INT_SET_MASK_OFFS);
230 static void armada_370_xp_irq_unmask(struct irq_data *d)
232 irq_hw_number_t hwirq = irqd_to_hwirq(d);
234 if (!is_percpu_irq(hwirq))
235 writel(hwirq, main_int_base +
236 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
238 writel(hwirq, per_cpu_int_base +
239 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
242 #ifdef CONFIG_PCI_MSI
244 static struct irq_chip armada_370_xp_msi_irq_chip = {
246 .irq_mask = pci_msi_mask_irq,
247 .irq_unmask = pci_msi_unmask_irq,
250 static struct msi_domain_info armada_370_xp_msi_domain_info = {
251 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
252 MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX),
253 .chip = &armada_370_xp_msi_irq_chip,
256 static void armada_370_xp_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
258 unsigned int cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
260 msg->address_lo = lower_32_bits(msi_doorbell_addr);
261 msg->address_hi = upper_32_bits(msi_doorbell_addr);
262 msg->data = BIT(cpu + 8) | (data->hwirq + msi_doorbell_start());
265 static int armada_370_xp_msi_set_affinity(struct irq_data *irq_data,
266 const struct cpumask *mask, bool force)
271 cpu = cpumask_any_and(mask, cpu_online_mask);
273 cpu = cpumask_first(mask);
275 if (cpu >= nr_cpu_ids)
278 irq_data_update_effective_affinity(irq_data, cpumask_of(cpu));
280 return IRQ_SET_MASK_OK;
283 static struct irq_chip armada_370_xp_msi_bottom_irq_chip = {
285 .irq_compose_msi_msg = armada_370_xp_compose_msi_msg,
286 .irq_set_affinity = armada_370_xp_msi_set_affinity,
289 static int armada_370_xp_msi_alloc(struct irq_domain *domain, unsigned int virq,
290 unsigned int nr_irqs, void *args)
294 mutex_lock(&msi_used_lock);
295 hwirq = bitmap_find_free_region(msi_used, msi_doorbell_size(),
296 order_base_2(nr_irqs));
297 mutex_unlock(&msi_used_lock);
302 for (i = 0; i < nr_irqs; i++) {
303 irq_domain_set_info(domain, virq + i, hwirq + i,
304 &armada_370_xp_msi_bottom_irq_chip,
305 domain->host_data, handle_simple_irq,
312 static void armada_370_xp_msi_free(struct irq_domain *domain,
313 unsigned int virq, unsigned int nr_irqs)
315 struct irq_data *d = irq_domain_get_irq_data(domain, virq);
317 mutex_lock(&msi_used_lock);
318 bitmap_release_region(msi_used, d->hwirq, order_base_2(nr_irqs));
319 mutex_unlock(&msi_used_lock);
322 static const struct irq_domain_ops armada_370_xp_msi_domain_ops = {
323 .alloc = armada_370_xp_msi_alloc,
324 .free = armada_370_xp_msi_free,
327 static void armada_370_xp_msi_reenable_percpu(void)
331 /* Enable MSI doorbell mask and combined cpu local interrupt */
332 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
333 reg |= msi_doorbell_mask();
334 writel(reg, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
336 /* Unmask local doorbell interrupt */
337 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
340 static int armada_370_xp_msi_init(struct device_node *node,
341 phys_addr_t main_int_phys_base)
343 msi_doorbell_addr = main_int_phys_base +
344 ARMADA_370_XP_SW_TRIG_INT_OFFS;
346 armada_370_xp_msi_inner_domain =
347 irq_domain_add_linear(NULL, msi_doorbell_size(),
348 &armada_370_xp_msi_domain_ops, NULL);
349 if (!armada_370_xp_msi_inner_domain)
352 armada_370_xp_msi_domain =
353 pci_msi_create_irq_domain(of_node_to_fwnode(node),
354 &armada_370_xp_msi_domain_info,
355 armada_370_xp_msi_inner_domain);
356 if (!armada_370_xp_msi_domain) {
357 irq_domain_remove(armada_370_xp_msi_inner_domain);
361 armada_370_xp_msi_reenable_percpu();
363 /* Unmask low 16 MSI irqs on non-IPI platforms */
364 if (!is_ipi_available())
365 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
370 static __maybe_unused void armada_370_xp_msi_reenable_percpu(void) {}
372 static inline int armada_370_xp_msi_init(struct device_node *node,
373 phys_addr_t main_int_phys_base)
379 static void armada_xp_mpic_perf_init(void)
384 * This Performance Counter Overflow interrupt is specific for
385 * Armada 370 and XP. It is not available on Armada 375, 38x and 39x.
387 if (!of_machine_is_compatible("marvell,armada-370-xp"))
390 cpuid = cpu_logical_map(smp_processor_id());
392 /* Enable Performance Counter Overflow interrupts */
393 writel(ARMADA_370_XP_INT_CAUSE_PERF(cpuid),
394 per_cpu_int_base + ARMADA_370_XP_INT_FABRIC_MASK_OFFS);
398 static struct irq_domain *ipi_domain;
400 static void armada_370_xp_ipi_mask(struct irq_data *d)
403 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
404 reg &= ~BIT(d->hwirq);
405 writel(reg, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
408 static void armada_370_xp_ipi_unmask(struct irq_data *d)
411 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
412 reg |= BIT(d->hwirq);
413 writel(reg, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
416 static void armada_370_xp_ipi_send_mask(struct irq_data *d,
417 const struct cpumask *mask)
419 unsigned long map = 0;
422 /* Convert our logical CPU mask into a physical one. */
423 for_each_cpu(cpu, mask)
424 map |= 1 << cpu_logical_map(cpu);
427 * Ensure that stores to Normal memory are visible to the
428 * other CPUs before issuing the IPI.
433 writel((map << 8) | d->hwirq, main_int_base +
434 ARMADA_370_XP_SW_TRIG_INT_OFFS);
437 static void armada_370_xp_ipi_ack(struct irq_data *d)
439 writel(~BIT(d->hwirq), per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
442 static struct irq_chip ipi_irqchip = {
444 .irq_ack = armada_370_xp_ipi_ack,
445 .irq_mask = armada_370_xp_ipi_mask,
446 .irq_unmask = armada_370_xp_ipi_unmask,
447 .ipi_send_mask = armada_370_xp_ipi_send_mask,
450 static int armada_370_xp_ipi_alloc(struct irq_domain *d,
452 unsigned int nr_irqs, void *args)
456 for (i = 0; i < nr_irqs; i++) {
457 irq_set_percpu_devid(virq + i);
458 irq_domain_set_info(d, virq + i, i, &ipi_irqchip,
460 handle_percpu_devid_irq,
467 static void armada_370_xp_ipi_free(struct irq_domain *d,
469 unsigned int nr_irqs)
471 /* Not freeing IPIs */
474 static const struct irq_domain_ops ipi_domain_ops = {
475 .alloc = armada_370_xp_ipi_alloc,
476 .free = armada_370_xp_ipi_free,
479 static void ipi_resume(void)
483 for (i = 0; i < IPI_DOORBELL_END; i++) {
486 irq = irq_find_mapping(ipi_domain, i);
489 if (irq_percpu_is_enabled(irq)) {
491 d = irq_domain_get_irq_data(ipi_domain, irq);
492 armada_370_xp_ipi_unmask(d);
497 static __init void armada_xp_ipi_init(struct device_node *node)
501 ipi_domain = irq_domain_create_linear(of_node_to_fwnode(node),
503 &ipi_domain_ops, NULL);
504 if (WARN_ON(!ipi_domain))
507 irq_domain_update_bus_token(ipi_domain, DOMAIN_BUS_IPI);
508 base_ipi = irq_domain_alloc_irqs(ipi_domain, IPI_DOORBELL_END, NUMA_NO_NODE, NULL);
509 if (WARN_ON(!base_ipi))
512 set_smp_ipi_range(base_ipi, IPI_DOORBELL_END);
515 static int armada_xp_set_affinity(struct irq_data *d,
516 const struct cpumask *mask_val, bool force)
518 irq_hw_number_t hwirq = irqd_to_hwirq(d);
521 /* Select a single core from the affinity mask which is online */
522 cpu = cpumask_any_and(mask_val, cpu_online_mask);
524 atomic_io_modify(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq),
525 ARMADA_370_XP_INT_SOURCE_CPU_MASK,
526 BIT(cpu_logical_map(cpu)));
528 irq_data_update_effective_affinity(d, cpumask_of(cpu));
530 return IRQ_SET_MASK_OK;
533 static void armada_xp_mpic_smp_cpu_init(void)
538 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
539 nr_irqs = (control >> 2) & 0x3ff;
541 for (i = 0; i < nr_irqs; i++)
542 writel(i, per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS);
544 if (!is_ipi_available())
547 /* Disable all IPIs */
548 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
550 /* Clear pending IPIs */
551 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
553 /* Unmask IPI interrupt */
554 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
557 static void armada_xp_mpic_reenable_percpu(void)
561 /* Re-enable per-CPU interrupts that were enabled before suspend */
562 for (irq = 0; irq < ARMADA_370_XP_MAX_PER_CPU_IRQS; irq++) {
563 struct irq_data *data;
566 virq = irq_linear_revmap(armada_370_xp_mpic_domain, irq);
570 data = irq_get_irq_data(virq);
572 if (!irq_percpu_is_enabled(virq))
575 armada_370_xp_irq_unmask(data);
578 if (is_ipi_available())
581 armada_370_xp_msi_reenable_percpu();
584 static int armada_xp_mpic_starting_cpu(unsigned int cpu)
586 armada_xp_mpic_perf_init();
587 armada_xp_mpic_smp_cpu_init();
588 armada_xp_mpic_reenable_percpu();
592 static int mpic_cascaded_starting_cpu(unsigned int cpu)
594 armada_xp_mpic_perf_init();
595 armada_xp_mpic_reenable_percpu();
596 enable_percpu_irq(parent_irq, IRQ_TYPE_NONE);
600 static void armada_xp_mpic_smp_cpu_init(void) {}
601 static void ipi_resume(void) {}
604 static struct irq_chip armada_370_xp_irq_chip = {
606 .irq_mask = armada_370_xp_irq_mask,
607 .irq_mask_ack = armada_370_xp_irq_mask,
608 .irq_unmask = armada_370_xp_irq_unmask,
610 .irq_set_affinity = armada_xp_set_affinity,
612 .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
615 static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
616 unsigned int virq, irq_hw_number_t hw)
618 /* IRQs 0 and 1 cannot be mapped, they are handled internally */
622 armada_370_xp_irq_mask(irq_get_irq_data(virq));
623 if (!is_percpu_irq(hw))
624 writel(hw, per_cpu_int_base +
625 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
627 writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
628 irq_set_status_flags(virq, IRQ_LEVEL);
630 if (is_percpu_irq(hw)) {
631 irq_set_percpu_devid(virq);
632 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
633 handle_percpu_devid_irq);
635 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
637 irqd_set_single_target(irq_desc_get_irq_data(irq_to_desc(virq)));
644 static const struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
645 .map = armada_370_xp_mpic_irq_map,
646 .xlate = irq_domain_xlate_onecell,
649 #ifdef CONFIG_PCI_MSI
650 static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
654 msimask = readl_relaxed(per_cpu_int_base +
655 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
656 msimask &= msi_doorbell_mask();
658 writel(~msimask, per_cpu_int_base +
659 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
661 for (msinr = msi_doorbell_start();
662 msinr < msi_doorbell_end(); msinr++) {
665 if (!(msimask & BIT(msinr)))
668 irq = msinr - msi_doorbell_start();
670 generic_handle_domain_irq(armada_370_xp_msi_inner_domain, irq);
674 static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
677 static void armada_370_xp_mpic_handle_cascade_irq(struct irq_desc *desc)
679 struct irq_chip *chip = irq_desc_get_chip(desc);
680 unsigned long irqmap, irqn, irqsrc, cpuid;
682 chained_irq_enter(chip, desc);
684 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
685 cpuid = cpu_logical_map(smp_processor_id());
687 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
688 irqsrc = readl_relaxed(main_int_base +
689 ARMADA_370_XP_INT_SOURCE_CTL(irqn));
691 /* Check if the interrupt is not masked on current CPU.
692 * Test IRQ (0-1) and FIQ (8-9) mask bits.
694 if (!(irqsrc & ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid)))
697 if (irqn == 0 || irqn == 1) {
698 armada_370_xp_handle_msi_irq(NULL, true);
702 generic_handle_domain_irq(armada_370_xp_mpic_domain, irqn);
705 chained_irq_exit(chip, desc);
708 static void __exception_irq_entry
709 armada_370_xp_handle_irq(struct pt_regs *regs)
714 irqstat = readl_relaxed(per_cpu_int_base +
715 ARMADA_370_XP_CPU_INTACK_OFFS);
716 irqnr = irqstat & 0x3FF;
722 generic_handle_domain_irq(armada_370_xp_mpic_domain,
729 armada_370_xp_handle_msi_irq(regs, false);
734 unsigned long ipimask;
737 ipimask = readl_relaxed(per_cpu_int_base +
738 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
741 for_each_set_bit(ipi, &ipimask, IPI_DOORBELL_END)
742 generic_handle_domain_irq(ipi_domain, ipi);
749 static int armada_370_xp_mpic_suspend(void)
751 doorbell_mask_reg = readl(per_cpu_int_base +
752 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
756 static void armada_370_xp_mpic_resume(void)
762 /* Re-enable interrupts */
763 nirqs = (readl(main_int_base + ARMADA_370_XP_INT_CONTROL) >> 2) & 0x3ff;
764 for (irq = 0; irq < nirqs; irq++) {
765 struct irq_data *data;
768 virq = irq_linear_revmap(armada_370_xp_mpic_domain, irq);
772 data = irq_get_irq_data(virq);
774 if (!is_percpu_irq(irq)) {
775 /* Non per-CPU interrupts */
776 writel(irq, per_cpu_int_base +
777 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
778 if (!irqd_irq_disabled(data))
779 armada_370_xp_irq_unmask(data);
781 /* Per-CPU interrupts */
782 writel(irq, main_int_base +
783 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
786 * Re-enable on the current CPU,
787 * armada_xp_mpic_reenable_percpu() will take
788 * care of secondary CPUs when they come up.
790 if (irq_percpu_is_enabled(virq))
791 armada_370_xp_irq_unmask(data);
795 /* Reconfigure doorbells for IPIs and MSIs */
796 writel(doorbell_mask_reg,
797 per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
799 if (is_ipi_available()) {
800 src0 = doorbell_mask_reg & IPI_DOORBELL_MASK;
801 src1 = doorbell_mask_reg & PCI_MSI_DOORBELL_MASK;
803 src0 = doorbell_mask_reg & PCI_MSI_FULL_DOORBELL_SRC0_MASK;
804 src1 = doorbell_mask_reg & PCI_MSI_FULL_DOORBELL_SRC1_MASK;
808 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
810 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
812 if (is_ipi_available())
816 static struct syscore_ops armada_370_xp_mpic_syscore_ops = {
817 .suspend = armada_370_xp_mpic_suspend,
818 .resume = armada_370_xp_mpic_resume,
821 static int __init armada_370_xp_mpic_of_init(struct device_node *node,
822 struct device_node *parent)
824 struct resource main_int_res, per_cpu_int_res;
828 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
829 BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
831 BUG_ON(!request_mem_region(main_int_res.start,
832 resource_size(&main_int_res),
834 BUG_ON(!request_mem_region(per_cpu_int_res.start,
835 resource_size(&per_cpu_int_res),
838 main_int_base = ioremap(main_int_res.start,
839 resource_size(&main_int_res));
840 BUG_ON(!main_int_base);
842 per_cpu_int_base = ioremap(per_cpu_int_res.start,
843 resource_size(&per_cpu_int_res));
844 BUG_ON(!per_cpu_int_base);
846 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
847 nr_irqs = (control >> 2) & 0x3ff;
849 for (i = 0; i < nr_irqs; i++)
850 writel(i, main_int_base + ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
852 armada_370_xp_mpic_domain =
853 irq_domain_add_linear(node, nr_irqs,
854 &armada_370_xp_mpic_irq_ops, NULL);
855 BUG_ON(!armada_370_xp_mpic_domain);
856 irq_domain_update_bus_token(armada_370_xp_mpic_domain, DOMAIN_BUS_WIRED);
859 * Initialize parent_irq before calling any other functions, since it is
860 * used to distinguish between IPI and non-IPI platforms.
862 parent_irq = irq_of_parse_and_map(node, 0);
864 /* Setup for the boot CPU */
865 armada_xp_mpic_perf_init();
866 armada_xp_mpic_smp_cpu_init();
868 armada_370_xp_msi_init(node, main_int_res.start);
870 if (parent_irq <= 0) {
871 irq_set_default_host(armada_370_xp_mpic_domain);
872 set_handle_irq(armada_370_xp_handle_irq);
874 armada_xp_ipi_init(node);
875 cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_ARMADA_XP_STARTING,
876 "irqchip/armada/ipi:starting",
877 armada_xp_mpic_starting_cpu, NULL);
881 cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_ARMADA_XP_STARTING,
882 "irqchip/armada/cascade:starting",
883 mpic_cascaded_starting_cpu, NULL);
885 irq_set_chained_handler(parent_irq,
886 armada_370_xp_mpic_handle_cascade_irq);
889 register_syscore_ops(&armada_370_xp_mpic_syscore_ops);
894 IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);