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 | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 22 | #include <linux/io.h> |
| 23 | #include <linux/of_address.h> |
| 24 | #include <linux/of_irq.h> |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 25 | #include <linux/of_pci.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 26 | #include <linux/irqdomain.h> |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/msi.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/exception.h> |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 31 | #include <asm/smp_plat.h> |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 32 | #include <asm/mach/irq.h> |
| 33 | |
| 34 | #include "irqchip.h" |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 35 | |
| 36 | /* Interrupt Controller Registers Map */ |
| 37 | #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48) |
| 38 | #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C) |
| 39 | |
Ben Dooks | f3e16cc | 2012-06-04 18:50:12 +0200 | [diff] [blame] | 40 | #define ARMADA_370_XP_INT_CONTROL (0x00) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 41 | #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30) |
| 42 | #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 43 | #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame^] | 44 | #define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 45 | |
| 46 | #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44) |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 47 | #define ARMADA_375_PPI_CAUSE (0x10) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 48 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 49 | #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 CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 53 | #define ARMADA_370_XP_MAX_PER_CPU_IRQS (28) |
| 54 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 55 | #define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5) |
| 56 | |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 57 | #define IPI_DOORBELL_START (0) |
| 58 | #define IPI_DOORBELL_END (8) |
| 59 | #define IPI_DOORBELL_MASK 0xFF |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 60 | #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 CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 64 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 65 | static void __iomem *per_cpu_int_base; |
| 66 | static void __iomem *main_int_base; |
| 67 | static struct irq_domain *armada_370_xp_mpic_domain; |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 68 | #ifdef CONFIG_PCI_MSI |
| 69 | static struct irq_domain *armada_370_xp_msi_domain; |
| 70 | static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR); |
| 71 | static DEFINE_MUTEX(msi_used_lock); |
| 72 | static phys_addr_t msi_doorbell_addr; |
| 73 | #endif |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 74 | |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 75 | /* |
| 76 | * In SMP mode: |
| 77 | * For shared global interrupts, mask/unmask global enable bit |
Marek Belisko | 097ef18 | 2013-03-15 23:34:04 +0100 | [diff] [blame] | 78 | * For CPU interrupts, mask/unmask the calling CPU's bit |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 79 | */ |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 80 | static void armada_370_xp_irq_mask(struct irq_data *d) |
| 81 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 82 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
| 83 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 84 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 85 | 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 Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void armada_370_xp_irq_unmask(struct irq_data *d) |
| 93 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 94 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
| 95 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 96 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 97 | 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 Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_PCI_MSI |
| 105 | |
| 106 | static 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 | |
| 121 | static 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 | |
| 131 | static 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 | |
| 159 | static 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 | |
| 167 | static 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 | |
| 175 | static 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 | |
| 185 | static const struct irq_domain_ops armada_370_xp_msi_irq_ops = { |
| 186 | .map = armada_370_xp_msi_map, |
| 187 | }; |
| 188 | |
| 189 | static 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 |
| 235 | static 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 CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 242 | #ifdef CONFIG_SMP |
Arnaud Ebalard | 19e61d4 | 2014-01-20 22:52:05 +0100 | [diff] [blame] | 243 | static DEFINE_RAW_SPINLOCK(irq_controller_lock); |
| 244 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 245 | static int armada_xp_set_affinity(struct irq_data *d, |
| 246 | const struct cpumask *mask_val, bool force) |
| 247 | { |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 248 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame^] | 249 | unsigned long reg, mask; |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 250 | int cpu; |
| 251 | |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame^] | 252 | /* Select a single core from the affinity mask which is online */ |
| 253 | cpu = cpumask_any_and(mask_val, cpu_online_mask); |
| 254 | mask = 1UL << cpu_logical_map(cpu); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 255 | |
| 256 | raw_spin_lock(&irq_controller_lock); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 257 | reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
Thomas Gleixner | 8cc3cfc | 2014-03-04 20:43:41 +0000 | [diff] [blame^] | 258 | reg = (reg & (~ARMADA_370_XP_INT_SOURCE_CPU_MASK)) | mask; |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 259 | writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 260 | raw_spin_unlock(&irq_controller_lock); |
| 261 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | #endif |
| 265 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 266 | static struct irq_chip armada_370_xp_irq_chip = { |
| 267 | .name = "armada_370_xp_irq", |
| 268 | .irq_mask = armada_370_xp_irq_mask, |
| 269 | .irq_mask_ack = armada_370_xp_irq_mask, |
| 270 | .irq_unmask = armada_370_xp_irq_unmask, |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 271 | #ifdef CONFIG_SMP |
| 272 | .irq_set_affinity = armada_xp_set_affinity, |
| 273 | #endif |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | static int armada_370_xp_mpic_irq_map(struct irq_domain *h, |
| 277 | unsigned int virq, irq_hw_number_t hw) |
| 278 | { |
| 279 | armada_370_xp_irq_mask(irq_get_irq_data(virq)); |
Gregory CLEMENT | 600468d | 2013-04-05 14:32:52 +0200 | [diff] [blame] | 280 | if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
| 281 | writel(hw, per_cpu_int_base + |
| 282 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 283 | else |
| 284 | writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 285 | irq_set_status_flags(virq, IRQ_LEVEL); |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 286 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 287 | if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) { |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 288 | irq_set_percpu_devid(virq); |
| 289 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 290 | handle_percpu_devid_irq); |
| 291 | |
| 292 | } else { |
| 293 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 294 | handle_level_irq); |
| 295 | } |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 296 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 301 | #ifdef CONFIG_SMP |
| 302 | void armada_mpic_send_doorbell(const struct cpumask *mask, unsigned int irq) |
| 303 | { |
| 304 | int cpu; |
| 305 | unsigned long map = 0; |
| 306 | |
| 307 | /* Convert our logical CPU mask into a physical one. */ |
| 308 | for_each_cpu(cpu, mask) |
| 309 | map |= 1 << cpu_logical_map(cpu); |
| 310 | |
| 311 | /* |
| 312 | * Ensure that stores to Normal memory are visible to the |
| 313 | * other CPUs before issuing the IPI. |
| 314 | */ |
| 315 | dsb(); |
| 316 | |
| 317 | /* submit softirq */ |
| 318 | writel((map << 8) | irq, main_int_base + |
| 319 | ARMADA_370_XP_SW_TRIG_INT_OFFS); |
| 320 | } |
| 321 | |
| 322 | void armada_xp_mpic_smp_cpu_init(void) |
| 323 | { |
| 324 | /* Clear pending IPIs */ |
| 325 | writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 326 | |
| 327 | /* Enable first 8 IPIs */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 328 | writel(IPI_DOORBELL_MASK, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 329 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 330 | |
| 331 | /* Unmask IPI interrupt */ |
| 332 | writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 333 | } |
| 334 | #endif /* CONFIG_SMP */ |
| 335 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 336 | static struct irq_domain_ops armada_370_xp_mpic_irq_ops = { |
| 337 | .map = armada_370_xp_mpic_irq_map, |
| 338 | .xlate = irq_domain_xlate_onecell, |
| 339 | }; |
| 340 | |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 341 | #ifdef CONFIG_PCI_MSI |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 342 | 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] | 343 | { |
| 344 | u32 msimask, msinr; |
| 345 | |
| 346 | msimask = readl_relaxed(per_cpu_int_base + |
| 347 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
| 348 | & PCI_MSI_DOORBELL_MASK; |
| 349 | |
| 350 | writel(~msimask, per_cpu_int_base + |
| 351 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 352 | |
| 353 | for (msinr = PCI_MSI_DOORBELL_START; |
| 354 | msinr < PCI_MSI_DOORBELL_END; msinr++) { |
| 355 | int irq; |
| 356 | |
| 357 | if (!(msimask & BIT(msinr))) |
| 358 | continue; |
| 359 | |
| 360 | irq = irq_find_mapping(armada_370_xp_msi_domain, |
| 361 | msinr - 16); |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 362 | |
| 363 | if (is_chained) |
| 364 | generic_handle_irq(irq); |
| 365 | else |
| 366 | handle_IRQ(irq, regs); |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | #else |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 370 | 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] | 371 | #endif |
| 372 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 373 | static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq, |
| 374 | struct irq_desc *desc) |
| 375 | { |
| 376 | struct irq_chip *chip = irq_get_chip(irq); |
| 377 | unsigned long irqmap, irqn; |
| 378 | unsigned int cascade_irq; |
| 379 | |
| 380 | chained_irq_enter(chip, desc); |
| 381 | |
| 382 | irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE); |
| 383 | |
| 384 | if (irqmap & BIT(0)) { |
| 385 | armada_370_xp_handle_msi_irq(NULL, true); |
| 386 | irqmap &= ~BIT(0); |
| 387 | } |
| 388 | |
| 389 | for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) { |
| 390 | cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn); |
| 391 | generic_handle_irq(cascade_irq); |
| 392 | } |
| 393 | |
| 394 | chained_irq_exit(chip, desc); |
| 395 | } |
| 396 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 397 | static void __exception_irq_entry |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 398 | armada_370_xp_handle_irq(struct pt_regs *regs) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 399 | { |
| 400 | u32 irqstat, irqnr; |
| 401 | |
| 402 | do { |
| 403 | irqstat = readl_relaxed(per_cpu_int_base + |
| 404 | ARMADA_370_XP_CPU_INTACK_OFFS); |
| 405 | irqnr = irqstat & 0x3FF; |
| 406 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 407 | if (irqnr > 1022) |
| 408 | break; |
| 409 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 410 | if (irqnr > 1) { |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 411 | irqnr = irq_find_mapping(armada_370_xp_mpic_domain, |
| 412 | irqnr); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 413 | handle_IRQ(irqnr, regs); |
| 414 | continue; |
| 415 | } |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 416 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 417 | /* MSI handling */ |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 418 | if (irqnr == 1) |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 419 | armada_370_xp_handle_msi_irq(regs, false); |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 420 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 421 | #ifdef CONFIG_SMP |
| 422 | /* IPI Handling */ |
| 423 | if (irqnr == 0) { |
| 424 | u32 ipimask, ipinr; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 425 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 426 | ipimask = readl_relaxed(per_cpu_int_base + |
| 427 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 428 | & IPI_DOORBELL_MASK; |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 429 | |
Lior Amsalem | a6f089e | 2013-11-25 17:26:44 +0100 | [diff] [blame] | 430 | writel(~ipimask, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 431 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 432 | |
| 433 | /* Handle all pending doorbells */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 434 | for (ipinr = IPI_DOORBELL_START; |
| 435 | ipinr < IPI_DOORBELL_END; ipinr++) { |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 436 | if (ipimask & (0x1 << ipinr)) |
| 437 | handle_IPI(ipinr, regs); |
| 438 | } |
| 439 | continue; |
| 440 | } |
| 441 | #endif |
| 442 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 443 | } while (1); |
| 444 | } |
| 445 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 446 | static int __init armada_370_xp_mpic_of_init(struct device_node *node, |
| 447 | struct device_node *parent) |
| 448 | { |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 449 | struct resource main_int_res, per_cpu_int_res; |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 450 | int parent_irq; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 451 | u32 control; |
| 452 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 453 | BUG_ON(of_address_to_resource(node, 0, &main_int_res)); |
| 454 | BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 455 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 456 | BUG_ON(!request_mem_region(main_int_res.start, |
| 457 | resource_size(&main_int_res), |
| 458 | node->full_name)); |
| 459 | BUG_ON(!request_mem_region(per_cpu_int_res.start, |
| 460 | resource_size(&per_cpu_int_res), |
| 461 | node->full_name)); |
| 462 | |
| 463 | main_int_base = ioremap(main_int_res.start, |
| 464 | resource_size(&main_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 465 | BUG_ON(!main_int_base); |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 466 | |
| 467 | per_cpu_int_base = ioremap(per_cpu_int_res.start, |
| 468 | resource_size(&per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 469 | BUG_ON(!per_cpu_int_base); |
Gregory CLEMENT | d792b1e | 2012-09-26 18:02:48 +0200 | [diff] [blame] | 470 | |
| 471 | control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL); |
| 472 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 473 | armada_370_xp_mpic_domain = |
| 474 | irq_domain_add_linear(node, (control >> 2) & 0x3ff, |
| 475 | &armada_370_xp_mpic_irq_ops, NULL); |
| 476 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 477 | BUG_ON(!armada_370_xp_mpic_domain); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 478 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 479 | #ifdef CONFIG_SMP |
| 480 | armada_xp_mpic_smp_cpu_init(); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 481 | #endif |
| 482 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 483 | armada_370_xp_msi_init(node, main_int_res.start); |
| 484 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 485 | parent_irq = irq_of_parse_and_map(node, 0); |
| 486 | if (parent_irq <= 0) { |
| 487 | irq_set_default_host(armada_370_xp_mpic_domain); |
| 488 | set_handle_irq(armada_370_xp_handle_irq); |
| 489 | } else { |
| 490 | irq_set_chained_handler(parent_irq, |
| 491 | armada_370_xp_mpic_handle_cascade_irq); |
| 492 | } |
Thomas Petazzoni | b313ada | 2013-04-09 23:26:16 +0200 | [diff] [blame] | 493 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 497 | IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init); |