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