Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 2 | /* |
Marc Zyngier | d7276b8 | 2016-12-20 15:11:47 +0000 | [diff] [blame] | 3 | * Copyright (C) 2013-2017 ARM Limited, All Rights Reserved. |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 4 | * Author: Marc Zyngier <marc.zyngier@arm.com> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 7 | #include <linux/acpi.h> |
Hanjun Guo | 8d3554b | 2017-03-07 20:39:59 +0800 | [diff] [blame] | 8 | #include <linux/acpi_iort.h> |
Marc Zyngier | ffedbf0 | 2019-11-08 16:57:59 +0000 | [diff] [blame] | 9 | #include <linux/bitfield.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 10 | #include <linux/bitmap.h> |
| 11 | #include <linux/cpu.h> |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 12 | #include <linux/crash_dump.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 13 | #include <linux/delay.h> |
Robin Murphy | 44bb7e2 | 2016-09-12 17:13:59 +0100 | [diff] [blame] | 14 | #include <linux/dma-iommu.h> |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 15 | #include <linux/efi.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 17 | #include <linux/irqdomain.h> |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 18 | #include <linux/list.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 19 | #include <linux/log2.h> |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 20 | #include <linux/memblock.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 21 | #include <linux/mm.h> |
| 22 | #include <linux/msi.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <linux/of_irq.h> |
| 26 | #include <linux/of_pci.h> |
| 27 | #include <linux/of_platform.h> |
| 28 | #include <linux/percpu.h> |
| 29 | #include <linux/slab.h> |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 30 | #include <linux/syscore_ops.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 31 | |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 32 | #include <linux/irqchip.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 33 | #include <linux/irqchip/arm-gic-v3.h> |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 34 | #include <linux/irqchip/arm-gic-v4.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 35 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 36 | #include <asm/cputype.h> |
| 37 | #include <asm/exception.h> |
| 38 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 39 | #include "irq-gic-common.h" |
| 40 | |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 41 | #define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0) |
| 42 | #define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1) |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 43 | #define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2) |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 44 | #define ITS_FLAGS_SAVE_SUSPEND_STATE (1ULL << 3) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 45 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 46 | #define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0) |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 47 | #define RDIST_FLAGS_RD_TABLES_PREALLOCATED (1 << 1) |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 48 | |
Marc Zyngier | a13b040 | 2016-12-19 17:15:24 +0000 | [diff] [blame] | 49 | static u32 lpi_id_bits; |
| 50 | |
| 51 | /* |
| 52 | * We allocate memory for PROPBASE to cover 2 ^ lpi_id_bits LPIs to |
| 53 | * deal with (one configuration byte per interrupt). PENDBASE has to |
| 54 | * be 64kB aligned (one bit per LPI, plus 8192 bits for SPI/PPI/SGI). |
| 55 | */ |
| 56 | #define LPI_NRBITS lpi_id_bits |
| 57 | #define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K) |
| 58 | #define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K) |
| 59 | |
Julien Thierry | 2130b78 | 2018-08-28 16:51:18 +0100 | [diff] [blame] | 60 | #define LPI_PROP_DEFAULT_PRIO GICD_INT_DEF_PRI |
Marc Zyngier | a13b040 | 2016-12-19 17:15:24 +0000 | [diff] [blame] | 61 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 62 | /* |
| 63 | * Collection structure - just an ID, and a redistributor address to |
| 64 | * ping. We use one per CPU as a bag of interrupts assigned to this |
| 65 | * CPU. |
| 66 | */ |
| 67 | struct its_collection { |
| 68 | u64 target_address; |
| 69 | u16 col_id; |
| 70 | }; |
| 71 | |
| 72 | /* |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 73 | * The ITS_BASER structure - contains memory information, cached |
| 74 | * value of BASER register configuration and ITS page size. |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 75 | */ |
| 76 | struct its_baser { |
| 77 | void *base; |
| 78 | u64 val; |
| 79 | u32 order; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 80 | u32 psz; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 81 | }; |
| 82 | |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 83 | struct its_device; |
| 84 | |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 85 | /* |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 86 | * The ITS structure - contains most of the infrastructure, with the |
Marc Zyngier | 841514a | 2015-07-28 14:46:20 +0100 | [diff] [blame] | 87 | * top-level MSI domain, the command queue, the collections, and the |
| 88 | * list of devices writing to it. |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 89 | * |
| 90 | * dev_alloc_lock has to be taken for device allocations, while the |
| 91 | * spinlock must be taken to parse data structures such as the device |
| 92 | * list. |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 93 | */ |
| 94 | struct its_node { |
| 95 | raw_spinlock_t lock; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 96 | struct mutex dev_alloc_lock; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 97 | struct list_head entry; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 98 | void __iomem *base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 99 | phys_addr_t phys_base; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 100 | struct its_cmd_block *cmd_base; |
| 101 | struct its_cmd_block *cmd_write; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 102 | struct its_baser tables[GITS_BASER_NR_REGS]; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 103 | struct its_collection *collections; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 104 | struct fwnode_handle *fwnode_handle; |
| 105 | u64 (*get_msi_base)(struct its_device *its_dev); |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 106 | u64 typer; |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 107 | u64 cbaser_save; |
| 108 | u32 ctlr_save; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 109 | struct list_head its_device_list; |
| 110 | u64 flags; |
Marc Zyngier | debf6d0 | 2017-10-08 18:44:42 +0100 | [diff] [blame] | 111 | unsigned long list_nr; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 112 | int numa_node; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 113 | unsigned int msi_domain_flags; |
| 114 | u32 pre_its_base; /* for Socionext Synquacer */ |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 115 | int vlpi_redist_offset; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 118 | #define is_v4(its) (!!((its)->typer & GITS_TYPER_VLPIS)) |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 119 | #define device_ids(its) (FIELD_GET(GITS_TYPER_DEVBITS, (its)->typer) + 1) |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 120 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 121 | #define ITS_ITT_ALIGN SZ_256 |
| 122 | |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 123 | /* The maximum number of VPEID bits supported by VLPI commands */ |
| 124 | #define ITS_MAX_VPEID_BITS (16) |
| 125 | #define ITS_MAX_VPEID (1 << (ITS_MAX_VPEID_BITS)) |
| 126 | |
Shanker Donthineni | 2eca0d6 | 2016-02-16 18:00:36 -0600 | [diff] [blame] | 127 | /* Convert page order to size in bytes */ |
| 128 | #define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o)) |
| 129 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 130 | struct event_lpi_map { |
| 131 | unsigned long *lpi_map; |
| 132 | u16 *col_map; |
| 133 | irq_hw_number_t lpi_base; |
| 134 | int nr_lpis; |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 135 | raw_spinlock_t vlpi_lock; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 136 | struct its_vm *vm; |
| 137 | struct its_vlpi_map *vlpi_maps; |
| 138 | int nr_vlpis; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 141 | /* |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 142 | * The ITS view of a device - belongs to an ITS, owns an interrupt |
| 143 | * translation table, and a list of interrupts. If it some of its |
| 144 | * LPIs are injected into a guest (GICv4), the event_map.vm field |
| 145 | * indicates which one. |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 146 | */ |
| 147 | struct its_device { |
| 148 | struct list_head entry; |
| 149 | struct its_node *its; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 150 | struct event_lpi_map event_map; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 151 | void *itt; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 152 | u32 nr_ites; |
| 153 | u32 device_id; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 154 | bool shared; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 157 | static struct { |
| 158 | raw_spinlock_t lock; |
| 159 | struct its_device *dev; |
| 160 | struct its_vpe **vpes; |
| 161 | int next_victim; |
| 162 | } vpe_proxy; |
| 163 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 164 | static LIST_HEAD(its_nodes); |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 165 | static DEFINE_RAW_SPINLOCK(its_lock); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 166 | static struct rdists *gic_rdists; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 167 | static struct irq_domain *its_parent; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 168 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 169 | static unsigned long its_list_map; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 170 | static u16 vmovp_seq_num; |
| 171 | static DEFINE_RAW_SPINLOCK(vmovp_lock); |
| 172 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 173 | static DEFINE_IDA(its_vpeid_ida); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 174 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 175 | #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist)) |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 176 | #define gic_data_rdist_cpu(cpu) (per_cpu_ptr(gic_rdists->rdist, cpu)) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 177 | #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 178 | #define gic_data_rdist_vlpi_base() (gic_data_rdist_rd_base() + SZ_128K) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 179 | |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 180 | static u16 get_its_list(struct its_vm *vm) |
| 181 | { |
| 182 | struct its_node *its; |
| 183 | unsigned long its_list = 0; |
| 184 | |
| 185 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 186 | if (!is_v4(its)) |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 187 | continue; |
| 188 | |
| 189 | if (vm->vlpi_count[its->list_nr]) |
| 190 | __set_bit(its->list_nr, &its_list); |
| 191 | } |
| 192 | |
| 193 | return (u16)its_list; |
| 194 | } |
| 195 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 196 | static inline u32 its_get_event_id(struct irq_data *d) |
| 197 | { |
| 198 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 199 | return d->hwirq - its_dev->event_map.lpi_base; |
| 200 | } |
| 201 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 202 | static struct its_collection *dev_event_to_col(struct its_device *its_dev, |
| 203 | u32 event) |
| 204 | { |
| 205 | struct its_node *its = its_dev->its; |
| 206 | |
| 207 | return its->collections + its_dev->event_map.col_map[event]; |
| 208 | } |
| 209 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 210 | static struct its_vlpi_map *dev_event_to_vlpi_map(struct its_device *its_dev, |
| 211 | u32 event) |
| 212 | { |
| 213 | if (WARN_ON_ONCE(event >= its_dev->event_map.nr_lpis)) |
| 214 | return NULL; |
| 215 | |
| 216 | return &its_dev->event_map.vlpi_maps[event]; |
| 217 | } |
| 218 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 219 | static struct its_collection *irq_to_col(struct irq_data *d) |
| 220 | { |
| 221 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 222 | |
| 223 | return dev_event_to_col(its_dev, its_get_event_id(d)); |
| 224 | } |
| 225 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 226 | static struct its_collection *valid_col(struct its_collection *col) |
| 227 | { |
Joe Perches | 20faba8 | 2019-07-09 22:04:18 -0700 | [diff] [blame] | 228 | if (WARN_ON_ONCE(col->target_address & GENMASK_ULL(15, 0))) |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 229 | return NULL; |
| 230 | |
| 231 | return col; |
| 232 | } |
| 233 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 234 | static struct its_vpe *valid_vpe(struct its_node *its, struct its_vpe *vpe) |
| 235 | { |
| 236 | if (valid_col(its->collections + vpe->col_idx)) |
| 237 | return vpe; |
| 238 | |
| 239 | return NULL; |
| 240 | } |
| 241 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 242 | /* |
| 243 | * ITS command descriptors - parameters to be encoded in a command |
| 244 | * block. |
| 245 | */ |
| 246 | struct its_cmd_desc { |
| 247 | union { |
| 248 | struct { |
| 249 | struct its_device *dev; |
| 250 | u32 event_id; |
| 251 | } its_inv_cmd; |
| 252 | |
| 253 | struct { |
| 254 | struct its_device *dev; |
| 255 | u32 event_id; |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 256 | } its_clear_cmd; |
| 257 | |
| 258 | struct { |
| 259 | struct its_device *dev; |
| 260 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 261 | } its_int_cmd; |
| 262 | |
| 263 | struct { |
| 264 | struct its_device *dev; |
| 265 | int valid; |
| 266 | } its_mapd_cmd; |
| 267 | |
| 268 | struct { |
| 269 | struct its_collection *col; |
| 270 | int valid; |
| 271 | } its_mapc_cmd; |
| 272 | |
| 273 | struct { |
| 274 | struct its_device *dev; |
| 275 | u32 phys_id; |
| 276 | u32 event_id; |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 277 | } its_mapti_cmd; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 278 | |
| 279 | struct { |
| 280 | struct its_device *dev; |
| 281 | struct its_collection *col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 282 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 283 | } its_movi_cmd; |
| 284 | |
| 285 | struct { |
| 286 | struct its_device *dev; |
| 287 | u32 event_id; |
| 288 | } its_discard_cmd; |
| 289 | |
| 290 | struct { |
| 291 | struct its_collection *col; |
| 292 | } its_invall_cmd; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 293 | |
| 294 | struct { |
| 295 | struct its_vpe *vpe; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 296 | } its_vinvall_cmd; |
| 297 | |
| 298 | struct { |
| 299 | struct its_vpe *vpe; |
| 300 | struct its_collection *col; |
| 301 | bool valid; |
| 302 | } its_vmapp_cmd; |
| 303 | |
| 304 | struct { |
| 305 | struct its_vpe *vpe; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 306 | struct its_device *dev; |
| 307 | u32 virt_id; |
| 308 | u32 event_id; |
| 309 | bool db_enabled; |
| 310 | } its_vmapti_cmd; |
| 311 | |
| 312 | struct { |
| 313 | struct its_vpe *vpe; |
| 314 | struct its_device *dev; |
| 315 | u32 event_id; |
| 316 | bool db_enabled; |
| 317 | } its_vmovi_cmd; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 318 | |
| 319 | struct { |
| 320 | struct its_vpe *vpe; |
| 321 | struct its_collection *col; |
| 322 | u16 seq_num; |
| 323 | u16 its_list; |
| 324 | } its_vmovp_cmd; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 325 | }; |
| 326 | }; |
| 327 | |
| 328 | /* |
| 329 | * The ITS command block, which is what the ITS actually parses. |
| 330 | */ |
| 331 | struct its_cmd_block { |
Ben Dooks (Codethink) | 2bbdfcc | 2019-10-17 12:29:55 +0100 | [diff] [blame] | 332 | union { |
| 333 | u64 raw_cmd[4]; |
| 334 | __le64 raw_cmd_le[4]; |
| 335 | }; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | #define ITS_CMD_QUEUE_SZ SZ_64K |
| 339 | #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(struct its_cmd_block)) |
| 340 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 341 | typedef struct its_collection *(*its_cmd_builder_t)(struct its_node *, |
| 342 | struct its_cmd_block *, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 343 | struct its_cmd_desc *); |
| 344 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 345 | typedef struct its_vpe *(*its_cmd_vbuilder_t)(struct its_node *, |
| 346 | struct its_cmd_block *, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 347 | struct its_cmd_desc *); |
| 348 | |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 349 | static void its_mask_encode(u64 *raw_cmd, u64 val, int h, int l) |
| 350 | { |
| 351 | u64 mask = GENMASK_ULL(h, l); |
| 352 | *raw_cmd &= ~mask; |
| 353 | *raw_cmd |= (val << l) & mask; |
| 354 | } |
| 355 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 356 | static void its_encode_cmd(struct its_cmd_block *cmd, u8 cmd_nr) |
| 357 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 358 | its_mask_encode(&cmd->raw_cmd[0], cmd_nr, 7, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void its_encode_devid(struct its_cmd_block *cmd, u32 devid) |
| 362 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 363 | its_mask_encode(&cmd->raw_cmd[0], devid, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static void its_encode_event_id(struct its_cmd_block *cmd, u32 id) |
| 367 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 368 | its_mask_encode(&cmd->raw_cmd[1], id, 31, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static void its_encode_phys_id(struct its_cmd_block *cmd, u32 phys_id) |
| 372 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 373 | its_mask_encode(&cmd->raw_cmd[1], phys_id, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | static void its_encode_size(struct its_cmd_block *cmd, u8 size) |
| 377 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 378 | its_mask_encode(&cmd->raw_cmd[1], size, 4, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static void its_encode_itt(struct its_cmd_block *cmd, u64 itt_addr) |
| 382 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 383 | its_mask_encode(&cmd->raw_cmd[2], itt_addr >> 8, 51, 8); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void its_encode_valid(struct its_cmd_block *cmd, int valid) |
| 387 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 388 | its_mask_encode(&cmd->raw_cmd[2], !!valid, 63, 63); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void its_encode_target(struct its_cmd_block *cmd, u64 target_addr) |
| 392 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 393 | its_mask_encode(&cmd->raw_cmd[2], target_addr >> 16, 51, 16); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void its_encode_collection(struct its_cmd_block *cmd, u16 col) |
| 397 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 398 | its_mask_encode(&cmd->raw_cmd[2], col, 15, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 401 | static void its_encode_vpeid(struct its_cmd_block *cmd, u16 vpeid) |
| 402 | { |
| 403 | its_mask_encode(&cmd->raw_cmd[1], vpeid, 47, 32); |
| 404 | } |
| 405 | |
| 406 | static void its_encode_virt_id(struct its_cmd_block *cmd, u32 virt_id) |
| 407 | { |
| 408 | its_mask_encode(&cmd->raw_cmd[2], virt_id, 31, 0); |
| 409 | } |
| 410 | |
| 411 | static void its_encode_db_phys_id(struct its_cmd_block *cmd, u32 db_phys_id) |
| 412 | { |
| 413 | its_mask_encode(&cmd->raw_cmd[2], db_phys_id, 63, 32); |
| 414 | } |
| 415 | |
| 416 | static void its_encode_db_valid(struct its_cmd_block *cmd, bool db_valid) |
| 417 | { |
| 418 | its_mask_encode(&cmd->raw_cmd[2], db_valid, 0, 0); |
| 419 | } |
| 420 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 421 | static void its_encode_seq_num(struct its_cmd_block *cmd, u16 seq_num) |
| 422 | { |
| 423 | its_mask_encode(&cmd->raw_cmd[0], seq_num, 47, 32); |
| 424 | } |
| 425 | |
| 426 | static void its_encode_its_list(struct its_cmd_block *cmd, u16 its_list) |
| 427 | { |
| 428 | its_mask_encode(&cmd->raw_cmd[1], its_list, 15, 0); |
| 429 | } |
| 430 | |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 431 | static void its_encode_vpt_addr(struct its_cmd_block *cmd, u64 vpt_pa) |
| 432 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 433 | its_mask_encode(&cmd->raw_cmd[3], vpt_pa >> 16, 51, 16); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void its_encode_vpt_size(struct its_cmd_block *cmd, u8 vpt_size) |
| 437 | { |
| 438 | its_mask_encode(&cmd->raw_cmd[3], vpt_size, 4, 0); |
| 439 | } |
| 440 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 441 | static inline void its_fixup_cmd(struct its_cmd_block *cmd) |
| 442 | { |
| 443 | /* Let's fixup BE commands */ |
Ben Dooks (Codethink) | 2bbdfcc | 2019-10-17 12:29:55 +0100 | [diff] [blame] | 444 | cmd->raw_cmd_le[0] = cpu_to_le64(cmd->raw_cmd[0]); |
| 445 | cmd->raw_cmd_le[1] = cpu_to_le64(cmd->raw_cmd[1]); |
| 446 | cmd->raw_cmd_le[2] = cpu_to_le64(cmd->raw_cmd[2]); |
| 447 | cmd->raw_cmd_le[3] = cpu_to_le64(cmd->raw_cmd[3]); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 450 | static struct its_collection *its_build_mapd_cmd(struct its_node *its, |
| 451 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 452 | struct its_cmd_desc *desc) |
| 453 | { |
| 454 | unsigned long itt_addr; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 455 | u8 size = ilog2(desc->its_mapd_cmd.dev->nr_ites); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 456 | |
| 457 | itt_addr = virt_to_phys(desc->its_mapd_cmd.dev->itt); |
| 458 | itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN); |
| 459 | |
| 460 | its_encode_cmd(cmd, GITS_CMD_MAPD); |
| 461 | its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id); |
| 462 | its_encode_size(cmd, size - 1); |
| 463 | its_encode_itt(cmd, itt_addr); |
| 464 | its_encode_valid(cmd, desc->its_mapd_cmd.valid); |
| 465 | |
| 466 | its_fixup_cmd(cmd); |
| 467 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 468 | return NULL; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 471 | static struct its_collection *its_build_mapc_cmd(struct its_node *its, |
| 472 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 473 | struct its_cmd_desc *desc) |
| 474 | { |
| 475 | its_encode_cmd(cmd, GITS_CMD_MAPC); |
| 476 | its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); |
| 477 | its_encode_target(cmd, desc->its_mapc_cmd.col->target_address); |
| 478 | its_encode_valid(cmd, desc->its_mapc_cmd.valid); |
| 479 | |
| 480 | its_fixup_cmd(cmd); |
| 481 | |
| 482 | return desc->its_mapc_cmd.col; |
| 483 | } |
| 484 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 485 | static struct its_collection *its_build_mapti_cmd(struct its_node *its, |
| 486 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 487 | struct its_cmd_desc *desc) |
| 488 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 489 | struct its_collection *col; |
| 490 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 491 | col = dev_event_to_col(desc->its_mapti_cmd.dev, |
| 492 | desc->its_mapti_cmd.event_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 493 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 494 | its_encode_cmd(cmd, GITS_CMD_MAPTI); |
| 495 | its_encode_devid(cmd, desc->its_mapti_cmd.dev->device_id); |
| 496 | its_encode_event_id(cmd, desc->its_mapti_cmd.event_id); |
| 497 | its_encode_phys_id(cmd, desc->its_mapti_cmd.phys_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 498 | its_encode_collection(cmd, col->col_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 499 | |
| 500 | its_fixup_cmd(cmd); |
| 501 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 502 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 505 | static struct its_collection *its_build_movi_cmd(struct its_node *its, |
| 506 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 507 | struct its_cmd_desc *desc) |
| 508 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 509 | struct its_collection *col; |
| 510 | |
| 511 | col = dev_event_to_col(desc->its_movi_cmd.dev, |
| 512 | desc->its_movi_cmd.event_id); |
| 513 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 514 | its_encode_cmd(cmd, GITS_CMD_MOVI); |
| 515 | its_encode_devid(cmd, desc->its_movi_cmd.dev->device_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 516 | its_encode_event_id(cmd, desc->its_movi_cmd.event_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 517 | its_encode_collection(cmd, desc->its_movi_cmd.col->col_id); |
| 518 | |
| 519 | its_fixup_cmd(cmd); |
| 520 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 521 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 524 | static struct its_collection *its_build_discard_cmd(struct its_node *its, |
| 525 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 526 | struct its_cmd_desc *desc) |
| 527 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 528 | struct its_collection *col; |
| 529 | |
| 530 | col = dev_event_to_col(desc->its_discard_cmd.dev, |
| 531 | desc->its_discard_cmd.event_id); |
| 532 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 533 | its_encode_cmd(cmd, GITS_CMD_DISCARD); |
| 534 | its_encode_devid(cmd, desc->its_discard_cmd.dev->device_id); |
| 535 | its_encode_event_id(cmd, desc->its_discard_cmd.event_id); |
| 536 | |
| 537 | its_fixup_cmd(cmd); |
| 538 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 539 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 542 | static struct its_collection *its_build_inv_cmd(struct its_node *its, |
| 543 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 544 | struct its_cmd_desc *desc) |
| 545 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 546 | struct its_collection *col; |
| 547 | |
| 548 | col = dev_event_to_col(desc->its_inv_cmd.dev, |
| 549 | desc->its_inv_cmd.event_id); |
| 550 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 551 | its_encode_cmd(cmd, GITS_CMD_INV); |
| 552 | its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); |
| 553 | its_encode_event_id(cmd, desc->its_inv_cmd.event_id); |
| 554 | |
| 555 | its_fixup_cmd(cmd); |
| 556 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 557 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 560 | static struct its_collection *its_build_int_cmd(struct its_node *its, |
| 561 | struct its_cmd_block *cmd, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 562 | struct its_cmd_desc *desc) |
| 563 | { |
| 564 | struct its_collection *col; |
| 565 | |
| 566 | col = dev_event_to_col(desc->its_int_cmd.dev, |
| 567 | desc->its_int_cmd.event_id); |
| 568 | |
| 569 | its_encode_cmd(cmd, GITS_CMD_INT); |
| 570 | its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); |
| 571 | its_encode_event_id(cmd, desc->its_int_cmd.event_id); |
| 572 | |
| 573 | its_fixup_cmd(cmd); |
| 574 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 575 | return valid_col(col); |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 578 | static struct its_collection *its_build_clear_cmd(struct its_node *its, |
| 579 | struct its_cmd_block *cmd, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 580 | struct its_cmd_desc *desc) |
| 581 | { |
| 582 | struct its_collection *col; |
| 583 | |
| 584 | col = dev_event_to_col(desc->its_clear_cmd.dev, |
| 585 | desc->its_clear_cmd.event_id); |
| 586 | |
| 587 | its_encode_cmd(cmd, GITS_CMD_CLEAR); |
| 588 | its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); |
| 589 | its_encode_event_id(cmd, desc->its_clear_cmd.event_id); |
| 590 | |
| 591 | its_fixup_cmd(cmd); |
| 592 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 593 | return valid_col(col); |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 596 | static struct its_collection *its_build_invall_cmd(struct its_node *its, |
| 597 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 598 | struct its_cmd_desc *desc) |
| 599 | { |
| 600 | its_encode_cmd(cmd, GITS_CMD_INVALL); |
| 601 | its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); |
| 602 | |
| 603 | its_fixup_cmd(cmd); |
| 604 | |
| 605 | return NULL; |
| 606 | } |
| 607 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 608 | static struct its_vpe *its_build_vinvall_cmd(struct its_node *its, |
| 609 | struct its_cmd_block *cmd, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 610 | struct its_cmd_desc *desc) |
| 611 | { |
| 612 | its_encode_cmd(cmd, GITS_CMD_VINVALL); |
| 613 | its_encode_vpeid(cmd, desc->its_vinvall_cmd.vpe->vpe_id); |
| 614 | |
| 615 | its_fixup_cmd(cmd); |
| 616 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 617 | return valid_vpe(its, desc->its_vinvall_cmd.vpe); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 620 | static struct its_vpe *its_build_vmapp_cmd(struct its_node *its, |
| 621 | struct its_cmd_block *cmd, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 622 | struct its_cmd_desc *desc) |
| 623 | { |
| 624 | unsigned long vpt_addr; |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 625 | u64 target; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 626 | |
| 627 | vpt_addr = virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->vpt_page)); |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 628 | target = desc->its_vmapp_cmd.col->target_address + its->vlpi_redist_offset; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 629 | |
| 630 | its_encode_cmd(cmd, GITS_CMD_VMAPP); |
| 631 | its_encode_vpeid(cmd, desc->its_vmapp_cmd.vpe->vpe_id); |
| 632 | its_encode_valid(cmd, desc->its_vmapp_cmd.valid); |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 633 | its_encode_target(cmd, target); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 634 | its_encode_vpt_addr(cmd, vpt_addr); |
| 635 | its_encode_vpt_size(cmd, LPI_NRBITS - 1); |
| 636 | |
| 637 | its_fixup_cmd(cmd); |
| 638 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 639 | return valid_vpe(its, desc->its_vmapp_cmd.vpe); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 642 | static struct its_vpe *its_build_vmapti_cmd(struct its_node *its, |
| 643 | struct its_cmd_block *cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 644 | struct its_cmd_desc *desc) |
| 645 | { |
| 646 | u32 db; |
| 647 | |
| 648 | if (desc->its_vmapti_cmd.db_enabled) |
| 649 | db = desc->its_vmapti_cmd.vpe->vpe_db_lpi; |
| 650 | else |
| 651 | db = 1023; |
| 652 | |
| 653 | its_encode_cmd(cmd, GITS_CMD_VMAPTI); |
| 654 | its_encode_devid(cmd, desc->its_vmapti_cmd.dev->device_id); |
| 655 | its_encode_vpeid(cmd, desc->its_vmapti_cmd.vpe->vpe_id); |
| 656 | its_encode_event_id(cmd, desc->its_vmapti_cmd.event_id); |
| 657 | its_encode_db_phys_id(cmd, db); |
| 658 | its_encode_virt_id(cmd, desc->its_vmapti_cmd.virt_id); |
| 659 | |
| 660 | its_fixup_cmd(cmd); |
| 661 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 662 | return valid_vpe(its, desc->its_vmapti_cmd.vpe); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 665 | static struct its_vpe *its_build_vmovi_cmd(struct its_node *its, |
| 666 | struct its_cmd_block *cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 667 | struct its_cmd_desc *desc) |
| 668 | { |
| 669 | u32 db; |
| 670 | |
| 671 | if (desc->its_vmovi_cmd.db_enabled) |
| 672 | db = desc->its_vmovi_cmd.vpe->vpe_db_lpi; |
| 673 | else |
| 674 | db = 1023; |
| 675 | |
| 676 | its_encode_cmd(cmd, GITS_CMD_VMOVI); |
| 677 | its_encode_devid(cmd, desc->its_vmovi_cmd.dev->device_id); |
| 678 | its_encode_vpeid(cmd, desc->its_vmovi_cmd.vpe->vpe_id); |
| 679 | its_encode_event_id(cmd, desc->its_vmovi_cmd.event_id); |
| 680 | its_encode_db_phys_id(cmd, db); |
| 681 | its_encode_db_valid(cmd, true); |
| 682 | |
| 683 | its_fixup_cmd(cmd); |
| 684 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 685 | return valid_vpe(its, desc->its_vmovi_cmd.vpe); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 688 | static struct its_vpe *its_build_vmovp_cmd(struct its_node *its, |
| 689 | struct its_cmd_block *cmd, |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 690 | struct its_cmd_desc *desc) |
| 691 | { |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 692 | u64 target; |
| 693 | |
| 694 | target = desc->its_vmovp_cmd.col->target_address + its->vlpi_redist_offset; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 695 | its_encode_cmd(cmd, GITS_CMD_VMOVP); |
| 696 | its_encode_seq_num(cmd, desc->its_vmovp_cmd.seq_num); |
| 697 | its_encode_its_list(cmd, desc->its_vmovp_cmd.its_list); |
| 698 | its_encode_vpeid(cmd, desc->its_vmovp_cmd.vpe->vpe_id); |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 699 | its_encode_target(cmd, target); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 700 | |
| 701 | its_fixup_cmd(cmd); |
| 702 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 703 | return valid_vpe(its, desc->its_vmovp_cmd.vpe); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 706 | static struct its_vpe *its_build_vinv_cmd(struct its_node *its, |
| 707 | struct its_cmd_block *cmd, |
| 708 | struct its_cmd_desc *desc) |
| 709 | { |
| 710 | struct its_vlpi_map *map; |
| 711 | |
| 712 | map = dev_event_to_vlpi_map(desc->its_inv_cmd.dev, |
| 713 | desc->its_inv_cmd.event_id); |
| 714 | |
| 715 | its_encode_cmd(cmd, GITS_CMD_INV); |
| 716 | its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); |
| 717 | its_encode_event_id(cmd, desc->its_inv_cmd.event_id); |
| 718 | |
| 719 | its_fixup_cmd(cmd); |
| 720 | |
| 721 | return valid_vpe(its, map->vpe); |
| 722 | } |
| 723 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 724 | static struct its_vpe *its_build_vint_cmd(struct its_node *its, |
| 725 | struct its_cmd_block *cmd, |
| 726 | struct its_cmd_desc *desc) |
| 727 | { |
| 728 | struct its_vlpi_map *map; |
| 729 | |
| 730 | map = dev_event_to_vlpi_map(desc->its_int_cmd.dev, |
| 731 | desc->its_int_cmd.event_id); |
| 732 | |
| 733 | its_encode_cmd(cmd, GITS_CMD_INT); |
| 734 | its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); |
| 735 | its_encode_event_id(cmd, desc->its_int_cmd.event_id); |
| 736 | |
| 737 | its_fixup_cmd(cmd); |
| 738 | |
| 739 | return valid_vpe(its, map->vpe); |
| 740 | } |
| 741 | |
| 742 | static struct its_vpe *its_build_vclear_cmd(struct its_node *its, |
| 743 | struct its_cmd_block *cmd, |
| 744 | struct its_cmd_desc *desc) |
| 745 | { |
| 746 | struct its_vlpi_map *map; |
| 747 | |
| 748 | map = dev_event_to_vlpi_map(desc->its_clear_cmd.dev, |
| 749 | desc->its_clear_cmd.event_id); |
| 750 | |
| 751 | its_encode_cmd(cmd, GITS_CMD_CLEAR); |
| 752 | its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); |
| 753 | its_encode_event_id(cmd, desc->its_clear_cmd.event_id); |
| 754 | |
| 755 | its_fixup_cmd(cmd); |
| 756 | |
| 757 | return valid_vpe(its, map->vpe); |
| 758 | } |
| 759 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 760 | static u64 its_cmd_ptr_to_offset(struct its_node *its, |
| 761 | struct its_cmd_block *ptr) |
| 762 | { |
| 763 | return (ptr - its->cmd_base) * sizeof(*ptr); |
| 764 | } |
| 765 | |
| 766 | static int its_queue_full(struct its_node *its) |
| 767 | { |
| 768 | int widx; |
| 769 | int ridx; |
| 770 | |
| 771 | widx = its->cmd_write - its->cmd_base; |
| 772 | ridx = readl_relaxed(its->base + GITS_CREADR) / sizeof(struct its_cmd_block); |
| 773 | |
| 774 | /* This is incredibly unlikely to happen, unless the ITS locks up. */ |
| 775 | if (((widx + 1) % ITS_CMD_QUEUE_NR_ENTRIES) == ridx) |
| 776 | return 1; |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static struct its_cmd_block *its_allocate_entry(struct its_node *its) |
| 782 | { |
| 783 | struct its_cmd_block *cmd; |
| 784 | u32 count = 1000000; /* 1s! */ |
| 785 | |
| 786 | while (its_queue_full(its)) { |
| 787 | count--; |
| 788 | if (!count) { |
| 789 | pr_err_ratelimited("ITS queue not draining\n"); |
| 790 | return NULL; |
| 791 | } |
| 792 | cpu_relax(); |
| 793 | udelay(1); |
| 794 | } |
| 795 | |
| 796 | cmd = its->cmd_write++; |
| 797 | |
| 798 | /* Handle queue wrapping */ |
| 799 | if (its->cmd_write == (its->cmd_base + ITS_CMD_QUEUE_NR_ENTRIES)) |
| 800 | its->cmd_write = its->cmd_base; |
| 801 | |
Marc Zyngier | 34d677a | 2016-12-19 17:16:45 +0000 | [diff] [blame] | 802 | /* Clear command */ |
| 803 | cmd->raw_cmd[0] = 0; |
| 804 | cmd->raw_cmd[1] = 0; |
| 805 | cmd->raw_cmd[2] = 0; |
| 806 | cmd->raw_cmd[3] = 0; |
| 807 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 808 | return cmd; |
| 809 | } |
| 810 | |
| 811 | static struct its_cmd_block *its_post_commands(struct its_node *its) |
| 812 | { |
| 813 | u64 wr = its_cmd_ptr_to_offset(its, its->cmd_write); |
| 814 | |
| 815 | writel_relaxed(wr, its->base + GITS_CWRITER); |
| 816 | |
| 817 | return its->cmd_write; |
| 818 | } |
| 819 | |
| 820 | static void its_flush_cmd(struct its_node *its, struct its_cmd_block *cmd) |
| 821 | { |
| 822 | /* |
| 823 | * Make sure the commands written to memory are observable by |
| 824 | * the ITS. |
| 825 | */ |
| 826 | if (its->flags & ITS_FLAGS_CMDQ_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 827 | gic_flush_dcache_to_poc(cmd, sizeof(*cmd)); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 828 | else |
| 829 | dsb(ishst); |
| 830 | } |
| 831 | |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 832 | static int its_wait_for_range_completion(struct its_node *its, |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 833 | u64 prev_idx, |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 834 | struct its_cmd_block *to) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 835 | { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 836 | u64 rd_idx, to_idx, linear_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 837 | u32 count = 1000000; /* 1s! */ |
| 838 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 839 | /* Linearize to_idx if the command set has wrapped around */ |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 840 | to_idx = its_cmd_ptr_to_offset(its, to); |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 841 | if (to_idx < prev_idx) |
| 842 | to_idx += ITS_CMD_QUEUE_SZ; |
| 843 | |
| 844 | linear_idx = prev_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 845 | |
| 846 | while (1) { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 847 | s64 delta; |
| 848 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 849 | rd_idx = readl_relaxed(its->base + GITS_CREADR); |
Marc Zyngier | 9bdd8b1 | 2017-08-19 10:16:02 +0100 | [diff] [blame] | 850 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 851 | /* |
| 852 | * Compute the read pointer progress, taking the |
| 853 | * potential wrap-around into account. |
| 854 | */ |
| 855 | delta = rd_idx - prev_idx; |
| 856 | if (rd_idx < prev_idx) |
| 857 | delta += ITS_CMD_QUEUE_SZ; |
Marc Zyngier | 9bdd8b1 | 2017-08-19 10:16:02 +0100 | [diff] [blame] | 858 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 859 | linear_idx += delta; |
| 860 | if (linear_idx >= to_idx) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | count--; |
| 864 | if (!count) { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 865 | pr_err_ratelimited("ITS queue timeout (%llu %llu)\n", |
| 866 | to_idx, linear_idx); |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 867 | return -1; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 868 | } |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 869 | prev_idx = rd_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 870 | cpu_relax(); |
| 871 | udelay(1); |
| 872 | } |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 873 | |
| 874 | return 0; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 877 | /* Warning, macro hell follows */ |
| 878 | #define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \ |
| 879 | void name(struct its_node *its, \ |
| 880 | buildtype builder, \ |
| 881 | struct its_cmd_desc *desc) \ |
| 882 | { \ |
| 883 | struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \ |
| 884 | synctype *sync_obj; \ |
| 885 | unsigned long flags; \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 886 | u64 rd_idx; \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 887 | \ |
| 888 | raw_spin_lock_irqsave(&its->lock, flags); \ |
| 889 | \ |
| 890 | cmd = its_allocate_entry(its); \ |
| 891 | if (!cmd) { /* We're soooooo screewed... */ \ |
| 892 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 893 | return; \ |
| 894 | } \ |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 895 | sync_obj = builder(its, cmd, desc); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 896 | its_flush_cmd(its, cmd); \ |
| 897 | \ |
| 898 | if (sync_obj) { \ |
| 899 | sync_cmd = its_allocate_entry(its); \ |
| 900 | if (!sync_cmd) \ |
| 901 | goto post; \ |
| 902 | \ |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 903 | buildfn(its, sync_cmd, sync_obj); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 904 | its_flush_cmd(its, sync_cmd); \ |
| 905 | } \ |
| 906 | \ |
| 907 | post: \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 908 | rd_idx = readl_relaxed(its->base + GITS_CREADR); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 909 | next_cmd = its_post_commands(its); \ |
| 910 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 911 | \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 912 | if (its_wait_for_range_completion(its, rd_idx, next_cmd)) \ |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 913 | pr_err_ratelimited("ITS cmd %ps failed\n", builder); \ |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 916 | static void its_build_sync_cmd(struct its_node *its, |
| 917 | struct its_cmd_block *sync_cmd, |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 918 | struct its_collection *sync_col) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 919 | { |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 920 | its_encode_cmd(sync_cmd, GITS_CMD_SYNC); |
| 921 | its_encode_target(sync_cmd, sync_col->target_address); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 922 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 923 | its_fixup_cmd(sync_cmd); |
| 924 | } |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 925 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 926 | static BUILD_SINGLE_CMD_FUNC(its_send_single_command, its_cmd_builder_t, |
| 927 | struct its_collection, its_build_sync_cmd) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 928 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 929 | static void its_build_vsync_cmd(struct its_node *its, |
| 930 | struct its_cmd_block *sync_cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 931 | struct its_vpe *sync_vpe) |
| 932 | { |
| 933 | its_encode_cmd(sync_cmd, GITS_CMD_VSYNC); |
| 934 | its_encode_vpeid(sync_cmd, sync_vpe->vpe_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 935 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 936 | its_fixup_cmd(sync_cmd); |
| 937 | } |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 938 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 939 | static BUILD_SINGLE_CMD_FUNC(its_send_single_vcommand, its_cmd_vbuilder_t, |
| 940 | struct its_vpe, its_build_vsync_cmd) |
| 941 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 942 | static void its_send_int(struct its_device *dev, u32 event_id) |
| 943 | { |
| 944 | struct its_cmd_desc desc; |
| 945 | |
| 946 | desc.its_int_cmd.dev = dev; |
| 947 | desc.its_int_cmd.event_id = event_id; |
| 948 | |
| 949 | its_send_single_command(dev->its, its_build_int_cmd, &desc); |
| 950 | } |
| 951 | |
| 952 | static void its_send_clear(struct its_device *dev, u32 event_id) |
| 953 | { |
| 954 | struct its_cmd_desc desc; |
| 955 | |
| 956 | desc.its_clear_cmd.dev = dev; |
| 957 | desc.its_clear_cmd.event_id = event_id; |
| 958 | |
| 959 | its_send_single_command(dev->its, its_build_clear_cmd, &desc); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static void its_send_inv(struct its_device *dev, u32 event_id) |
| 963 | { |
| 964 | struct its_cmd_desc desc; |
| 965 | |
| 966 | desc.its_inv_cmd.dev = dev; |
| 967 | desc.its_inv_cmd.event_id = event_id; |
| 968 | |
| 969 | its_send_single_command(dev->its, its_build_inv_cmd, &desc); |
| 970 | } |
| 971 | |
| 972 | static void its_send_mapd(struct its_device *dev, int valid) |
| 973 | { |
| 974 | struct its_cmd_desc desc; |
| 975 | |
| 976 | desc.its_mapd_cmd.dev = dev; |
| 977 | desc.its_mapd_cmd.valid = !!valid; |
| 978 | |
| 979 | its_send_single_command(dev->its, its_build_mapd_cmd, &desc); |
| 980 | } |
| 981 | |
| 982 | static void its_send_mapc(struct its_node *its, struct its_collection *col, |
| 983 | int valid) |
| 984 | { |
| 985 | struct its_cmd_desc desc; |
| 986 | |
| 987 | desc.its_mapc_cmd.col = col; |
| 988 | desc.its_mapc_cmd.valid = !!valid; |
| 989 | |
| 990 | its_send_single_command(its, its_build_mapc_cmd, &desc); |
| 991 | } |
| 992 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 993 | static void its_send_mapti(struct its_device *dev, u32 irq_id, u32 id) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 994 | { |
| 995 | struct its_cmd_desc desc; |
| 996 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 997 | desc.its_mapti_cmd.dev = dev; |
| 998 | desc.its_mapti_cmd.phys_id = irq_id; |
| 999 | desc.its_mapti_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1000 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 1001 | its_send_single_command(dev->its, its_build_mapti_cmd, &desc); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static void its_send_movi(struct its_device *dev, |
| 1005 | struct its_collection *col, u32 id) |
| 1006 | { |
| 1007 | struct its_cmd_desc desc; |
| 1008 | |
| 1009 | desc.its_movi_cmd.dev = dev; |
| 1010 | desc.its_movi_cmd.col = col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1011 | desc.its_movi_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1012 | |
| 1013 | its_send_single_command(dev->its, its_build_movi_cmd, &desc); |
| 1014 | } |
| 1015 | |
| 1016 | static void its_send_discard(struct its_device *dev, u32 id) |
| 1017 | { |
| 1018 | struct its_cmd_desc desc; |
| 1019 | |
| 1020 | desc.its_discard_cmd.dev = dev; |
| 1021 | desc.its_discard_cmd.event_id = id; |
| 1022 | |
| 1023 | its_send_single_command(dev->its, its_build_discard_cmd, &desc); |
| 1024 | } |
| 1025 | |
| 1026 | static void its_send_invall(struct its_node *its, struct its_collection *col) |
| 1027 | { |
| 1028 | struct its_cmd_desc desc; |
| 1029 | |
| 1030 | desc.its_invall_cmd.col = col; |
| 1031 | |
| 1032 | its_send_single_command(its, its_build_invall_cmd, &desc); |
| 1033 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1034 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1035 | static void its_send_vmapti(struct its_device *dev, u32 id) |
| 1036 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1037 | struct its_vlpi_map *map = dev_event_to_vlpi_map(dev, id); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1038 | struct its_cmd_desc desc; |
| 1039 | |
| 1040 | desc.its_vmapti_cmd.vpe = map->vpe; |
| 1041 | desc.its_vmapti_cmd.dev = dev; |
| 1042 | desc.its_vmapti_cmd.virt_id = map->vintid; |
| 1043 | desc.its_vmapti_cmd.event_id = id; |
| 1044 | desc.its_vmapti_cmd.db_enabled = map->db_enabled; |
| 1045 | |
| 1046 | its_send_single_vcommand(dev->its, its_build_vmapti_cmd, &desc); |
| 1047 | } |
| 1048 | |
| 1049 | static void its_send_vmovi(struct its_device *dev, u32 id) |
| 1050 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1051 | struct its_vlpi_map *map = dev_event_to_vlpi_map(dev, id); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1052 | struct its_cmd_desc desc; |
| 1053 | |
| 1054 | desc.its_vmovi_cmd.vpe = map->vpe; |
| 1055 | desc.its_vmovi_cmd.dev = dev; |
| 1056 | desc.its_vmovi_cmd.event_id = id; |
| 1057 | desc.its_vmovi_cmd.db_enabled = map->db_enabled; |
| 1058 | |
| 1059 | its_send_single_vcommand(dev->its, its_build_vmovi_cmd, &desc); |
| 1060 | } |
| 1061 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1062 | static void its_send_vmapp(struct its_node *its, |
| 1063 | struct its_vpe *vpe, bool valid) |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1064 | { |
| 1065 | struct its_cmd_desc desc; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1066 | |
| 1067 | desc.its_vmapp_cmd.vpe = vpe; |
| 1068 | desc.its_vmapp_cmd.valid = valid; |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1069 | desc.its_vmapp_cmd.col = &its->collections[vpe->col_idx]; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1070 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1071 | its_send_single_vcommand(its, its_build_vmapp_cmd, &desc); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1074 | static void its_send_vmovp(struct its_vpe *vpe) |
| 1075 | { |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 1076 | struct its_cmd_desc desc = {}; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1077 | struct its_node *its; |
| 1078 | unsigned long flags; |
| 1079 | int col_id = vpe->col_idx; |
| 1080 | |
| 1081 | desc.its_vmovp_cmd.vpe = vpe; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1082 | |
| 1083 | if (!its_list_map) { |
| 1084 | its = list_first_entry(&its_nodes, struct its_node, entry); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1085 | desc.its_vmovp_cmd.col = &its->collections[col_id]; |
| 1086 | its_send_single_vcommand(its, its_build_vmovp_cmd, &desc); |
| 1087 | return; |
| 1088 | } |
| 1089 | |
| 1090 | /* |
| 1091 | * Yet another marvel of the architecture. If using the |
| 1092 | * its_list "feature", we need to make sure that all ITSs |
| 1093 | * receive all VMOVP commands in the same order. The only way |
| 1094 | * to guarantee this is to make vmovp a serialization point. |
| 1095 | * |
| 1096 | * Wall <-- Head. |
| 1097 | */ |
| 1098 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1099 | |
| 1100 | desc.its_vmovp_cmd.seq_num = vmovp_seq_num++; |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 1101 | desc.its_vmovp_cmd.its_list = get_its_list(vpe->its_vm); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1102 | |
| 1103 | /* Emit VMOVPs */ |
| 1104 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 1105 | if (!is_v4(its)) |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1106 | continue; |
| 1107 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1108 | if (!vpe->its_vm->vlpi_count[its->list_nr]) |
| 1109 | continue; |
| 1110 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1111 | desc.its_vmovp_cmd.col = &its->collections[col_id]; |
| 1112 | its_send_single_vcommand(its, its_build_vmovp_cmd, &desc); |
| 1113 | } |
| 1114 | |
| 1115 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1116 | } |
| 1117 | |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 1118 | static void its_send_vinvall(struct its_node *its, struct its_vpe *vpe) |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1119 | { |
| 1120 | struct its_cmd_desc desc; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1121 | |
| 1122 | desc.its_vinvall_cmd.vpe = vpe; |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 1123 | its_send_single_vcommand(its, its_build_vinvall_cmd, &desc); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1126 | static void its_send_vinv(struct its_device *dev, u32 event_id) |
| 1127 | { |
| 1128 | struct its_cmd_desc desc; |
| 1129 | |
| 1130 | /* |
| 1131 | * There is no real VINV command. This is just a normal INV, |
| 1132 | * with a VSYNC instead of a SYNC. |
| 1133 | */ |
| 1134 | desc.its_inv_cmd.dev = dev; |
| 1135 | desc.its_inv_cmd.event_id = event_id; |
| 1136 | |
| 1137 | its_send_single_vcommand(dev->its, its_build_vinv_cmd, &desc); |
| 1138 | } |
| 1139 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 1140 | static void its_send_vint(struct its_device *dev, u32 event_id) |
| 1141 | { |
| 1142 | struct its_cmd_desc desc; |
| 1143 | |
| 1144 | /* |
| 1145 | * There is no real VINT command. This is just a normal INT, |
| 1146 | * with a VSYNC instead of a SYNC. |
| 1147 | */ |
| 1148 | desc.its_int_cmd.dev = dev; |
| 1149 | desc.its_int_cmd.event_id = event_id; |
| 1150 | |
| 1151 | its_send_single_vcommand(dev->its, its_build_vint_cmd, &desc); |
| 1152 | } |
| 1153 | |
| 1154 | static void its_send_vclear(struct its_device *dev, u32 event_id) |
| 1155 | { |
| 1156 | struct its_cmd_desc desc; |
| 1157 | |
| 1158 | /* |
| 1159 | * There is no real VCLEAR command. This is just a normal CLEAR, |
| 1160 | * with a VSYNC instead of a SYNC. |
| 1161 | */ |
| 1162 | desc.its_clear_cmd.dev = dev; |
| 1163 | desc.its_clear_cmd.event_id = event_id; |
| 1164 | |
| 1165 | its_send_single_vcommand(dev->its, its_build_vclear_cmd, &desc); |
| 1166 | } |
| 1167 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1168 | /* |
| 1169 | * irqchip functions - assumes MSI, mostly. |
| 1170 | */ |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1171 | static struct its_vlpi_map *get_vlpi_map(struct irq_data *d) |
| 1172 | { |
| 1173 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1174 | u32 event = its_get_event_id(d); |
| 1175 | |
| 1176 | if (!irqd_is_forwarded_to_vcpu(d)) |
| 1177 | return NULL; |
| 1178 | |
| 1179 | return dev_event_to_vlpi_map(its_dev, event); |
| 1180 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1181 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1182 | static void lpi_write_config(struct irq_data *d, u8 clr, u8 set) |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1183 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1184 | struct its_vlpi_map *map = get_vlpi_map(d); |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1185 | irq_hw_number_t hwirq; |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1186 | void *va; |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1187 | u8 *cfg; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1188 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1189 | if (map) { |
| 1190 | va = page_address(map->vm->vprop_page); |
Marc Zyngier | d4d7b4a | 2017-10-26 10:44:07 +0100 | [diff] [blame] | 1191 | hwirq = map->vintid; |
| 1192 | |
| 1193 | /* Remember the updated property */ |
| 1194 | map->properties &= ~clr; |
| 1195 | map->properties |= set | LPI_PROP_GROUP1; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1196 | } else { |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1197 | va = gic_rdists->prop_table_va; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1198 | hwirq = d->hwirq; |
| 1199 | } |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1200 | |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1201 | cfg = va + hwirq - 8192; |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1202 | *cfg &= ~clr; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1203 | *cfg |= set | LPI_PROP_GROUP1; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1204 | |
| 1205 | /* |
| 1206 | * Make the above write visible to the redistributors. |
| 1207 | * And yes, we're flushing exactly: One. Single. Byte. |
| 1208 | * Humpf... |
| 1209 | */ |
| 1210 | if (gic_rdists->flags & RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1211 | gic_flush_dcache_to_poc(cfg, sizeof(*cfg)); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1212 | else |
| 1213 | dsb(ishst); |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 1216 | static void wait_for_syncr(void __iomem *rdbase) |
| 1217 | { |
| 1218 | while (gic_read_lpir(rdbase + GICR_SYNCR) & 1) |
| 1219 | cpu_relax(); |
| 1220 | } |
| 1221 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1222 | static void direct_lpi_inv(struct irq_data *d) |
| 1223 | { |
| 1224 | struct its_collection *col; |
| 1225 | void __iomem *rdbase; |
| 1226 | |
| 1227 | /* Target the redistributor this LPI is currently routed to */ |
| 1228 | col = irq_to_col(d); |
| 1229 | rdbase = per_cpu_ptr(gic_rdists->rdist, col->col_id)->rd_base; |
| 1230 | gic_write_lpir(d->hwirq, rdbase + GICR_INVLPIR); |
| 1231 | |
| 1232 | wait_for_syncr(rdbase); |
| 1233 | } |
| 1234 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1235 | static void lpi_update_config(struct irq_data *d, u8 clr, u8 set) |
| 1236 | { |
| 1237 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1238 | |
| 1239 | lpi_write_config(d, clr, set); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1240 | if (gic_rdists->has_direct_lpi && !irqd_is_forwarded_to_vcpu(d)) |
| 1241 | direct_lpi_inv(d); |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1242 | else if (!irqd_is_forwarded_to_vcpu(d)) |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1243 | its_send_inv(its_dev, its_get_event_id(d)); |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1244 | else |
| 1245 | its_send_vinv(its_dev, its_get_event_id(d)); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1248 | static void its_vlpi_set_doorbell(struct irq_data *d, bool enable) |
| 1249 | { |
| 1250 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1251 | u32 event = its_get_event_id(d); |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1252 | struct its_vlpi_map *map; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1253 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1254 | map = dev_event_to_vlpi_map(its_dev, event); |
| 1255 | |
| 1256 | if (map->db_enabled == enable) |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1257 | return; |
| 1258 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1259 | map->db_enabled = enable; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1260 | |
| 1261 | /* |
| 1262 | * More fun with the architecture: |
| 1263 | * |
| 1264 | * Ideally, we'd issue a VMAPTI to set the doorbell to its LPI |
| 1265 | * value or to 1023, depending on the enable bit. But that |
| 1266 | * would be issueing a mapping for an /existing/ DevID+EventID |
| 1267 | * pair, which is UNPREDICTABLE. Instead, let's issue a VMOVI |
| 1268 | * to the /same/ vPE, using this opportunity to adjust the |
| 1269 | * doorbell. Mouahahahaha. We loves it, Precious. |
| 1270 | */ |
| 1271 | its_send_vmovi(its_dev, event); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | static void its_mask_irq(struct irq_data *d) |
| 1275 | { |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1276 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1277 | its_vlpi_set_doorbell(d, false); |
| 1278 | |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1279 | lpi_update_config(d, LPI_PROP_ENABLED, 0); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void its_unmask_irq(struct irq_data *d) |
| 1283 | { |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1284 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1285 | its_vlpi_set_doorbell(d, true); |
| 1286 | |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1287 | lpi_update_config(d, 0, LPI_PROP_ENABLED); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1290 | static int its_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 1291 | bool force) |
| 1292 | { |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1293 | unsigned int cpu; |
| 1294 | const struct cpumask *cpu_mask = cpu_online_mask; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1295 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1296 | struct its_collection *target_col; |
| 1297 | u32 id = its_get_event_id(d); |
| 1298 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1299 | /* A forwarded interrupt should use irq_set_vcpu_affinity */ |
| 1300 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1301 | return -EINVAL; |
| 1302 | |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1303 | /* lpi cannot be routed to a redistributor that is on a foreign node */ |
| 1304 | if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 1305 | if (its_dev->its->numa_node >= 0) { |
| 1306 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
| 1307 | if (!cpumask_intersects(mask_val, cpu_mask)) |
| 1308 | return -EINVAL; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | cpu = cpumask_any_and(mask_val, cpu_mask); |
| 1313 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1314 | if (cpu >= nr_cpu_ids) |
| 1315 | return -EINVAL; |
| 1316 | |
MaJun | 8b8d94a | 2017-05-18 16:19:13 +0800 | [diff] [blame] | 1317 | /* don't set the affinity when the target cpu is same as current one */ |
| 1318 | if (cpu != its_dev->event_map.col_map[id]) { |
| 1319 | target_col = &its_dev->its->collections[cpu]; |
| 1320 | its_send_movi(its_dev, target_col, id); |
| 1321 | its_dev->event_map.col_map[id] = cpu; |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 1322 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
MaJun | 8b8d94a | 2017-05-18 16:19:13 +0800 | [diff] [blame] | 1323 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1324 | |
| 1325 | return IRQ_SET_MASK_OK_DONE; |
| 1326 | } |
| 1327 | |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 1328 | static u64 its_irq_get_msi_base(struct its_device *its_dev) |
| 1329 | { |
| 1330 | struct its_node *its = its_dev->its; |
| 1331 | |
| 1332 | return its->phys_base + GITS_TRANSLATER; |
| 1333 | } |
| 1334 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1335 | static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg) |
| 1336 | { |
| 1337 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1338 | struct its_node *its; |
| 1339 | u64 addr; |
| 1340 | |
| 1341 | its = its_dev->its; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 1342 | addr = its->get_msi_base(its_dev); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1343 | |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 1344 | msg->address_lo = lower_32_bits(addr); |
| 1345 | msg->address_hi = upper_32_bits(addr); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1346 | msg->data = its_get_event_id(d); |
Robin Murphy | 44bb7e2 | 2016-09-12 17:13:59 +0100 | [diff] [blame] | 1347 | |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 1348 | iommu_dma_compose_msi_msg(irq_data_get_msi_desc(d), msg); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1351 | static int its_irq_set_irqchip_state(struct irq_data *d, |
| 1352 | enum irqchip_irq_state which, |
| 1353 | bool state) |
| 1354 | { |
| 1355 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1356 | u32 event = its_get_event_id(d); |
| 1357 | |
| 1358 | if (which != IRQCHIP_STATE_PENDING) |
| 1359 | return -EINVAL; |
| 1360 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 1361 | if (irqd_is_forwarded_to_vcpu(d)) { |
| 1362 | if (state) |
| 1363 | its_send_vint(its_dev, event); |
| 1364 | else |
| 1365 | its_send_vclear(its_dev, event); |
| 1366 | } else { |
| 1367 | if (state) |
| 1368 | its_send_int(its_dev, event); |
| 1369 | else |
| 1370 | its_send_clear(its_dev, event); |
| 1371 | } |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1376 | static void its_map_vm(struct its_node *its, struct its_vm *vm) |
| 1377 | { |
| 1378 | unsigned long flags; |
| 1379 | |
| 1380 | /* Not using the ITS list? Everything is always mapped. */ |
| 1381 | if (!its_list_map) |
| 1382 | return; |
| 1383 | |
| 1384 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1385 | |
| 1386 | /* |
| 1387 | * If the VM wasn't mapped yet, iterate over the vpes and get |
| 1388 | * them mapped now. |
| 1389 | */ |
| 1390 | vm->vlpi_count[its->list_nr]++; |
| 1391 | |
| 1392 | if (vm->vlpi_count[its->list_nr] == 1) { |
| 1393 | int i; |
| 1394 | |
| 1395 | for (i = 0; i < vm->nr_vpes; i++) { |
| 1396 | struct its_vpe *vpe = vm->vpes[i]; |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 1397 | struct irq_data *d = irq_get_irq_data(vpe->irq); |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1398 | |
| 1399 | /* Map the VPE to the first possible CPU */ |
| 1400 | vpe->col_idx = cpumask_first(cpu_online_mask); |
| 1401 | its_send_vmapp(its, vpe, true); |
| 1402 | its_send_vinvall(its, vpe); |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 1403 | irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1408 | } |
| 1409 | |
| 1410 | static void its_unmap_vm(struct its_node *its, struct its_vm *vm) |
| 1411 | { |
| 1412 | unsigned long flags; |
| 1413 | |
| 1414 | /* Not using the ITS list? Everything is always mapped. */ |
| 1415 | if (!its_list_map) |
| 1416 | return; |
| 1417 | |
| 1418 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1419 | |
| 1420 | if (!--vm->vlpi_count[its->list_nr]) { |
| 1421 | int i; |
| 1422 | |
| 1423 | for (i = 0; i < vm->nr_vpes; i++) |
| 1424 | its_send_vmapp(its, vm->vpes[i], false); |
| 1425 | } |
| 1426 | |
| 1427 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1428 | } |
| 1429 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1430 | static int its_vlpi_map(struct irq_data *d, struct its_cmd_info *info) |
| 1431 | { |
| 1432 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1433 | u32 event = its_get_event_id(d); |
| 1434 | int ret = 0; |
| 1435 | |
| 1436 | if (!info->map) |
| 1437 | return -EINVAL; |
| 1438 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1439 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1440 | |
| 1441 | if (!its_dev->event_map.vm) { |
| 1442 | struct its_vlpi_map *maps; |
| 1443 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1444 | maps = kcalloc(its_dev->event_map.nr_lpis, sizeof(*maps), |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1445 | GFP_ATOMIC); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1446 | if (!maps) { |
| 1447 | ret = -ENOMEM; |
| 1448 | goto out; |
| 1449 | } |
| 1450 | |
| 1451 | its_dev->event_map.vm = info->map->vm; |
| 1452 | its_dev->event_map.vlpi_maps = maps; |
| 1453 | } else if (its_dev->event_map.vm != info->map->vm) { |
| 1454 | ret = -EINVAL; |
| 1455 | goto out; |
| 1456 | } |
| 1457 | |
| 1458 | /* Get our private copy of the mapping information */ |
| 1459 | its_dev->event_map.vlpi_maps[event] = *info->map; |
| 1460 | |
| 1461 | if (irqd_is_forwarded_to_vcpu(d)) { |
| 1462 | /* Already mapped, move it around */ |
| 1463 | its_send_vmovi(its_dev, event); |
| 1464 | } else { |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1465 | /* Ensure all the VPEs are mapped on this ITS */ |
| 1466 | its_map_vm(its_dev->its, info->map->vm); |
| 1467 | |
Marc Zyngier | d4d7b4a | 2017-10-26 10:44:07 +0100 | [diff] [blame] | 1468 | /* |
| 1469 | * Flag the interrupt as forwarded so that we can |
| 1470 | * start poking the virtual property table. |
| 1471 | */ |
| 1472 | irqd_set_forwarded_to_vcpu(d); |
| 1473 | |
| 1474 | /* Write out the property to the prop table */ |
| 1475 | lpi_write_config(d, 0xff, info->map->properties); |
| 1476 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1477 | /* Drop the physical mapping */ |
| 1478 | its_send_discard(its_dev, event); |
| 1479 | |
| 1480 | /* and install the virtual one */ |
| 1481 | its_send_vmapti(its_dev, event); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1482 | |
| 1483 | /* Increment the number of VLPIs */ |
| 1484 | its_dev->event_map.nr_vlpis++; |
| 1485 | } |
| 1486 | |
| 1487 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1488 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1489 | return ret; |
| 1490 | } |
| 1491 | |
| 1492 | static int its_vlpi_get(struct irq_data *d, struct its_cmd_info *info) |
| 1493 | { |
| 1494 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 046b505 | 2019-11-08 16:58:04 +0000 | [diff] [blame] | 1495 | struct its_vlpi_map *map; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1496 | int ret = 0; |
| 1497 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1498 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1499 | |
Marc Zyngier | 046b505 | 2019-11-08 16:58:04 +0000 | [diff] [blame] | 1500 | map = get_vlpi_map(d); |
| 1501 | |
| 1502 | if (!its_dev->event_map.vm || !map) { |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1503 | ret = -EINVAL; |
| 1504 | goto out; |
| 1505 | } |
| 1506 | |
| 1507 | /* Copy our mapping information to the incoming request */ |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1508 | *info->map = *map; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1509 | |
| 1510 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1511 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1512 | return ret; |
| 1513 | } |
| 1514 | |
| 1515 | static int its_vlpi_unmap(struct irq_data *d) |
| 1516 | { |
| 1517 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1518 | u32 event = its_get_event_id(d); |
| 1519 | int ret = 0; |
| 1520 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1521 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1522 | |
| 1523 | if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) { |
| 1524 | ret = -EINVAL; |
| 1525 | goto out; |
| 1526 | } |
| 1527 | |
| 1528 | /* Drop the virtual mapping */ |
| 1529 | its_send_discard(its_dev, event); |
| 1530 | |
| 1531 | /* and restore the physical one */ |
| 1532 | irqd_clr_forwarded_to_vcpu(d); |
| 1533 | its_send_mapti(its_dev, d->hwirq, event); |
| 1534 | lpi_update_config(d, 0xff, (LPI_PROP_DEFAULT_PRIO | |
| 1535 | LPI_PROP_ENABLED | |
| 1536 | LPI_PROP_GROUP1)); |
| 1537 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1538 | /* Potentially unmap the VM from this ITS */ |
| 1539 | its_unmap_vm(its_dev->its, its_dev->event_map.vm); |
| 1540 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1541 | /* |
| 1542 | * Drop the refcount and make the device available again if |
| 1543 | * this was the last VLPI. |
| 1544 | */ |
| 1545 | if (!--its_dev->event_map.nr_vlpis) { |
| 1546 | its_dev->event_map.vm = NULL; |
| 1547 | kfree(its_dev->event_map.vlpi_maps); |
| 1548 | } |
| 1549 | |
| 1550 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 1551 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1552 | return ret; |
| 1553 | } |
| 1554 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1555 | static int its_vlpi_prop_update(struct irq_data *d, struct its_cmd_info *info) |
| 1556 | { |
| 1557 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1558 | |
| 1559 | if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) |
| 1560 | return -EINVAL; |
| 1561 | |
| 1562 | if (info->cmd_type == PROP_UPDATE_AND_INV_VLPI) |
| 1563 | lpi_update_config(d, 0xff, info->config); |
| 1564 | else |
| 1565 | lpi_write_config(d, 0xff, info->config); |
| 1566 | its_vlpi_set_doorbell(d, !!(info->config & LPI_PROP_ENABLED)); |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1571 | static int its_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 1572 | { |
| 1573 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1574 | struct its_cmd_info *info = vcpu_info; |
| 1575 | |
| 1576 | /* Need a v4 ITS */ |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 1577 | if (!is_v4(its_dev->its)) |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1578 | return -EINVAL; |
| 1579 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1580 | /* Unmap request? */ |
| 1581 | if (!info) |
| 1582 | return its_vlpi_unmap(d); |
| 1583 | |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1584 | switch (info->cmd_type) { |
| 1585 | case MAP_VLPI: |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1586 | return its_vlpi_map(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1587 | |
| 1588 | case GET_VLPI: |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1589 | return its_vlpi_get(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1590 | |
| 1591 | case PROP_UPDATE_VLPI: |
| 1592 | case PROP_UPDATE_AND_INV_VLPI: |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1593 | return its_vlpi_prop_update(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1594 | |
| 1595 | default: |
| 1596 | return -EINVAL; |
| 1597 | } |
| 1598 | } |
| 1599 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1600 | static struct irq_chip its_irq_chip = { |
| 1601 | .name = "ITS", |
| 1602 | .irq_mask = its_mask_irq, |
| 1603 | .irq_unmask = its_unmask_irq, |
Ashok Kumar | 004fa08 | 2016-02-11 05:38:53 -0800 | [diff] [blame] | 1604 | .irq_eoi = irq_chip_eoi_parent, |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1605 | .irq_set_affinity = its_set_affinity, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1606 | .irq_compose_msi_msg = its_irq_compose_msi_msg, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1607 | .irq_set_irqchip_state = its_irq_set_irqchip_state, |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1608 | .irq_set_vcpu_affinity = its_irq_set_vcpu_affinity, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1609 | }; |
| 1610 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1611 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1612 | /* |
| 1613 | * How we allocate LPIs: |
| 1614 | * |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1615 | * lpi_range_list contains ranges of LPIs that are to available to |
| 1616 | * allocate from. To allocate LPIs, just pick the first range that |
| 1617 | * fits the required allocation, and reduce it by the required |
| 1618 | * amount. Once empty, remove the range from the list. |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1619 | * |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1620 | * To free a range of LPIs, add a free range to the list, sort it and |
| 1621 | * merge the result if the new range happens to be adjacent to an |
| 1622 | * already free block. |
| 1623 | * |
| 1624 | * The consequence of the above is that allocation is cost is low, but |
| 1625 | * freeing is expensive. We assumes that freeing rarely occurs. |
| 1626 | */ |
Jia He | 4cb205c | 2018-08-28 12:53:26 +0800 | [diff] [blame] | 1627 | #define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */ |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1628 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1629 | static DEFINE_MUTEX(lpi_range_lock); |
| 1630 | static LIST_HEAD(lpi_range_list); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1631 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1632 | struct lpi_range { |
| 1633 | struct list_head entry; |
| 1634 | u32 base_id; |
| 1635 | u32 span; |
| 1636 | }; |
| 1637 | |
| 1638 | static struct lpi_range *mk_lpi_range(u32 base, u32 span) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1639 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1640 | struct lpi_range *range; |
| 1641 | |
Rasmus Villemoes | 1c73fac | 2019-03-12 18:33:48 +0100 | [diff] [blame] | 1642 | range = kmalloc(sizeof(*range), GFP_KERNEL); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1643 | if (range) { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1644 | range->base_id = base; |
| 1645 | range->span = span; |
| 1646 | } |
| 1647 | |
| 1648 | return range; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1651 | static int alloc_lpi_range(u32 nr_lpis, u32 *base) |
| 1652 | { |
| 1653 | struct lpi_range *range, *tmp; |
| 1654 | int err = -ENOSPC; |
| 1655 | |
| 1656 | mutex_lock(&lpi_range_lock); |
| 1657 | |
| 1658 | list_for_each_entry_safe(range, tmp, &lpi_range_list, entry) { |
| 1659 | if (range->span >= nr_lpis) { |
| 1660 | *base = range->base_id; |
| 1661 | range->base_id += nr_lpis; |
| 1662 | range->span -= nr_lpis; |
| 1663 | |
| 1664 | if (range->span == 0) { |
| 1665 | list_del(&range->entry); |
| 1666 | kfree(range); |
| 1667 | } |
| 1668 | |
| 1669 | err = 0; |
| 1670 | break; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | mutex_unlock(&lpi_range_lock); |
| 1675 | |
| 1676 | pr_debug("ITS: alloc %u:%u\n", *base, nr_lpis); |
| 1677 | return err; |
| 1678 | } |
| 1679 | |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1680 | static void merge_lpi_ranges(struct lpi_range *a, struct lpi_range *b) |
| 1681 | { |
| 1682 | if (&a->entry == &lpi_range_list || &b->entry == &lpi_range_list) |
| 1683 | return; |
| 1684 | if (a->base_id + a->span != b->base_id) |
| 1685 | return; |
| 1686 | b->base_id = a->base_id; |
| 1687 | b->span += a->span; |
| 1688 | list_del(&a->entry); |
| 1689 | kfree(a); |
| 1690 | } |
| 1691 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1692 | static int free_lpi_range(u32 base, u32 nr_lpis) |
| 1693 | { |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1694 | struct lpi_range *new, *old; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1695 | |
| 1696 | new = mk_lpi_range(base, nr_lpis); |
Rasmus Villemoes | b31a383 | 2019-03-12 18:33:47 +0100 | [diff] [blame] | 1697 | if (!new) |
| 1698 | return -ENOMEM; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1699 | |
| 1700 | mutex_lock(&lpi_range_lock); |
| 1701 | |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1702 | list_for_each_entry_reverse(old, &lpi_range_list, entry) { |
| 1703 | if (old->base_id < base) |
| 1704 | break; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1705 | } |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1706 | /* |
| 1707 | * old is the last element with ->base_id smaller than base, |
| 1708 | * so new goes right after it. If there are no elements with |
| 1709 | * ->base_id smaller than base, &old->entry ends up pointing |
| 1710 | * at the head of the list, and inserting new it the start of |
| 1711 | * the list is the right thing to do in that case as well. |
| 1712 | */ |
| 1713 | list_add(&new->entry, &old->entry); |
| 1714 | /* |
| 1715 | * Now check if we can merge with the preceding and/or |
| 1716 | * following ranges. |
| 1717 | */ |
| 1718 | merge_lpi_ranges(old, new); |
| 1719 | merge_lpi_ranges(new, list_next_entry(new, entry)); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1720 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1721 | mutex_unlock(&lpi_range_lock); |
Rasmus Villemoes | b31a383 | 2019-03-12 18:33:47 +0100 | [diff] [blame] | 1722 | return 0; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Tomasz Nowicki | 04a0e4d | 2016-01-19 14:11:18 +0100 | [diff] [blame] | 1725 | static int __init its_lpi_init(u32 id_bits) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1726 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1727 | u32 lpis = (1UL << id_bits) - 8192; |
Marc Zyngier | 12b2905 | 2018-05-31 09:01:59 +0100 | [diff] [blame] | 1728 | u32 numlpis; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1729 | int err; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1730 | |
Marc Zyngier | 12b2905 | 2018-05-31 09:01:59 +0100 | [diff] [blame] | 1731 | numlpis = 1UL << GICD_TYPER_NUM_LPIS(gic_rdists->gicd_typer); |
| 1732 | |
| 1733 | if (numlpis > 2 && !WARN_ON(numlpis > lpis)) { |
| 1734 | lpis = numlpis; |
| 1735 | pr_info("ITS: Using hypervisor restricted LPI range [%u]\n", |
| 1736 | lpis); |
| 1737 | } |
| 1738 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1739 | /* |
| 1740 | * Initializing the allocator is just the same as freeing the |
| 1741 | * full range of LPIs. |
| 1742 | */ |
| 1743 | err = free_lpi_range(8192, lpis); |
| 1744 | pr_debug("ITS: Allocator initialized for %u LPIs\n", lpis); |
| 1745 | return err; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1748 | static unsigned long *its_lpi_alloc(int nr_irqs, u32 *base, int *nr_ids) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1749 | { |
| 1750 | unsigned long *bitmap = NULL; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1751 | int err = 0; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1752 | |
| 1753 | do { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1754 | err = alloc_lpi_range(nr_irqs, base); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1755 | if (!err) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1756 | break; |
| 1757 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1758 | nr_irqs /= 2; |
| 1759 | } while (nr_irqs > 0); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1760 | |
Marc Zyngier | 45725e0 | 2019-01-29 15:19:23 +0000 | [diff] [blame] | 1761 | if (!nr_irqs) |
| 1762 | err = -ENOSPC; |
| 1763 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1764 | if (err) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1765 | goto out; |
| 1766 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1767 | bitmap = kcalloc(BITS_TO_LONGS(nr_irqs), sizeof (long), GFP_ATOMIC); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1768 | if (!bitmap) |
| 1769 | goto out; |
| 1770 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1771 | *nr_ids = nr_irqs; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1772 | |
| 1773 | out: |
Marc Zyngier | c8415b9 | 2015-10-02 16:44:05 +0100 | [diff] [blame] | 1774 | if (!bitmap) |
| 1775 | *base = *nr_ids = 0; |
| 1776 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1777 | return bitmap; |
| 1778 | } |
| 1779 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1780 | static void its_lpi_free(unsigned long *bitmap, u32 base, u32 nr_ids) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1781 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1782 | WARN_ON(free_lpi_range(base, nr_ids)); |
Marc Zyngier | cf2be8b | 2016-12-19 18:49:59 +0000 | [diff] [blame] | 1783 | kfree(bitmap); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1784 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1785 | |
Marc Zyngier | 053be48 | 2018-07-27 15:02:27 +0100 | [diff] [blame] | 1786 | static void gic_reset_prop_table(void *va) |
| 1787 | { |
| 1788 | /* Priority 0xa0, Group-1, disabled */ |
| 1789 | memset(va, LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1, LPI_PROPBASE_SZ); |
| 1790 | |
| 1791 | /* Make sure the GIC will observe the written configuration */ |
| 1792 | gic_flush_dcache_to_poc(va, LPI_PROPBASE_SZ); |
| 1793 | } |
| 1794 | |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 1795 | static struct page *its_allocate_prop_table(gfp_t gfp_flags) |
| 1796 | { |
| 1797 | struct page *prop_page; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1798 | |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 1799 | prop_page = alloc_pages(gfp_flags, get_order(LPI_PROPBASE_SZ)); |
| 1800 | if (!prop_page) |
| 1801 | return NULL; |
| 1802 | |
Marc Zyngier | 053be48 | 2018-07-27 15:02:27 +0100 | [diff] [blame] | 1803 | gic_reset_prop_table(page_address(prop_page)); |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 1804 | |
| 1805 | return prop_page; |
| 1806 | } |
| 1807 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 1808 | static void its_free_prop_table(struct page *prop_page) |
| 1809 | { |
| 1810 | free_pages((unsigned long)page_address(prop_page), |
| 1811 | get_order(LPI_PROPBASE_SZ)); |
| 1812 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1813 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 1814 | static bool gic_check_reserved_range(phys_addr_t addr, unsigned long size) |
| 1815 | { |
| 1816 | phys_addr_t start, end, addr_end; |
| 1817 | u64 i; |
| 1818 | |
| 1819 | /* |
| 1820 | * We don't bother checking for a kdump kernel as by |
| 1821 | * construction, the LPI tables are out of this kernel's |
| 1822 | * memory map. |
| 1823 | */ |
| 1824 | if (is_kdump_kernel()) |
| 1825 | return true; |
| 1826 | |
| 1827 | addr_end = addr + size - 1; |
| 1828 | |
| 1829 | for_each_reserved_mem_region(i, &start, &end) { |
| 1830 | if (addr >= start && addr_end <= end) |
| 1831 | return true; |
| 1832 | } |
| 1833 | |
| 1834 | /* Not found, not a good sign... */ |
| 1835 | pr_warn("GICv3: Expected reserved range [%pa:%pa], not found\n", |
| 1836 | &addr, &addr_end); |
| 1837 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 1838 | return false; |
| 1839 | } |
| 1840 | |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 1841 | static int gic_reserve_range(phys_addr_t addr, unsigned long size) |
| 1842 | { |
| 1843 | if (efi_enabled(EFI_CONFIG_TABLES)) |
| 1844 | return efi_mem_reserve_persistent(addr, size); |
| 1845 | |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 1849 | static int __init its_setup_lpi_prop_table(void) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1850 | { |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 1851 | if (gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED) { |
| 1852 | u64 val; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1853 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 1854 | val = gicr_read_propbaser(gic_data_rdist_rd_base() + GICR_PROPBASER); |
| 1855 | lpi_id_bits = (val & GICR_PROPBASER_IDBITS_MASK) + 1; |
| 1856 | |
| 1857 | gic_rdists->prop_table_pa = val & GENMASK_ULL(51, 12); |
| 1858 | gic_rdists->prop_table_va = memremap(gic_rdists->prop_table_pa, |
| 1859 | LPI_PROPBASE_SZ, |
| 1860 | MEMREMAP_WB); |
| 1861 | gic_reset_prop_table(gic_rdists->prop_table_va); |
| 1862 | } else { |
| 1863 | struct page *page; |
| 1864 | |
| 1865 | lpi_id_bits = min_t(u32, |
| 1866 | GICD_TYPER_ID_BITS(gic_rdists->gicd_typer), |
| 1867 | ITS_MAX_LPI_NRBITS); |
| 1868 | page = its_allocate_prop_table(GFP_NOWAIT); |
| 1869 | if (!page) { |
| 1870 | pr_err("Failed to allocate PROPBASE\n"); |
| 1871 | return -ENOMEM; |
| 1872 | } |
| 1873 | |
| 1874 | gic_rdists->prop_table_pa = page_to_phys(page); |
| 1875 | gic_rdists->prop_table_va = page_address(page); |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 1876 | WARN_ON(gic_reserve_range(gic_rdists->prop_table_pa, |
| 1877 | LPI_PROPBASE_SZ)); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1880 | pr_info("GICv3: using LPI property table @%pa\n", |
| 1881 | &gic_rdists->prop_table_pa); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1882 | |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 1883 | return its_lpi_init(lpi_id_bits); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | static const char *its_base_type_string[] = { |
| 1887 | [GITS_BASER_TYPE_DEVICE] = "Devices", |
| 1888 | [GITS_BASER_TYPE_VCPU] = "Virtual CPUs", |
Marc Zyngier | 4f46de9 | 2016-12-20 15:50:14 +0000 | [diff] [blame] | 1889 | [GITS_BASER_TYPE_RESERVED3] = "Reserved (3)", |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1890 | [GITS_BASER_TYPE_COLLECTION] = "Interrupt Collections", |
| 1891 | [GITS_BASER_TYPE_RESERVED5] = "Reserved (5)", |
| 1892 | [GITS_BASER_TYPE_RESERVED6] = "Reserved (6)", |
| 1893 | [GITS_BASER_TYPE_RESERVED7] = "Reserved (7)", |
| 1894 | }; |
| 1895 | |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 1896 | static u64 its_read_baser(struct its_node *its, struct its_baser *baser) |
| 1897 | { |
| 1898 | u32 idx = baser - its->tables; |
| 1899 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1900 | return gits_read_baser(its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | static void its_write_baser(struct its_node *its, struct its_baser *baser, |
| 1904 | u64 val) |
| 1905 | { |
| 1906 | u32 idx = baser - its->tables; |
| 1907 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1908 | gits_write_baser(val, its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 1909 | baser->val = its_read_baser(its, baser); |
| 1910 | } |
| 1911 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1912 | static int its_setup_baser(struct its_node *its, struct its_baser *baser, |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1913 | u64 cache, u64 shr, u32 psz, u32 order, |
| 1914 | bool indirect) |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1915 | { |
| 1916 | u64 val = its_read_baser(its, baser); |
| 1917 | u64 esz = GITS_BASER_ENTRY_SIZE(val); |
| 1918 | u64 type = GITS_BASER_TYPE(val); |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 1919 | u64 baser_phys, tmp; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1920 | u32 alloc_pages; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 1921 | struct page *page; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1922 | void *base; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1923 | |
| 1924 | retry_alloc_baser: |
| 1925 | alloc_pages = (PAGE_ORDER_TO_SIZE(order) / psz); |
| 1926 | if (alloc_pages > GITS_BASER_PAGES_MAX) { |
| 1927 | pr_warn("ITS@%pa: %s too large, reduce ITS pages %u->%u\n", |
| 1928 | &its->phys_base, its_base_type_string[type], |
| 1929 | alloc_pages, GITS_BASER_PAGES_MAX); |
| 1930 | alloc_pages = GITS_BASER_PAGES_MAX; |
| 1931 | order = get_order(GITS_BASER_PAGES_MAX * psz); |
| 1932 | } |
| 1933 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 1934 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order); |
| 1935 | if (!page) |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1936 | return -ENOMEM; |
| 1937 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 1938 | base = (void *)page_address(page); |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 1939 | baser_phys = virt_to_phys(base); |
| 1940 | |
| 1941 | /* Check if the physical address of the memory is above 48bits */ |
| 1942 | if (IS_ENABLED(CONFIG_ARM64_64K_PAGES) && (baser_phys >> 48)) { |
| 1943 | |
| 1944 | /* 52bit PA is supported only when PageSize=64K */ |
| 1945 | if (psz != SZ_64K) { |
| 1946 | pr_err("ITS: no 52bit PA support when psz=%d\n", psz); |
| 1947 | free_pages((unsigned long)base, order); |
| 1948 | return -ENXIO; |
| 1949 | } |
| 1950 | |
| 1951 | /* Convert 52bit PA to 48bit field */ |
| 1952 | baser_phys = GITS_BASER_PHYS_52_to_48(baser_phys); |
| 1953 | } |
| 1954 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1955 | retry_baser: |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 1956 | val = (baser_phys | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1957 | (type << GITS_BASER_TYPE_SHIFT) | |
| 1958 | ((esz - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | |
| 1959 | ((alloc_pages - 1) << GITS_BASER_PAGES_SHIFT) | |
| 1960 | cache | |
| 1961 | shr | |
| 1962 | GITS_BASER_VALID); |
| 1963 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1964 | val |= indirect ? GITS_BASER_INDIRECT : 0x0; |
| 1965 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1966 | switch (psz) { |
| 1967 | case SZ_4K: |
| 1968 | val |= GITS_BASER_PAGE_SIZE_4K; |
| 1969 | break; |
| 1970 | case SZ_16K: |
| 1971 | val |= GITS_BASER_PAGE_SIZE_16K; |
| 1972 | break; |
| 1973 | case SZ_64K: |
| 1974 | val |= GITS_BASER_PAGE_SIZE_64K; |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | its_write_baser(its, baser, val); |
| 1979 | tmp = baser->val; |
| 1980 | |
| 1981 | if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) { |
| 1982 | /* |
| 1983 | * Shareability didn't stick. Just use |
| 1984 | * whatever the read reported, which is likely |
| 1985 | * to be the only thing this redistributor |
| 1986 | * supports. If that's zero, make it |
| 1987 | * non-cacheable as well. |
| 1988 | */ |
| 1989 | shr = tmp & GITS_BASER_SHAREABILITY_MASK; |
| 1990 | if (!shr) { |
| 1991 | cache = GITS_BASER_nC; |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1992 | gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1993 | } |
| 1994 | goto retry_baser; |
| 1995 | } |
| 1996 | |
| 1997 | if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) { |
| 1998 | /* |
| 1999 | * Page size didn't stick. Let's try a smaller |
| 2000 | * size and retry. If we reach 4K, then |
| 2001 | * something is horribly wrong... |
| 2002 | */ |
| 2003 | free_pages((unsigned long)base, order); |
| 2004 | baser->base = NULL; |
| 2005 | |
| 2006 | switch (psz) { |
| 2007 | case SZ_16K: |
| 2008 | psz = SZ_4K; |
| 2009 | goto retry_alloc_baser; |
| 2010 | case SZ_64K: |
| 2011 | psz = SZ_16K; |
| 2012 | goto retry_alloc_baser; |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | if (val != tmp) { |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 2017 | pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n", |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2018 | &its->phys_base, its_base_type_string[type], |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 2019 | val, tmp); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2020 | free_pages((unsigned long)base, order); |
| 2021 | return -ENXIO; |
| 2022 | } |
| 2023 | |
| 2024 | baser->order = order; |
| 2025 | baser->base = base; |
| 2026 | baser->psz = psz; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2027 | tmp = indirect ? GITS_LVL1_ENTRY_SIZE : esz; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2028 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2029 | pr_info("ITS@%pa: allocated %d %s @%lx (%s, esz %d, psz %dK, shr %d)\n", |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 2030 | &its->phys_base, (int)(PAGE_ORDER_TO_SIZE(order) / (int)tmp), |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2031 | its_base_type_string[type], |
| 2032 | (unsigned long)virt_to_phys(base), |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2033 | indirect ? "indirect" : "flat", (int)esz, |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2034 | psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT); |
| 2035 | |
| 2036 | return 0; |
| 2037 | } |
| 2038 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2039 | static bool its_parse_indirect_baser(struct its_node *its, |
| 2040 | struct its_baser *baser, |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2041 | u32 psz, u32 *order, u32 ids) |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2042 | { |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2043 | u64 tmp = its_read_baser(its, baser); |
| 2044 | u64 type = GITS_BASER_TYPE(tmp); |
| 2045 | u64 esz = GITS_BASER_ENTRY_SIZE(tmp); |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2046 | u64 val = GITS_BASER_InnerShareable | GITS_BASER_RaWaWb; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2047 | u32 new_order = *order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2048 | bool indirect = false; |
| 2049 | |
| 2050 | /* No need to enable Indirection if memory requirement < (psz*2)bytes */ |
| 2051 | if ((esz << ids) > (psz * 2)) { |
| 2052 | /* |
| 2053 | * Find out whether hw supports a single or two-level table by |
| 2054 | * table by reading bit at offset '62' after writing '1' to it. |
| 2055 | */ |
| 2056 | its_write_baser(its, baser, val | GITS_BASER_INDIRECT); |
| 2057 | indirect = !!(baser->val & GITS_BASER_INDIRECT); |
| 2058 | |
| 2059 | if (indirect) { |
| 2060 | /* |
| 2061 | * The size of the lvl2 table is equal to ITS page size |
| 2062 | * which is 'psz'. For computing lvl1 table size, |
| 2063 | * subtract ID bits that sparse lvl2 table from 'ids' |
| 2064 | * which is reported by ITS hardware times lvl1 table |
| 2065 | * entry size. |
| 2066 | */ |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 2067 | ids -= ilog2(psz / (int)esz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2068 | esz = GITS_LVL1_ENTRY_SIZE; |
| 2069 | } |
| 2070 | } |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2071 | |
| 2072 | /* |
| 2073 | * Allocate as many entries as required to fit the |
| 2074 | * range of device IDs that the ITS can grok... The ID |
| 2075 | * space being incredibly sparse, this results in a |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2076 | * massive waste of memory if two-level device table |
| 2077 | * feature is not supported by hardware. |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2078 | */ |
| 2079 | new_order = max_t(u32, get_order(esz << ids), new_order); |
| 2080 | if (new_order >= MAX_ORDER) { |
| 2081 | new_order = MAX_ORDER - 1; |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 2082 | ids = ilog2(PAGE_ORDER_TO_SIZE(new_order) / (int)esz); |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2083 | pr_warn("ITS@%pa: %s Table too large, reduce ids %llu->%u\n", |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2084 | &its->phys_base, its_base_type_string[type], |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2085 | device_ids(its), ids); |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | *order = new_order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2089 | |
| 2090 | return indirect; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2091 | } |
| 2092 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2093 | static void its_free_tables(struct its_node *its) |
| 2094 | { |
| 2095 | int i; |
| 2096 | |
| 2097 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 1a485f4 | 2016-02-01 20:19:44 -0600 | [diff] [blame] | 2098 | if (its->tables[i].base) { |
| 2099 | free_pages((unsigned long)its->tables[i].base, |
| 2100 | its->tables[i].order); |
| 2101 | its->tables[i].base = NULL; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 2106 | static int its_alloc_tables(struct its_node *its) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2107 | { |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2108 | u64 shr = GITS_BASER_InnerShareable; |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2109 | u64 cache = GITS_BASER_RaWaWb; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2110 | u32 psz = SZ_64K; |
| 2111 | int err, i; |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 2112 | |
Ard Biesheuvel | fa15001 | 2017-10-17 17:55:54 +0100 | [diff] [blame] | 2113 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_22375) |
| 2114 | /* erratum 24313: ignore memory access type */ |
| 2115 | cache = GITS_BASER_nCnB; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 2116 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2117 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 2118 | struct its_baser *baser = its->tables + i; |
| 2119 | u64 val = its_read_baser(its, baser); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2120 | u64 type = GITS_BASER_TYPE(val); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2121 | u32 order = get_order(psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2122 | bool indirect = false; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2123 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2124 | switch (type) { |
| 2125 | case GITS_BASER_TYPE_NONE: |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2126 | continue; |
| 2127 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2128 | case GITS_BASER_TYPE_DEVICE: |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2129 | indirect = its_parse_indirect_baser(its, baser, |
| 2130 | psz, &order, |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2131 | device_ids(its)); |
Zenghui Yu | 8d56574 | 2019-02-10 05:24:10 +0000 | [diff] [blame] | 2132 | break; |
| 2133 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2134 | case GITS_BASER_TYPE_VCPU: |
| 2135 | indirect = its_parse_indirect_baser(its, baser, |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2136 | psz, &order, |
| 2137 | ITS_MAX_VPEID_BITS); |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | } |
Marc Zyngier | f54b97e | 2015-03-06 16:37:41 +0000 | [diff] [blame] | 2140 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2141 | err = its_setup_baser(its, baser, cache, shr, psz, order, indirect); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2142 | if (err < 0) { |
| 2143 | its_free_tables(its); |
| 2144 | return err; |
Robert Richter | 30f2136 | 2015-09-21 22:58:34 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2147 | /* Update settings which will be used for next BASERn */ |
| 2148 | psz = baser->psz; |
| 2149 | cache = baser->val & GITS_BASER_CACHEABILITY_MASK; |
| 2150 | shr = baser->val & GITS_BASER_SHAREABILITY_MASK; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | return 0; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | static int its_alloc_collections(struct its_node *its) |
| 2157 | { |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 2158 | int i; |
| 2159 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2160 | its->collections = kcalloc(nr_cpu_ids, sizeof(*its->collections), |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2161 | GFP_KERNEL); |
| 2162 | if (!its->collections) |
| 2163 | return -ENOMEM; |
| 2164 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 2165 | for (i = 0; i < nr_cpu_ids; i++) |
| 2166 | its->collections[i].target_address = ~0ULL; |
| 2167 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2168 | return 0; |
| 2169 | } |
| 2170 | |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2171 | static struct page *its_allocate_pending_table(gfp_t gfp_flags) |
| 2172 | { |
| 2173 | struct page *pend_page; |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2174 | |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2175 | pend_page = alloc_pages(gfp_flags | __GFP_ZERO, |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2176 | get_order(LPI_PENDBASE_SZ)); |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2177 | if (!pend_page) |
| 2178 | return NULL; |
| 2179 | |
| 2180 | /* Make sure the GIC will observe the zero-ed page */ |
| 2181 | gic_flush_dcache_to_poc(page_address(pend_page), LPI_PENDBASE_SZ); |
| 2182 | |
| 2183 | return pend_page; |
| 2184 | } |
| 2185 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2186 | static void its_free_pending_table(struct page *pt) |
| 2187 | { |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2188 | free_pages((unsigned long)page_address(pt), get_order(LPI_PENDBASE_SZ)); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2191 | /* |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2192 | * Booting with kdump and LPIs enabled is generally fine. Any other |
| 2193 | * case is wrong in the absence of firmware/EFI support. |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2194 | */ |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2195 | static bool enabled_lpis_allowed(void) |
| 2196 | { |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2197 | phys_addr_t addr; |
| 2198 | u64 val; |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2199 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2200 | /* Check whether the property table is in a reserved region */ |
| 2201 | val = gicr_read_propbaser(gic_data_rdist_rd_base() + GICR_PROPBASER); |
| 2202 | addr = val & GENMASK_ULL(51, 12); |
| 2203 | |
| 2204 | return gic_check_reserved_range(addr, LPI_PROPBASE_SZ); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2207 | static int __init allocate_lpi_tables(void) |
| 2208 | { |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2209 | u64 val; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2210 | int err, cpu; |
| 2211 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2212 | /* |
| 2213 | * If LPIs are enabled while we run this from the boot CPU, |
| 2214 | * flag the RD tables as pre-allocated if the stars do align. |
| 2215 | */ |
| 2216 | val = readl_relaxed(gic_data_rdist_rd_base() + GICR_CTLR); |
| 2217 | if ((val & GICR_CTLR_ENABLE_LPIS) && enabled_lpis_allowed()) { |
| 2218 | gic_rdists->flags |= (RDIST_FLAGS_RD_TABLES_PREALLOCATED | |
| 2219 | RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING); |
| 2220 | pr_info("GICv3: Using preallocated redistributor tables\n"); |
| 2221 | } |
| 2222 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2223 | err = its_setup_lpi_prop_table(); |
| 2224 | if (err) |
| 2225 | return err; |
| 2226 | |
| 2227 | /* |
| 2228 | * We allocate all the pending tables anyway, as we may have a |
| 2229 | * mix of RDs that have had LPIs enabled, and some that |
| 2230 | * don't. We'll free the unused ones as each CPU comes online. |
| 2231 | */ |
| 2232 | for_each_possible_cpu(cpu) { |
| 2233 | struct page *pend_page; |
| 2234 | |
| 2235 | pend_page = its_allocate_pending_table(GFP_NOWAIT); |
| 2236 | if (!pend_page) { |
| 2237 | pr_err("Failed to allocate PENDBASE for CPU%d\n", cpu); |
| 2238 | return -ENOMEM; |
| 2239 | } |
| 2240 | |
| 2241 | gic_data_rdist_cpu(cpu)->pend_page = pend_page; |
| 2242 | } |
| 2243 | |
| 2244 | return 0; |
| 2245 | } |
| 2246 | |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2247 | static u64 its_clear_vpend_valid(void __iomem *vlpi_base) |
| 2248 | { |
| 2249 | u32 count = 1000000; /* 1s! */ |
| 2250 | bool clean; |
| 2251 | u64 val; |
| 2252 | |
| 2253 | val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); |
| 2254 | val &= ~GICR_VPENDBASER_Valid; |
| 2255 | gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); |
| 2256 | |
| 2257 | do { |
| 2258 | val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); |
| 2259 | clean = !(val & GICR_VPENDBASER_Dirty); |
| 2260 | if (!clean) { |
| 2261 | count--; |
| 2262 | cpu_relax(); |
| 2263 | udelay(1); |
| 2264 | } |
| 2265 | } while (!clean && count); |
| 2266 | |
| 2267 | return val; |
| 2268 | } |
| 2269 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2270 | static void its_cpu_init_lpis(void) |
| 2271 | { |
| 2272 | void __iomem *rbase = gic_data_rdist_rd_base(); |
| 2273 | struct page *pend_page; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2274 | phys_addr_t paddr; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2275 | u64 val, tmp; |
| 2276 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2277 | if (gic_data_rdist()->lpi_enabled) |
| 2278 | return; |
| 2279 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2280 | val = readl_relaxed(rbase + GICR_CTLR); |
| 2281 | if ((gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED) && |
| 2282 | (val & GICR_CTLR_ENABLE_LPIS)) { |
Marc Zyngier | f842ca8 | 2018-07-27 16:03:31 +0100 | [diff] [blame] | 2283 | /* |
| 2284 | * Check that we get the same property table on all |
| 2285 | * RDs. If we don't, this is hopeless. |
| 2286 | */ |
| 2287 | paddr = gicr_read_propbaser(rbase + GICR_PROPBASER); |
| 2288 | paddr &= GENMASK_ULL(51, 12); |
| 2289 | if (WARN_ON(gic_rdists->prop_table_pa != paddr)) |
| 2290 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 2291 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2292 | paddr = gicr_read_pendbaser(rbase + GICR_PENDBASER); |
| 2293 | paddr &= GENMASK_ULL(51, 16); |
| 2294 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2295 | WARN_ON(!gic_check_reserved_range(paddr, LPI_PENDBASE_SZ)); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2296 | its_free_pending_table(gic_data_rdist()->pend_page); |
| 2297 | gic_data_rdist()->pend_page = NULL; |
| 2298 | |
| 2299 | goto out; |
| 2300 | } |
| 2301 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2302 | pend_page = gic_data_rdist()->pend_page; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2303 | paddr = page_to_phys(pend_page); |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 2304 | WARN_ON(gic_reserve_range(paddr, LPI_PENDBASE_SZ)); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2305 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2306 | /* set PROPBASE */ |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 2307 | val = (gic_rdists->prop_table_pa | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2308 | GICR_PROPBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2309 | GICR_PROPBASER_RaWaWb | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2310 | ((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK)); |
| 2311 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2312 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
| 2313 | tmp = gicr_read_propbaser(rbase + GICR_PROPBASER); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2314 | |
| 2315 | if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2316 | if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) { |
| 2317 | /* |
| 2318 | * The HW reports non-shareable, we must |
| 2319 | * remove the cacheability attributes as |
| 2320 | * well. |
| 2321 | */ |
| 2322 | val &= ~(GICR_PROPBASER_SHAREABILITY_MASK | |
| 2323 | GICR_PROPBASER_CACHEABILITY_MASK); |
| 2324 | val |= GICR_PROPBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2325 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2326 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2327 | pr_info_once("GIC: using cache flushing for LPI property table\n"); |
| 2328 | gic_rdists->flags |= RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING; |
| 2329 | } |
| 2330 | |
| 2331 | /* set PENDBASE */ |
| 2332 | val = (page_to_phys(pend_page) | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 2333 | GICR_PENDBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2334 | GICR_PENDBASER_RaWaWb); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2335 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2336 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
| 2337 | tmp = gicr_read_pendbaser(rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2338 | |
| 2339 | if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) { |
| 2340 | /* |
| 2341 | * The HW reports non-shareable, we must remove the |
| 2342 | * cacheability attributes as well. |
| 2343 | */ |
| 2344 | val &= ~(GICR_PENDBASER_SHAREABILITY_MASK | |
| 2345 | GICR_PENDBASER_CACHEABILITY_MASK); |
| 2346 | val |= GICR_PENDBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2347 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2348 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2349 | |
| 2350 | /* Enable LPIs */ |
| 2351 | val = readl_relaxed(rbase + GICR_CTLR); |
| 2352 | val |= GICR_CTLR_ENABLE_LPIS; |
| 2353 | writel_relaxed(val, rbase + GICR_CTLR); |
| 2354 | |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2355 | if (gic_rdists->has_vlpis) { |
| 2356 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
| 2357 | |
| 2358 | /* |
| 2359 | * It's possible for CPU to receive VLPIs before it is |
| 2360 | * sheduled as a vPE, especially for the first CPU, and the |
| 2361 | * VLPI with INTID larger than 2^(IDbits+1) will be considered |
| 2362 | * as out of range and dropped by GIC. |
| 2363 | * So we initialize IDbits to known value to avoid VLPI drop. |
| 2364 | */ |
| 2365 | val = (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; |
| 2366 | pr_debug("GICv4: CPU%d: Init IDbits to 0x%llx for GICR_VPROPBASER\n", |
| 2367 | smp_processor_id(), val); |
| 2368 | gits_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
| 2369 | |
| 2370 | /* |
| 2371 | * Also clear Valid bit of GICR_VPENDBASER, in case some |
| 2372 | * ancient programming gets left in and has possibility of |
| 2373 | * corrupting memory. |
| 2374 | */ |
| 2375 | val = its_clear_vpend_valid(vlpi_base); |
| 2376 | WARN_ON(val & GICR_VPENDBASER_Dirty); |
| 2377 | } |
| 2378 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2379 | /* Make sure the GIC has seen the above */ |
| 2380 | dsb(sy); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2381 | out: |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2382 | gic_data_rdist()->lpi_enabled = true; |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2383 | pr_info("GICv3: CPU%d: using %s LPI pending table @%pa\n", |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2384 | smp_processor_id(), |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2385 | gic_data_rdist()->pend_page ? "allocated" : "reserved", |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2386 | &paddr); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2389 | static void its_cpu_init_collection(struct its_node *its) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2390 | { |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2391 | int cpu = smp_processor_id(); |
| 2392 | u64 target; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2393 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2394 | /* avoid cross node collections and its mapping */ |
| 2395 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 2396 | struct device_node *cpu_node; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2397 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2398 | cpu_node = of_get_cpu_node(cpu, NULL); |
| 2399 | if (its->numa_node != NUMA_NO_NODE && |
| 2400 | its->numa_node != of_node_to_nid(cpu_node)) |
| 2401 | return; |
| 2402 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2403 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2404 | /* |
| 2405 | * We now have to bind each collection to its target |
| 2406 | * redistributor. |
| 2407 | */ |
| 2408 | if (gic_read_typer(its->base + GITS_TYPER) & GITS_TYPER_PTA) { |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2409 | /* |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2410 | * This ITS wants the physical address of the |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2411 | * redistributor. |
| 2412 | */ |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2413 | target = gic_data_rdist()->phys_base; |
| 2414 | } else { |
| 2415 | /* This ITS wants a linear CPU number. */ |
| 2416 | target = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER); |
| 2417 | target = GICR_TYPER_CPU_NUMBER(target) << 16; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2420 | /* Perform collection mapping */ |
| 2421 | its->collections[cpu].target_address = target; |
| 2422 | its->collections[cpu].col_id = cpu; |
| 2423 | |
| 2424 | its_send_mapc(its, &its->collections[cpu], 1); |
| 2425 | its_send_invall(its, &its->collections[cpu]); |
| 2426 | } |
| 2427 | |
| 2428 | static void its_cpu_init_collections(void) |
| 2429 | { |
| 2430 | struct its_node *its; |
| 2431 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 2432 | raw_spin_lock(&its_lock); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 2433 | |
| 2434 | list_for_each_entry(its, &its_nodes, entry) |
| 2435 | its_cpu_init_collection(its); |
| 2436 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 2437 | raw_spin_unlock(&its_lock); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2438 | } |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2439 | |
| 2440 | static struct its_device *its_find_device(struct its_node *its, u32 dev_id) |
| 2441 | { |
| 2442 | struct its_device *its_dev = NULL, *tmp; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2443 | unsigned long flags; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2444 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2445 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2446 | |
| 2447 | list_for_each_entry(tmp, &its->its_device_list, entry) { |
| 2448 | if (tmp->device_id == dev_id) { |
| 2449 | its_dev = tmp; |
| 2450 | break; |
| 2451 | } |
| 2452 | } |
| 2453 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2454 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2455 | |
| 2456 | return its_dev; |
| 2457 | } |
| 2458 | |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 2459 | static struct its_baser *its_get_baser(struct its_node *its, u32 type) |
| 2460 | { |
| 2461 | int i; |
| 2462 | |
| 2463 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
| 2464 | if (GITS_BASER_TYPE(its->tables[i].val) == type) |
| 2465 | return &its->tables[i]; |
| 2466 | } |
| 2467 | |
| 2468 | return NULL; |
| 2469 | } |
| 2470 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2471 | static bool its_alloc_table_entry(struct its_node *its, |
| 2472 | struct its_baser *baser, u32 id) |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2473 | { |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2474 | struct page *page; |
| 2475 | u32 esz, idx; |
| 2476 | __le64 *table; |
| 2477 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2478 | /* Don't allow device id that exceeds single, flat table limit */ |
| 2479 | esz = GITS_BASER_ENTRY_SIZE(baser->val); |
| 2480 | if (!(baser->val & GITS_BASER_INDIRECT)) |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 2481 | return (id < (PAGE_ORDER_TO_SIZE(baser->order) / esz)); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2482 | |
| 2483 | /* Compute 1st level table index & check if that exceeds table limit */ |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 2484 | idx = id >> ilog2(baser->psz / esz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2485 | if (idx >= (PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE)) |
| 2486 | return false; |
| 2487 | |
| 2488 | table = baser->base; |
| 2489 | |
| 2490 | /* Allocate memory for 2nd level table */ |
| 2491 | if (!table[idx]) { |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2492 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, |
| 2493 | get_order(baser->psz)); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2494 | if (!page) |
| 2495 | return false; |
| 2496 | |
| 2497 | /* Flush Lvl2 table to PoC if hw doesn't support coherency */ |
| 2498 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 2499 | gic_flush_dcache_to_poc(page_address(page), baser->psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2500 | |
| 2501 | table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID); |
| 2502 | |
| 2503 | /* Flush Lvl1 entry to PoC if hw doesn't support coherency */ |
| 2504 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 2505 | gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2506 | |
| 2507 | /* Ensure updated table contents are visible to ITS hardware */ |
| 2508 | dsb(sy); |
| 2509 | } |
| 2510 | |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 2514 | static bool its_alloc_device_table(struct its_node *its, u32 dev_id) |
| 2515 | { |
| 2516 | struct its_baser *baser; |
| 2517 | |
| 2518 | baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE); |
| 2519 | |
| 2520 | /* Don't allow device id that exceeds ITS hardware limit */ |
| 2521 | if (!baser) |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2522 | return (ilog2(dev_id) < device_ids(its)); |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 2523 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2524 | return its_alloc_table_entry(its, baser, dev_id); |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2527 | static bool its_alloc_vpe_table(u32 vpe_id) |
| 2528 | { |
| 2529 | struct its_node *its; |
| 2530 | |
| 2531 | /* |
| 2532 | * Make sure the L2 tables are allocated on *all* v4 ITSs. We |
| 2533 | * could try and only do it on ITSs corresponding to devices |
| 2534 | * that have interrupts targeted at this VPE, but the |
| 2535 | * complexity becomes crazy (and you have tons of memory |
| 2536 | * anyway, right?). |
| 2537 | */ |
| 2538 | list_for_each_entry(its, &its_nodes, entry) { |
| 2539 | struct its_baser *baser; |
| 2540 | |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 2541 | if (!is_v4(its)) |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2542 | continue; |
| 2543 | |
| 2544 | baser = its_get_baser(its, GITS_BASER_TYPE_VCPU); |
| 2545 | if (!baser) |
| 2546 | return false; |
| 2547 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2548 | if (!its_alloc_table_entry(its, baser, vpe_id)) |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | return true; |
| 2553 | } |
| 2554 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2555 | static struct its_device *its_create_device(struct its_node *its, u32 dev_id, |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2556 | int nvecs, bool alloc_lpis) |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2557 | { |
| 2558 | struct its_device *dev; |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2559 | unsigned long *lpi_map = NULL; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2560 | unsigned long flags; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2561 | u16 *col_map = NULL; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2562 | void *itt; |
| 2563 | int lpi_base; |
| 2564 | int nr_lpis; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 2565 | int nr_ites; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2566 | int sz; |
| 2567 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2568 | if (!its_alloc_device_table(its, dev_id)) |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 2569 | return NULL; |
| 2570 | |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 2571 | if (WARN_ON(!is_power_of_2(nvecs))) |
| 2572 | nvecs = roundup_pow_of_two(nvecs); |
| 2573 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2574 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 2575 | /* |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 2576 | * Even if the device wants a single LPI, the ITT must be |
| 2577 | * sized as a power of two (and you need at least one bit...). |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 2578 | */ |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 2579 | nr_ites = max(2, nvecs); |
Marc Zyngier | ffedbf0 | 2019-11-08 16:57:59 +0000 | [diff] [blame] | 2580 | sz = nr_ites * (FIELD_GET(GITS_TYPER_ITT_ENTRY_SIZE, its->typer) + 1); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2581 | sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2582 | itt = kzalloc_node(sz, GFP_KERNEL, its->numa_node); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2583 | if (alloc_lpis) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 2584 | lpi_map = its_lpi_alloc(nvecs, &lpi_base, &nr_lpis); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2585 | if (lpi_map) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2586 | col_map = kcalloc(nr_lpis, sizeof(*col_map), |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2587 | GFP_KERNEL); |
| 2588 | } else { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2589 | col_map = kcalloc(nr_ites, sizeof(*col_map), GFP_KERNEL); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2590 | nr_lpis = 0; |
| 2591 | lpi_base = 0; |
| 2592 | } |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2593 | |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2594 | if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) { |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2595 | kfree(dev); |
| 2596 | kfree(itt); |
| 2597 | kfree(lpi_map); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2598 | kfree(col_map); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2599 | return NULL; |
| 2600 | } |
| 2601 | |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 2602 | gic_flush_dcache_to_poc(itt, sz); |
Marc Zyngier | 5a9a891 | 2015-09-13 12:14:32 +0100 | [diff] [blame] | 2603 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2604 | dev->its = its; |
| 2605 | dev->itt = itt; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 2606 | dev->nr_ites = nr_ites; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2607 | dev->event_map.lpi_map = lpi_map; |
| 2608 | dev->event_map.col_map = col_map; |
| 2609 | dev->event_map.lpi_base = lpi_base; |
| 2610 | dev->event_map.nr_lpis = nr_lpis; |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame^] | 2611 | raw_spin_lock_init(&dev->event_map.vlpi_lock); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2612 | dev->device_id = dev_id; |
| 2613 | INIT_LIST_HEAD(&dev->entry); |
| 2614 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2615 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2616 | list_add(&dev->entry, &its->its_device_list); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2617 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2618 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2619 | /* Map device to its ITT */ |
| 2620 | its_send_mapd(dev, 1); |
| 2621 | |
| 2622 | return dev; |
| 2623 | } |
| 2624 | |
| 2625 | static void its_free_device(struct its_device *its_dev) |
| 2626 | { |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2627 | unsigned long flags; |
| 2628 | |
| 2629 | raw_spin_lock_irqsave(&its_dev->its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2630 | list_del(&its_dev->entry); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 2631 | raw_spin_unlock_irqrestore(&its_dev->its->lock, flags); |
Marc Zyngier | 898aa5c | 2019-11-08 16:57:55 +0000 | [diff] [blame] | 2632 | kfree(its_dev->event_map.col_map); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 2633 | kfree(its_dev->itt); |
| 2634 | kfree(its_dev); |
| 2635 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2636 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2637 | static int its_alloc_device_irq(struct its_device *dev, int nvecs, irq_hw_number_t *hwirq) |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2638 | { |
| 2639 | int idx; |
| 2640 | |
Zenghui Yu | 342be10 | 2019-07-27 06:14:22 +0000 | [diff] [blame] | 2641 | /* Find a free LPI region in lpi_map and allocate them. */ |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2642 | idx = bitmap_find_free_region(dev->event_map.lpi_map, |
| 2643 | dev->event_map.nr_lpis, |
| 2644 | get_count_order(nvecs)); |
| 2645 | if (idx < 0) |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2646 | return -ENOSPC; |
| 2647 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2648 | *hwirq = dev->event_map.lpi_base + idx; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2649 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2650 | return 0; |
| 2651 | } |
| 2652 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 2653 | static int its_msi_prepare(struct irq_domain *domain, struct device *dev, |
| 2654 | int nvec, msi_alloc_info_t *info) |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 2655 | { |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2656 | struct its_node *its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2657 | struct its_device *its_dev; |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 2658 | struct msi_domain_info *msi_info; |
| 2659 | u32 dev_id; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2660 | int err = 0; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2661 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 2662 | /* |
Julien Grall | a7c90f5 | 2019-04-18 16:58:14 +0100 | [diff] [blame] | 2663 | * We ignore "dev" entirely, and rely on the dev_id that has |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 2664 | * been passed via the scratchpad. This limits this domain's |
| 2665 | * usefulness to upper layers that definitely know that they |
| 2666 | * are built on top of the ITS. |
| 2667 | */ |
| 2668 | dev_id = info->scratchpad[0].ul; |
| 2669 | |
| 2670 | msi_info = msi_get_domain_info(domain); |
| 2671 | its = msi_info->data; |
| 2672 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 2673 | if (!gic_rdists->has_direct_lpi && |
| 2674 | vpe_proxy.dev && |
| 2675 | vpe_proxy.dev->its == its && |
| 2676 | dev_id == vpe_proxy.dev->device_id) { |
| 2677 | /* Bad luck. Get yourself a better implementation */ |
| 2678 | WARN_ONCE(1, "DevId %x clashes with GICv4 VPE proxy device\n", |
| 2679 | dev_id); |
| 2680 | return -EINVAL; |
| 2681 | } |
| 2682 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2683 | mutex_lock(&its->dev_alloc_lock); |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 2684 | its_dev = its_find_device(its, dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 2685 | if (its_dev) { |
| 2686 | /* |
| 2687 | * We already have seen this ID, probably through |
| 2688 | * another alias (PCI bridge of some sort). No need to |
| 2689 | * create the device. |
| 2690 | */ |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2691 | its_dev->shared = true; |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 2692 | pr_debug("Reusing ITT for devID %x\n", dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 2693 | goto out; |
| 2694 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2695 | |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 2696 | its_dev = its_create_device(its, dev_id, nvec, true); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2697 | if (!its_dev) { |
| 2698 | err = -ENOMEM; |
| 2699 | goto out; |
| 2700 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2701 | |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 2702 | pr_debug("ITT %d entries, %d bits\n", nvec, ilog2(nvec)); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 2703 | out: |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2704 | mutex_unlock(&its->dev_alloc_lock); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2705 | info->scratchpad[0].ptr = its_dev; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2706 | return err; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 2709 | static struct msi_domain_ops its_msi_domain_ops = { |
| 2710 | .msi_prepare = its_msi_prepare, |
| 2711 | }; |
| 2712 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2713 | static int its_irq_gic_domain_alloc(struct irq_domain *domain, |
| 2714 | unsigned int virq, |
| 2715 | irq_hw_number_t hwirq) |
| 2716 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 2717 | struct irq_fwspec fwspec; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2718 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 2719 | if (irq_domain_get_of_node(domain->parent)) { |
| 2720 | fwspec.fwnode = domain->parent->fwnode; |
| 2721 | fwspec.param_count = 3; |
| 2722 | fwspec.param[0] = GIC_IRQ_TYPE_LPI; |
| 2723 | fwspec.param[1] = hwirq; |
| 2724 | fwspec.param[2] = IRQ_TYPE_EDGE_RISING; |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2725 | } else if (is_fwnode_irqchip(domain->parent->fwnode)) { |
| 2726 | fwspec.fwnode = domain->parent->fwnode; |
| 2727 | fwspec.param_count = 2; |
| 2728 | fwspec.param[0] = hwirq; |
| 2729 | fwspec.param[1] = IRQ_TYPE_EDGE_RISING; |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 2730 | } else { |
| 2731 | return -EINVAL; |
| 2732 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2733 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 2734 | return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | static int its_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 2738 | unsigned int nr_irqs, void *args) |
| 2739 | { |
| 2740 | msi_alloc_info_t *info = args; |
| 2741 | struct its_device *its_dev = info->scratchpad[0].ptr; |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 2742 | struct its_node *its = its_dev->its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2743 | irq_hw_number_t hwirq; |
| 2744 | int err; |
| 2745 | int i; |
| 2746 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2747 | err = its_alloc_device_irq(its_dev, nr_irqs, &hwirq); |
| 2748 | if (err) |
| 2749 | return err; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2750 | |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 2751 | err = iommu_dma_prepare_msi(info->desc, its->get_msi_base(its_dev)); |
| 2752 | if (err) |
| 2753 | return err; |
| 2754 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2755 | for (i = 0; i < nr_irqs; i++) { |
| 2756 | err = its_irq_gic_domain_alloc(domain, virq + i, hwirq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2757 | if (err) |
| 2758 | return err; |
| 2759 | |
| 2760 | irq_domain_set_hwirq_and_chip(domain, virq + i, |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2761 | hwirq + i, &its_irq_chip, its_dev); |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 2762 | irqd_set_single_target(irq_desc_get_irq_data(irq_to_desc(virq + i))); |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 2763 | pr_debug("ID:%d pID:%d vID:%d\n", |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 2764 | (int)(hwirq + i - its_dev->event_map.lpi_base), |
| 2765 | (int)(hwirq + i), virq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | return 0; |
| 2769 | } |
| 2770 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 2771 | static int its_irq_domain_activate(struct irq_domain *domain, |
Thomas Gleixner | 702cb0a | 2017-12-29 16:59:06 +0100 | [diff] [blame] | 2772 | struct irq_data *d, bool reserve) |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 2773 | { |
| 2774 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 2775 | u32 event = its_get_event_id(d); |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 2776 | const struct cpumask *cpu_mask = cpu_online_mask; |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 2777 | int cpu; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 2778 | |
| 2779 | /* get the cpu_mask of local node */ |
| 2780 | if (its_dev->its->numa_node >= 0) |
| 2781 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 2782 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2783 | /* Bind the LPI to the first possible CPU */ |
Yang Yingliang | c1797b1 | 2018-06-22 10:52:51 +0100 | [diff] [blame] | 2784 | cpu = cpumask_first_and(cpu_mask, cpu_online_mask); |
| 2785 | if (cpu >= nr_cpu_ids) { |
| 2786 | if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) |
| 2787 | return -EINVAL; |
| 2788 | |
| 2789 | cpu = cpumask_first(cpu_online_mask); |
| 2790 | } |
| 2791 | |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 2792 | its_dev->event_map.col_map[event] = cpu; |
| 2793 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2794 | |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 2795 | /* Map the GIC IRQ and event to the device */ |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 2796 | its_send_mapti(its_dev, d->hwirq, event); |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 2797 | return 0; |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | static void its_irq_domain_deactivate(struct irq_domain *domain, |
| 2801 | struct irq_data *d) |
| 2802 | { |
| 2803 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 2804 | u32 event = its_get_event_id(d); |
| 2805 | |
| 2806 | /* Stop the delivery of interrupts */ |
| 2807 | its_send_discard(its_dev, event); |
| 2808 | } |
| 2809 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2810 | static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq, |
| 2811 | unsigned int nr_irqs) |
| 2812 | { |
| 2813 | struct irq_data *d = irq_domain_get_irq_data(domain, virq); |
| 2814 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2815 | struct its_node *its = its_dev->its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2816 | int i; |
| 2817 | |
Marc Zyngier | c9c96e3 | 2019-09-05 14:56:47 +0100 | [diff] [blame] | 2818 | bitmap_release_region(its_dev->event_map.lpi_map, |
| 2819 | its_get_event_id(irq_domain_get_irq_data(domain, virq)), |
| 2820 | get_count_order(nr_irqs)); |
| 2821 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2822 | for (i = 0; i < nr_irqs; i++) { |
| 2823 | struct irq_data *data = irq_domain_get_irq_data(domain, |
| 2824 | virq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2825 | /* Nuke the entry in the domain */ |
Marc Zyngier | 2da3994 | 2014-12-12 10:51:22 +0000 | [diff] [blame] | 2826 | irq_domain_reset_irq_data(data); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2829 | mutex_lock(&its->dev_alloc_lock); |
| 2830 | |
| 2831 | /* |
| 2832 | * If all interrupts have been freed, start mopping the |
| 2833 | * floor. This is conditionned on the device not being shared. |
| 2834 | */ |
| 2835 | if (!its_dev->shared && |
| 2836 | bitmap_empty(its_dev->event_map.lpi_map, |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 2837 | its_dev->event_map.nr_lpis)) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 2838 | its_lpi_free(its_dev->event_map.lpi_map, |
| 2839 | its_dev->event_map.lpi_base, |
| 2840 | its_dev->event_map.nr_lpis); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2841 | |
| 2842 | /* Unmap device/itt */ |
| 2843 | its_send_mapd(its_dev, 0); |
| 2844 | its_free_device(its_dev); |
| 2845 | } |
| 2846 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 2847 | mutex_unlock(&its->dev_alloc_lock); |
| 2848 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2849 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 2850 | } |
| 2851 | |
| 2852 | static const struct irq_domain_ops its_domain_ops = { |
| 2853 | .alloc = its_irq_domain_alloc, |
| 2854 | .free = its_irq_domain_free, |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 2855 | .activate = its_irq_domain_activate, |
| 2856 | .deactivate = its_irq_domain_deactivate, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 2857 | }; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 2858 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 2859 | /* |
| 2860 | * This is insane. |
| 2861 | * |
| 2862 | * If a GICv4 doesn't implement Direct LPIs (which is extremely |
| 2863 | * likely), the only way to perform an invalidate is to use a fake |
| 2864 | * device to issue an INV command, implying that the LPI has first |
| 2865 | * been mapped to some event on that device. Since this is not exactly |
| 2866 | * cheap, we try to keep that mapping around as long as possible, and |
| 2867 | * only issue an UNMAP if we're short on available slots. |
| 2868 | * |
| 2869 | * Broken by design(tm). |
| 2870 | */ |
| 2871 | static void its_vpe_db_proxy_unmap_locked(struct its_vpe *vpe) |
| 2872 | { |
| 2873 | /* Already unmapped? */ |
| 2874 | if (vpe->vpe_proxy_event == -1) |
| 2875 | return; |
| 2876 | |
| 2877 | its_send_discard(vpe_proxy.dev, vpe->vpe_proxy_event); |
| 2878 | vpe_proxy.vpes[vpe->vpe_proxy_event] = NULL; |
| 2879 | |
| 2880 | /* |
| 2881 | * We don't track empty slots at all, so let's move the |
| 2882 | * next_victim pointer if we can quickly reuse that slot |
| 2883 | * instead of nuking an existing entry. Not clear that this is |
| 2884 | * always a win though, and this might just generate a ripple |
| 2885 | * effect... Let's just hope VPEs don't migrate too often. |
| 2886 | */ |
| 2887 | if (vpe_proxy.vpes[vpe_proxy.next_victim]) |
| 2888 | vpe_proxy.next_victim = vpe->vpe_proxy_event; |
| 2889 | |
| 2890 | vpe->vpe_proxy_event = -1; |
| 2891 | } |
| 2892 | |
| 2893 | static void its_vpe_db_proxy_unmap(struct its_vpe *vpe) |
| 2894 | { |
| 2895 | if (!gic_rdists->has_direct_lpi) { |
| 2896 | unsigned long flags; |
| 2897 | |
| 2898 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 2899 | its_vpe_db_proxy_unmap_locked(vpe); |
| 2900 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | static void its_vpe_db_proxy_map_locked(struct its_vpe *vpe) |
| 2905 | { |
| 2906 | /* Already mapped? */ |
| 2907 | if (vpe->vpe_proxy_event != -1) |
| 2908 | return; |
| 2909 | |
| 2910 | /* This slot was already allocated. Kick the other VPE out. */ |
| 2911 | if (vpe_proxy.vpes[vpe_proxy.next_victim]) |
| 2912 | its_vpe_db_proxy_unmap_locked(vpe_proxy.vpes[vpe_proxy.next_victim]); |
| 2913 | |
| 2914 | /* Map the new VPE instead */ |
| 2915 | vpe_proxy.vpes[vpe_proxy.next_victim] = vpe; |
| 2916 | vpe->vpe_proxy_event = vpe_proxy.next_victim; |
| 2917 | vpe_proxy.next_victim = (vpe_proxy.next_victim + 1) % vpe_proxy.dev->nr_ites; |
| 2918 | |
| 2919 | vpe_proxy.dev->event_map.col_map[vpe->vpe_proxy_event] = vpe->col_idx; |
| 2920 | its_send_mapti(vpe_proxy.dev, vpe->vpe_db_lpi, vpe->vpe_proxy_event); |
| 2921 | } |
| 2922 | |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 2923 | static void its_vpe_db_proxy_move(struct its_vpe *vpe, int from, int to) |
| 2924 | { |
| 2925 | unsigned long flags; |
| 2926 | struct its_collection *target_col; |
| 2927 | |
| 2928 | if (gic_rdists->has_direct_lpi) { |
| 2929 | void __iomem *rdbase; |
| 2930 | |
| 2931 | rdbase = per_cpu_ptr(gic_rdists->rdist, from)->rd_base; |
| 2932 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_CLRLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 2933 | wait_for_syncr(rdbase); |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 2934 | |
| 2935 | return; |
| 2936 | } |
| 2937 | |
| 2938 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 2939 | |
| 2940 | its_vpe_db_proxy_map_locked(vpe); |
| 2941 | |
| 2942 | target_col = &vpe_proxy.dev->its->collections[to]; |
| 2943 | its_send_movi(vpe_proxy.dev, target_col, vpe->vpe_proxy_event); |
| 2944 | vpe_proxy.dev->event_map.col_map[vpe->vpe_proxy_event] = to; |
| 2945 | |
| 2946 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 2947 | } |
| 2948 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 2949 | static int its_vpe_set_affinity(struct irq_data *d, |
| 2950 | const struct cpumask *mask_val, |
| 2951 | bool force) |
| 2952 | { |
| 2953 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 2954 | int cpu = cpumask_first(mask_val); |
| 2955 | |
| 2956 | /* |
| 2957 | * Changing affinity is mega expensive, so let's be as lazy as |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 2958 | * we can and only do it if we really have to. Also, if mapped |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 2959 | * into the proxy device, we need to move the doorbell |
| 2960 | * interrupt to its new location. |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 2961 | */ |
| 2962 | if (vpe->col_idx != cpu) { |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 2963 | int from = vpe->col_idx; |
| 2964 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 2965 | vpe->col_idx = cpu; |
| 2966 | its_send_vmovp(vpe); |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 2967 | its_vpe_db_proxy_move(vpe, from, cpu); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 2970 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
| 2971 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 2972 | return IRQ_SET_MASK_OK_DONE; |
| 2973 | } |
| 2974 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 2975 | static void its_vpe_schedule(struct its_vpe *vpe) |
| 2976 | { |
Robin Murphy | 50c3309 | 2018-02-16 16:57:56 +0000 | [diff] [blame] | 2977 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 2978 | u64 val; |
| 2979 | |
| 2980 | /* Schedule the VPE */ |
| 2981 | val = virt_to_phys(page_address(vpe->its_vm->vprop_page)) & |
| 2982 | GENMASK_ULL(51, 12); |
| 2983 | val |= (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; |
| 2984 | val |= GICR_VPROPBASER_RaWb; |
| 2985 | val |= GICR_VPROPBASER_InnerShareable; |
| 2986 | gits_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
| 2987 | |
| 2988 | val = virt_to_phys(page_address(vpe->vpt_page)) & |
| 2989 | GENMASK_ULL(51, 16); |
| 2990 | val |= GICR_VPENDBASER_RaWaWb; |
| 2991 | val |= GICR_VPENDBASER_NonShareable; |
| 2992 | /* |
| 2993 | * There is no good way of finding out if the pending table is |
| 2994 | * empty as we can race against the doorbell interrupt very |
| 2995 | * easily. So in the end, vpe->pending_last is only an |
| 2996 | * indication that the vcpu has something pending, not one |
| 2997 | * that the pending table is empty. A good implementation |
| 2998 | * would be able to read its coarse map pretty quickly anyway, |
| 2999 | * making this a tolerable issue. |
| 3000 | */ |
| 3001 | val |= GICR_VPENDBASER_PendingLast; |
| 3002 | val |= vpe->idai ? GICR_VPENDBASER_IDAI : 0; |
| 3003 | val |= GICR_VPENDBASER_Valid; |
| 3004 | gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); |
| 3005 | } |
| 3006 | |
| 3007 | static void its_vpe_deschedule(struct its_vpe *vpe) |
| 3008 | { |
Robin Murphy | 50c3309 | 2018-02-16 16:57:56 +0000 | [diff] [blame] | 3009 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3010 | u64 val; |
| 3011 | |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 3012 | val = its_clear_vpend_valid(vlpi_base); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3013 | |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 3014 | if (unlikely(val & GICR_VPENDBASER_Dirty)) { |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3015 | pr_err_ratelimited("ITS virtual pending table not cleaning\n"); |
| 3016 | vpe->idai = false; |
| 3017 | vpe->pending_last = true; |
| 3018 | } else { |
| 3019 | vpe->idai = !!(val & GICR_VPENDBASER_IDAI); |
| 3020 | vpe->pending_last = !!(val & GICR_VPENDBASER_PendingLast); |
| 3021 | } |
| 3022 | } |
| 3023 | |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3024 | static void its_vpe_invall(struct its_vpe *vpe) |
| 3025 | { |
| 3026 | struct its_node *its; |
| 3027 | |
| 3028 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3029 | if (!is_v4(its)) |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3030 | continue; |
| 3031 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 3032 | if (its_list_map && !vpe->its_vm->vlpi_count[its->list_nr]) |
| 3033 | continue; |
| 3034 | |
Marc Zyngier | 3c1ccee | 2017-10-09 13:17:43 +0100 | [diff] [blame] | 3035 | /* |
| 3036 | * Sending a VINVALL to a single ITS is enough, as all |
| 3037 | * we need is to reach the redistributors. |
| 3038 | */ |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3039 | its_send_vinvall(its, vpe); |
Marc Zyngier | 3c1ccee | 2017-10-09 13:17:43 +0100 | [diff] [blame] | 3040 | return; |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3044 | static int its_vpe_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 3045 | { |
| 3046 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3047 | struct its_cmd_info *info = vcpu_info; |
| 3048 | |
| 3049 | switch (info->cmd_type) { |
| 3050 | case SCHEDULE_VPE: |
| 3051 | its_vpe_schedule(vpe); |
| 3052 | return 0; |
| 3053 | |
| 3054 | case DESCHEDULE_VPE: |
| 3055 | its_vpe_deschedule(vpe); |
| 3056 | return 0; |
| 3057 | |
Marc Zyngier | 5e2f764 | 2016-12-20 15:10:50 +0000 | [diff] [blame] | 3058 | case INVALL_VPE: |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3059 | its_vpe_invall(vpe); |
Marc Zyngier | 5e2f764 | 2016-12-20 15:10:50 +0000 | [diff] [blame] | 3060 | return 0; |
| 3061 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3062 | default: |
| 3063 | return -EINVAL; |
| 3064 | } |
| 3065 | } |
| 3066 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3067 | static void its_vpe_send_cmd(struct its_vpe *vpe, |
| 3068 | void (*cmd)(struct its_device *, u32)) |
| 3069 | { |
| 3070 | unsigned long flags; |
| 3071 | |
| 3072 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 3073 | |
| 3074 | its_vpe_db_proxy_map_locked(vpe); |
| 3075 | cmd(vpe_proxy.dev, vpe->vpe_proxy_event); |
| 3076 | |
| 3077 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 3078 | } |
| 3079 | |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3080 | static void its_vpe_send_inv(struct irq_data *d) |
| 3081 | { |
| 3082 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3083 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3084 | if (gic_rdists->has_direct_lpi) { |
| 3085 | void __iomem *rdbase; |
| 3086 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 3087 | /* Target the redistributor this VPE is currently known on */ |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3088 | rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 3089 | gic_write_lpir(d->parent_data->hwirq, rdbase + GICR_INVLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 3090 | wait_for_syncr(rdbase); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3091 | } else { |
| 3092 | its_vpe_send_cmd(vpe, its_send_inv); |
| 3093 | } |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | static void its_vpe_mask_irq(struct irq_data *d) |
| 3097 | { |
| 3098 | /* |
| 3099 | * We need to unmask the LPI, which is described by the parent |
| 3100 | * irq_data. Instead of calling into the parent (which won't |
| 3101 | * exactly do the right thing, let's simply use the |
| 3102 | * parent_data pointer. Yes, I'm naughty. |
| 3103 | */ |
| 3104 | lpi_write_config(d->parent_data, LPI_PROP_ENABLED, 0); |
| 3105 | its_vpe_send_inv(d); |
| 3106 | } |
| 3107 | |
| 3108 | static void its_vpe_unmask_irq(struct irq_data *d) |
| 3109 | { |
| 3110 | /* Same hack as above... */ |
| 3111 | lpi_write_config(d->parent_data, 0, LPI_PROP_ENABLED); |
| 3112 | its_vpe_send_inv(d); |
| 3113 | } |
| 3114 | |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3115 | static int its_vpe_set_irqchip_state(struct irq_data *d, |
| 3116 | enum irqchip_irq_state which, |
| 3117 | bool state) |
| 3118 | { |
| 3119 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3120 | |
| 3121 | if (which != IRQCHIP_STATE_PENDING) |
| 3122 | return -EINVAL; |
| 3123 | |
| 3124 | if (gic_rdists->has_direct_lpi) { |
| 3125 | void __iomem *rdbase; |
| 3126 | |
| 3127 | rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; |
| 3128 | if (state) { |
| 3129 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_SETLPIR); |
| 3130 | } else { |
| 3131 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_CLRLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 3132 | wait_for_syncr(rdbase); |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3133 | } |
| 3134 | } else { |
| 3135 | if (state) |
| 3136 | its_vpe_send_cmd(vpe, its_send_int); |
| 3137 | else |
| 3138 | its_vpe_send_cmd(vpe, its_send_clear); |
| 3139 | } |
| 3140 | |
| 3141 | return 0; |
| 3142 | } |
| 3143 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3144 | static struct irq_chip its_vpe_irq_chip = { |
| 3145 | .name = "GICv4-vpe", |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3146 | .irq_mask = its_vpe_mask_irq, |
| 3147 | .irq_unmask = its_vpe_unmask_irq, |
| 3148 | .irq_eoi = irq_chip_eoi_parent, |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3149 | .irq_set_affinity = its_vpe_set_affinity, |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3150 | .irq_set_irqchip_state = its_vpe_set_irqchip_state, |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3151 | .irq_set_vcpu_affinity = its_vpe_set_vcpu_affinity, |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3152 | }; |
| 3153 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3154 | static int its_vpe_id_alloc(void) |
| 3155 | { |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 3156 | return ida_simple_get(&its_vpeid_ida, 0, ITS_MAX_VPEID, GFP_KERNEL); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | static void its_vpe_id_free(u16 id) |
| 3160 | { |
| 3161 | ida_simple_remove(&its_vpeid_ida, id); |
| 3162 | } |
| 3163 | |
| 3164 | static int its_vpe_init(struct its_vpe *vpe) |
| 3165 | { |
| 3166 | struct page *vpt_page; |
| 3167 | int vpe_id; |
| 3168 | |
| 3169 | /* Allocate vpe_id */ |
| 3170 | vpe_id = its_vpe_id_alloc(); |
| 3171 | if (vpe_id < 0) |
| 3172 | return vpe_id; |
| 3173 | |
| 3174 | /* Allocate VPT */ |
| 3175 | vpt_page = its_allocate_pending_table(GFP_KERNEL); |
| 3176 | if (!vpt_page) { |
| 3177 | its_vpe_id_free(vpe_id); |
| 3178 | return -ENOMEM; |
| 3179 | } |
| 3180 | |
| 3181 | if (!its_alloc_vpe_table(vpe_id)) { |
| 3182 | its_vpe_id_free(vpe_id); |
Nianyao Tang | 34f8eb9 | 2019-07-26 17:32:57 +0800 | [diff] [blame] | 3183 | its_free_pending_table(vpt_page); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3184 | return -ENOMEM; |
| 3185 | } |
| 3186 | |
| 3187 | vpe->vpe_id = vpe_id; |
| 3188 | vpe->vpt_page = vpt_page; |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3189 | vpe->vpe_proxy_event = -1; |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3190 | |
| 3191 | return 0; |
| 3192 | } |
| 3193 | |
| 3194 | static void its_vpe_teardown(struct its_vpe *vpe) |
| 3195 | { |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3196 | its_vpe_db_proxy_unmap(vpe); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3197 | its_vpe_id_free(vpe->vpe_id); |
| 3198 | its_free_pending_table(vpe->vpt_page); |
| 3199 | } |
| 3200 | |
| 3201 | static void its_vpe_irq_domain_free(struct irq_domain *domain, |
| 3202 | unsigned int virq, |
| 3203 | unsigned int nr_irqs) |
| 3204 | { |
| 3205 | struct its_vm *vm = domain->host_data; |
| 3206 | int i; |
| 3207 | |
| 3208 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 3209 | |
| 3210 | for (i = 0; i < nr_irqs; i++) { |
| 3211 | struct irq_data *data = irq_domain_get_irq_data(domain, |
| 3212 | virq + i); |
| 3213 | struct its_vpe *vpe = irq_data_get_irq_chip_data(data); |
| 3214 | |
| 3215 | BUG_ON(vm != vpe->its_vm); |
| 3216 | |
| 3217 | clear_bit(data->hwirq, vm->db_bitmap); |
| 3218 | its_vpe_teardown(vpe); |
| 3219 | irq_domain_reset_irq_data(data); |
| 3220 | } |
| 3221 | |
| 3222 | if (bitmap_empty(vm->db_bitmap, vm->nr_db_lpis)) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3223 | its_lpi_free(vm->db_bitmap, vm->db_lpi_base, vm->nr_db_lpis); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3224 | its_free_prop_table(vm->vprop_page); |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 3229 | unsigned int nr_irqs, void *args) |
| 3230 | { |
| 3231 | struct its_vm *vm = args; |
| 3232 | unsigned long *bitmap; |
| 3233 | struct page *vprop_page; |
| 3234 | int base, nr_ids, i, err = 0; |
| 3235 | |
| 3236 | BUG_ON(!vm); |
| 3237 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3238 | bitmap = its_lpi_alloc(roundup_pow_of_two(nr_irqs), &base, &nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3239 | if (!bitmap) |
| 3240 | return -ENOMEM; |
| 3241 | |
| 3242 | if (nr_ids < nr_irqs) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3243 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3244 | return -ENOMEM; |
| 3245 | } |
| 3246 | |
| 3247 | vprop_page = its_allocate_prop_table(GFP_KERNEL); |
| 3248 | if (!vprop_page) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3249 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3250 | return -ENOMEM; |
| 3251 | } |
| 3252 | |
| 3253 | vm->db_bitmap = bitmap; |
| 3254 | vm->db_lpi_base = base; |
| 3255 | vm->nr_db_lpis = nr_ids; |
| 3256 | vm->vprop_page = vprop_page; |
| 3257 | |
| 3258 | for (i = 0; i < nr_irqs; i++) { |
| 3259 | vm->vpes[i]->vpe_db_lpi = base + i; |
| 3260 | err = its_vpe_init(vm->vpes[i]); |
| 3261 | if (err) |
| 3262 | break; |
| 3263 | err = its_irq_gic_domain_alloc(domain, virq + i, |
| 3264 | vm->vpes[i]->vpe_db_lpi); |
| 3265 | if (err) |
| 3266 | break; |
| 3267 | irq_domain_set_hwirq_and_chip(domain, virq + i, i, |
| 3268 | &its_vpe_irq_chip, vm->vpes[i]); |
| 3269 | set_bit(i, bitmap); |
| 3270 | } |
| 3271 | |
| 3272 | if (err) { |
| 3273 | if (i > 0) |
| 3274 | its_vpe_irq_domain_free(domain, virq, i - 1); |
| 3275 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3276 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3277 | its_free_prop_table(vprop_page); |
| 3278 | } |
| 3279 | |
| 3280 | return err; |
| 3281 | } |
| 3282 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 3283 | static int its_vpe_irq_domain_activate(struct irq_domain *domain, |
Thomas Gleixner | 702cb0a | 2017-12-29 16:59:06 +0100 | [diff] [blame] | 3284 | struct irq_data *d, bool reserve) |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3285 | { |
| 3286 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3287 | struct its_node *its; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3288 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 3289 | /* If we use the list map, we issue VMAPP on demand... */ |
| 3290 | if (its_list_map) |
Marc Zyngier | 6ef930f | 2017-11-07 10:04:38 +0000 | [diff] [blame] | 3291 | return 0; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3292 | |
| 3293 | /* Map the VPE to the first possible CPU */ |
| 3294 | vpe->col_idx = cpumask_first(cpu_online_mask); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3295 | |
| 3296 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3297 | if (!is_v4(its)) |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3298 | continue; |
| 3299 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 3300 | its_send_vmapp(its, vpe, true); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3301 | its_send_vinvall(its, vpe); |
| 3302 | } |
| 3303 | |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 3304 | irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); |
| 3305 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 3306 | return 0; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | static void its_vpe_irq_domain_deactivate(struct irq_domain *domain, |
| 3310 | struct irq_data *d) |
| 3311 | { |
| 3312 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 3313 | struct its_node *its; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3314 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 3315 | /* |
| 3316 | * If we use the list map, we unmap the VPE once no VLPIs are |
| 3317 | * associated with the VM. |
| 3318 | */ |
| 3319 | if (its_list_map) |
| 3320 | return; |
| 3321 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 3322 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3323 | if (!is_v4(its)) |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 3324 | continue; |
| 3325 | |
| 3326 | its_send_vmapp(its, vpe, false); |
| 3327 | } |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3330 | static const struct irq_domain_ops its_vpe_domain_ops = { |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3331 | .alloc = its_vpe_irq_domain_alloc, |
| 3332 | .free = its_vpe_irq_domain_free, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 3333 | .activate = its_vpe_irq_domain_activate, |
| 3334 | .deactivate = its_vpe_irq_domain_deactivate, |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3335 | }; |
| 3336 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 3337 | static int its_force_quiescent(void __iomem *base) |
| 3338 | { |
| 3339 | u32 count = 1000000; /* 1s */ |
| 3340 | u32 val; |
| 3341 | |
| 3342 | val = readl_relaxed(base + GITS_CTLR); |
David Daney | 7611da8 | 2016-08-18 15:41:58 -0700 | [diff] [blame] | 3343 | /* |
| 3344 | * GIC architecture specification requires the ITS to be both |
| 3345 | * disabled and quiescent for writes to GITS_BASER<n> or |
| 3346 | * GITS_CBASER to not have UNPREDICTABLE results. |
| 3347 | */ |
| 3348 | if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE)) |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 3349 | return 0; |
| 3350 | |
| 3351 | /* Disable the generation of all interrupts to this ITS */ |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 3352 | val &= ~(GITS_CTLR_ENABLE | GITS_CTLR_ImDe); |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 3353 | writel_relaxed(val, base + GITS_CTLR); |
| 3354 | |
| 3355 | /* Poll GITS_CTLR and wait until ITS becomes quiescent */ |
| 3356 | while (1) { |
| 3357 | val = readl_relaxed(base + GITS_CTLR); |
| 3358 | if (val & GITS_CTLR_QUIESCENT) |
| 3359 | return 0; |
| 3360 | |
| 3361 | count--; |
| 3362 | if (!count) |
| 3363 | return -EBUSY; |
| 3364 | |
| 3365 | cpu_relax(); |
| 3366 | udelay(1); |
| 3367 | } |
| 3368 | } |
| 3369 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3370 | static bool __maybe_unused its_enable_quirk_cavium_22375(void *data) |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 3371 | { |
| 3372 | struct its_node *its = data; |
| 3373 | |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 3374 | /* erratum 22375: only alloc 8MB table size (20 bits) */ |
| 3375 | its->typer &= ~GITS_TYPER_DEVBITS; |
| 3376 | its->typer |= FIELD_PREP(GITS_TYPER_DEVBITS, 20 - 1); |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 3377 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_22375; |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3378 | |
| 3379 | return true; |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 3380 | } |
| 3381 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3382 | static bool __maybe_unused its_enable_quirk_cavium_23144(void *data) |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 3383 | { |
| 3384 | struct its_node *its = data; |
| 3385 | |
| 3386 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_23144; |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3387 | |
| 3388 | return true; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 3389 | } |
| 3390 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3391 | static bool __maybe_unused its_enable_quirk_qdf2400_e0065(void *data) |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 3392 | { |
| 3393 | struct its_node *its = data; |
| 3394 | |
| 3395 | /* On QDF2400, the size of the ITE is 16Bytes */ |
Marc Zyngier | ffedbf0 | 2019-11-08 16:57:59 +0000 | [diff] [blame] | 3396 | its->typer &= ~GITS_TYPER_ITT_ENTRY_SIZE; |
| 3397 | its->typer |= FIELD_PREP(GITS_TYPER_ITT_ENTRY_SIZE, 16 - 1); |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 3398 | |
| 3399 | return true; |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 3400 | } |
| 3401 | |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 3402 | static u64 its_irq_get_msi_base_pre_its(struct its_device *its_dev) |
| 3403 | { |
| 3404 | struct its_node *its = its_dev->its; |
| 3405 | |
| 3406 | /* |
| 3407 | * The Socionext Synquacer SoC has a so-called 'pre-ITS', |
| 3408 | * which maps 32-bit writes targeted at a separate window of |
| 3409 | * size '4 << device_id_bits' onto writes to GITS_TRANSLATER |
| 3410 | * with device ID taken from bits [device_id_bits + 1:2] of |
| 3411 | * the window offset. |
| 3412 | */ |
| 3413 | return its->pre_its_base + (its_dev->device_id << 2); |
| 3414 | } |
| 3415 | |
| 3416 | static bool __maybe_unused its_enable_quirk_socionext_synquacer(void *data) |
| 3417 | { |
| 3418 | struct its_node *its = data; |
| 3419 | u32 pre_its_window[2]; |
| 3420 | u32 ids; |
| 3421 | |
| 3422 | if (!fwnode_property_read_u32_array(its->fwnode_handle, |
| 3423 | "socionext,synquacer-pre-its", |
| 3424 | pre_its_window, |
| 3425 | ARRAY_SIZE(pre_its_window))) { |
| 3426 | |
| 3427 | its->pre_its_base = pre_its_window[0]; |
| 3428 | its->get_msi_base = its_irq_get_msi_base_pre_its; |
| 3429 | |
| 3430 | ids = ilog2(pre_its_window[1]) - 2; |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 3431 | if (device_ids(its) > ids) { |
| 3432 | its->typer &= ~GITS_TYPER_DEVBITS; |
| 3433 | its->typer |= FIELD_PREP(GITS_TYPER_DEVBITS, ids - 1); |
| 3434 | } |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 3435 | |
| 3436 | /* the pre-ITS breaks isolation, so disable MSI remapping */ |
| 3437 | its->msi_domain_flags &= ~IRQ_DOMAIN_FLAG_MSI_REMAP; |
| 3438 | return true; |
| 3439 | } |
| 3440 | return false; |
| 3441 | } |
| 3442 | |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 3443 | static bool __maybe_unused its_enable_quirk_hip07_161600802(void *data) |
| 3444 | { |
| 3445 | struct its_node *its = data; |
| 3446 | |
| 3447 | /* |
| 3448 | * Hip07 insists on using the wrong address for the VLPI |
| 3449 | * page. Trick it into doing the right thing... |
| 3450 | */ |
| 3451 | its->vlpi_redist_offset = SZ_128K; |
| 3452 | return true; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 3453 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3454 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 3455 | static const struct gic_quirk its_quirks[] = { |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 3456 | #ifdef CONFIG_CAVIUM_ERRATUM_22375 |
| 3457 | { |
| 3458 | .desc = "ITS: Cavium errata 22375, 24313", |
| 3459 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 3460 | .mask = 0xffff0fff, |
| 3461 | .init = its_enable_quirk_cavium_22375, |
| 3462 | }, |
| 3463 | #endif |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 3464 | #ifdef CONFIG_CAVIUM_ERRATUM_23144 |
| 3465 | { |
| 3466 | .desc = "ITS: Cavium erratum 23144", |
| 3467 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 3468 | .mask = 0xffff0fff, |
| 3469 | .init = its_enable_quirk_cavium_23144, |
| 3470 | }, |
| 3471 | #endif |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 3472 | #ifdef CONFIG_QCOM_QDF2400_ERRATUM_0065 |
| 3473 | { |
| 3474 | .desc = "ITS: QDF2400 erratum 0065", |
| 3475 | .iidr = 0x00001070, /* QDF2400 ITS rev 1.x */ |
| 3476 | .mask = 0xffffffff, |
| 3477 | .init = its_enable_quirk_qdf2400_e0065, |
| 3478 | }, |
| 3479 | #endif |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 3480 | #ifdef CONFIG_SOCIONEXT_SYNQUACER_PREITS |
| 3481 | { |
| 3482 | /* |
| 3483 | * The Socionext Synquacer SoC incorporates ARM's own GIC-500 |
| 3484 | * implementation, but with a 'pre-ITS' added that requires |
| 3485 | * special handling in software. |
| 3486 | */ |
| 3487 | .desc = "ITS: Socionext Synquacer pre-ITS", |
| 3488 | .iidr = 0x0001143b, |
| 3489 | .mask = 0xffffffff, |
| 3490 | .init = its_enable_quirk_socionext_synquacer, |
| 3491 | }, |
| 3492 | #endif |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 3493 | #ifdef CONFIG_HISILICON_ERRATUM_161600802 |
| 3494 | { |
| 3495 | .desc = "ITS: Hip07 erratum 161600802", |
| 3496 | .iidr = 0x00000004, |
| 3497 | .mask = 0xffffffff, |
| 3498 | .init = its_enable_quirk_hip07_161600802, |
| 3499 | }, |
| 3500 | #endif |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 3501 | { |
| 3502 | } |
| 3503 | }; |
| 3504 | |
| 3505 | static void its_enable_quirks(struct its_node *its) |
| 3506 | { |
| 3507 | u32 iidr = readl_relaxed(its->base + GITS_IIDR); |
| 3508 | |
| 3509 | gic_enable_quirks(iidr, its_quirks, its); |
| 3510 | } |
| 3511 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3512 | static int its_save_disable(void) |
| 3513 | { |
| 3514 | struct its_node *its; |
| 3515 | int err = 0; |
| 3516 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3517 | raw_spin_lock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3518 | list_for_each_entry(its, &its_nodes, entry) { |
| 3519 | void __iomem *base; |
| 3520 | |
| 3521 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 3522 | continue; |
| 3523 | |
| 3524 | base = its->base; |
| 3525 | its->ctlr_save = readl_relaxed(base + GITS_CTLR); |
| 3526 | err = its_force_quiescent(base); |
| 3527 | if (err) { |
| 3528 | pr_err("ITS@%pa: failed to quiesce: %d\n", |
| 3529 | &its->phys_base, err); |
| 3530 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
| 3531 | goto err; |
| 3532 | } |
| 3533 | |
| 3534 | its->cbaser_save = gits_read_cbaser(base + GITS_CBASER); |
| 3535 | } |
| 3536 | |
| 3537 | err: |
| 3538 | if (err) { |
| 3539 | list_for_each_entry_continue_reverse(its, &its_nodes, entry) { |
| 3540 | void __iomem *base; |
| 3541 | |
| 3542 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 3543 | continue; |
| 3544 | |
| 3545 | base = its->base; |
| 3546 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
| 3547 | } |
| 3548 | } |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3549 | raw_spin_unlock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3550 | |
| 3551 | return err; |
| 3552 | } |
| 3553 | |
| 3554 | static void its_restore_enable(void) |
| 3555 | { |
| 3556 | struct its_node *its; |
| 3557 | int ret; |
| 3558 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3559 | raw_spin_lock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3560 | list_for_each_entry(its, &its_nodes, entry) { |
| 3561 | void __iomem *base; |
| 3562 | int i; |
| 3563 | |
| 3564 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 3565 | continue; |
| 3566 | |
| 3567 | base = its->base; |
| 3568 | |
| 3569 | /* |
| 3570 | * Make sure that the ITS is disabled. If it fails to quiesce, |
| 3571 | * don't restore it since writing to CBASER or BASER<n> |
| 3572 | * registers is undefined according to the GIC v3 ITS |
| 3573 | * Specification. |
| 3574 | */ |
| 3575 | ret = its_force_quiescent(base); |
| 3576 | if (ret) { |
| 3577 | pr_err("ITS@%pa: failed to quiesce on resume: %d\n", |
| 3578 | &its->phys_base, ret); |
| 3579 | continue; |
| 3580 | } |
| 3581 | |
| 3582 | gits_write_cbaser(its->cbaser_save, base + GITS_CBASER); |
| 3583 | |
| 3584 | /* |
| 3585 | * Writing CBASER resets CREADR to 0, so make CWRITER and |
| 3586 | * cmd_write line up with it. |
| 3587 | */ |
| 3588 | its->cmd_write = its->cmd_base; |
| 3589 | gits_write_cwriter(0, base + GITS_CWRITER); |
| 3590 | |
| 3591 | /* Restore GITS_BASER from the value cache. */ |
| 3592 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
| 3593 | struct its_baser *baser = &its->tables[i]; |
| 3594 | |
| 3595 | if (!(baser->val & GITS_BASER_VALID)) |
| 3596 | continue; |
| 3597 | |
| 3598 | its_write_baser(its, baser, baser->val); |
| 3599 | } |
| 3600 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3601 | |
| 3602 | /* |
| 3603 | * Reinit the collection if it's stored in the ITS. This is |
| 3604 | * indicated by the col_id being less than the HCC field. |
| 3605 | * CID < HCC as specified in the GIC v3 Documentation. |
| 3606 | */ |
| 3607 | if (its->collections[smp_processor_id()].col_id < |
| 3608 | GITS_TYPER_HCC(gic_read_typer(base + GITS_TYPER))) |
| 3609 | its_cpu_init_collection(its); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3610 | } |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3611 | raw_spin_unlock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | static struct syscore_ops its_syscore_ops = { |
| 3615 | .suspend = its_save_disable, |
| 3616 | .resume = its_restore_enable, |
| 3617 | }; |
| 3618 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3619 | static int its_init_domain(struct fwnode_handle *handle, struct its_node *its) |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3620 | { |
| 3621 | struct irq_domain *inner_domain; |
| 3622 | struct msi_domain_info *info; |
| 3623 | |
| 3624 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 3625 | if (!info) |
| 3626 | return -ENOMEM; |
| 3627 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3628 | inner_domain = irq_domain_create_tree(handle, &its_domain_ops, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3629 | if (!inner_domain) { |
| 3630 | kfree(info); |
| 3631 | return -ENOMEM; |
| 3632 | } |
| 3633 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3634 | inner_domain->parent = its_parent; |
Marc Zyngier | 96f0d93 | 2017-06-22 11:42:50 +0100 | [diff] [blame] | 3635 | irq_domain_update_bus_token(inner_domain, DOMAIN_BUS_NEXUS); |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 3636 | inner_domain->flags |= its->msi_domain_flags; |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3637 | info->ops = &its_msi_domain_ops; |
| 3638 | info->data = its; |
| 3639 | inner_domain->host_data = info; |
| 3640 | |
| 3641 | return 0; |
| 3642 | } |
| 3643 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3644 | static int its_init_vpe_domain(void) |
| 3645 | { |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3646 | struct its_node *its; |
| 3647 | u32 devid; |
| 3648 | int entries; |
| 3649 | |
| 3650 | if (gic_rdists->has_direct_lpi) { |
| 3651 | pr_info("ITS: Using DirectLPI for VPE invalidation\n"); |
| 3652 | return 0; |
| 3653 | } |
| 3654 | |
| 3655 | /* Any ITS will do, even if not v4 */ |
| 3656 | its = list_first_entry(&its_nodes, struct its_node, entry); |
| 3657 | |
| 3658 | entries = roundup_pow_of_two(nr_cpu_ids); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3659 | vpe_proxy.vpes = kcalloc(entries, sizeof(*vpe_proxy.vpes), |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3660 | GFP_KERNEL); |
| 3661 | if (!vpe_proxy.vpes) { |
| 3662 | pr_err("ITS: Can't allocate GICv4 proxy device array\n"); |
| 3663 | return -ENOMEM; |
| 3664 | } |
| 3665 | |
| 3666 | /* Use the last possible DevID */ |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 3667 | devid = GENMASK(device_ids(its) - 1, 0); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3668 | vpe_proxy.dev = its_create_device(its, devid, entries, false); |
| 3669 | if (!vpe_proxy.dev) { |
| 3670 | kfree(vpe_proxy.vpes); |
| 3671 | pr_err("ITS: Can't allocate GICv4 proxy device\n"); |
| 3672 | return -ENOMEM; |
| 3673 | } |
| 3674 | |
Shanker Donthineni | c427a47 | 2017-09-23 13:50:19 -0500 | [diff] [blame] | 3675 | BUG_ON(entries > vpe_proxy.dev->nr_ites); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3676 | |
| 3677 | raw_spin_lock_init(&vpe_proxy.lock); |
| 3678 | vpe_proxy.next_victim = 0; |
| 3679 | pr_info("ITS: Allocated DevID %x as GICv4 proxy device (%d slots)\n", |
| 3680 | devid, vpe_proxy.dev->nr_ites); |
| 3681 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3682 | return 0; |
| 3683 | } |
| 3684 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3685 | static int __init its_compute_its_list_map(struct resource *res, |
| 3686 | void __iomem *its_base) |
| 3687 | { |
| 3688 | int its_number; |
| 3689 | u32 ctlr; |
| 3690 | |
| 3691 | /* |
| 3692 | * This is assumed to be done early enough that we're |
| 3693 | * guaranteed to be single-threaded, hence no |
| 3694 | * locking. Should this change, we should address |
| 3695 | * this. |
| 3696 | */ |
Marc Zyngier | ab60491 | 2017-10-08 18:48:06 +0100 | [diff] [blame] | 3697 | its_number = find_first_zero_bit(&its_list_map, GICv4_ITS_LIST_MAX); |
| 3698 | if (its_number >= GICv4_ITS_LIST_MAX) { |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3699 | pr_err("ITS@%pa: No ITSList entry available!\n", |
| 3700 | &res->start); |
| 3701 | return -EINVAL; |
| 3702 | } |
| 3703 | |
| 3704 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 3705 | ctlr &= ~GITS_CTLR_ITS_NUMBER; |
| 3706 | ctlr |= its_number << GITS_CTLR_ITS_NUMBER_SHIFT; |
| 3707 | writel_relaxed(ctlr, its_base + GITS_CTLR); |
| 3708 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 3709 | if ((ctlr & GITS_CTLR_ITS_NUMBER) != (its_number << GITS_CTLR_ITS_NUMBER_SHIFT)) { |
| 3710 | its_number = ctlr & GITS_CTLR_ITS_NUMBER; |
| 3711 | its_number >>= GITS_CTLR_ITS_NUMBER_SHIFT; |
| 3712 | } |
| 3713 | |
| 3714 | if (test_and_set_bit(its_number, &its_list_map)) { |
| 3715 | pr_err("ITS@%pa: Duplicate ITSList entry %d\n", |
| 3716 | &res->start, its_number); |
| 3717 | return -EINVAL; |
| 3718 | } |
| 3719 | |
| 3720 | return its_number; |
| 3721 | } |
| 3722 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3723 | static int __init its_probe_one(struct resource *res, |
| 3724 | struct fwnode_handle *handle, int numa_node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3725 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3726 | struct its_node *its; |
| 3727 | void __iomem *its_base; |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3728 | u32 val, ctlr; |
| 3729 | u64 baser, tmp, typer; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3730 | struct page *page; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3731 | int err; |
| 3732 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3733 | its_base = ioremap(res->start, resource_size(res)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3734 | if (!its_base) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3735 | pr_warn("ITS@%pa: Unable to map ITS registers\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3736 | return -ENOMEM; |
| 3737 | } |
| 3738 | |
| 3739 | val = readl_relaxed(its_base + GITS_PIDR2) & GIC_PIDR2_ARCH_MASK; |
| 3740 | if (val != 0x30 && val != 0x40) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3741 | pr_warn("ITS@%pa: No ITS detected, giving up\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3742 | err = -ENODEV; |
| 3743 | goto out_unmap; |
| 3744 | } |
| 3745 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 3746 | err = its_force_quiescent(its_base); |
| 3747 | if (err) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3748 | pr_warn("ITS@%pa: Failed to quiesce, giving up\n", &res->start); |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 3749 | goto out_unmap; |
| 3750 | } |
| 3751 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3752 | pr_info("ITS %pR\n", res); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3753 | |
| 3754 | its = kzalloc(sizeof(*its), GFP_KERNEL); |
| 3755 | if (!its) { |
| 3756 | err = -ENOMEM; |
| 3757 | goto out_unmap; |
| 3758 | } |
| 3759 | |
| 3760 | raw_spin_lock_init(&its->lock); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3761 | mutex_init(&its->dev_alloc_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3762 | INIT_LIST_HEAD(&its->entry); |
| 3763 | INIT_LIST_HEAD(&its->its_device_list); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3764 | typer = gic_read_typer(its_base + GITS_TYPER); |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3765 | its->typer = typer; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3766 | its->base = its_base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3767 | its->phys_base = res->start; |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3768 | if (is_v4(its)) { |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3769 | if (!(typer & GITS_TYPER_VMOVP)) { |
| 3770 | err = its_compute_its_list_map(res, its_base); |
| 3771 | if (err < 0) |
| 3772 | goto out_free_its; |
| 3773 | |
Marc Zyngier | debf6d0 | 2017-10-08 18:44:42 +0100 | [diff] [blame] | 3774 | its->list_nr = err; |
| 3775 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3776 | pr_info("ITS@%pa: Using ITS number %d\n", |
| 3777 | &res->start, err); |
| 3778 | } else { |
| 3779 | pr_info("ITS@%pa: Single VMOVP capable\n", &res->start); |
| 3780 | } |
| 3781 | } |
| 3782 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3783 | its->numa_node = numa_node; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3784 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3785 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, |
| 3786 | get_order(ITS_CMD_QUEUE_SZ)); |
| 3787 | if (!page) { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3788 | err = -ENOMEM; |
| 3789 | goto out_free_its; |
| 3790 | } |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3791 | its->cmd_base = (void *)page_address(page); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3792 | its->cmd_write = its->cmd_base; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 3793 | its->fwnode_handle = handle; |
| 3794 | its->get_msi_base = its_irq_get_msi_base; |
| 3795 | its->msi_domain_flags = IRQ_DOMAIN_FLAG_MSI_REMAP; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3796 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 3797 | its_enable_quirks(its); |
| 3798 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 3799 | err = its_alloc_tables(its); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3800 | if (err) |
| 3801 | goto out_free_cmd; |
| 3802 | |
| 3803 | err = its_alloc_collections(its); |
| 3804 | if (err) |
| 3805 | goto out_free_tables; |
| 3806 | |
| 3807 | baser = (virt_to_phys(its->cmd_base) | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 3808 | GITS_CBASER_RaWaWb | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3809 | GITS_CBASER_InnerShareable | |
| 3810 | (ITS_CMD_QUEUE_SZ / SZ_4K - 1) | |
| 3811 | GITS_CBASER_VALID); |
| 3812 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 3813 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
| 3814 | tmp = gits_read_cbaser(its->base + GITS_CBASER); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3815 | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 3816 | if ((tmp ^ baser) & GITS_CBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 3817 | if (!(tmp & GITS_CBASER_SHAREABILITY_MASK)) { |
| 3818 | /* |
| 3819 | * The HW reports non-shareable, we must |
| 3820 | * remove the cacheability attributes as |
| 3821 | * well. |
| 3822 | */ |
| 3823 | baser &= ~(GITS_CBASER_SHAREABILITY_MASK | |
| 3824 | GITS_CBASER_CACHEABILITY_MASK); |
| 3825 | baser |= GITS_CBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 3826 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 3827 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3828 | pr_info("ITS: using cache flushing for cmd queue\n"); |
| 3829 | its->flags |= ITS_FLAGS_CMDQ_NEEDS_FLUSHING; |
| 3830 | } |
| 3831 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 3832 | gits_write_cwriter(0, its->base + GITS_CWRITER); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 3833 | ctlr = readl_relaxed(its->base + GITS_CTLR); |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 3834 | ctlr |= GITS_CTLR_ENABLE; |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3835 | if (is_v4(its)) |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 3836 | ctlr |= GITS_CTLR_ImDe; |
| 3837 | writel_relaxed(ctlr, its->base + GITS_CTLR); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 3838 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 3839 | if (GITS_TYPER_HCC(typer)) |
| 3840 | its->flags |= ITS_FLAGS_SAVE_SUSPEND_STATE; |
| 3841 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3842 | err = its_init_domain(handle, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3843 | if (err) |
| 3844 | goto out_free_tables; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3845 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3846 | raw_spin_lock(&its_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3847 | list_add(&its->entry, &its_nodes); |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3848 | raw_spin_unlock(&its_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3849 | |
| 3850 | return 0; |
| 3851 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3852 | out_free_tables: |
| 3853 | its_free_tables(its); |
| 3854 | out_free_cmd: |
Robert Richter | 5bc13c2 | 2017-02-01 18:38:25 +0100 | [diff] [blame] | 3855 | free_pages((unsigned long)its->cmd_base, get_order(ITS_CMD_QUEUE_SZ)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3856 | out_free_its: |
| 3857 | kfree(its); |
| 3858 | out_unmap: |
| 3859 | iounmap(its_base); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3860 | pr_err("ITS@%pa: failed probing (%d)\n", &res->start, err); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3861 | return err; |
| 3862 | } |
| 3863 | |
| 3864 | static bool gic_rdists_supports_plpis(void) |
| 3865 | { |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 3866 | return !!(gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER) & GICR_TYPER_PLPIS); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Shanker Donthineni | 6eb486b | 2018-03-21 20:58:49 -0500 | [diff] [blame] | 3869 | static int redist_disable_lpis(void) |
| 3870 | { |
| 3871 | void __iomem *rbase = gic_data_rdist_rd_base(); |
| 3872 | u64 timeout = USEC_PER_SEC; |
| 3873 | u64 val; |
| 3874 | |
| 3875 | if (!gic_rdists_supports_plpis()) { |
| 3876 | pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); |
| 3877 | return -ENXIO; |
| 3878 | } |
| 3879 | |
| 3880 | val = readl_relaxed(rbase + GICR_CTLR); |
| 3881 | if (!(val & GICR_CTLR_ENABLE_LPIS)) |
| 3882 | return 0; |
| 3883 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 3884 | /* |
| 3885 | * If coming via a CPU hotplug event, we don't need to disable |
| 3886 | * LPIs before trying to re-enable them. They are already |
| 3887 | * configured and all is well in the world. |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 3888 | * |
| 3889 | * If running with preallocated tables, there is nothing to do. |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 3890 | */ |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 3891 | if (gic_data_rdist()->lpi_enabled || |
| 3892 | (gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED)) |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 3893 | return 0; |
| 3894 | |
| 3895 | /* |
| 3896 | * From that point on, we only try to do some damage control. |
| 3897 | */ |
| 3898 | pr_warn("GICv3: CPU%d: Booted with LPIs enabled, memory probably corrupted\n", |
Shanker Donthineni | 6eb486b | 2018-03-21 20:58:49 -0500 | [diff] [blame] | 3899 | smp_processor_id()); |
| 3900 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 3901 | |
| 3902 | /* Disable LPIs */ |
| 3903 | val &= ~GICR_CTLR_ENABLE_LPIS; |
| 3904 | writel_relaxed(val, rbase + GICR_CTLR); |
| 3905 | |
| 3906 | /* Make sure any change to GICR_CTLR is observable by the GIC */ |
| 3907 | dsb(sy); |
| 3908 | |
| 3909 | /* |
| 3910 | * Software must observe RWP==0 after clearing GICR_CTLR.EnableLPIs |
| 3911 | * from 1 to 0 before programming GICR_PEND{PROP}BASER registers. |
| 3912 | * Error out if we time out waiting for RWP to clear. |
| 3913 | */ |
| 3914 | while (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_RWP) { |
| 3915 | if (!timeout) { |
| 3916 | pr_err("CPU%d: Timeout while disabling LPIs\n", |
| 3917 | smp_processor_id()); |
| 3918 | return -ETIMEDOUT; |
| 3919 | } |
| 3920 | udelay(1); |
| 3921 | timeout--; |
| 3922 | } |
| 3923 | |
| 3924 | /* |
| 3925 | * After it has been written to 1, it is IMPLEMENTATION |
| 3926 | * DEFINED whether GICR_CTLR.EnableLPI becomes RES1 or can be |
| 3927 | * cleared to 0. Error out if clearing the bit failed. |
| 3928 | */ |
| 3929 | if (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_ENABLE_LPIS) { |
| 3930 | pr_err("CPU%d: Failed to disable LPIs\n", smp_processor_id()); |
| 3931 | return -EBUSY; |
| 3932 | } |
| 3933 | |
| 3934 | return 0; |
| 3935 | } |
| 3936 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3937 | int its_cpu_init(void) |
| 3938 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3939 | if (!list_empty(&its_nodes)) { |
Shanker Donthineni | 6eb486b | 2018-03-21 20:58:49 -0500 | [diff] [blame] | 3940 | int ret; |
| 3941 | |
| 3942 | ret = redist_disable_lpis(); |
| 3943 | if (ret) |
| 3944 | return ret; |
| 3945 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3946 | its_cpu_init_lpis(); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3947 | its_cpu_init_collections(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | return 0; |
| 3951 | } |
| 3952 | |
Arvind Yadav | 935bba7 | 2017-06-22 16:05:30 +0530 | [diff] [blame] | 3953 | static const struct of_device_id its_device_id[] = { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3954 | { .compatible = "arm,gic-v3-its", }, |
| 3955 | {}, |
| 3956 | }; |
| 3957 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3958 | static int __init its_of_probe(struct device_node *node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3959 | { |
| 3960 | struct device_node *np; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3961 | struct resource res; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3962 | |
| 3963 | for (np = of_find_matching_node(node, its_device_id); np; |
| 3964 | np = of_find_matching_node(np, its_device_id)) { |
Stephen Boyd | 95a2562 | 2018-02-01 09:03:29 -0800 | [diff] [blame] | 3965 | if (!of_device_is_available(np)) |
| 3966 | continue; |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3967 | if (!of_property_read_bool(np, "msi-controller")) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 3968 | pr_warn("%pOF: no msi-controller property, ITS ignored\n", |
| 3969 | np); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 3970 | continue; |
| 3971 | } |
| 3972 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3973 | if (of_address_to_resource(np, 0, &res)) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 3974 | pr_warn("%pOF: no regs?\n", np); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3975 | continue; |
| 3976 | } |
| 3977 | |
| 3978 | its_probe_one(&res, &np->fwnode, of_node_to_nid(np)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3979 | } |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 3980 | return 0; |
| 3981 | } |
| 3982 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 3983 | #ifdef CONFIG_ACPI |
| 3984 | |
| 3985 | #define ACPI_GICV3_ITS_MEM_SIZE (SZ_128K) |
| 3986 | |
Robert Richter | d1ce263 | 2017-07-12 15:25:09 +0200 | [diff] [blame] | 3987 | #ifdef CONFIG_ACPI_NUMA |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 3988 | struct its_srat_map { |
| 3989 | /* numa node id */ |
| 3990 | u32 numa_node; |
| 3991 | /* GIC ITS ID */ |
| 3992 | u32 its_id; |
| 3993 | }; |
| 3994 | |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 3995 | static struct its_srat_map *its_srat_maps __initdata; |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 3996 | static int its_in_srat __initdata; |
| 3997 | |
| 3998 | static int __init acpi_get_its_numa_node(u32 its_id) |
| 3999 | { |
| 4000 | int i; |
| 4001 | |
| 4002 | for (i = 0; i < its_in_srat; i++) { |
| 4003 | if (its_id == its_srat_maps[i].its_id) |
| 4004 | return its_srat_maps[i].numa_node; |
| 4005 | } |
| 4006 | return NUMA_NO_NODE; |
| 4007 | } |
| 4008 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 4009 | static int __init gic_acpi_match_srat_its(union acpi_subtable_headers *header, |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4010 | const unsigned long end) |
| 4011 | { |
| 4012 | return 0; |
| 4013 | } |
| 4014 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 4015 | static int __init gic_acpi_parse_srat_its(union acpi_subtable_headers *header, |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4016 | const unsigned long end) |
| 4017 | { |
| 4018 | int node; |
| 4019 | struct acpi_srat_gic_its_affinity *its_affinity; |
| 4020 | |
| 4021 | its_affinity = (struct acpi_srat_gic_its_affinity *)header; |
| 4022 | if (!its_affinity) |
| 4023 | return -EINVAL; |
| 4024 | |
| 4025 | if (its_affinity->header.length < sizeof(*its_affinity)) { |
| 4026 | pr_err("SRAT: Invalid header length %d in ITS affinity\n", |
| 4027 | its_affinity->header.length); |
| 4028 | return -EINVAL; |
| 4029 | } |
| 4030 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4031 | node = acpi_map_pxm_to_node(its_affinity->proximity_domain); |
| 4032 | |
| 4033 | if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) { |
| 4034 | pr_err("SRAT: Invalid NUMA node %d in ITS affinity\n", node); |
| 4035 | return 0; |
| 4036 | } |
| 4037 | |
| 4038 | its_srat_maps[its_in_srat].numa_node = node; |
| 4039 | its_srat_maps[its_in_srat].its_id = its_affinity->its_id; |
| 4040 | its_in_srat++; |
| 4041 | pr_info("SRAT: PXM %d -> ITS %d -> Node %d\n", |
| 4042 | its_affinity->proximity_domain, its_affinity->its_id, node); |
| 4043 | |
| 4044 | return 0; |
| 4045 | } |
| 4046 | |
| 4047 | static void __init acpi_table_parse_srat_its(void) |
| 4048 | { |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4049 | int count; |
| 4050 | |
| 4051 | count = acpi_table_parse_entries(ACPI_SIG_SRAT, |
| 4052 | sizeof(struct acpi_table_srat), |
| 4053 | ACPI_SRAT_TYPE_GIC_ITS_AFFINITY, |
| 4054 | gic_acpi_match_srat_its, 0); |
| 4055 | if (count <= 0) |
| 4056 | return; |
| 4057 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 4058 | its_srat_maps = kmalloc_array(count, sizeof(struct its_srat_map), |
| 4059 | GFP_KERNEL); |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4060 | if (!its_srat_maps) { |
| 4061 | pr_warn("SRAT: Failed to allocate memory for its_srat_maps!\n"); |
| 4062 | return; |
| 4063 | } |
| 4064 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4065 | acpi_table_parse_entries(ACPI_SIG_SRAT, |
| 4066 | sizeof(struct acpi_table_srat), |
| 4067 | ACPI_SRAT_TYPE_GIC_ITS_AFFINITY, |
| 4068 | gic_acpi_parse_srat_its, 0); |
| 4069 | } |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4070 | |
| 4071 | /* free the its_srat_maps after ITS probing */ |
| 4072 | static void __init acpi_its_srat_maps_free(void) |
| 4073 | { |
| 4074 | kfree(its_srat_maps); |
| 4075 | } |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4076 | #else |
| 4077 | static void __init acpi_table_parse_srat_its(void) { } |
| 4078 | static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; } |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4079 | static void __init acpi_its_srat_maps_free(void) { } |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4080 | #endif |
| 4081 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 4082 | static int __init gic_acpi_parse_madt_its(union acpi_subtable_headers *header, |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4083 | const unsigned long end) |
| 4084 | { |
| 4085 | struct acpi_madt_generic_translator *its_entry; |
| 4086 | struct fwnode_handle *dom_handle; |
| 4087 | struct resource res; |
| 4088 | int err; |
| 4089 | |
| 4090 | its_entry = (struct acpi_madt_generic_translator *)header; |
| 4091 | memset(&res, 0, sizeof(res)); |
| 4092 | res.start = its_entry->base_address; |
| 4093 | res.end = its_entry->base_address + ACPI_GICV3_ITS_MEM_SIZE - 1; |
| 4094 | res.flags = IORESOURCE_MEM; |
| 4095 | |
Marc Zyngier | 5778cc7 | 2019-07-31 16:13:42 +0100 | [diff] [blame] | 4096 | dom_handle = irq_domain_alloc_fwnode(&res.start); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4097 | if (!dom_handle) { |
| 4098 | pr_err("ITS@%pa: Unable to allocate GICv3 ITS domain token\n", |
| 4099 | &res.start); |
| 4100 | return -ENOMEM; |
| 4101 | } |
| 4102 | |
Shameer Kolothum | 8b4282e | 2018-02-13 15:20:50 +0000 | [diff] [blame] | 4103 | err = iort_register_domain_token(its_entry->translation_id, res.start, |
| 4104 | dom_handle); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4105 | if (err) { |
| 4106 | pr_err("ITS@%pa: Unable to register GICv3 ITS domain token (ITS ID %d) to IORT\n", |
| 4107 | &res.start, its_entry->translation_id); |
| 4108 | goto dom_err; |
| 4109 | } |
| 4110 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4111 | err = its_probe_one(&res, dom_handle, |
| 4112 | acpi_get_its_numa_node(its_entry->translation_id)); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4113 | if (!err) |
| 4114 | return 0; |
| 4115 | |
| 4116 | iort_deregister_domain_token(its_entry->translation_id); |
| 4117 | dom_err: |
| 4118 | irq_domain_free_fwnode(dom_handle); |
| 4119 | return err; |
| 4120 | } |
| 4121 | |
| 4122 | static void __init its_acpi_probe(void) |
| 4123 | { |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 4124 | acpi_table_parse_srat_its(); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4125 | acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR, |
| 4126 | gic_acpi_parse_madt_its, 0); |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 4127 | acpi_its_srat_maps_free(); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4128 | } |
| 4129 | #else |
| 4130 | static void __init its_acpi_probe(void) { } |
| 4131 | #endif |
| 4132 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4133 | int __init its_init(struct fwnode_handle *handle, struct rdists *rdists, |
| 4134 | struct irq_domain *parent_domain) |
| 4135 | { |
| 4136 | struct device_node *of_node; |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4137 | struct its_node *its; |
| 4138 | bool has_v4 = false; |
| 4139 | int err; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4140 | |
| 4141 | its_parent = parent_domain; |
| 4142 | of_node = to_of_node(handle); |
| 4143 | if (of_node) |
| 4144 | its_of_probe(of_node); |
| 4145 | else |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 4146 | its_acpi_probe(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4147 | |
| 4148 | if (list_empty(&its_nodes)) { |
| 4149 | pr_warn("ITS: No ITS available, not enabling LPIs\n"); |
| 4150 | return -ENXIO; |
| 4151 | } |
| 4152 | |
| 4153 | gic_rdists = rdists; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 4154 | |
| 4155 | err = allocate_lpi_tables(); |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4156 | if (err) |
| 4157 | return err; |
| 4158 | |
| 4159 | list_for_each_entry(its, &its_nodes, entry) |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4160 | has_v4 |= is_v4(its); |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4161 | |
| 4162 | if (has_v4 & rdists->has_vlpis) { |
Marc Zyngier | 3d63cb5 | 2016-12-20 15:31:54 +0000 | [diff] [blame] | 4163 | if (its_init_vpe_domain() || |
| 4164 | its_init_v4(parent_domain, &its_vpe_domain_ops)) { |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4165 | rdists->has_vlpis = false; |
| 4166 | pr_err("ITS: Disabling GICv4 support\n"); |
| 4167 | } |
| 4168 | } |
| 4169 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4170 | register_syscore_ops(&its_syscore_ops); |
| 4171 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4172 | return 0; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4173 | } |