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