Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 1 | /* |
| 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 Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 21 | #include <linux/irqchip/chained_irq.h> |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 22 | #include <linux/cpu.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 23 | #include <linux/io.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <linux/of_irq.h> |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 26 | #include <linux/of_pci.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 27 | #include <linux/irqdomain.h> |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 28 | #include <linux/slab.h> |
Thomas Petazzoni | 0f077eb | 2014-11-21 17:00:00 +0100 | [diff] [blame] | 29 | #include <linux/syscore_ops.h> |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 30 | #include <linux/msi.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 31 | #include <asm/mach/arch.h> |
| 32 | #include <asm/exception.h> |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 33 | #include <asm/smp_plat.h> |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 34 | #include <asm/mach/irq.h> |
| 35 | |
| 36 | #include "irqchip.h" |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 37 | |
| 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 Dooks | f3e16cc | 2012-06-04 18:50:12 +0200 | [diff] [blame] | 42 | #define ARMADA_370_XP_INT_CONTROL (0x00) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 43 | #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30) |
| 44 | #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 45 | #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame] | 46 | #define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF |
Grzegorz Jaszczyk | 758e836 | 2014-09-25 13:17:19 +0200 | [diff] [blame] | 47 | #define ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid) ((BIT(0) | BIT(8)) << cpuid) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 48 | |
| 49 | #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44) |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 50 | #define ARMADA_375_PPI_CAUSE (0x10) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 51 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 52 | #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 CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 56 | #define ARMADA_370_XP_MAX_PER_CPU_IRQS (28) |
| 57 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 58 | #define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5) |
| 59 | |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 60 | #define IPI_DOORBELL_START (0) |
| 61 | #define IPI_DOORBELL_END (8) |
| 62 | #define IPI_DOORBELL_MASK 0xFF |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 63 | #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 CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 67 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 68 | static void __iomem *per_cpu_int_base; |
| 69 | static void __iomem *main_int_base; |
| 70 | static struct irq_domain *armada_370_xp_mpic_domain; |
Thomas Petazzoni | 0f077eb | 2014-11-21 17:00:00 +0100 | [diff] [blame] | 71 | static u32 doorbell_mask_reg; |
Maxime Ripard | 5724be8 | 2015-03-03 11:27:23 +0100 | [diff] [blame] | 72 | static int parent_irq; |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 73 | #ifdef CONFIG_PCI_MSI |
| 74 | static struct irq_domain *armada_370_xp_msi_domain; |
| 75 | static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR); |
| 76 | static DEFINE_MUTEX(msi_used_lock); |
| 77 | static phys_addr_t msi_doorbell_addr; |
| 78 | #endif |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 79 | |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 80 | /* |
| 81 | * In SMP mode: |
| 82 | * For shared global interrupts, mask/unmask global enable bit |
Marek Belisko | 097ef18 | 2013-03-15 23:34:04 +0100 | [diff] [blame] | 83 | * For CPU interrupts, mask/unmask the calling CPU's bit |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 84 | */ |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 85 | static void armada_370_xp_irq_mask(struct irq_data *d) |
| 86 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 87 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
| 88 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 89 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 90 | writel(hwirq, main_int_base + |
| 91 | ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS); |
| 92 | else |
| 93 | writel(hwirq, per_cpu_int_base + |
| 94 | ARMADA_370_XP_INT_SET_MASK_OFFS); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static void armada_370_xp_irq_unmask(struct irq_data *d) |
| 98 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 99 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
| 100 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 101 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 102 | writel(hwirq, main_int_base + |
| 103 | ARMADA_370_XP_INT_SET_ENABLE_OFFS); |
| 104 | else |
| 105 | writel(hwirq, per_cpu_int_base + |
| 106 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 109 | #ifdef CONFIG_PCI_MSI |
| 110 | |
| 111 | static int armada_370_xp_alloc_msi(void) |
| 112 | { |
| 113 | int hwirq; |
| 114 | |
| 115 | mutex_lock(&msi_used_lock); |
| 116 | hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR); |
| 117 | if (hwirq >= PCI_MSI_DOORBELL_NR) |
| 118 | hwirq = -ENOSPC; |
| 119 | else |
| 120 | set_bit(hwirq, msi_used); |
| 121 | mutex_unlock(&msi_used_lock); |
| 122 | |
| 123 | return hwirq; |
| 124 | } |
| 125 | |
| 126 | static void armada_370_xp_free_msi(int hwirq) |
| 127 | { |
| 128 | mutex_lock(&msi_used_lock); |
| 129 | if (!test_bit(hwirq, msi_used)) |
| 130 | pr_err("trying to free unused MSI#%d\n", hwirq); |
| 131 | else |
| 132 | clear_bit(hwirq, msi_used); |
| 133 | mutex_unlock(&msi_used_lock); |
| 134 | } |
| 135 | |
Yijing Wang | c2791b8 | 2014-11-11 17:45:45 -0700 | [diff] [blame] | 136 | static int armada_370_xp_setup_msi_irq(struct msi_controller *chip, |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 137 | struct pci_dev *pdev, |
| 138 | struct msi_desc *desc) |
| 139 | { |
| 140 | struct msi_msg msg; |
Thomas Petazzoni | da343fc | 2014-04-18 14:19:47 +0200 | [diff] [blame] | 141 | int virq, hwirq; |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 142 | |
Alexander Gordeev | 3930115 | 2014-09-07 20:57:54 +0200 | [diff] [blame] | 143 | /* We support MSI, but not MSI-X */ |
| 144 | if (desc->msi_attrib.is_msix) |
| 145 | return -EINVAL; |
| 146 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 147 | hwirq = armada_370_xp_alloc_msi(); |
| 148 | if (hwirq < 0) |
| 149 | return hwirq; |
| 150 | |
| 151 | virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq); |
| 152 | if (!virq) { |
| 153 | armada_370_xp_free_msi(hwirq); |
| 154 | return -EINVAL; |
| 155 | } |
| 156 | |
| 157 | irq_set_msi_desc(virq, desc); |
| 158 | |
| 159 | msg.address_lo = msi_doorbell_addr; |
| 160 | msg.address_hi = 0; |
| 161 | msg.data = 0xf00 | (hwirq + 16); |
| 162 | |
Jiang Liu | 83a1891 | 2014-11-09 23:10:34 +0800 | [diff] [blame] | 163 | pci_write_msi_msg(virq, &msg); |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
Yijing Wang | c2791b8 | 2014-11-11 17:45:45 -0700 | [diff] [blame] | 167 | static void armada_370_xp_teardown_msi_irq(struct msi_controller *chip, |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 168 | unsigned int irq) |
| 169 | { |
| 170 | struct irq_data *d = irq_get_irq_data(irq); |
Neil Greatorex | ff3c664 | 2014-04-18 14:19:49 +0200 | [diff] [blame] | 171 | unsigned long hwirq = d->hwirq; |
| 172 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 173 | irq_dispose_mapping(irq); |
Neil Greatorex | ff3c664 | 2014-04-18 14:19:49 +0200 | [diff] [blame] | 174 | armada_370_xp_free_msi(hwirq); |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static struct irq_chip armada_370_xp_msi_irq_chip = { |
| 178 | .name = "armada_370_xp_msi_irq", |
Thomas Gleixner | 280510f | 2014-11-23 12:23:20 +0100 | [diff] [blame] | 179 | .irq_enable = pci_msi_unmask_irq, |
| 180 | .irq_disable = pci_msi_mask_irq, |
| 181 | .irq_mask = pci_msi_mask_irq, |
| 182 | .irq_unmask = pci_msi_unmask_irq, |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq, |
| 186 | irq_hw_number_t hw) |
| 187 | { |
| 188 | irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip, |
| 189 | handle_simple_irq); |
| 190 | set_irq_flags(virq, IRQF_VALID); |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static const struct irq_domain_ops armada_370_xp_msi_irq_ops = { |
| 196 | .map = armada_370_xp_msi_map, |
| 197 | }; |
| 198 | |
| 199 | static int armada_370_xp_msi_init(struct device_node *node, |
| 200 | phys_addr_t main_int_phys_base) |
| 201 | { |
Yijing Wang | c2791b8 | 2014-11-11 17:45:45 -0700 | [diff] [blame] | 202 | struct msi_controller *msi_chip; |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 203 | u32 reg; |
| 204 | int ret; |
| 205 | |
| 206 | msi_doorbell_addr = main_int_phys_base + |
| 207 | ARMADA_370_XP_SW_TRIG_INT_OFFS; |
| 208 | |
| 209 | msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL); |
| 210 | if (!msi_chip) |
| 211 | return -ENOMEM; |
| 212 | |
| 213 | msi_chip->setup_irq = armada_370_xp_setup_msi_irq; |
| 214 | msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq; |
| 215 | msi_chip->of_node = node; |
| 216 | |
| 217 | armada_370_xp_msi_domain = |
| 218 | irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR, |
| 219 | &armada_370_xp_msi_irq_ops, |
| 220 | NULL); |
| 221 | if (!armada_370_xp_msi_domain) { |
| 222 | kfree(msi_chip); |
| 223 | return -ENOMEM; |
| 224 | } |
| 225 | |
| 226 | ret = of_pci_msi_chip_add(msi_chip); |
| 227 | if (ret < 0) { |
| 228 | irq_domain_remove(armada_370_xp_msi_domain); |
| 229 | kfree(msi_chip); |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS) |
| 234 | | PCI_MSI_DOORBELL_MASK; |
| 235 | |
| 236 | writel(reg, per_cpu_int_base + |
| 237 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 238 | |
| 239 | /* Unmask IPI interrupt */ |
| 240 | writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | #else |
| 245 | static inline int armada_370_xp_msi_init(struct device_node *node, |
| 246 | phys_addr_t main_int_phys_base) |
| 247 | { |
| 248 | return 0; |
| 249 | } |
| 250 | #endif |
| 251 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 252 | #ifdef CONFIG_SMP |
Arnaud Ebalard | 19e61d4 | 2014-01-20 22:52:05 +0100 | [diff] [blame] | 253 | static DEFINE_RAW_SPINLOCK(irq_controller_lock); |
| 254 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 255 | static int armada_xp_set_affinity(struct irq_data *d, |
| 256 | const struct cpumask *mask_val, bool force) |
| 257 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 258 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame] | 259 | unsigned long reg, mask; |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 260 | int cpu; |
| 261 | |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame] | 262 | /* Select a single core from the affinity mask which is online */ |
| 263 | cpu = cpumask_any_and(mask_val, cpu_online_mask); |
| 264 | mask = 1UL << cpu_logical_map(cpu); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 265 | |
| 266 | raw_spin_lock(&irq_controller_lock); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 267 | reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame] | 268 | reg = (reg & (~ARMADA_370_XP_INT_SOURCE_CPU_MASK)) | mask; |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 269 | writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 270 | raw_spin_unlock(&irq_controller_lock); |
| 271 | |
Thomas Petazzoni | 1dacf19 | 2014-10-24 13:59:16 +0200 | [diff] [blame] | 272 | return IRQ_SET_MASK_OK; |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 273 | } |
| 274 | #endif |
| 275 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 276 | static struct irq_chip armada_370_xp_irq_chip = { |
| 277 | .name = "armada_370_xp_irq", |
| 278 | .irq_mask = armada_370_xp_irq_mask, |
| 279 | .irq_mask_ack = armada_370_xp_irq_mask, |
| 280 | .irq_unmask = armada_370_xp_irq_unmask, |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 281 | #ifdef CONFIG_SMP |
| 282 | .irq_set_affinity = armada_xp_set_affinity, |
| 283 | #endif |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | static int armada_370_xp_mpic_irq_map(struct irq_domain *h, |
| 287 | unsigned int virq, irq_hw_number_t hw) |
| 288 | { |
| 289 | armada_370_xp_irq_mask(irq_get_irq_data(virq)); |
Gregory CLEMENT | 600468d | 2013-04-05 14:32:52 +0200 | [diff] [blame] | 290 | if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
| 291 | writel(hw, per_cpu_int_base + |
| 292 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 293 | else |
| 294 | writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 295 | irq_set_status_flags(virq, IRQ_LEVEL); |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 296 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 297 | if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) { |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 298 | irq_set_percpu_devid(virq); |
| 299 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 300 | handle_percpu_devid_irq); |
| 301 | |
| 302 | } else { |
| 303 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 304 | handle_level_irq); |
| 305 | } |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 306 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 311 | static void armada_xp_mpic_smp_cpu_init(void) |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 312 | { |
Thomas Petazzoni | b73842b | 2014-05-30 22:18:18 +0200 | [diff] [blame] | 313 | u32 control; |
| 314 | int nr_irqs, i; |
| 315 | |
| 316 | control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL); |
| 317 | nr_irqs = (control >> 2) & 0x3ff; |
| 318 | |
| 319 | for (i = 0; i < nr_irqs; i++) |
| 320 | writel(i, per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS); |
| 321 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 322 | /* Clear pending IPIs */ |
| 323 | writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 324 | |
| 325 | /* Enable first 8 IPIs */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 326 | writel(IPI_DOORBELL_MASK, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 327 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 328 | |
| 329 | /* Unmask IPI interrupt */ |
| 330 | writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 331 | } |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 332 | |
Ezequiel Garcia | 933a24b | 2015-03-03 11:43:14 +0100 | [diff] [blame^] | 333 | #ifdef CONFIG_SMP |
| 334 | static void armada_mpic_send_doorbell(const struct cpumask *mask, |
| 335 | unsigned int irq) |
| 336 | { |
| 337 | int cpu; |
| 338 | unsigned long map = 0; |
| 339 | |
| 340 | /* Convert our logical CPU mask into a physical one. */ |
| 341 | for_each_cpu(cpu, mask) |
| 342 | map |= 1 << cpu_logical_map(cpu); |
| 343 | |
| 344 | /* |
| 345 | * Ensure that stores to Normal memory are visible to the |
| 346 | * other CPUs before issuing the IPI. |
| 347 | */ |
| 348 | dsb(); |
| 349 | |
| 350 | /* submit softirq */ |
| 351 | writel((map << 8) | irq, main_int_base + |
| 352 | ARMADA_370_XP_SW_TRIG_INT_OFFS); |
| 353 | } |
| 354 | |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 355 | static int armada_xp_mpic_secondary_init(struct notifier_block *nfb, |
| 356 | unsigned long action, void *hcpu) |
| 357 | { |
| 358 | if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) |
| 359 | armada_xp_mpic_smp_cpu_init(); |
Maxime Ripard | 5724be8 | 2015-03-03 11:27:23 +0100 | [diff] [blame] | 360 | |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 361 | return NOTIFY_OK; |
| 362 | } |
| 363 | |
| 364 | static struct notifier_block armada_370_xp_mpic_cpu_notifier = { |
| 365 | .notifier_call = armada_xp_mpic_secondary_init, |
| 366 | .priority = 100, |
| 367 | }; |
| 368 | |
Maxime Ripard | 5724be8 | 2015-03-03 11:27:23 +0100 | [diff] [blame] | 369 | static int mpic_cascaded_secondary_init(struct notifier_block *nfb, |
| 370 | unsigned long action, void *hcpu) |
| 371 | { |
| 372 | if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) |
| 373 | enable_percpu_irq(parent_irq, IRQ_TYPE_NONE); |
| 374 | |
| 375 | return NOTIFY_OK; |
| 376 | } |
| 377 | |
| 378 | static struct notifier_block mpic_cascaded_cpu_notifier = { |
| 379 | .notifier_call = mpic_cascaded_secondary_init, |
| 380 | .priority = 100, |
| 381 | }; |
| 382 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 383 | #endif /* CONFIG_SMP */ |
| 384 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 385 | static struct irq_domain_ops armada_370_xp_mpic_irq_ops = { |
| 386 | .map = armada_370_xp_mpic_irq_map, |
| 387 | .xlate = irq_domain_xlate_onecell, |
| 388 | }; |
| 389 | |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 390 | #ifdef CONFIG_PCI_MSI |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 391 | static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained) |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 392 | { |
| 393 | u32 msimask, msinr; |
| 394 | |
| 395 | msimask = readl_relaxed(per_cpu_int_base + |
| 396 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
| 397 | & PCI_MSI_DOORBELL_MASK; |
| 398 | |
| 399 | writel(~msimask, per_cpu_int_base + |
| 400 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 401 | |
| 402 | for (msinr = PCI_MSI_DOORBELL_START; |
| 403 | msinr < PCI_MSI_DOORBELL_END; msinr++) { |
| 404 | int irq; |
| 405 | |
| 406 | if (!(msimask & BIT(msinr))) |
| 407 | continue; |
| 408 | |
Marc Zyngier | e89c6a0 | 2014-08-26 11:03:21 +0100 | [diff] [blame] | 409 | if (is_chained) { |
| 410 | irq = irq_find_mapping(armada_370_xp_msi_domain, |
| 411 | msinr - 16); |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 412 | generic_handle_irq(irq); |
Marc Zyngier | e89c6a0 | 2014-08-26 11:03:21 +0100 | [diff] [blame] | 413 | } else { |
| 414 | irq = msinr - 16; |
| 415 | handle_domain_irq(armada_370_xp_msi_domain, |
| 416 | irq, regs); |
| 417 | } |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | #else |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 421 | static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {} |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 422 | #endif |
| 423 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 424 | static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq, |
| 425 | struct irq_desc *desc) |
| 426 | { |
| 427 | struct irq_chip *chip = irq_get_chip(irq); |
Grzegorz Jaszczyk | 758e836 | 2014-09-25 13:17:19 +0200 | [diff] [blame] | 428 | unsigned long irqmap, irqn, irqsrc, cpuid; |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 429 | unsigned int cascade_irq; |
| 430 | |
| 431 | chained_irq_enter(chip, desc); |
| 432 | |
| 433 | irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE); |
Grzegorz Jaszczyk | 758e836 | 2014-09-25 13:17:19 +0200 | [diff] [blame] | 434 | cpuid = cpu_logical_map(smp_processor_id()); |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 435 | |
| 436 | for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) { |
Grzegorz Jaszczyk | 758e836 | 2014-09-25 13:17:19 +0200 | [diff] [blame] | 437 | irqsrc = readl_relaxed(main_int_base + |
| 438 | ARMADA_370_XP_INT_SOURCE_CTL(irqn)); |
| 439 | |
| 440 | /* Check if the interrupt is not masked on current CPU. |
| 441 | * Test IRQ (0-1) and FIQ (8-9) mask bits. |
| 442 | */ |
| 443 | if (!(irqsrc & ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid))) |
| 444 | continue; |
| 445 | |
| 446 | if (irqn == 1) { |
| 447 | armada_370_xp_handle_msi_irq(NULL, true); |
| 448 | continue; |
| 449 | } |
| 450 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 451 | cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn); |
| 452 | generic_handle_irq(cascade_irq); |
| 453 | } |
| 454 | |
| 455 | chained_irq_exit(chip, desc); |
| 456 | } |
| 457 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 458 | static void __exception_irq_entry |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 459 | armada_370_xp_handle_irq(struct pt_regs *regs) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 460 | { |
| 461 | u32 irqstat, irqnr; |
| 462 | |
| 463 | do { |
| 464 | irqstat = readl_relaxed(per_cpu_int_base + |
| 465 | ARMADA_370_XP_CPU_INTACK_OFFS); |
| 466 | irqnr = irqstat & 0x3FF; |
| 467 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 468 | if (irqnr > 1022) |
| 469 | break; |
| 470 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 471 | if (irqnr > 1) { |
Marc Zyngier | e89c6a0 | 2014-08-26 11:03:21 +0100 | [diff] [blame] | 472 | handle_domain_irq(armada_370_xp_mpic_domain, |
| 473 | irqnr, regs); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 474 | continue; |
| 475 | } |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 476 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 477 | /* MSI handling */ |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 478 | if (irqnr == 1) |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 479 | armada_370_xp_handle_msi_irq(regs, false); |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 480 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 481 | #ifdef CONFIG_SMP |
| 482 | /* IPI Handling */ |
| 483 | if (irqnr == 0) { |
| 484 | u32 ipimask, ipinr; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 485 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 486 | ipimask = readl_relaxed(per_cpu_int_base + |
| 487 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 488 | & IPI_DOORBELL_MASK; |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 489 | |
Lior Amsalem | a6f089e | 2013-11-25 17:26:44 +0100 | [diff] [blame] | 490 | writel(~ipimask, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 491 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 492 | |
| 493 | /* Handle all pending doorbells */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 494 | for (ipinr = IPI_DOORBELL_START; |
| 495 | ipinr < IPI_DOORBELL_END; ipinr++) { |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 496 | if (ipimask & (0x1 << ipinr)) |
| 497 | handle_IPI(ipinr, regs); |
| 498 | } |
| 499 | continue; |
| 500 | } |
| 501 | #endif |
| 502 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 503 | } while (1); |
| 504 | } |
| 505 | |
Thomas Petazzoni | 0f077eb | 2014-11-21 17:00:00 +0100 | [diff] [blame] | 506 | static int armada_370_xp_mpic_suspend(void) |
| 507 | { |
| 508 | doorbell_mask_reg = readl(per_cpu_int_base + |
| 509 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | static void armada_370_xp_mpic_resume(void) |
| 514 | { |
| 515 | int nirqs; |
| 516 | irq_hw_number_t irq; |
| 517 | |
| 518 | /* Re-enable interrupts */ |
| 519 | nirqs = (readl(main_int_base + ARMADA_370_XP_INT_CONTROL) >> 2) & 0x3ff; |
| 520 | for (irq = 0; irq < nirqs; irq++) { |
| 521 | struct irq_data *data; |
| 522 | int virq; |
| 523 | |
| 524 | virq = irq_linear_revmap(armada_370_xp_mpic_domain, irq); |
| 525 | if (virq == 0) |
| 526 | continue; |
| 527 | |
| 528 | if (irq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
| 529 | writel(irq, per_cpu_int_base + |
| 530 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 531 | else |
| 532 | writel(irq, main_int_base + |
| 533 | ARMADA_370_XP_INT_SET_ENABLE_OFFS); |
| 534 | |
| 535 | data = irq_get_irq_data(virq); |
| 536 | if (!irqd_irq_disabled(data)) |
| 537 | armada_370_xp_irq_unmask(data); |
| 538 | } |
| 539 | |
| 540 | /* Reconfigure doorbells for IPIs and MSIs */ |
| 541 | writel(doorbell_mask_reg, |
| 542 | per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 543 | if (doorbell_mask_reg & IPI_DOORBELL_MASK) |
| 544 | writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 545 | if (doorbell_mask_reg & PCI_MSI_DOORBELL_MASK) |
| 546 | writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 547 | } |
| 548 | |
| 549 | struct syscore_ops armada_370_xp_mpic_syscore_ops = { |
| 550 | .suspend = armada_370_xp_mpic_suspend, |
| 551 | .resume = armada_370_xp_mpic_resume, |
| 552 | }; |
| 553 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 554 | static int __init armada_370_xp_mpic_of_init(struct device_node *node, |
| 555 | struct device_node *parent) |
| 556 | { |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 557 | struct resource main_int_res, per_cpu_int_res; |
Maxime Ripard | 5724be8 | 2015-03-03 11:27:23 +0100 | [diff] [blame] | 558 | int nr_irqs, i; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 559 | u32 control; |
| 560 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 561 | BUG_ON(of_address_to_resource(node, 0, &main_int_res)); |
| 562 | BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 563 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 564 | BUG_ON(!request_mem_region(main_int_res.start, |
| 565 | resource_size(&main_int_res), |
| 566 | node->full_name)); |
| 567 | BUG_ON(!request_mem_region(per_cpu_int_res.start, |
| 568 | resource_size(&per_cpu_int_res), |
| 569 | node->full_name)); |
| 570 | |
| 571 | main_int_base = ioremap(main_int_res.start, |
| 572 | resource_size(&main_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 573 | BUG_ON(!main_int_base); |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 574 | |
| 575 | per_cpu_int_base = ioremap(per_cpu_int_res.start, |
| 576 | resource_size(&per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 577 | BUG_ON(!per_cpu_int_base); |
Gregory CLEMENT | d792b1e | 2012-09-26 18:02:48 +0200 | [diff] [blame] | 578 | |
| 579 | control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL); |
Thomas Petazzoni | b73842b | 2014-05-30 22:18:18 +0200 | [diff] [blame] | 580 | nr_irqs = (control >> 2) & 0x3ff; |
| 581 | |
| 582 | for (i = 0; i < nr_irqs; i++) |
| 583 | writel(i, main_int_base + ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS); |
Gregory CLEMENT | d792b1e | 2012-09-26 18:02:48 +0200 | [diff] [blame] | 584 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 585 | armada_370_xp_mpic_domain = |
Thomas Petazzoni | b73842b | 2014-05-30 22:18:18 +0200 | [diff] [blame] | 586 | irq_domain_add_linear(node, nr_irqs, |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 587 | &armada_370_xp_mpic_irq_ops, NULL); |
| 588 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 589 | BUG_ON(!armada_370_xp_mpic_domain); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 590 | |
Ezequiel Garcia | 933a24b | 2015-03-03 11:43:14 +0100 | [diff] [blame^] | 591 | /* Setup for the boot CPU */ |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 592 | armada_xp_mpic_smp_cpu_init(); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 593 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 594 | armada_370_xp_msi_init(node, main_int_res.start); |
| 595 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 596 | parent_irq = irq_of_parse_and_map(node, 0); |
| 597 | if (parent_irq <= 0) { |
| 598 | irq_set_default_host(armada_370_xp_mpic_domain); |
| 599 | set_handle_irq(armada_370_xp_handle_irq); |
Thomas Petazzoni | ef37d33 | 2014-04-14 15:54:01 +0200 | [diff] [blame] | 600 | #ifdef CONFIG_SMP |
| 601 | set_smp_cross_call(armada_mpic_send_doorbell); |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame] | 602 | register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier); |
Thomas Petazzoni | ef37d33 | 2014-04-14 15:54:01 +0200 | [diff] [blame] | 603 | #endif |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 604 | } else { |
Maxime Ripard | 5724be8 | 2015-03-03 11:27:23 +0100 | [diff] [blame] | 605 | #ifdef CONFIG_SMP |
| 606 | register_cpu_notifier(&mpic_cascaded_cpu_notifier); |
| 607 | #endif |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 608 | irq_set_chained_handler(parent_irq, |
| 609 | armada_370_xp_mpic_handle_cascade_irq); |
| 610 | } |
Thomas Petazzoni | b313ada | 2013-04-09 23:26:16 +0200 | [diff] [blame] | 611 | |
Thomas Petazzoni | 0f077eb | 2014-11-21 17:00:00 +0100 | [diff] [blame] | 612 | register_syscore_ops(&armada_370_xp_mpic_syscore_ops); |
| 613 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 614 | return 0; |
| 615 | } |
| 616 | |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 617 | IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init); |