Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/common/gic.c |
| 3 | * |
| 4 | * Copyright (C) 2002 ARM Limited, All Rights Reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * Interrupt architecture for the GIC: |
| 11 | * |
| 12 | * o There is one Interrupt Distributor, which receives interrupts |
| 13 | * from system devices and sends them to the Interrupt Controllers. |
| 14 | * |
| 15 | * o There is one CPU Interface per CPU, which sends interrupts sent |
| 16 | * by the Distributor, and interrupts generated locally, to the |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 17 | * associated CPU. The base address of the CPU interface is usually |
| 18 | * aliased so that the same address points to different chips depending |
| 19 | * on the CPU it is accessed from. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 20 | * |
| 21 | * Note that IRQs 0-31 are special - they are local to each CPU. |
| 22 | * As such, the enable set/clear, pending set/clear and active bit |
| 23 | * registers are banked per-cpu for these sources. |
| 24 | */ |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/kernel.h> |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 27 | #include <linux/err.h> |
Arnd Bergmann | 4f87410 | 2011-11-01 00:28:37 +0100 | [diff] [blame] | 28 | #include <linux/module.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 29 | #include <linux/list.h> |
| 30 | #include <linux/smp.h> |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 31 | #include <linux/cpu_pm.h> |
Catalin Marinas | dcb86e8 | 2005-08-31 21:45:14 +0100 | [diff] [blame] | 32 | #include <linux/cpumask.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 33 | #include <linux/io.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | #include <linux/syscore_ops.h> |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 35 | #include <linux/of.h> |
| 36 | #include <linux/of_address.h> |
| 37 | #include <linux/of_irq.h> |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 38 | #include <linux/irqdomain.h> |
Trilok Soni | eecb28c | 2011-07-20 16:24:14 +0100 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
| 40 | #include <linux/percpu.h> |
| 41 | #include <linux/slab.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 42 | |
| 43 | #include <asm/irq.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 44 | #include <asm/mach/irq.h> |
| 45 | #include <asm/hardware/gic.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | #include <asm/system.h> |
Trilok Soni | eecb28c | 2011-07-20 16:24:14 +0100 | [diff] [blame] | 47 | #include <asm/localtimer.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 48 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 49 | union gic_base { |
| 50 | void __iomem *common_base; |
| 51 | void __percpu __iomem **percpu_base; |
| 52 | }; |
| 53 | |
| 54 | struct gic_chip_data { |
| 55 | unsigned int irq_offset; |
| 56 | union gic_base dist_base; |
| 57 | union gic_base cpu_base; |
| 58 | unsigned int max_irq; |
| 59 | #ifdef CONFIG_PM |
| 60 | unsigned int wakeup_irqs[32]; |
| 61 | unsigned int enabled_irqs[32]; |
| 62 | #endif |
| 63 | #ifdef CONFIG_CPU_PM |
| 64 | u32 saved_spi_enable[DIV_ROUND_UP(1020, 32)]; |
| 65 | u32 saved_spi_conf[DIV_ROUND_UP(1020, 16)]; |
| 66 | u32 saved_spi_target[DIV_ROUND_UP(1020, 4)]; |
| 67 | u32 __percpu *saved_ppi_enable; |
| 68 | u32 __percpu *saved_ppi_conf; |
| 69 | #endif |
| 70 | #ifdef CONFIG_IRQ_DOMAIN |
| 71 | struct irq_domain domain; |
| 72 | #endif |
| 73 | unsigned int gic_irqs; |
| 74 | #ifdef CONFIG_GIC_NON_BANKED |
| 75 | void __iomem *(*get_base)(union gic_base *); |
| 76 | #endif |
| 77 | }; |
| 78 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 79 | static DEFINE_RAW_SPINLOCK(irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 80 | |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 81 | /* Address of GIC 0 CPU interface */ |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 82 | void __iomem *gic_cpu_base_addr __read_mostly; |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 83 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 84 | /* |
| 85 | * Supported arch specific GIC irq extension. |
| 86 | * Default make them NULL. |
| 87 | */ |
| 88 | struct irq_chip gic_arch_extn = { |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 89 | .irq_eoi = NULL, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 90 | .irq_mask = NULL, |
| 91 | .irq_unmask = NULL, |
| 92 | .irq_retrigger = NULL, |
| 93 | .irq_set_type = NULL, |
| 94 | .irq_set_wake = NULL, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | .irq_disable = NULL, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 98 | #ifndef MAX_GIC_NR |
| 99 | #define MAX_GIC_NR 1 |
| 100 | #endif |
| 101 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 102 | static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 103 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 104 | #ifdef CONFIG_GIC_NON_BANKED |
| 105 | static void __iomem *gic_get_percpu_base(union gic_base *base) |
| 106 | { |
| 107 | return *__this_cpu_ptr(base->percpu_base); |
| 108 | } |
| 109 | |
| 110 | static void __iomem *gic_get_common_base(union gic_base *base) |
| 111 | { |
| 112 | return base->common_base; |
| 113 | } |
| 114 | |
| 115 | static inline void __iomem *gic_data_dist_base(struct gic_chip_data *data) |
| 116 | { |
| 117 | return data->get_base(&data->dist_base); |
| 118 | } |
| 119 | |
| 120 | static inline void __iomem *gic_data_cpu_base(struct gic_chip_data *data) |
| 121 | { |
| 122 | return data->get_base(&data->cpu_base); |
| 123 | } |
| 124 | |
| 125 | static inline void gic_set_base_accessor(struct gic_chip_data *data, |
| 126 | void __iomem *(*f)(union gic_base *)) |
| 127 | { |
| 128 | data->get_base = f; |
| 129 | } |
| 130 | #else |
| 131 | #define gic_data_dist_base(d) ((d)->dist_base.common_base) |
| 132 | #define gic_data_cpu_base(d) ((d)->cpu_base.common_base) |
| 133 | #define gic_set_base_accessor(d,f) |
| 134 | #endif |
| 135 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 136 | static inline void __iomem *gic_dist_base(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 137 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 138 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 139 | return gic_data_dist_base(gic_data); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 142 | static inline void __iomem *gic_cpu_base(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 143 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 144 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 145 | return gic_data_cpu_base(gic_data); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 148 | static inline unsigned int gic_irq(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 149 | { |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 150 | return d->hwirq; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 153 | /* |
| 154 | * Routines to acknowledge, disable and enable interrupts |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 155 | */ |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 156 | static void gic_mask_irq(struct irq_data *d) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 157 | { |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 158 | u32 mask = 1 << (gic_irq(d) % 32); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 159 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 160 | raw_spin_lock(&irq_controller_lock); |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 161 | writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4); |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 162 | if (gic_arch_extn.irq_mask) |
| 163 | gic_arch_extn.irq_mask(d); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 164 | raw_spin_unlock(&irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 167 | static void gic_unmask_irq(struct irq_data *d) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 168 | { |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 169 | u32 mask = 1 << (gic_irq(d) % 32); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 170 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 171 | raw_spin_lock(&irq_controller_lock); |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 172 | if (gic_arch_extn.irq_unmask) |
| 173 | gic_arch_extn.irq_unmask(d); |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 174 | writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 175 | raw_spin_unlock(&irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | static void gic_disable_irq(struct irq_data *d) |
| 179 | { |
| 180 | if (gic_arch_extn.irq_disable) |
| 181 | gic_arch_extn.irq_disable(d); |
| 182 | } |
| 183 | |
| 184 | #ifdef CONFIG_PM |
| 185 | static int gic_suspend_one(struct gic_chip_data *gic) |
| 186 | { |
| 187 | unsigned int i; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 188 | void __iomem *base = gic_data_dist_base(gic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 189 | |
| 190 | for (i = 0; i * 32 < gic->max_irq; i++) { |
| 191 | gic->enabled_irqs[i] |
| 192 | = readl_relaxed(base + GIC_DIST_ENABLE_SET + i * 4); |
| 193 | /* disable all of them */ |
| 194 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 195 | /* enable the wakeup set */ |
| 196 | writel_relaxed(gic->wakeup_irqs[i], |
| 197 | base + GIC_DIST_ENABLE_SET + i * 4); |
| 198 | } |
| 199 | mb(); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int gic_suspend(void) |
| 204 | { |
| 205 | int i; |
| 206 | for (i = 0; i < MAX_GIC_NR; i++) |
| 207 | gic_suspend_one(&gic_data[i]); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | extern int msm_show_resume_irq_mask; |
| 212 | |
| 213 | static void gic_show_resume_irq(struct gic_chip_data *gic) |
| 214 | { |
| 215 | unsigned int i; |
| 216 | u32 enabled; |
| 217 | unsigned long pending[32]; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 218 | void __iomem *base = gic_data_dist_base(gic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | |
| 220 | if (!msm_show_resume_irq_mask) |
| 221 | return; |
| 222 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 223 | raw_spin_lock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | for (i = 0; i * 32 < gic->max_irq; i++) { |
| 225 | enabled = readl_relaxed(base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 226 | pending[i] = readl_relaxed(base + GIC_DIST_PENDING_SET + i * 4); |
| 227 | pending[i] &= enabled; |
| 228 | } |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 229 | raw_spin_unlock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | |
| 231 | for (i = find_first_bit(pending, gic->max_irq); |
| 232 | i < gic->max_irq; |
| 233 | i = find_next_bit(pending, gic->max_irq, i+1)) { |
| 234 | pr_warning("%s: %d triggered", __func__, |
| 235 | i + gic->irq_offset); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | static void gic_resume_one(struct gic_chip_data *gic) |
| 240 | { |
| 241 | unsigned int i; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 242 | void __iomem *base = gic_data_dist_base(gic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 243 | |
| 244 | gic_show_resume_irq(gic); |
| 245 | for (i = 0; i * 32 < gic->max_irq; i++) { |
| 246 | /* disable all of them */ |
| 247 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 248 | /* enable the enabled set */ |
| 249 | writel_relaxed(gic->enabled_irqs[i], |
| 250 | base + GIC_DIST_ENABLE_SET + i * 4); |
| 251 | } |
| 252 | mb(); |
| 253 | } |
| 254 | |
| 255 | static void gic_resume(void) |
| 256 | { |
| 257 | int i; |
| 258 | for (i = 0; i < MAX_GIC_NR; i++) |
| 259 | gic_resume_one(&gic_data[i]); |
| 260 | } |
| 261 | |
| 262 | static struct syscore_ops gic_syscore_ops = { |
| 263 | .suspend = gic_suspend, |
| 264 | .resume = gic_resume, |
| 265 | }; |
| 266 | |
| 267 | static int __init gic_init_sys(void) |
| 268 | { |
| 269 | register_syscore_ops(&gic_syscore_ops); |
| 270 | return 0; |
| 271 | } |
| 272 | arch_initcall(gic_init_sys); |
| 273 | |
| 274 | #endif |
| 275 | |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 276 | static void gic_eoi_irq(struct irq_data *d) |
| 277 | { |
| 278 | if (gic_arch_extn.irq_eoi) { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 279 | raw_spin_lock(&irq_controller_lock); |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 280 | gic_arch_extn.irq_eoi(d); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 281 | raw_spin_unlock(&irq_controller_lock); |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 284 | writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 287 | static int gic_set_type(struct irq_data *d, unsigned int type) |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 288 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 289 | void __iomem *base = gic_dist_base(d); |
| 290 | unsigned int gicirq = gic_irq(d); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 291 | u32 enablemask = 1 << (gicirq % 32); |
| 292 | u32 enableoff = (gicirq / 32) * 4; |
| 293 | u32 confmask = 0x2 << ((gicirq % 16) * 2); |
| 294 | u32 confoff = (gicirq / 16) * 4; |
| 295 | bool enabled = false; |
| 296 | u32 val; |
| 297 | |
| 298 | /* Interrupt configuration for SGIs can't be changed */ |
| 299 | if (gicirq < 16) |
| 300 | return -EINVAL; |
| 301 | |
| 302 | if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING) |
| 303 | return -EINVAL; |
| 304 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 305 | raw_spin_lock(&irq_controller_lock); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 306 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 307 | if (gic_arch_extn.irq_set_type) |
| 308 | gic_arch_extn.irq_set_type(d, type); |
| 309 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 310 | val = readl_relaxed(base + GIC_DIST_CONFIG + confoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 311 | if (type == IRQ_TYPE_LEVEL_HIGH) |
| 312 | val &= ~confmask; |
| 313 | else if (type == IRQ_TYPE_EDGE_RISING) |
| 314 | val |= confmask; |
| 315 | |
| 316 | /* |
| 317 | * As recommended by the spec, disable the interrupt before changing |
| 318 | * the configuration |
| 319 | */ |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 320 | if (readl_relaxed(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) { |
| 321 | writel_relaxed(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 322 | enabled = true; |
| 323 | } |
| 324 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 325 | writel_relaxed(val, base + GIC_DIST_CONFIG + confoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 326 | |
| 327 | if (enabled) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 328 | writel_relaxed(enablemask, base + GIC_DIST_ENABLE_SET + enableoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 329 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 330 | raw_spin_unlock(&irq_controller_lock); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 335 | static int gic_retrigger(struct irq_data *d) |
| 336 | { |
| 337 | if (gic_arch_extn.irq_retrigger) |
| 338 | return gic_arch_extn.irq_retrigger(d); |
| 339 | |
Abhijeet Dharmapurikar | 9d44ea0 | 2011-10-30 16:47:19 -0700 | [diff] [blame] | 340 | /* the retrigger expects 0 for failure */ |
| 341 | return 0; |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 344 | #ifdef CONFIG_SMP |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 345 | static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 346 | bool force) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 347 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 348 | void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3); |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 349 | unsigned int shift = (gic_irq(d) % 4) * 8; |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 350 | unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask); |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 351 | u32 val, mask, bit; |
| 352 | |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 353 | if (cpu >= 8 || cpu >= nr_cpu_ids) |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 354 | return -EINVAL; |
| 355 | |
| 356 | mask = 0xff << shift; |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 357 | bit = 1 << (cpu_logical_map(cpu) + shift); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 358 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 359 | raw_spin_lock(&irq_controller_lock); |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 360 | val = readl_relaxed(reg) & ~mask; |
| 361 | writel_relaxed(val | bit, reg); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 362 | raw_spin_unlock(&irq_controller_lock); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 363 | |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 364 | return IRQ_SET_MASK_OK; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 365 | } |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 366 | #endif |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 367 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 368 | #ifdef CONFIG_PM |
| 369 | static int gic_set_wake(struct irq_data *d, unsigned int on) |
| 370 | { |
| 371 | int ret = -ENXIO; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | unsigned int reg_offset, bit_offset; |
| 373 | unsigned int gicirq = gic_irq(d); |
| 374 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
| 375 | |
| 376 | /* per-cpu interrupts cannot be wakeup interrupts */ |
| 377 | WARN_ON(gicirq < 32); |
| 378 | |
| 379 | reg_offset = gicirq / 32; |
| 380 | bit_offset = gicirq % 32; |
| 381 | |
| 382 | if (on) |
| 383 | gic_data->wakeup_irqs[reg_offset] |= 1 << bit_offset; |
| 384 | else |
| 385 | gic_data->wakeup_irqs[reg_offset] &= ~(1 << bit_offset); |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 386 | |
| 387 | if (gic_arch_extn.irq_set_wake) |
| 388 | ret = gic_arch_extn.irq_set_wake(d, on); |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | #else |
Rohit Vaswani | 550aa1a | 2011-10-06 21:15:37 -0700 | [diff] [blame] | 394 | static int gic_set_wake(struct irq_data *d, unsigned int on) |
| 395 | { |
| 396 | return 0; |
| 397 | } |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 398 | #endif |
| 399 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 400 | static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 401 | { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 402 | struct gic_chip_data *chip_data = irq_get_handler_data(irq); |
| 403 | struct irq_chip *chip = irq_get_chip(irq); |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 404 | unsigned int cascade_irq, gic_irq; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 405 | unsigned long status; |
| 406 | |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 407 | chained_irq_enter(chip, desc); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 408 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 409 | raw_spin_lock(&irq_controller_lock); |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 410 | status = readl_relaxed(gic_data_cpu_base(chip_data) + GIC_CPU_INTACK); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 411 | raw_spin_unlock(&irq_controller_lock); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 412 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 413 | gic_irq = (status & 0x3ff); |
| 414 | if (gic_irq == 1023) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 415 | goto out; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 416 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 417 | cascade_irq = irq_domain_to_irq(&chip_data->domain, gic_irq); |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 418 | if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS)) |
| 419 | do_bad_IRQ(cascade_irq, desc); |
| 420 | else |
| 421 | generic_handle_irq(cascade_irq); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 422 | |
| 423 | out: |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 424 | chained_irq_exit(chip, desc); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 425 | } |
| 426 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 427 | static struct irq_chip gic_chip = { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 428 | .name = "GIC", |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 429 | .irq_mask = gic_mask_irq, |
| 430 | .irq_unmask = gic_unmask_irq, |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 431 | .irq_eoi = gic_eoi_irq, |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 432 | .irq_set_type = gic_set_type, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 433 | .irq_retrigger = gic_retrigger, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 434 | #ifdef CONFIG_SMP |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 435 | .irq_set_affinity = gic_set_affinity, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 436 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 437 | .irq_disable = gic_disable_irq, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 438 | .irq_set_wake = gic_set_wake, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 439 | }; |
| 440 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 441 | void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq) |
| 442 | { |
| 443 | if (gic_nr >= MAX_GIC_NR) |
| 444 | BUG(); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 445 | if (irq_set_handler_data(irq, &gic_data[gic_nr]) != 0) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 446 | BUG(); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 447 | irq_set_chained_handler(irq, gic_handle_cascade_irq); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 448 | } |
| 449 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 450 | static void __init gic_dist_init(struct gic_chip_data *gic) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 451 | { |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 452 | unsigned int i, irq; |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 453 | u32 cpumask; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 454 | unsigned int gic_irqs = gic->gic_irqs; |
| 455 | struct irq_domain *domain = &gic->domain; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 456 | void __iomem *base = gic_data_dist_base(gic); |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 457 | u32 cpu = 0; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 458 | |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 459 | #ifdef CONFIG_SMP |
| 460 | cpu = cpu_logical_map(smp_processor_id()); |
| 461 | #endif |
| 462 | |
| 463 | cpumask = 1 << cpu; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 464 | cpumask |= cpumask << 8; |
| 465 | cpumask |= cpumask << 16; |
| 466 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 467 | writel_relaxed(0, base + GIC_DIST_CTRL); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 468 | |
| 469 | /* |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 470 | * Set all global interrupts to be level triggered, active low. |
| 471 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 472 | for (i = 32; i < gic_irqs; i += 16) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 473 | writel_relaxed(0, base + GIC_DIST_CONFIG + i * 4 / 16); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * Set all global interrupts to this CPU only. |
| 477 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 478 | for (i = 32; i < gic_irqs; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 479 | writel_relaxed(cpumask, base + GIC_DIST_TARGET + i * 4 / 4); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 480 | |
| 481 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 482 | * Set priority on all global interrupts. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 483 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 484 | for (i = 32; i < gic_irqs; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 485 | writel_relaxed(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 486 | |
| 487 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 488 | * Disable all interrupts. Leave the PPI and SGIs alone |
| 489 | * as these enables are banked registers. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 490 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 491 | for (i = 32; i < gic_irqs; i += 32) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 492 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * Setup the Linux IRQ subsystem. |
| 496 | */ |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 497 | irq_domain_for_each_irq(domain, i, irq) { |
| 498 | if (i < 32) { |
| 499 | irq_set_percpu_devid(irq); |
| 500 | irq_set_chip_and_handler(irq, &gic_chip, |
| 501 | handle_percpu_devid_irq); |
| 502 | set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN); |
| 503 | } else { |
| 504 | irq_set_chip_and_handler(irq, &gic_chip, |
| 505 | handle_fasteoi_irq); |
| 506 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 507 | } |
| 508 | irq_set_chip_data(irq, gic); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 511 | gic->max_irq = gic_irqs; |
| 512 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 513 | writel_relaxed(1, base + GIC_DIST_CTRL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 514 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 517 | static void __cpuinit gic_cpu_init(struct gic_chip_data *gic) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 518 | { |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 519 | void __iomem *dist_base = gic_data_dist_base(gic); |
| 520 | void __iomem *base = gic_data_cpu_base(gic); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 521 | int i; |
| 522 | |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 523 | /* |
| 524 | * Deal with the banked PPI and SGI interrupts - disable all |
| 525 | * PPI interrupts, ensure all SGI interrupts are enabled. |
| 526 | */ |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 527 | writel_relaxed(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR); |
| 528 | writel_relaxed(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 529 | |
| 530 | /* |
| 531 | * Set priority on PPI and SGI interrupts |
| 532 | */ |
| 533 | for (i = 0; i < 32; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 534 | writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 535 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 536 | writel_relaxed(0xf0, base + GIC_CPU_PRIMASK); |
| 537 | writel_relaxed(1, base + GIC_CPU_CTRL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 538 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 541 | #ifdef CONFIG_CPU_PM |
| 542 | /* |
| 543 | * Saves the GIC distributor registers during suspend or idle. Must be called |
| 544 | * with interrupts disabled but before powering down the GIC. After calling |
| 545 | * this function, no interrupts will be delivered by the GIC, and another |
| 546 | * platform-specific wakeup source must be enabled. |
| 547 | */ |
| 548 | static void gic_dist_save(unsigned int gic_nr) |
| 549 | { |
| 550 | unsigned int gic_irqs; |
| 551 | void __iomem *dist_base; |
| 552 | int i; |
| 553 | |
| 554 | if (gic_nr >= MAX_GIC_NR) |
| 555 | BUG(); |
| 556 | |
| 557 | gic_irqs = gic_data[gic_nr].gic_irqs; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 558 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 559 | |
| 560 | if (!dist_base) |
| 561 | return; |
| 562 | |
| 563 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++) |
| 564 | gic_data[gic_nr].saved_spi_conf[i] = |
| 565 | readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4); |
| 566 | |
| 567 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 568 | gic_data[gic_nr].saved_spi_target[i] = |
| 569 | readl_relaxed(dist_base + GIC_DIST_TARGET + i * 4); |
| 570 | |
| 571 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++) |
| 572 | gic_data[gic_nr].saved_spi_enable[i] = |
| 573 | readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Restores the GIC distributor registers during resume or when coming out of |
| 578 | * idle. Must be called before enabling interrupts. If a level interrupt |
| 579 | * that occured while the GIC was suspended is still present, it will be |
| 580 | * handled normally, but any edge interrupts that occured will not be seen by |
| 581 | * the GIC and need to be handled by the platform-specific wakeup source. |
| 582 | */ |
| 583 | static void gic_dist_restore(unsigned int gic_nr) |
| 584 | { |
| 585 | unsigned int gic_irqs; |
| 586 | unsigned int i; |
| 587 | void __iomem *dist_base; |
| 588 | |
| 589 | if (gic_nr >= MAX_GIC_NR) |
| 590 | BUG(); |
| 591 | |
| 592 | gic_irqs = gic_data[gic_nr].gic_irqs; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 593 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 594 | |
| 595 | if (!dist_base) |
| 596 | return; |
| 597 | |
| 598 | writel_relaxed(0, dist_base + GIC_DIST_CTRL); |
| 599 | |
| 600 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++) |
| 601 | writel_relaxed(gic_data[gic_nr].saved_spi_conf[i], |
| 602 | dist_base + GIC_DIST_CONFIG + i * 4); |
| 603 | |
| 604 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 605 | writel_relaxed(0xa0a0a0a0, |
| 606 | dist_base + GIC_DIST_PRI + i * 4); |
| 607 | |
| 608 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 609 | writel_relaxed(gic_data[gic_nr].saved_spi_target[i], |
| 610 | dist_base + GIC_DIST_TARGET + i * 4); |
| 611 | |
| 612 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++) |
| 613 | writel_relaxed(gic_data[gic_nr].saved_spi_enable[i], |
| 614 | dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 615 | |
| 616 | writel_relaxed(1, dist_base + GIC_DIST_CTRL); |
| 617 | } |
| 618 | |
| 619 | static void gic_cpu_save(unsigned int gic_nr) |
| 620 | { |
| 621 | int i; |
| 622 | u32 *ptr; |
| 623 | void __iomem *dist_base; |
| 624 | void __iomem *cpu_base; |
| 625 | |
| 626 | if (gic_nr >= MAX_GIC_NR) |
| 627 | BUG(); |
| 628 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 629 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
| 630 | cpu_base = gic_data_cpu_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 631 | |
| 632 | if (!dist_base || !cpu_base) |
| 633 | return; |
| 634 | |
| 635 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable); |
| 636 | for (i = 0; i < DIV_ROUND_UP(32, 32); i++) |
| 637 | ptr[i] = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 638 | |
| 639 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf); |
| 640 | for (i = 0; i < DIV_ROUND_UP(32, 16); i++) |
| 641 | ptr[i] = readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4); |
| 642 | |
| 643 | } |
| 644 | |
| 645 | static void gic_cpu_restore(unsigned int gic_nr) |
| 646 | { |
| 647 | int i; |
| 648 | u32 *ptr; |
| 649 | void __iomem *dist_base; |
| 650 | void __iomem *cpu_base; |
| 651 | |
| 652 | if (gic_nr >= MAX_GIC_NR) |
| 653 | BUG(); |
| 654 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 655 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
| 656 | cpu_base = gic_data_cpu_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 657 | |
| 658 | if (!dist_base || !cpu_base) |
| 659 | return; |
| 660 | |
| 661 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable); |
| 662 | for (i = 0; i < DIV_ROUND_UP(32, 32); i++) |
| 663 | writel_relaxed(ptr[i], dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 664 | |
| 665 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf); |
| 666 | for (i = 0; i < DIV_ROUND_UP(32, 16); i++) |
| 667 | writel_relaxed(ptr[i], dist_base + GIC_DIST_CONFIG + i * 4); |
| 668 | |
| 669 | for (i = 0; i < DIV_ROUND_UP(32, 4); i++) |
| 670 | writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4); |
| 671 | |
| 672 | writel_relaxed(0xf0, cpu_base + GIC_CPU_PRIMASK); |
| 673 | writel_relaxed(1, cpu_base + GIC_CPU_CTRL); |
| 674 | } |
| 675 | |
| 676 | static int gic_notifier(struct notifier_block *self, unsigned long cmd, void *v) |
| 677 | { |
| 678 | int i; |
| 679 | |
| 680 | for (i = 0; i < MAX_GIC_NR; i++) { |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 681 | #ifdef CONFIG_GIC_NON_BANKED |
| 682 | /* Skip over unused GICs */ |
| 683 | if (!gic_data[i].get_base) |
| 684 | continue; |
| 685 | #endif |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 686 | switch (cmd) { |
| 687 | case CPU_PM_ENTER: |
| 688 | gic_cpu_save(i); |
| 689 | break; |
| 690 | case CPU_PM_ENTER_FAILED: |
| 691 | case CPU_PM_EXIT: |
| 692 | gic_cpu_restore(i); |
| 693 | break; |
| 694 | case CPU_CLUSTER_PM_ENTER: |
| 695 | gic_dist_save(i); |
| 696 | break; |
| 697 | case CPU_CLUSTER_PM_ENTER_FAILED: |
| 698 | case CPU_CLUSTER_PM_EXIT: |
| 699 | gic_dist_restore(i); |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | return NOTIFY_OK; |
| 705 | } |
| 706 | |
| 707 | static struct notifier_block gic_notifier_block = { |
| 708 | .notifier_call = gic_notifier, |
| 709 | }; |
| 710 | |
| 711 | static void __init gic_pm_init(struct gic_chip_data *gic) |
| 712 | { |
| 713 | gic->saved_ppi_enable = __alloc_percpu(DIV_ROUND_UP(32, 32) * 4, |
| 714 | sizeof(u32)); |
| 715 | BUG_ON(!gic->saved_ppi_enable); |
| 716 | |
| 717 | gic->saved_ppi_conf = __alloc_percpu(DIV_ROUND_UP(32, 16) * 4, |
| 718 | sizeof(u32)); |
| 719 | BUG_ON(!gic->saved_ppi_conf); |
| 720 | |
| 721 | cpu_pm_register_notifier(&gic_notifier_block); |
| 722 | } |
| 723 | #else |
| 724 | static void __init gic_pm_init(struct gic_chip_data *gic) |
| 725 | { |
| 726 | } |
| 727 | #endif |
| 728 | |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 729 | #ifdef CONFIG_OF |
| 730 | static int gic_irq_domain_dt_translate(struct irq_domain *d, |
| 731 | struct device_node *controller, |
| 732 | const u32 *intspec, unsigned int intsize, |
| 733 | unsigned long *out_hwirq, unsigned int *out_type) |
| 734 | { |
| 735 | if (d->of_node != controller) |
| 736 | return -EINVAL; |
| 737 | if (intsize < 3) |
| 738 | return -EINVAL; |
| 739 | |
| 740 | /* Get the interrupt number and add 16 to skip over SGIs */ |
| 741 | *out_hwirq = intspec[1] + 16; |
| 742 | |
| 743 | /* For SPIs, we need to add 16 more to get the GIC irq ID number */ |
| 744 | if (!intspec[0]) |
| 745 | *out_hwirq += 16; |
| 746 | |
| 747 | *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK; |
| 748 | return 0; |
| 749 | } |
| 750 | #endif |
| 751 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 752 | const struct irq_domain_ops gic_irq_domain_ops = { |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 753 | #ifdef CONFIG_OF |
| 754 | .dt_translate = gic_irq_domain_dt_translate, |
| 755 | #endif |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 756 | }; |
| 757 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 758 | void __init gic_init_bases(unsigned int gic_nr, int irq_start, |
| 759 | void __iomem *dist_base, void __iomem *cpu_base, |
| 760 | u32 percpu_offset) |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 761 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 762 | struct gic_chip_data *gic; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 763 | struct irq_domain *domain; |
| 764 | int gic_irqs; |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 765 | |
| 766 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 767 | |
| 768 | gic = &gic_data[gic_nr]; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 769 | domain = &gic->domain; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 770 | #ifdef CONFIG_GIC_NON_BANKED |
| 771 | if (percpu_offset) { /* Frankein-GIC without banked registers... */ |
| 772 | unsigned int cpu; |
| 773 | |
| 774 | gic->dist_base.percpu_base = alloc_percpu(void __iomem *); |
| 775 | gic->cpu_base.percpu_base = alloc_percpu(void __iomem *); |
| 776 | if (WARN_ON(!gic->dist_base.percpu_base || |
| 777 | !gic->cpu_base.percpu_base)) { |
| 778 | free_percpu(gic->dist_base.percpu_base); |
| 779 | free_percpu(gic->cpu_base.percpu_base); |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | for_each_possible_cpu(cpu) { |
| 784 | unsigned long offset = percpu_offset * cpu_logical_map(cpu); |
| 785 | *per_cpu_ptr(gic->dist_base.percpu_base, cpu) = dist_base + offset; |
| 786 | *per_cpu_ptr(gic->cpu_base.percpu_base, cpu) = cpu_base + offset; |
| 787 | } |
| 788 | |
| 789 | gic_set_base_accessor(gic, gic_get_percpu_base); |
| 790 | } else |
| 791 | #endif |
| 792 | { /* Normal, sane GIC... */ |
| 793 | WARN(percpu_offset, |
| 794 | "GIC_NON_BANKED not enabled, ignoring %08x offset!", |
| 795 | percpu_offset); |
| 796 | gic->dist_base.common_base = dist_base; |
| 797 | gic->cpu_base.common_base = cpu_base; |
| 798 | gic_set_base_accessor(gic, gic_get_common_base); |
| 799 | } |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 800 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 801 | /* |
| 802 | * For primary GICs, skip over SGIs. |
| 803 | * For secondary GICs, skip over PPIs, too. |
| 804 | */ |
| 805 | if (gic_nr == 0) { |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 806 | gic_cpu_base_addr = cpu_base; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 807 | domain->hwirq_base = 16; |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 808 | if (irq_start > 0) |
| 809 | irq_start = (irq_start & ~31) + 16; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 810 | } else |
| 811 | domain->hwirq_base = 32; |
| 812 | |
| 813 | /* |
| 814 | * Find out how many interrupts are supported. |
| 815 | * The GIC only supports up to 1020 interrupt sources. |
| 816 | */ |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 817 | gic_irqs = readl_relaxed(gic_data_dist_base(gic) + GIC_DIST_CTR) & 0x1f; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 818 | gic_irqs = (gic_irqs + 1) * 32; |
| 819 | if (gic_irqs > 1020) |
| 820 | gic_irqs = 1020; |
| 821 | gic->gic_irqs = gic_irqs; |
| 822 | |
| 823 | domain->nr_irq = gic_irqs - domain->hwirq_base; |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 824 | domain->irq_base = irq_alloc_descs(irq_start, 16, domain->nr_irq, |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 825 | numa_node_id()); |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 826 | if (IS_ERR_VALUE(domain->irq_base)) { |
| 827 | WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", |
| 828 | irq_start); |
| 829 | domain->irq_base = irq_start; |
| 830 | } |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 831 | domain->priv = gic; |
| 832 | domain->ops = &gic_irq_domain_ops; |
| 833 | irq_domain_add(domain); |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 834 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 835 | gic_chip.flags |= gic_arch_extn.flags; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 836 | gic_dist_init(gic); |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 837 | gic_cpu_init(gic); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 838 | gic_pm_init(gic); |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 841 | void __cpuinit gic_secondary_init(unsigned int gic_nr) |
| 842 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 843 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 844 | |
| 845 | gic_cpu_init(&gic_data[gic_nr]); |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 848 | #ifdef CONFIG_SMP |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 849 | void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 850 | { |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 851 | int cpu; |
| 852 | unsigned long map = 0; |
| 853 | |
| 854 | /* Convert our logical CPU mask into a physical one. */ |
| 855 | for_each_cpu(cpu, mask) |
| 856 | map |= 1 << cpu_logical_map(cpu); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 857 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 858 | /* |
| 859 | * Ensure that stores to Normal memory are visible to the |
| 860 | * other CPUs before issuing the IPI. |
| 861 | */ |
| 862 | dsb(); |
| 863 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 864 | /* this always happens on GIC0 */ |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 865 | writel_relaxed(map << 16 | irq, gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 866 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 867 | } |
| 868 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 869 | |
| 870 | /* before calling this function the interrupts should be disabled |
| 871 | * and the irq must be disabled at gic to avoid spurious interrupts */ |
| 872 | bool gic_is_spi_pending(unsigned int irq) |
| 873 | { |
| 874 | struct irq_data *d = irq_get_irq_data(irq); |
| 875 | struct gic_chip_data *gic_data = &gic_data[0]; |
| 876 | u32 mask, val; |
| 877 | |
| 878 | WARN_ON(!irqs_disabled()); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 879 | raw_spin_lock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 880 | mask = 1 << (gic_irq(d) % 32); |
| 881 | val = readl(gic_dist_base(d) + |
| 882 | GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
| 883 | /* warn if the interrupt is enabled */ |
| 884 | WARN_ON(val & mask); |
| 885 | val = readl(gic_dist_base(d) + |
| 886 | GIC_DIST_PENDING_SET + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 887 | raw_spin_unlock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 888 | return (bool) (val & mask); |
| 889 | } |
| 890 | |
| 891 | /* before calling this function the interrupts should be disabled |
| 892 | * and the irq must be disabled at gic to avoid spurious interrupts */ |
| 893 | void gic_clear_spi_pending(unsigned int irq) |
| 894 | { |
| 895 | struct gic_chip_data *gic_data = &gic_data[0]; |
| 896 | struct irq_data *d = irq_get_irq_data(irq); |
| 897 | |
| 898 | u32 mask, val; |
| 899 | WARN_ON(!irqs_disabled()); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 900 | raw_spin_lock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 901 | mask = 1 << (gic_irq(d) % 32); |
| 902 | val = readl(gic_dist_base(d) + |
| 903 | GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
| 904 | /* warn if the interrupt is enabled */ |
| 905 | WARN_ON(val & mask); |
| 906 | writel(mask, gic_dist_base(d) + |
| 907 | GIC_DIST_PENDING_CLEAR + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 908 | raw_spin_unlock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 909 | } |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 910 | #ifdef CONFIG_OF |
| 911 | static int gic_cnt __initdata = 0; |
| 912 | |
| 913 | int __init gic_of_init(struct device_node *node, struct device_node *parent) |
| 914 | { |
| 915 | void __iomem *cpu_base; |
| 916 | void __iomem *dist_base; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 917 | u32 percpu_offset; |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 918 | int irq; |
| 919 | struct irq_domain *domain = &gic_data[gic_cnt].domain; |
| 920 | |
| 921 | if (WARN_ON(!node)) |
| 922 | return -ENODEV; |
| 923 | |
| 924 | dist_base = of_iomap(node, 0); |
| 925 | WARN(!dist_base, "unable to map gic dist registers\n"); |
| 926 | |
| 927 | cpu_base = of_iomap(node, 1); |
| 928 | WARN(!cpu_base, "unable to map gic cpu registers\n"); |
| 929 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 930 | if (of_property_read_u32(node, "cpu-offset", &percpu_offset)) |
| 931 | percpu_offset = 0; |
| 932 | |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 933 | domain->of_node = of_node_get(node); |
| 934 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame^] | 935 | gic_init_bases(gic_cnt, -1, dist_base, cpu_base, percpu_offset); |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 936 | |
| 937 | if (parent) { |
| 938 | irq = irq_of_parse_and_map(node, 0); |
| 939 | gic_cascade_irq(gic_cnt, irq); |
| 940 | } |
| 941 | gic_cnt++; |
| 942 | return 0; |
| 943 | } |
| 944 | #endif |