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