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> |
| 29 | #include <linux/msi.h> |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 30 | #include <asm/mach/arch.h> |
| 31 | #include <asm/exception.h> |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 32 | #include <asm/smp_plat.h> |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 33 | #include <asm/mach/irq.h> |
| 34 | |
| 35 | #include "irqchip.h" |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 36 | |
| 37 | /* Interrupt Controller Registers Map */ |
| 38 | #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48) |
| 39 | #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C) |
| 40 | |
Ben Dooks | f3e16cc | 2012-06-04 18:50:12 +0200 | [diff] [blame] | 41 | #define ARMADA_370_XP_INT_CONTROL (0x00) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 42 | #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30) |
| 43 | #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34) |
Gregory CLEMENT | 3202bf0 | 2012-12-05 21:43:23 +0100 | [diff] [blame] | 44 | #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) |
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 | unsigned long reg; |
| 249 | unsigned long new_mask = 0; |
| 250 | unsigned long online_mask = 0; |
| 251 | unsigned long count = 0; |
| 252 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
| 253 | int cpu; |
| 254 | |
| 255 | for_each_cpu(cpu, mask_val) { |
| 256 | new_mask |= 1 << cpu_logical_map(cpu); |
| 257 | count++; |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Forbid mutlicore interrupt affinity |
| 262 | * This is required since the MPIC HW doesn't limit |
| 263 | * several CPUs from acknowledging the same interrupt. |
| 264 | */ |
| 265 | if (count > 1) |
| 266 | return -EINVAL; |
| 267 | |
| 268 | for_each_cpu(cpu, cpu_online_mask) |
| 269 | online_mask |= 1 << cpu_logical_map(cpu); |
| 270 | |
| 271 | raw_spin_lock(&irq_controller_lock); |
| 272 | |
| 273 | reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
| 274 | reg = (reg & (~online_mask)) | new_mask; |
| 275 | writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); |
| 276 | |
| 277 | raw_spin_unlock(&irq_controller_lock); |
| 278 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | #endif |
| 282 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 283 | static struct irq_chip armada_370_xp_irq_chip = { |
| 284 | .name = "armada_370_xp_irq", |
| 285 | .irq_mask = armada_370_xp_irq_mask, |
| 286 | .irq_mask_ack = armada_370_xp_irq_mask, |
| 287 | .irq_unmask = armada_370_xp_irq_unmask, |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 288 | #ifdef CONFIG_SMP |
| 289 | .irq_set_affinity = armada_xp_set_affinity, |
| 290 | #endif |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | static int armada_370_xp_mpic_irq_map(struct irq_domain *h, |
| 294 | unsigned int virq, irq_hw_number_t hw) |
| 295 | { |
| 296 | armada_370_xp_irq_mask(irq_get_irq_data(virq)); |
Gregory CLEMENT | 600468d | 2013-04-05 14:32:52 +0200 | [diff] [blame] | 297 | if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) |
| 298 | writel(hw, per_cpu_int_base + |
| 299 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 300 | else |
| 301 | writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 302 | irq_set_status_flags(virq, IRQ_LEVEL); |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 303 | |
Gregory CLEMENT | 7f23f62 | 2013-03-20 16:09:35 +0100 | [diff] [blame] | 304 | if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) { |
Gregory CLEMENT | 3a6f08a | 2013-01-25 18:32:41 +0100 | [diff] [blame] | 305 | irq_set_percpu_devid(virq); |
| 306 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 307 | handle_percpu_devid_irq); |
| 308 | |
| 309 | } else { |
| 310 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, |
| 311 | handle_level_irq); |
| 312 | } |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 313 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 318 | #ifdef CONFIG_SMP |
Thomas Petazzoni | ef37d33 | 2014-04-14 15:54:01 +0200 | [diff] [blame] | 319 | static void armada_mpic_send_doorbell(const struct cpumask *mask, |
| 320 | unsigned int irq) |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 321 | { |
| 322 | int cpu; |
| 323 | unsigned long map = 0; |
| 324 | |
| 325 | /* Convert our logical CPU mask into a physical one. */ |
| 326 | for_each_cpu(cpu, mask) |
| 327 | map |= 1 << cpu_logical_map(cpu); |
| 328 | |
| 329 | /* |
| 330 | * Ensure that stores to Normal memory are visible to the |
| 331 | * other CPUs before issuing the IPI. |
| 332 | */ |
| 333 | dsb(); |
| 334 | |
| 335 | /* submit softirq */ |
| 336 | writel((map << 8) | irq, main_int_base + |
| 337 | ARMADA_370_XP_SW_TRIG_INT_OFFS); |
| 338 | } |
| 339 | |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame^] | 340 | static void armada_xp_mpic_smp_cpu_init(void) |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 341 | { |
| 342 | /* Clear pending IPIs */ |
| 343 | writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 344 | |
| 345 | /* Enable first 8 IPIs */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 346 | writel(IPI_DOORBELL_MASK, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 347 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); |
| 348 | |
| 349 | /* Unmask IPI interrupt */ |
| 350 | writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); |
| 351 | } |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame^] | 352 | |
| 353 | static int armada_xp_mpic_secondary_init(struct notifier_block *nfb, |
| 354 | unsigned long action, void *hcpu) |
| 355 | { |
| 356 | if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) |
| 357 | armada_xp_mpic_smp_cpu_init(); |
| 358 | return NOTIFY_OK; |
| 359 | } |
| 360 | |
| 361 | static struct notifier_block armada_370_xp_mpic_cpu_notifier = { |
| 362 | .notifier_call = armada_xp_mpic_secondary_init, |
| 363 | .priority = 100, |
| 364 | }; |
| 365 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 366 | #endif /* CONFIG_SMP */ |
| 367 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 368 | static struct irq_domain_ops armada_370_xp_mpic_irq_ops = { |
| 369 | .map = armada_370_xp_mpic_irq_map, |
| 370 | .xlate = irq_domain_xlate_onecell, |
| 371 | }; |
| 372 | |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 373 | #ifdef CONFIG_PCI_MSI |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 374 | 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] | 375 | { |
| 376 | u32 msimask, msinr; |
| 377 | |
| 378 | msimask = readl_relaxed(per_cpu_int_base + |
| 379 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
| 380 | & PCI_MSI_DOORBELL_MASK; |
| 381 | |
| 382 | writel(~msimask, per_cpu_int_base + |
| 383 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 384 | |
| 385 | for (msinr = PCI_MSI_DOORBELL_START; |
| 386 | msinr < PCI_MSI_DOORBELL_END; msinr++) { |
| 387 | int irq; |
| 388 | |
| 389 | if (!(msimask & BIT(msinr))) |
| 390 | continue; |
| 391 | |
| 392 | irq = irq_find_mapping(armada_370_xp_msi_domain, |
| 393 | msinr - 16); |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 394 | |
| 395 | if (is_chained) |
| 396 | generic_handle_irq(irq); |
| 397 | else |
| 398 | handle_IRQ(irq, regs); |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | #else |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 402 | 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] | 403 | #endif |
| 404 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 405 | static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq, |
| 406 | struct irq_desc *desc) |
| 407 | { |
| 408 | struct irq_chip *chip = irq_get_chip(irq); |
| 409 | unsigned long irqmap, irqn; |
| 410 | unsigned int cascade_irq; |
| 411 | |
| 412 | chained_irq_enter(chip, desc); |
| 413 | |
| 414 | irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE); |
| 415 | |
| 416 | if (irqmap & BIT(0)) { |
| 417 | armada_370_xp_handle_msi_irq(NULL, true); |
| 418 | irqmap &= ~BIT(0); |
| 419 | } |
| 420 | |
| 421 | for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) { |
| 422 | cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn); |
| 423 | generic_handle_irq(cascade_irq); |
| 424 | } |
| 425 | |
| 426 | chained_irq_exit(chip, desc); |
| 427 | } |
| 428 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 429 | static void __exception_irq_entry |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 430 | armada_370_xp_handle_irq(struct pt_regs *regs) |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 431 | { |
| 432 | u32 irqstat, irqnr; |
| 433 | |
| 434 | do { |
| 435 | irqstat = readl_relaxed(per_cpu_int_base + |
| 436 | ARMADA_370_XP_CPU_INTACK_OFFS); |
| 437 | irqnr = irqstat & 0x3FF; |
| 438 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 439 | if (irqnr > 1022) |
| 440 | break; |
| 441 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 442 | if (irqnr > 1) { |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 443 | irqnr = irq_find_mapping(armada_370_xp_mpic_domain, |
| 444 | irqnr); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 445 | handle_IRQ(irqnr, regs); |
| 446 | continue; |
| 447 | } |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 448 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 449 | /* MSI handling */ |
Ezequiel Garcia | 9b8cf77 | 2014-02-10 17:00:01 -0300 | [diff] [blame] | 450 | if (irqnr == 1) |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 451 | armada_370_xp_handle_msi_irq(regs, false); |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 452 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 453 | #ifdef CONFIG_SMP |
| 454 | /* IPI Handling */ |
| 455 | if (irqnr == 0) { |
| 456 | u32 ipimask, ipinr; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 457 | |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 458 | ipimask = readl_relaxed(per_cpu_int_base + |
| 459 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 460 | & IPI_DOORBELL_MASK; |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 461 | |
Lior Amsalem | a6f089e | 2013-11-25 17:26:44 +0100 | [diff] [blame] | 462 | writel(~ipimask, per_cpu_int_base + |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 463 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); |
| 464 | |
| 465 | /* Handle all pending doorbells */ |
Thomas Petazzoni | 5ec6901 | 2013-04-09 23:26:17 +0200 | [diff] [blame] | 466 | for (ipinr = IPI_DOORBELL_START; |
| 467 | ipinr < IPI_DOORBELL_END; ipinr++) { |
Gregory CLEMENT | 344e873 | 2012-08-02 11:19:12 +0300 | [diff] [blame] | 468 | if (ipimask & (0x1 << ipinr)) |
| 469 | handle_IPI(ipinr, regs); |
| 470 | } |
| 471 | continue; |
| 472 | } |
| 473 | #endif |
| 474 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 475 | } while (1); |
| 476 | } |
| 477 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 478 | static int __init armada_370_xp_mpic_of_init(struct device_node *node, |
| 479 | struct device_node *parent) |
| 480 | { |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 481 | struct resource main_int_res, per_cpu_int_res; |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 482 | int parent_irq; |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 483 | u32 control; |
| 484 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 485 | BUG_ON(of_address_to_resource(node, 0, &main_int_res)); |
| 486 | BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 487 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 488 | BUG_ON(!request_mem_region(main_int_res.start, |
| 489 | resource_size(&main_int_res), |
| 490 | node->full_name)); |
| 491 | BUG_ON(!request_mem_region(per_cpu_int_res.start, |
| 492 | resource_size(&per_cpu_int_res), |
| 493 | node->full_name)); |
| 494 | |
| 495 | main_int_base = ioremap(main_int_res.start, |
| 496 | resource_size(&main_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 497 | BUG_ON(!main_int_base); |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 498 | |
| 499 | per_cpu_int_base = ioremap(per_cpu_int_res.start, |
| 500 | resource_size(&per_cpu_int_res)); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 501 | BUG_ON(!per_cpu_int_base); |
Gregory CLEMENT | d792b1e | 2012-09-26 18:02:48 +0200 | [diff] [blame] | 502 | |
| 503 | control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL); |
| 504 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 505 | armada_370_xp_mpic_domain = |
| 506 | irq_domain_add_linear(node, (control >> 2) & 0x3ff, |
| 507 | &armada_370_xp_mpic_irq_ops, NULL); |
| 508 | |
Thomas Petazzoni | 627dfcc | 2013-08-09 22:27:10 +0200 | [diff] [blame] | 509 | BUG_ON(!armada_370_xp_mpic_domain); |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 510 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 511 | #ifdef CONFIG_SMP |
| 512 | armada_xp_mpic_smp_cpu_init(); |
| 513 | |
| 514 | /* |
| 515 | * Set the default affinity from all CPUs to the boot cpu. |
| 516 | * This is required since the MPIC doesn't limit several CPUs |
| 517 | * from acknowledging the same interrupt. |
| 518 | */ |
| 519 | cpumask_clear(irq_default_affinity); |
| 520 | cpumask_set_cpu(smp_processor_id(), irq_default_affinity); |
| 521 | |
| 522 | #endif |
| 523 | |
Thomas Petazzoni | 31f614e | 2013-08-09 22:27:11 +0200 | [diff] [blame] | 524 | armada_370_xp_msi_init(node, main_int_res.start); |
| 525 | |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 526 | parent_irq = irq_of_parse_and_map(node, 0); |
| 527 | if (parent_irq <= 0) { |
| 528 | irq_set_default_host(armada_370_xp_mpic_domain); |
| 529 | set_handle_irq(armada_370_xp_handle_irq); |
Thomas Petazzoni | ef37d33 | 2014-04-14 15:54:01 +0200 | [diff] [blame] | 530 | #ifdef CONFIG_SMP |
| 531 | set_smp_cross_call(armada_mpic_send_doorbell); |
Thomas Petazzoni | d7df84b | 2014-04-14 15:54:02 +0200 | [diff] [blame^] | 532 | register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier); |
Thomas Petazzoni | ef37d33 | 2014-04-14 15:54:01 +0200 | [diff] [blame] | 533 | #endif |
Ezequiel Garcia | bc69b8a | 2014-02-10 17:00:02 -0300 | [diff] [blame] | 534 | } else { |
| 535 | irq_set_chained_handler(parent_irq, |
| 536 | armada_370_xp_mpic_handle_cascade_irq); |
| 537 | } |
Thomas Petazzoni | b313ada | 2013-04-09 23:26:16 +0200 | [diff] [blame] | 538 | |
Thomas Petazzoni | 9ae6f74 | 2012-06-13 19:01:28 +0200 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
Thomas Petazzoni | 9339d43 | 2013-04-09 23:26:15 +0200 | [diff] [blame] | 542 | IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init); |