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); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 215 | #ifdef CONFIG_ARCH_MSM8625 |
| 216 | unsigned long flags; |
| 217 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 218 | |
| 219 | for (i = 0; i * 32 < gic->max_irq; i++) { |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 220 | #ifdef CONFIG_ARCH_MSM8625 |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 221 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 222 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | gic->enabled_irqs[i] |
| 224 | = readl_relaxed(base + GIC_DIST_ENABLE_SET + i * 4); |
| 225 | /* disable all of them */ |
| 226 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 227 | /* enable the wakeup set */ |
| 228 | writel_relaxed(gic->wakeup_irqs[i], |
| 229 | base + GIC_DIST_ENABLE_SET + i * 4); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 230 | #ifdef CONFIG_ARCH_MSM8625 |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 231 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 232 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | } |
| 234 | mb(); |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int gic_suspend(void) |
| 239 | { |
| 240 | int i; |
| 241 | for (i = 0; i < MAX_GIC_NR; i++) |
| 242 | gic_suspend_one(&gic_data[i]); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | extern int msm_show_resume_irq_mask; |
| 247 | |
| 248 | static void gic_show_resume_irq(struct gic_chip_data *gic) |
| 249 | { |
| 250 | unsigned int i; |
| 251 | u32 enabled; |
| 252 | unsigned long pending[32]; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 253 | void __iomem *base = gic_data_dist_base(gic); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 254 | #ifdef CONFIG_ARCH_MSM8625 |
| 255 | unsigned long flags; |
| 256 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | |
| 258 | if (!msm_show_resume_irq_mask) |
| 259 | return; |
| 260 | |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 261 | #ifdef CONFIG_ARCH_MSM8625 |
| 262 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
| 263 | #else |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 264 | raw_spin_lock(&irq_controller_lock); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 265 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | for (i = 0; i * 32 < gic->max_irq; i++) { |
| 267 | enabled = readl_relaxed(base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 268 | pending[i] = readl_relaxed(base + GIC_DIST_PENDING_SET + i * 4); |
| 269 | pending[i] &= enabled; |
| 270 | } |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 271 | #ifdef CONFIG_ARCH_MSM8625 |
| 272 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
| 273 | #else |
| 274 | raw_spin_lock(&irq_controller_lock); |
| 275 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 276 | |
| 277 | for (i = find_first_bit(pending, gic->max_irq); |
| 278 | i < gic->max_irq; |
| 279 | i = find_next_bit(pending, gic->max_irq, i+1)) { |
| 280 | pr_warning("%s: %d triggered", __func__, |
| 281 | i + gic->irq_offset); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | static void gic_resume_one(struct gic_chip_data *gic) |
| 286 | { |
| 287 | unsigned int i; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 288 | void __iomem *base = gic_data_dist_base(gic); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 289 | #ifdef CONFIG_ARCH_MSM8625 |
| 290 | unsigned long flags; |
| 291 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 292 | gic_show_resume_irq(gic); |
| 293 | for (i = 0; i * 32 < gic->max_irq; i++) { |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 294 | #ifdef CONFIG_ARCH_MSM8625 |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 295 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 296 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | /* disable all of them */ |
| 298 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4); |
| 299 | /* enable the enabled set */ |
| 300 | writel_relaxed(gic->enabled_irqs[i], |
| 301 | base + GIC_DIST_ENABLE_SET + i * 4); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 302 | #ifdef CONFIG_ARCH_MSM8625 |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 303 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 304 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 305 | } |
| 306 | mb(); |
| 307 | } |
| 308 | |
| 309 | static void gic_resume(void) |
| 310 | { |
| 311 | int i; |
| 312 | for (i = 0; i < MAX_GIC_NR; i++) |
| 313 | gic_resume_one(&gic_data[i]); |
| 314 | } |
| 315 | |
| 316 | static struct syscore_ops gic_syscore_ops = { |
| 317 | .suspend = gic_suspend, |
| 318 | .resume = gic_resume, |
| 319 | }; |
| 320 | |
| 321 | static int __init gic_init_sys(void) |
| 322 | { |
| 323 | register_syscore_ops(&gic_syscore_ops); |
| 324 | return 0; |
| 325 | } |
| 326 | arch_initcall(gic_init_sys); |
| 327 | |
| 328 | #endif |
| 329 | |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 330 | static void gic_eoi_irq(struct irq_data *d) |
| 331 | { |
| 332 | if (gic_arch_extn.irq_eoi) { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 333 | raw_spin_lock(&irq_controller_lock); |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 334 | gic_arch_extn.irq_eoi(d); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 335 | raw_spin_unlock(&irq_controller_lock); |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 336 | } |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 337 | #ifdef CONFIG_ARCH_MSM8625 |
| 338 | raw_spin_lock(&irq_controller_lock); |
| 339 | #endif |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 340 | writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 341 | #ifdef CONFIG_ARCH_MSM8625 |
| 342 | raw_spin_unlock(&irq_controller_lock); |
| 343 | #endif |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 346 | static int gic_set_type(struct irq_data *d, unsigned int type) |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 347 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 348 | void __iomem *base = gic_dist_base(d); |
| 349 | unsigned int gicirq = gic_irq(d); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 350 | u32 enablemask = 1 << (gicirq % 32); |
| 351 | u32 enableoff = (gicirq / 32) * 4; |
| 352 | u32 confmask = 0x2 << ((gicirq % 16) * 2); |
| 353 | u32 confoff = (gicirq / 16) * 4; |
| 354 | bool enabled = false; |
| 355 | u32 val; |
| 356 | |
| 357 | /* Interrupt configuration for SGIs can't be changed */ |
| 358 | if (gicirq < 16) |
| 359 | return -EINVAL; |
| 360 | |
| 361 | if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING) |
| 362 | return -EINVAL; |
| 363 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 364 | raw_spin_lock(&irq_controller_lock); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 365 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 366 | if (gic_arch_extn.irq_set_type) |
| 367 | gic_arch_extn.irq_set_type(d, type); |
| 368 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 369 | val = readl_relaxed(base + GIC_DIST_CONFIG + confoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 370 | if (type == IRQ_TYPE_LEVEL_HIGH) |
| 371 | val &= ~confmask; |
| 372 | else if (type == IRQ_TYPE_EDGE_RISING) |
| 373 | val |= confmask; |
| 374 | |
| 375 | /* |
| 376 | * As recommended by the spec, disable the interrupt before changing |
| 377 | * the configuration |
| 378 | */ |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 379 | if (readl_relaxed(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) { |
| 380 | writel_relaxed(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 381 | enabled = true; |
| 382 | } |
| 383 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 384 | writel_relaxed(val, base + GIC_DIST_CONFIG + confoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 385 | |
| 386 | if (enabled) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 387 | writel_relaxed(enablemask, base + GIC_DIST_ENABLE_SET + enableoff); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 388 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 389 | raw_spin_unlock(&irq_controller_lock); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 394 | static int gic_retrigger(struct irq_data *d) |
| 395 | { |
| 396 | if (gic_arch_extn.irq_retrigger) |
| 397 | return gic_arch_extn.irq_retrigger(d); |
| 398 | |
Abhijeet Dharmapurikar | 9d44ea0 | 2011-10-30 16:47:19 -0700 | [diff] [blame] | 399 | /* the retrigger expects 0 for failure */ |
| 400 | return 0; |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 403 | #ifdef CONFIG_SMP |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 404 | static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 405 | bool force) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 406 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 407 | 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] | 408 | unsigned int shift = (gic_irq(d) % 4) * 8; |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 409 | unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask); |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 410 | u32 val, mask, bit; |
| 411 | |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 412 | if (cpu >= 8 || cpu >= nr_cpu_ids) |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 413 | return -EINVAL; |
| 414 | |
| 415 | mask = 0xff << shift; |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 416 | bit = 1 << (cpu_logical_map(cpu) + shift); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 417 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 418 | raw_spin_lock(&irq_controller_lock); |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 419 | val = readl_relaxed(reg) & ~mask; |
| 420 | writel_relaxed(val | bit, reg); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 421 | raw_spin_unlock(&irq_controller_lock); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 422 | |
Russell King | f3c52e2 | 2011-07-21 15:00:57 +0100 | [diff] [blame] | 423 | return IRQ_SET_MASK_OK; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 424 | } |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 425 | #endif |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 426 | |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 427 | #ifdef CONFIG_PM |
| 428 | static int gic_set_wake(struct irq_data *d, unsigned int on) |
| 429 | { |
| 430 | int ret = -ENXIO; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 431 | unsigned int reg_offset, bit_offset; |
| 432 | unsigned int gicirq = gic_irq(d); |
| 433 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
| 434 | |
| 435 | /* per-cpu interrupts cannot be wakeup interrupts */ |
| 436 | WARN_ON(gicirq < 32); |
| 437 | |
| 438 | reg_offset = gicirq / 32; |
| 439 | bit_offset = gicirq % 32; |
| 440 | |
| 441 | if (on) |
| 442 | gic_data->wakeup_irqs[reg_offset] |= 1 << bit_offset; |
| 443 | else |
| 444 | gic_data->wakeup_irqs[reg_offset] &= ~(1 << bit_offset); |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 445 | |
| 446 | if (gic_arch_extn.irq_set_wake) |
| 447 | ret = gic_arch_extn.irq_set_wake(d, on); |
| 448 | |
| 449 | return ret; |
| 450 | } |
| 451 | |
| 452 | #else |
Rohit Vaswani | 550aa1a | 2011-10-06 21:15:37 -0700 | [diff] [blame] | 453 | static int gic_set_wake(struct irq_data *d, unsigned int on) |
| 454 | { |
| 455 | return 0; |
| 456 | } |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 457 | #endif |
| 458 | |
Marc Zyngier | 181621e | 2011-09-06 09:56:17 +0100 | [diff] [blame] | 459 | asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) |
| 460 | { |
| 461 | u32 irqstat, irqnr; |
| 462 | struct gic_chip_data *gic = &gic_data[0]; |
| 463 | void __iomem *cpu_base = gic_data_cpu_base(gic); |
| 464 | |
| 465 | do { |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 466 | #ifdef CONFIG_ARCH_MSM8625 |
| 467 | raw_spin_lock(&irq_controller_lock); |
| 468 | #endif |
Marc Zyngier | 181621e | 2011-09-06 09:56:17 +0100 | [diff] [blame] | 469 | irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 470 | #ifdef CONFIG_ARCH_MSM8625 |
| 471 | raw_spin_unlock(&irq_controller_lock); |
| 472 | #endif |
Marc Zyngier | 181621e | 2011-09-06 09:56:17 +0100 | [diff] [blame] | 473 | irqnr = irqstat & ~0x1c00; |
| 474 | |
| 475 | if (likely(irqnr > 15 && irqnr < 1021)) { |
| 476 | irqnr = irq_domain_to_irq(&gic->domain, irqnr); |
| 477 | handle_IRQ(irqnr, regs); |
| 478 | continue; |
| 479 | } |
| 480 | if (irqnr < 16) { |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 481 | #ifdef CONFIG_ARCH_MSM8625 |
| 482 | raw_spin_lock(&irq_controller_lock); |
| 483 | #endif |
Marc Zyngier | 181621e | 2011-09-06 09:56:17 +0100 | [diff] [blame] | 484 | writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 485 | #ifdef CONFIG_ARCH_MSM8625 |
| 486 | raw_spin_unlock(&irq_controller_lock); |
| 487 | #endif |
Marc Zyngier | 181621e | 2011-09-06 09:56:17 +0100 | [diff] [blame] | 488 | #ifdef CONFIG_SMP |
| 489 | handle_IPI(irqnr, regs); |
| 490 | #endif |
| 491 | continue; |
| 492 | } |
| 493 | break; |
| 494 | } while (1); |
| 495 | } |
| 496 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 497 | 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] | 498 | { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 499 | struct gic_chip_data *chip_data = irq_get_handler_data(irq); |
| 500 | struct irq_chip *chip = irq_get_chip(irq); |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 501 | unsigned int cascade_irq, gic_irq; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 502 | unsigned long status; |
| 503 | |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 504 | chained_irq_enter(chip, desc); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 505 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 506 | raw_spin_lock(&irq_controller_lock); |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 507 | status = readl_relaxed(gic_data_cpu_base(chip_data) + GIC_CPU_INTACK); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 508 | raw_spin_unlock(&irq_controller_lock); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 509 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 510 | gic_irq = (status & 0x3ff); |
| 511 | if (gic_irq == 1023) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 512 | goto out; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 513 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 514 | cascade_irq = irq_domain_to_irq(&chip_data->domain, gic_irq); |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 515 | if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS)) |
| 516 | do_bad_IRQ(cascade_irq, desc); |
| 517 | else |
| 518 | generic_handle_irq(cascade_irq); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 519 | |
| 520 | out: |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 521 | chained_irq_exit(chip, desc); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 522 | } |
| 523 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 524 | static struct irq_chip gic_chip = { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 525 | .name = "GIC", |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 526 | .irq_mask = gic_mask_irq, |
| 527 | .irq_unmask = gic_unmask_irq, |
Will Deacon | 1a01753 | 2011-02-09 12:01:12 +0000 | [diff] [blame] | 528 | .irq_eoi = gic_eoi_irq, |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame] | 529 | .irq_set_type = gic_set_type, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 530 | .irq_retrigger = gic_retrigger, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 531 | #ifdef CONFIG_SMP |
Russell King | c191789 | 2011-01-23 12:12:01 +0000 | [diff] [blame] | 532 | .irq_set_affinity = gic_set_affinity, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 533 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 534 | .irq_disable = gic_disable_irq, |
Santosh Shilimkar | d7ed36a | 2011-03-02 08:03:22 +0100 | [diff] [blame] | 535 | .irq_set_wake = gic_set_wake, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 536 | }; |
| 537 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 538 | void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq) |
| 539 | { |
| 540 | if (gic_nr >= MAX_GIC_NR) |
| 541 | BUG(); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 542 | if (irq_set_handler_data(irq, &gic_data[gic_nr]) != 0) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 543 | BUG(); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 544 | irq_set_chained_handler(irq, gic_handle_cascade_irq); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 547 | static void __init gic_dist_init(struct gic_chip_data *gic) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 548 | { |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 549 | unsigned int i, irq; |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 550 | u32 cpumask; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 551 | unsigned int gic_irqs = gic->gic_irqs; |
| 552 | struct irq_domain *domain = &gic->domain; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 553 | void __iomem *base = gic_data_dist_base(gic); |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 554 | u32 cpu = 0; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 555 | |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 556 | #ifdef CONFIG_SMP |
| 557 | cpu = cpu_logical_map(smp_processor_id()); |
| 558 | #endif |
| 559 | |
| 560 | cpumask = 1 << cpu; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 561 | cpumask |= cpumask << 8; |
| 562 | cpumask |= cpumask << 16; |
| 563 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 564 | writel_relaxed(0, base + GIC_DIST_CTRL); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 565 | |
| 566 | /* |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 567 | * Set all global interrupts to be level triggered, active low. |
| 568 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 569 | for (i = 32; i < gic_irqs; i += 16) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 570 | writel_relaxed(0, base + GIC_DIST_CONFIG + i * 4 / 16); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 571 | |
| 572 | /* |
| 573 | * Set all global interrupts to this CPU only. |
| 574 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 575 | for (i = 32; i < gic_irqs; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 576 | writel_relaxed(cpumask, base + GIC_DIST_TARGET + i * 4 / 4); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 577 | |
| 578 | /* |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 579 | * Set NS/S. |
| 580 | */ |
| 581 | if (is_cpu_secure()) |
| 582 | for (i = 32; i < gic_irqs; i += 32) |
| 583 | writel_relaxed(0xFFFFFFFF, |
| 584 | base + GIC_DIST_ISR + i * 4 / 32); |
| 585 | |
| 586 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 587 | * Set priority on all global interrupts. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 588 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 589 | for (i = 32; i < gic_irqs; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 590 | writel_relaxed(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 591 | |
| 592 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 593 | * Disable all interrupts. Leave the PPI and SGIs alone |
| 594 | * as these enables are banked registers. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 595 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 596 | for (i = 32; i < gic_irqs; i += 32) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 597 | writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * Setup the Linux IRQ subsystem. |
| 601 | */ |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 602 | irq_domain_for_each_irq(domain, i, irq) { |
| 603 | if (i < 32) { |
| 604 | irq_set_percpu_devid(irq); |
| 605 | irq_set_chip_and_handler(irq, &gic_chip, |
| 606 | handle_percpu_devid_irq); |
| 607 | set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN); |
| 608 | } else { |
| 609 | irq_set_chip_and_handler(irq, &gic_chip, |
| 610 | handle_fasteoi_irq); |
| 611 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 612 | } |
| 613 | irq_set_chip_data(irq, gic); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 616 | gic->max_irq = gic_irqs; |
| 617 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 618 | if (is_cpu_secure()) |
| 619 | writel_relaxed(3, base + GIC_DIST_CTRL); |
| 620 | else |
| 621 | writel_relaxed(1, base + GIC_DIST_CTRL); |
| 622 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 626 | static void __cpuinit gic_cpu_init(struct gic_chip_data *gic) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 627 | { |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 628 | void __iomem *dist_base = gic_data_dist_base(gic); |
| 629 | void __iomem *base = gic_data_cpu_base(gic); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 630 | int i; |
| 631 | |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 632 | /* |
| 633 | * Deal with the banked PPI and SGI interrupts - disable all |
| 634 | * PPI interrupts, ensure all SGI interrupts are enabled. |
| 635 | */ |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 636 | #ifdef CONFIG_ARCH_MSM8625 |
| 637 | raw_spin_lock(&irq_controller_lock); |
| 638 | #endif |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 639 | writel_relaxed(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR); |
| 640 | writel_relaxed(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 641 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 642 | /* Set NS/S */ |
| 643 | if (is_cpu_secure()) |
| 644 | writel_relaxed(0xFFFFFFFF, dist_base + GIC_DIST_ISR); |
| 645 | |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 646 | /* |
| 647 | * Set priority on PPI and SGI interrupts |
| 648 | */ |
| 649 | for (i = 0; i < 32; i += 4) |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 650 | writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4); |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 651 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 652 | writel_relaxed(0xf0, base + GIC_CPU_PRIMASK); |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 653 | |
| 654 | if (is_cpu_secure()) |
| 655 | writel_relaxed(0xF, base + GIC_CPU_CTRL); |
| 656 | else |
| 657 | writel_relaxed(1, base + GIC_CPU_CTRL); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 658 | #ifdef CONFIG_ARCH_MSM8625 |
| 659 | raw_spin_unlock(&irq_controller_lock); |
| 660 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 662 | } |
| 663 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 664 | #ifdef CONFIG_CPU_PM |
| 665 | /* |
| 666 | * Saves the GIC distributor registers during suspend or idle. Must be called |
| 667 | * with interrupts disabled but before powering down the GIC. After calling |
| 668 | * this function, no interrupts will be delivered by the GIC, and another |
| 669 | * platform-specific wakeup source must be enabled. |
| 670 | */ |
| 671 | static void gic_dist_save(unsigned int gic_nr) |
| 672 | { |
| 673 | unsigned int gic_irqs; |
| 674 | void __iomem *dist_base; |
| 675 | int i; |
| 676 | |
| 677 | if (gic_nr >= MAX_GIC_NR) |
| 678 | BUG(); |
| 679 | |
| 680 | gic_irqs = gic_data[gic_nr].gic_irqs; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 681 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 682 | |
| 683 | if (!dist_base) |
| 684 | return; |
| 685 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 686 | saved_dist_ctrl = readl_relaxed(dist_base + GIC_DIST_CTRL); |
| 687 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 688 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++) |
| 689 | gic_data[gic_nr].saved_spi_conf[i] = |
| 690 | readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4); |
| 691 | |
| 692 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 693 | gic_data[gic_nr].saved_spi_target[i] = |
| 694 | readl_relaxed(dist_base + GIC_DIST_TARGET + i * 4); |
| 695 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 696 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 697 | gic_data[gic_nr].saved_dist_pri[i] = |
| 698 | readl_relaxed(dist_base + GIC_DIST_PRI + i * 4); |
| 699 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 700 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++) |
| 701 | gic_data[gic_nr].saved_spi_enable[i] = |
| 702 | readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Restores the GIC distributor registers during resume or when coming out of |
| 707 | * idle. Must be called before enabling interrupts. If a level interrupt |
| 708 | * that occured while the GIC was suspended is still present, it will be |
| 709 | * handled normally, but any edge interrupts that occured will not be seen by |
| 710 | * the GIC and need to be handled by the platform-specific wakeup source. |
| 711 | */ |
| 712 | static void gic_dist_restore(unsigned int gic_nr) |
| 713 | { |
| 714 | unsigned int gic_irqs; |
| 715 | unsigned int i; |
| 716 | void __iomem *dist_base; |
| 717 | |
| 718 | if (gic_nr >= MAX_GIC_NR) |
| 719 | BUG(); |
| 720 | |
| 721 | gic_irqs = gic_data[gic_nr].gic_irqs; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 722 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 723 | |
| 724 | if (!dist_base) |
| 725 | return; |
| 726 | |
| 727 | writel_relaxed(0, dist_base + GIC_DIST_CTRL); |
| 728 | |
| 729 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++) |
| 730 | writel_relaxed(gic_data[gic_nr].saved_spi_conf[i], |
| 731 | dist_base + GIC_DIST_CONFIG + i * 4); |
| 732 | |
| 733 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 734 | writel_relaxed(gic_data[gic_nr].saved_dist_pri[i], |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 735 | dist_base + GIC_DIST_PRI + i * 4); |
| 736 | |
| 737 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++) |
| 738 | writel_relaxed(gic_data[gic_nr].saved_spi_target[i], |
| 739 | dist_base + GIC_DIST_TARGET + i * 4); |
| 740 | |
| 741 | for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++) |
| 742 | writel_relaxed(gic_data[gic_nr].saved_spi_enable[i], |
| 743 | dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 744 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 745 | writel_relaxed(saved_dist_ctrl, dist_base + GIC_DIST_CTRL); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static void gic_cpu_save(unsigned int gic_nr) |
| 749 | { |
| 750 | int i; |
| 751 | u32 *ptr; |
| 752 | void __iomem *dist_base; |
| 753 | void __iomem *cpu_base; |
| 754 | |
| 755 | if (gic_nr >= MAX_GIC_NR) |
| 756 | BUG(); |
| 757 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 758 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
| 759 | cpu_base = gic_data_cpu_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 760 | |
| 761 | if (!dist_base || !cpu_base) |
| 762 | return; |
| 763 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 764 | saved_cpu_ctrl = readl_relaxed(cpu_base + GIC_CPU_CTRL); |
| 765 | |
| 766 | for (i = 0; i < DIV_ROUND_UP(32, 4); i++) |
| 767 | gic_data[gic_nr].saved_dist_pri[i] = readl_relaxed(dist_base + |
| 768 | GIC_DIST_PRI + i * 4); |
| 769 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 770 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable); |
| 771 | for (i = 0; i < DIV_ROUND_UP(32, 32); i++) |
| 772 | ptr[i] = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 773 | |
| 774 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf); |
| 775 | for (i = 0; i < DIV_ROUND_UP(32, 16); i++) |
| 776 | ptr[i] = readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4); |
| 777 | |
| 778 | } |
| 779 | |
| 780 | static void gic_cpu_restore(unsigned int gic_nr) |
| 781 | { |
| 782 | int i; |
| 783 | u32 *ptr; |
| 784 | void __iomem *dist_base; |
| 785 | void __iomem *cpu_base; |
| 786 | |
| 787 | if (gic_nr >= MAX_GIC_NR) |
| 788 | BUG(); |
| 789 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 790 | dist_base = gic_data_dist_base(&gic_data[gic_nr]); |
| 791 | cpu_base = gic_data_cpu_base(&gic_data[gic_nr]); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 792 | |
| 793 | if (!dist_base || !cpu_base) |
| 794 | return; |
| 795 | |
| 796 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable); |
| 797 | for (i = 0; i < DIV_ROUND_UP(32, 32); i++) |
| 798 | writel_relaxed(ptr[i], dist_base + GIC_DIST_ENABLE_SET + i * 4); |
| 799 | |
| 800 | ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf); |
| 801 | for (i = 0; i < DIV_ROUND_UP(32, 16); i++) |
| 802 | writel_relaxed(ptr[i], dist_base + GIC_DIST_CONFIG + i * 4); |
| 803 | |
| 804 | for (i = 0; i < DIV_ROUND_UP(32, 4); i++) |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 805 | writel_relaxed(gic_data[gic_nr].saved_dist_pri[i], |
| 806 | dist_base + GIC_DIST_PRI + i * 4); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 807 | |
| 808 | writel_relaxed(0xf0, cpu_base + GIC_CPU_PRIMASK); |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 809 | writel_relaxed(saved_cpu_ctrl, cpu_base + GIC_CPU_CTRL); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | static int gic_notifier(struct notifier_block *self, unsigned long cmd, void *v) |
| 813 | { |
| 814 | int i; |
| 815 | |
| 816 | for (i = 0; i < MAX_GIC_NR; i++) { |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 817 | #ifdef CONFIG_GIC_NON_BANKED |
| 818 | /* Skip over unused GICs */ |
| 819 | if (!gic_data[i].get_base) |
| 820 | continue; |
| 821 | #endif |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 822 | switch (cmd) { |
| 823 | case CPU_PM_ENTER: |
| 824 | gic_cpu_save(i); |
| 825 | break; |
| 826 | case CPU_PM_ENTER_FAILED: |
| 827 | case CPU_PM_EXIT: |
| 828 | gic_cpu_restore(i); |
| 829 | break; |
| 830 | case CPU_CLUSTER_PM_ENTER: |
| 831 | gic_dist_save(i); |
| 832 | break; |
| 833 | case CPU_CLUSTER_PM_ENTER_FAILED: |
| 834 | case CPU_CLUSTER_PM_EXIT: |
| 835 | gic_dist_restore(i); |
| 836 | break; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return NOTIFY_OK; |
| 841 | } |
| 842 | |
| 843 | static struct notifier_block gic_notifier_block = { |
| 844 | .notifier_call = gic_notifier, |
| 845 | }; |
| 846 | |
| 847 | static void __init gic_pm_init(struct gic_chip_data *gic) |
| 848 | { |
| 849 | gic->saved_ppi_enable = __alloc_percpu(DIV_ROUND_UP(32, 32) * 4, |
| 850 | sizeof(u32)); |
| 851 | BUG_ON(!gic->saved_ppi_enable); |
| 852 | |
| 853 | gic->saved_ppi_conf = __alloc_percpu(DIV_ROUND_UP(32, 16) * 4, |
| 854 | sizeof(u32)); |
| 855 | BUG_ON(!gic->saved_ppi_conf); |
| 856 | |
| 857 | cpu_pm_register_notifier(&gic_notifier_block); |
| 858 | } |
| 859 | #else |
| 860 | static void __init gic_pm_init(struct gic_chip_data *gic) |
| 861 | { |
| 862 | } |
| 863 | #endif |
| 864 | |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 865 | #ifdef CONFIG_OF |
| 866 | static int gic_irq_domain_dt_translate(struct irq_domain *d, |
| 867 | struct device_node *controller, |
| 868 | const u32 *intspec, unsigned int intsize, |
| 869 | unsigned long *out_hwirq, unsigned int *out_type) |
| 870 | { |
| 871 | if (d->of_node != controller) |
| 872 | return -EINVAL; |
| 873 | if (intsize < 3) |
| 874 | return -EINVAL; |
| 875 | |
| 876 | /* Get the interrupt number and add 16 to skip over SGIs */ |
| 877 | *out_hwirq = intspec[1] + 16; |
| 878 | |
| 879 | /* For SPIs, we need to add 16 more to get the GIC irq ID number */ |
| 880 | if (!intspec[0]) |
| 881 | *out_hwirq += 16; |
| 882 | |
| 883 | *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK; |
| 884 | return 0; |
| 885 | } |
| 886 | #endif |
| 887 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 888 | const struct irq_domain_ops gic_irq_domain_ops = { |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 889 | #ifdef CONFIG_OF |
| 890 | .dt_translate = gic_irq_domain_dt_translate, |
| 891 | #endif |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 892 | }; |
| 893 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 894 | void __init gic_init_bases(unsigned int gic_nr, int irq_start, |
| 895 | void __iomem *dist_base, void __iomem *cpu_base, |
| 896 | u32 percpu_offset) |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 897 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 898 | struct gic_chip_data *gic; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 899 | struct irq_domain *domain; |
Michael Bohan | 33efecf | 2012-01-12 15:32:21 -0800 | [diff] [blame] | 900 | int gic_irqs, rc; |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 901 | |
| 902 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 903 | |
| 904 | gic = &gic_data[gic_nr]; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 905 | domain = &gic->domain; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 906 | #ifdef CONFIG_GIC_NON_BANKED |
| 907 | if (percpu_offset) { /* Frankein-GIC without banked registers... */ |
| 908 | unsigned int cpu; |
| 909 | |
| 910 | gic->dist_base.percpu_base = alloc_percpu(void __iomem *); |
| 911 | gic->cpu_base.percpu_base = alloc_percpu(void __iomem *); |
| 912 | if (WARN_ON(!gic->dist_base.percpu_base || |
Michael Bohan | 33efecf | 2012-01-12 15:32:21 -0800 | [diff] [blame] | 913 | !gic->cpu_base.percpu_base)) |
| 914 | goto init_bases_err; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 915 | |
| 916 | for_each_possible_cpu(cpu) { |
| 917 | unsigned long offset = percpu_offset * cpu_logical_map(cpu); |
| 918 | *per_cpu_ptr(gic->dist_base.percpu_base, cpu) = dist_base + offset; |
| 919 | *per_cpu_ptr(gic->cpu_base.percpu_base, cpu) = cpu_base + offset; |
| 920 | } |
| 921 | |
| 922 | gic_set_base_accessor(gic, gic_get_percpu_base); |
| 923 | } else |
| 924 | #endif |
| 925 | { /* Normal, sane GIC... */ |
| 926 | WARN(percpu_offset, |
| 927 | "GIC_NON_BANKED not enabled, ignoring %08x offset!", |
| 928 | percpu_offset); |
| 929 | gic->dist_base.common_base = dist_base; |
| 930 | gic->cpu_base.common_base = cpu_base; |
| 931 | gic_set_base_accessor(gic, gic_get_common_base); |
| 932 | } |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 933 | |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 934 | /* |
| 935 | * For primary GICs, skip over SGIs. |
| 936 | * For secondary GICs, skip over PPIs, too. |
| 937 | */ |
| 938 | if (gic_nr == 0) { |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 939 | gic_cpu_base_addr = cpu_base; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 940 | domain->hwirq_base = 16; |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 941 | if (irq_start > 0) |
| 942 | irq_start = (irq_start & ~31) + 16; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 943 | } else |
| 944 | domain->hwirq_base = 32; |
| 945 | |
| 946 | /* |
| 947 | * Find out how many interrupts are supported. |
| 948 | * The GIC only supports up to 1020 interrupt sources. |
| 949 | */ |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 950 | 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] | 951 | gic_irqs = (gic_irqs + 1) * 32; |
| 952 | if (gic_irqs > 1020) |
| 953 | gic_irqs = 1020; |
| 954 | gic->gic_irqs = gic_irqs; |
| 955 | |
| 956 | domain->nr_irq = gic_irqs - domain->hwirq_base; |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 957 | domain->irq_base = irq_alloc_descs(irq_start, 16, domain->nr_irq, |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 958 | numa_node_id()); |
Rob Herring | 050113e | 2011-10-21 17:14:27 -0500 | [diff] [blame] | 959 | if (IS_ERR_VALUE(domain->irq_base)) { |
| 960 | WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", |
| 961 | irq_start); |
| 962 | domain->irq_base = irq_start; |
| 963 | } |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 964 | domain->priv = gic; |
| 965 | domain->ops = &gic_irq_domain_ops; |
Michael Bohan | 33efecf | 2012-01-12 15:32:21 -0800 | [diff] [blame] | 966 | rc = irq_domain_add(domain); |
| 967 | if (rc) { |
| 968 | WARN(1, "Unable to create irq_domain\n"); |
| 969 | goto init_bases_err; |
| 970 | } |
Michael Bohan | b8635c3 | 2012-01-05 18:32:10 -0800 | [diff] [blame] | 971 | irq_domain_register(domain); |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 972 | |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 973 | gic_chip.flags |= gic_arch_extn.flags; |
Rob Herring | c383e04 | 2011-09-28 21:25:31 -0500 | [diff] [blame] | 974 | gic_dist_init(gic); |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 975 | gic_cpu_init(gic); |
Colin Cross | 692c3e25 | 2011-02-10 12:54:10 -0800 | [diff] [blame] | 976 | gic_pm_init(gic); |
Michael Bohan | 33efecf | 2012-01-12 15:32:21 -0800 | [diff] [blame] | 977 | |
| 978 | return; |
| 979 | |
| 980 | init_bases_err: |
| 981 | free_percpu(gic->dist_base.percpu_base); |
| 982 | free_percpu(gic->cpu_base.percpu_base); |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 985 | void __cpuinit gic_secondary_init(unsigned int gic_nr) |
| 986 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 987 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 988 | |
| 989 | gic_cpu_init(&gic_data[gic_nr]); |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 992 | #ifdef CONFIG_SMP |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 993 | void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 994 | { |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 995 | int cpu; |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 996 | unsigned long sgir; |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 997 | unsigned long map = 0; |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 998 | #ifdef CONFIG_ARCH_MSM8625 |
| 999 | unsigned long flags; |
| 1000 | #endif |
Will Deacon | a803a8d | 2011-08-23 22:20:03 +0100 | [diff] [blame] | 1001 | |
| 1002 | /* Convert our logical CPU mask into a physical one. */ |
| 1003 | for_each_cpu(cpu, mask) |
| 1004 | map |= 1 << cpu_logical_map(cpu); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 1005 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 1006 | sgir = (map << 16) | irq; |
| 1007 | if (is_cpu_secure()) |
| 1008 | sgir |= (1 << 15); |
| 1009 | |
Santosh Shilimkar | 6ac77e4 | 2011-03-28 19:27:46 +0530 | [diff] [blame] | 1010 | /* |
| 1011 | * Ensure that stores to Normal memory are visible to the |
| 1012 | * other CPUs before issuing the IPI. |
| 1013 | */ |
| 1014 | dsb(); |
| 1015 | |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 1016 | #ifdef CONFIG_ARCH_MSM8625 |
| 1017 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
| 1018 | #endif |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 1019 | /* this always happens on GIC0 */ |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 1020 | writel_relaxed(sgir, |
| 1021 | gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT); |
Taniya Das | 6639886 | 2012-04-30 12:24:17 +0530 | [diff] [blame] | 1022 | #ifdef CONFIG_ARCH_MSM8625 |
| 1023 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
| 1024 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1025 | mb(); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 1026 | } |
| 1027 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1028 | |
Rohit Vaswani | 26e4486 | 2012-01-05 20:26:40 -0800 | [diff] [blame] | 1029 | void gic_set_irq_secure(unsigned int irq) |
| 1030 | { |
| 1031 | unsigned int gicd_isr_reg, gicd_pri_reg; |
| 1032 | unsigned int mask = 0xFFFFFF00; |
| 1033 | struct gic_chip_data *gic_data = &gic_data[0]; |
| 1034 | struct irq_data *d = irq_get_irq_data(irq); |
| 1035 | |
| 1036 | if (is_cpu_secure()) { |
| 1037 | raw_spin_lock(&irq_controller_lock); |
| 1038 | gicd_isr_reg = readl_relaxed(gic_dist_base(d) + |
| 1039 | GIC_DIST_ISR + gic_irq(d) / 32 * 4); |
| 1040 | gicd_isr_reg &= ~BIT(gic_irq(d) % 32); |
| 1041 | writel_relaxed(gicd_isr_reg, gic_dist_base(d) + |
| 1042 | GIC_DIST_ISR + gic_irq(d) / 32 * 4); |
| 1043 | /* Also increase the priority of that irq */ |
| 1044 | gicd_pri_reg = readl_relaxed(gic_dist_base(d) + |
| 1045 | GIC_DIST_PRI + (gic_irq(d) * 4 / 4)); |
| 1046 | gicd_pri_reg &= mask; |
| 1047 | gicd_pri_reg |= 0x80; /* Priority of 0x80 > 0xA0 */ |
| 1048 | writel_relaxed(gicd_pri_reg, gic_dist_base(d) + GIC_DIST_PRI + |
| 1049 | gic_irq(d) * 4 / 4); |
| 1050 | mb(); |
| 1051 | raw_spin_unlock(&irq_controller_lock); |
| 1052 | } else { |
| 1053 | WARN(1, "Trying to run secure operation from Non-secure mode"); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1057 | /* before calling this function the interrupts should be disabled |
| 1058 | * and the irq must be disabled at gic to avoid spurious interrupts */ |
| 1059 | bool gic_is_spi_pending(unsigned int irq) |
| 1060 | { |
| 1061 | struct irq_data *d = irq_get_irq_data(irq); |
| 1062 | struct gic_chip_data *gic_data = &gic_data[0]; |
| 1063 | u32 mask, val; |
| 1064 | |
| 1065 | WARN_ON(!irqs_disabled()); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 1066 | raw_spin_lock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1067 | mask = 1 << (gic_irq(d) % 32); |
| 1068 | val = readl(gic_dist_base(d) + |
| 1069 | GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
| 1070 | /* warn if the interrupt is enabled */ |
| 1071 | WARN_ON(val & mask); |
| 1072 | val = readl(gic_dist_base(d) + |
| 1073 | GIC_DIST_PENDING_SET + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 1074 | raw_spin_unlock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1075 | return (bool) (val & mask); |
| 1076 | } |
| 1077 | |
| 1078 | /* before calling this function the interrupts should be disabled |
| 1079 | * and the irq must be disabled at gic to avoid spurious interrupts */ |
| 1080 | void gic_clear_spi_pending(unsigned int irq) |
| 1081 | { |
| 1082 | struct gic_chip_data *gic_data = &gic_data[0]; |
| 1083 | struct irq_data *d = irq_get_irq_data(irq); |
| 1084 | |
| 1085 | u32 mask, val; |
| 1086 | WARN_ON(!irqs_disabled()); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 1087 | raw_spin_lock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1088 | mask = 1 << (gic_irq(d) % 32); |
| 1089 | val = readl(gic_dist_base(d) + |
| 1090 | GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
| 1091 | /* warn if the interrupt is enabled */ |
| 1092 | WARN_ON(val & mask); |
| 1093 | writel(mask, gic_dist_base(d) + |
| 1094 | GIC_DIST_PENDING_CLEAR + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 1095 | raw_spin_unlock(&irq_controller_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1096 | } |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 1097 | #ifdef CONFIG_OF |
| 1098 | static int gic_cnt __initdata = 0; |
| 1099 | |
| 1100 | int __init gic_of_init(struct device_node *node, struct device_node *parent) |
| 1101 | { |
| 1102 | void __iomem *cpu_base; |
| 1103 | void __iomem *dist_base; |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 1104 | u32 percpu_offset; |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 1105 | int irq; |
| 1106 | struct irq_domain *domain = &gic_data[gic_cnt].domain; |
| 1107 | |
| 1108 | if (WARN_ON(!node)) |
| 1109 | return -ENODEV; |
| 1110 | |
| 1111 | dist_base = of_iomap(node, 0); |
| 1112 | WARN(!dist_base, "unable to map gic dist registers\n"); |
| 1113 | |
| 1114 | cpu_base = of_iomap(node, 1); |
| 1115 | WARN(!cpu_base, "unable to map gic cpu registers\n"); |
| 1116 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 1117 | if (of_property_read_u32(node, "cpu-offset", &percpu_offset)) |
| 1118 | percpu_offset = 0; |
| 1119 | |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 1120 | domain->of_node = of_node_get(node); |
| 1121 | |
Marc Zyngier | 680392b | 2011-11-12 16:09:49 +0000 | [diff] [blame] | 1122 | gic_init_bases(gic_cnt, -1, dist_base, cpu_base, percpu_offset); |
Rob Herring | 0fc0d94 | 2011-09-28 21:27:52 -0500 | [diff] [blame] | 1123 | |
| 1124 | if (parent) { |
| 1125 | irq = irq_of_parse_and_map(node, 0); |
| 1126 | gic_cascade_irq(gic_cnt, irq); |
| 1127 | } |
| 1128 | gic_cnt++; |
| 1129 | return 0; |
| 1130 | } |
| 1131 | #endif |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1132 | #ifdef CONFIG_ARCH_MSM8625 |
| 1133 | /* |
| 1134 | * Check for any interrupts which are enabled are pending |
| 1135 | * in the pending set or not. |
| 1136 | * Return : |
| 1137 | * 0 : No pending interrupts |
| 1138 | * 1 : Pending interrupts other than A9_M2A_5 |
| 1139 | */ |
| 1140 | unsigned int msm_gic_spi_ppi_pending(void) |
| 1141 | { |
| 1142 | unsigned int i, bit = 0; |
| 1143 | unsigned int pending_enb = 0, pending = 0; |
| 1144 | unsigned long value = 0; |
| 1145 | struct gic_chip_data *gic = &gic_data[0]; |
| 1146 | void __iomem *base = gic_data_dist_base(gic); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1147 | unsigned long flags; |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1148 | |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1149 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1150 | /* |
| 1151 | * PPI and SGI to be included. |
| 1152 | * MSM8625_INT_A9_M2A_5 needs to be ignored, as A9_M2A_5 |
| 1153 | * requesting sleep triggers it |
| 1154 | */ |
| 1155 | for (i = 0; (i * 32) < gic->max_irq; i++) { |
| 1156 | pending = readl_relaxed(base + |
| 1157 | GIC_DIST_PENDING_SET + i * 4); |
| 1158 | pending_enb = readl_relaxed(base + |
| 1159 | GIC_DIST_ENABLE_SET + i * 4); |
| 1160 | value = pending & pending_enb; |
| 1161 | |
| 1162 | if (value) { |
| 1163 | for (bit = 0; bit < 32; bit++) { |
| 1164 | bit = find_next_bit(&value, 32, bit); |
| 1165 | if ((bit + 32 * i) != MSM8625_INT_A9_M2A_5) { |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1166 | raw_spin_unlock_irqrestore( |
| 1167 | &irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1168 | return 1; |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | } |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1173 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | void msm_gic_save(bool modem_wake, int from_idle) |
| 1179 | { |
| 1180 | unsigned int i; |
| 1181 | struct gic_chip_data *gic = &gic_data[0]; |
| 1182 | void __iomem *base = gic_data_dist_base(gic); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1183 | unsigned long flags; |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1184 | |
| 1185 | gic_cpu_save(0); |
| 1186 | gic_dist_save(0); |
| 1187 | /* Disable all the Interrupts, if we enter from idle pc */ |
| 1188 | if (from_idle) { |
| 1189 | for (i = 0; (i * 32) < gic->max_irq; i++) { |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1190 | raw_spin_lock_irqsave( |
| 1191 | &irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1192 | writel_relaxed(0xffffffff, base |
| 1193 | + GIC_DIST_ENABLE_CLEAR + i * 4); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1194 | raw_spin_unlock_irqrestore( |
| 1195 | &irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | void msm_gic_restore(void) |
| 1201 | { |
| 1202 | gic_dist_restore(0); |
| 1203 | gic_cpu_restore(0); |
| 1204 | } |
| 1205 | |
| 1206 | /* |
| 1207 | * Configure the GIC after we come out of power collapse. |
| 1208 | * This function will configure some of the GIC registers so as to prepare the |
| 1209 | * core1 to receive an SPI(ACSR_MP_CORE_IPC1, (32 + 8)), which will bring |
| 1210 | * core1 out of GDFS. |
| 1211 | */ |
| 1212 | void core1_gic_configure_and_raise(void) |
| 1213 | { |
| 1214 | struct gic_chip_data *gic = &gic_data[0]; |
| 1215 | void __iomem *base = gic_data_dist_base(gic); |
| 1216 | unsigned int value = 0; |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1217 | unsigned long flags; |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1218 | |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1219 | raw_spin_lock_irqsave(&irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1220 | |
| 1221 | value = __raw_readl(base + GIC_DIST_ACTIVE_BIT + 0x4); |
| 1222 | value |= BIT(8); |
| 1223 | __raw_writel(value, base + GIC_DIST_ACTIVE_BIT + 0x4); |
| 1224 | mb(); |
| 1225 | |
| 1226 | value = __raw_readl(base + GIC_DIST_TARGET + 0x24); |
| 1227 | value |= BIT(13); |
| 1228 | __raw_writel(value, base + GIC_DIST_TARGET + 0x24); |
| 1229 | mb(); |
| 1230 | |
| 1231 | value = __raw_readl(base + GIC_DIST_TARGET + 0x28); |
| 1232 | value |= BIT(1); |
| 1233 | __raw_writel(value, base + GIC_DIST_TARGET + 0x28); |
| 1234 | mb(); |
| 1235 | |
| 1236 | value = __raw_readl(base + GIC_DIST_ENABLE_SET + 0x4); |
| 1237 | value |= BIT(8); |
| 1238 | __raw_writel(value, base + GIC_DIST_ENABLE_SET + 0x4); |
| 1239 | mb(); |
| 1240 | |
| 1241 | value = __raw_readl(base + GIC_DIST_PENDING_SET + 0x4); |
| 1242 | value |= BIT(8); |
| 1243 | __raw_writel(value, base + GIC_DIST_PENDING_SET + 0x4); |
| 1244 | mb(); |
Trilok Soni | 6278db0 | 2012-05-20 01:29:52 +0530 | [diff] [blame^] | 1245 | raw_spin_unlock_irqrestore(&irq_controller_lock, flags); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 1246 | } |
| 1247 | #endif |