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