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