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