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; |
Marc Zyngier | 5e46a48 | 2020-03-04 20:33:14 +0000 | [diff] [blame] | 99 | void __iomem *sgir_base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 100 | phys_addr_t phys_base; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 101 | struct its_cmd_block *cmd_base; |
| 102 | struct its_cmd_block *cmd_write; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 103 | struct its_baser tables[GITS_BASER_NR_REGS]; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 104 | struct its_collection *collections; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 105 | struct fwnode_handle *fwnode_handle; |
| 106 | u64 (*get_msi_base)(struct its_device *its_dev); |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 107 | u64 typer; |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 108 | u64 cbaser_save; |
| 109 | u32 ctlr_save; |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 110 | u32 mpidr; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 111 | struct list_head its_device_list; |
| 112 | u64 flags; |
Marc Zyngier | debf6d0 | 2017-10-08 18:44:42 +0100 | [diff] [blame] | 113 | unsigned long list_nr; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 114 | int numa_node; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 115 | unsigned int msi_domain_flags; |
| 116 | u32 pre_its_base; /* for Socionext Synquacer */ |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 117 | int vlpi_redist_offset; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 120 | #define is_v4(its) (!!((its)->typer & GITS_TYPER_VLPIS)) |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 121 | #define is_v4_1(its) (!!((its)->typer & GITS_TYPER_VMAPP)) |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 122 | #define device_ids(its) (FIELD_GET(GITS_TYPER_DEVBITS, (its)->typer) + 1) |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 123 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 124 | #define ITS_ITT_ALIGN SZ_256 |
| 125 | |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 126 | /* The maximum number of VPEID bits supported by VLPI commands */ |
Marc Zyngier | f2d8340 | 2019-12-24 11:10:25 +0000 | [diff] [blame] | 127 | #define ITS_MAX_VPEID_BITS \ |
| 128 | ({ \ |
| 129 | int nvpeid = 16; \ |
| 130 | if (gic_rdists->has_rvpeid && \ |
| 131 | gic_rdists->gicd_typer2 & GICD_TYPER2_VIL) \ |
| 132 | nvpeid = 1 + (gic_rdists->gicd_typer2 & \ |
| 133 | GICD_TYPER2_VID); \ |
| 134 | \ |
| 135 | nvpeid; \ |
| 136 | }) |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 137 | #define ITS_MAX_VPEID (1 << (ITS_MAX_VPEID_BITS)) |
| 138 | |
Shanker Donthineni | 2eca0d6 | 2016-02-16 18:00:36 -0600 | [diff] [blame] | 139 | /* Convert page order to size in bytes */ |
| 140 | #define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o)) |
| 141 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 142 | struct event_lpi_map { |
| 143 | unsigned long *lpi_map; |
| 144 | u16 *col_map; |
| 145 | irq_hw_number_t lpi_base; |
| 146 | int nr_lpis; |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 147 | raw_spinlock_t vlpi_lock; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 148 | struct its_vm *vm; |
| 149 | struct its_vlpi_map *vlpi_maps; |
| 150 | int nr_vlpis; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 151 | }; |
| 152 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 153 | /* |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 154 | * The ITS view of a device - belongs to an ITS, owns an interrupt |
| 155 | * translation table, and a list of interrupts. If it some of its |
| 156 | * LPIs are injected into a guest (GICv4), the event_map.vm field |
| 157 | * indicates which one. |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 158 | */ |
| 159 | struct its_device { |
| 160 | struct list_head entry; |
| 161 | struct its_node *its; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 162 | struct event_lpi_map event_map; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 163 | void *itt; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 164 | u32 nr_ites; |
| 165 | u32 device_id; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 166 | bool shared; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 169 | static struct { |
| 170 | raw_spinlock_t lock; |
| 171 | struct its_device *dev; |
| 172 | struct its_vpe **vpes; |
| 173 | int next_victim; |
| 174 | } vpe_proxy; |
| 175 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 176 | static LIST_HEAD(its_nodes); |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 177 | static DEFINE_RAW_SPINLOCK(its_lock); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 178 | static struct rdists *gic_rdists; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 179 | static struct irq_domain *its_parent; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 180 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 181 | static unsigned long its_list_map; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 182 | static u16 vmovp_seq_num; |
| 183 | static DEFINE_RAW_SPINLOCK(vmovp_lock); |
| 184 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 185 | static DEFINE_IDA(its_vpeid_ida); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 186 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 187 | #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist)) |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 188 | #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] | 189 | #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 190 | #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] | 191 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 192 | /* |
| 193 | * Skip ITSs that have no vLPIs mapped, unless we're on GICv4.1, as we |
| 194 | * always have vSGIs mapped. |
| 195 | */ |
| 196 | static bool require_its_list_vmovp(struct its_vm *vm, struct its_node *its) |
| 197 | { |
| 198 | return (gic_rdists->has_rvpeid || vm->vlpi_count[its->list_nr]); |
| 199 | } |
| 200 | |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 201 | static u16 get_its_list(struct its_vm *vm) |
| 202 | { |
| 203 | struct its_node *its; |
| 204 | unsigned long its_list = 0; |
| 205 | |
| 206 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 207 | if (!is_v4(its)) |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 208 | continue; |
| 209 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 210 | if (require_its_list_vmovp(vm, its)) |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 211 | __set_bit(its->list_nr, &its_list); |
| 212 | } |
| 213 | |
| 214 | return (u16)its_list; |
| 215 | } |
| 216 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 217 | static inline u32 its_get_event_id(struct irq_data *d) |
| 218 | { |
| 219 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 220 | return d->hwirq - its_dev->event_map.lpi_base; |
| 221 | } |
| 222 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 223 | static struct its_collection *dev_event_to_col(struct its_device *its_dev, |
| 224 | u32 event) |
| 225 | { |
| 226 | struct its_node *its = its_dev->its; |
| 227 | |
| 228 | return its->collections + its_dev->event_map.col_map[event]; |
| 229 | } |
| 230 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 231 | static struct its_vlpi_map *dev_event_to_vlpi_map(struct its_device *its_dev, |
| 232 | u32 event) |
| 233 | { |
| 234 | if (WARN_ON_ONCE(event >= its_dev->event_map.nr_lpis)) |
| 235 | return NULL; |
| 236 | |
| 237 | return &its_dev->event_map.vlpi_maps[event]; |
| 238 | } |
| 239 | |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 240 | static struct its_vlpi_map *get_vlpi_map(struct irq_data *d) |
| 241 | { |
| 242 | if (irqd_is_forwarded_to_vcpu(d)) { |
| 243 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 244 | u32 event = its_get_event_id(d); |
| 245 | |
| 246 | return dev_event_to_vlpi_map(its_dev, event); |
| 247 | } |
| 248 | |
| 249 | return NULL; |
| 250 | } |
| 251 | |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 252 | static int vpe_to_cpuid_lock(struct its_vpe *vpe, unsigned long *flags) |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 253 | { |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 254 | raw_spin_lock_irqsave(&vpe->vpe_lock, *flags); |
| 255 | return vpe->col_idx; |
| 256 | } |
| 257 | |
| 258 | static void vpe_to_cpuid_unlock(struct its_vpe *vpe, unsigned long flags) |
| 259 | { |
| 260 | raw_spin_unlock_irqrestore(&vpe->vpe_lock, flags); |
| 261 | } |
| 262 | |
| 263 | static int irq_to_cpuid_lock(struct irq_data *d, unsigned long *flags) |
| 264 | { |
| 265 | struct its_vlpi_map *map = get_vlpi_map(d); |
| 266 | int cpu; |
| 267 | |
| 268 | if (map) { |
| 269 | cpu = vpe_to_cpuid_lock(map->vpe, flags); |
| 270 | } else { |
| 271 | /* Physical LPIs are already locked via the irq_desc lock */ |
| 272 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 273 | cpu = its_dev->event_map.col_map[its_get_event_id(d)]; |
| 274 | /* Keep GCC quiet... */ |
| 275 | *flags = 0; |
| 276 | } |
| 277 | |
| 278 | return cpu; |
| 279 | } |
| 280 | |
| 281 | static void irq_to_cpuid_unlock(struct irq_data *d, unsigned long flags) |
| 282 | { |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 283 | struct its_vlpi_map *map = get_vlpi_map(d); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 284 | |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 285 | if (map) |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 286 | vpe_to_cpuid_unlock(map->vpe, flags); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 289 | static struct its_collection *valid_col(struct its_collection *col) |
| 290 | { |
Joe Perches | 20faba8 | 2019-07-09 22:04:18 -0700 | [diff] [blame] | 291 | if (WARN_ON_ONCE(col->target_address & GENMASK_ULL(15, 0))) |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 292 | return NULL; |
| 293 | |
| 294 | return col; |
| 295 | } |
| 296 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 297 | static struct its_vpe *valid_vpe(struct its_node *its, struct its_vpe *vpe) |
| 298 | { |
| 299 | if (valid_col(its->collections + vpe->col_idx)) |
| 300 | return vpe; |
| 301 | |
| 302 | return NULL; |
| 303 | } |
| 304 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 305 | /* |
| 306 | * ITS command descriptors - parameters to be encoded in a command |
| 307 | * block. |
| 308 | */ |
| 309 | struct its_cmd_desc { |
| 310 | union { |
| 311 | struct { |
| 312 | struct its_device *dev; |
| 313 | u32 event_id; |
| 314 | } its_inv_cmd; |
| 315 | |
| 316 | struct { |
| 317 | struct its_device *dev; |
| 318 | u32 event_id; |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 319 | } its_clear_cmd; |
| 320 | |
| 321 | struct { |
| 322 | struct its_device *dev; |
| 323 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 324 | } its_int_cmd; |
| 325 | |
| 326 | struct { |
| 327 | struct its_device *dev; |
| 328 | int valid; |
| 329 | } its_mapd_cmd; |
| 330 | |
| 331 | struct { |
| 332 | struct its_collection *col; |
| 333 | int valid; |
| 334 | } its_mapc_cmd; |
| 335 | |
| 336 | struct { |
| 337 | struct its_device *dev; |
| 338 | u32 phys_id; |
| 339 | u32 event_id; |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 340 | } its_mapti_cmd; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 341 | |
| 342 | struct { |
| 343 | struct its_device *dev; |
| 344 | struct its_collection *col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 345 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 346 | } its_movi_cmd; |
| 347 | |
| 348 | struct { |
| 349 | struct its_device *dev; |
| 350 | u32 event_id; |
| 351 | } its_discard_cmd; |
| 352 | |
| 353 | struct { |
| 354 | struct its_collection *col; |
| 355 | } its_invall_cmd; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 356 | |
| 357 | struct { |
| 358 | struct its_vpe *vpe; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 359 | } its_vinvall_cmd; |
| 360 | |
| 361 | struct { |
| 362 | struct its_vpe *vpe; |
| 363 | struct its_collection *col; |
| 364 | bool valid; |
| 365 | } its_vmapp_cmd; |
| 366 | |
| 367 | struct { |
| 368 | struct its_vpe *vpe; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 369 | struct its_device *dev; |
| 370 | u32 virt_id; |
| 371 | u32 event_id; |
| 372 | bool db_enabled; |
| 373 | } its_vmapti_cmd; |
| 374 | |
| 375 | struct { |
| 376 | struct its_vpe *vpe; |
| 377 | struct its_device *dev; |
| 378 | u32 event_id; |
| 379 | bool db_enabled; |
| 380 | } its_vmovi_cmd; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 381 | |
| 382 | struct { |
| 383 | struct its_vpe *vpe; |
| 384 | struct its_collection *col; |
| 385 | u16 seq_num; |
| 386 | u16 its_list; |
| 387 | } its_vmovp_cmd; |
Marc Zyngier | d97c97b | 2019-12-24 11:10:33 +0000 | [diff] [blame] | 388 | |
| 389 | struct { |
| 390 | struct its_vpe *vpe; |
| 391 | } its_invdb_cmd; |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 392 | |
| 393 | struct { |
| 394 | struct its_vpe *vpe; |
| 395 | u8 sgi; |
| 396 | u8 priority; |
| 397 | bool enable; |
| 398 | bool group; |
| 399 | bool clear; |
| 400 | } its_vsgi_cmd; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 401 | }; |
| 402 | }; |
| 403 | |
| 404 | /* |
| 405 | * The ITS command block, which is what the ITS actually parses. |
| 406 | */ |
| 407 | struct its_cmd_block { |
Ben Dooks (Codethink) | 2bbdfcc | 2019-10-17 12:29:55 +0100 | [diff] [blame] | 408 | union { |
| 409 | u64 raw_cmd[4]; |
| 410 | __le64 raw_cmd_le[4]; |
| 411 | }; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | #define ITS_CMD_QUEUE_SZ SZ_64K |
| 415 | #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(struct its_cmd_block)) |
| 416 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 417 | typedef struct its_collection *(*its_cmd_builder_t)(struct its_node *, |
| 418 | struct its_cmd_block *, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 419 | struct its_cmd_desc *); |
| 420 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 421 | typedef struct its_vpe *(*its_cmd_vbuilder_t)(struct its_node *, |
| 422 | struct its_cmd_block *, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 423 | struct its_cmd_desc *); |
| 424 | |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 425 | static void its_mask_encode(u64 *raw_cmd, u64 val, int h, int l) |
| 426 | { |
| 427 | u64 mask = GENMASK_ULL(h, l); |
| 428 | *raw_cmd &= ~mask; |
| 429 | *raw_cmd |= (val << l) & mask; |
| 430 | } |
| 431 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 432 | static void its_encode_cmd(struct its_cmd_block *cmd, u8 cmd_nr) |
| 433 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 434 | its_mask_encode(&cmd->raw_cmd[0], cmd_nr, 7, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void its_encode_devid(struct its_cmd_block *cmd, u32 devid) |
| 438 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 439 | its_mask_encode(&cmd->raw_cmd[0], devid, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static void its_encode_event_id(struct its_cmd_block *cmd, u32 id) |
| 443 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 444 | its_mask_encode(&cmd->raw_cmd[1], id, 31, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void its_encode_phys_id(struct its_cmd_block *cmd, u32 phys_id) |
| 448 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 449 | its_mask_encode(&cmd->raw_cmd[1], phys_id, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void its_encode_size(struct its_cmd_block *cmd, u8 size) |
| 453 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 454 | its_mask_encode(&cmd->raw_cmd[1], size, 4, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void its_encode_itt(struct its_cmd_block *cmd, u64 itt_addr) |
| 458 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 459 | its_mask_encode(&cmd->raw_cmd[2], itt_addr >> 8, 51, 8); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static void its_encode_valid(struct its_cmd_block *cmd, int valid) |
| 463 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 464 | its_mask_encode(&cmd->raw_cmd[2], !!valid, 63, 63); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static void its_encode_target(struct its_cmd_block *cmd, u64 target_addr) |
| 468 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 469 | its_mask_encode(&cmd->raw_cmd[2], target_addr >> 16, 51, 16); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void its_encode_collection(struct its_cmd_block *cmd, u16 col) |
| 473 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 474 | its_mask_encode(&cmd->raw_cmd[2], col, 15, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 477 | static void its_encode_vpeid(struct its_cmd_block *cmd, u16 vpeid) |
| 478 | { |
| 479 | its_mask_encode(&cmd->raw_cmd[1], vpeid, 47, 32); |
| 480 | } |
| 481 | |
| 482 | static void its_encode_virt_id(struct its_cmd_block *cmd, u32 virt_id) |
| 483 | { |
| 484 | its_mask_encode(&cmd->raw_cmd[2], virt_id, 31, 0); |
| 485 | } |
| 486 | |
| 487 | static void its_encode_db_phys_id(struct its_cmd_block *cmd, u32 db_phys_id) |
| 488 | { |
| 489 | its_mask_encode(&cmd->raw_cmd[2], db_phys_id, 63, 32); |
| 490 | } |
| 491 | |
| 492 | static void its_encode_db_valid(struct its_cmd_block *cmd, bool db_valid) |
| 493 | { |
| 494 | its_mask_encode(&cmd->raw_cmd[2], db_valid, 0, 0); |
| 495 | } |
| 496 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 497 | static void its_encode_seq_num(struct its_cmd_block *cmd, u16 seq_num) |
| 498 | { |
| 499 | its_mask_encode(&cmd->raw_cmd[0], seq_num, 47, 32); |
| 500 | } |
| 501 | |
| 502 | static void its_encode_its_list(struct its_cmd_block *cmd, u16 its_list) |
| 503 | { |
| 504 | its_mask_encode(&cmd->raw_cmd[1], its_list, 15, 0); |
| 505 | } |
| 506 | |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 507 | static void its_encode_vpt_addr(struct its_cmd_block *cmd, u64 vpt_pa) |
| 508 | { |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 509 | its_mask_encode(&cmd->raw_cmd[3], vpt_pa >> 16, 51, 16); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static void its_encode_vpt_size(struct its_cmd_block *cmd, u8 vpt_size) |
| 513 | { |
| 514 | its_mask_encode(&cmd->raw_cmd[3], vpt_size, 4, 0); |
| 515 | } |
| 516 | |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 517 | static void its_encode_vconf_addr(struct its_cmd_block *cmd, u64 vconf_pa) |
| 518 | { |
| 519 | its_mask_encode(&cmd->raw_cmd[0], vconf_pa >> 16, 51, 16); |
| 520 | } |
| 521 | |
| 522 | static void its_encode_alloc(struct its_cmd_block *cmd, bool alloc) |
| 523 | { |
| 524 | its_mask_encode(&cmd->raw_cmd[0], alloc, 8, 8); |
| 525 | } |
| 526 | |
| 527 | static void its_encode_ptz(struct its_cmd_block *cmd, bool ptz) |
| 528 | { |
| 529 | its_mask_encode(&cmd->raw_cmd[0], ptz, 9, 9); |
| 530 | } |
| 531 | |
| 532 | static void its_encode_vmapp_default_db(struct its_cmd_block *cmd, |
| 533 | u32 vpe_db_lpi) |
| 534 | { |
| 535 | its_mask_encode(&cmd->raw_cmd[1], vpe_db_lpi, 31, 0); |
| 536 | } |
| 537 | |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 538 | static void its_encode_vmovp_default_db(struct its_cmd_block *cmd, |
| 539 | u32 vpe_db_lpi) |
| 540 | { |
| 541 | its_mask_encode(&cmd->raw_cmd[3], vpe_db_lpi, 31, 0); |
| 542 | } |
| 543 | |
| 544 | static void its_encode_db(struct its_cmd_block *cmd, bool db) |
| 545 | { |
| 546 | its_mask_encode(&cmd->raw_cmd[2], db, 63, 63); |
| 547 | } |
| 548 | |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 549 | static void its_encode_sgi_intid(struct its_cmd_block *cmd, u8 sgi) |
| 550 | { |
| 551 | its_mask_encode(&cmd->raw_cmd[0], sgi, 35, 32); |
| 552 | } |
| 553 | |
| 554 | static void its_encode_sgi_priority(struct its_cmd_block *cmd, u8 prio) |
| 555 | { |
| 556 | its_mask_encode(&cmd->raw_cmd[0], prio >> 4, 23, 20); |
| 557 | } |
| 558 | |
| 559 | static void its_encode_sgi_group(struct its_cmd_block *cmd, bool grp) |
| 560 | { |
| 561 | its_mask_encode(&cmd->raw_cmd[0], grp, 10, 10); |
| 562 | } |
| 563 | |
| 564 | static void its_encode_sgi_clear(struct its_cmd_block *cmd, bool clr) |
| 565 | { |
| 566 | its_mask_encode(&cmd->raw_cmd[0], clr, 9, 9); |
| 567 | } |
| 568 | |
| 569 | static void its_encode_sgi_enable(struct its_cmd_block *cmd, bool en) |
| 570 | { |
| 571 | its_mask_encode(&cmd->raw_cmd[0], en, 8, 8); |
| 572 | } |
| 573 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 574 | static inline void its_fixup_cmd(struct its_cmd_block *cmd) |
| 575 | { |
| 576 | /* Let's fixup BE commands */ |
Ben Dooks (Codethink) | 2bbdfcc | 2019-10-17 12:29:55 +0100 | [diff] [blame] | 577 | cmd->raw_cmd_le[0] = cpu_to_le64(cmd->raw_cmd[0]); |
| 578 | cmd->raw_cmd_le[1] = cpu_to_le64(cmd->raw_cmd[1]); |
| 579 | cmd->raw_cmd_le[2] = cpu_to_le64(cmd->raw_cmd[2]); |
| 580 | cmd->raw_cmd_le[3] = cpu_to_le64(cmd->raw_cmd[3]); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 583 | static struct its_collection *its_build_mapd_cmd(struct its_node *its, |
| 584 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 585 | struct its_cmd_desc *desc) |
| 586 | { |
| 587 | unsigned long itt_addr; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 588 | u8 size = ilog2(desc->its_mapd_cmd.dev->nr_ites); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 589 | |
| 590 | itt_addr = virt_to_phys(desc->its_mapd_cmd.dev->itt); |
| 591 | itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN); |
| 592 | |
| 593 | its_encode_cmd(cmd, GITS_CMD_MAPD); |
| 594 | its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id); |
| 595 | its_encode_size(cmd, size - 1); |
| 596 | its_encode_itt(cmd, itt_addr); |
| 597 | its_encode_valid(cmd, desc->its_mapd_cmd.valid); |
| 598 | |
| 599 | its_fixup_cmd(cmd); |
| 600 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 601 | return NULL; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 604 | static struct its_collection *its_build_mapc_cmd(struct its_node *its, |
| 605 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 606 | struct its_cmd_desc *desc) |
| 607 | { |
| 608 | its_encode_cmd(cmd, GITS_CMD_MAPC); |
| 609 | its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); |
| 610 | its_encode_target(cmd, desc->its_mapc_cmd.col->target_address); |
| 611 | its_encode_valid(cmd, desc->its_mapc_cmd.valid); |
| 612 | |
| 613 | its_fixup_cmd(cmd); |
| 614 | |
| 615 | return desc->its_mapc_cmd.col; |
| 616 | } |
| 617 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 618 | static struct its_collection *its_build_mapti_cmd(struct its_node *its, |
| 619 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 620 | struct its_cmd_desc *desc) |
| 621 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 622 | struct its_collection *col; |
| 623 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 624 | col = dev_event_to_col(desc->its_mapti_cmd.dev, |
| 625 | desc->its_mapti_cmd.event_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 626 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 627 | its_encode_cmd(cmd, GITS_CMD_MAPTI); |
| 628 | its_encode_devid(cmd, desc->its_mapti_cmd.dev->device_id); |
| 629 | its_encode_event_id(cmd, desc->its_mapti_cmd.event_id); |
| 630 | its_encode_phys_id(cmd, desc->its_mapti_cmd.phys_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 631 | its_encode_collection(cmd, col->col_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 632 | |
| 633 | its_fixup_cmd(cmd); |
| 634 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 635 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 638 | static struct its_collection *its_build_movi_cmd(struct its_node *its, |
| 639 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 640 | struct its_cmd_desc *desc) |
| 641 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 642 | struct its_collection *col; |
| 643 | |
| 644 | col = dev_event_to_col(desc->its_movi_cmd.dev, |
| 645 | desc->its_movi_cmd.event_id); |
| 646 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 647 | its_encode_cmd(cmd, GITS_CMD_MOVI); |
| 648 | its_encode_devid(cmd, desc->its_movi_cmd.dev->device_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 649 | its_encode_event_id(cmd, desc->its_movi_cmd.event_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 650 | its_encode_collection(cmd, desc->its_movi_cmd.col->col_id); |
| 651 | |
| 652 | its_fixup_cmd(cmd); |
| 653 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 654 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 657 | static struct its_collection *its_build_discard_cmd(struct its_node *its, |
| 658 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 659 | struct its_cmd_desc *desc) |
| 660 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 661 | struct its_collection *col; |
| 662 | |
| 663 | col = dev_event_to_col(desc->its_discard_cmd.dev, |
| 664 | desc->its_discard_cmd.event_id); |
| 665 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 666 | its_encode_cmd(cmd, GITS_CMD_DISCARD); |
| 667 | its_encode_devid(cmd, desc->its_discard_cmd.dev->device_id); |
| 668 | its_encode_event_id(cmd, desc->its_discard_cmd.event_id); |
| 669 | |
| 670 | its_fixup_cmd(cmd); |
| 671 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 672 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 675 | static struct its_collection *its_build_inv_cmd(struct its_node *its, |
| 676 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 677 | struct its_cmd_desc *desc) |
| 678 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 679 | struct its_collection *col; |
| 680 | |
| 681 | col = dev_event_to_col(desc->its_inv_cmd.dev, |
| 682 | desc->its_inv_cmd.event_id); |
| 683 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 684 | its_encode_cmd(cmd, GITS_CMD_INV); |
| 685 | its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); |
| 686 | its_encode_event_id(cmd, desc->its_inv_cmd.event_id); |
| 687 | |
| 688 | its_fixup_cmd(cmd); |
| 689 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 690 | return valid_col(col); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 693 | static struct its_collection *its_build_int_cmd(struct its_node *its, |
| 694 | struct its_cmd_block *cmd, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 695 | struct its_cmd_desc *desc) |
| 696 | { |
| 697 | struct its_collection *col; |
| 698 | |
| 699 | col = dev_event_to_col(desc->its_int_cmd.dev, |
| 700 | desc->its_int_cmd.event_id); |
| 701 | |
| 702 | its_encode_cmd(cmd, GITS_CMD_INT); |
| 703 | its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); |
| 704 | its_encode_event_id(cmd, desc->its_int_cmd.event_id); |
| 705 | |
| 706 | its_fixup_cmd(cmd); |
| 707 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 708 | return valid_col(col); |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 711 | static struct its_collection *its_build_clear_cmd(struct its_node *its, |
| 712 | struct its_cmd_block *cmd, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 713 | struct its_cmd_desc *desc) |
| 714 | { |
| 715 | struct its_collection *col; |
| 716 | |
| 717 | col = dev_event_to_col(desc->its_clear_cmd.dev, |
| 718 | desc->its_clear_cmd.event_id); |
| 719 | |
| 720 | its_encode_cmd(cmd, GITS_CMD_CLEAR); |
| 721 | its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); |
| 722 | its_encode_event_id(cmd, desc->its_clear_cmd.event_id); |
| 723 | |
| 724 | its_fixup_cmd(cmd); |
| 725 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 726 | return valid_col(col); |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 729 | static struct its_collection *its_build_invall_cmd(struct its_node *its, |
| 730 | struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 731 | struct its_cmd_desc *desc) |
| 732 | { |
| 733 | its_encode_cmd(cmd, GITS_CMD_INVALL); |
Zenghui Yu | 1079452 | 2019-12-02 15:10:21 +0800 | [diff] [blame] | 734 | its_encode_collection(cmd, desc->its_invall_cmd.col->col_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 735 | |
| 736 | its_fixup_cmd(cmd); |
| 737 | |
| 738 | return NULL; |
| 739 | } |
| 740 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 741 | static struct its_vpe *its_build_vinvall_cmd(struct its_node *its, |
| 742 | struct its_cmd_block *cmd, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 743 | struct its_cmd_desc *desc) |
| 744 | { |
| 745 | its_encode_cmd(cmd, GITS_CMD_VINVALL); |
| 746 | its_encode_vpeid(cmd, desc->its_vinvall_cmd.vpe->vpe_id); |
| 747 | |
| 748 | its_fixup_cmd(cmd); |
| 749 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 750 | return valid_vpe(its, desc->its_vinvall_cmd.vpe); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 753 | static struct its_vpe *its_build_vmapp_cmd(struct its_node *its, |
| 754 | struct its_cmd_block *cmd, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 755 | struct its_cmd_desc *desc) |
| 756 | { |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 757 | unsigned long vpt_addr, vconf_addr; |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 758 | u64 target; |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 759 | bool alloc; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 760 | |
| 761 | its_encode_cmd(cmd, GITS_CMD_VMAPP); |
| 762 | its_encode_vpeid(cmd, desc->its_vmapp_cmd.vpe->vpe_id); |
| 763 | its_encode_valid(cmd, desc->its_vmapp_cmd.valid); |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 764 | |
| 765 | if (!desc->its_vmapp_cmd.valid) { |
| 766 | if (is_v4_1(its)) { |
| 767 | alloc = !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count); |
| 768 | its_encode_alloc(cmd, alloc); |
| 769 | } |
| 770 | |
| 771 | goto out; |
| 772 | } |
| 773 | |
| 774 | vpt_addr = virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->vpt_page)); |
| 775 | target = desc->its_vmapp_cmd.col->target_address + its->vlpi_redist_offset; |
| 776 | |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 777 | its_encode_target(cmd, target); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 778 | its_encode_vpt_addr(cmd, vpt_addr); |
| 779 | its_encode_vpt_size(cmd, LPI_NRBITS - 1); |
| 780 | |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 781 | if (!is_v4_1(its)) |
| 782 | goto out; |
| 783 | |
| 784 | vconf_addr = virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->its_vm->vprop_page)); |
| 785 | |
| 786 | alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count); |
| 787 | |
| 788 | its_encode_alloc(cmd, alloc); |
| 789 | |
| 790 | /* We can only signal PTZ when alloc==1. Why do we have two bits? */ |
| 791 | its_encode_ptz(cmd, alloc); |
| 792 | its_encode_vconf_addr(cmd, vconf_addr); |
| 793 | its_encode_vmapp_default_db(cmd, desc->its_vmapp_cmd.vpe->vpe_db_lpi); |
| 794 | |
| 795 | out: |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 796 | its_fixup_cmd(cmd); |
| 797 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 798 | return valid_vpe(its, desc->its_vmapp_cmd.vpe); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 801 | static struct its_vpe *its_build_vmapti_cmd(struct its_node *its, |
| 802 | struct its_cmd_block *cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 803 | struct its_cmd_desc *desc) |
| 804 | { |
| 805 | u32 db; |
| 806 | |
Marc Zyngier | 3858d4d | 2019-12-24 11:10:37 +0000 | [diff] [blame] | 807 | if (!is_v4_1(its) && desc->its_vmapti_cmd.db_enabled) |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 808 | db = desc->its_vmapti_cmd.vpe->vpe_db_lpi; |
| 809 | else |
| 810 | db = 1023; |
| 811 | |
| 812 | its_encode_cmd(cmd, GITS_CMD_VMAPTI); |
| 813 | its_encode_devid(cmd, desc->its_vmapti_cmd.dev->device_id); |
| 814 | its_encode_vpeid(cmd, desc->its_vmapti_cmd.vpe->vpe_id); |
| 815 | its_encode_event_id(cmd, desc->its_vmapti_cmd.event_id); |
| 816 | its_encode_db_phys_id(cmd, db); |
| 817 | its_encode_virt_id(cmd, desc->its_vmapti_cmd.virt_id); |
| 818 | |
| 819 | its_fixup_cmd(cmd); |
| 820 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 821 | return valid_vpe(its, desc->its_vmapti_cmd.vpe); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 824 | static struct its_vpe *its_build_vmovi_cmd(struct its_node *its, |
| 825 | struct its_cmd_block *cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 826 | struct its_cmd_desc *desc) |
| 827 | { |
| 828 | u32 db; |
| 829 | |
Marc Zyngier | 3858d4d | 2019-12-24 11:10:37 +0000 | [diff] [blame] | 830 | if (!is_v4_1(its) && desc->its_vmovi_cmd.db_enabled) |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 831 | db = desc->its_vmovi_cmd.vpe->vpe_db_lpi; |
| 832 | else |
| 833 | db = 1023; |
| 834 | |
| 835 | its_encode_cmd(cmd, GITS_CMD_VMOVI); |
| 836 | its_encode_devid(cmd, desc->its_vmovi_cmd.dev->device_id); |
| 837 | its_encode_vpeid(cmd, desc->its_vmovi_cmd.vpe->vpe_id); |
| 838 | its_encode_event_id(cmd, desc->its_vmovi_cmd.event_id); |
| 839 | its_encode_db_phys_id(cmd, db); |
| 840 | its_encode_db_valid(cmd, true); |
| 841 | |
| 842 | its_fixup_cmd(cmd); |
| 843 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 844 | return valid_vpe(its, desc->its_vmovi_cmd.vpe); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 847 | static struct its_vpe *its_build_vmovp_cmd(struct its_node *its, |
| 848 | struct its_cmd_block *cmd, |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 849 | struct its_cmd_desc *desc) |
| 850 | { |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 851 | u64 target; |
| 852 | |
| 853 | target = desc->its_vmovp_cmd.col->target_address + its->vlpi_redist_offset; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 854 | its_encode_cmd(cmd, GITS_CMD_VMOVP); |
| 855 | its_encode_seq_num(cmd, desc->its_vmovp_cmd.seq_num); |
| 856 | its_encode_its_list(cmd, desc->its_vmovp_cmd.its_list); |
| 857 | its_encode_vpeid(cmd, desc->its_vmovp_cmd.vpe->vpe_id); |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 858 | its_encode_target(cmd, target); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 859 | |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 860 | if (is_v4_1(its)) { |
| 861 | its_encode_db(cmd, true); |
| 862 | its_encode_vmovp_default_db(cmd, desc->its_vmovp_cmd.vpe->vpe_db_lpi); |
| 863 | } |
| 864 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 865 | its_fixup_cmd(cmd); |
| 866 | |
Marc Zyngier | 205e065 | 2018-06-22 10:52:53 +0100 | [diff] [blame] | 867 | return valid_vpe(its, desc->its_vmovp_cmd.vpe); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 870 | static struct its_vpe *its_build_vinv_cmd(struct its_node *its, |
| 871 | struct its_cmd_block *cmd, |
| 872 | struct its_cmd_desc *desc) |
| 873 | { |
| 874 | struct its_vlpi_map *map; |
| 875 | |
| 876 | map = dev_event_to_vlpi_map(desc->its_inv_cmd.dev, |
| 877 | desc->its_inv_cmd.event_id); |
| 878 | |
| 879 | its_encode_cmd(cmd, GITS_CMD_INV); |
| 880 | its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); |
| 881 | its_encode_event_id(cmd, desc->its_inv_cmd.event_id); |
| 882 | |
| 883 | its_fixup_cmd(cmd); |
| 884 | |
| 885 | return valid_vpe(its, map->vpe); |
| 886 | } |
| 887 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 888 | static struct its_vpe *its_build_vint_cmd(struct its_node *its, |
| 889 | struct its_cmd_block *cmd, |
| 890 | struct its_cmd_desc *desc) |
| 891 | { |
| 892 | struct its_vlpi_map *map; |
| 893 | |
| 894 | map = dev_event_to_vlpi_map(desc->its_int_cmd.dev, |
| 895 | desc->its_int_cmd.event_id); |
| 896 | |
| 897 | its_encode_cmd(cmd, GITS_CMD_INT); |
| 898 | its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); |
| 899 | its_encode_event_id(cmd, desc->its_int_cmd.event_id); |
| 900 | |
| 901 | its_fixup_cmd(cmd); |
| 902 | |
| 903 | return valid_vpe(its, map->vpe); |
| 904 | } |
| 905 | |
| 906 | static struct its_vpe *its_build_vclear_cmd(struct its_node *its, |
| 907 | struct its_cmd_block *cmd, |
| 908 | struct its_cmd_desc *desc) |
| 909 | { |
| 910 | struct its_vlpi_map *map; |
| 911 | |
| 912 | map = dev_event_to_vlpi_map(desc->its_clear_cmd.dev, |
| 913 | desc->its_clear_cmd.event_id); |
| 914 | |
| 915 | its_encode_cmd(cmd, GITS_CMD_CLEAR); |
| 916 | its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); |
| 917 | its_encode_event_id(cmd, desc->its_clear_cmd.event_id); |
| 918 | |
| 919 | its_fixup_cmd(cmd); |
| 920 | |
| 921 | return valid_vpe(its, map->vpe); |
| 922 | } |
| 923 | |
Marc Zyngier | d97c97b | 2019-12-24 11:10:33 +0000 | [diff] [blame] | 924 | static struct its_vpe *its_build_invdb_cmd(struct its_node *its, |
| 925 | struct its_cmd_block *cmd, |
| 926 | struct its_cmd_desc *desc) |
| 927 | { |
| 928 | if (WARN_ON(!is_v4_1(its))) |
| 929 | return NULL; |
| 930 | |
| 931 | its_encode_cmd(cmd, GITS_CMD_INVDB); |
| 932 | its_encode_vpeid(cmd, desc->its_invdb_cmd.vpe->vpe_id); |
| 933 | |
| 934 | its_fixup_cmd(cmd); |
| 935 | |
| 936 | return valid_vpe(its, desc->its_invdb_cmd.vpe); |
| 937 | } |
| 938 | |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 939 | static struct its_vpe *its_build_vsgi_cmd(struct its_node *its, |
| 940 | struct its_cmd_block *cmd, |
| 941 | struct its_cmd_desc *desc) |
| 942 | { |
| 943 | if (WARN_ON(!is_v4_1(its))) |
| 944 | return NULL; |
| 945 | |
| 946 | its_encode_cmd(cmd, GITS_CMD_VSGI); |
| 947 | its_encode_vpeid(cmd, desc->its_vsgi_cmd.vpe->vpe_id); |
| 948 | its_encode_sgi_intid(cmd, desc->its_vsgi_cmd.sgi); |
| 949 | its_encode_sgi_priority(cmd, desc->its_vsgi_cmd.priority); |
| 950 | its_encode_sgi_group(cmd, desc->its_vsgi_cmd.group); |
| 951 | its_encode_sgi_clear(cmd, desc->its_vsgi_cmd.clear); |
| 952 | its_encode_sgi_enable(cmd, desc->its_vsgi_cmd.enable); |
| 953 | |
| 954 | its_fixup_cmd(cmd); |
| 955 | |
| 956 | return valid_vpe(its, desc->its_vsgi_cmd.vpe); |
| 957 | } |
| 958 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 959 | static u64 its_cmd_ptr_to_offset(struct its_node *its, |
| 960 | struct its_cmd_block *ptr) |
| 961 | { |
| 962 | return (ptr - its->cmd_base) * sizeof(*ptr); |
| 963 | } |
| 964 | |
| 965 | static int its_queue_full(struct its_node *its) |
| 966 | { |
| 967 | int widx; |
| 968 | int ridx; |
| 969 | |
| 970 | widx = its->cmd_write - its->cmd_base; |
| 971 | ridx = readl_relaxed(its->base + GITS_CREADR) / sizeof(struct its_cmd_block); |
| 972 | |
| 973 | /* This is incredibly unlikely to happen, unless the ITS locks up. */ |
| 974 | if (((widx + 1) % ITS_CMD_QUEUE_NR_ENTRIES) == ridx) |
| 975 | return 1; |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static struct its_cmd_block *its_allocate_entry(struct its_node *its) |
| 981 | { |
| 982 | struct its_cmd_block *cmd; |
| 983 | u32 count = 1000000; /* 1s! */ |
| 984 | |
| 985 | while (its_queue_full(its)) { |
| 986 | count--; |
| 987 | if (!count) { |
| 988 | pr_err_ratelimited("ITS queue not draining\n"); |
| 989 | return NULL; |
| 990 | } |
| 991 | cpu_relax(); |
| 992 | udelay(1); |
| 993 | } |
| 994 | |
| 995 | cmd = its->cmd_write++; |
| 996 | |
| 997 | /* Handle queue wrapping */ |
| 998 | if (its->cmd_write == (its->cmd_base + ITS_CMD_QUEUE_NR_ENTRIES)) |
| 999 | its->cmd_write = its->cmd_base; |
| 1000 | |
Marc Zyngier | 34d677a | 2016-12-19 17:16:45 +0000 | [diff] [blame] | 1001 | /* Clear command */ |
| 1002 | cmd->raw_cmd[0] = 0; |
| 1003 | cmd->raw_cmd[1] = 0; |
| 1004 | cmd->raw_cmd[2] = 0; |
| 1005 | cmd->raw_cmd[3] = 0; |
| 1006 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1007 | return cmd; |
| 1008 | } |
| 1009 | |
| 1010 | static struct its_cmd_block *its_post_commands(struct its_node *its) |
| 1011 | { |
| 1012 | u64 wr = its_cmd_ptr_to_offset(its, its->cmd_write); |
| 1013 | |
| 1014 | writel_relaxed(wr, its->base + GITS_CWRITER); |
| 1015 | |
| 1016 | return its->cmd_write; |
| 1017 | } |
| 1018 | |
| 1019 | static void its_flush_cmd(struct its_node *its, struct its_cmd_block *cmd) |
| 1020 | { |
| 1021 | /* |
| 1022 | * Make sure the commands written to memory are observable by |
| 1023 | * the ITS. |
| 1024 | */ |
| 1025 | if (its->flags & ITS_FLAGS_CMDQ_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1026 | gic_flush_dcache_to_poc(cmd, sizeof(*cmd)); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1027 | else |
| 1028 | dsb(ishst); |
| 1029 | } |
| 1030 | |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 1031 | static int its_wait_for_range_completion(struct its_node *its, |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1032 | u64 prev_idx, |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 1033 | struct its_cmd_block *to) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1034 | { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1035 | u64 rd_idx, to_idx, linear_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1036 | u32 count = 1000000; /* 1s! */ |
| 1037 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1038 | /* Linearize to_idx if the command set has wrapped around */ |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1039 | to_idx = its_cmd_ptr_to_offset(its, to); |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1040 | if (to_idx < prev_idx) |
| 1041 | to_idx += ITS_CMD_QUEUE_SZ; |
| 1042 | |
| 1043 | linear_idx = prev_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1044 | |
| 1045 | while (1) { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1046 | s64 delta; |
| 1047 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1048 | rd_idx = readl_relaxed(its->base + GITS_CREADR); |
Marc Zyngier | 9bdd8b1 | 2017-08-19 10:16:02 +0100 | [diff] [blame] | 1049 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1050 | /* |
| 1051 | * Compute the read pointer progress, taking the |
| 1052 | * potential wrap-around into account. |
| 1053 | */ |
| 1054 | delta = rd_idx - prev_idx; |
| 1055 | if (rd_idx < prev_idx) |
| 1056 | delta += ITS_CMD_QUEUE_SZ; |
Marc Zyngier | 9bdd8b1 | 2017-08-19 10:16:02 +0100 | [diff] [blame] | 1057 | |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1058 | linear_idx += delta; |
| 1059 | if (linear_idx >= to_idx) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | |
| 1062 | count--; |
| 1063 | if (!count) { |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1064 | pr_err_ratelimited("ITS queue timeout (%llu %llu)\n", |
| 1065 | to_idx, linear_idx); |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 1066 | return -1; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1067 | } |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1068 | prev_idx = rd_idx; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1069 | cpu_relax(); |
| 1070 | udelay(1); |
| 1071 | } |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 1072 | |
| 1073 | return 0; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1076 | /* Warning, macro hell follows */ |
| 1077 | #define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \ |
| 1078 | void name(struct its_node *its, \ |
| 1079 | buildtype builder, \ |
| 1080 | struct its_cmd_desc *desc) \ |
| 1081 | { \ |
| 1082 | struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \ |
| 1083 | synctype *sync_obj; \ |
| 1084 | unsigned long flags; \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1085 | u64 rd_idx; \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1086 | \ |
| 1087 | raw_spin_lock_irqsave(&its->lock, flags); \ |
| 1088 | \ |
| 1089 | cmd = its_allocate_entry(its); \ |
| 1090 | if (!cmd) { /* We're soooooo screewed... */ \ |
| 1091 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 1092 | return; \ |
| 1093 | } \ |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 1094 | sync_obj = builder(its, cmd, desc); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1095 | its_flush_cmd(its, cmd); \ |
| 1096 | \ |
| 1097 | if (sync_obj) { \ |
| 1098 | sync_cmd = its_allocate_entry(its); \ |
| 1099 | if (!sync_cmd) \ |
| 1100 | goto post; \ |
| 1101 | \ |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 1102 | buildfn(its, sync_cmd, sync_obj); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1103 | its_flush_cmd(its, sync_cmd); \ |
| 1104 | } \ |
| 1105 | \ |
| 1106 | post: \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1107 | rd_idx = readl_relaxed(its->base + GITS_CREADR); \ |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1108 | next_cmd = its_post_commands(its); \ |
| 1109 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 1110 | \ |
Heyi Guo | a050fa5 | 2019-05-13 19:42:06 +0800 | [diff] [blame] | 1111 | if (its_wait_for_range_completion(its, rd_idx, next_cmd)) \ |
Marc Zyngier | a19b462 | 2017-08-04 17:45:50 +0100 | [diff] [blame] | 1112 | pr_err_ratelimited("ITS cmd %ps failed\n", builder); \ |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 1115 | static void its_build_sync_cmd(struct its_node *its, |
| 1116 | struct its_cmd_block *sync_cmd, |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1117 | struct its_collection *sync_col) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1118 | { |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1119 | its_encode_cmd(sync_cmd, GITS_CMD_SYNC); |
| 1120 | its_encode_target(sync_cmd, sync_col->target_address); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1121 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1122 | its_fixup_cmd(sync_cmd); |
| 1123 | } |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1124 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 1125 | static BUILD_SINGLE_CMD_FUNC(its_send_single_command, its_cmd_builder_t, |
| 1126 | struct its_collection, its_build_sync_cmd) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1127 | |
Marc Zyngier | 67047f90 | 2017-07-28 21:16:58 +0100 | [diff] [blame] | 1128 | static void its_build_vsync_cmd(struct its_node *its, |
| 1129 | struct its_cmd_block *sync_cmd, |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1130 | struct its_vpe *sync_vpe) |
| 1131 | { |
| 1132 | its_encode_cmd(sync_cmd, GITS_CMD_VSYNC); |
| 1133 | its_encode_vpeid(sync_cmd, sync_vpe->vpe_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1134 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1135 | its_fixup_cmd(sync_cmd); |
| 1136 | } |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1137 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1138 | static BUILD_SINGLE_CMD_FUNC(its_send_single_vcommand, its_cmd_vbuilder_t, |
| 1139 | struct its_vpe, its_build_vsync_cmd) |
| 1140 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1141 | static void its_send_int(struct its_device *dev, u32 event_id) |
| 1142 | { |
| 1143 | struct its_cmd_desc desc; |
| 1144 | |
| 1145 | desc.its_int_cmd.dev = dev; |
| 1146 | desc.its_int_cmd.event_id = event_id; |
| 1147 | |
| 1148 | its_send_single_command(dev->its, its_build_int_cmd, &desc); |
| 1149 | } |
| 1150 | |
| 1151 | static void its_send_clear(struct its_device *dev, u32 event_id) |
| 1152 | { |
| 1153 | struct its_cmd_desc desc; |
| 1154 | |
| 1155 | desc.its_clear_cmd.dev = dev; |
| 1156 | desc.its_clear_cmd.event_id = event_id; |
| 1157 | |
| 1158 | its_send_single_command(dev->its, its_build_clear_cmd, &desc); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static void its_send_inv(struct its_device *dev, u32 event_id) |
| 1162 | { |
| 1163 | struct its_cmd_desc desc; |
| 1164 | |
| 1165 | desc.its_inv_cmd.dev = dev; |
| 1166 | desc.its_inv_cmd.event_id = event_id; |
| 1167 | |
| 1168 | its_send_single_command(dev->its, its_build_inv_cmd, &desc); |
| 1169 | } |
| 1170 | |
| 1171 | static void its_send_mapd(struct its_device *dev, int valid) |
| 1172 | { |
| 1173 | struct its_cmd_desc desc; |
| 1174 | |
| 1175 | desc.its_mapd_cmd.dev = dev; |
| 1176 | desc.its_mapd_cmd.valid = !!valid; |
| 1177 | |
| 1178 | its_send_single_command(dev->its, its_build_mapd_cmd, &desc); |
| 1179 | } |
| 1180 | |
| 1181 | static void its_send_mapc(struct its_node *its, struct its_collection *col, |
| 1182 | int valid) |
| 1183 | { |
| 1184 | struct its_cmd_desc desc; |
| 1185 | |
| 1186 | desc.its_mapc_cmd.col = col; |
| 1187 | desc.its_mapc_cmd.valid = !!valid; |
| 1188 | |
| 1189 | its_send_single_command(its, its_build_mapc_cmd, &desc); |
| 1190 | } |
| 1191 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 1192 | 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] | 1193 | { |
| 1194 | struct its_cmd_desc desc; |
| 1195 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 1196 | desc.its_mapti_cmd.dev = dev; |
| 1197 | desc.its_mapti_cmd.phys_id = irq_id; |
| 1198 | desc.its_mapti_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1199 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 1200 | its_send_single_command(dev->its, its_build_mapti_cmd, &desc); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | static void its_send_movi(struct its_device *dev, |
| 1204 | struct its_collection *col, u32 id) |
| 1205 | { |
| 1206 | struct its_cmd_desc desc; |
| 1207 | |
| 1208 | desc.its_movi_cmd.dev = dev; |
| 1209 | desc.its_movi_cmd.col = col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1210 | desc.its_movi_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1211 | |
| 1212 | its_send_single_command(dev->its, its_build_movi_cmd, &desc); |
| 1213 | } |
| 1214 | |
| 1215 | static void its_send_discard(struct its_device *dev, u32 id) |
| 1216 | { |
| 1217 | struct its_cmd_desc desc; |
| 1218 | |
| 1219 | desc.its_discard_cmd.dev = dev; |
| 1220 | desc.its_discard_cmd.event_id = id; |
| 1221 | |
| 1222 | its_send_single_command(dev->its, its_build_discard_cmd, &desc); |
| 1223 | } |
| 1224 | |
| 1225 | static void its_send_invall(struct its_node *its, struct its_collection *col) |
| 1226 | { |
| 1227 | struct its_cmd_desc desc; |
| 1228 | |
| 1229 | desc.its_invall_cmd.col = col; |
| 1230 | |
| 1231 | its_send_single_command(its, its_build_invall_cmd, &desc); |
| 1232 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1233 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1234 | static void its_send_vmapti(struct its_device *dev, u32 id) |
| 1235 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1236 | struct its_vlpi_map *map = dev_event_to_vlpi_map(dev, id); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1237 | struct its_cmd_desc desc; |
| 1238 | |
| 1239 | desc.its_vmapti_cmd.vpe = map->vpe; |
| 1240 | desc.its_vmapti_cmd.dev = dev; |
| 1241 | desc.its_vmapti_cmd.virt_id = map->vintid; |
| 1242 | desc.its_vmapti_cmd.event_id = id; |
| 1243 | desc.its_vmapti_cmd.db_enabled = map->db_enabled; |
| 1244 | |
| 1245 | its_send_single_vcommand(dev->its, its_build_vmapti_cmd, &desc); |
| 1246 | } |
| 1247 | |
| 1248 | static void its_send_vmovi(struct its_device *dev, u32 id) |
| 1249 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1250 | struct its_vlpi_map *map = dev_event_to_vlpi_map(dev, id); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1251 | struct its_cmd_desc desc; |
| 1252 | |
| 1253 | desc.its_vmovi_cmd.vpe = map->vpe; |
| 1254 | desc.its_vmovi_cmd.dev = dev; |
| 1255 | desc.its_vmovi_cmd.event_id = id; |
| 1256 | desc.its_vmovi_cmd.db_enabled = map->db_enabled; |
| 1257 | |
| 1258 | its_send_single_vcommand(dev->its, its_build_vmovi_cmd, &desc); |
| 1259 | } |
| 1260 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1261 | static void its_send_vmapp(struct its_node *its, |
| 1262 | struct its_vpe *vpe, bool valid) |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1263 | { |
| 1264 | struct its_cmd_desc desc; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1265 | |
| 1266 | desc.its_vmapp_cmd.vpe = vpe; |
| 1267 | desc.its_vmapp_cmd.valid = valid; |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1268 | desc.its_vmapp_cmd.col = &its->collections[vpe->col_idx]; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1269 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 1270 | its_send_single_vcommand(its, its_build_vmapp_cmd, &desc); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1273 | static void its_send_vmovp(struct its_vpe *vpe) |
| 1274 | { |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 1275 | struct its_cmd_desc desc = {}; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1276 | struct its_node *its; |
| 1277 | unsigned long flags; |
| 1278 | int col_id = vpe->col_idx; |
| 1279 | |
| 1280 | desc.its_vmovp_cmd.vpe = vpe; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1281 | |
| 1282 | if (!its_list_map) { |
| 1283 | its = list_first_entry(&its_nodes, struct its_node, entry); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1284 | desc.its_vmovp_cmd.col = &its->collections[col_id]; |
| 1285 | its_send_single_vcommand(its, its_build_vmovp_cmd, &desc); |
| 1286 | return; |
| 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * Yet another marvel of the architecture. If using the |
| 1291 | * its_list "feature", we need to make sure that all ITSs |
| 1292 | * receive all VMOVP commands in the same order. The only way |
| 1293 | * to guarantee this is to make vmovp a serialization point. |
| 1294 | * |
| 1295 | * Wall <-- Head. |
| 1296 | */ |
| 1297 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1298 | |
| 1299 | desc.its_vmovp_cmd.seq_num = vmovp_seq_num++; |
Zenghui Yu | 8424312 | 2019-10-23 03:46:26 +0000 | [diff] [blame] | 1300 | desc.its_vmovp_cmd.its_list = get_its_list(vpe->its_vm); |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1301 | |
| 1302 | /* Emit VMOVPs */ |
| 1303 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 1304 | if (!is_v4(its)) |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1305 | continue; |
| 1306 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 1307 | if (!require_its_list_vmovp(vpe->its_vm, its)) |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1308 | continue; |
| 1309 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 1310 | desc.its_vmovp_cmd.col = &its->collections[col_id]; |
| 1311 | its_send_single_vcommand(its, its_build_vmovp_cmd, &desc); |
| 1312 | } |
| 1313 | |
| 1314 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1315 | } |
| 1316 | |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 1317 | 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] | 1318 | { |
| 1319 | struct its_cmd_desc desc; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1320 | |
| 1321 | desc.its_vinvall_cmd.vpe = vpe; |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 1322 | its_send_single_vcommand(its, its_build_vinvall_cmd, &desc); |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1325 | static void its_send_vinv(struct its_device *dev, u32 event_id) |
| 1326 | { |
| 1327 | struct its_cmd_desc desc; |
| 1328 | |
| 1329 | /* |
| 1330 | * There is no real VINV command. This is just a normal INV, |
| 1331 | * with a VSYNC instead of a SYNC. |
| 1332 | */ |
| 1333 | desc.its_inv_cmd.dev = dev; |
| 1334 | desc.its_inv_cmd.event_id = event_id; |
| 1335 | |
| 1336 | its_send_single_vcommand(dev->its, its_build_vinv_cmd, &desc); |
| 1337 | } |
| 1338 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 1339 | static void its_send_vint(struct its_device *dev, u32 event_id) |
| 1340 | { |
| 1341 | struct its_cmd_desc desc; |
| 1342 | |
| 1343 | /* |
| 1344 | * There is no real VINT command. This is just a normal INT, |
| 1345 | * with a VSYNC instead of a SYNC. |
| 1346 | */ |
| 1347 | desc.its_int_cmd.dev = dev; |
| 1348 | desc.its_int_cmd.event_id = event_id; |
| 1349 | |
| 1350 | its_send_single_vcommand(dev->its, its_build_vint_cmd, &desc); |
| 1351 | } |
| 1352 | |
| 1353 | static void its_send_vclear(struct its_device *dev, u32 event_id) |
| 1354 | { |
| 1355 | struct its_cmd_desc desc; |
| 1356 | |
| 1357 | /* |
| 1358 | * There is no real VCLEAR command. This is just a normal CLEAR, |
| 1359 | * with a VSYNC instead of a SYNC. |
| 1360 | */ |
| 1361 | desc.its_clear_cmd.dev = dev; |
| 1362 | desc.its_clear_cmd.event_id = event_id; |
| 1363 | |
| 1364 | its_send_single_vcommand(dev->its, its_build_vclear_cmd, &desc); |
| 1365 | } |
| 1366 | |
Marc Zyngier | d97c97b | 2019-12-24 11:10:33 +0000 | [diff] [blame] | 1367 | static void its_send_invdb(struct its_node *its, struct its_vpe *vpe) |
| 1368 | { |
| 1369 | struct its_cmd_desc desc; |
| 1370 | |
| 1371 | desc.its_invdb_cmd.vpe = vpe; |
| 1372 | its_send_single_vcommand(its, its_build_invdb_cmd, &desc); |
| 1373 | } |
| 1374 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1375 | /* |
| 1376 | * irqchip functions - assumes MSI, mostly. |
| 1377 | */ |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1378 | 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] | 1379 | { |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1380 | struct its_vlpi_map *map = get_vlpi_map(d); |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1381 | irq_hw_number_t hwirq; |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1382 | void *va; |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1383 | u8 *cfg; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1384 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1385 | if (map) { |
| 1386 | va = page_address(map->vm->vprop_page); |
Marc Zyngier | d4d7b4a | 2017-10-26 10:44:07 +0100 | [diff] [blame] | 1387 | hwirq = map->vintid; |
| 1388 | |
| 1389 | /* Remember the updated property */ |
| 1390 | map->properties &= ~clr; |
| 1391 | map->properties |= set | LPI_PROP_GROUP1; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1392 | } else { |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1393 | va = gic_rdists->prop_table_va; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1394 | hwirq = d->hwirq; |
| 1395 | } |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1396 | |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 1397 | cfg = va + hwirq - 8192; |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1398 | *cfg &= ~clr; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1399 | *cfg |= set | LPI_PROP_GROUP1; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1400 | |
| 1401 | /* |
| 1402 | * Make the above write visible to the redistributors. |
| 1403 | * And yes, we're flushing exactly: One. Single. Byte. |
| 1404 | * Humpf... |
| 1405 | */ |
| 1406 | if (gic_rdists->flags & RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1407 | gic_flush_dcache_to_poc(cfg, sizeof(*cfg)); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1408 | else |
| 1409 | dsb(ishst); |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 1412 | static void wait_for_syncr(void __iomem *rdbase) |
| 1413 | { |
| 1414 | while (gic_read_lpir(rdbase + GICR_SYNCR) & 1) |
| 1415 | cpu_relax(); |
| 1416 | } |
| 1417 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1418 | static void direct_lpi_inv(struct irq_data *d) |
| 1419 | { |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 1420 | struct its_vlpi_map *map = get_vlpi_map(d); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1421 | void __iomem *rdbase; |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 1422 | unsigned long flags; |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 1423 | u64 val; |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 1424 | int cpu; |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 1425 | |
| 1426 | if (map) { |
| 1427 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1428 | |
| 1429 | WARN_ON(!is_v4_1(its_dev->its)); |
| 1430 | |
| 1431 | val = GICR_INVLPIR_V; |
| 1432 | val |= FIELD_PREP(GICR_INVLPIR_VPEID, map->vpe->vpe_id); |
| 1433 | val |= FIELD_PREP(GICR_INVLPIR_INTID, map->vintid); |
| 1434 | } else { |
| 1435 | val = d->hwirq; |
| 1436 | } |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1437 | |
| 1438 | /* Target the redistributor this LPI is currently routed to */ |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 1439 | cpu = irq_to_cpuid_lock(d, &flags); |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 1440 | raw_spin_lock(&gic_data_rdist_cpu(cpu)->rd_lock); |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 1441 | rdbase = per_cpu_ptr(gic_rdists->rdist, cpu)->rd_base; |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 1442 | gic_write_lpir(val, rdbase + GICR_INVLPIR); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1443 | |
| 1444 | wait_for_syncr(rdbase); |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 1445 | raw_spin_unlock(&gic_data_rdist_cpu(cpu)->rd_lock); |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 1446 | irq_to_cpuid_unlock(d, flags); |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1449 | static void lpi_update_config(struct irq_data *d, u8 clr, u8 set) |
| 1450 | { |
| 1451 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1452 | |
| 1453 | lpi_write_config(d, clr, set); |
Marc Zyngier | f4a81f5 | 2019-12-24 11:10:38 +0000 | [diff] [blame] | 1454 | if (gic_rdists->has_direct_lpi && |
| 1455 | (is_v4_1(its_dev->its) || !irqd_is_forwarded_to_vcpu(d))) |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1456 | direct_lpi_inv(d); |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1457 | else if (!irqd_is_forwarded_to_vcpu(d)) |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 1458 | its_send_inv(its_dev, its_get_event_id(d)); |
Marc Zyngier | 2861469 | 2019-11-08 16:58:02 +0000 | [diff] [blame] | 1459 | else |
| 1460 | its_send_vinv(its_dev, its_get_event_id(d)); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1463 | static void its_vlpi_set_doorbell(struct irq_data *d, bool enable) |
| 1464 | { |
| 1465 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1466 | u32 event = its_get_event_id(d); |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1467 | struct its_vlpi_map *map; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1468 | |
Marc Zyngier | 3858d4d | 2019-12-24 11:10:37 +0000 | [diff] [blame] | 1469 | /* |
| 1470 | * GICv4.1 does away with the per-LPI nonsense, nothing to do |
| 1471 | * here. |
| 1472 | */ |
| 1473 | if (is_v4_1(its_dev->its)) |
| 1474 | return; |
| 1475 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1476 | map = dev_event_to_vlpi_map(its_dev, event); |
| 1477 | |
| 1478 | if (map->db_enabled == enable) |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1479 | return; |
| 1480 | |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1481 | map->db_enabled = enable; |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1482 | |
| 1483 | /* |
| 1484 | * More fun with the architecture: |
| 1485 | * |
| 1486 | * Ideally, we'd issue a VMAPTI to set the doorbell to its LPI |
| 1487 | * value or to 1023, depending on the enable bit. But that |
| 1488 | * would be issueing a mapping for an /existing/ DevID+EventID |
| 1489 | * pair, which is UNPREDICTABLE. Instead, let's issue a VMOVI |
| 1490 | * to the /same/ vPE, using this opportunity to adjust the |
| 1491 | * doorbell. Mouahahahaha. We loves it, Precious. |
| 1492 | */ |
| 1493 | its_send_vmovi(its_dev, event); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | static void its_mask_irq(struct irq_data *d) |
| 1497 | { |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1498 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1499 | its_vlpi_set_doorbell(d, false); |
| 1500 | |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1501 | lpi_update_config(d, LPI_PROP_ENABLED, 0); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static void its_unmask_irq(struct irq_data *d) |
| 1505 | { |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1506 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1507 | its_vlpi_set_doorbell(d, true); |
| 1508 | |
Marc Zyngier | adcdb94 | 2016-12-19 19:18:13 +0000 | [diff] [blame] | 1509 | lpi_update_config(d, 0, LPI_PROP_ENABLED); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1512 | static int its_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 1513 | bool force) |
| 1514 | { |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1515 | unsigned int cpu; |
| 1516 | const struct cpumask *cpu_mask = cpu_online_mask; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1517 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1518 | struct its_collection *target_col; |
| 1519 | u32 id = its_get_event_id(d); |
| 1520 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1521 | /* A forwarded interrupt should use irq_set_vcpu_affinity */ |
| 1522 | if (irqd_is_forwarded_to_vcpu(d)) |
| 1523 | return -EINVAL; |
| 1524 | |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1525 | /* lpi cannot be routed to a redistributor that is on a foreign node */ |
| 1526 | if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 1527 | if (its_dev->its->numa_node >= 0) { |
| 1528 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
| 1529 | if (!cpumask_intersects(mask_val, cpu_mask)) |
| 1530 | return -EINVAL; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | cpu = cpumask_any_and(mask_val, cpu_mask); |
| 1535 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1536 | if (cpu >= nr_cpu_ids) |
| 1537 | return -EINVAL; |
| 1538 | |
MaJun | 8b8d94a | 2017-05-18 16:19:13 +0800 | [diff] [blame] | 1539 | /* don't set the affinity when the target cpu is same as current one */ |
| 1540 | if (cpu != its_dev->event_map.col_map[id]) { |
| 1541 | target_col = &its_dev->its->collections[cpu]; |
| 1542 | its_send_movi(its_dev, target_col, id); |
| 1543 | its_dev->event_map.col_map[id] = cpu; |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 1544 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
MaJun | 8b8d94a | 2017-05-18 16:19:13 +0800 | [diff] [blame] | 1545 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1546 | |
| 1547 | return IRQ_SET_MASK_OK_DONE; |
| 1548 | } |
| 1549 | |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 1550 | static u64 its_irq_get_msi_base(struct its_device *its_dev) |
| 1551 | { |
| 1552 | struct its_node *its = its_dev->its; |
| 1553 | |
| 1554 | return its->phys_base + GITS_TRANSLATER; |
| 1555 | } |
| 1556 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1557 | static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg) |
| 1558 | { |
| 1559 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1560 | struct its_node *its; |
| 1561 | u64 addr; |
| 1562 | |
| 1563 | its = its_dev->its; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 1564 | addr = its->get_msi_base(its_dev); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1565 | |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 1566 | msg->address_lo = lower_32_bits(addr); |
| 1567 | msg->address_hi = upper_32_bits(addr); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1568 | msg->data = its_get_event_id(d); |
Robin Murphy | 44bb7e2 | 2016-09-12 17:13:59 +0100 | [diff] [blame] | 1569 | |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 1570 | iommu_dma_compose_msi_msg(irq_data_get_msi_desc(d), msg); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1573 | static int its_irq_set_irqchip_state(struct irq_data *d, |
| 1574 | enum irqchip_irq_state which, |
| 1575 | bool state) |
| 1576 | { |
| 1577 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1578 | u32 event = its_get_event_id(d); |
| 1579 | |
| 1580 | if (which != IRQCHIP_STATE_PENDING) |
| 1581 | return -EINVAL; |
| 1582 | |
Marc Zyngier | ed0e4aa | 2019-11-08 16:58:03 +0000 | [diff] [blame] | 1583 | if (irqd_is_forwarded_to_vcpu(d)) { |
| 1584 | if (state) |
| 1585 | its_send_vint(its_dev, event); |
| 1586 | else |
| 1587 | its_send_vclear(its_dev, event); |
| 1588 | } else { |
| 1589 | if (state) |
| 1590 | its_send_int(its_dev, event); |
| 1591 | else |
| 1592 | its_send_clear(its_dev, event); |
| 1593 | } |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1594 | |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 1598 | /* |
| 1599 | * Two favourable cases: |
| 1600 | * |
| 1601 | * (a) Either we have a GICv4.1, and all vPEs have to be mapped at all times |
| 1602 | * for vSGI delivery |
| 1603 | * |
| 1604 | * (b) Or the ITSs do not use a list map, meaning that VMOVP is cheap enough |
| 1605 | * and we're better off mapping all VPEs always |
| 1606 | * |
| 1607 | * If neither (a) nor (b) is true, then we map vPEs on demand. |
| 1608 | * |
| 1609 | */ |
| 1610 | static bool gic_requires_eager_mapping(void) |
| 1611 | { |
| 1612 | if (!its_list_map || gic_rdists->has_rvpeid) |
| 1613 | return true; |
| 1614 | |
| 1615 | return false; |
| 1616 | } |
| 1617 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1618 | static void its_map_vm(struct its_node *its, struct its_vm *vm) |
| 1619 | { |
| 1620 | unsigned long flags; |
| 1621 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 1622 | if (gic_requires_eager_mapping()) |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1623 | return; |
| 1624 | |
| 1625 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1626 | |
| 1627 | /* |
| 1628 | * If the VM wasn't mapped yet, iterate over the vpes and get |
| 1629 | * them mapped now. |
| 1630 | */ |
| 1631 | vm->vlpi_count[its->list_nr]++; |
| 1632 | |
| 1633 | if (vm->vlpi_count[its->list_nr] == 1) { |
| 1634 | int i; |
| 1635 | |
| 1636 | for (i = 0; i < vm->nr_vpes; i++) { |
| 1637 | struct its_vpe *vpe = vm->vpes[i]; |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 1638 | struct irq_data *d = irq_get_irq_data(vpe->irq); |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1639 | |
| 1640 | /* Map the VPE to the first possible CPU */ |
| 1641 | vpe->col_idx = cpumask_first(cpu_online_mask); |
| 1642 | its_send_vmapp(its, vpe, true); |
| 1643 | its_send_vinvall(its, vpe); |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 1644 | irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1649 | } |
| 1650 | |
| 1651 | static void its_unmap_vm(struct its_node *its, struct its_vm *vm) |
| 1652 | { |
| 1653 | unsigned long flags; |
| 1654 | |
| 1655 | /* Not using the ITS list? Everything is always mapped. */ |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 1656 | if (gic_requires_eager_mapping()) |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1657 | return; |
| 1658 | |
| 1659 | raw_spin_lock_irqsave(&vmovp_lock, flags); |
| 1660 | |
| 1661 | if (!--vm->vlpi_count[its->list_nr]) { |
| 1662 | int i; |
| 1663 | |
| 1664 | for (i = 0; i < vm->nr_vpes; i++) |
| 1665 | its_send_vmapp(its, vm->vpes[i], false); |
| 1666 | } |
| 1667 | |
| 1668 | raw_spin_unlock_irqrestore(&vmovp_lock, flags); |
| 1669 | } |
| 1670 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1671 | static int its_vlpi_map(struct irq_data *d, struct its_cmd_info *info) |
| 1672 | { |
| 1673 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1674 | u32 event = its_get_event_id(d); |
| 1675 | int ret = 0; |
| 1676 | |
| 1677 | if (!info->map) |
| 1678 | return -EINVAL; |
| 1679 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1680 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (!its_dev->event_map.vm) { |
| 1683 | struct its_vlpi_map *maps; |
| 1684 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1685 | maps = kcalloc(its_dev->event_map.nr_lpis, sizeof(*maps), |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1686 | GFP_ATOMIC); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1687 | if (!maps) { |
| 1688 | ret = -ENOMEM; |
| 1689 | goto out; |
| 1690 | } |
| 1691 | |
| 1692 | its_dev->event_map.vm = info->map->vm; |
| 1693 | its_dev->event_map.vlpi_maps = maps; |
| 1694 | } else if (its_dev->event_map.vm != info->map->vm) { |
| 1695 | ret = -EINVAL; |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
| 1699 | /* Get our private copy of the mapping information */ |
| 1700 | its_dev->event_map.vlpi_maps[event] = *info->map; |
| 1701 | |
| 1702 | if (irqd_is_forwarded_to_vcpu(d)) { |
| 1703 | /* Already mapped, move it around */ |
| 1704 | its_send_vmovi(its_dev, event); |
| 1705 | } else { |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1706 | /* Ensure all the VPEs are mapped on this ITS */ |
| 1707 | its_map_vm(its_dev->its, info->map->vm); |
| 1708 | |
Marc Zyngier | d4d7b4a | 2017-10-26 10:44:07 +0100 | [diff] [blame] | 1709 | /* |
| 1710 | * Flag the interrupt as forwarded so that we can |
| 1711 | * start poking the virtual property table. |
| 1712 | */ |
| 1713 | irqd_set_forwarded_to_vcpu(d); |
| 1714 | |
| 1715 | /* Write out the property to the prop table */ |
| 1716 | lpi_write_config(d, 0xff, info->map->properties); |
| 1717 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1718 | /* Drop the physical mapping */ |
| 1719 | its_send_discard(its_dev, event); |
| 1720 | |
| 1721 | /* and install the virtual one */ |
| 1722 | its_send_vmapti(its_dev, event); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1723 | |
| 1724 | /* Increment the number of VLPIs */ |
| 1725 | its_dev->event_map.nr_vlpis++; |
| 1726 | } |
| 1727 | |
| 1728 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1729 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1730 | return ret; |
| 1731 | } |
| 1732 | |
| 1733 | static int its_vlpi_get(struct irq_data *d, struct its_cmd_info *info) |
| 1734 | { |
| 1735 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 046b505 | 2019-11-08 16:58:04 +0000 | [diff] [blame] | 1736 | struct its_vlpi_map *map; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1737 | int ret = 0; |
| 1738 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1739 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1740 | |
Marc Zyngier | 046b505 | 2019-11-08 16:58:04 +0000 | [diff] [blame] | 1741 | map = get_vlpi_map(d); |
| 1742 | |
| 1743 | if (!its_dev->event_map.vm || !map) { |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1744 | ret = -EINVAL; |
| 1745 | goto out; |
| 1746 | } |
| 1747 | |
| 1748 | /* Copy our mapping information to the incoming request */ |
Marc Zyngier | c1d4d5c | 2019-11-08 16:58:01 +0000 | [diff] [blame] | 1749 | *info->map = *map; |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1750 | |
| 1751 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1752 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1753 | return ret; |
| 1754 | } |
| 1755 | |
| 1756 | static int its_vlpi_unmap(struct irq_data *d) |
| 1757 | { |
| 1758 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1759 | u32 event = its_get_event_id(d); |
| 1760 | int ret = 0; |
| 1761 | |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1762 | raw_spin_lock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1763 | |
| 1764 | if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) { |
| 1765 | ret = -EINVAL; |
| 1766 | goto out; |
| 1767 | } |
| 1768 | |
| 1769 | /* Drop the virtual mapping */ |
| 1770 | its_send_discard(its_dev, event); |
| 1771 | |
| 1772 | /* and restore the physical one */ |
| 1773 | irqd_clr_forwarded_to_vcpu(d); |
| 1774 | its_send_mapti(its_dev, d->hwirq, event); |
| 1775 | lpi_update_config(d, 0xff, (LPI_PROP_DEFAULT_PRIO | |
| 1776 | LPI_PROP_ENABLED | |
| 1777 | LPI_PROP_GROUP1)); |
| 1778 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 1779 | /* Potentially unmap the VM from this ITS */ |
| 1780 | its_unmap_vm(its_dev->its, its_dev->event_map.vm); |
| 1781 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1782 | /* |
| 1783 | * Drop the refcount and make the device available again if |
| 1784 | * this was the last VLPI. |
| 1785 | */ |
| 1786 | if (!--its_dev->event_map.nr_vlpis) { |
| 1787 | its_dev->event_map.vm = NULL; |
| 1788 | kfree(its_dev->event_map.vlpi_maps); |
| 1789 | } |
| 1790 | |
| 1791 | out: |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 1792 | raw_spin_unlock(&its_dev->event_map.vlpi_lock); |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1793 | return ret; |
| 1794 | } |
| 1795 | |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1796 | static int its_vlpi_prop_update(struct irq_data *d, struct its_cmd_info *info) |
| 1797 | { |
| 1798 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1799 | |
| 1800 | if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) |
| 1801 | return -EINVAL; |
| 1802 | |
| 1803 | if (info->cmd_type == PROP_UPDATE_AND_INV_VLPI) |
| 1804 | lpi_update_config(d, 0xff, info->config); |
| 1805 | else |
| 1806 | lpi_write_config(d, 0xff, info->config); |
| 1807 | its_vlpi_set_doorbell(d, !!(info->config & LPI_PROP_ENABLED)); |
| 1808 | |
| 1809 | return 0; |
| 1810 | } |
| 1811 | |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1812 | static int its_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 1813 | { |
| 1814 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1815 | struct its_cmd_info *info = vcpu_info; |
| 1816 | |
| 1817 | /* Need a v4 ITS */ |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 1818 | if (!is_v4(its_dev->its)) |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1819 | return -EINVAL; |
| 1820 | |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1821 | /* Unmap request? */ |
| 1822 | if (!info) |
| 1823 | return its_vlpi_unmap(d); |
| 1824 | |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1825 | switch (info->cmd_type) { |
| 1826 | case MAP_VLPI: |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1827 | return its_vlpi_map(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1828 | |
| 1829 | case GET_VLPI: |
Marc Zyngier | d011e4e | 2016-12-20 09:44:41 +0000 | [diff] [blame] | 1830 | return its_vlpi_get(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1831 | |
| 1832 | case PROP_UPDATE_VLPI: |
| 1833 | case PROP_UPDATE_AND_INV_VLPI: |
Marc Zyngier | 015ec03 | 2016-12-20 09:54:57 +0000 | [diff] [blame] | 1834 | return its_vlpi_prop_update(d, info); |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1835 | |
| 1836 | default: |
| 1837 | return -EINVAL; |
| 1838 | } |
| 1839 | } |
| 1840 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1841 | static struct irq_chip its_irq_chip = { |
| 1842 | .name = "ITS", |
| 1843 | .irq_mask = its_mask_irq, |
| 1844 | .irq_unmask = its_unmask_irq, |
Ashok Kumar | 004fa08 | 2016-02-11 05:38:53 -0800 | [diff] [blame] | 1845 | .irq_eoi = irq_chip_eoi_parent, |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 1846 | .irq_set_affinity = its_set_affinity, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1847 | .irq_compose_msi_msg = its_irq_compose_msi_msg, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 1848 | .irq_set_irqchip_state = its_irq_set_irqchip_state, |
Marc Zyngier | c808eea | 2016-12-20 09:31:20 +0000 | [diff] [blame] | 1849 | .irq_set_vcpu_affinity = its_irq_set_vcpu_affinity, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1850 | }; |
| 1851 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1852 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1853 | /* |
| 1854 | * How we allocate LPIs: |
| 1855 | * |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1856 | * lpi_range_list contains ranges of LPIs that are to available to |
| 1857 | * allocate from. To allocate LPIs, just pick the first range that |
| 1858 | * fits the required allocation, and reduce it by the required |
| 1859 | * amount. Once empty, remove the range from the list. |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1860 | * |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1861 | * To free a range of LPIs, add a free range to the list, sort it and |
| 1862 | * merge the result if the new range happens to be adjacent to an |
| 1863 | * already free block. |
| 1864 | * |
| 1865 | * The consequence of the above is that allocation is cost is low, but |
| 1866 | * freeing is expensive. We assumes that freeing rarely occurs. |
| 1867 | */ |
Jia He | 4cb205c | 2018-08-28 12:53:26 +0800 | [diff] [blame] | 1868 | #define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */ |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1869 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1870 | static DEFINE_MUTEX(lpi_range_lock); |
| 1871 | static LIST_HEAD(lpi_range_list); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1872 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1873 | struct lpi_range { |
| 1874 | struct list_head entry; |
| 1875 | u32 base_id; |
| 1876 | u32 span; |
| 1877 | }; |
| 1878 | |
| 1879 | static struct lpi_range *mk_lpi_range(u32 base, u32 span) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1880 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1881 | struct lpi_range *range; |
| 1882 | |
Rasmus Villemoes | 1c73fac | 2019-03-12 18:33:48 +0100 | [diff] [blame] | 1883 | range = kmalloc(sizeof(*range), GFP_KERNEL); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1884 | if (range) { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1885 | range->base_id = base; |
| 1886 | range->span = span; |
| 1887 | } |
| 1888 | |
| 1889 | return range; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1892 | static int alloc_lpi_range(u32 nr_lpis, u32 *base) |
| 1893 | { |
| 1894 | struct lpi_range *range, *tmp; |
| 1895 | int err = -ENOSPC; |
| 1896 | |
| 1897 | mutex_lock(&lpi_range_lock); |
| 1898 | |
| 1899 | list_for_each_entry_safe(range, tmp, &lpi_range_list, entry) { |
| 1900 | if (range->span >= nr_lpis) { |
| 1901 | *base = range->base_id; |
| 1902 | range->base_id += nr_lpis; |
| 1903 | range->span -= nr_lpis; |
| 1904 | |
| 1905 | if (range->span == 0) { |
| 1906 | list_del(&range->entry); |
| 1907 | kfree(range); |
| 1908 | } |
| 1909 | |
| 1910 | err = 0; |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | mutex_unlock(&lpi_range_lock); |
| 1916 | |
| 1917 | pr_debug("ITS: alloc %u:%u\n", *base, nr_lpis); |
| 1918 | return err; |
| 1919 | } |
| 1920 | |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1921 | static void merge_lpi_ranges(struct lpi_range *a, struct lpi_range *b) |
| 1922 | { |
| 1923 | if (&a->entry == &lpi_range_list || &b->entry == &lpi_range_list) |
| 1924 | return; |
| 1925 | if (a->base_id + a->span != b->base_id) |
| 1926 | return; |
| 1927 | b->base_id = a->base_id; |
| 1928 | b->span += a->span; |
| 1929 | list_del(&a->entry); |
| 1930 | kfree(a); |
| 1931 | } |
| 1932 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1933 | static int free_lpi_range(u32 base, u32 nr_lpis) |
| 1934 | { |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1935 | struct lpi_range *new, *old; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1936 | |
| 1937 | new = mk_lpi_range(base, nr_lpis); |
Rasmus Villemoes | b31a383 | 2019-03-12 18:33:47 +0100 | [diff] [blame] | 1938 | if (!new) |
| 1939 | return -ENOMEM; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1940 | |
| 1941 | mutex_lock(&lpi_range_lock); |
| 1942 | |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1943 | list_for_each_entry_reverse(old, &lpi_range_list, entry) { |
| 1944 | if (old->base_id < base) |
| 1945 | break; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1946 | } |
Rasmus Villemoes | 12eade1 | 2019-03-12 18:33:49 +0100 | [diff] [blame] | 1947 | /* |
| 1948 | * old is the last element with ->base_id smaller than base, |
| 1949 | * so new goes right after it. If there are no elements with |
| 1950 | * ->base_id smaller than base, &old->entry ends up pointing |
| 1951 | * at the head of the list, and inserting new it the start of |
| 1952 | * the list is the right thing to do in that case as well. |
| 1953 | */ |
| 1954 | list_add(&new->entry, &old->entry); |
| 1955 | /* |
| 1956 | * Now check if we can merge with the preceding and/or |
| 1957 | * following ranges. |
| 1958 | */ |
| 1959 | merge_lpi_ranges(old, new); |
| 1960 | merge_lpi_ranges(new, list_next_entry(new, entry)); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1961 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1962 | mutex_unlock(&lpi_range_lock); |
Rasmus Villemoes | b31a383 | 2019-03-12 18:33:47 +0100 | [diff] [blame] | 1963 | return 0; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Tomasz Nowicki | 04a0e4d | 2016-01-19 14:11:18 +0100 | [diff] [blame] | 1966 | static int __init its_lpi_init(u32 id_bits) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1967 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1968 | u32 lpis = (1UL << id_bits) - 8192; |
Marc Zyngier | 12b2905 | 2018-05-31 09:01:59 +0100 | [diff] [blame] | 1969 | u32 numlpis; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1970 | int err; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1971 | |
Marc Zyngier | 12b2905 | 2018-05-31 09:01:59 +0100 | [diff] [blame] | 1972 | numlpis = 1UL << GICD_TYPER_NUM_LPIS(gic_rdists->gicd_typer); |
| 1973 | |
| 1974 | if (numlpis > 2 && !WARN_ON(numlpis > lpis)) { |
| 1975 | lpis = numlpis; |
| 1976 | pr_info("ITS: Using hypervisor restricted LPI range [%u]\n", |
| 1977 | lpis); |
| 1978 | } |
| 1979 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1980 | /* |
| 1981 | * Initializing the allocator is just the same as freeing the |
| 1982 | * full range of LPIs. |
| 1983 | */ |
| 1984 | err = free_lpi_range(8192, lpis); |
| 1985 | pr_debug("ITS: Allocator initialized for %u LPIs\n", lpis); |
| 1986 | return err; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1989 | 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] | 1990 | { |
| 1991 | unsigned long *bitmap = NULL; |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1992 | int err = 0; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1993 | |
| 1994 | do { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1995 | err = alloc_lpi_range(nr_irqs, base); |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 1996 | if (!err) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 1997 | break; |
| 1998 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 1999 | nr_irqs /= 2; |
| 2000 | } while (nr_irqs > 0); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2001 | |
Marc Zyngier | 45725e0 | 2019-01-29 15:19:23 +0000 | [diff] [blame] | 2002 | if (!nr_irqs) |
| 2003 | err = -ENOSPC; |
| 2004 | |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 2005 | if (err) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2006 | goto out; |
| 2007 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 2008 | bitmap = kcalloc(BITS_TO_LONGS(nr_irqs), sizeof (long), GFP_ATOMIC); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2009 | if (!bitmap) |
| 2010 | goto out; |
| 2011 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 2012 | *nr_ids = nr_irqs; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2013 | |
| 2014 | out: |
Marc Zyngier | c8415b9 | 2015-10-02 16:44:05 +0100 | [diff] [blame] | 2015 | if (!bitmap) |
| 2016 | *base = *nr_ids = 0; |
| 2017 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2018 | return bitmap; |
| 2019 | } |
| 2020 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 2021 | 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] | 2022 | { |
Marc Zyngier | 880cb3c | 2018-05-27 16:14:15 +0100 | [diff] [blame] | 2023 | WARN_ON(free_lpi_range(base, nr_ids)); |
Marc Zyngier | cf2be8b | 2016-12-19 18:49:59 +0000 | [diff] [blame] | 2024 | kfree(bitmap); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 2025 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2026 | |
Marc Zyngier | 053be48 | 2018-07-27 15:02:27 +0100 | [diff] [blame] | 2027 | static void gic_reset_prop_table(void *va) |
| 2028 | { |
| 2029 | /* Priority 0xa0, Group-1, disabled */ |
| 2030 | memset(va, LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1, LPI_PROPBASE_SZ); |
| 2031 | |
| 2032 | /* Make sure the GIC will observe the written configuration */ |
| 2033 | gic_flush_dcache_to_poc(va, LPI_PROPBASE_SZ); |
| 2034 | } |
| 2035 | |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 2036 | static struct page *its_allocate_prop_table(gfp_t gfp_flags) |
| 2037 | { |
| 2038 | struct page *prop_page; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2039 | |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 2040 | prop_page = alloc_pages(gfp_flags, get_order(LPI_PROPBASE_SZ)); |
| 2041 | if (!prop_page) |
| 2042 | return NULL; |
| 2043 | |
Marc Zyngier | 053be48 | 2018-07-27 15:02:27 +0100 | [diff] [blame] | 2044 | gic_reset_prop_table(page_address(prop_page)); |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame] | 2045 | |
| 2046 | return prop_page; |
| 2047 | } |
| 2048 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2049 | static void its_free_prop_table(struct page *prop_page) |
| 2050 | { |
| 2051 | free_pages((unsigned long)page_address(prop_page), |
| 2052 | get_order(LPI_PROPBASE_SZ)); |
| 2053 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2054 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2055 | static bool gic_check_reserved_range(phys_addr_t addr, unsigned long size) |
| 2056 | { |
| 2057 | phys_addr_t start, end, addr_end; |
| 2058 | u64 i; |
| 2059 | |
| 2060 | /* |
| 2061 | * We don't bother checking for a kdump kernel as by |
| 2062 | * construction, the LPI tables are out of this kernel's |
| 2063 | * memory map. |
| 2064 | */ |
| 2065 | if (is_kdump_kernel()) |
| 2066 | return true; |
| 2067 | |
| 2068 | addr_end = addr + size - 1; |
| 2069 | |
| 2070 | for_each_reserved_mem_region(i, &start, &end) { |
| 2071 | if (addr >= start && addr_end <= end) |
| 2072 | return true; |
| 2073 | } |
| 2074 | |
| 2075 | /* Not found, not a good sign... */ |
| 2076 | pr_warn("GICv3: Expected reserved range [%pa:%pa], not found\n", |
| 2077 | &addr, &addr_end); |
| 2078 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 2079 | return false; |
| 2080 | } |
| 2081 | |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 2082 | static int gic_reserve_range(phys_addr_t addr, unsigned long size) |
| 2083 | { |
| 2084 | if (efi_enabled(EFI_CONFIG_TABLES)) |
| 2085 | return efi_mem_reserve_persistent(addr, size); |
| 2086 | |
| 2087 | return 0; |
| 2088 | } |
| 2089 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2090 | static int __init its_setup_lpi_prop_table(void) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2091 | { |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2092 | if (gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED) { |
| 2093 | u64 val; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2094 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2095 | val = gicr_read_propbaser(gic_data_rdist_rd_base() + GICR_PROPBASER); |
| 2096 | lpi_id_bits = (val & GICR_PROPBASER_IDBITS_MASK) + 1; |
| 2097 | |
| 2098 | gic_rdists->prop_table_pa = val & GENMASK_ULL(51, 12); |
| 2099 | gic_rdists->prop_table_va = memremap(gic_rdists->prop_table_pa, |
| 2100 | LPI_PROPBASE_SZ, |
| 2101 | MEMREMAP_WB); |
| 2102 | gic_reset_prop_table(gic_rdists->prop_table_va); |
| 2103 | } else { |
| 2104 | struct page *page; |
| 2105 | |
| 2106 | lpi_id_bits = min_t(u32, |
| 2107 | GICD_TYPER_ID_BITS(gic_rdists->gicd_typer), |
| 2108 | ITS_MAX_LPI_NRBITS); |
| 2109 | page = its_allocate_prop_table(GFP_NOWAIT); |
| 2110 | if (!page) { |
| 2111 | pr_err("Failed to allocate PROPBASE\n"); |
| 2112 | return -ENOMEM; |
| 2113 | } |
| 2114 | |
| 2115 | gic_rdists->prop_table_pa = page_to_phys(page); |
| 2116 | gic_rdists->prop_table_va = page_address(page); |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 2117 | WARN_ON(gic_reserve_range(gic_rdists->prop_table_pa, |
| 2118 | LPI_PROPBASE_SZ)); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 2121 | pr_info("GICv3: using LPI property table @%pa\n", |
| 2122 | &gic_rdists->prop_table_pa); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2123 | |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 2124 | return its_lpi_init(lpi_id_bits); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | static const char *its_base_type_string[] = { |
| 2128 | [GITS_BASER_TYPE_DEVICE] = "Devices", |
| 2129 | [GITS_BASER_TYPE_VCPU] = "Virtual CPUs", |
Marc Zyngier | 4f46de9 | 2016-12-20 15:50:14 +0000 | [diff] [blame] | 2130 | [GITS_BASER_TYPE_RESERVED3] = "Reserved (3)", |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2131 | [GITS_BASER_TYPE_COLLECTION] = "Interrupt Collections", |
| 2132 | [GITS_BASER_TYPE_RESERVED5] = "Reserved (5)", |
| 2133 | [GITS_BASER_TYPE_RESERVED6] = "Reserved (6)", |
| 2134 | [GITS_BASER_TYPE_RESERVED7] = "Reserved (7)", |
| 2135 | }; |
| 2136 | |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 2137 | static u64 its_read_baser(struct its_node *its, struct its_baser *baser) |
| 2138 | { |
| 2139 | u32 idx = baser - its->tables; |
| 2140 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2141 | return gits_read_baser(its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | static void its_write_baser(struct its_node *its, struct its_baser *baser, |
| 2145 | u64 val) |
| 2146 | { |
| 2147 | u32 idx = baser - its->tables; |
| 2148 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2149 | gits_write_baser(val, its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 2150 | baser->val = its_read_baser(its, baser); |
| 2151 | } |
| 2152 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2153 | 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] | 2154 | u64 cache, u64 shr, u32 psz, u32 order, |
| 2155 | bool indirect) |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2156 | { |
| 2157 | u64 val = its_read_baser(its, baser); |
| 2158 | u64 esz = GITS_BASER_ENTRY_SIZE(val); |
| 2159 | u64 type = GITS_BASER_TYPE(val); |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 2160 | u64 baser_phys, tmp; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2161 | u32 alloc_pages; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2162 | struct page *page; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2163 | void *base; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2164 | |
| 2165 | retry_alloc_baser: |
| 2166 | alloc_pages = (PAGE_ORDER_TO_SIZE(order) / psz); |
| 2167 | if (alloc_pages > GITS_BASER_PAGES_MAX) { |
| 2168 | pr_warn("ITS@%pa: %s too large, reduce ITS pages %u->%u\n", |
| 2169 | &its->phys_base, its_base_type_string[type], |
| 2170 | alloc_pages, GITS_BASER_PAGES_MAX); |
| 2171 | alloc_pages = GITS_BASER_PAGES_MAX; |
| 2172 | order = get_order(GITS_BASER_PAGES_MAX * psz); |
| 2173 | } |
| 2174 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2175 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order); |
| 2176 | if (!page) |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2177 | return -ENOMEM; |
| 2178 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 2179 | base = (void *)page_address(page); |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 2180 | baser_phys = virt_to_phys(base); |
| 2181 | |
| 2182 | /* Check if the physical address of the memory is above 48bits */ |
| 2183 | if (IS_ENABLED(CONFIG_ARM64_64K_PAGES) && (baser_phys >> 48)) { |
| 2184 | |
| 2185 | /* 52bit PA is supported only when PageSize=64K */ |
| 2186 | if (psz != SZ_64K) { |
| 2187 | pr_err("ITS: no 52bit PA support when psz=%d\n", psz); |
| 2188 | free_pages((unsigned long)base, order); |
| 2189 | return -ENXIO; |
| 2190 | } |
| 2191 | |
| 2192 | /* Convert 52bit PA to 48bit field */ |
| 2193 | baser_phys = GITS_BASER_PHYS_52_to_48(baser_phys); |
| 2194 | } |
| 2195 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2196 | retry_baser: |
Shanker Donthineni | 30ae961 | 2017-10-09 11:46:55 -0500 | [diff] [blame] | 2197 | val = (baser_phys | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2198 | (type << GITS_BASER_TYPE_SHIFT) | |
| 2199 | ((esz - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | |
| 2200 | ((alloc_pages - 1) << GITS_BASER_PAGES_SHIFT) | |
| 2201 | cache | |
| 2202 | shr | |
| 2203 | GITS_BASER_VALID); |
| 2204 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2205 | val |= indirect ? GITS_BASER_INDIRECT : 0x0; |
| 2206 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2207 | switch (psz) { |
| 2208 | case SZ_4K: |
| 2209 | val |= GITS_BASER_PAGE_SIZE_4K; |
| 2210 | break; |
| 2211 | case SZ_16K: |
| 2212 | val |= GITS_BASER_PAGE_SIZE_16K; |
| 2213 | break; |
| 2214 | case SZ_64K: |
| 2215 | val |= GITS_BASER_PAGE_SIZE_64K; |
| 2216 | break; |
| 2217 | } |
| 2218 | |
| 2219 | its_write_baser(its, baser, val); |
| 2220 | tmp = baser->val; |
| 2221 | |
| 2222 | if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) { |
| 2223 | /* |
| 2224 | * Shareability didn't stick. Just use |
| 2225 | * whatever the read reported, which is likely |
| 2226 | * to be the only thing this redistributor |
| 2227 | * supports. If that's zero, make it |
| 2228 | * non-cacheable as well. |
| 2229 | */ |
| 2230 | shr = tmp & GITS_BASER_SHAREABILITY_MASK; |
| 2231 | if (!shr) { |
| 2232 | cache = GITS_BASER_nC; |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 2233 | gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2234 | } |
| 2235 | goto retry_baser; |
| 2236 | } |
| 2237 | |
| 2238 | if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) { |
| 2239 | /* |
| 2240 | * Page size didn't stick. Let's try a smaller |
| 2241 | * size and retry. If we reach 4K, then |
| 2242 | * something is horribly wrong... |
| 2243 | */ |
| 2244 | free_pages((unsigned long)base, order); |
| 2245 | baser->base = NULL; |
| 2246 | |
| 2247 | switch (psz) { |
| 2248 | case SZ_16K: |
| 2249 | psz = SZ_4K; |
| 2250 | goto retry_alloc_baser; |
| 2251 | case SZ_64K: |
| 2252 | psz = SZ_16K; |
| 2253 | goto retry_alloc_baser; |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | if (val != tmp) { |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 2258 | pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n", |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2259 | &its->phys_base, its_base_type_string[type], |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 2260 | val, tmp); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2261 | free_pages((unsigned long)base, order); |
| 2262 | return -ENXIO; |
| 2263 | } |
| 2264 | |
| 2265 | baser->order = order; |
| 2266 | baser->base = base; |
| 2267 | baser->psz = psz; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2268 | tmp = indirect ? GITS_LVL1_ENTRY_SIZE : esz; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2269 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2270 | 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] | 2271 | &its->phys_base, (int)(PAGE_ORDER_TO_SIZE(order) / (int)tmp), |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2272 | its_base_type_string[type], |
| 2273 | (unsigned long)virt_to_phys(base), |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2274 | indirect ? "indirect" : "flat", (int)esz, |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2275 | psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT); |
| 2276 | |
| 2277 | return 0; |
| 2278 | } |
| 2279 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2280 | static bool its_parse_indirect_baser(struct its_node *its, |
| 2281 | struct its_baser *baser, |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2282 | u32 psz, u32 *order, u32 ids) |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2283 | { |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2284 | u64 tmp = its_read_baser(its, baser); |
| 2285 | u64 type = GITS_BASER_TYPE(tmp); |
| 2286 | u64 esz = GITS_BASER_ENTRY_SIZE(tmp); |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2287 | u64 val = GITS_BASER_InnerShareable | GITS_BASER_RaWaWb; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2288 | u32 new_order = *order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2289 | bool indirect = false; |
| 2290 | |
| 2291 | /* No need to enable Indirection if memory requirement < (psz*2)bytes */ |
| 2292 | if ((esz << ids) > (psz * 2)) { |
| 2293 | /* |
| 2294 | * Find out whether hw supports a single or two-level table by |
| 2295 | * table by reading bit at offset '62' after writing '1' to it. |
| 2296 | */ |
| 2297 | its_write_baser(its, baser, val | GITS_BASER_INDIRECT); |
| 2298 | indirect = !!(baser->val & GITS_BASER_INDIRECT); |
| 2299 | |
| 2300 | if (indirect) { |
| 2301 | /* |
| 2302 | * The size of the lvl2 table is equal to ITS page size |
| 2303 | * which is 'psz'. For computing lvl1 table size, |
| 2304 | * subtract ID bits that sparse lvl2 table from 'ids' |
| 2305 | * which is reported by ITS hardware times lvl1 table |
| 2306 | * entry size. |
| 2307 | */ |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 2308 | ids -= ilog2(psz / (int)esz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2309 | esz = GITS_LVL1_ENTRY_SIZE; |
| 2310 | } |
| 2311 | } |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2312 | |
| 2313 | /* |
| 2314 | * Allocate as many entries as required to fit the |
| 2315 | * range of device IDs that the ITS can grok... The ID |
| 2316 | * space being incredibly sparse, this results in a |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2317 | * massive waste of memory if two-level device table |
| 2318 | * feature is not supported by hardware. |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2319 | */ |
| 2320 | new_order = max_t(u32, get_order(esz << ids), new_order); |
| 2321 | if (new_order >= MAX_ORDER) { |
| 2322 | new_order = MAX_ORDER - 1; |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 2323 | ids = ilog2(PAGE_ORDER_TO_SIZE(new_order) / (int)esz); |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2324 | 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] | 2325 | &its->phys_base, its_base_type_string[type], |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2326 | device_ids(its), ids); |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | *order = new_order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2330 | |
| 2331 | return indirect; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 2332 | } |
| 2333 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2334 | static u32 compute_common_aff(u64 val) |
| 2335 | { |
| 2336 | u32 aff, clpiaff; |
| 2337 | |
| 2338 | aff = FIELD_GET(GICR_TYPER_AFFINITY, val); |
| 2339 | clpiaff = FIELD_GET(GICR_TYPER_COMMON_LPI_AFF, val); |
| 2340 | |
| 2341 | return aff & ~(GENMASK(31, 0) >> (clpiaff * 8)); |
| 2342 | } |
| 2343 | |
| 2344 | static u32 compute_its_aff(struct its_node *its) |
| 2345 | { |
| 2346 | u64 val; |
| 2347 | u32 svpet; |
| 2348 | |
| 2349 | /* |
| 2350 | * Reencode the ITS SVPET and MPIDR as a GICR_TYPER, and compute |
| 2351 | * the resulting affinity. We then use that to see if this match |
| 2352 | * our own affinity. |
| 2353 | */ |
| 2354 | svpet = FIELD_GET(GITS_TYPER_SVPET, its->typer); |
| 2355 | val = FIELD_PREP(GICR_TYPER_COMMON_LPI_AFF, svpet); |
| 2356 | val |= FIELD_PREP(GICR_TYPER_AFFINITY, its->mpidr); |
| 2357 | return compute_common_aff(val); |
| 2358 | } |
| 2359 | |
| 2360 | static struct its_node *find_sibling_its(struct its_node *cur_its) |
| 2361 | { |
| 2362 | struct its_node *its; |
| 2363 | u32 aff; |
| 2364 | |
| 2365 | if (!FIELD_GET(GITS_TYPER_SVPET, cur_its->typer)) |
| 2366 | return NULL; |
| 2367 | |
| 2368 | aff = compute_its_aff(cur_its); |
| 2369 | |
| 2370 | list_for_each_entry(its, &its_nodes, entry) { |
| 2371 | u64 baser; |
| 2372 | |
| 2373 | if (!is_v4_1(its) || its == cur_its) |
| 2374 | continue; |
| 2375 | |
| 2376 | if (!FIELD_GET(GITS_TYPER_SVPET, its->typer)) |
| 2377 | continue; |
| 2378 | |
| 2379 | if (aff != compute_its_aff(its)) |
| 2380 | continue; |
| 2381 | |
| 2382 | /* GICv4.1 guarantees that the vPE table is GITS_BASER2 */ |
| 2383 | baser = its->tables[2].val; |
| 2384 | if (!(baser & GITS_BASER_VALID)) |
| 2385 | continue; |
| 2386 | |
| 2387 | return its; |
| 2388 | } |
| 2389 | |
| 2390 | return NULL; |
| 2391 | } |
| 2392 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2393 | static void its_free_tables(struct its_node *its) |
| 2394 | { |
| 2395 | int i; |
| 2396 | |
| 2397 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 1a485f4 | 2016-02-01 20:19:44 -0600 | [diff] [blame] | 2398 | if (its->tables[i].base) { |
| 2399 | free_pages((unsigned long)its->tables[i].base, |
| 2400 | its->tables[i].order); |
| 2401 | its->tables[i].base = NULL; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 2406 | static int its_alloc_tables(struct its_node *its) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2407 | { |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2408 | u64 shr = GITS_BASER_InnerShareable; |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2409 | u64 cache = GITS_BASER_RaWaWb; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2410 | u32 psz = SZ_64K; |
| 2411 | int err, i; |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 2412 | |
Ard Biesheuvel | fa15001 | 2017-10-17 17:55:54 +0100 | [diff] [blame] | 2413 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_22375) |
| 2414 | /* erratum 24313: ignore memory access type */ |
| 2415 | cache = GITS_BASER_nCnB; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 2416 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2417 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 2418 | struct its_baser *baser = its->tables + i; |
| 2419 | u64 val = its_read_baser(its, baser); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2420 | u64 type = GITS_BASER_TYPE(val); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2421 | u32 order = get_order(psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2422 | bool indirect = false; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2423 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2424 | switch (type) { |
| 2425 | case GITS_BASER_TYPE_NONE: |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2426 | continue; |
| 2427 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2428 | case GITS_BASER_TYPE_DEVICE: |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2429 | indirect = its_parse_indirect_baser(its, baser, |
| 2430 | psz, &order, |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 2431 | device_ids(its)); |
Zenghui Yu | 8d56574 | 2019-02-10 05:24:10 +0000 | [diff] [blame] | 2432 | break; |
| 2433 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2434 | case GITS_BASER_TYPE_VCPU: |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2435 | if (is_v4_1(its)) { |
| 2436 | struct its_node *sibling; |
| 2437 | |
| 2438 | WARN_ON(i != 2); |
| 2439 | if ((sibling = find_sibling_its(its))) { |
| 2440 | *baser = sibling->tables[2]; |
| 2441 | its_write_baser(its, baser, baser->val); |
| 2442 | continue; |
| 2443 | } |
| 2444 | } |
| 2445 | |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2446 | indirect = its_parse_indirect_baser(its, baser, |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 2447 | psz, &order, |
| 2448 | ITS_MAX_VPEID_BITS); |
Marc Zyngier | 4cacac5 | 2016-12-19 18:18:34 +0000 | [diff] [blame] | 2449 | break; |
| 2450 | } |
Marc Zyngier | f54b97e | 2015-03-06 16:37:41 +0000 | [diff] [blame] | 2451 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 2452 | err = its_setup_baser(its, baser, cache, shr, psz, order, indirect); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2453 | if (err < 0) { |
| 2454 | its_free_tables(its); |
| 2455 | return err; |
Robert Richter | 30f2136 | 2015-09-21 22:58:34 +0200 | [diff] [blame] | 2456 | } |
| 2457 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 2458 | /* Update settings which will be used for next BASERn */ |
| 2459 | psz = baser->psz; |
| 2460 | cache = baser->val & GITS_BASER_CACHEABILITY_MASK; |
| 2461 | shr = baser->val & GITS_BASER_SHAREABILITY_MASK; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | return 0; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2467 | static u64 inherit_vpe_l1_table_from_its(void) |
| 2468 | { |
| 2469 | struct its_node *its; |
| 2470 | u64 val; |
| 2471 | u32 aff; |
| 2472 | |
| 2473 | val = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER); |
| 2474 | aff = compute_common_aff(val); |
| 2475 | |
| 2476 | list_for_each_entry(its, &its_nodes, entry) { |
| 2477 | u64 baser, addr; |
| 2478 | |
| 2479 | if (!is_v4_1(its)) |
| 2480 | continue; |
| 2481 | |
| 2482 | if (!FIELD_GET(GITS_TYPER_SVPET, its->typer)) |
| 2483 | continue; |
| 2484 | |
| 2485 | if (aff != compute_its_aff(its)) |
| 2486 | continue; |
| 2487 | |
| 2488 | /* GICv4.1 guarantees that the vPE table is GITS_BASER2 */ |
| 2489 | baser = its->tables[2].val; |
| 2490 | if (!(baser & GITS_BASER_VALID)) |
| 2491 | continue; |
| 2492 | |
| 2493 | /* We have a winner! */ |
Zenghui Yu | 8b718d4 | 2020-02-06 15:57:07 +0800 | [diff] [blame] | 2494 | gic_data_rdist()->vpe_l1_base = its->tables[2].base; |
| 2495 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2496 | val = GICR_VPROPBASER_4_1_VALID; |
| 2497 | if (baser & GITS_BASER_INDIRECT) |
| 2498 | val |= GICR_VPROPBASER_4_1_INDIRECT; |
| 2499 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_PAGE_SIZE, |
| 2500 | FIELD_GET(GITS_BASER_PAGE_SIZE_MASK, baser)); |
| 2501 | switch (FIELD_GET(GITS_BASER_PAGE_SIZE_MASK, baser)) { |
| 2502 | case GIC_PAGE_SIZE_64K: |
| 2503 | addr = GITS_BASER_ADDR_48_to_52(baser); |
| 2504 | break; |
| 2505 | default: |
| 2506 | addr = baser & GENMASK_ULL(47, 12); |
| 2507 | break; |
| 2508 | } |
| 2509 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_ADDR, addr >> 12); |
| 2510 | val |= FIELD_PREP(GICR_VPROPBASER_SHAREABILITY_MASK, |
| 2511 | FIELD_GET(GITS_BASER_SHAREABILITY_MASK, baser)); |
| 2512 | val |= FIELD_PREP(GICR_VPROPBASER_INNER_CACHEABILITY_MASK, |
| 2513 | FIELD_GET(GITS_BASER_INNER_CACHEABILITY_MASK, baser)); |
| 2514 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_SIZE, GITS_BASER_NR_PAGES(baser) - 1); |
| 2515 | |
| 2516 | return val; |
| 2517 | } |
| 2518 | |
| 2519 | return 0; |
| 2520 | } |
| 2521 | |
| 2522 | static u64 inherit_vpe_l1_table_from_rd(cpumask_t **mask) |
| 2523 | { |
| 2524 | u32 aff; |
| 2525 | u64 val; |
| 2526 | int cpu; |
| 2527 | |
| 2528 | val = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER); |
| 2529 | aff = compute_common_aff(val); |
| 2530 | |
| 2531 | for_each_possible_cpu(cpu) { |
| 2532 | void __iomem *base = gic_data_rdist_cpu(cpu)->rd_base; |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2533 | |
| 2534 | if (!base || cpu == smp_processor_id()) |
| 2535 | continue; |
| 2536 | |
| 2537 | val = gic_read_typer(base + GICR_TYPER); |
Zenghui Yu | 4bccf1d | 2020-02-06 15:57:09 +0800 | [diff] [blame] | 2538 | if (aff != compute_common_aff(val)) |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2539 | continue; |
| 2540 | |
| 2541 | /* |
| 2542 | * At this point, we have a victim. This particular CPU |
| 2543 | * has already booted, and has an affinity that matches |
| 2544 | * ours wrt CommonLPIAff. Let's use its own VPROPBASER. |
| 2545 | * Make sure we don't write the Z bit in that case. |
| 2546 | */ |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2547 | val = gicr_read_vpropbaser(base + SZ_128K + GICR_VPROPBASER); |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2548 | val &= ~GICR_VPROPBASER_4_1_Z; |
| 2549 | |
Zenghui Yu | 8b718d4 | 2020-02-06 15:57:07 +0800 | [diff] [blame] | 2550 | gic_data_rdist()->vpe_l1_base = gic_data_rdist_cpu(cpu)->vpe_l1_base; |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2551 | *mask = gic_data_rdist_cpu(cpu)->vpe_table_mask; |
| 2552 | |
| 2553 | return val; |
| 2554 | } |
| 2555 | |
| 2556 | return 0; |
| 2557 | } |
| 2558 | |
Zenghui Yu | 4e6437f | 2020-02-06 15:57:08 +0800 | [diff] [blame] | 2559 | static bool allocate_vpe_l2_table(int cpu, u32 id) |
| 2560 | { |
| 2561 | void __iomem *base = gic_data_rdist_cpu(cpu)->rd_base; |
Marc Zyngier | 490d332 | 2020-02-09 22:48:50 +0000 | [diff] [blame] | 2562 | unsigned int psz, esz, idx, npg, gpsz; |
| 2563 | u64 val; |
Zenghui Yu | 4e6437f | 2020-02-06 15:57:08 +0800 | [diff] [blame] | 2564 | struct page *page; |
| 2565 | __le64 *table; |
| 2566 | |
| 2567 | if (!gic_rdists->has_rvpeid) |
| 2568 | return true; |
| 2569 | |
Marc Zyngier | 28d160d | 2020-03-04 20:33:09 +0000 | [diff] [blame] | 2570 | /* Skip non-present CPUs */ |
| 2571 | if (!base) |
| 2572 | return true; |
| 2573 | |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2574 | val = gicr_read_vpropbaser(base + SZ_128K + GICR_VPROPBASER); |
Zenghui Yu | 4e6437f | 2020-02-06 15:57:08 +0800 | [diff] [blame] | 2575 | |
| 2576 | esz = FIELD_GET(GICR_VPROPBASER_4_1_ENTRY_SIZE, val) + 1; |
| 2577 | gpsz = FIELD_GET(GICR_VPROPBASER_4_1_PAGE_SIZE, val); |
| 2578 | npg = FIELD_GET(GICR_VPROPBASER_4_1_SIZE, val) + 1; |
| 2579 | |
| 2580 | switch (gpsz) { |
| 2581 | default: |
| 2582 | WARN_ON(1); |
| 2583 | /* fall through */ |
| 2584 | case GIC_PAGE_SIZE_4K: |
| 2585 | psz = SZ_4K; |
| 2586 | break; |
| 2587 | case GIC_PAGE_SIZE_16K: |
| 2588 | psz = SZ_16K; |
| 2589 | break; |
| 2590 | case GIC_PAGE_SIZE_64K: |
| 2591 | psz = SZ_64K; |
| 2592 | break; |
| 2593 | } |
| 2594 | |
| 2595 | /* Don't allow vpe_id that exceeds single, flat table limit */ |
| 2596 | if (!(val & GICR_VPROPBASER_4_1_INDIRECT)) |
| 2597 | return (id < (npg * psz / (esz * SZ_8))); |
| 2598 | |
| 2599 | /* Compute 1st level table index & check if that exceeds table limit */ |
| 2600 | idx = id >> ilog2(psz / (esz * SZ_8)); |
| 2601 | if (idx >= (npg * psz / GITS_LVL1_ENTRY_SIZE)) |
| 2602 | return false; |
| 2603 | |
| 2604 | table = gic_data_rdist_cpu(cpu)->vpe_l1_base; |
| 2605 | |
| 2606 | /* Allocate memory for 2nd level table */ |
| 2607 | if (!table[idx]) { |
| 2608 | page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(psz)); |
| 2609 | if (!page) |
| 2610 | return false; |
| 2611 | |
| 2612 | /* Flush Lvl2 table to PoC if hw doesn't support coherency */ |
| 2613 | if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK)) |
| 2614 | gic_flush_dcache_to_poc(page_address(page), psz); |
| 2615 | |
| 2616 | table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID); |
| 2617 | |
| 2618 | /* Flush Lvl1 entry to PoC if hw doesn't support coherency */ |
| 2619 | if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK)) |
| 2620 | gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE); |
| 2621 | |
| 2622 | /* Ensure updated table contents are visible to RD hardware */ |
| 2623 | dsb(sy); |
| 2624 | } |
| 2625 | |
| 2626 | return true; |
| 2627 | } |
| 2628 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2629 | static int allocate_vpe_l1_table(void) |
| 2630 | { |
| 2631 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
| 2632 | u64 val, gpsz, npg, pa; |
| 2633 | unsigned int psz = SZ_64K; |
| 2634 | unsigned int np, epp, esz; |
| 2635 | struct page *page; |
| 2636 | |
| 2637 | if (!gic_rdists->has_rvpeid) |
| 2638 | return 0; |
| 2639 | |
| 2640 | /* |
| 2641 | * if VPENDBASER.Valid is set, disable any previously programmed |
| 2642 | * VPE by setting PendingLast while clearing Valid. This has the |
| 2643 | * effect of making sure no doorbell will be generated and we can |
| 2644 | * then safely clear VPROPBASER.Valid. |
| 2645 | */ |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2646 | if (gicr_read_vpendbaser(vlpi_base + GICR_VPENDBASER) & GICR_VPENDBASER_Valid) |
| 2647 | gicr_write_vpendbaser(GICR_VPENDBASER_PendingLast, |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2648 | vlpi_base + GICR_VPENDBASER); |
| 2649 | |
| 2650 | /* |
| 2651 | * If we can inherit the configuration from another RD, let's do |
| 2652 | * so. Otherwise, we have to go through the allocation process. We |
| 2653 | * assume that all RDs have the exact same requirements, as |
| 2654 | * nothing will work otherwise. |
| 2655 | */ |
| 2656 | val = inherit_vpe_l1_table_from_rd(&gic_data_rdist()->vpe_table_mask); |
| 2657 | if (val & GICR_VPROPBASER_4_1_VALID) |
| 2658 | goto out; |
| 2659 | |
| 2660 | gic_data_rdist()->vpe_table_mask = kzalloc(sizeof(cpumask_t), GFP_KERNEL); |
| 2661 | if (!gic_data_rdist()->vpe_table_mask) |
| 2662 | return -ENOMEM; |
| 2663 | |
| 2664 | val = inherit_vpe_l1_table_from_its(); |
| 2665 | if (val & GICR_VPROPBASER_4_1_VALID) |
| 2666 | goto out; |
| 2667 | |
| 2668 | /* First probe the page size */ |
| 2669 | val = FIELD_PREP(GICR_VPROPBASER_4_1_PAGE_SIZE, GIC_PAGE_SIZE_64K); |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2670 | gicr_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
| 2671 | val = gicr_read_vpropbaser(vlpi_base + GICR_VPROPBASER); |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2672 | gpsz = FIELD_GET(GICR_VPROPBASER_4_1_PAGE_SIZE, val); |
| 2673 | esz = FIELD_GET(GICR_VPROPBASER_4_1_ENTRY_SIZE, val); |
| 2674 | |
| 2675 | switch (gpsz) { |
| 2676 | default: |
| 2677 | gpsz = GIC_PAGE_SIZE_4K; |
| 2678 | /* fall through */ |
| 2679 | case GIC_PAGE_SIZE_4K: |
| 2680 | psz = SZ_4K; |
| 2681 | break; |
| 2682 | case GIC_PAGE_SIZE_16K: |
| 2683 | psz = SZ_16K; |
| 2684 | break; |
| 2685 | case GIC_PAGE_SIZE_64K: |
| 2686 | psz = SZ_64K; |
| 2687 | break; |
| 2688 | } |
| 2689 | |
| 2690 | /* |
| 2691 | * Start populating the register from scratch, including RO fields |
| 2692 | * (which we want to print in debug cases...) |
| 2693 | */ |
| 2694 | val = 0; |
| 2695 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_PAGE_SIZE, gpsz); |
| 2696 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_ENTRY_SIZE, esz); |
| 2697 | |
| 2698 | /* How many entries per GIC page? */ |
| 2699 | esz++; |
| 2700 | epp = psz / (esz * SZ_8); |
| 2701 | |
| 2702 | /* |
| 2703 | * If we need more than just a single L1 page, flag the table |
| 2704 | * as indirect and compute the number of required L1 pages. |
| 2705 | */ |
| 2706 | if (epp < ITS_MAX_VPEID) { |
| 2707 | int nl2; |
| 2708 | |
| 2709 | val |= GICR_VPROPBASER_4_1_INDIRECT; |
| 2710 | |
| 2711 | /* Number of L2 pages required to cover the VPEID space */ |
| 2712 | nl2 = DIV_ROUND_UP(ITS_MAX_VPEID, epp); |
| 2713 | |
| 2714 | /* Number of L1 pages to point to the L2 pages */ |
| 2715 | npg = DIV_ROUND_UP(nl2 * SZ_8, psz); |
| 2716 | } else { |
| 2717 | npg = 1; |
| 2718 | } |
| 2719 | |
Zenghui Yu | e88bd31 | 2020-02-06 15:57:06 +0800 | [diff] [blame] | 2720 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_SIZE, npg - 1); |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2721 | |
| 2722 | /* Right, that's the number of CPU pages we need for L1 */ |
| 2723 | np = DIV_ROUND_UP(npg * psz, PAGE_SIZE); |
| 2724 | |
| 2725 | pr_debug("np = %d, npg = %lld, psz = %d, epp = %d, esz = %d\n", |
| 2726 | np, npg, psz, epp, esz); |
| 2727 | page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(np * PAGE_SIZE)); |
| 2728 | if (!page) |
| 2729 | return -ENOMEM; |
| 2730 | |
Zenghui Yu | 8b718d4 | 2020-02-06 15:57:07 +0800 | [diff] [blame] | 2731 | gic_data_rdist()->vpe_l1_base = page_address(page); |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2732 | pa = virt_to_phys(page_address(page)); |
| 2733 | WARN_ON(!IS_ALIGNED(pa, psz)); |
| 2734 | |
| 2735 | val |= FIELD_PREP(GICR_VPROPBASER_4_1_ADDR, pa >> 12); |
| 2736 | val |= GICR_VPROPBASER_RaWb; |
| 2737 | val |= GICR_VPROPBASER_InnerShareable; |
| 2738 | val |= GICR_VPROPBASER_4_1_Z; |
| 2739 | val |= GICR_VPROPBASER_4_1_VALID; |
| 2740 | |
| 2741 | out: |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2742 | gicr_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2743 | cpumask_set_cpu(smp_processor_id(), gic_data_rdist()->vpe_table_mask); |
| 2744 | |
| 2745 | pr_debug("CPU%d: VPROPBASER = %llx %*pbl\n", |
| 2746 | smp_processor_id(), val, |
| 2747 | cpumask_pr_args(gic_data_rdist()->vpe_table_mask)); |
| 2748 | |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2752 | static int its_alloc_collections(struct its_node *its) |
| 2753 | { |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 2754 | int i; |
| 2755 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2756 | its->collections = kcalloc(nr_cpu_ids, sizeof(*its->collections), |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2757 | GFP_KERNEL); |
| 2758 | if (!its->collections) |
| 2759 | return -ENOMEM; |
| 2760 | |
Marc Zyngier | 83559b4 | 2018-06-22 10:52:52 +0100 | [diff] [blame] | 2761 | for (i = 0; i < nr_cpu_ids; i++) |
| 2762 | its->collections[i].target_address = ~0ULL; |
| 2763 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2764 | return 0; |
| 2765 | } |
| 2766 | |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2767 | static struct page *its_allocate_pending_table(gfp_t gfp_flags) |
| 2768 | { |
| 2769 | struct page *pend_page; |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2770 | |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2771 | pend_page = alloc_pages(gfp_flags | __GFP_ZERO, |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2772 | get_order(LPI_PENDBASE_SZ)); |
Marc Zyngier | 7c297a2 | 2016-12-19 18:34:38 +0000 | [diff] [blame] | 2773 | if (!pend_page) |
| 2774 | return NULL; |
| 2775 | |
| 2776 | /* Make sure the GIC will observe the zero-ed page */ |
| 2777 | gic_flush_dcache_to_poc(page_address(pend_page), LPI_PENDBASE_SZ); |
| 2778 | |
| 2779 | return pend_page; |
| 2780 | } |
| 2781 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2782 | static void its_free_pending_table(struct page *pt) |
| 2783 | { |
Marc Zyngier | adaab50 | 2018-07-17 18:06:39 +0100 | [diff] [blame] | 2784 | free_pages((unsigned long)page_address(pt), get_order(LPI_PENDBASE_SZ)); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2787 | /* |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2788 | * Booting with kdump and LPIs enabled is generally fine. Any other |
| 2789 | * case is wrong in the absence of firmware/EFI support. |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2790 | */ |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2791 | static bool enabled_lpis_allowed(void) |
| 2792 | { |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2793 | phys_addr_t addr; |
| 2794 | u64 val; |
Marc Zyngier | c6e2ccb | 2018-06-26 11:21:11 +0100 | [diff] [blame] | 2795 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2796 | /* Check whether the property table is in a reserved region */ |
| 2797 | val = gicr_read_propbaser(gic_data_rdist_rd_base() + GICR_PROPBASER); |
| 2798 | addr = val & GENMASK_ULL(51, 12); |
| 2799 | |
| 2800 | return gic_check_reserved_range(addr, LPI_PROPBASE_SZ); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2801 | } |
| 2802 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2803 | static int __init allocate_lpi_tables(void) |
| 2804 | { |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2805 | u64 val; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2806 | int err, cpu; |
| 2807 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2808 | /* |
| 2809 | * If LPIs are enabled while we run this from the boot CPU, |
| 2810 | * flag the RD tables as pre-allocated if the stars do align. |
| 2811 | */ |
| 2812 | val = readl_relaxed(gic_data_rdist_rd_base() + GICR_CTLR); |
| 2813 | if ((val & GICR_CTLR_ENABLE_LPIS) && enabled_lpis_allowed()) { |
| 2814 | gic_rdists->flags |= (RDIST_FLAGS_RD_TABLES_PREALLOCATED | |
| 2815 | RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING); |
| 2816 | pr_info("GICv3: Using preallocated redistributor tables\n"); |
| 2817 | } |
| 2818 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2819 | err = its_setup_lpi_prop_table(); |
| 2820 | if (err) |
| 2821 | return err; |
| 2822 | |
| 2823 | /* |
| 2824 | * We allocate all the pending tables anyway, as we may have a |
| 2825 | * mix of RDs that have had LPIs enabled, and some that |
| 2826 | * don't. We'll free the unused ones as each CPU comes online. |
| 2827 | */ |
| 2828 | for_each_possible_cpu(cpu) { |
| 2829 | struct page *pend_page; |
| 2830 | |
| 2831 | pend_page = its_allocate_pending_table(GFP_NOWAIT); |
| 2832 | if (!pend_page) { |
| 2833 | pr_err("Failed to allocate PENDBASE for CPU%d\n", cpu); |
| 2834 | return -ENOMEM; |
| 2835 | } |
| 2836 | |
| 2837 | gic_data_rdist_cpu(cpu)->pend_page = pend_page; |
| 2838 | } |
| 2839 | |
| 2840 | return 0; |
| 2841 | } |
| 2842 | |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 2843 | static u64 its_clear_vpend_valid(void __iomem *vlpi_base, u64 clr, u64 set) |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2844 | { |
| 2845 | u32 count = 1000000; /* 1s! */ |
| 2846 | bool clean; |
| 2847 | u64 val; |
| 2848 | |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2849 | val = gicr_read_vpendbaser(vlpi_base + GICR_VPENDBASER); |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2850 | val &= ~GICR_VPENDBASER_Valid; |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 2851 | val &= ~clr; |
| 2852 | val |= set; |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2853 | gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2854 | |
| 2855 | do { |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2856 | val = gicr_read_vpendbaser(vlpi_base + GICR_VPENDBASER); |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2857 | clean = !(val & GICR_VPENDBASER_Dirty); |
| 2858 | if (!clean) { |
| 2859 | count--; |
| 2860 | cpu_relax(); |
| 2861 | udelay(1); |
| 2862 | } |
| 2863 | } while (!clean && count); |
| 2864 | |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 2865 | if (unlikely(val & GICR_VPENDBASER_Dirty)) { |
| 2866 | pr_err_ratelimited("ITS virtual pending table not cleaning\n"); |
| 2867 | val |= GICR_VPENDBASER_PendingLast; |
| 2868 | } |
| 2869 | |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2870 | return val; |
| 2871 | } |
| 2872 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2873 | static void its_cpu_init_lpis(void) |
| 2874 | { |
| 2875 | void __iomem *rbase = gic_data_rdist_rd_base(); |
| 2876 | struct page *pend_page; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2877 | phys_addr_t paddr; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2878 | u64 val, tmp; |
| 2879 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2880 | if (gic_data_rdist()->lpi_enabled) |
| 2881 | return; |
| 2882 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2883 | val = readl_relaxed(rbase + GICR_CTLR); |
| 2884 | if ((gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED) && |
| 2885 | (val & GICR_CTLR_ENABLE_LPIS)) { |
Marc Zyngier | f842ca8 | 2018-07-27 16:03:31 +0100 | [diff] [blame] | 2886 | /* |
| 2887 | * Check that we get the same property table on all |
| 2888 | * RDs. If we don't, this is hopeless. |
| 2889 | */ |
| 2890 | paddr = gicr_read_propbaser(rbase + GICR_PROPBASER); |
| 2891 | paddr &= GENMASK_ULL(51, 12); |
| 2892 | if (WARN_ON(gic_rdists->prop_table_pa != paddr)) |
| 2893 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 2894 | |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2895 | paddr = gicr_read_pendbaser(rbase + GICR_PENDBASER); |
| 2896 | paddr &= GENMASK_ULL(51, 16); |
| 2897 | |
Marc Zyngier | 5e2c9f9 | 2018-07-27 16:23:18 +0100 | [diff] [blame] | 2898 | WARN_ON(!gic_check_reserved_range(paddr, LPI_PENDBASE_SZ)); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2899 | its_free_pending_table(gic_data_rdist()->pend_page); |
| 2900 | gic_data_rdist()->pend_page = NULL; |
| 2901 | |
| 2902 | goto out; |
| 2903 | } |
| 2904 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2905 | pend_page = gic_data_rdist()->pend_page; |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2906 | paddr = page_to_phys(pend_page); |
Marc Zyngier | 3fb68fa | 2018-07-27 16:21:18 +0100 | [diff] [blame] | 2907 | WARN_ON(gic_reserve_range(paddr, LPI_PENDBASE_SZ)); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2908 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2909 | /* set PROPBASE */ |
Marc Zyngier | e1a2e20 | 2018-07-27 14:36:00 +0100 | [diff] [blame] | 2910 | val = (gic_rdists->prop_table_pa | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2911 | GICR_PROPBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2912 | GICR_PROPBASER_RaWaWb | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2913 | ((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK)); |
| 2914 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2915 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
| 2916 | tmp = gicr_read_propbaser(rbase + GICR_PROPBASER); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2917 | |
| 2918 | if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2919 | if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) { |
| 2920 | /* |
| 2921 | * The HW reports non-shareable, we must |
| 2922 | * remove the cacheability attributes as |
| 2923 | * well. |
| 2924 | */ |
| 2925 | val &= ~(GICR_PROPBASER_SHAREABILITY_MASK | |
| 2926 | GICR_PROPBASER_CACHEABILITY_MASK); |
| 2927 | val |= GICR_PROPBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2928 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2929 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2930 | pr_info_once("GIC: using cache flushing for LPI property table\n"); |
| 2931 | gic_rdists->flags |= RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING; |
| 2932 | } |
| 2933 | |
| 2934 | /* set PENDBASE */ |
| 2935 | val = (page_to_phys(pend_page) | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 2936 | GICR_PENDBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 2937 | GICR_PENDBASER_RaWaWb); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2938 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2939 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
| 2940 | tmp = gicr_read_pendbaser(rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2941 | |
| 2942 | if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) { |
| 2943 | /* |
| 2944 | * The HW reports non-shareable, we must remove the |
| 2945 | * cacheability attributes as well. |
| 2946 | */ |
| 2947 | val &= ~(GICR_PENDBASER_SHAREABILITY_MASK | |
| 2948 | GICR_PENDBASER_CACHEABILITY_MASK); |
| 2949 | val |= GICR_PENDBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 2950 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 2951 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2952 | |
| 2953 | /* Enable LPIs */ |
| 2954 | val = readl_relaxed(rbase + GICR_CTLR); |
| 2955 | val |= GICR_CTLR_ENABLE_LPIS; |
| 2956 | writel_relaxed(val, rbase + GICR_CTLR); |
| 2957 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2958 | if (gic_rdists->has_vlpis && !gic_rdists->has_rvpeid) { |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2959 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
| 2960 | |
| 2961 | /* |
| 2962 | * It's possible for CPU to receive VLPIs before it is |
| 2963 | * sheduled as a vPE, especially for the first CPU, and the |
| 2964 | * VLPI with INTID larger than 2^(IDbits+1) will be considered |
| 2965 | * as out of range and dropped by GIC. |
| 2966 | * So we initialize IDbits to known value to avoid VLPI drop. |
| 2967 | */ |
| 2968 | val = (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; |
| 2969 | pr_debug("GICv4: CPU%d: Init IDbits to 0x%llx for GICR_VPROPBASER\n", |
| 2970 | smp_processor_id(), val); |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 2971 | gicr_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2972 | |
| 2973 | /* |
| 2974 | * Also clear Valid bit of GICR_VPENDBASER, in case some |
| 2975 | * ancient programming gets left in and has possibility of |
| 2976 | * corrupting memory. |
| 2977 | */ |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 2978 | val = its_clear_vpend_valid(vlpi_base, 0, 0); |
Heyi Guo | 6479450 | 2019-01-24 21:37:08 +0800 | [diff] [blame] | 2979 | } |
| 2980 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 2981 | if (allocate_vpe_l1_table()) { |
| 2982 | /* |
| 2983 | * If the allocation has failed, we're in massive trouble. |
| 2984 | * Disable direct injection, and pray that no VM was |
| 2985 | * already running... |
| 2986 | */ |
| 2987 | gic_rdists->has_rvpeid = false; |
| 2988 | gic_rdists->has_vlpis = false; |
| 2989 | } |
| 2990 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2991 | /* Make sure the GIC has seen the above */ |
| 2992 | dsb(sy); |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2993 | out: |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2994 | gic_data_rdist()->lpi_enabled = true; |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2995 | pr_info("GICv3: CPU%d: using %s LPI pending table @%pa\n", |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2996 | smp_processor_id(), |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 2997 | gic_data_rdist()->pend_page ? "allocated" : "reserved", |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 2998 | &paddr); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3001 | static void its_cpu_init_collection(struct its_node *its) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3002 | { |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3003 | int cpu = smp_processor_id(); |
| 3004 | u64 target; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3005 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3006 | /* avoid cross node collections and its mapping */ |
| 3007 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 3008 | struct device_node *cpu_node; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3009 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3010 | cpu_node = of_get_cpu_node(cpu, NULL); |
| 3011 | if (its->numa_node != NUMA_NO_NODE && |
| 3012 | its->numa_node != of_node_to_nid(cpu_node)) |
| 3013 | return; |
| 3014 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3015 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3016 | /* |
| 3017 | * We now have to bind each collection to its target |
| 3018 | * redistributor. |
| 3019 | */ |
| 3020 | if (gic_read_typer(its->base + GITS_TYPER) & GITS_TYPER_PTA) { |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3021 | /* |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3022 | * This ITS wants the physical address of the |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3023 | * redistributor. |
| 3024 | */ |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3025 | target = gic_data_rdist()->phys_base; |
| 3026 | } else { |
| 3027 | /* This ITS wants a linear CPU number. */ |
| 3028 | target = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER); |
| 3029 | target = GICR_TYPER_CPU_NUMBER(target) << 16; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3032 | /* Perform collection mapping */ |
| 3033 | its->collections[cpu].target_address = target; |
| 3034 | its->collections[cpu].col_id = cpu; |
| 3035 | |
| 3036 | its_send_mapc(its, &its->collections[cpu], 1); |
| 3037 | its_send_invall(its, &its->collections[cpu]); |
| 3038 | } |
| 3039 | |
| 3040 | static void its_cpu_init_collections(void) |
| 3041 | { |
| 3042 | struct its_node *its; |
| 3043 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3044 | raw_spin_lock(&its_lock); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 3045 | |
| 3046 | list_for_each_entry(its, &its_nodes, entry) |
| 3047 | its_cpu_init_collection(its); |
| 3048 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 3049 | raw_spin_unlock(&its_lock); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 3050 | } |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3051 | |
| 3052 | static struct its_device *its_find_device(struct its_node *its, u32 dev_id) |
| 3053 | { |
| 3054 | struct its_device *its_dev = NULL, *tmp; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3055 | unsigned long flags; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3056 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3057 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3058 | |
| 3059 | list_for_each_entry(tmp, &its->its_device_list, entry) { |
| 3060 | if (tmp->device_id == dev_id) { |
| 3061 | its_dev = tmp; |
| 3062 | break; |
| 3063 | } |
| 3064 | } |
| 3065 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3066 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3067 | |
| 3068 | return its_dev; |
| 3069 | } |
| 3070 | |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 3071 | static struct its_baser *its_get_baser(struct its_node *its, u32 type) |
| 3072 | { |
| 3073 | int i; |
| 3074 | |
| 3075 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
| 3076 | if (GITS_BASER_TYPE(its->tables[i].val) == type) |
| 3077 | return &its->tables[i]; |
| 3078 | } |
| 3079 | |
| 3080 | return NULL; |
| 3081 | } |
| 3082 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3083 | static bool its_alloc_table_entry(struct its_node *its, |
| 3084 | struct its_baser *baser, u32 id) |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3085 | { |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3086 | struct page *page; |
| 3087 | u32 esz, idx; |
| 3088 | __le64 *table; |
| 3089 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3090 | /* Don't allow device id that exceeds single, flat table limit */ |
| 3091 | esz = GITS_BASER_ENTRY_SIZE(baser->val); |
| 3092 | if (!(baser->val & GITS_BASER_INDIRECT)) |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 3093 | return (id < (PAGE_ORDER_TO_SIZE(baser->order) / esz)); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3094 | |
| 3095 | /* Compute 1st level table index & check if that exceeds table limit */ |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 3096 | idx = id >> ilog2(baser->psz / esz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3097 | if (idx >= (PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE)) |
| 3098 | return false; |
| 3099 | |
| 3100 | table = baser->base; |
| 3101 | |
| 3102 | /* Allocate memory for 2nd level table */ |
| 3103 | if (!table[idx]) { |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3104 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, |
| 3105 | get_order(baser->psz)); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3106 | if (!page) |
| 3107 | return false; |
| 3108 | |
| 3109 | /* Flush Lvl2 table to PoC if hw doesn't support coherency */ |
| 3110 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 3111 | gic_flush_dcache_to_poc(page_address(page), baser->psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3112 | |
| 3113 | table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID); |
| 3114 | |
| 3115 | /* Flush Lvl1 entry to PoC if hw doesn't support coherency */ |
| 3116 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 3117 | gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3118 | |
| 3119 | /* Ensure updated table contents are visible to ITS hardware */ |
| 3120 | dsb(sy); |
| 3121 | } |
| 3122 | |
| 3123 | return true; |
| 3124 | } |
| 3125 | |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 3126 | static bool its_alloc_device_table(struct its_node *its, u32 dev_id) |
| 3127 | { |
| 3128 | struct its_baser *baser; |
| 3129 | |
| 3130 | baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE); |
| 3131 | |
| 3132 | /* Don't allow device id that exceeds ITS hardware limit */ |
| 3133 | if (!baser) |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 3134 | return (ilog2(dev_id) < device_ids(its)); |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 3135 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3136 | return its_alloc_table_entry(its, baser, dev_id); |
Marc Zyngier | 70cc81e | 2016-12-19 18:53:02 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3139 | static bool its_alloc_vpe_table(u32 vpe_id) |
| 3140 | { |
| 3141 | struct its_node *its; |
Zenghui Yu | 4e6437f | 2020-02-06 15:57:08 +0800 | [diff] [blame] | 3142 | int cpu; |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3143 | |
| 3144 | /* |
| 3145 | * Make sure the L2 tables are allocated on *all* v4 ITSs. We |
| 3146 | * could try and only do it on ITSs corresponding to devices |
| 3147 | * that have interrupts targeted at this VPE, but the |
| 3148 | * complexity becomes crazy (and you have tons of memory |
| 3149 | * anyway, right?). |
| 3150 | */ |
| 3151 | list_for_each_entry(its, &its_nodes, entry) { |
| 3152 | struct its_baser *baser; |
| 3153 | |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3154 | if (!is_v4(its)) |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3155 | continue; |
| 3156 | |
| 3157 | baser = its_get_baser(its, GITS_BASER_TYPE_VCPU); |
| 3158 | if (!baser) |
| 3159 | return false; |
| 3160 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3161 | if (!its_alloc_table_entry(its, baser, vpe_id)) |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3162 | return false; |
| 3163 | } |
| 3164 | |
Zenghui Yu | 4e6437f | 2020-02-06 15:57:08 +0800 | [diff] [blame] | 3165 | /* Non v4.1? No need to iterate RDs and go back early. */ |
| 3166 | if (!gic_rdists->has_rvpeid) |
| 3167 | return true; |
| 3168 | |
| 3169 | /* |
| 3170 | * Make sure the L2 tables are allocated for all copies of |
| 3171 | * the L1 table on *all* v4.1 RDs. |
| 3172 | */ |
| 3173 | for_each_possible_cpu(cpu) { |
| 3174 | if (!allocate_vpe_l2_table(cpu, vpe_id)) |
| 3175 | return false; |
| 3176 | } |
| 3177 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 3178 | return true; |
| 3179 | } |
| 3180 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3181 | 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] | 3182 | int nvecs, bool alloc_lpis) |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3183 | { |
| 3184 | struct its_device *dev; |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3185 | unsigned long *lpi_map = NULL; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3186 | unsigned long flags; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3187 | u16 *col_map = NULL; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3188 | void *itt; |
| 3189 | int lpi_base; |
| 3190 | int nr_lpis; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 3191 | int nr_ites; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3192 | int sz; |
| 3193 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 3194 | if (!its_alloc_device_table(its, dev_id)) |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 3195 | return NULL; |
| 3196 | |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 3197 | if (WARN_ON(!is_power_of_2(nvecs))) |
| 3198 | nvecs = roundup_pow_of_two(nvecs); |
| 3199 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3200 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 3201 | /* |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 3202 | * Even if the device wants a single LPI, the ITT must be |
| 3203 | * 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] | 3204 | */ |
Marc Zyngier | 147c8f3 | 2018-05-27 16:39:55 +0100 | [diff] [blame] | 3205 | nr_ites = max(2, nvecs); |
Marc Zyngier | ffedbf0 | 2019-11-08 16:57:59 +0000 | [diff] [blame] | 3206 | 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] | 3207 | sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 3208 | itt = kzalloc_node(sz, GFP_KERNEL, its->numa_node); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3209 | if (alloc_lpis) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3210 | lpi_map = its_lpi_alloc(nvecs, &lpi_base, &nr_lpis); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3211 | if (lpi_map) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3212 | col_map = kcalloc(nr_lpis, sizeof(*col_map), |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3213 | GFP_KERNEL); |
| 3214 | } else { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3215 | col_map = kcalloc(nr_ites, sizeof(*col_map), GFP_KERNEL); |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3216 | nr_lpis = 0; |
| 3217 | lpi_base = 0; |
| 3218 | } |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3219 | |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3220 | if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) { |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3221 | kfree(dev); |
| 3222 | kfree(itt); |
| 3223 | kfree(lpi_map); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3224 | kfree(col_map); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3225 | return NULL; |
| 3226 | } |
| 3227 | |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 3228 | gic_flush_dcache_to_poc(itt, sz); |
Marc Zyngier | 5a9a891 | 2015-09-13 12:14:32 +0100 | [diff] [blame] | 3229 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3230 | dev->its = its; |
| 3231 | dev->itt = itt; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 3232 | dev->nr_ites = nr_ites; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3233 | dev->event_map.lpi_map = lpi_map; |
| 3234 | dev->event_map.col_map = col_map; |
| 3235 | dev->event_map.lpi_base = lpi_base; |
| 3236 | dev->event_map.nr_lpis = nr_lpis; |
Marc Zyngier | 11635fa | 2019-11-08 16:58:05 +0000 | [diff] [blame] | 3237 | raw_spin_lock_init(&dev->event_map.vlpi_lock); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3238 | dev->device_id = dev_id; |
| 3239 | INIT_LIST_HEAD(&dev->entry); |
| 3240 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3241 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3242 | list_add(&dev->entry, &its->its_device_list); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3243 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3244 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3245 | /* Map device to its ITT */ |
| 3246 | its_send_mapd(dev, 1); |
| 3247 | |
| 3248 | return dev; |
| 3249 | } |
| 3250 | |
| 3251 | static void its_free_device(struct its_device *its_dev) |
| 3252 | { |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3253 | unsigned long flags; |
| 3254 | |
| 3255 | raw_spin_lock_irqsave(&its_dev->its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3256 | list_del(&its_dev->entry); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 3257 | raw_spin_unlock_irqrestore(&its_dev->its->lock, flags); |
Marc Zyngier | 898aa5c | 2019-11-08 16:57:55 +0000 | [diff] [blame] | 3258 | kfree(its_dev->event_map.col_map); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 3259 | kfree(its_dev->itt); |
| 3260 | kfree(its_dev); |
| 3261 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3262 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3263 | 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] | 3264 | { |
| 3265 | int idx; |
| 3266 | |
Zenghui Yu | 342be10 | 2019-07-27 06:14:22 +0000 | [diff] [blame] | 3267 | /* Find a free LPI region in lpi_map and allocate them. */ |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3268 | idx = bitmap_find_free_region(dev->event_map.lpi_map, |
| 3269 | dev->event_map.nr_lpis, |
| 3270 | get_count_order(nvecs)); |
| 3271 | if (idx < 0) |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3272 | return -ENOSPC; |
| 3273 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3274 | *hwirq = dev->event_map.lpi_base + idx; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3275 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3276 | return 0; |
| 3277 | } |
| 3278 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 3279 | static int its_msi_prepare(struct irq_domain *domain, struct device *dev, |
| 3280 | int nvec, msi_alloc_info_t *info) |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 3281 | { |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3282 | struct its_node *its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3283 | struct its_device *its_dev; |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 3284 | struct msi_domain_info *msi_info; |
| 3285 | u32 dev_id; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3286 | int err = 0; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3287 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 3288 | /* |
Julien Grall | a7c90f5 | 2019-04-18 16:58:14 +0100 | [diff] [blame] | 3289 | * We ignore "dev" entirely, and rely on the dev_id that has |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 3290 | * been passed via the scratchpad. This limits this domain's |
| 3291 | * usefulness to upper layers that definitely know that they |
| 3292 | * are built on top of the ITS. |
| 3293 | */ |
| 3294 | dev_id = info->scratchpad[0].ul; |
| 3295 | |
| 3296 | msi_info = msi_get_domain_info(domain); |
| 3297 | its = msi_info->data; |
| 3298 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3299 | if (!gic_rdists->has_direct_lpi && |
| 3300 | vpe_proxy.dev && |
| 3301 | vpe_proxy.dev->its == its && |
| 3302 | dev_id == vpe_proxy.dev->device_id) { |
| 3303 | /* Bad luck. Get yourself a better implementation */ |
| 3304 | WARN_ONCE(1, "DevId %x clashes with GICv4 VPE proxy device\n", |
| 3305 | dev_id); |
| 3306 | return -EINVAL; |
| 3307 | } |
| 3308 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3309 | mutex_lock(&its->dev_alloc_lock); |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 3310 | its_dev = its_find_device(its, dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 3311 | if (its_dev) { |
| 3312 | /* |
| 3313 | * We already have seen this ID, probably through |
| 3314 | * another alias (PCI bridge of some sort). No need to |
| 3315 | * create the device. |
| 3316 | */ |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3317 | its_dev->shared = true; |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 3318 | pr_debug("Reusing ITT for devID %x\n", dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 3319 | goto out; |
| 3320 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3321 | |
Marc Zyngier | 93f94ea | 2017-08-04 18:37:09 +0100 | [diff] [blame] | 3322 | its_dev = its_create_device(its, dev_id, nvec, true); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3323 | if (!its_dev) { |
| 3324 | err = -ENOMEM; |
| 3325 | goto out; |
| 3326 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3327 | |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 3328 | pr_debug("ITT %d entries, %d bits\n", nvec, ilog2(nvec)); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 3329 | out: |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3330 | mutex_unlock(&its->dev_alloc_lock); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3331 | info->scratchpad[0].ptr = its_dev; |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3332 | return err; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 3335 | static struct msi_domain_ops its_msi_domain_ops = { |
| 3336 | .msi_prepare = its_msi_prepare, |
| 3337 | }; |
| 3338 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3339 | static int its_irq_gic_domain_alloc(struct irq_domain *domain, |
| 3340 | unsigned int virq, |
| 3341 | irq_hw_number_t hwirq) |
| 3342 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 3343 | struct irq_fwspec fwspec; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3344 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 3345 | if (irq_domain_get_of_node(domain->parent)) { |
| 3346 | fwspec.fwnode = domain->parent->fwnode; |
| 3347 | fwspec.param_count = 3; |
| 3348 | fwspec.param[0] = GIC_IRQ_TYPE_LPI; |
| 3349 | fwspec.param[1] = hwirq; |
| 3350 | fwspec.param[2] = IRQ_TYPE_EDGE_RISING; |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 3351 | } else if (is_fwnode_irqchip(domain->parent->fwnode)) { |
| 3352 | fwspec.fwnode = domain->parent->fwnode; |
| 3353 | fwspec.param_count = 2; |
| 3354 | fwspec.param[0] = hwirq; |
| 3355 | fwspec.param[1] = IRQ_TYPE_EDGE_RISING; |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 3356 | } else { |
| 3357 | return -EINVAL; |
| 3358 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3359 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 3360 | return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | static int its_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 3364 | unsigned int nr_irqs, void *args) |
| 3365 | { |
| 3366 | msi_alloc_info_t *info = args; |
| 3367 | struct its_device *its_dev = info->scratchpad[0].ptr; |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 3368 | struct its_node *its = its_dev->its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3369 | irq_hw_number_t hwirq; |
| 3370 | int err; |
| 3371 | int i; |
| 3372 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3373 | err = its_alloc_device_irq(its_dev, nr_irqs, &hwirq); |
| 3374 | if (err) |
| 3375 | return err; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3376 | |
Julien Grall | 35ae7df | 2019-05-01 14:58:21 +0100 | [diff] [blame] | 3377 | err = iommu_dma_prepare_msi(info->desc, its->get_msi_base(its_dev)); |
| 3378 | if (err) |
| 3379 | return err; |
| 3380 | |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3381 | for (i = 0; i < nr_irqs; i++) { |
| 3382 | err = its_irq_gic_domain_alloc(domain, virq + i, hwirq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3383 | if (err) |
| 3384 | return err; |
| 3385 | |
| 3386 | irq_domain_set_hwirq_and_chip(domain, virq + i, |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3387 | hwirq + i, &its_irq_chip, its_dev); |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 3388 | 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] | 3389 | pr_debug("ID:%d pID:%d vID:%d\n", |
Marc Zyngier | 8208d17 | 2019-01-18 14:08:59 +0000 | [diff] [blame] | 3390 | (int)(hwirq + i - its_dev->event_map.lpi_base), |
| 3391 | (int)(hwirq + i), virq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | return 0; |
| 3395 | } |
| 3396 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 3397 | static int its_irq_domain_activate(struct irq_domain *domain, |
Thomas Gleixner | 702cb0a | 2017-12-29 16:59:06 +0100 | [diff] [blame] | 3398 | struct irq_data *d, bool reserve) |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 3399 | { |
| 3400 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 3401 | u32 event = its_get_event_id(d); |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 3402 | const struct cpumask *cpu_mask = cpu_online_mask; |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 3403 | int cpu; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 3404 | |
| 3405 | /* get the cpu_mask of local node */ |
| 3406 | if (its_dev->its->numa_node >= 0) |
| 3407 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 3408 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3409 | /* Bind the LPI to the first possible CPU */ |
Yang Yingliang | c1797b1 | 2018-06-22 10:52:51 +0100 | [diff] [blame] | 3410 | cpu = cpumask_first_and(cpu_mask, cpu_online_mask); |
| 3411 | if (cpu >= nr_cpu_ids) { |
| 3412 | if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) |
| 3413 | return -EINVAL; |
| 3414 | |
| 3415 | cpu = cpumask_first(cpu_online_mask); |
| 3416 | } |
| 3417 | |
Marc Zyngier | 0d224d3 | 2017-08-18 09:39:18 +0100 | [diff] [blame] | 3418 | its_dev->event_map.col_map[event] = cpu; |
| 3419 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3420 | |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 3421 | /* Map the GIC IRQ and event to the device */ |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 3422 | its_send_mapti(its_dev, d->hwirq, event); |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 3423 | return 0; |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | static void its_irq_domain_deactivate(struct irq_domain *domain, |
| 3427 | struct irq_data *d) |
| 3428 | { |
| 3429 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 3430 | u32 event = its_get_event_id(d); |
| 3431 | |
| 3432 | /* Stop the delivery of interrupts */ |
| 3433 | its_send_discard(its_dev, event); |
| 3434 | } |
| 3435 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3436 | static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq, |
| 3437 | unsigned int nr_irqs) |
| 3438 | { |
| 3439 | struct irq_data *d = irq_domain_get_irq_data(domain, virq); |
| 3440 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3441 | struct its_node *its = its_dev->its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3442 | int i; |
| 3443 | |
Marc Zyngier | c9c96e3 | 2019-09-05 14:56:47 +0100 | [diff] [blame] | 3444 | bitmap_release_region(its_dev->event_map.lpi_map, |
| 3445 | its_get_event_id(irq_domain_get_irq_data(domain, virq)), |
| 3446 | get_count_order(nr_irqs)); |
| 3447 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3448 | for (i = 0; i < nr_irqs; i++) { |
| 3449 | struct irq_data *data = irq_domain_get_irq_data(domain, |
| 3450 | virq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3451 | /* Nuke the entry in the domain */ |
Marc Zyngier | 2da3994 | 2014-12-12 10:51:22 +0000 | [diff] [blame] | 3452 | irq_domain_reset_irq_data(data); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3455 | mutex_lock(&its->dev_alloc_lock); |
| 3456 | |
| 3457 | /* |
| 3458 | * If all interrupts have been freed, start mopping the |
| 3459 | * floor. This is conditionned on the device not being shared. |
| 3460 | */ |
| 3461 | if (!its_dev->shared && |
| 3462 | bitmap_empty(its_dev->event_map.lpi_map, |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 3463 | its_dev->event_map.nr_lpis)) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 3464 | its_lpi_free(its_dev->event_map.lpi_map, |
| 3465 | its_dev->event_map.lpi_base, |
| 3466 | its_dev->event_map.nr_lpis); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3467 | |
| 3468 | /* Unmap device/itt */ |
| 3469 | its_send_mapd(its_dev, 0); |
| 3470 | its_free_device(its_dev); |
| 3471 | } |
| 3472 | |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 3473 | mutex_unlock(&its->dev_alloc_lock); |
| 3474 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3475 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 3476 | } |
| 3477 | |
| 3478 | static const struct irq_domain_ops its_domain_ops = { |
| 3479 | .alloc = its_irq_domain_alloc, |
| 3480 | .free = its_irq_domain_free, |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 3481 | .activate = its_irq_domain_activate, |
| 3482 | .deactivate = its_irq_domain_deactivate, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 3483 | }; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 3484 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3485 | /* |
| 3486 | * This is insane. |
| 3487 | * |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3488 | * If a GICv4.0 doesn't implement Direct LPIs (which is extremely |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3489 | * likely), the only way to perform an invalidate is to use a fake |
| 3490 | * device to issue an INV command, implying that the LPI has first |
| 3491 | * been mapped to some event on that device. Since this is not exactly |
| 3492 | * cheap, we try to keep that mapping around as long as possible, and |
| 3493 | * only issue an UNMAP if we're short on available slots. |
| 3494 | * |
| 3495 | * Broken by design(tm). |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3496 | * |
| 3497 | * GICv4.1, on the other hand, mandates that we're able to invalidate |
| 3498 | * by writing to a MMIO register. It doesn't implement the whole of |
| 3499 | * DirectLPI, but that's good enough. And most of the time, we don't |
| 3500 | * even have to invalidate anything, as the redistributor can be told |
| 3501 | * whether to generate a doorbell or not (we thus leave it enabled, |
| 3502 | * always). |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3503 | */ |
| 3504 | static void its_vpe_db_proxy_unmap_locked(struct its_vpe *vpe) |
| 3505 | { |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3506 | /* GICv4.1 doesn't use a proxy, so nothing to do here */ |
| 3507 | if (gic_rdists->has_rvpeid) |
| 3508 | return; |
| 3509 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3510 | /* Already unmapped? */ |
| 3511 | if (vpe->vpe_proxy_event == -1) |
| 3512 | return; |
| 3513 | |
| 3514 | its_send_discard(vpe_proxy.dev, vpe->vpe_proxy_event); |
| 3515 | vpe_proxy.vpes[vpe->vpe_proxy_event] = NULL; |
| 3516 | |
| 3517 | /* |
| 3518 | * We don't track empty slots at all, so let's move the |
| 3519 | * next_victim pointer if we can quickly reuse that slot |
| 3520 | * instead of nuking an existing entry. Not clear that this is |
| 3521 | * always a win though, and this might just generate a ripple |
| 3522 | * effect... Let's just hope VPEs don't migrate too often. |
| 3523 | */ |
| 3524 | if (vpe_proxy.vpes[vpe_proxy.next_victim]) |
| 3525 | vpe_proxy.next_victim = vpe->vpe_proxy_event; |
| 3526 | |
| 3527 | vpe->vpe_proxy_event = -1; |
| 3528 | } |
| 3529 | |
| 3530 | static void its_vpe_db_proxy_unmap(struct its_vpe *vpe) |
| 3531 | { |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3532 | /* GICv4.1 doesn't use a proxy, so nothing to do here */ |
| 3533 | if (gic_rdists->has_rvpeid) |
| 3534 | return; |
| 3535 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3536 | if (!gic_rdists->has_direct_lpi) { |
| 3537 | unsigned long flags; |
| 3538 | |
| 3539 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 3540 | its_vpe_db_proxy_unmap_locked(vpe); |
| 3541 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | static void its_vpe_db_proxy_map_locked(struct its_vpe *vpe) |
| 3546 | { |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3547 | /* GICv4.1 doesn't use a proxy, so nothing to do here */ |
| 3548 | if (gic_rdists->has_rvpeid) |
| 3549 | return; |
| 3550 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3551 | /* Already mapped? */ |
| 3552 | if (vpe->vpe_proxy_event != -1) |
| 3553 | return; |
| 3554 | |
| 3555 | /* This slot was already allocated. Kick the other VPE out. */ |
| 3556 | if (vpe_proxy.vpes[vpe_proxy.next_victim]) |
| 3557 | its_vpe_db_proxy_unmap_locked(vpe_proxy.vpes[vpe_proxy.next_victim]); |
| 3558 | |
| 3559 | /* Map the new VPE instead */ |
| 3560 | vpe_proxy.vpes[vpe_proxy.next_victim] = vpe; |
| 3561 | vpe->vpe_proxy_event = vpe_proxy.next_victim; |
| 3562 | vpe_proxy.next_victim = (vpe_proxy.next_victim + 1) % vpe_proxy.dev->nr_ites; |
| 3563 | |
| 3564 | vpe_proxy.dev->event_map.col_map[vpe->vpe_proxy_event] = vpe->col_idx; |
| 3565 | its_send_mapti(vpe_proxy.dev, vpe->vpe_db_lpi, vpe->vpe_proxy_event); |
| 3566 | } |
| 3567 | |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 3568 | static void its_vpe_db_proxy_move(struct its_vpe *vpe, int from, int to) |
| 3569 | { |
| 3570 | unsigned long flags; |
| 3571 | struct its_collection *target_col; |
| 3572 | |
Marc Zyngier | 0684c70 | 2019-12-24 11:10:30 +0000 | [diff] [blame] | 3573 | /* GICv4.1 doesn't use a proxy, so nothing to do here */ |
| 3574 | if (gic_rdists->has_rvpeid) |
| 3575 | return; |
| 3576 | |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 3577 | if (gic_rdists->has_direct_lpi) { |
| 3578 | void __iomem *rdbase; |
| 3579 | |
| 3580 | rdbase = per_cpu_ptr(gic_rdists->rdist, from)->rd_base; |
| 3581 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_CLRLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 3582 | wait_for_syncr(rdbase); |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 3583 | |
| 3584 | return; |
| 3585 | } |
| 3586 | |
| 3587 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 3588 | |
| 3589 | its_vpe_db_proxy_map_locked(vpe); |
| 3590 | |
| 3591 | target_col = &vpe_proxy.dev->its->collections[to]; |
| 3592 | its_send_movi(vpe_proxy.dev, target_col, vpe->vpe_proxy_event); |
| 3593 | vpe_proxy.dev->event_map.col_map[vpe->vpe_proxy_event] = to; |
| 3594 | |
| 3595 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 3596 | } |
| 3597 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3598 | static int its_vpe_set_affinity(struct irq_data *d, |
| 3599 | const struct cpumask *mask_val, |
| 3600 | bool force) |
| 3601 | { |
| 3602 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 3603 | int from, cpu = cpumask_first(mask_val); |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 3604 | unsigned long flags; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3605 | |
| 3606 | /* |
| 3607 | * Changing affinity is mega expensive, so let's be as lazy as |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3608 | * 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] | 3609 | * into the proxy device, we need to move the doorbell |
| 3610 | * interrupt to its new location. |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 3611 | * |
| 3612 | * Another thing is that changing the affinity of a vPE affects |
| 3613 | * *other interrupts* such as all the vLPIs that are routed to |
| 3614 | * this vPE. This means that the irq_desc lock is not enough to |
| 3615 | * protect us, and that we must ensure nobody samples vpe->col_idx |
| 3616 | * during the update, hence the lock below which must also be |
| 3617 | * taken on any vLPI handling path that evaluates vpe->col_idx. |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3618 | */ |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 3619 | from = vpe_to_cpuid_lock(vpe, &flags); |
| 3620 | if (from == cpu) |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 3621 | goto out; |
Marc Zyngier | 958b90d | 2017-08-18 16:14:17 +0100 | [diff] [blame] | 3622 | |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 3623 | vpe->col_idx = cpu; |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3624 | |
Marc Zyngier | dd3f050 | 2019-12-24 11:10:31 +0000 | [diff] [blame] | 3625 | /* |
| 3626 | * GICv4.1 allows us to skip VMOVP if moving to a cpu whose RD |
| 3627 | * is sharing its VPE table with the current one. |
| 3628 | */ |
| 3629 | if (gic_data_rdist_cpu(cpu)->vpe_table_mask && |
| 3630 | cpumask_test_cpu(from, gic_data_rdist_cpu(cpu)->vpe_table_mask)) |
| 3631 | goto out; |
| 3632 | |
| 3633 | its_send_vmovp(vpe); |
| 3634 | its_vpe_db_proxy_move(vpe, from, cpu); |
| 3635 | |
| 3636 | out: |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 3637 | irq_data_update_effective_affinity(d, cpumask_of(cpu)); |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 3638 | vpe_to_cpuid_unlock(vpe, flags); |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 3639 | |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3640 | return IRQ_SET_MASK_OK_DONE; |
| 3641 | } |
| 3642 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3643 | static void its_vpe_schedule(struct its_vpe *vpe) |
| 3644 | { |
Robin Murphy | 50c3309 | 2018-02-16 16:57:56 +0000 | [diff] [blame] | 3645 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3646 | u64 val; |
| 3647 | |
| 3648 | /* Schedule the VPE */ |
| 3649 | val = virt_to_phys(page_address(vpe->its_vm->vprop_page)) & |
| 3650 | GENMASK_ULL(51, 12); |
| 3651 | val |= (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; |
| 3652 | val |= GICR_VPROPBASER_RaWb; |
| 3653 | val |= GICR_VPROPBASER_InnerShareable; |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 3654 | gicr_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3655 | |
| 3656 | val = virt_to_phys(page_address(vpe->vpt_page)) & |
| 3657 | GENMASK_ULL(51, 16); |
| 3658 | val |= GICR_VPENDBASER_RaWaWb; |
| 3659 | val |= GICR_VPENDBASER_NonShareable; |
| 3660 | /* |
| 3661 | * There is no good way of finding out if the pending table is |
| 3662 | * empty as we can race against the doorbell interrupt very |
| 3663 | * easily. So in the end, vpe->pending_last is only an |
| 3664 | * indication that the vcpu has something pending, not one |
| 3665 | * that the pending table is empty. A good implementation |
| 3666 | * would be able to read its coarse map pretty quickly anyway, |
| 3667 | * making this a tolerable issue. |
| 3668 | */ |
| 3669 | val |= GICR_VPENDBASER_PendingLast; |
| 3670 | val |= vpe->idai ? GICR_VPENDBASER_IDAI : 0; |
| 3671 | val |= GICR_VPENDBASER_Valid; |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 3672 | gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | static void its_vpe_deschedule(struct its_vpe *vpe) |
| 3676 | { |
Robin Murphy | 50c3309 | 2018-02-16 16:57:56 +0000 | [diff] [blame] | 3677 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3678 | u64 val; |
| 3679 | |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 3680 | val = its_clear_vpend_valid(vlpi_base, 0, 0); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3681 | |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 3682 | vpe->idai = !!(val & GICR_VPENDBASER_IDAI); |
| 3683 | vpe->pending_last = !!(val & GICR_VPENDBASER_PendingLast); |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3686 | static void its_vpe_invall(struct its_vpe *vpe) |
| 3687 | { |
| 3688 | struct its_node *its; |
| 3689 | |
| 3690 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 3691 | if (!is_v4(its)) |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3692 | continue; |
| 3693 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 3694 | if (its_list_map && !vpe->its_vm->vlpi_count[its->list_nr]) |
| 3695 | continue; |
| 3696 | |
Marc Zyngier | 3c1ccee | 2017-10-09 13:17:43 +0100 | [diff] [blame] | 3697 | /* |
| 3698 | * Sending a VINVALL to a single ITS is enough, as all |
| 3699 | * we need is to reach the redistributors. |
| 3700 | */ |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3701 | its_send_vinvall(its, vpe); |
Marc Zyngier | 3c1ccee | 2017-10-09 13:17:43 +0100 | [diff] [blame] | 3702 | return; |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3706 | static int its_vpe_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 3707 | { |
| 3708 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3709 | struct its_cmd_info *info = vcpu_info; |
| 3710 | |
| 3711 | switch (info->cmd_type) { |
| 3712 | case SCHEDULE_VPE: |
| 3713 | its_vpe_schedule(vpe); |
| 3714 | return 0; |
| 3715 | |
| 3716 | case DESCHEDULE_VPE: |
| 3717 | its_vpe_deschedule(vpe); |
| 3718 | return 0; |
| 3719 | |
Marc Zyngier | 5e2f764 | 2016-12-20 15:10:50 +0000 | [diff] [blame] | 3720 | case INVALL_VPE: |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 3721 | its_vpe_invall(vpe); |
Marc Zyngier | 5e2f764 | 2016-12-20 15:10:50 +0000 | [diff] [blame] | 3722 | return 0; |
| 3723 | |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3724 | default: |
| 3725 | return -EINVAL; |
| 3726 | } |
| 3727 | } |
| 3728 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3729 | static void its_vpe_send_cmd(struct its_vpe *vpe, |
| 3730 | void (*cmd)(struct its_device *, u32)) |
| 3731 | { |
| 3732 | unsigned long flags; |
| 3733 | |
| 3734 | raw_spin_lock_irqsave(&vpe_proxy.lock, flags); |
| 3735 | |
| 3736 | its_vpe_db_proxy_map_locked(vpe); |
| 3737 | cmd(vpe_proxy.dev, vpe->vpe_proxy_event); |
| 3738 | |
| 3739 | raw_spin_unlock_irqrestore(&vpe_proxy.lock, flags); |
| 3740 | } |
| 3741 | |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3742 | static void its_vpe_send_inv(struct irq_data *d) |
| 3743 | { |
| 3744 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3745 | |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3746 | if (gic_rdists->has_direct_lpi) { |
| 3747 | void __iomem *rdbase; |
| 3748 | |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 3749 | /* Target the redistributor this VPE is currently known on */ |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 3750 | raw_spin_lock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3751 | rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; |
Marc Zyngier | 425c09b | 2019-11-08 16:57:57 +0000 | [diff] [blame] | 3752 | gic_write_lpir(d->parent_data->hwirq, rdbase + GICR_INVLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 3753 | wait_for_syncr(rdbase); |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 3754 | raw_spin_unlock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 3755 | } else { |
| 3756 | its_vpe_send_cmd(vpe, its_send_inv); |
| 3757 | } |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | static void its_vpe_mask_irq(struct irq_data *d) |
| 3761 | { |
| 3762 | /* |
| 3763 | * We need to unmask the LPI, which is described by the parent |
| 3764 | * irq_data. Instead of calling into the parent (which won't |
| 3765 | * exactly do the right thing, let's simply use the |
| 3766 | * parent_data pointer. Yes, I'm naughty. |
| 3767 | */ |
| 3768 | lpi_write_config(d->parent_data, LPI_PROP_ENABLED, 0); |
| 3769 | its_vpe_send_inv(d); |
| 3770 | } |
| 3771 | |
| 3772 | static void its_vpe_unmask_irq(struct irq_data *d) |
| 3773 | { |
| 3774 | /* Same hack as above... */ |
| 3775 | lpi_write_config(d->parent_data, 0, LPI_PROP_ENABLED); |
| 3776 | its_vpe_send_inv(d); |
| 3777 | } |
| 3778 | |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3779 | static int its_vpe_set_irqchip_state(struct irq_data *d, |
| 3780 | enum irqchip_irq_state which, |
| 3781 | bool state) |
| 3782 | { |
| 3783 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3784 | |
| 3785 | if (which != IRQCHIP_STATE_PENDING) |
| 3786 | return -EINVAL; |
| 3787 | |
| 3788 | if (gic_rdists->has_direct_lpi) { |
| 3789 | void __iomem *rdbase; |
| 3790 | |
| 3791 | rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; |
| 3792 | if (state) { |
| 3793 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_SETLPIR); |
| 3794 | } else { |
| 3795 | gic_write_lpir(vpe->vpe_db_lpi, rdbase + GICR_CLRLPIR); |
Marc Zyngier | 2f4f064 | 2019-11-08 16:57:56 +0000 | [diff] [blame] | 3796 | wait_for_syncr(rdbase); |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3797 | } |
| 3798 | } else { |
| 3799 | if (state) |
| 3800 | its_vpe_send_cmd(vpe, its_send_int); |
| 3801 | else |
| 3802 | its_vpe_send_cmd(vpe, its_send_clear); |
| 3803 | } |
| 3804 | |
| 3805 | return 0; |
| 3806 | } |
| 3807 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3808 | static struct irq_chip its_vpe_irq_chip = { |
| 3809 | .name = "GICv4-vpe", |
Marc Zyngier | f6a91da | 2016-12-20 15:20:38 +0000 | [diff] [blame] | 3810 | .irq_mask = its_vpe_mask_irq, |
| 3811 | .irq_unmask = its_vpe_unmask_irq, |
| 3812 | .irq_eoi = irq_chip_eoi_parent, |
Marc Zyngier | 3171a47 | 2016-12-20 15:17:28 +0000 | [diff] [blame] | 3813 | .irq_set_affinity = its_vpe_set_affinity, |
Marc Zyngier | e57a3e28 | 2017-07-31 14:47:24 +0100 | [diff] [blame] | 3814 | .irq_set_irqchip_state = its_vpe_set_irqchip_state, |
Marc Zyngier | e643d80 | 2016-12-20 15:09:31 +0000 | [diff] [blame] | 3815 | .irq_set_vcpu_affinity = its_vpe_set_vcpu_affinity, |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 3816 | }; |
| 3817 | |
Marc Zyngier | d97c97b | 2019-12-24 11:10:33 +0000 | [diff] [blame] | 3818 | static struct its_node *find_4_1_its(void) |
| 3819 | { |
| 3820 | static struct its_node *its = NULL; |
| 3821 | |
| 3822 | if (!its) { |
| 3823 | list_for_each_entry(its, &its_nodes, entry) { |
| 3824 | if (is_v4_1(its)) |
| 3825 | return its; |
| 3826 | } |
| 3827 | |
| 3828 | /* Oops? */ |
| 3829 | its = NULL; |
| 3830 | } |
| 3831 | |
| 3832 | return its; |
| 3833 | } |
| 3834 | |
| 3835 | static void its_vpe_4_1_send_inv(struct irq_data *d) |
| 3836 | { |
| 3837 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3838 | struct its_node *its; |
| 3839 | |
| 3840 | /* |
| 3841 | * GICv4.1 wants doorbells to be invalidated using the |
| 3842 | * INVDB command in order to be broadcast to all RDs. Send |
| 3843 | * it to the first valid ITS, and let the HW do its magic. |
| 3844 | */ |
| 3845 | its = find_4_1_its(); |
| 3846 | if (its) |
| 3847 | its_send_invdb(its, vpe); |
| 3848 | } |
| 3849 | |
| 3850 | static void its_vpe_4_1_mask_irq(struct irq_data *d) |
| 3851 | { |
| 3852 | lpi_write_config(d->parent_data, LPI_PROP_ENABLED, 0); |
| 3853 | its_vpe_4_1_send_inv(d); |
| 3854 | } |
| 3855 | |
| 3856 | static void its_vpe_4_1_unmask_irq(struct irq_data *d) |
| 3857 | { |
| 3858 | lpi_write_config(d->parent_data, 0, LPI_PROP_ENABLED); |
| 3859 | its_vpe_4_1_send_inv(d); |
| 3860 | } |
| 3861 | |
Marc Zyngier | 91bf639 | 2019-12-24 11:10:34 +0000 | [diff] [blame] | 3862 | static void its_vpe_4_1_schedule(struct its_vpe *vpe, |
| 3863 | struct its_cmd_info *info) |
| 3864 | { |
| 3865 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
| 3866 | u64 val = 0; |
| 3867 | |
| 3868 | /* Schedule the VPE */ |
| 3869 | val |= GICR_VPENDBASER_Valid; |
| 3870 | val |= info->g0en ? GICR_VPENDBASER_4_1_VGRP0EN : 0; |
| 3871 | val |= info->g1en ? GICR_VPENDBASER_4_1_VGRP1EN : 0; |
| 3872 | val |= FIELD_PREP(GICR_VPENDBASER_4_1_VPEID, vpe->vpe_id); |
| 3873 | |
Zenghui Yu | 5186a6c | 2020-02-06 15:57:11 +0800 | [diff] [blame] | 3874 | gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); |
Marc Zyngier | 91bf639 | 2019-12-24 11:10:34 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 3877 | static void its_vpe_4_1_deschedule(struct its_vpe *vpe, |
| 3878 | struct its_cmd_info *info) |
| 3879 | { |
| 3880 | void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); |
| 3881 | u64 val; |
| 3882 | |
| 3883 | if (info->req_db) { |
| 3884 | /* |
| 3885 | * vPE is going to block: make the vPE non-resident with |
| 3886 | * PendingLast clear and DB set. The GIC guarantees that if |
| 3887 | * we read-back PendingLast clear, then a doorbell will be |
| 3888 | * delivered when an interrupt comes. |
| 3889 | */ |
| 3890 | val = its_clear_vpend_valid(vlpi_base, |
| 3891 | GICR_VPENDBASER_PendingLast, |
| 3892 | GICR_VPENDBASER_4_1_DB); |
| 3893 | vpe->pending_last = !!(val & GICR_VPENDBASER_PendingLast); |
| 3894 | } else { |
| 3895 | /* |
| 3896 | * We're not blocking, so just make the vPE non-resident |
| 3897 | * with PendingLast set, indicating that we'll be back. |
| 3898 | */ |
| 3899 | val = its_clear_vpend_valid(vlpi_base, |
| 3900 | 0, |
| 3901 | GICR_VPENDBASER_PendingLast); |
| 3902 | vpe->pending_last = true; |
| 3903 | } |
| 3904 | } |
| 3905 | |
Marc Zyngier | b4a4bd0 | 2019-12-24 11:10:36 +0000 | [diff] [blame] | 3906 | static void its_vpe_4_1_invall(struct its_vpe *vpe) |
| 3907 | { |
| 3908 | void __iomem *rdbase; |
| 3909 | u64 val; |
| 3910 | |
| 3911 | val = GICR_INVALLR_V; |
| 3912 | val |= FIELD_PREP(GICR_INVALLR_VPEID, vpe->vpe_id); |
| 3913 | |
| 3914 | /* Target the redistributor this vPE is currently known on */ |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 3915 | raw_spin_lock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); |
Marc Zyngier | b4a4bd0 | 2019-12-24 11:10:36 +0000 | [diff] [blame] | 3916 | rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; |
| 3917 | gic_write_lpir(val, rdbase + GICR_INVALLR); |
Zenghui Yu | b978c25 | 2020-03-04 20:33:11 +0000 | [diff] [blame] | 3918 | |
| 3919 | wait_for_syncr(rdbase); |
Marc Zyngier | 9058a4e | 2020-03-04 20:33:12 +0000 | [diff] [blame] | 3920 | raw_spin_unlock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); |
Marc Zyngier | b4a4bd0 | 2019-12-24 11:10:36 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3923 | static int its_vpe_4_1_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 3924 | { |
Marc Zyngier | 91bf639 | 2019-12-24 11:10:34 +0000 | [diff] [blame] | 3925 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3926 | struct its_cmd_info *info = vcpu_info; |
| 3927 | |
| 3928 | switch (info->cmd_type) { |
| 3929 | case SCHEDULE_VPE: |
Marc Zyngier | 91bf639 | 2019-12-24 11:10:34 +0000 | [diff] [blame] | 3930 | its_vpe_4_1_schedule(vpe, info); |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3931 | return 0; |
| 3932 | |
| 3933 | case DESCHEDULE_VPE: |
Marc Zyngier | e64fab1 | 2019-12-24 11:10:35 +0000 | [diff] [blame] | 3934 | its_vpe_4_1_deschedule(vpe, info); |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3935 | return 0; |
| 3936 | |
| 3937 | case INVALL_VPE: |
Marc Zyngier | b4a4bd0 | 2019-12-24 11:10:36 +0000 | [diff] [blame] | 3938 | its_vpe_4_1_invall(vpe); |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3939 | return 0; |
| 3940 | |
| 3941 | default: |
| 3942 | return -EINVAL; |
| 3943 | } |
| 3944 | } |
| 3945 | |
| 3946 | static struct irq_chip its_vpe_4_1_irq_chip = { |
| 3947 | .name = "GICv4.1-vpe", |
Marc Zyngier | d97c97b | 2019-12-24 11:10:33 +0000 | [diff] [blame] | 3948 | .irq_mask = its_vpe_4_1_mask_irq, |
| 3949 | .irq_unmask = its_vpe_4_1_unmask_irq, |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 3950 | .irq_eoi = irq_chip_eoi_parent, |
| 3951 | .irq_set_affinity = its_vpe_set_affinity, |
| 3952 | .irq_set_vcpu_affinity = its_vpe_4_1_set_vcpu_affinity, |
| 3953 | }; |
| 3954 | |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 3955 | static void its_configure_sgi(struct irq_data *d, bool clear) |
| 3956 | { |
| 3957 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3958 | struct its_cmd_desc desc; |
| 3959 | |
| 3960 | desc.its_vsgi_cmd.vpe = vpe; |
| 3961 | desc.its_vsgi_cmd.sgi = d->hwirq; |
| 3962 | desc.its_vsgi_cmd.priority = vpe->sgi_config[d->hwirq].priority; |
| 3963 | desc.its_vsgi_cmd.enable = vpe->sgi_config[d->hwirq].enabled; |
| 3964 | desc.its_vsgi_cmd.group = vpe->sgi_config[d->hwirq].group; |
| 3965 | desc.its_vsgi_cmd.clear = clear; |
| 3966 | |
| 3967 | /* |
| 3968 | * GICv4.1 allows us to send VSGI commands to any ITS as long as the |
| 3969 | * destination VPE is mapped there. Since we map them eagerly at |
| 3970 | * activation time, we're pretty sure the first GICv4.1 ITS will do. |
| 3971 | */ |
| 3972 | its_send_single_vcommand(find_4_1_its(), its_build_vsgi_cmd, &desc); |
| 3973 | } |
| 3974 | |
Marc Zyngier | b4e8d64 | 2020-03-04 20:33:17 +0000 | [diff] [blame] | 3975 | static void its_sgi_mask_irq(struct irq_data *d) |
| 3976 | { |
| 3977 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3978 | |
| 3979 | vpe->sgi_config[d->hwirq].enabled = false; |
| 3980 | its_configure_sgi(d, false); |
| 3981 | } |
| 3982 | |
| 3983 | static void its_sgi_unmask_irq(struct irq_data *d) |
| 3984 | { |
| 3985 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 3986 | |
| 3987 | vpe->sgi_config[d->hwirq].enabled = true; |
| 3988 | its_configure_sgi(d, false); |
| 3989 | } |
| 3990 | |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 3991 | static int its_sgi_set_affinity(struct irq_data *d, |
| 3992 | const struct cpumask *mask_val, |
| 3993 | bool force) |
| 3994 | { |
| 3995 | /* |
| 3996 | * There is no notion of affinity for virtual SGIs, at least |
| 3997 | * not on the host (since they can only be targetting a vPE). |
| 3998 | * Tell the kernel we've done whatever it asked for. |
| 3999 | */ |
| 4000 | return IRQ_SET_MASK_OK; |
| 4001 | } |
| 4002 | |
Marc Zyngier | 7017ff0 | 2020-03-04 20:33:18 +0000 | [diff] [blame] | 4003 | static int its_sgi_set_irqchip_state(struct irq_data *d, |
| 4004 | enum irqchip_irq_state which, |
| 4005 | bool state) |
| 4006 | { |
| 4007 | if (which != IRQCHIP_STATE_PENDING) |
| 4008 | return -EINVAL; |
| 4009 | |
| 4010 | if (state) { |
| 4011 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 4012 | struct its_node *its = find_4_1_its(); |
| 4013 | u64 val; |
| 4014 | |
| 4015 | val = FIELD_PREP(GITS_SGIR_VPEID, vpe->vpe_id); |
| 4016 | val |= FIELD_PREP(GITS_SGIR_VINTID, d->hwirq); |
| 4017 | writeq_relaxed(val, its->sgir_base + GITS_SGIR - SZ_128K); |
| 4018 | } else { |
| 4019 | its_configure_sgi(d, true); |
| 4020 | } |
| 4021 | |
| 4022 | return 0; |
| 4023 | } |
| 4024 | |
| 4025 | static int its_sgi_get_irqchip_state(struct irq_data *d, |
| 4026 | enum irqchip_irq_state which, bool *val) |
| 4027 | { |
| 4028 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 4029 | void __iomem *base; |
| 4030 | unsigned long flags; |
| 4031 | u32 count = 1000000; /* 1s! */ |
| 4032 | u32 status; |
| 4033 | int cpu; |
| 4034 | |
| 4035 | if (which != IRQCHIP_STATE_PENDING) |
| 4036 | return -EINVAL; |
| 4037 | |
| 4038 | /* |
| 4039 | * Locking galore! We can race against two different events: |
| 4040 | * |
| 4041 | * - Concurent vPE affinity change: we must make sure it cannot |
| 4042 | * happen, or we'll talk to the wrong redistributor. This is |
| 4043 | * identical to what happens with vLPIs. |
| 4044 | * |
| 4045 | * - Concurrent VSGIPENDR access: As it involves accessing two |
| 4046 | * MMIO registers, this must be made atomic one way or another. |
| 4047 | */ |
| 4048 | cpu = vpe_to_cpuid_lock(vpe, &flags); |
| 4049 | raw_spin_lock(&gic_data_rdist_cpu(cpu)->rd_lock); |
| 4050 | base = gic_data_rdist_cpu(cpu)->rd_base + SZ_128K; |
| 4051 | writel_relaxed(vpe->vpe_id, base + GICR_VSGIR); |
| 4052 | do { |
| 4053 | status = readl_relaxed(base + GICR_VSGIPENDR); |
| 4054 | if (!(status & GICR_VSGIPENDR_BUSY)) |
| 4055 | goto out; |
| 4056 | |
| 4057 | count--; |
| 4058 | if (!count) { |
| 4059 | pr_err_ratelimited("Unable to get SGI status\n"); |
| 4060 | goto out; |
| 4061 | } |
| 4062 | cpu_relax(); |
| 4063 | udelay(1); |
| 4064 | } while (count); |
| 4065 | |
| 4066 | out: |
| 4067 | raw_spin_unlock(&gic_data_rdist_cpu(cpu)->rd_lock); |
| 4068 | vpe_to_cpuid_unlock(vpe, flags); |
| 4069 | |
| 4070 | if (!count) |
| 4071 | return -ENXIO; |
| 4072 | |
| 4073 | *val = !!(status & (1 << d->hwirq)); |
| 4074 | |
| 4075 | return 0; |
| 4076 | } |
| 4077 | |
Marc Zyngier | 05d32df | 2020-03-04 20:33:19 +0000 | [diff] [blame] | 4078 | static int its_sgi_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) |
| 4079 | { |
| 4080 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 4081 | struct its_cmd_info *info = vcpu_info; |
| 4082 | |
| 4083 | switch (info->cmd_type) { |
| 4084 | case PROP_UPDATE_VSGI: |
| 4085 | vpe->sgi_config[d->hwirq].priority = info->priority; |
| 4086 | vpe->sgi_config[d->hwirq].group = info->group; |
| 4087 | its_configure_sgi(d, false); |
| 4088 | return 0; |
| 4089 | |
| 4090 | default: |
| 4091 | return -EINVAL; |
| 4092 | } |
| 4093 | } |
| 4094 | |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 4095 | static struct irq_chip its_sgi_irq_chip = { |
| 4096 | .name = "GICv4.1-sgi", |
Marc Zyngier | b4e8d64 | 2020-03-04 20:33:17 +0000 | [diff] [blame] | 4097 | .irq_mask = its_sgi_mask_irq, |
| 4098 | .irq_unmask = its_sgi_unmask_irq, |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 4099 | .irq_set_affinity = its_sgi_set_affinity, |
Marc Zyngier | 7017ff0 | 2020-03-04 20:33:18 +0000 | [diff] [blame] | 4100 | .irq_set_irqchip_state = its_sgi_set_irqchip_state, |
| 4101 | .irq_get_irqchip_state = its_sgi_get_irqchip_state, |
Marc Zyngier | 05d32df | 2020-03-04 20:33:19 +0000 | [diff] [blame] | 4102 | .irq_set_vcpu_affinity = its_sgi_set_vcpu_affinity, |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 4103 | }; |
| 4104 | |
| 4105 | static int its_sgi_irq_domain_alloc(struct irq_domain *domain, |
| 4106 | unsigned int virq, unsigned int nr_irqs, |
| 4107 | void *args) |
| 4108 | { |
| 4109 | struct its_vpe *vpe = args; |
| 4110 | int i; |
| 4111 | |
| 4112 | /* Yes, we do want 16 SGIs */ |
| 4113 | WARN_ON(nr_irqs != 16); |
| 4114 | |
| 4115 | for (i = 0; i < 16; i++) { |
| 4116 | vpe->sgi_config[i].priority = 0; |
| 4117 | vpe->sgi_config[i].enabled = false; |
| 4118 | vpe->sgi_config[i].group = false; |
| 4119 | |
| 4120 | irq_domain_set_hwirq_and_chip(domain, virq + i, i, |
| 4121 | &its_sgi_irq_chip, vpe); |
| 4122 | irq_set_status_flags(virq + i, IRQ_DISABLE_UNLAZY); |
| 4123 | } |
| 4124 | |
| 4125 | return 0; |
| 4126 | } |
| 4127 | |
| 4128 | static void its_sgi_irq_domain_free(struct irq_domain *domain, |
| 4129 | unsigned int virq, |
| 4130 | unsigned int nr_irqs) |
| 4131 | { |
| 4132 | /* Nothing to do */ |
| 4133 | } |
| 4134 | |
| 4135 | static int its_sgi_irq_domain_activate(struct irq_domain *domain, |
| 4136 | struct irq_data *d, bool reserve) |
| 4137 | { |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 4138 | /* Write out the initial SGI configuration */ |
| 4139 | its_configure_sgi(d, false); |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 4140 | return 0; |
| 4141 | } |
| 4142 | |
| 4143 | static void its_sgi_irq_domain_deactivate(struct irq_domain *domain, |
| 4144 | struct irq_data *d) |
| 4145 | { |
Marc Zyngier | e252cf8 | 2020-03-04 20:33:16 +0000 | [diff] [blame] | 4146 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
| 4147 | |
| 4148 | /* |
| 4149 | * The VSGI command is awkward: |
| 4150 | * |
| 4151 | * - To change the configuration, CLEAR must be set to false, |
| 4152 | * leaving the pending bit unchanged. |
| 4153 | * - To clear the pending bit, CLEAR must be set to true, leaving |
| 4154 | * the configuration unchanged. |
| 4155 | * |
| 4156 | * You just can't do both at once, hence the two commands below. |
| 4157 | */ |
| 4158 | vpe->sgi_config[d->hwirq].enabled = false; |
| 4159 | its_configure_sgi(d, false); |
| 4160 | its_configure_sgi(d, true); |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | static const struct irq_domain_ops its_sgi_domain_ops = { |
| 4164 | .alloc = its_sgi_irq_domain_alloc, |
| 4165 | .free = its_sgi_irq_domain_free, |
| 4166 | .activate = its_sgi_irq_domain_activate, |
| 4167 | .deactivate = its_sgi_irq_domain_deactivate, |
| 4168 | }; |
| 4169 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4170 | static int its_vpe_id_alloc(void) |
| 4171 | { |
Shanker Donthineni | 32bd44d | 2017-10-07 15:43:48 -0500 | [diff] [blame] | 4172 | 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] | 4173 | } |
| 4174 | |
| 4175 | static void its_vpe_id_free(u16 id) |
| 4176 | { |
| 4177 | ida_simple_remove(&its_vpeid_ida, id); |
| 4178 | } |
| 4179 | |
| 4180 | static int its_vpe_init(struct its_vpe *vpe) |
| 4181 | { |
| 4182 | struct page *vpt_page; |
| 4183 | int vpe_id; |
| 4184 | |
| 4185 | /* Allocate vpe_id */ |
| 4186 | vpe_id = its_vpe_id_alloc(); |
| 4187 | if (vpe_id < 0) |
| 4188 | return vpe_id; |
| 4189 | |
| 4190 | /* Allocate VPT */ |
| 4191 | vpt_page = its_allocate_pending_table(GFP_KERNEL); |
| 4192 | if (!vpt_page) { |
| 4193 | its_vpe_id_free(vpe_id); |
| 4194 | return -ENOMEM; |
| 4195 | } |
| 4196 | |
| 4197 | if (!its_alloc_vpe_table(vpe_id)) { |
| 4198 | its_vpe_id_free(vpe_id); |
Nianyao Tang | 34f8eb9 | 2019-07-26 17:32:57 +0800 | [diff] [blame] | 4199 | its_free_pending_table(vpt_page); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4200 | return -ENOMEM; |
| 4201 | } |
| 4202 | |
Marc Zyngier | f3a05921 | 2020-03-04 20:33:10 +0000 | [diff] [blame] | 4203 | raw_spin_lock_init(&vpe->vpe_lock); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4204 | vpe->vpe_id = vpe_id; |
| 4205 | vpe->vpt_page = vpt_page; |
Marc Zyngier | 64edfaa | 2019-12-24 11:10:29 +0000 | [diff] [blame] | 4206 | if (gic_rdists->has_rvpeid) |
| 4207 | atomic_set(&vpe->vmapp_count, 0); |
| 4208 | else |
| 4209 | vpe->vpe_proxy_event = -1; |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4210 | |
| 4211 | return 0; |
| 4212 | } |
| 4213 | |
| 4214 | static void its_vpe_teardown(struct its_vpe *vpe) |
| 4215 | { |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 4216 | its_vpe_db_proxy_unmap(vpe); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4217 | its_vpe_id_free(vpe->vpe_id); |
| 4218 | its_free_pending_table(vpe->vpt_page); |
| 4219 | } |
| 4220 | |
| 4221 | static void its_vpe_irq_domain_free(struct irq_domain *domain, |
| 4222 | unsigned int virq, |
| 4223 | unsigned int nr_irqs) |
| 4224 | { |
| 4225 | struct its_vm *vm = domain->host_data; |
| 4226 | int i; |
| 4227 | |
| 4228 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 4229 | |
| 4230 | for (i = 0; i < nr_irqs; i++) { |
| 4231 | struct irq_data *data = irq_domain_get_irq_data(domain, |
| 4232 | virq + i); |
| 4233 | struct its_vpe *vpe = irq_data_get_irq_chip_data(data); |
| 4234 | |
| 4235 | BUG_ON(vm != vpe->its_vm); |
| 4236 | |
| 4237 | clear_bit(data->hwirq, vm->db_bitmap); |
| 4238 | its_vpe_teardown(vpe); |
| 4239 | irq_domain_reset_irq_data(data); |
| 4240 | } |
| 4241 | |
| 4242 | if (bitmap_empty(vm->db_bitmap, vm->nr_db_lpis)) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 4243 | 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] | 4244 | its_free_prop_table(vm->vprop_page); |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 4249 | unsigned int nr_irqs, void *args) |
| 4250 | { |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 4251 | struct irq_chip *irqchip = &its_vpe_irq_chip; |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4252 | struct its_vm *vm = args; |
| 4253 | unsigned long *bitmap; |
| 4254 | struct page *vprop_page; |
| 4255 | int base, nr_ids, i, err = 0; |
| 4256 | |
| 4257 | BUG_ON(!vm); |
| 4258 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 4259 | 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] | 4260 | if (!bitmap) |
| 4261 | return -ENOMEM; |
| 4262 | |
| 4263 | if (nr_ids < nr_irqs) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 4264 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4265 | return -ENOMEM; |
| 4266 | } |
| 4267 | |
| 4268 | vprop_page = its_allocate_prop_table(GFP_KERNEL); |
| 4269 | if (!vprop_page) { |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 4270 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4271 | return -ENOMEM; |
| 4272 | } |
| 4273 | |
| 4274 | vm->db_bitmap = bitmap; |
| 4275 | vm->db_lpi_base = base; |
| 4276 | vm->nr_db_lpis = nr_ids; |
| 4277 | vm->vprop_page = vprop_page; |
| 4278 | |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 4279 | if (gic_rdists->has_rvpeid) |
| 4280 | irqchip = &its_vpe_4_1_irq_chip; |
| 4281 | |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4282 | for (i = 0; i < nr_irqs; i++) { |
| 4283 | vm->vpes[i]->vpe_db_lpi = base + i; |
| 4284 | err = its_vpe_init(vm->vpes[i]); |
| 4285 | if (err) |
| 4286 | break; |
| 4287 | err = its_irq_gic_domain_alloc(domain, virq + i, |
| 4288 | vm->vpes[i]->vpe_db_lpi); |
| 4289 | if (err) |
| 4290 | break; |
| 4291 | irq_domain_set_hwirq_and_chip(domain, virq + i, i, |
Marc Zyngier | 29c647f | 2019-12-24 11:10:32 +0000 | [diff] [blame] | 4292 | irqchip, vm->vpes[i]); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4293 | set_bit(i, bitmap); |
| 4294 | } |
| 4295 | |
| 4296 | if (err) { |
| 4297 | if (i > 0) |
| 4298 | its_vpe_irq_domain_free(domain, virq, i - 1); |
| 4299 | |
Marc Zyngier | 38dd7c4 | 2018-05-27 17:03:03 +0100 | [diff] [blame] | 4300 | its_lpi_free(bitmap, base, nr_ids); |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4301 | its_free_prop_table(vprop_page); |
| 4302 | } |
| 4303 | |
| 4304 | return err; |
| 4305 | } |
| 4306 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 4307 | static int its_vpe_irq_domain_activate(struct irq_domain *domain, |
Thomas Gleixner | 702cb0a | 2017-12-29 16:59:06 +0100 | [diff] [blame] | 4308 | struct irq_data *d, bool reserve) |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4309 | { |
| 4310 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 4311 | struct its_node *its; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4312 | |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 4313 | /* |
| 4314 | * If we use the list map, we issue VMAPP on demand... Unless |
| 4315 | * we're on a GICv4.1 and we eagerly map the VPE on all ITSs |
| 4316 | * so that VSGIs can work. |
| 4317 | */ |
| 4318 | if (!gic_requires_eager_mapping()) |
Marc Zyngier | 6ef930f | 2017-11-07 10:04:38 +0000 | [diff] [blame] | 4319 | return 0; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4320 | |
| 4321 | /* Map the VPE to the first possible CPU */ |
| 4322 | vpe->col_idx = cpumask_first(cpu_online_mask); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 4323 | |
| 4324 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4325 | if (!is_v4(its)) |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 4326 | continue; |
| 4327 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 4328 | its_send_vmapp(its, vpe, true); |
Marc Zyngier | 40619a2 | 2017-10-08 15:16:09 +0100 | [diff] [blame] | 4329 | its_send_vinvall(its, vpe); |
| 4330 | } |
| 4331 | |
Marc Zyngier | 44c4c25 | 2017-10-19 10:11:34 +0100 | [diff] [blame] | 4332 | irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); |
| 4333 | |
Thomas Gleixner | 7249164 | 2017-09-13 23:29:10 +0200 | [diff] [blame] | 4334 | return 0; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | static void its_vpe_irq_domain_deactivate(struct irq_domain *domain, |
| 4338 | struct irq_data *d) |
| 4339 | { |
| 4340 | struct its_vpe *vpe = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 4341 | struct its_node *its; |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4342 | |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 4343 | /* |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 4344 | * If we use the list map on GICv4.0, we unmap the VPE once no |
| 4345 | * VLPIs are associated with the VM. |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 4346 | */ |
Marc Zyngier | 009384b | 2020-03-04 20:33:23 +0000 | [diff] [blame^] | 4347 | if (!gic_requires_eager_mapping()) |
Marc Zyngier | 2247e1b | 2017-10-08 18:50:36 +0100 | [diff] [blame] | 4348 | return; |
| 4349 | |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 4350 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4351 | if (!is_v4(its)) |
Marc Zyngier | 75fd951 | 2017-10-08 18:46:39 +0100 | [diff] [blame] | 4352 | continue; |
| 4353 | |
| 4354 | its_send_vmapp(its, vpe, false); |
| 4355 | } |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4358 | static const struct irq_domain_ops its_vpe_domain_ops = { |
Marc Zyngier | 7d75bbb | 2016-12-20 13:55:54 +0000 | [diff] [blame] | 4359 | .alloc = its_vpe_irq_domain_alloc, |
| 4360 | .free = its_vpe_irq_domain_free, |
Marc Zyngier | eb78192 | 2016-12-20 14:47:05 +0000 | [diff] [blame] | 4361 | .activate = its_vpe_irq_domain_activate, |
| 4362 | .deactivate = its_vpe_irq_domain_deactivate, |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4363 | }; |
| 4364 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 4365 | static int its_force_quiescent(void __iomem *base) |
| 4366 | { |
| 4367 | u32 count = 1000000; /* 1s */ |
| 4368 | u32 val; |
| 4369 | |
| 4370 | val = readl_relaxed(base + GITS_CTLR); |
David Daney | 7611da8 | 2016-08-18 15:41:58 -0700 | [diff] [blame] | 4371 | /* |
| 4372 | * GIC architecture specification requires the ITS to be both |
| 4373 | * disabled and quiescent for writes to GITS_BASER<n> or |
| 4374 | * GITS_CBASER to not have UNPREDICTABLE results. |
| 4375 | */ |
| 4376 | if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE)) |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 4377 | return 0; |
| 4378 | |
| 4379 | /* Disable the generation of all interrupts to this ITS */ |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 4380 | val &= ~(GITS_CTLR_ENABLE | GITS_CTLR_ImDe); |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 4381 | writel_relaxed(val, base + GITS_CTLR); |
| 4382 | |
| 4383 | /* Poll GITS_CTLR and wait until ITS becomes quiescent */ |
| 4384 | while (1) { |
| 4385 | val = readl_relaxed(base + GITS_CTLR); |
| 4386 | if (val & GITS_CTLR_QUIESCENT) |
| 4387 | return 0; |
| 4388 | |
| 4389 | count--; |
| 4390 | if (!count) |
| 4391 | return -EBUSY; |
| 4392 | |
| 4393 | cpu_relax(); |
| 4394 | udelay(1); |
| 4395 | } |
| 4396 | } |
| 4397 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4398 | static bool __maybe_unused its_enable_quirk_cavium_22375(void *data) |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 4399 | { |
| 4400 | struct its_node *its = data; |
| 4401 | |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 4402 | /* erratum 22375: only alloc 8MB table size (20 bits) */ |
| 4403 | its->typer &= ~GITS_TYPER_DEVBITS; |
| 4404 | its->typer |= FIELD_PREP(GITS_TYPER_DEVBITS, 20 - 1); |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 4405 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_22375; |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4406 | |
| 4407 | return true; |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 4408 | } |
| 4409 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4410 | static bool __maybe_unused its_enable_quirk_cavium_23144(void *data) |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 4411 | { |
| 4412 | struct its_node *its = data; |
| 4413 | |
| 4414 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_23144; |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4415 | |
| 4416 | return true; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 4417 | } |
| 4418 | |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4419 | static bool __maybe_unused its_enable_quirk_qdf2400_e0065(void *data) |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 4420 | { |
| 4421 | struct its_node *its = data; |
| 4422 | |
| 4423 | /* On QDF2400, the size of the ITE is 16Bytes */ |
Marc Zyngier | ffedbf0 | 2019-11-08 16:57:59 +0000 | [diff] [blame] | 4424 | its->typer &= ~GITS_TYPER_ITT_ENTRY_SIZE; |
| 4425 | its->typer |= FIELD_PREP(GITS_TYPER_ITT_ENTRY_SIZE, 16 - 1); |
Ard Biesheuvel | 9d111d4 | 2017-10-17 17:55:55 +0100 | [diff] [blame] | 4426 | |
| 4427 | return true; |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 4428 | } |
| 4429 | |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 4430 | static u64 its_irq_get_msi_base_pre_its(struct its_device *its_dev) |
| 4431 | { |
| 4432 | struct its_node *its = its_dev->its; |
| 4433 | |
| 4434 | /* |
| 4435 | * The Socionext Synquacer SoC has a so-called 'pre-ITS', |
| 4436 | * which maps 32-bit writes targeted at a separate window of |
| 4437 | * size '4 << device_id_bits' onto writes to GITS_TRANSLATER |
| 4438 | * with device ID taken from bits [device_id_bits + 1:2] of |
| 4439 | * the window offset. |
| 4440 | */ |
| 4441 | return its->pre_its_base + (its_dev->device_id << 2); |
| 4442 | } |
| 4443 | |
| 4444 | static bool __maybe_unused its_enable_quirk_socionext_synquacer(void *data) |
| 4445 | { |
| 4446 | struct its_node *its = data; |
| 4447 | u32 pre_its_window[2]; |
| 4448 | u32 ids; |
| 4449 | |
| 4450 | if (!fwnode_property_read_u32_array(its->fwnode_handle, |
| 4451 | "socionext,synquacer-pre-its", |
| 4452 | pre_its_window, |
| 4453 | ARRAY_SIZE(pre_its_window))) { |
| 4454 | |
| 4455 | its->pre_its_base = pre_its_window[0]; |
| 4456 | its->get_msi_base = its_irq_get_msi_base_pre_its; |
| 4457 | |
| 4458 | ids = ilog2(pre_its_window[1]) - 2; |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 4459 | if (device_ids(its) > ids) { |
| 4460 | its->typer &= ~GITS_TYPER_DEVBITS; |
| 4461 | its->typer |= FIELD_PREP(GITS_TYPER_DEVBITS, ids - 1); |
| 4462 | } |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 4463 | |
| 4464 | /* the pre-ITS breaks isolation, so disable MSI remapping */ |
| 4465 | its->msi_domain_flags &= ~IRQ_DOMAIN_FLAG_MSI_REMAP; |
| 4466 | return true; |
| 4467 | } |
| 4468 | return false; |
| 4469 | } |
| 4470 | |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 4471 | static bool __maybe_unused its_enable_quirk_hip07_161600802(void *data) |
| 4472 | { |
| 4473 | struct its_node *its = data; |
| 4474 | |
| 4475 | /* |
| 4476 | * Hip07 insists on using the wrong address for the VLPI |
| 4477 | * page. Trick it into doing the right thing... |
| 4478 | */ |
| 4479 | its->vlpi_redist_offset = SZ_128K; |
| 4480 | return true; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 4481 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4482 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 4483 | static const struct gic_quirk its_quirks[] = { |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 4484 | #ifdef CONFIG_CAVIUM_ERRATUM_22375 |
| 4485 | { |
| 4486 | .desc = "ITS: Cavium errata 22375, 24313", |
| 4487 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 4488 | .mask = 0xffff0fff, |
| 4489 | .init = its_enable_quirk_cavium_22375, |
| 4490 | }, |
| 4491 | #endif |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 4492 | #ifdef CONFIG_CAVIUM_ERRATUM_23144 |
| 4493 | { |
| 4494 | .desc = "ITS: Cavium erratum 23144", |
| 4495 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 4496 | .mask = 0xffff0fff, |
| 4497 | .init = its_enable_quirk_cavium_23144, |
| 4498 | }, |
| 4499 | #endif |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 4500 | #ifdef CONFIG_QCOM_QDF2400_ERRATUM_0065 |
| 4501 | { |
| 4502 | .desc = "ITS: QDF2400 erratum 0065", |
| 4503 | .iidr = 0x00001070, /* QDF2400 ITS rev 1.x */ |
| 4504 | .mask = 0xffffffff, |
| 4505 | .init = its_enable_quirk_qdf2400_e0065, |
| 4506 | }, |
| 4507 | #endif |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 4508 | #ifdef CONFIG_SOCIONEXT_SYNQUACER_PREITS |
| 4509 | { |
| 4510 | /* |
| 4511 | * The Socionext Synquacer SoC incorporates ARM's own GIC-500 |
| 4512 | * implementation, but with a 'pre-ITS' added that requires |
| 4513 | * special handling in software. |
| 4514 | */ |
| 4515 | .desc = "ITS: Socionext Synquacer pre-ITS", |
| 4516 | .iidr = 0x0001143b, |
| 4517 | .mask = 0xffffffff, |
| 4518 | .init = its_enable_quirk_socionext_synquacer, |
| 4519 | }, |
| 4520 | #endif |
Marc Zyngier | 5c9a882 | 2017-07-28 21:20:37 +0100 | [diff] [blame] | 4521 | #ifdef CONFIG_HISILICON_ERRATUM_161600802 |
| 4522 | { |
| 4523 | .desc = "ITS: Hip07 erratum 161600802", |
| 4524 | .iidr = 0x00000004, |
| 4525 | .mask = 0xffffffff, |
| 4526 | .init = its_enable_quirk_hip07_161600802, |
| 4527 | }, |
| 4528 | #endif |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 4529 | { |
| 4530 | } |
| 4531 | }; |
| 4532 | |
| 4533 | static void its_enable_quirks(struct its_node *its) |
| 4534 | { |
| 4535 | u32 iidr = readl_relaxed(its->base + GITS_IIDR); |
| 4536 | |
| 4537 | gic_enable_quirks(iidr, its_quirks, its); |
| 4538 | } |
| 4539 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4540 | static int its_save_disable(void) |
| 4541 | { |
| 4542 | struct its_node *its; |
| 4543 | int err = 0; |
| 4544 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4545 | raw_spin_lock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4546 | list_for_each_entry(its, &its_nodes, entry) { |
| 4547 | void __iomem *base; |
| 4548 | |
| 4549 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 4550 | continue; |
| 4551 | |
| 4552 | base = its->base; |
| 4553 | its->ctlr_save = readl_relaxed(base + GITS_CTLR); |
| 4554 | err = its_force_quiescent(base); |
| 4555 | if (err) { |
| 4556 | pr_err("ITS@%pa: failed to quiesce: %d\n", |
| 4557 | &its->phys_base, err); |
| 4558 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
| 4559 | goto err; |
| 4560 | } |
| 4561 | |
| 4562 | its->cbaser_save = gits_read_cbaser(base + GITS_CBASER); |
| 4563 | } |
| 4564 | |
| 4565 | err: |
| 4566 | if (err) { |
| 4567 | list_for_each_entry_continue_reverse(its, &its_nodes, entry) { |
| 4568 | void __iomem *base; |
| 4569 | |
| 4570 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 4571 | continue; |
| 4572 | |
| 4573 | base = its->base; |
| 4574 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
| 4575 | } |
| 4576 | } |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4577 | raw_spin_unlock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4578 | |
| 4579 | return err; |
| 4580 | } |
| 4581 | |
| 4582 | static void its_restore_enable(void) |
| 4583 | { |
| 4584 | struct its_node *its; |
| 4585 | int ret; |
| 4586 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4587 | raw_spin_lock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4588 | list_for_each_entry(its, &its_nodes, entry) { |
| 4589 | void __iomem *base; |
| 4590 | int i; |
| 4591 | |
| 4592 | if (!(its->flags & ITS_FLAGS_SAVE_SUSPEND_STATE)) |
| 4593 | continue; |
| 4594 | |
| 4595 | base = its->base; |
| 4596 | |
| 4597 | /* |
| 4598 | * Make sure that the ITS is disabled. If it fails to quiesce, |
| 4599 | * don't restore it since writing to CBASER or BASER<n> |
| 4600 | * registers is undefined according to the GIC v3 ITS |
| 4601 | * Specification. |
| 4602 | */ |
| 4603 | ret = its_force_quiescent(base); |
| 4604 | if (ret) { |
| 4605 | pr_err("ITS@%pa: failed to quiesce on resume: %d\n", |
| 4606 | &its->phys_base, ret); |
| 4607 | continue; |
| 4608 | } |
| 4609 | |
| 4610 | gits_write_cbaser(its->cbaser_save, base + GITS_CBASER); |
| 4611 | |
| 4612 | /* |
| 4613 | * Writing CBASER resets CREADR to 0, so make CWRITER and |
| 4614 | * cmd_write line up with it. |
| 4615 | */ |
| 4616 | its->cmd_write = its->cmd_base; |
| 4617 | gits_write_cwriter(0, base + GITS_CWRITER); |
| 4618 | |
| 4619 | /* Restore GITS_BASER from the value cache. */ |
| 4620 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
| 4621 | struct its_baser *baser = &its->tables[i]; |
| 4622 | |
| 4623 | if (!(baser->val & GITS_BASER_VALID)) |
| 4624 | continue; |
| 4625 | |
| 4626 | its_write_baser(its, baser, baser->val); |
| 4627 | } |
| 4628 | writel_relaxed(its->ctlr_save, base + GITS_CTLR); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 4629 | |
| 4630 | /* |
| 4631 | * Reinit the collection if it's stored in the ITS. This is |
| 4632 | * indicated by the col_id being less than the HCC field. |
| 4633 | * CID < HCC as specified in the GIC v3 Documentation. |
| 4634 | */ |
| 4635 | if (its->collections[smp_processor_id()].col_id < |
| 4636 | GITS_TYPER_HCC(gic_read_typer(base + GITS_TYPER))) |
| 4637 | its_cpu_init_collection(its); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4638 | } |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4639 | raw_spin_unlock(&its_lock); |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | static struct syscore_ops its_syscore_ops = { |
| 4643 | .suspend = its_save_disable, |
| 4644 | .resume = its_restore_enable, |
| 4645 | }; |
| 4646 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4647 | 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] | 4648 | { |
| 4649 | struct irq_domain *inner_domain; |
| 4650 | struct msi_domain_info *info; |
| 4651 | |
| 4652 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 4653 | if (!info) |
| 4654 | return -ENOMEM; |
| 4655 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4656 | inner_domain = irq_domain_create_tree(handle, &its_domain_ops, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 4657 | if (!inner_domain) { |
| 4658 | kfree(info); |
| 4659 | return -ENOMEM; |
| 4660 | } |
| 4661 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4662 | inner_domain->parent = its_parent; |
Marc Zyngier | 96f0d93 | 2017-06-22 11:42:50 +0100 | [diff] [blame] | 4663 | irq_domain_update_bus_token(inner_domain, DOMAIN_BUS_NEXUS); |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 4664 | inner_domain->flags |= its->msi_domain_flags; |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 4665 | info->ops = &its_msi_domain_ops; |
| 4666 | info->data = its; |
| 4667 | inner_domain->host_data = info; |
| 4668 | |
| 4669 | return 0; |
| 4670 | } |
| 4671 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4672 | static int its_init_vpe_domain(void) |
| 4673 | { |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 4674 | struct its_node *its; |
| 4675 | u32 devid; |
| 4676 | int entries; |
| 4677 | |
| 4678 | if (gic_rdists->has_direct_lpi) { |
| 4679 | pr_info("ITS: Using DirectLPI for VPE invalidation\n"); |
| 4680 | return 0; |
| 4681 | } |
| 4682 | |
| 4683 | /* Any ITS will do, even if not v4 */ |
| 4684 | its = list_first_entry(&its_nodes, struct its_node, entry); |
| 4685 | |
| 4686 | entries = roundup_pow_of_two(nr_cpu_ids); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 4687 | vpe_proxy.vpes = kcalloc(entries, sizeof(*vpe_proxy.vpes), |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 4688 | GFP_KERNEL); |
| 4689 | if (!vpe_proxy.vpes) { |
| 4690 | pr_err("ITS: Can't allocate GICv4 proxy device array\n"); |
| 4691 | return -ENOMEM; |
| 4692 | } |
| 4693 | |
| 4694 | /* Use the last possible DevID */ |
Marc Zyngier | 576a834 | 2019-11-08 16:58:00 +0000 | [diff] [blame] | 4695 | devid = GENMASK(device_ids(its) - 1, 0); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 4696 | vpe_proxy.dev = its_create_device(its, devid, entries, false); |
| 4697 | if (!vpe_proxy.dev) { |
| 4698 | kfree(vpe_proxy.vpes); |
| 4699 | pr_err("ITS: Can't allocate GICv4 proxy device\n"); |
| 4700 | return -ENOMEM; |
| 4701 | } |
| 4702 | |
Shanker Donthineni | c427a47 | 2017-09-23 13:50:19 -0500 | [diff] [blame] | 4703 | BUG_ON(entries > vpe_proxy.dev->nr_ites); |
Marc Zyngier | 20b3d54 | 2016-12-20 15:23:22 +0000 | [diff] [blame] | 4704 | |
| 4705 | raw_spin_lock_init(&vpe_proxy.lock); |
| 4706 | vpe_proxy.next_victim = 0; |
| 4707 | pr_info("ITS: Allocated DevID %x as GICv4 proxy device (%d slots)\n", |
| 4708 | devid, vpe_proxy.dev->nr_ites); |
| 4709 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 4710 | return 0; |
| 4711 | } |
| 4712 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4713 | static int __init its_compute_its_list_map(struct resource *res, |
| 4714 | void __iomem *its_base) |
| 4715 | { |
| 4716 | int its_number; |
| 4717 | u32 ctlr; |
| 4718 | |
| 4719 | /* |
| 4720 | * This is assumed to be done early enough that we're |
| 4721 | * guaranteed to be single-threaded, hence no |
| 4722 | * locking. Should this change, we should address |
| 4723 | * this. |
| 4724 | */ |
Marc Zyngier | ab60491 | 2017-10-08 18:48:06 +0100 | [diff] [blame] | 4725 | its_number = find_first_zero_bit(&its_list_map, GICv4_ITS_LIST_MAX); |
| 4726 | if (its_number >= GICv4_ITS_LIST_MAX) { |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4727 | pr_err("ITS@%pa: No ITSList entry available!\n", |
| 4728 | &res->start); |
| 4729 | return -EINVAL; |
| 4730 | } |
| 4731 | |
| 4732 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 4733 | ctlr &= ~GITS_CTLR_ITS_NUMBER; |
| 4734 | ctlr |= its_number << GITS_CTLR_ITS_NUMBER_SHIFT; |
| 4735 | writel_relaxed(ctlr, its_base + GITS_CTLR); |
| 4736 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 4737 | if ((ctlr & GITS_CTLR_ITS_NUMBER) != (its_number << GITS_CTLR_ITS_NUMBER_SHIFT)) { |
| 4738 | its_number = ctlr & GITS_CTLR_ITS_NUMBER; |
| 4739 | its_number >>= GITS_CTLR_ITS_NUMBER_SHIFT; |
| 4740 | } |
| 4741 | |
| 4742 | if (test_and_set_bit(its_number, &its_list_map)) { |
| 4743 | pr_err("ITS@%pa: Duplicate ITSList entry %d\n", |
| 4744 | &res->start, its_number); |
| 4745 | return -EINVAL; |
| 4746 | } |
| 4747 | |
| 4748 | return its_number; |
| 4749 | } |
| 4750 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4751 | static int __init its_probe_one(struct resource *res, |
| 4752 | struct fwnode_handle *handle, int numa_node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4753 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4754 | struct its_node *its; |
| 4755 | void __iomem *its_base; |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4756 | u32 val, ctlr; |
| 4757 | u64 baser, tmp, typer; |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 4758 | struct page *page; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4759 | int err; |
| 4760 | |
Marc Zyngier | 5e46a48 | 2020-03-04 20:33:14 +0000 | [diff] [blame] | 4761 | its_base = ioremap(res->start, SZ_64K); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4762 | if (!its_base) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4763 | pr_warn("ITS@%pa: Unable to map ITS registers\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4764 | return -ENOMEM; |
| 4765 | } |
| 4766 | |
| 4767 | val = readl_relaxed(its_base + GITS_PIDR2) & GIC_PIDR2_ARCH_MASK; |
| 4768 | if (val != 0x30 && val != 0x40) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4769 | pr_warn("ITS@%pa: No ITS detected, giving up\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4770 | err = -ENODEV; |
| 4771 | goto out_unmap; |
| 4772 | } |
| 4773 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 4774 | err = its_force_quiescent(its_base); |
| 4775 | if (err) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4776 | pr_warn("ITS@%pa: Failed to quiesce, giving up\n", &res->start); |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 4777 | goto out_unmap; |
| 4778 | } |
| 4779 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4780 | pr_info("ITS %pR\n", res); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4781 | |
| 4782 | its = kzalloc(sizeof(*its), GFP_KERNEL); |
| 4783 | if (!its) { |
| 4784 | err = -ENOMEM; |
| 4785 | goto out_unmap; |
| 4786 | } |
| 4787 | |
| 4788 | raw_spin_lock_init(&its->lock); |
Marc Zyngier | 9791ec7 | 2019-01-29 10:02:33 +0000 | [diff] [blame] | 4789 | mutex_init(&its->dev_alloc_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4790 | INIT_LIST_HEAD(&its->entry); |
| 4791 | INIT_LIST_HEAD(&its->its_device_list); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4792 | typer = gic_read_typer(its_base + GITS_TYPER); |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4793 | its->typer = typer; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4794 | its->base = its_base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4795 | its->phys_base = res->start; |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4796 | if (is_v4(its)) { |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4797 | if (!(typer & GITS_TYPER_VMOVP)) { |
| 4798 | err = its_compute_its_list_map(res, its_base); |
| 4799 | if (err < 0) |
| 4800 | goto out_free_its; |
| 4801 | |
Marc Zyngier | debf6d0 | 2017-10-08 18:44:42 +0100 | [diff] [blame] | 4802 | its->list_nr = err; |
| 4803 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4804 | pr_info("ITS@%pa: Using ITS number %d\n", |
| 4805 | &res->start, err); |
| 4806 | } else { |
| 4807 | pr_info("ITS@%pa: Single VMOVP capable\n", &res->start); |
| 4808 | } |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 4809 | |
| 4810 | if (is_v4_1(its)) { |
| 4811 | u32 svpet = FIELD_GET(GITS_TYPER_SVPET, typer); |
Marc Zyngier | 5e46a48 | 2020-03-04 20:33:14 +0000 | [diff] [blame] | 4812 | |
| 4813 | its->sgir_base = ioremap(res->start + SZ_128K, SZ_64K); |
| 4814 | if (!its->sgir_base) { |
| 4815 | err = -ENOMEM; |
| 4816 | goto out_free_its; |
| 4817 | } |
| 4818 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 4819 | its->mpidr = readl_relaxed(its_base + GITS_MPIDR); |
| 4820 | |
| 4821 | pr_info("ITS@%pa: Using GICv4.1 mode %08x %08x\n", |
| 4822 | &res->start, its->mpidr, svpet); |
| 4823 | } |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4824 | } |
| 4825 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4826 | its->numa_node = numa_node; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4827 | |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 4828 | page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, |
| 4829 | get_order(ITS_CMD_QUEUE_SZ)); |
| 4830 | if (!page) { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4831 | err = -ENOMEM; |
Marc Zyngier | 5e46a48 | 2020-03-04 20:33:14 +0000 | [diff] [blame] | 4832 | goto out_unmap_sgir; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4833 | } |
Shanker Donthineni | 539d378 | 2019-01-14 09:50:19 +0000 | [diff] [blame] | 4834 | its->cmd_base = (void *)page_address(page); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4835 | its->cmd_write = its->cmd_base; |
Ard Biesheuvel | 558b016 | 2017-10-17 17:55:56 +0100 | [diff] [blame] | 4836 | its->fwnode_handle = handle; |
| 4837 | its->get_msi_base = its_irq_get_msi_base; |
| 4838 | its->msi_domain_flags = IRQ_DOMAIN_FLAG_MSI_REMAP; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4839 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 4840 | its_enable_quirks(its); |
| 4841 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 4842 | err = its_alloc_tables(its); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4843 | if (err) |
| 4844 | goto out_free_cmd; |
| 4845 | |
| 4846 | err = its_alloc_collections(its); |
| 4847 | if (err) |
| 4848 | goto out_free_tables; |
| 4849 | |
| 4850 | baser = (virt_to_phys(its->cmd_base) | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 4851 | GITS_CBASER_RaWaWb | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4852 | GITS_CBASER_InnerShareable | |
| 4853 | (ITS_CMD_QUEUE_SZ / SZ_4K - 1) | |
| 4854 | GITS_CBASER_VALID); |
| 4855 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 4856 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
| 4857 | tmp = gits_read_cbaser(its->base + GITS_CBASER); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4858 | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 4859 | if ((tmp ^ baser) & GITS_CBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 4860 | if (!(tmp & GITS_CBASER_SHAREABILITY_MASK)) { |
| 4861 | /* |
| 4862 | * The HW reports non-shareable, we must |
| 4863 | * remove the cacheability attributes as |
| 4864 | * well. |
| 4865 | */ |
| 4866 | baser &= ~(GITS_CBASER_SHAREABILITY_MASK | |
| 4867 | GITS_CBASER_CACHEABILITY_MASK); |
| 4868 | baser |= GITS_CBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 4869 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 4870 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4871 | pr_info("ITS: using cache flushing for cmd queue\n"); |
| 4872 | its->flags |= ITS_FLAGS_CMDQ_NEEDS_FLUSHING; |
| 4873 | } |
| 4874 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 4875 | gits_write_cwriter(0, its->base + GITS_CWRITER); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 4876 | ctlr = readl_relaxed(its->base + GITS_CTLR); |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 4877 | ctlr |= GITS_CTLR_ENABLE; |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 4878 | if (is_v4(its)) |
Marc Zyngier | d51c4b4 | 2017-06-27 21:24:25 +0100 | [diff] [blame] | 4879 | ctlr |= GITS_CTLR_ImDe; |
| 4880 | writel_relaxed(ctlr, its->base + GITS_CTLR); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 4881 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 4882 | if (GITS_TYPER_HCC(typer)) |
| 4883 | its->flags |= ITS_FLAGS_SAVE_SUSPEND_STATE; |
| 4884 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4885 | err = its_init_domain(handle, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 4886 | if (err) |
| 4887 | goto out_free_tables; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4888 | |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4889 | raw_spin_lock(&its_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4890 | list_add(&its->entry, &its_nodes); |
Sebastian Andrzej Siewior | a8db745 | 2018-07-18 17:42:04 +0200 | [diff] [blame] | 4891 | raw_spin_unlock(&its_lock); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4892 | |
| 4893 | return 0; |
| 4894 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4895 | out_free_tables: |
| 4896 | its_free_tables(its); |
| 4897 | out_free_cmd: |
Robert Richter | 5bc13c2 | 2017-02-01 18:38:25 +0100 | [diff] [blame] | 4898 | free_pages((unsigned long)its->cmd_base, get_order(ITS_CMD_QUEUE_SZ)); |
Marc Zyngier | 5e46a48 | 2020-03-04 20:33:14 +0000 | [diff] [blame] | 4899 | out_unmap_sgir: |
| 4900 | if (its->sgir_base) |
| 4901 | iounmap(its->sgir_base); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4902 | out_free_its: |
| 4903 | kfree(its); |
| 4904 | out_unmap: |
| 4905 | iounmap(its_base); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 4906 | pr_err("ITS@%pa: failed probing (%d)\n", &res->start, err); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4907 | return err; |
| 4908 | } |
| 4909 | |
| 4910 | static bool gic_rdists_supports_plpis(void) |
| 4911 | { |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 4912 | 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] | 4913 | } |
| 4914 | |
Shanker Donthineni | 6eb486b | 2018-03-21 20:58:49 -0500 | [diff] [blame] | 4915 | static int redist_disable_lpis(void) |
| 4916 | { |
| 4917 | void __iomem *rbase = gic_data_rdist_rd_base(); |
| 4918 | u64 timeout = USEC_PER_SEC; |
| 4919 | u64 val; |
| 4920 | |
| 4921 | if (!gic_rdists_supports_plpis()) { |
| 4922 | pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); |
| 4923 | return -ENXIO; |
| 4924 | } |
| 4925 | |
| 4926 | val = readl_relaxed(rbase + GICR_CTLR); |
| 4927 | if (!(val & GICR_CTLR_ENABLE_LPIS)) |
| 4928 | return 0; |
| 4929 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 4930 | /* |
| 4931 | * If coming via a CPU hotplug event, we don't need to disable |
| 4932 | * LPIs before trying to re-enable them. They are already |
| 4933 | * configured and all is well in the world. |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 4934 | * |
| 4935 | * If running with preallocated tables, there is nothing to do. |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 4936 | */ |
Marc Zyngier | c440a9d | 2018-07-27 15:40:13 +0100 | [diff] [blame] | 4937 | if (gic_data_rdist()->lpi_enabled || |
| 4938 | (gic_rdists->flags & RDIST_FLAGS_RD_TABLES_PREALLOCATED)) |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 4939 | return 0; |
| 4940 | |
| 4941 | /* |
| 4942 | * From that point on, we only try to do some damage control. |
| 4943 | */ |
| 4944 | 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] | 4945 | smp_processor_id()); |
| 4946 | add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); |
| 4947 | |
| 4948 | /* Disable LPIs */ |
| 4949 | val &= ~GICR_CTLR_ENABLE_LPIS; |
| 4950 | writel_relaxed(val, rbase + GICR_CTLR); |
| 4951 | |
| 4952 | /* Make sure any change to GICR_CTLR is observable by the GIC */ |
| 4953 | dsb(sy); |
| 4954 | |
| 4955 | /* |
| 4956 | * Software must observe RWP==0 after clearing GICR_CTLR.EnableLPIs |
| 4957 | * from 1 to 0 before programming GICR_PEND{PROP}BASER registers. |
| 4958 | * Error out if we time out waiting for RWP to clear. |
| 4959 | */ |
| 4960 | while (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_RWP) { |
| 4961 | if (!timeout) { |
| 4962 | pr_err("CPU%d: Timeout while disabling LPIs\n", |
| 4963 | smp_processor_id()); |
| 4964 | return -ETIMEDOUT; |
| 4965 | } |
| 4966 | udelay(1); |
| 4967 | timeout--; |
| 4968 | } |
| 4969 | |
| 4970 | /* |
| 4971 | * After it has been written to 1, it is IMPLEMENTATION |
| 4972 | * DEFINED whether GICR_CTLR.EnableLPI becomes RES1 or can be |
| 4973 | * cleared to 0. Error out if clearing the bit failed. |
| 4974 | */ |
| 4975 | if (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_ENABLE_LPIS) { |
| 4976 | pr_err("CPU%d: Failed to disable LPIs\n", smp_processor_id()); |
| 4977 | return -EBUSY; |
| 4978 | } |
| 4979 | |
| 4980 | return 0; |
| 4981 | } |
| 4982 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4983 | int its_cpu_init(void) |
| 4984 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4985 | if (!list_empty(&its_nodes)) { |
Shanker Donthineni | 6eb486b | 2018-03-21 20:58:49 -0500 | [diff] [blame] | 4986 | int ret; |
| 4987 | |
| 4988 | ret = redist_disable_lpis(); |
| 4989 | if (ret) |
| 4990 | return ret; |
| 4991 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4992 | its_cpu_init_lpis(); |
Derek Basehore | 920181c | 2018-02-28 21:48:20 -0800 | [diff] [blame] | 4993 | its_cpu_init_collections(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | return 0; |
| 4997 | } |
| 4998 | |
Arvind Yadav | 935bba7 | 2017-06-22 16:05:30 +0530 | [diff] [blame] | 4999 | static const struct of_device_id its_device_id[] = { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5000 | { .compatible = "arm,gic-v3-its", }, |
| 5001 | {}, |
| 5002 | }; |
| 5003 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5004 | static int __init its_of_probe(struct device_node *node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5005 | { |
| 5006 | struct device_node *np; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5007 | struct resource res; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5008 | |
| 5009 | for (np = of_find_matching_node(node, its_device_id); np; |
| 5010 | np = of_find_matching_node(np, its_device_id)) { |
Stephen Boyd | 95a2562 | 2018-02-01 09:03:29 -0800 | [diff] [blame] | 5011 | if (!of_device_is_available(np)) |
| 5012 | continue; |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 5013 | if (!of_property_read_bool(np, "msi-controller")) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 5014 | pr_warn("%pOF: no msi-controller property, ITS ignored\n", |
| 5015 | np); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 5016 | continue; |
| 5017 | } |
| 5018 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5019 | if (of_address_to_resource(np, 0, &res)) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 5020 | pr_warn("%pOF: no regs?\n", np); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5021 | continue; |
| 5022 | } |
| 5023 | |
| 5024 | its_probe_one(&res, &np->fwnode, of_node_to_nid(np)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5025 | } |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5026 | return 0; |
| 5027 | } |
| 5028 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5029 | #ifdef CONFIG_ACPI |
| 5030 | |
| 5031 | #define ACPI_GICV3_ITS_MEM_SIZE (SZ_128K) |
| 5032 | |
Robert Richter | d1ce263 | 2017-07-12 15:25:09 +0200 | [diff] [blame] | 5033 | #ifdef CONFIG_ACPI_NUMA |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5034 | struct its_srat_map { |
| 5035 | /* numa node id */ |
| 5036 | u32 numa_node; |
| 5037 | /* GIC ITS ID */ |
| 5038 | u32 its_id; |
| 5039 | }; |
| 5040 | |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 5041 | static struct its_srat_map *its_srat_maps __initdata; |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5042 | static int its_in_srat __initdata; |
| 5043 | |
| 5044 | static int __init acpi_get_its_numa_node(u32 its_id) |
| 5045 | { |
| 5046 | int i; |
| 5047 | |
| 5048 | for (i = 0; i < its_in_srat; i++) { |
| 5049 | if (its_id == its_srat_maps[i].its_id) |
| 5050 | return its_srat_maps[i].numa_node; |
| 5051 | } |
| 5052 | return NUMA_NO_NODE; |
| 5053 | } |
| 5054 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 5055 | 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] | 5056 | const unsigned long end) |
| 5057 | { |
| 5058 | return 0; |
| 5059 | } |
| 5060 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 5061 | 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] | 5062 | const unsigned long end) |
| 5063 | { |
| 5064 | int node; |
| 5065 | struct acpi_srat_gic_its_affinity *its_affinity; |
| 5066 | |
| 5067 | its_affinity = (struct acpi_srat_gic_its_affinity *)header; |
| 5068 | if (!its_affinity) |
| 5069 | return -EINVAL; |
| 5070 | |
| 5071 | if (its_affinity->header.length < sizeof(*its_affinity)) { |
| 5072 | pr_err("SRAT: Invalid header length %d in ITS affinity\n", |
| 5073 | its_affinity->header.length); |
| 5074 | return -EINVAL; |
| 5075 | } |
| 5076 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5077 | node = acpi_map_pxm_to_node(its_affinity->proximity_domain); |
| 5078 | |
| 5079 | if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) { |
| 5080 | pr_err("SRAT: Invalid NUMA node %d in ITS affinity\n", node); |
| 5081 | return 0; |
| 5082 | } |
| 5083 | |
| 5084 | its_srat_maps[its_in_srat].numa_node = node; |
| 5085 | its_srat_maps[its_in_srat].its_id = its_affinity->its_id; |
| 5086 | its_in_srat++; |
| 5087 | pr_info("SRAT: PXM %d -> ITS %d -> Node %d\n", |
| 5088 | its_affinity->proximity_domain, its_affinity->its_id, node); |
| 5089 | |
| 5090 | return 0; |
| 5091 | } |
| 5092 | |
| 5093 | static void __init acpi_table_parse_srat_its(void) |
| 5094 | { |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 5095 | int count; |
| 5096 | |
| 5097 | count = acpi_table_parse_entries(ACPI_SIG_SRAT, |
| 5098 | sizeof(struct acpi_table_srat), |
| 5099 | ACPI_SRAT_TYPE_GIC_ITS_AFFINITY, |
| 5100 | gic_acpi_match_srat_its, 0); |
| 5101 | if (count <= 0) |
| 5102 | return; |
| 5103 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 5104 | its_srat_maps = kmalloc_array(count, sizeof(struct its_srat_map), |
| 5105 | GFP_KERNEL); |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 5106 | if (!its_srat_maps) { |
| 5107 | pr_warn("SRAT: Failed to allocate memory for its_srat_maps!\n"); |
| 5108 | return; |
| 5109 | } |
| 5110 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5111 | acpi_table_parse_entries(ACPI_SIG_SRAT, |
| 5112 | sizeof(struct acpi_table_srat), |
| 5113 | ACPI_SRAT_TYPE_GIC_ITS_AFFINITY, |
| 5114 | gic_acpi_parse_srat_its, 0); |
| 5115 | } |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 5116 | |
| 5117 | /* free the its_srat_maps after ITS probing */ |
| 5118 | static void __init acpi_its_srat_maps_free(void) |
| 5119 | { |
| 5120 | kfree(its_srat_maps); |
| 5121 | } |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5122 | #else |
| 5123 | static void __init acpi_table_parse_srat_its(void) { } |
| 5124 | 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] | 5125 | static void __init acpi_its_srat_maps_free(void) { } |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5126 | #endif |
| 5127 | |
Keith Busch | 60574d1 | 2019-03-11 14:55:57 -0600 | [diff] [blame] | 5128 | 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] | 5129 | const unsigned long end) |
| 5130 | { |
| 5131 | struct acpi_madt_generic_translator *its_entry; |
| 5132 | struct fwnode_handle *dom_handle; |
| 5133 | struct resource res; |
| 5134 | int err; |
| 5135 | |
| 5136 | its_entry = (struct acpi_madt_generic_translator *)header; |
| 5137 | memset(&res, 0, sizeof(res)); |
| 5138 | res.start = its_entry->base_address; |
| 5139 | res.end = its_entry->base_address + ACPI_GICV3_ITS_MEM_SIZE - 1; |
| 5140 | res.flags = IORESOURCE_MEM; |
| 5141 | |
Marc Zyngier | 5778cc7 | 2019-07-31 16:13:42 +0100 | [diff] [blame] | 5142 | dom_handle = irq_domain_alloc_fwnode(&res.start); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5143 | if (!dom_handle) { |
| 5144 | pr_err("ITS@%pa: Unable to allocate GICv3 ITS domain token\n", |
| 5145 | &res.start); |
| 5146 | return -ENOMEM; |
| 5147 | } |
| 5148 | |
Shameer Kolothum | 8b4282e | 2018-02-13 15:20:50 +0000 | [diff] [blame] | 5149 | err = iort_register_domain_token(its_entry->translation_id, res.start, |
| 5150 | dom_handle); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5151 | if (err) { |
| 5152 | pr_err("ITS@%pa: Unable to register GICv3 ITS domain token (ITS ID %d) to IORT\n", |
| 5153 | &res.start, its_entry->translation_id); |
| 5154 | goto dom_err; |
| 5155 | } |
| 5156 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5157 | err = its_probe_one(&res, dom_handle, |
| 5158 | acpi_get_its_numa_node(its_entry->translation_id)); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5159 | if (!err) |
| 5160 | return 0; |
| 5161 | |
| 5162 | iort_deregister_domain_token(its_entry->translation_id); |
| 5163 | dom_err: |
| 5164 | irq_domain_free_fwnode(dom_handle); |
| 5165 | return err; |
| 5166 | } |
| 5167 | |
| 5168 | static void __init its_acpi_probe(void) |
| 5169 | { |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 5170 | acpi_table_parse_srat_its(); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5171 | acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR, |
| 5172 | gic_acpi_parse_madt_its, 0); |
Hanjun Guo | fdf6e7a | 2017-07-26 18:15:49 +0800 | [diff] [blame] | 5173 | acpi_its_srat_maps_free(); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5174 | } |
| 5175 | #else |
| 5176 | static void __init its_acpi_probe(void) { } |
| 5177 | #endif |
| 5178 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5179 | int __init its_init(struct fwnode_handle *handle, struct rdists *rdists, |
| 5180 | struct irq_domain *parent_domain) |
| 5181 | { |
| 5182 | struct device_node *of_node; |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5183 | struct its_node *its; |
| 5184 | bool has_v4 = false; |
Marc Zyngier | 3c40706 | 2020-03-04 20:33:13 +0000 | [diff] [blame] | 5185 | bool has_v4_1 = false; |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5186 | int err; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5187 | |
Marc Zyngier | 5e51684 | 2019-12-24 11:10:28 +0000 | [diff] [blame] | 5188 | gic_rdists = rdists; |
| 5189 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 5190 | its_parent = parent_domain; |
| 5191 | of_node = to_of_node(handle); |
| 5192 | if (of_node) |
| 5193 | its_of_probe(of_node); |
| 5194 | else |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 5195 | its_acpi_probe(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5196 | |
| 5197 | if (list_empty(&its_nodes)) { |
| 5198 | pr_warn("ITS: No ITS available, not enabling LPIs\n"); |
| 5199 | return -ENXIO; |
| 5200 | } |
| 5201 | |
Marc Zyngier | 11e37d3 | 2018-07-27 13:38:54 +0100 | [diff] [blame] | 5202 | err = allocate_lpi_tables(); |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5203 | if (err) |
| 5204 | return err; |
| 5205 | |
Marc Zyngier | 3c40706 | 2020-03-04 20:33:13 +0000 | [diff] [blame] | 5206 | list_for_each_entry(its, &its_nodes, entry) { |
Marc Zyngier | 0dd57fe | 2019-11-08 16:57:58 +0000 | [diff] [blame] | 5207 | has_v4 |= is_v4(its); |
Marc Zyngier | 3c40706 | 2020-03-04 20:33:13 +0000 | [diff] [blame] | 5208 | has_v4_1 |= is_v4_1(its); |
| 5209 | } |
| 5210 | |
| 5211 | /* Don't bother with inconsistent systems */ |
| 5212 | if (WARN_ON(!has_v4_1 && rdists->has_rvpeid)) |
| 5213 | rdists->has_rvpeid = false; |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5214 | |
| 5215 | if (has_v4 & rdists->has_vlpis) { |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 5216 | const struct irq_domain_ops *sgi_ops; |
| 5217 | |
| 5218 | if (has_v4_1) |
| 5219 | sgi_ops = &its_sgi_domain_ops; |
| 5220 | else |
| 5221 | sgi_ops = NULL; |
| 5222 | |
Marc Zyngier | 3d63cb5 | 2016-12-20 15:31:54 +0000 | [diff] [blame] | 5223 | if (its_init_vpe_domain() || |
Marc Zyngier | 166cba7 | 2020-03-04 20:33:15 +0000 | [diff] [blame] | 5224 | its_init_v4(parent_domain, &its_vpe_domain_ops, sgi_ops)) { |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5225 | rdists->has_vlpis = false; |
| 5226 | pr_err("ITS: Disabling GICv4 support\n"); |
| 5227 | } |
| 5228 | } |
| 5229 | |
Derek Basehore | dba0bc7 | 2018-02-28 21:48:18 -0800 | [diff] [blame] | 5230 | register_syscore_ops(&its_syscore_ops); |
| 5231 | |
Marc Zyngier | 8fff27a | 2016-12-20 13:41:55 +0000 | [diff] [blame] | 5232 | return 0; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 5233 | } |