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> |
| 27 | #include <linux/list.h> |
| 28 | #include <linux/smp.h> |
Catalin Marinas | dcb86e8 | 2005-08-31 21:45:14 +0100 | [diff] [blame] | 29 | #include <linux/cpumask.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 30 | #include <linux/io.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 31 | |
| 32 | #include <asm/irq.h> |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 33 | #include <asm/mach/irq.h> |
| 34 | #include <asm/hardware/gic.h> |
| 35 | |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 36 | static DEFINE_SPINLOCK(irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 37 | |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 38 | /* Address of GIC 0 CPU interface */ |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 39 | void __iomem *gic_cpu_base_addr __read_mostly; |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 40 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 41 | struct gic_chip_data { |
| 42 | unsigned int irq_offset; |
| 43 | void __iomem *dist_base; |
| 44 | void __iomem *cpu_base; |
| 45 | }; |
| 46 | |
| 47 | #ifndef MAX_GIC_NR |
| 48 | #define MAX_GIC_NR 1 |
| 49 | #endif |
| 50 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 51 | static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 52 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 53 | static inline void __iomem *gic_dist_base(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 54 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 55 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 56 | return gic_data->dist_base; |
| 57 | } |
| 58 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 59 | static inline void __iomem *gic_cpu_base(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 60 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 61 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 62 | return gic_data->cpu_base; |
| 63 | } |
| 64 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 65 | static inline unsigned int gic_irq(struct irq_data *d) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 66 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 67 | struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d); |
| 68 | return d->irq - gic_data->irq_offset; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 71 | /* |
| 72 | * Routines to acknowledge, disable and enable interrupts |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 73 | */ |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 74 | static void gic_ack_irq(struct irq_data *d) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 75 | { |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 76 | spin_lock(&irq_controller_lock); |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 77 | writel(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 78 | spin_unlock(&irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 81 | static void gic_mask_irq(struct irq_data *d) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 82 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 83 | u32 mask = 1 << (d->irq % 32); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 84 | |
| 85 | spin_lock(&irq_controller_lock); |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 86 | writel(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 87 | spin_unlock(&irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 90 | static void gic_unmask_irq(struct irq_data *d) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 91 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 92 | u32 mask = 1 << (d->irq % 32); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 93 | |
| 94 | spin_lock(&irq_controller_lock); |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 95 | writel(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 96 | spin_unlock(&irq_controller_lock); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 99 | static int gic_set_type(struct irq_data *d, unsigned int type) |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 100 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 101 | void __iomem *base = gic_dist_base(d); |
| 102 | unsigned int gicirq = gic_irq(d); |
Rabin Vincent | 5c0c1f0 | 2010-05-28 04:37:38 +0100 | [diff] [blame] | 103 | u32 enablemask = 1 << (gicirq % 32); |
| 104 | u32 enableoff = (gicirq / 32) * 4; |
| 105 | u32 confmask = 0x2 << ((gicirq % 16) * 2); |
| 106 | u32 confoff = (gicirq / 16) * 4; |
| 107 | bool enabled = false; |
| 108 | u32 val; |
| 109 | |
| 110 | /* Interrupt configuration for SGIs can't be changed */ |
| 111 | if (gicirq < 16) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING) |
| 115 | return -EINVAL; |
| 116 | |
| 117 | spin_lock(&irq_controller_lock); |
| 118 | |
| 119 | val = readl(base + GIC_DIST_CONFIG + confoff); |
| 120 | if (type == IRQ_TYPE_LEVEL_HIGH) |
| 121 | val &= ~confmask; |
| 122 | else if (type == IRQ_TYPE_EDGE_RISING) |
| 123 | val |= confmask; |
| 124 | |
| 125 | /* |
| 126 | * As recommended by the spec, disable the interrupt before changing |
| 127 | * the configuration |
| 128 | */ |
| 129 | if (readl(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) { |
| 130 | writel(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff); |
| 131 | enabled = true; |
| 132 | } |
| 133 | |
| 134 | writel(val, base + GIC_DIST_CONFIG + confoff); |
| 135 | |
| 136 | if (enabled) |
| 137 | writel(enablemask, base + GIC_DIST_ENABLE_SET + enableoff); |
| 138 | |
| 139 | spin_unlock(&irq_controller_lock); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 144 | #ifdef CONFIG_SMP |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 145 | static int |
| 146 | gic_set_cpu(struct irq_data *d, const struct cpumask *mask_val, bool force) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 147 | { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 148 | void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3); |
| 149 | unsigned int shift = (d->irq % 4) * 8; |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 150 | unsigned int cpu = cpumask_first(mask_val); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 151 | u32 val; |
Chao Xie | 8750750 | 2010-12-06 07:01:10 +0100 | [diff] [blame] | 152 | struct irq_desc *desc; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 153 | |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 154 | spin_lock(&irq_controller_lock); |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 155 | desc = irq_to_desc(d->irq); |
Chao Xie | 8750750 | 2010-12-06 07:01:10 +0100 | [diff] [blame] | 156 | if (desc == NULL) { |
| 157 | spin_unlock(&irq_controller_lock); |
| 158 | return -EINVAL; |
| 159 | } |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 160 | d->node = cpu; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 161 | val = readl(reg) & ~(0xff << shift); |
| 162 | val |= 1 << (cpu + shift); |
| 163 | writel(val, reg); |
Thomas Gleixner | c4bfa28 | 2006-07-01 22:32:14 +0100 | [diff] [blame] | 164 | spin_unlock(&irq_controller_lock); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 165 | |
| 166 | return 0; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 167 | } |
Catalin Marinas | a06f546 | 2005-09-30 16:07:05 +0100 | [diff] [blame] | 168 | #endif |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 169 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 170 | 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] | 171 | { |
| 172 | struct gic_chip_data *chip_data = get_irq_data(irq); |
| 173 | struct irq_chip *chip = get_irq_chip(irq); |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 174 | unsigned int cascade_irq, gic_irq; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 175 | unsigned long status; |
| 176 | |
| 177 | /* primary controller ack'ing */ |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 178 | chip->irq_ack(&desc->irq_data); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 179 | |
| 180 | spin_lock(&irq_controller_lock); |
| 181 | status = readl(chip_data->cpu_base + GIC_CPU_INTACK); |
| 182 | spin_unlock(&irq_controller_lock); |
| 183 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 184 | gic_irq = (status & 0x3ff); |
| 185 | if (gic_irq == 1023) |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 186 | goto out; |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 187 | |
Russell King | 0f347bb | 2007-05-17 10:11:34 +0100 | [diff] [blame] | 188 | cascade_irq = gic_irq + chip_data->irq_offset; |
| 189 | if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS)) |
| 190 | do_bad_IRQ(cascade_irq, desc); |
| 191 | else |
| 192 | generic_handle_irq(cascade_irq); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 193 | |
| 194 | out: |
| 195 | /* primary controller unmasking */ |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 196 | chip->irq_unmask(&desc->irq_data); |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 197 | } |
| 198 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 199 | static struct irq_chip gic_chip = { |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 200 | .name = "GIC", |
| 201 | .irq_ack = gic_ack_irq, |
| 202 | .irq_mask = gic_mask_irq, |
| 203 | .irq_unmask = gic_unmask_irq, |
| 204 | .irq_set_type = gic_set_type, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 205 | #ifdef CONFIG_SMP |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 206 | .irq_set_affinity = gic_set_cpu, |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 207 | #endif |
| 208 | }; |
| 209 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 210 | void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq) |
| 211 | { |
| 212 | if (gic_nr >= MAX_GIC_NR) |
| 213 | BUG(); |
| 214 | if (set_irq_data(irq, &gic_data[gic_nr]) != 0) |
| 215 | BUG(); |
| 216 | set_irq_chained_handler(irq, gic_handle_cascade_irq); |
| 217 | } |
| 218 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 219 | static void __init gic_dist_init(struct gic_chip_data *gic, |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 220 | unsigned int irq_start) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 221 | { |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 222 | unsigned int gic_irqs, irq_limit, i; |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 223 | void __iomem *base = gic->dist_base; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 224 | u32 cpumask = 1 << smp_processor_id(); |
| 225 | |
| 226 | cpumask |= cpumask << 8; |
| 227 | cpumask |= cpumask << 16; |
| 228 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 229 | writel(0, base + GIC_DIST_CTRL); |
| 230 | |
| 231 | /* |
| 232 | * Find out how many interrupts are supported. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 233 | * The GIC only supports up to 1020 interrupt sources. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 234 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 235 | gic_irqs = readl(base + GIC_DIST_CTR) & 0x1f; |
| 236 | gic_irqs = (gic_irqs + 1) * 32; |
| 237 | if (gic_irqs > 1020) |
| 238 | gic_irqs = 1020; |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 239 | |
| 240 | /* |
| 241 | * Set all global interrupts to be level triggered, active low. |
| 242 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 243 | for (i = 32; i < gic_irqs; i += 16) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 244 | writel(0, base + GIC_DIST_CONFIG + i * 4 / 16); |
| 245 | |
| 246 | /* |
| 247 | * Set all global interrupts to this CPU only. |
| 248 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 249 | for (i = 32; i < gic_irqs; i += 4) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 250 | writel(cpumask, base + GIC_DIST_TARGET + i * 4 / 4); |
| 251 | |
| 252 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 253 | * Set priority on all global interrupts. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 254 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 255 | for (i = 32; i < gic_irqs; i += 4) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 256 | writel(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4); |
| 257 | |
| 258 | /* |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 259 | * Disable all interrupts. Leave the PPI and SGIs alone |
| 260 | * as these enables are banked registers. |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 261 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 262 | for (i = 32; i < gic_irqs; i += 32) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 263 | writel(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32); |
| 264 | |
| 265 | /* |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 266 | * Limit number of interrupts registered to the platform maximum |
| 267 | */ |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 268 | irq_limit = gic->irq_offset + gic_irqs; |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 269 | if (WARN_ON(irq_limit > NR_IRQS)) |
| 270 | irq_limit = NR_IRQS; |
| 271 | |
| 272 | /* |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 273 | * Setup the Linux IRQ subsystem. |
| 274 | */ |
Pawel Moll | e6afec9 | 2010-11-26 13:45:43 +0100 | [diff] [blame] | 275 | for (i = irq_start; i < irq_limit; i++) { |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 276 | set_irq_chip(i, &gic_chip); |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 277 | set_irq_chip_data(i, gic); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 278 | set_irq_handler(i, handle_level_irq); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 279 | set_irq_flags(i, IRQF_VALID | IRQF_PROBE); |
| 280 | } |
| 281 | |
| 282 | writel(1, base + GIC_DIST_CTRL); |
| 283 | } |
| 284 | |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 285 | static void __cpuinit gic_cpu_init(struct gic_chip_data *gic) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 286 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 287 | void __iomem *dist_base = gic->dist_base; |
| 288 | void __iomem *base = gic->cpu_base; |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 289 | int i; |
| 290 | |
Russell King | 9395f6e | 2010-11-11 23:10:30 +0000 | [diff] [blame] | 291 | /* |
| 292 | * Deal with the banked PPI and SGI interrupts - disable all |
| 293 | * PPI interrupts, ensure all SGI interrupts are enabled. |
| 294 | */ |
| 295 | writel(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR); |
| 296 | writel(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET); |
| 297 | |
| 298 | /* |
| 299 | * Set priority on PPI and SGI interrupts |
| 300 | */ |
| 301 | for (i = 0; i < 32; i += 4) |
| 302 | writel(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4); |
| 303 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 304 | writel(0xf0, base + GIC_CPU_PRIMASK); |
| 305 | writel(1, base + GIC_CPU_CTRL); |
| 306 | } |
| 307 | |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 308 | void __init gic_init(unsigned int gic_nr, unsigned int irq_start, |
| 309 | void __iomem *dist_base, void __iomem *cpu_base) |
| 310 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 311 | struct gic_chip_data *gic; |
| 312 | |
| 313 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 314 | |
| 315 | gic = &gic_data[gic_nr]; |
| 316 | gic->dist_base = dist_base; |
| 317 | gic->cpu_base = cpu_base; |
| 318 | gic->irq_offset = (irq_start - 1) & ~31; |
| 319 | |
Russell King | ff2e27a | 2010-12-04 16:13:29 +0000 | [diff] [blame] | 320 | if (gic_nr == 0) |
| 321 | gic_cpu_base_addr = cpu_base; |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 322 | |
| 323 | gic_dist_init(gic, irq_start); |
| 324 | gic_cpu_init(gic); |
Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 327 | void __cpuinit gic_secondary_init(unsigned int gic_nr) |
| 328 | { |
Russell King | bef8f9e | 2010-12-04 16:50:58 +0000 | [diff] [blame] | 329 | BUG_ON(gic_nr >= MAX_GIC_NR); |
| 330 | |
| 331 | gic_cpu_init(&gic_data[gic_nr]); |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Russell King | ac61d14 | 2010-12-06 10:38:14 +0000 | [diff] [blame] | 334 | void __cpuinit gic_enable_ppi(unsigned int irq) |
| 335 | { |
| 336 | unsigned long flags; |
| 337 | |
| 338 | local_irq_save(flags); |
| 339 | irq_to_desc(irq)->status |= IRQ_NOPROBE; |
Lennert Buytenhek | 7d1f428 | 2010-11-29 10:18:20 +0100 | [diff] [blame^] | 340 | gic_unmask_irq(irq_get_irq_data(irq)); |
Russell King | ac61d14 | 2010-12-06 10:38:14 +0000 | [diff] [blame] | 341 | local_irq_restore(flags); |
| 342 | } |
| 343 | |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 344 | #ifdef CONFIG_SMP |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 345 | void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 346 | { |
Russell King | 8266810 | 2009-05-17 16:20:18 +0100 | [diff] [blame] | 347 | unsigned long map = *cpus_addr(*mask); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 348 | |
Catalin Marinas | b3a1bde | 2007-02-14 19:14:56 +0100 | [diff] [blame] | 349 | /* this always happens on GIC0 */ |
| 350 | writel(map << 16 | irq, gic_data[0].dist_base + GIC_DIST_SOFTINT); |
Russell King | f27ecac | 2005-08-18 21:31:00 +0100 | [diff] [blame] | 351 | } |
| 352 | #endif |