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