Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013, 2014 ARM Limited, All Rights Reserved. |
| 3 | * Author: Marc Zyngier <marc.zyngier@arm.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
Julien Grall | 68628bb | 2016-04-11 16:32:55 +0100 | [diff] [blame] | 18 | #define pr_fmt(fmt) "GICv3: " fmt |
| 19 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 20 | #include <linux/acpi.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 21 | #include <linux/cpu.h> |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 22 | #include <linux/cpu_pm.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/interrupt.h> |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 25 | #include <linux/irqdomain.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 26 | #include <linux/of.h> |
| 27 | #include <linux/of_address.h> |
| 28 | #include <linux/of_irq.h> |
| 29 | #include <linux/percpu.h> |
| 30 | #include <linux/slab.h> |
Channagoud Kadabi | df16454 | 2016-09-19 20:24:21 -0700 | [diff] [blame] | 31 | #include <linux/msm_rtb.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 32 | |
Joel Porquet | 41a83e0 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 33 | #include <linux/irqchip.h> |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 34 | #include <linux/irqchip/arm-gic-common.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 35 | #include <linux/irqchip/arm-gic-v3.h> |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 36 | #include <linux/irqchip/irq-partition-percpu.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 37 | |
| 38 | #include <asm/cputype.h> |
| 39 | #include <asm/exception.h> |
| 40 | #include <asm/smp_plat.h> |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 41 | #include <asm/virt.h> |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 42 | |
| 43 | #include "irq-gic-common.h" |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 44 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 45 | struct redist_region { |
| 46 | void __iomem *redist_base; |
| 47 | phys_addr_t phys_base; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 48 | bool single_redist; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 51 | struct gic_chip_data { |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 52 | struct fwnode_handle *fwnode; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 53 | void __iomem *dist_base; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 54 | struct redist_region *redist_regions; |
| 55 | struct rdists rdists; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 56 | struct irq_domain *domain; |
| 57 | u64 redist_stride; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 58 | u32 nr_redist_regions; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 59 | unsigned int irq_nr; |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 60 | struct partition_desc *ppi_descs[16]; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static struct gic_chip_data gic_data __read_mostly; |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 64 | static struct static_key supports_deactivate = STATIC_KEY_INIT_TRUE; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 65 | |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 66 | static struct gic_kvm_info gic_v3_kvm_info; |
| 67 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 68 | #define gic_data_rdist() (this_cpu_ptr(gic_data.rdists.rdist)) |
| 69 | #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 70 | #define gic_data_rdist_sgi_base() (gic_data_rdist_rd_base() + SZ_64K) |
| 71 | |
| 72 | /* Our default, arbitrary priority value. Linux only uses one anyway. */ |
| 73 | #define DEFAULT_PMR_VALUE 0xf0 |
| 74 | |
| 75 | static inline unsigned int gic_irq(struct irq_data *d) |
| 76 | { |
| 77 | return d->hwirq; |
| 78 | } |
| 79 | |
| 80 | static inline int gic_irq_in_rdist(struct irq_data *d) |
| 81 | { |
| 82 | return gic_irq(d) < 32; |
| 83 | } |
| 84 | |
| 85 | static inline void __iomem *gic_dist_base(struct irq_data *d) |
| 86 | { |
| 87 | if (gic_irq_in_rdist(d)) /* SGI+PPI -> SGI_base for this CPU */ |
| 88 | return gic_data_rdist_sgi_base(); |
| 89 | |
| 90 | if (d->hwirq <= 1023) /* SPI -> dist_base */ |
| 91 | return gic_data.dist_base; |
| 92 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 93 | return NULL; |
| 94 | } |
| 95 | |
| 96 | static void gic_do_wait_for_rwp(void __iomem *base) |
| 97 | { |
| 98 | u32 count = 1000000; /* 1s! */ |
| 99 | |
| 100 | while (readl_relaxed(base + GICD_CTLR) & GICD_CTLR_RWP) { |
| 101 | count--; |
| 102 | if (!count) { |
| 103 | pr_err_ratelimited("RWP timeout, gone fishing\n"); |
| 104 | return; |
| 105 | } |
| 106 | cpu_relax(); |
| 107 | udelay(1); |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | /* Wait for completion of a distributor change */ |
| 112 | static void gic_dist_wait_for_rwp(void) |
| 113 | { |
| 114 | gic_do_wait_for_rwp(gic_data.dist_base); |
| 115 | } |
| 116 | |
| 117 | /* Wait for completion of a redistributor change */ |
| 118 | static void gic_redist_wait_for_rwp(void) |
| 119 | { |
| 120 | gic_do_wait_for_rwp(gic_data_rdist_rd_base()); |
| 121 | } |
| 122 | |
Jean-Philippe Brucker | 7936e91 | 2015-10-01 13:47:14 +0100 | [diff] [blame] | 123 | #ifdef CONFIG_ARM64 |
Robert Richter | 8ac2a17 | 2015-09-21 22:58:39 +0200 | [diff] [blame] | 124 | static DEFINE_STATIC_KEY_FALSE(is_cavium_thunderx); |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 125 | |
| 126 | static u64 __maybe_unused gic_read_iar(void) |
| 127 | { |
Robert Richter | 8ac2a17 | 2015-09-21 22:58:39 +0200 | [diff] [blame] | 128 | if (static_branch_unlikely(&is_cavium_thunderx)) |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 129 | return gic_read_iar_cavium_thunderx(); |
| 130 | else |
| 131 | return gic_read_iar_common(); |
| 132 | } |
Jean-Philippe Brucker | 7936e91 | 2015-10-01 13:47:14 +0100 | [diff] [blame] | 133 | #endif |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 134 | |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 135 | static void gic_enable_redist(bool enable) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 136 | { |
| 137 | void __iomem *rbase; |
| 138 | u32 count = 1000000; /* 1s! */ |
| 139 | u32 val; |
| 140 | |
| 141 | rbase = gic_data_rdist_rd_base(); |
| 142 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 143 | val = readl_relaxed(rbase + GICR_WAKER); |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 144 | if (enable) |
| 145 | /* Wake up this CPU redistributor */ |
| 146 | val &= ~GICR_WAKER_ProcessorSleep; |
| 147 | else |
| 148 | val |= GICR_WAKER_ProcessorSleep; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 149 | writel_relaxed(val, rbase + GICR_WAKER); |
| 150 | |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 151 | if (!enable) { /* Check that GICR_WAKER is writeable */ |
| 152 | val = readl_relaxed(rbase + GICR_WAKER); |
| 153 | if (!(val & GICR_WAKER_ProcessorSleep)) |
| 154 | return; /* No PM support in this redistributor */ |
| 155 | } |
| 156 | |
| 157 | while (count--) { |
| 158 | val = readl_relaxed(rbase + GICR_WAKER); |
Andrew Jones | cf1d9d1 | 2016-05-11 21:23:17 +0200 | [diff] [blame] | 159 | if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep)) |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 160 | break; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 161 | cpu_relax(); |
| 162 | udelay(1); |
| 163 | }; |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 164 | if (!count) |
| 165 | pr_err_ratelimited("redistributor failed to %s...\n", |
| 166 | enable ? "wakeup" : "sleep"); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /* |
| 170 | * Routines to disable, enable, EOI and route interrupts |
| 171 | */ |
Marc Zyngier | b594c6e | 2015-03-18 11:01:24 +0000 | [diff] [blame] | 172 | static int gic_peek_irq(struct irq_data *d, u32 offset) |
| 173 | { |
| 174 | u32 mask = 1 << (gic_irq(d) % 32); |
| 175 | void __iomem *base; |
| 176 | |
| 177 | if (gic_irq_in_rdist(d)) |
| 178 | base = gic_data_rdist_sgi_base(); |
| 179 | else |
| 180 | base = gic_data.dist_base; |
| 181 | |
| 182 | return !!(readl_relaxed(base + offset + (gic_irq(d) / 32) * 4) & mask); |
| 183 | } |
| 184 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 185 | static void gic_poke_irq(struct irq_data *d, u32 offset) |
| 186 | { |
| 187 | u32 mask = 1 << (gic_irq(d) % 32); |
| 188 | void (*rwp_wait)(void); |
| 189 | void __iomem *base; |
| 190 | |
| 191 | if (gic_irq_in_rdist(d)) { |
| 192 | base = gic_data_rdist_sgi_base(); |
| 193 | rwp_wait = gic_redist_wait_for_rwp; |
| 194 | } else { |
| 195 | base = gic_data.dist_base; |
| 196 | rwp_wait = gic_dist_wait_for_rwp; |
| 197 | } |
| 198 | |
| 199 | writel_relaxed(mask, base + offset + (gic_irq(d) / 32) * 4); |
| 200 | rwp_wait(); |
| 201 | } |
| 202 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 203 | static void gic_mask_irq(struct irq_data *d) |
| 204 | { |
| 205 | gic_poke_irq(d, GICD_ICENABLER); |
| 206 | } |
| 207 | |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 208 | static void gic_eoimode1_mask_irq(struct irq_data *d) |
| 209 | { |
| 210 | gic_mask_irq(d); |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 211 | /* |
| 212 | * When masking a forwarded interrupt, make sure it is |
| 213 | * deactivated as well. |
| 214 | * |
| 215 | * This ensures that an interrupt that is getting |
| 216 | * disabled/masked will not get "stuck", because there is |
| 217 | * noone to deactivate it (guest is being terminated). |
| 218 | */ |
Thomas Gleixner | 4df7f54 | 2015-09-15 13:19:16 +0200 | [diff] [blame] | 219 | if (irqd_is_forwarded_to_vcpu(d)) |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 220 | gic_poke_irq(d, GICD_ICACTIVER); |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 223 | static void gic_unmask_irq(struct irq_data *d) |
| 224 | { |
| 225 | gic_poke_irq(d, GICD_ISENABLER); |
| 226 | } |
| 227 | |
Marc Zyngier | b594c6e | 2015-03-18 11:01:24 +0000 | [diff] [blame] | 228 | static int gic_irq_set_irqchip_state(struct irq_data *d, |
| 229 | enum irqchip_irq_state which, bool val) |
| 230 | { |
| 231 | u32 reg; |
| 232 | |
| 233 | if (d->hwirq >= gic_data.irq_nr) /* PPI/SPI only */ |
| 234 | return -EINVAL; |
| 235 | |
| 236 | switch (which) { |
| 237 | case IRQCHIP_STATE_PENDING: |
| 238 | reg = val ? GICD_ISPENDR : GICD_ICPENDR; |
| 239 | break; |
| 240 | |
| 241 | case IRQCHIP_STATE_ACTIVE: |
| 242 | reg = val ? GICD_ISACTIVER : GICD_ICACTIVER; |
| 243 | break; |
| 244 | |
| 245 | case IRQCHIP_STATE_MASKED: |
| 246 | reg = val ? GICD_ICENABLER : GICD_ISENABLER; |
| 247 | break; |
| 248 | |
| 249 | default: |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | |
| 253 | gic_poke_irq(d, reg); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int gic_irq_get_irqchip_state(struct irq_data *d, |
| 258 | enum irqchip_irq_state which, bool *val) |
| 259 | { |
| 260 | if (d->hwirq >= gic_data.irq_nr) /* PPI/SPI only */ |
| 261 | return -EINVAL; |
| 262 | |
| 263 | switch (which) { |
| 264 | case IRQCHIP_STATE_PENDING: |
| 265 | *val = gic_peek_irq(d, GICD_ISPENDR); |
| 266 | break; |
| 267 | |
| 268 | case IRQCHIP_STATE_ACTIVE: |
| 269 | *val = gic_peek_irq(d, GICD_ISACTIVER); |
| 270 | break; |
| 271 | |
| 272 | case IRQCHIP_STATE_MASKED: |
| 273 | *val = !gic_peek_irq(d, GICD_ISENABLER); |
| 274 | break; |
| 275 | |
| 276 | default: |
| 277 | return -EINVAL; |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 283 | static void gic_eoi_irq(struct irq_data *d) |
| 284 | { |
| 285 | gic_write_eoir(gic_irq(d)); |
| 286 | } |
| 287 | |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 288 | static void gic_eoimode1_eoi_irq(struct irq_data *d) |
| 289 | { |
| 290 | /* |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 291 | * No need to deactivate an LPI, or an interrupt that |
| 292 | * is is getting forwarded to a vcpu. |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 293 | */ |
Thomas Gleixner | 4df7f54 | 2015-09-15 13:19:16 +0200 | [diff] [blame] | 294 | if (gic_irq(d) >= 8192 || irqd_is_forwarded_to_vcpu(d)) |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 295 | return; |
| 296 | gic_write_dir(gic_irq(d)); |
| 297 | } |
| 298 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 299 | static int gic_set_type(struct irq_data *d, unsigned int type) |
| 300 | { |
| 301 | unsigned int irq = gic_irq(d); |
| 302 | void (*rwp_wait)(void); |
| 303 | void __iomem *base; |
| 304 | |
| 305 | /* Interrupt configuration for SGIs can't be changed */ |
| 306 | if (irq < 16) |
| 307 | return -EINVAL; |
| 308 | |
Liviu Dudau | fb7e7de | 2015-01-20 16:52:59 +0000 | [diff] [blame] | 309 | /* SPIs have restrictions on the supported types */ |
| 310 | if (irq >= 32 && type != IRQ_TYPE_LEVEL_HIGH && |
| 311 | type != IRQ_TYPE_EDGE_RISING) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 312 | return -EINVAL; |
| 313 | |
| 314 | if (gic_irq_in_rdist(d)) { |
| 315 | base = gic_data_rdist_sgi_base(); |
| 316 | rwp_wait = gic_redist_wait_for_rwp; |
| 317 | } else { |
| 318 | base = gic_data.dist_base; |
| 319 | rwp_wait = gic_dist_wait_for_rwp; |
| 320 | } |
| 321 | |
Liviu Dudau | fb7e7de | 2015-01-20 16:52:59 +0000 | [diff] [blame] | 322 | return gic_configure_irq(irq, type, base, rwp_wait); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 325 | static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) |
| 326 | { |
Thomas Gleixner | 4df7f54 | 2015-09-15 13:19:16 +0200 | [diff] [blame] | 327 | if (vcpu) |
| 328 | irqd_set_forwarded_to_vcpu(d); |
| 329 | else |
| 330 | irqd_clr_forwarded_to_vcpu(d); |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 334 | static u64 gic_mpidr_to_affinity(unsigned long mpidr) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 335 | { |
| 336 | u64 aff; |
| 337 | |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 338 | aff = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 339 | MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 | |
| 340 | MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 | |
| 341 | MPIDR_AFFINITY_LEVEL(mpidr, 0)); |
| 342 | |
| 343 | return aff; |
| 344 | } |
| 345 | |
| 346 | static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) |
| 347 | { |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 348 | u32 irqnr; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 349 | |
| 350 | do { |
| 351 | irqnr = gic_read_iar(); |
| 352 | |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 353 | if (likely(irqnr > 15 && irqnr < 1020) || irqnr >= 8192) { |
Marc Zyngier | ebc6de0 | 2014-08-26 11:03:33 +0100 | [diff] [blame] | 354 | int err; |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 355 | |
Channagoud Kadabi | df16454 | 2016-09-19 20:24:21 -0700 | [diff] [blame] | 356 | uncached_logk(LOGK_IRQ, (void *)(uintptr_t)irqnr); |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 357 | if (static_key_true(&supports_deactivate)) |
| 358 | gic_write_eoir(irqnr); |
| 359 | |
Marc Zyngier | ebc6de0 | 2014-08-26 11:03:33 +0100 | [diff] [blame] | 360 | err = handle_domain_irq(gic_data.domain, irqnr, regs); |
| 361 | if (err) { |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 362 | WARN_ONCE(true, "Unexpected interrupt received!\n"); |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 363 | if (static_key_true(&supports_deactivate)) { |
| 364 | if (irqnr < 8192) |
| 365 | gic_write_dir(irqnr); |
| 366 | } else { |
| 367 | gic_write_eoir(irqnr); |
| 368 | } |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 369 | } |
Marc Zyngier | ebc6de0 | 2014-08-26 11:03:33 +0100 | [diff] [blame] | 370 | continue; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 371 | } |
| 372 | if (irqnr < 16) { |
Channagoud Kadabi | df16454 | 2016-09-19 20:24:21 -0700 | [diff] [blame] | 373 | uncached_logk(LOGK_IRQ, (void *)(uintptr_t)irqnr); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 374 | gic_write_eoir(irqnr); |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 375 | if (static_key_true(&supports_deactivate)) |
| 376 | gic_write_dir(irqnr); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 377 | #ifdef CONFIG_SMP |
Will Deacon | f86c4fb | 2016-04-26 12:00:00 +0100 | [diff] [blame] | 378 | /* |
| 379 | * Unlike GICv2, we don't need an smp_rmb() here. |
| 380 | * The control dependency from gic_read_iar to |
| 381 | * the ISB in gic_write_eoir is enough to ensure |
| 382 | * that any shared data read by handle_IPI will |
| 383 | * be read after the ACK. |
| 384 | */ |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 385 | handle_IPI(irqnr, regs); |
| 386 | #else |
| 387 | WARN_ONCE(true, "Unexpected SGI received!\n"); |
| 388 | #endif |
| 389 | continue; |
| 390 | } |
| 391 | } while (irqnr != ICC_IAR1_EL1_SPURIOUS); |
| 392 | } |
| 393 | |
| 394 | static void __init gic_dist_init(void) |
| 395 | { |
| 396 | unsigned int i; |
| 397 | u64 affinity; |
| 398 | void __iomem *base = gic_data.dist_base; |
| 399 | |
| 400 | /* Disable the distributor */ |
| 401 | writel_relaxed(0, base + GICD_CTLR); |
| 402 | gic_dist_wait_for_rwp(); |
| 403 | |
Marc Zyngier | 7c9b973 | 2016-05-06 19:41:56 +0100 | [diff] [blame] | 404 | /* |
| 405 | * Configure SPIs as non-secure Group-1. This will only matter |
| 406 | * if the GIC only has a single security state. This will not |
| 407 | * do the right thing if the kernel is running in secure mode, |
| 408 | * but that's not the intended use case anyway. |
| 409 | */ |
| 410 | for (i = 32; i < gic_data.irq_nr; i += 32) |
| 411 | writel_relaxed(~0, base + GICD_IGROUPR + i / 8); |
| 412 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 413 | gic_dist_config(base, gic_data.irq_nr, gic_dist_wait_for_rwp); |
| 414 | |
| 415 | /* Enable distributor with ARE, Group1 */ |
| 416 | writel_relaxed(GICD_CTLR_ARE_NS | GICD_CTLR_ENABLE_G1A | GICD_CTLR_ENABLE_G1, |
| 417 | base + GICD_CTLR); |
| 418 | |
| 419 | /* |
| 420 | * Set all global interrupts to the boot CPU only. ARE must be |
| 421 | * enabled. |
| 422 | */ |
| 423 | affinity = gic_mpidr_to_affinity(cpu_logical_map(smp_processor_id())); |
| 424 | for (i = 32; i < gic_data.irq_nr; i++) |
Jean-Philippe Brucker | 72c9712 | 2015-10-01 13:47:16 +0100 | [diff] [blame] | 425 | gic_write_irouter(affinity, base + GICD_IROUTER + i * 8); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int gic_populate_rdist(void) |
| 429 | { |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 430 | unsigned long mpidr = cpu_logical_map(smp_processor_id()); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 431 | u64 typer; |
| 432 | u32 aff; |
| 433 | int i; |
| 434 | |
| 435 | /* |
| 436 | * Convert affinity to a 32bit value that can be matched to |
| 437 | * GICR_TYPER bits [63:32]. |
| 438 | */ |
| 439 | aff = (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 24 | |
| 440 | MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 | |
| 441 | MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 | |
| 442 | MPIDR_AFFINITY_LEVEL(mpidr, 0)); |
| 443 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 444 | for (i = 0; i < gic_data.nr_redist_regions; i++) { |
| 445 | void __iomem *ptr = gic_data.redist_regions[i].redist_base; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 446 | u32 reg; |
| 447 | |
| 448 | reg = readl_relaxed(ptr + GICR_PIDR2) & GIC_PIDR2_ARCH_MASK; |
| 449 | if (reg != GIC_PIDR2_ARCH_GICv3 && |
| 450 | reg != GIC_PIDR2_ARCH_GICv4) { /* We're in trouble... */ |
| 451 | pr_warn("No redistributor present @%p\n", ptr); |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | do { |
Jean-Philippe Brucker | 72c9712 | 2015-10-01 13:47:16 +0100 | [diff] [blame] | 456 | typer = gic_read_typer(ptr + GICR_TYPER); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 457 | if ((typer >> 32) == aff) { |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 458 | u64 offset = ptr - gic_data.redist_regions[i].redist_base; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 459 | gic_data_rdist_rd_base() = ptr; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 460 | gic_data_rdist()->phys_base = gic_data.redist_regions[i].phys_base + offset; |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 461 | pr_info("CPU%d: found redistributor %lx region %d:%pa\n", |
| 462 | smp_processor_id(), mpidr, i, |
| 463 | &gic_data_rdist()->phys_base); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 464 | return 0; |
| 465 | } |
| 466 | |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 467 | if (gic_data.redist_regions[i].single_redist) |
| 468 | break; |
| 469 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 470 | if (gic_data.redist_stride) { |
| 471 | ptr += gic_data.redist_stride; |
| 472 | } else { |
| 473 | ptr += SZ_64K * 2; /* Skip RD_base + SGI_base */ |
| 474 | if (typer & GICR_TYPER_VLPIS) |
| 475 | ptr += SZ_64K * 2; /* Skip VLPI_base + reserved page */ |
| 476 | } |
| 477 | } while (!(typer & GICR_TYPER_LAST)); |
| 478 | } |
| 479 | |
| 480 | /* We couldn't even deal with ourselves... */ |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 481 | WARN(true, "CPU%d: mpidr %lx has no re-distributor!\n", |
| 482 | smp_processor_id(), mpidr); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 483 | return -ENODEV; |
| 484 | } |
| 485 | |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 486 | static void gic_cpu_sys_reg_init(void) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 487 | { |
Marc Zyngier | 7cabd00 | 2015-09-30 11:48:01 +0100 | [diff] [blame] | 488 | /* |
| 489 | * Need to check that the SRE bit has actually been set. If |
| 490 | * not, it means that SRE is disabled at EL2. We're going to |
| 491 | * die painfully, and there is nothing we can do about it. |
| 492 | * |
| 493 | * Kindly inform the luser. |
| 494 | */ |
| 495 | if (!gic_enable_sre()) |
| 496 | pr_err("GIC: unable to set SRE (disabled at EL2), panic ahead\n"); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 497 | |
| 498 | /* Set priority mask register */ |
| 499 | gic_write_pmr(DEFAULT_PMR_VALUE); |
| 500 | |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 501 | if (static_key_true(&supports_deactivate)) { |
| 502 | /* EOI drops priority only (mode 1) */ |
| 503 | gic_write_ctlr(ICC_CTLR_EL1_EOImode_drop); |
| 504 | } else { |
| 505 | /* EOI deactivates interrupt too (mode 0) */ |
| 506 | gic_write_ctlr(ICC_CTLR_EL1_EOImode_drop_dir); |
| 507 | } |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 508 | |
| 509 | /* ... and let's hit the road... */ |
| 510 | gic_write_grpen1(1); |
| 511 | } |
| 512 | |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 513 | static int gic_dist_supports_lpis(void) |
| 514 | { |
| 515 | return !!(readl_relaxed(gic_data.dist_base + GICD_TYPER) & GICD_TYPER_LPIS); |
| 516 | } |
| 517 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 518 | static void gic_cpu_init(void) |
| 519 | { |
| 520 | void __iomem *rbase; |
| 521 | |
| 522 | /* Register ourselves with the rest of the world */ |
| 523 | if (gic_populate_rdist()) |
| 524 | return; |
| 525 | |
Sudeep Holla | a2c2251 | 2014-08-26 16:03:34 +0100 | [diff] [blame] | 526 | gic_enable_redist(true); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 527 | |
| 528 | rbase = gic_data_rdist_sgi_base(); |
| 529 | |
Marc Zyngier | 7c9b973 | 2016-05-06 19:41:56 +0100 | [diff] [blame] | 530 | /* Configure SGIs/PPIs as non-secure Group-1 */ |
| 531 | writel_relaxed(~0, rbase + GICR_IGROUPR0); |
| 532 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 533 | gic_cpu_config(rbase, gic_redist_wait_for_rwp); |
| 534 | |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 535 | /* Give LPIs a spin */ |
Channagoud Kadabi | fdb0664 | 2016-09-19 20:55:36 -0700 | [diff] [blame^] | 536 | if (IS_ENABLED(CONFIG_ARM_GIC_V3_ITS) && gic_dist_supports_lpis() && |
| 537 | !IS_ENABLED(CONFIG_ARM_GIC_V3_ACL)) |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 538 | its_cpu_init(); |
| 539 | |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 540 | /* initialise system registers */ |
| 541 | gic_cpu_sys_reg_init(); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | #ifdef CONFIG_SMP |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 545 | |
Richard Cochran | 6670a6d | 2016-07-13 17:16:05 +0000 | [diff] [blame] | 546 | static int gic_starting_cpu(unsigned int cpu) |
| 547 | { |
| 548 | gic_cpu_init(); |
| 549 | return 0; |
| 550 | } |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 551 | |
| 552 | static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask, |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 553 | unsigned long cluster_id) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 554 | { |
| 555 | int cpu = *base_cpu; |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 556 | unsigned long mpidr = cpu_logical_map(cpu); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 557 | u16 tlist = 0; |
| 558 | |
| 559 | while (cpu < nr_cpu_ids) { |
| 560 | /* |
| 561 | * If we ever get a cluster of more than 16 CPUs, just |
| 562 | * scream and skip that CPU. |
| 563 | */ |
| 564 | if (WARN_ON((mpidr & 0xff) >= 16)) |
| 565 | goto out; |
| 566 | |
| 567 | tlist |= 1 << (mpidr & 0xf); |
| 568 | |
| 569 | cpu = cpumask_next(cpu, mask); |
Vladimir Murzin | 614be38 | 2015-03-06 16:37:45 +0000 | [diff] [blame] | 570 | if (cpu >= nr_cpu_ids) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 571 | goto out; |
| 572 | |
| 573 | mpidr = cpu_logical_map(cpu); |
| 574 | |
| 575 | if (cluster_id != (mpidr & ~0xffUL)) { |
| 576 | cpu--; |
| 577 | goto out; |
| 578 | } |
| 579 | } |
| 580 | out: |
| 581 | *base_cpu = cpu; |
| 582 | return tlist; |
| 583 | } |
| 584 | |
Andre Przywara | 7e58027 | 2014-11-12 13:46:06 +0000 | [diff] [blame] | 585 | #define MPIDR_TO_SGI_AFFINITY(cluster_id, level) \ |
| 586 | (MPIDR_AFFINITY_LEVEL(cluster_id, level) \ |
| 587 | << ICC_SGI1R_AFFINITY_## level ##_SHIFT) |
| 588 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 589 | static void gic_send_sgi(u64 cluster_id, u16 tlist, unsigned int irq) |
| 590 | { |
| 591 | u64 val; |
| 592 | |
Andre Przywara | 7e58027 | 2014-11-12 13:46:06 +0000 | [diff] [blame] | 593 | val = (MPIDR_TO_SGI_AFFINITY(cluster_id, 3) | |
| 594 | MPIDR_TO_SGI_AFFINITY(cluster_id, 2) | |
| 595 | irq << ICC_SGI1R_SGI_ID_SHIFT | |
| 596 | MPIDR_TO_SGI_AFFINITY(cluster_id, 1) | |
| 597 | tlist << ICC_SGI1R_TARGET_LIST_SHIFT); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 598 | |
| 599 | pr_debug("CPU%d: ICC_SGI1R_EL1 %llx\n", smp_processor_id(), val); |
| 600 | gic_write_sgi1r(val); |
| 601 | } |
| 602 | |
| 603 | static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) |
| 604 | { |
| 605 | int cpu; |
| 606 | |
| 607 | if (WARN_ON(irq >= 16)) |
| 608 | return; |
| 609 | |
| 610 | /* |
| 611 | * Ensure that stores to Normal memory are visible to the |
| 612 | * other CPUs before issuing the IPI. |
| 613 | */ |
| 614 | smp_wmb(); |
| 615 | |
Rusty Russell | f9b531f | 2015-03-05 10:49:16 +1030 | [diff] [blame] | 616 | for_each_cpu(cpu, mask) { |
Jean-Philippe Brucker | f6c86a4 | 2015-10-01 13:47:15 +0100 | [diff] [blame] | 617 | unsigned long cluster_id = cpu_logical_map(cpu) & ~0xffUL; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 618 | u16 tlist; |
| 619 | |
| 620 | tlist = gic_compute_target_list(&cpu, mask, cluster_id); |
| 621 | gic_send_sgi(cluster_id, tlist, irq); |
| 622 | } |
| 623 | |
| 624 | /* Force the above writes to ICC_SGI1R_EL1 to be executed */ |
| 625 | isb(); |
| 626 | } |
| 627 | |
| 628 | static void gic_smp_init(void) |
| 629 | { |
| 630 | set_smp_cross_call(gic_raise_softirq); |
Richard Cochran | 6670a6d | 2016-07-13 17:16:05 +0000 | [diff] [blame] | 631 | cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_GICV3_STARTING, |
| 632 | "AP_IRQ_GICV3_STARTING", gic_starting_cpu, |
| 633 | NULL); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 637 | bool force) |
| 638 | { |
| 639 | unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask); |
| 640 | void __iomem *reg; |
| 641 | int enabled; |
| 642 | u64 val; |
| 643 | |
| 644 | if (gic_irq_in_rdist(d)) |
| 645 | return -EINVAL; |
| 646 | |
| 647 | /* If interrupt was enabled, disable it first */ |
| 648 | enabled = gic_peek_irq(d, GICD_ISENABLER); |
| 649 | if (enabled) |
| 650 | gic_mask_irq(d); |
| 651 | |
| 652 | reg = gic_dist_base(d) + GICD_IROUTER + (gic_irq(d) * 8); |
| 653 | val = gic_mpidr_to_affinity(cpu_logical_map(cpu)); |
| 654 | |
Jean-Philippe Brucker | 72c9712 | 2015-10-01 13:47:16 +0100 | [diff] [blame] | 655 | gic_write_irouter(val, reg); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 656 | |
| 657 | /* |
| 658 | * If the interrupt was enabled, enabled it again. Otherwise, |
| 659 | * just wait for the distributor to have digested our changes. |
| 660 | */ |
| 661 | if (enabled) |
| 662 | gic_unmask_irq(d); |
| 663 | else |
| 664 | gic_dist_wait_for_rwp(); |
| 665 | |
Antoine Tenart | 0fc6fa2 | 2016-02-19 16:22:43 +0100 | [diff] [blame] | 666 | return IRQ_SET_MASK_OK_DONE; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 667 | } |
| 668 | #else |
| 669 | #define gic_set_affinity NULL |
| 670 | #define gic_smp_init() do { } while(0) |
| 671 | #endif |
| 672 | |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 673 | #ifdef CONFIG_CPU_PM |
Sudeep Holla | ccd9432 | 2016-08-17 13:49:19 +0100 | [diff] [blame] | 674 | /* Check whether it's single security state view */ |
| 675 | static bool gic_dist_security_disabled(void) |
| 676 | { |
| 677 | return readl_relaxed(gic_data.dist_base + GICD_CTLR) & GICD_CTLR_DS; |
| 678 | } |
| 679 | |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 680 | static int gic_cpu_pm_notifier(struct notifier_block *self, |
| 681 | unsigned long cmd, void *v) |
| 682 | { |
| 683 | if (cmd == CPU_PM_EXIT) { |
Sudeep Holla | ccd9432 | 2016-08-17 13:49:19 +0100 | [diff] [blame] | 684 | if (gic_dist_security_disabled()) |
| 685 | gic_enable_redist(true); |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 686 | gic_cpu_sys_reg_init(); |
Sudeep Holla | ccd9432 | 2016-08-17 13:49:19 +0100 | [diff] [blame] | 687 | } else if (cmd == CPU_PM_ENTER && gic_dist_security_disabled()) { |
Sudeep Holla | 3708d52 | 2014-08-26 16:03:35 +0100 | [diff] [blame] | 688 | gic_write_grpen1(0); |
| 689 | gic_enable_redist(false); |
| 690 | } |
| 691 | return NOTIFY_OK; |
| 692 | } |
| 693 | |
| 694 | static struct notifier_block gic_cpu_pm_notifier_block = { |
| 695 | .notifier_call = gic_cpu_pm_notifier, |
| 696 | }; |
| 697 | |
| 698 | static void gic_cpu_pm_init(void) |
| 699 | { |
| 700 | cpu_pm_register_notifier(&gic_cpu_pm_notifier_block); |
| 701 | } |
| 702 | |
| 703 | #else |
| 704 | static inline void gic_cpu_pm_init(void) { } |
| 705 | #endif /* CONFIG_CPU_PM */ |
| 706 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 707 | static struct irq_chip gic_chip = { |
| 708 | .name = "GICv3", |
| 709 | .irq_mask = gic_mask_irq, |
| 710 | .irq_unmask = gic_unmask_irq, |
| 711 | .irq_eoi = gic_eoi_irq, |
| 712 | .irq_set_type = gic_set_type, |
| 713 | .irq_set_affinity = gic_set_affinity, |
Marc Zyngier | b594c6e | 2015-03-18 11:01:24 +0000 | [diff] [blame] | 714 | .irq_get_irqchip_state = gic_irq_get_irqchip_state, |
| 715 | .irq_set_irqchip_state = gic_irq_set_irqchip_state, |
Sudeep Holla | 55963c9 | 2015-06-05 11:59:57 +0100 | [diff] [blame] | 716 | .flags = IRQCHIP_SET_TYPE_MASKED, |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 717 | }; |
| 718 | |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 719 | static struct irq_chip gic_eoimode1_chip = { |
| 720 | .name = "GICv3", |
| 721 | .irq_mask = gic_eoimode1_mask_irq, |
| 722 | .irq_unmask = gic_unmask_irq, |
| 723 | .irq_eoi = gic_eoimode1_eoi_irq, |
| 724 | .irq_set_type = gic_set_type, |
| 725 | .irq_set_affinity = gic_set_affinity, |
| 726 | .irq_get_irqchip_state = gic_irq_get_irqchip_state, |
| 727 | .irq_set_irqchip_state = gic_irq_set_irqchip_state, |
Marc Zyngier | 530bf35 | 2015-08-26 17:00:43 +0100 | [diff] [blame] | 728 | .irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity, |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 729 | .flags = IRQCHIP_SET_TYPE_MASKED, |
| 730 | }; |
| 731 | |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 732 | #define GIC_ID_NR (1U << gic_data.rdists.id_bits) |
| 733 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 734 | static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq, |
| 735 | irq_hw_number_t hw) |
| 736 | { |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 737 | struct irq_chip *chip = &gic_chip; |
| 738 | |
| 739 | if (static_key_true(&supports_deactivate)) |
| 740 | chip = &gic_eoimode1_chip; |
| 741 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 742 | /* SGIs are private to the core kernel */ |
| 743 | if (hw < 16) |
| 744 | return -EPERM; |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 745 | /* Nothing here */ |
| 746 | if (hw >= gic_data.irq_nr && hw < 8192) |
| 747 | return -EPERM; |
| 748 | /* Off limits */ |
| 749 | if (hw >= GIC_ID_NR) |
| 750 | return -EPERM; |
| 751 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 752 | /* PPIs */ |
| 753 | if (hw < 32) { |
| 754 | irq_set_percpu_devid(irq); |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 755 | irq_domain_set_info(d, irq, hw, chip, d->host_data, |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 756 | handle_percpu_devid_irq, NULL, NULL); |
Rob Herring | d17cab4 | 2015-08-29 18:01:22 -0500 | [diff] [blame] | 757 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 758 | } |
| 759 | /* SPIs */ |
| 760 | if (hw >= 32 && hw < gic_data.irq_nr) { |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 761 | irq_domain_set_info(d, irq, hw, chip, d->host_data, |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 762 | handle_fasteoi_irq, NULL, NULL); |
Rob Herring | d17cab4 | 2015-08-29 18:01:22 -0500 | [diff] [blame] | 763 | irq_set_probe(irq); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 764 | } |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 765 | /* LPIs */ |
| 766 | if (hw >= 8192 && hw < GIC_ID_NR) { |
| 767 | if (!gic_dist_supports_lpis()) |
| 768 | return -EPERM; |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 769 | irq_domain_set_info(d, irq, hw, chip, d->host_data, |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 770 | handle_fasteoi_irq, NULL, NULL); |
Marc Zyngier | da33f31 | 2014-11-24 14:35:18 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 776 | static int gic_irq_domain_translate(struct irq_domain *d, |
| 777 | struct irq_fwspec *fwspec, |
| 778 | unsigned long *hwirq, |
| 779 | unsigned int *type) |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 780 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 781 | if (is_of_node(fwspec->fwnode)) { |
| 782 | if (fwspec->param_count < 3) |
| 783 | return -EINVAL; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 784 | |
Marc Zyngier | db8c70e | 2015-10-14 12:27:16 +0100 | [diff] [blame] | 785 | switch (fwspec->param[0]) { |
| 786 | case 0: /* SPI */ |
| 787 | *hwirq = fwspec->param[1] + 32; |
| 788 | break; |
| 789 | case 1: /* PPI */ |
| 790 | *hwirq = fwspec->param[1] + 16; |
| 791 | break; |
| 792 | case GIC_IRQ_TYPE_LPI: /* LPI */ |
| 793 | *hwirq = fwspec->param[1]; |
| 794 | break; |
| 795 | default: |
| 796 | return -EINVAL; |
| 797 | } |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 798 | |
| 799 | *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; |
| 800 | return 0; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 801 | } |
| 802 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 803 | if (is_fwnode_irqchip(fwspec->fwnode)) { |
| 804 | if(fwspec->param_count != 2) |
| 805 | return -EINVAL; |
| 806 | |
| 807 | *hwirq = fwspec->param[0]; |
| 808 | *type = fwspec->param[1]; |
| 809 | return 0; |
| 810 | } |
| 811 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 812 | return -EINVAL; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 815 | static int gic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 816 | unsigned int nr_irqs, void *arg) |
| 817 | { |
| 818 | int i, ret; |
| 819 | irq_hw_number_t hwirq; |
| 820 | unsigned int type = IRQ_TYPE_NONE; |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 821 | struct irq_fwspec *fwspec = arg; |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 822 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 823 | ret = gic_irq_domain_translate(domain, fwspec, &hwirq, &type); |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 824 | if (ret) |
| 825 | return ret; |
| 826 | |
| 827 | for (i = 0; i < nr_irqs; i++) |
| 828 | gic_irq_domain_map(domain, virq + i, hwirq + i); |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | static void gic_irq_domain_free(struct irq_domain *domain, unsigned int virq, |
| 834 | unsigned int nr_irqs) |
| 835 | { |
| 836 | int i; |
| 837 | |
| 838 | for (i = 0; i < nr_irqs; i++) { |
| 839 | struct irq_data *d = irq_domain_get_irq_data(domain, virq + i); |
| 840 | irq_set_handler(virq + i, NULL); |
| 841 | irq_domain_reset_irq_data(d); |
| 842 | } |
| 843 | } |
| 844 | |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 845 | static int gic_irq_domain_select(struct irq_domain *d, |
| 846 | struct irq_fwspec *fwspec, |
| 847 | enum irq_domain_bus_token bus_token) |
| 848 | { |
| 849 | /* Not for us */ |
| 850 | if (fwspec->fwnode != d->fwnode) |
| 851 | return 0; |
| 852 | |
| 853 | /* If this is not DT, then we have a single domain */ |
| 854 | if (!is_of_node(fwspec->fwnode)) |
| 855 | return 1; |
| 856 | |
| 857 | /* |
| 858 | * If this is a PPI and we have a 4th (non-null) parameter, |
| 859 | * then we need to match the partition domain. |
| 860 | */ |
| 861 | if (fwspec->param_count >= 4 && |
| 862 | fwspec->param[0] == 1 && fwspec->param[3] != 0) |
| 863 | return d == partition_get_domain(gic_data.ppi_descs[fwspec->param[1]]); |
| 864 | |
| 865 | return d == gic_data.domain; |
| 866 | } |
| 867 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 868 | static const struct irq_domain_ops gic_irq_domain_ops = { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 869 | .translate = gic_irq_domain_translate, |
Marc Zyngier | 443acc4 | 2014-11-24 14:35:09 +0000 | [diff] [blame] | 870 | .alloc = gic_irq_domain_alloc, |
| 871 | .free = gic_irq_domain_free, |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 872 | .select = gic_irq_domain_select, |
| 873 | }; |
| 874 | |
| 875 | static int partition_domain_translate(struct irq_domain *d, |
| 876 | struct irq_fwspec *fwspec, |
| 877 | unsigned long *hwirq, |
| 878 | unsigned int *type) |
| 879 | { |
| 880 | struct device_node *np; |
| 881 | int ret; |
| 882 | |
| 883 | np = of_find_node_by_phandle(fwspec->param[3]); |
| 884 | if (WARN_ON(!np)) |
| 885 | return -EINVAL; |
| 886 | |
| 887 | ret = partition_translate_id(gic_data.ppi_descs[fwspec->param[1]], |
| 888 | of_node_to_fwnode(np)); |
| 889 | if (ret < 0) |
| 890 | return ret; |
| 891 | |
| 892 | *hwirq = ret; |
| 893 | *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | static const struct irq_domain_ops partition_domain_ops = { |
| 899 | .translate = partition_domain_translate, |
| 900 | .select = gic_irq_domain_select, |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 901 | }; |
| 902 | |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 903 | static void gicv3_enable_quirks(void) |
| 904 | { |
Jean-Philippe Brucker | 7936e91 | 2015-10-01 13:47:14 +0100 | [diff] [blame] | 905 | #ifdef CONFIG_ARM64 |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 906 | if (cpus_have_cap(ARM64_WORKAROUND_CAVIUM_23154)) |
Robert Richter | 8ac2a17 | 2015-09-21 22:58:39 +0200 | [diff] [blame] | 907 | static_branch_enable(&is_cavium_thunderx); |
Jean-Philippe Brucker | 7936e91 | 2015-10-01 13:47:14 +0100 | [diff] [blame] | 908 | #endif |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 911 | static int __init gic_init_bases(void __iomem *dist_base, |
| 912 | struct redist_region *rdist_regs, |
| 913 | u32 nr_redist_regions, |
| 914 | u64 redist_stride, |
| 915 | struct fwnode_handle *handle) |
| 916 | { |
| 917 | struct device_node *node; |
| 918 | u32 typer; |
| 919 | int gic_irqs; |
| 920 | int err; |
| 921 | |
| 922 | if (!is_hyp_mode_available()) |
| 923 | static_key_slow_dec(&supports_deactivate); |
| 924 | |
| 925 | if (static_key_true(&supports_deactivate)) |
| 926 | pr_info("GIC: Using split EOI/Deactivate mode\n"); |
| 927 | |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 928 | gic_data.fwnode = handle; |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 929 | gic_data.dist_base = dist_base; |
| 930 | gic_data.redist_regions = rdist_regs; |
| 931 | gic_data.nr_redist_regions = nr_redist_regions; |
| 932 | gic_data.redist_stride = redist_stride; |
| 933 | |
| 934 | gicv3_enable_quirks(); |
| 935 | |
| 936 | /* |
| 937 | * Find out how many interrupts are supported. |
| 938 | * The GIC only supports up to 1020 interrupt sources (SGI+PPI+SPI) |
| 939 | */ |
| 940 | typer = readl_relaxed(gic_data.dist_base + GICD_TYPER); |
| 941 | gic_data.rdists.id_bits = GICD_TYPER_ID_BITS(typer); |
| 942 | gic_irqs = GICD_TYPER_IRQS(typer); |
| 943 | if (gic_irqs > 1020) |
| 944 | gic_irqs = 1020; |
| 945 | gic_data.irq_nr = gic_irqs; |
| 946 | |
| 947 | gic_data.domain = irq_domain_create_tree(handle, &gic_irq_domain_ops, |
| 948 | &gic_data); |
| 949 | gic_data.rdists.rdist = alloc_percpu(typeof(*gic_data.rdists.rdist)); |
| 950 | |
| 951 | if (WARN_ON(!gic_data.domain) || WARN_ON(!gic_data.rdists.rdist)) { |
| 952 | err = -ENOMEM; |
| 953 | goto out_free; |
| 954 | } |
| 955 | |
| 956 | set_handle_irq(gic_handle_irq); |
| 957 | |
| 958 | node = to_of_node(handle); |
| 959 | if (IS_ENABLED(CONFIG_ARM_GIC_V3_ITS) && gic_dist_supports_lpis() && |
Channagoud Kadabi | fdb0664 | 2016-09-19 20:55:36 -0700 | [diff] [blame^] | 960 | !IS_ENABLED(CONFIG_ARM_GIC_V3_ACL) && |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 961 | node) /* Temp hack to prevent ITS init for ACPI */ |
| 962 | its_init(node, &gic_data.rdists, gic_data.domain); |
| 963 | |
| 964 | gic_smp_init(); |
| 965 | gic_dist_init(); |
| 966 | gic_cpu_init(); |
| 967 | gic_cpu_pm_init(); |
| 968 | |
| 969 | return 0; |
| 970 | |
| 971 | out_free: |
| 972 | if (gic_data.domain) |
| 973 | irq_domain_remove(gic_data.domain); |
| 974 | free_percpu(gic_data.rdists.rdist); |
| 975 | return err; |
| 976 | } |
| 977 | |
| 978 | static int __init gic_validate_dist_version(void __iomem *dist_base) |
| 979 | { |
| 980 | u32 reg = readl_relaxed(dist_base + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK; |
| 981 | |
| 982 | if (reg != GIC_PIDR2_ARCH_GICv3 && reg != GIC_PIDR2_ARCH_GICv4) |
| 983 | return -ENODEV; |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 988 | static int get_cpu_number(struct device_node *dn) |
| 989 | { |
| 990 | const __be32 *cell; |
| 991 | u64 hwid; |
| 992 | int i; |
| 993 | |
| 994 | cell = of_get_property(dn, "reg", NULL); |
| 995 | if (!cell) |
| 996 | return -1; |
| 997 | |
| 998 | hwid = of_read_number(cell, of_n_addr_cells(dn)); |
| 999 | |
| 1000 | /* |
| 1001 | * Non affinity bits must be set to 0 in the DT |
| 1002 | */ |
| 1003 | if (hwid & ~MPIDR_HWID_BITMASK) |
| 1004 | return -1; |
| 1005 | |
| 1006 | for (i = 0; i < num_possible_cpus(); i++) |
| 1007 | if (cpu_logical_map(i) == hwid) |
| 1008 | return i; |
| 1009 | |
| 1010 | return -1; |
| 1011 | } |
| 1012 | |
| 1013 | /* Create all possible partitions at boot time */ |
Linus Torvalds | 7beaa24 | 2016-05-19 11:27:09 -0700 | [diff] [blame] | 1014 | static void __init gic_populate_ppi_partitions(struct device_node *gic_node) |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 1015 | { |
| 1016 | struct device_node *parts_node, *child_part; |
| 1017 | int part_idx = 0, i; |
| 1018 | int nr_parts; |
| 1019 | struct partition_affinity *parts; |
| 1020 | |
| 1021 | parts_node = of_find_node_by_name(gic_node, "ppi-partitions"); |
| 1022 | if (!parts_node) |
| 1023 | return; |
| 1024 | |
| 1025 | nr_parts = of_get_child_count(parts_node); |
| 1026 | |
| 1027 | if (!nr_parts) |
| 1028 | return; |
| 1029 | |
| 1030 | parts = kzalloc(sizeof(*parts) * nr_parts, GFP_KERNEL); |
| 1031 | if (WARN_ON(!parts)) |
| 1032 | return; |
| 1033 | |
| 1034 | for_each_child_of_node(parts_node, child_part) { |
| 1035 | struct partition_affinity *part; |
| 1036 | int n; |
| 1037 | |
| 1038 | part = &parts[part_idx]; |
| 1039 | |
| 1040 | part->partition_id = of_node_to_fwnode(child_part); |
| 1041 | |
| 1042 | pr_info("GIC: PPI partition %s[%d] { ", |
| 1043 | child_part->name, part_idx); |
| 1044 | |
| 1045 | n = of_property_count_elems_of_size(child_part, "affinity", |
| 1046 | sizeof(u32)); |
| 1047 | WARN_ON(n <= 0); |
| 1048 | |
| 1049 | for (i = 0; i < n; i++) { |
| 1050 | int err, cpu; |
| 1051 | u32 cpu_phandle; |
| 1052 | struct device_node *cpu_node; |
| 1053 | |
| 1054 | err = of_property_read_u32_index(child_part, "affinity", |
| 1055 | i, &cpu_phandle); |
| 1056 | if (WARN_ON(err)) |
| 1057 | continue; |
| 1058 | |
| 1059 | cpu_node = of_find_node_by_phandle(cpu_phandle); |
| 1060 | if (WARN_ON(!cpu_node)) |
| 1061 | continue; |
| 1062 | |
| 1063 | cpu = get_cpu_number(cpu_node); |
| 1064 | if (WARN_ON(cpu == -1)) |
| 1065 | continue; |
| 1066 | |
| 1067 | pr_cont("%s[%d] ", cpu_node->full_name, cpu); |
| 1068 | |
| 1069 | cpumask_set_cpu(cpu, &part->mask); |
| 1070 | } |
| 1071 | |
| 1072 | pr_cont("}\n"); |
| 1073 | part_idx++; |
| 1074 | } |
| 1075 | |
| 1076 | for (i = 0; i < 16; i++) { |
| 1077 | unsigned int irq; |
| 1078 | struct partition_desc *desc; |
| 1079 | struct irq_fwspec ppi_fwspec = { |
| 1080 | .fwnode = gic_data.fwnode, |
| 1081 | .param_count = 3, |
| 1082 | .param = { |
| 1083 | [0] = 1, |
| 1084 | [1] = i, |
| 1085 | [2] = IRQ_TYPE_NONE, |
| 1086 | }, |
| 1087 | }; |
| 1088 | |
| 1089 | irq = irq_create_fwspec_mapping(&ppi_fwspec); |
| 1090 | if (WARN_ON(!irq)) |
| 1091 | continue; |
| 1092 | desc = partition_create_desc(gic_data.fwnode, parts, nr_parts, |
| 1093 | irq, &partition_domain_ops); |
| 1094 | if (WARN_ON(!desc)) |
| 1095 | continue; |
| 1096 | |
| 1097 | gic_data.ppi_descs[i] = desc; |
| 1098 | } |
| 1099 | } |
| 1100 | |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 1101 | static void __init gic_of_setup_kvm_info(struct device_node *node) |
| 1102 | { |
| 1103 | int ret; |
| 1104 | struct resource r; |
| 1105 | u32 gicv_idx; |
| 1106 | |
| 1107 | gic_v3_kvm_info.type = GIC_V3; |
| 1108 | |
| 1109 | gic_v3_kvm_info.maint_irq = irq_of_parse_and_map(node, 0); |
| 1110 | if (!gic_v3_kvm_info.maint_irq) |
| 1111 | return; |
| 1112 | |
| 1113 | if (of_property_read_u32(node, "#redistributor-regions", |
| 1114 | &gicv_idx)) |
| 1115 | gicv_idx = 1; |
| 1116 | |
| 1117 | gicv_idx += 3; /* Also skip GICD, GICC, GICH */ |
| 1118 | ret = of_address_to_resource(node, gicv_idx, &r); |
| 1119 | if (!ret) |
| 1120 | gic_v3_kvm_info.vcpu = r; |
| 1121 | |
| 1122 | gic_set_kvm_info(&gic_v3_kvm_info); |
| 1123 | } |
| 1124 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1125 | static int __init gic_of_init(struct device_node *node, struct device_node *parent) |
| 1126 | { |
| 1127 | void __iomem *dist_base; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1128 | struct redist_region *rdist_regs; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1129 | u64 redist_stride; |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1130 | u32 nr_redist_regions; |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 1131 | int err, i; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1132 | |
| 1133 | dist_base = of_iomap(node, 0); |
| 1134 | if (!dist_base) { |
| 1135 | pr_err("%s: unable to map gic dist registers\n", |
| 1136 | node->full_name); |
| 1137 | return -ENXIO; |
| 1138 | } |
| 1139 | |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 1140 | err = gic_validate_dist_version(dist_base); |
| 1141 | if (err) { |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1142 | pr_err("%s: no distributor detected, giving up\n", |
| 1143 | node->full_name); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1144 | goto out_unmap_dist; |
| 1145 | } |
| 1146 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1147 | if (of_property_read_u32(node, "#redistributor-regions", &nr_redist_regions)) |
| 1148 | nr_redist_regions = 1; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1149 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1150 | rdist_regs = kzalloc(sizeof(*rdist_regs) * nr_redist_regions, GFP_KERNEL); |
| 1151 | if (!rdist_regs) { |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1152 | err = -ENOMEM; |
| 1153 | goto out_unmap_dist; |
| 1154 | } |
| 1155 | |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1156 | for (i = 0; i < nr_redist_regions; i++) { |
| 1157 | struct resource res; |
| 1158 | int ret; |
| 1159 | |
| 1160 | ret = of_address_to_resource(node, 1 + i, &res); |
| 1161 | rdist_regs[i].redist_base = of_iomap(node, 1 + i); |
| 1162 | if (ret || !rdist_regs[i].redist_base) { |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1163 | pr_err("%s: couldn't map region %d\n", |
| 1164 | node->full_name, i); |
| 1165 | err = -ENODEV; |
| 1166 | goto out_unmap_rdist; |
| 1167 | } |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1168 | rdist_regs[i].phys_base = res.start; |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | if (of_property_read_u64(node, "redistributor-stride", &redist_stride)) |
| 1172 | redist_stride = 0; |
| 1173 | |
Tomasz Nowicki | db57d74 | 2016-01-19 14:11:14 +0100 | [diff] [blame] | 1174 | err = gic_init_bases(dist_base, rdist_regs, nr_redist_regions, |
| 1175 | redist_stride, &node->fwnode); |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 1176 | if (err) |
| 1177 | goto out_unmap_rdist; |
| 1178 | |
| 1179 | gic_populate_ppi_partitions(node); |
Linus Torvalds | 7beaa24 | 2016-05-19 11:27:09 -0700 | [diff] [blame] | 1180 | gic_of_setup_kvm_info(node); |
Marc Zyngier | e3825ba | 2016-04-11 09:57:54 +0100 | [diff] [blame] | 1181 | return 0; |
Marc Zyngier | 0b6a3da | 2015-08-26 17:00:42 +0100 | [diff] [blame] | 1182 | |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1183 | out_unmap_rdist: |
Marc Zyngier | f5c1434 | 2014-11-24 14:35:10 +0000 | [diff] [blame] | 1184 | for (i = 0; i < nr_redist_regions; i++) |
| 1185 | if (rdist_regs[i].redist_base) |
| 1186 | iounmap(rdist_regs[i].redist_base); |
| 1187 | kfree(rdist_regs); |
Marc Zyngier | 021f653 | 2014-06-30 16:01:31 +0100 | [diff] [blame] | 1188 | out_unmap_dist: |
| 1189 | iounmap(dist_base); |
| 1190 | return err; |
| 1191 | } |
| 1192 | |
| 1193 | IRQCHIP_DECLARE(gic_v3, "arm,gic-v3", gic_of_init); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1194 | |
| 1195 | #ifdef CONFIG_ACPI |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1196 | static struct |
| 1197 | { |
| 1198 | void __iomem *dist_base; |
| 1199 | struct redist_region *redist_regs; |
| 1200 | u32 nr_redist_regions; |
| 1201 | bool single_redist; |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 1202 | u32 maint_irq; |
| 1203 | int maint_irq_mode; |
| 1204 | phys_addr_t vcpu_base; |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1205 | } acpi_data __initdata; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1206 | |
| 1207 | static void __init |
| 1208 | gic_acpi_register_redist(phys_addr_t phys_base, void __iomem *redist_base) |
| 1209 | { |
| 1210 | static int count = 0; |
| 1211 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1212 | acpi_data.redist_regs[count].phys_base = phys_base; |
| 1213 | acpi_data.redist_regs[count].redist_base = redist_base; |
| 1214 | acpi_data.redist_regs[count].single_redist = acpi_data.single_redist; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1215 | count++; |
| 1216 | } |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1217 | |
| 1218 | static int __init |
| 1219 | gic_acpi_parse_madt_redist(struct acpi_subtable_header *header, |
| 1220 | const unsigned long end) |
| 1221 | { |
| 1222 | struct acpi_madt_generic_redistributor *redist = |
| 1223 | (struct acpi_madt_generic_redistributor *)header; |
| 1224 | void __iomem *redist_base; |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1225 | |
| 1226 | redist_base = ioremap(redist->base_address, redist->length); |
| 1227 | if (!redist_base) { |
| 1228 | pr_err("Couldn't map GICR region @%llx\n", redist->base_address); |
| 1229 | return -ENOMEM; |
| 1230 | } |
| 1231 | |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1232 | gic_acpi_register_redist(redist->base_address, redist_base); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1233 | return 0; |
| 1234 | } |
| 1235 | |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1236 | static int __init |
| 1237 | gic_acpi_parse_madt_gicc(struct acpi_subtable_header *header, |
| 1238 | const unsigned long end) |
| 1239 | { |
| 1240 | struct acpi_madt_generic_interrupt *gicc = |
| 1241 | (struct acpi_madt_generic_interrupt *)header; |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1242 | u32 reg = readl_relaxed(acpi_data.dist_base + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1243 | u32 size = reg == GIC_PIDR2_ARCH_GICv4 ? SZ_64K * 4 : SZ_64K * 2; |
| 1244 | void __iomem *redist_base; |
| 1245 | |
| 1246 | redist_base = ioremap(gicc->gicr_base_address, size); |
| 1247 | if (!redist_base) |
| 1248 | return -ENOMEM; |
| 1249 | |
| 1250 | gic_acpi_register_redist(gicc->gicr_base_address, redist_base); |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | static int __init gic_acpi_collect_gicr_base(void) |
| 1255 | { |
| 1256 | acpi_tbl_entry_handler redist_parser; |
| 1257 | enum acpi_madt_type type; |
| 1258 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1259 | if (acpi_data.single_redist) { |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1260 | type = ACPI_MADT_TYPE_GENERIC_INTERRUPT; |
| 1261 | redist_parser = gic_acpi_parse_madt_gicc; |
| 1262 | } else { |
| 1263 | type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR; |
| 1264 | redist_parser = gic_acpi_parse_madt_redist; |
| 1265 | } |
| 1266 | |
| 1267 | /* Collect redistributor base addresses in GICR entries */ |
| 1268 | if (acpi_table_parse_madt(type, redist_parser, 0) > 0) |
| 1269 | return 0; |
| 1270 | |
| 1271 | pr_info("No valid GICR entries exist\n"); |
| 1272 | return -ENODEV; |
| 1273 | } |
| 1274 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1275 | static int __init gic_acpi_match_gicr(struct acpi_subtable_header *header, |
| 1276 | const unsigned long end) |
| 1277 | { |
| 1278 | /* Subtable presence means that redist exists, that's it */ |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1282 | static int __init gic_acpi_match_gicc(struct acpi_subtable_header *header, |
| 1283 | const unsigned long end) |
| 1284 | { |
| 1285 | struct acpi_madt_generic_interrupt *gicc = |
| 1286 | (struct acpi_madt_generic_interrupt *)header; |
| 1287 | |
| 1288 | /* |
| 1289 | * If GICC is enabled and has valid gicr base address, then it means |
| 1290 | * GICR base is presented via GICC |
| 1291 | */ |
| 1292 | if ((gicc->flags & ACPI_MADT_ENABLED) && gicc->gicr_base_address) |
| 1293 | return 0; |
| 1294 | |
| 1295 | return -ENODEV; |
| 1296 | } |
| 1297 | |
| 1298 | static int __init gic_acpi_count_gicr_regions(void) |
| 1299 | { |
| 1300 | int count; |
| 1301 | |
| 1302 | /* |
| 1303 | * Count how many redistributor regions we have. It is not allowed |
| 1304 | * to mix redistributor description, GICR and GICC subtables have to be |
| 1305 | * mutually exclusive. |
| 1306 | */ |
| 1307 | count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, |
| 1308 | gic_acpi_match_gicr, 0); |
| 1309 | if (count > 0) { |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1310 | acpi_data.single_redist = false; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1311 | return count; |
| 1312 | } |
| 1313 | |
| 1314 | count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, |
| 1315 | gic_acpi_match_gicc, 0); |
| 1316 | if (count > 0) |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1317 | acpi_data.single_redist = true; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1318 | |
| 1319 | return count; |
| 1320 | } |
| 1321 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1322 | static bool __init acpi_validate_gic_table(struct acpi_subtable_header *header, |
| 1323 | struct acpi_probe_entry *ape) |
| 1324 | { |
| 1325 | struct acpi_madt_generic_distributor *dist; |
| 1326 | int count; |
| 1327 | |
| 1328 | dist = (struct acpi_madt_generic_distributor *)header; |
| 1329 | if (dist->version != ape->driver_data) |
| 1330 | return false; |
| 1331 | |
| 1332 | /* We need to do that exercise anyway, the sooner the better */ |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1333 | count = gic_acpi_count_gicr_regions(); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1334 | if (count <= 0) |
| 1335 | return false; |
| 1336 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1337 | acpi_data.nr_redist_regions = count; |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1338 | return true; |
| 1339 | } |
| 1340 | |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 1341 | static int __init gic_acpi_parse_virt_madt_gicc(struct acpi_subtable_header *header, |
| 1342 | const unsigned long end) |
| 1343 | { |
| 1344 | struct acpi_madt_generic_interrupt *gicc = |
| 1345 | (struct acpi_madt_generic_interrupt *)header; |
| 1346 | int maint_irq_mode; |
| 1347 | static int first_madt = true; |
| 1348 | |
| 1349 | /* Skip unusable CPUs */ |
| 1350 | if (!(gicc->flags & ACPI_MADT_ENABLED)) |
| 1351 | return 0; |
| 1352 | |
| 1353 | maint_irq_mode = (gicc->flags & ACPI_MADT_VGIC_IRQ_MODE) ? |
| 1354 | ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; |
| 1355 | |
| 1356 | if (first_madt) { |
| 1357 | first_madt = false; |
| 1358 | |
| 1359 | acpi_data.maint_irq = gicc->vgic_interrupt; |
| 1360 | acpi_data.maint_irq_mode = maint_irq_mode; |
| 1361 | acpi_data.vcpu_base = gicc->gicv_base_address; |
| 1362 | |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | /* |
| 1367 | * The maintenance interrupt and GICV should be the same for every CPU |
| 1368 | */ |
| 1369 | if ((acpi_data.maint_irq != gicc->vgic_interrupt) || |
| 1370 | (acpi_data.maint_irq_mode != maint_irq_mode) || |
| 1371 | (acpi_data.vcpu_base != gicc->gicv_base_address)) |
| 1372 | return -EINVAL; |
| 1373 | |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
| 1377 | static bool __init gic_acpi_collect_virt_info(void) |
| 1378 | { |
| 1379 | int count; |
| 1380 | |
| 1381 | count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, |
| 1382 | gic_acpi_parse_virt_madt_gicc, 0); |
| 1383 | |
| 1384 | return (count > 0); |
| 1385 | } |
| 1386 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1387 | #define ACPI_GICV3_DIST_MEM_SIZE (SZ_64K) |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 1388 | #define ACPI_GICV2_VCTRL_MEM_SIZE (SZ_4K) |
| 1389 | #define ACPI_GICV2_VCPU_MEM_SIZE (SZ_8K) |
| 1390 | |
| 1391 | static void __init gic_acpi_setup_kvm_info(void) |
| 1392 | { |
| 1393 | int irq; |
| 1394 | |
| 1395 | if (!gic_acpi_collect_virt_info()) { |
| 1396 | pr_warn("Unable to get hardware information used for virtualization\n"); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | gic_v3_kvm_info.type = GIC_V3; |
| 1401 | |
| 1402 | irq = acpi_register_gsi(NULL, acpi_data.maint_irq, |
| 1403 | acpi_data.maint_irq_mode, |
| 1404 | ACPI_ACTIVE_HIGH); |
| 1405 | if (irq <= 0) |
| 1406 | return; |
| 1407 | |
| 1408 | gic_v3_kvm_info.maint_irq = irq; |
| 1409 | |
| 1410 | if (acpi_data.vcpu_base) { |
| 1411 | struct resource *vcpu = &gic_v3_kvm_info.vcpu; |
| 1412 | |
| 1413 | vcpu->flags = IORESOURCE_MEM; |
| 1414 | vcpu->start = acpi_data.vcpu_base; |
| 1415 | vcpu->end = vcpu->start + ACPI_GICV2_VCPU_MEM_SIZE - 1; |
| 1416 | } |
| 1417 | |
| 1418 | gic_set_kvm_info(&gic_v3_kvm_info); |
| 1419 | } |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1420 | |
| 1421 | static int __init |
| 1422 | gic_acpi_init(struct acpi_subtable_header *header, const unsigned long end) |
| 1423 | { |
| 1424 | struct acpi_madt_generic_distributor *dist; |
| 1425 | struct fwnode_handle *domain_handle; |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1426 | size_t size; |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1427 | int i, err; |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1428 | |
| 1429 | /* Get distributor base address */ |
| 1430 | dist = (struct acpi_madt_generic_distributor *)header; |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1431 | acpi_data.dist_base = ioremap(dist->base_address, |
| 1432 | ACPI_GICV3_DIST_MEM_SIZE); |
| 1433 | if (!acpi_data.dist_base) { |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1434 | pr_err("Unable to map GICD registers\n"); |
| 1435 | return -ENOMEM; |
| 1436 | } |
| 1437 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1438 | err = gic_validate_dist_version(acpi_data.dist_base); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1439 | if (err) { |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1440 | pr_err("No distributor detected at @%p, giving up", |
| 1441 | acpi_data.dist_base); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1442 | goto out_dist_unmap; |
| 1443 | } |
| 1444 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1445 | size = sizeof(*acpi_data.redist_regs) * acpi_data.nr_redist_regions; |
| 1446 | acpi_data.redist_regs = kzalloc(size, GFP_KERNEL); |
| 1447 | if (!acpi_data.redist_regs) { |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1448 | err = -ENOMEM; |
| 1449 | goto out_dist_unmap; |
| 1450 | } |
| 1451 | |
Tomasz Nowicki | b70fb7a | 2016-01-19 14:11:16 +0100 | [diff] [blame] | 1452 | err = gic_acpi_collect_gicr_base(); |
| 1453 | if (err) |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1454 | goto out_redist_unmap; |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1455 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1456 | domain_handle = irq_domain_alloc_fwnode(acpi_data.dist_base); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1457 | if (!domain_handle) { |
| 1458 | err = -ENOMEM; |
| 1459 | goto out_redist_unmap; |
| 1460 | } |
| 1461 | |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1462 | err = gic_init_bases(acpi_data.dist_base, acpi_data.redist_regs, |
| 1463 | acpi_data.nr_redist_regions, 0, domain_handle); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1464 | if (err) |
| 1465 | goto out_fwhandle_free; |
| 1466 | |
| 1467 | acpi_set_irq_model(ACPI_IRQ_MODEL_GIC, domain_handle); |
Julien Grall | 1839e57 | 2016-04-11 16:32:57 +0100 | [diff] [blame] | 1468 | gic_acpi_setup_kvm_info(); |
| 1469 | |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1470 | return 0; |
| 1471 | |
| 1472 | out_fwhandle_free: |
| 1473 | irq_domain_free_fwnode(domain_handle); |
| 1474 | out_redist_unmap: |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1475 | for (i = 0; i < acpi_data.nr_redist_regions; i++) |
| 1476 | if (acpi_data.redist_regs[i].redist_base) |
| 1477 | iounmap(acpi_data.redist_regs[i].redist_base); |
| 1478 | kfree(acpi_data.redist_regs); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1479 | out_dist_unmap: |
Julien Grall | 611f039 | 2016-04-11 16:32:56 +0100 | [diff] [blame] | 1480 | iounmap(acpi_data.dist_base); |
Tomasz Nowicki | ffa7d61 | 2016-01-19 14:11:15 +0100 | [diff] [blame] | 1481 | return err; |
| 1482 | } |
| 1483 | IRQCHIP_ACPI_DECLARE(gic_v3, ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, |
| 1484 | acpi_validate_gic_table, ACPI_MADT_GIC_VERSION_V3, |
| 1485 | gic_acpi_init); |
| 1486 | IRQCHIP_ACPI_DECLARE(gic_v4, ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, |
| 1487 | acpi_validate_gic_table, ACPI_MADT_GIC_VERSION_V4, |
| 1488 | gic_acpi_init); |
| 1489 | IRQCHIP_ACPI_DECLARE(gic_v3_or_v4, ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, |
| 1490 | acpi_validate_gic_table, ACPI_MADT_GIC_VERSION_NONE, |
| 1491 | gic_acpi_init); |
| 1492 | #endif |