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