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