Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013, 2014 ARM Limited, All Rights Reserved. |
| 3 | * Author: Marc Zyngier <marc.zyngier@arm.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 18 | #include <linux/acpi.h> |
Hanjun Guo | 8d3554b | 2017-03-07 20:39:59 +0800 | [diff] [blame] | 19 | #include <linux/acpi_iort.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 20 | #include <linux/bitmap.h> |
| 21 | #include <linux/cpu.h> |
| 22 | #include <linux/delay.h> |
Robin Murphy | 44bb7e2 | 2016-09-12 17:13:59 +0100 | [diff] [blame] | 23 | #include <linux/dma-iommu.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 25 | #include <linux/irqdomain.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 26 | #include <linux/log2.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/msi.h> |
| 29 | #include <linux/of.h> |
| 30 | #include <linux/of_address.h> |
| 31 | #include <linux/of_irq.h> |
| 32 | #include <linux/of_pci.h> |
| 33 | #include <linux/of_platform.h> |
| 34 | #include <linux/percpu.h> |
| 35 | #include <linux/slab.h> |
| 36 | |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 37 | #include <linux/irqchip.h> |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 38 | #include <linux/irqchip/arm-gic-v3.h> |
| 39 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 40 | #include <asm/cputype.h> |
| 41 | #include <asm/exception.h> |
| 42 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 43 | #include "irq-gic-common.h" |
| 44 | |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 45 | #define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0) |
| 46 | #define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1) |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 47 | #define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 48 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 49 | #define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0) |
| 50 | |
Marc Zyngier | a13b040 | 2016-12-19 17:15:24 +0000 | [diff] [blame] | 51 | static u32 lpi_id_bits; |
| 52 | |
| 53 | /* |
| 54 | * We allocate memory for PROPBASE to cover 2 ^ lpi_id_bits LPIs to |
| 55 | * deal with (one configuration byte per interrupt). PENDBASE has to |
| 56 | * be 64kB aligned (one bit per LPI, plus 8192 bits for SPI/PPI/SGI). |
| 57 | */ |
| 58 | #define LPI_NRBITS lpi_id_bits |
| 59 | #define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K) |
| 60 | #define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K) |
| 61 | |
| 62 | #define LPI_PROP_DEFAULT_PRIO 0xa0 |
| 63 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Collection structure - just an ID, and a redistributor address to |
| 66 | * ping. We use one per CPU as a bag of interrupts assigned to this |
| 67 | * CPU. |
| 68 | */ |
| 69 | struct its_collection { |
| 70 | u64 target_address; |
| 71 | u16 col_id; |
| 72 | }; |
| 73 | |
| 74 | /* |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 75 | * The ITS_BASER structure - contains memory information, cached |
| 76 | * value of BASER register configuration and ITS page size. |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 77 | */ |
| 78 | struct its_baser { |
| 79 | void *base; |
| 80 | u64 val; |
| 81 | u32 order; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 82 | u32 psz; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 83 | }; |
| 84 | |
| 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 | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 89 | */ |
| 90 | struct its_node { |
| 91 | raw_spinlock_t lock; |
| 92 | struct list_head entry; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 93 | void __iomem *base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 94 | phys_addr_t phys_base; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 95 | struct its_cmd_block *cmd_base; |
| 96 | struct its_cmd_block *cmd_write; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 97 | struct its_baser tables[GITS_BASER_NR_REGS]; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 98 | struct its_collection *collections; |
| 99 | struct list_head its_device_list; |
| 100 | u64 flags; |
| 101 | u32 ite_size; |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 102 | u32 device_ids; |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 103 | int numa_node; |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 104 | bool is_v4; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #define ITS_ITT_ALIGN SZ_256 |
| 108 | |
Shanker Donthineni | 2eca0d6 | 2016-02-16 18:00:36 -0600 | [diff] [blame] | 109 | /* Convert page order to size in bytes */ |
| 110 | #define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o)) |
| 111 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 112 | struct event_lpi_map { |
| 113 | unsigned long *lpi_map; |
| 114 | u16 *col_map; |
| 115 | irq_hw_number_t lpi_base; |
| 116 | int nr_lpis; |
| 117 | }; |
| 118 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 119 | /* |
| 120 | * The ITS view of a device - belongs to an ITS, a collection, owns an |
| 121 | * interrupt translation table, and a list of interrupts. |
| 122 | */ |
| 123 | struct its_device { |
| 124 | struct list_head entry; |
| 125 | struct its_node *its; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 126 | struct event_lpi_map event_map; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 127 | void *itt; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 128 | u32 nr_ites; |
| 129 | u32 device_id; |
| 130 | }; |
| 131 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 132 | static LIST_HEAD(its_nodes); |
| 133 | static DEFINE_SPINLOCK(its_lock); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 134 | static struct rdists *gic_rdists; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 135 | static struct irq_domain *its_parent; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 136 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 137 | /* |
| 138 | * We have a maximum number of 16 ITSs in the whole system if we're |
| 139 | * using the ITSList mechanism |
| 140 | */ |
| 141 | #define ITS_LIST_MAX 16 |
| 142 | |
| 143 | static unsigned long its_list_map; |
| 144 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 145 | #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist)) |
| 146 | #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) |
| 147 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 148 | static struct its_collection *dev_event_to_col(struct its_device *its_dev, |
| 149 | u32 event) |
| 150 | { |
| 151 | struct its_node *its = its_dev->its; |
| 152 | |
| 153 | return its->collections + its_dev->event_map.col_map[event]; |
| 154 | } |
| 155 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 156 | /* |
| 157 | * ITS command descriptors - parameters to be encoded in a command |
| 158 | * block. |
| 159 | */ |
| 160 | struct its_cmd_desc { |
| 161 | union { |
| 162 | struct { |
| 163 | struct its_device *dev; |
| 164 | u32 event_id; |
| 165 | } its_inv_cmd; |
| 166 | |
| 167 | struct { |
| 168 | struct its_device *dev; |
| 169 | u32 event_id; |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 170 | } its_clear_cmd; |
| 171 | |
| 172 | struct { |
| 173 | struct its_device *dev; |
| 174 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 175 | } its_int_cmd; |
| 176 | |
| 177 | struct { |
| 178 | struct its_device *dev; |
| 179 | int valid; |
| 180 | } its_mapd_cmd; |
| 181 | |
| 182 | struct { |
| 183 | struct its_collection *col; |
| 184 | int valid; |
| 185 | } its_mapc_cmd; |
| 186 | |
| 187 | struct { |
| 188 | struct its_device *dev; |
| 189 | u32 phys_id; |
| 190 | u32 event_id; |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 191 | } its_mapti_cmd; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 192 | |
| 193 | struct { |
| 194 | struct its_device *dev; |
| 195 | struct its_collection *col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 196 | u32 event_id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 197 | } its_movi_cmd; |
| 198 | |
| 199 | struct { |
| 200 | struct its_device *dev; |
| 201 | u32 event_id; |
| 202 | } its_discard_cmd; |
| 203 | |
| 204 | struct { |
| 205 | struct its_collection *col; |
| 206 | } its_invall_cmd; |
| 207 | }; |
| 208 | }; |
| 209 | |
| 210 | /* |
| 211 | * The ITS command block, which is what the ITS actually parses. |
| 212 | */ |
| 213 | struct its_cmd_block { |
| 214 | u64 raw_cmd[4]; |
| 215 | }; |
| 216 | |
| 217 | #define ITS_CMD_QUEUE_SZ SZ_64K |
| 218 | #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(struct its_cmd_block)) |
| 219 | |
| 220 | typedef struct its_collection *(*its_cmd_builder_t)(struct its_cmd_block *, |
| 221 | struct its_cmd_desc *); |
| 222 | |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 223 | static void its_mask_encode(u64 *raw_cmd, u64 val, int h, int l) |
| 224 | { |
| 225 | u64 mask = GENMASK_ULL(h, l); |
| 226 | *raw_cmd &= ~mask; |
| 227 | *raw_cmd |= (val << l) & mask; |
| 228 | } |
| 229 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 230 | static void its_encode_cmd(struct its_cmd_block *cmd, u8 cmd_nr) |
| 231 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 232 | its_mask_encode(&cmd->raw_cmd[0], cmd_nr, 7, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void its_encode_devid(struct its_cmd_block *cmd, u32 devid) |
| 236 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 237 | its_mask_encode(&cmd->raw_cmd[0], devid, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void its_encode_event_id(struct its_cmd_block *cmd, u32 id) |
| 241 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 242 | its_mask_encode(&cmd->raw_cmd[1], id, 31, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void its_encode_phys_id(struct its_cmd_block *cmd, u32 phys_id) |
| 246 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 247 | its_mask_encode(&cmd->raw_cmd[1], phys_id, 63, 32); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static void its_encode_size(struct its_cmd_block *cmd, u8 size) |
| 251 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 252 | its_mask_encode(&cmd->raw_cmd[1], size, 4, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static void its_encode_itt(struct its_cmd_block *cmd, u64 itt_addr) |
| 256 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 257 | its_mask_encode(&cmd->raw_cmd[2], itt_addr >> 8, 50, 8); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void its_encode_valid(struct its_cmd_block *cmd, int valid) |
| 261 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 262 | its_mask_encode(&cmd->raw_cmd[2], !!valid, 63, 63); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static void its_encode_target(struct its_cmd_block *cmd, u64 target_addr) |
| 266 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 267 | its_mask_encode(&cmd->raw_cmd[2], target_addr >> 16, 50, 16); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void its_encode_collection(struct its_cmd_block *cmd, u16 col) |
| 271 | { |
Marc Zyngier | 4d36f13 | 2016-12-19 17:11:52 +0000 | [diff] [blame] | 272 | its_mask_encode(&cmd->raw_cmd[2], col, 15, 0); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static inline void its_fixup_cmd(struct its_cmd_block *cmd) |
| 276 | { |
| 277 | /* Let's fixup BE commands */ |
| 278 | cmd->raw_cmd[0] = cpu_to_le64(cmd->raw_cmd[0]); |
| 279 | cmd->raw_cmd[1] = cpu_to_le64(cmd->raw_cmd[1]); |
| 280 | cmd->raw_cmd[2] = cpu_to_le64(cmd->raw_cmd[2]); |
| 281 | cmd->raw_cmd[3] = cpu_to_le64(cmd->raw_cmd[3]); |
| 282 | } |
| 283 | |
| 284 | static struct its_collection *its_build_mapd_cmd(struct its_cmd_block *cmd, |
| 285 | struct its_cmd_desc *desc) |
| 286 | { |
| 287 | unsigned long itt_addr; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 288 | u8 size = ilog2(desc->its_mapd_cmd.dev->nr_ites); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 289 | |
| 290 | itt_addr = virt_to_phys(desc->its_mapd_cmd.dev->itt); |
| 291 | itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN); |
| 292 | |
| 293 | its_encode_cmd(cmd, GITS_CMD_MAPD); |
| 294 | its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id); |
| 295 | its_encode_size(cmd, size - 1); |
| 296 | its_encode_itt(cmd, itt_addr); |
| 297 | its_encode_valid(cmd, desc->its_mapd_cmd.valid); |
| 298 | |
| 299 | its_fixup_cmd(cmd); |
| 300 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 301 | return NULL; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static struct its_collection *its_build_mapc_cmd(struct its_cmd_block *cmd, |
| 305 | struct its_cmd_desc *desc) |
| 306 | { |
| 307 | its_encode_cmd(cmd, GITS_CMD_MAPC); |
| 308 | its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); |
| 309 | its_encode_target(cmd, desc->its_mapc_cmd.col->target_address); |
| 310 | its_encode_valid(cmd, desc->its_mapc_cmd.valid); |
| 311 | |
| 312 | its_fixup_cmd(cmd); |
| 313 | |
| 314 | return desc->its_mapc_cmd.col; |
| 315 | } |
| 316 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 317 | static struct its_collection *its_build_mapti_cmd(struct its_cmd_block *cmd, |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 318 | struct its_cmd_desc *desc) |
| 319 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 320 | struct its_collection *col; |
| 321 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 322 | col = dev_event_to_col(desc->its_mapti_cmd.dev, |
| 323 | desc->its_mapti_cmd.event_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 324 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 325 | its_encode_cmd(cmd, GITS_CMD_MAPTI); |
| 326 | its_encode_devid(cmd, desc->its_mapti_cmd.dev->device_id); |
| 327 | its_encode_event_id(cmd, desc->its_mapti_cmd.event_id); |
| 328 | its_encode_phys_id(cmd, desc->its_mapti_cmd.phys_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 329 | its_encode_collection(cmd, col->col_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 330 | |
| 331 | its_fixup_cmd(cmd); |
| 332 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 333 | return col; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static struct its_collection *its_build_movi_cmd(struct its_cmd_block *cmd, |
| 337 | struct its_cmd_desc *desc) |
| 338 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 339 | struct its_collection *col; |
| 340 | |
| 341 | col = dev_event_to_col(desc->its_movi_cmd.dev, |
| 342 | desc->its_movi_cmd.event_id); |
| 343 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 344 | its_encode_cmd(cmd, GITS_CMD_MOVI); |
| 345 | its_encode_devid(cmd, desc->its_movi_cmd.dev->device_id); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 346 | its_encode_event_id(cmd, desc->its_movi_cmd.event_id); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 347 | its_encode_collection(cmd, desc->its_movi_cmd.col->col_id); |
| 348 | |
| 349 | its_fixup_cmd(cmd); |
| 350 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 351 | return col; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static struct its_collection *its_build_discard_cmd(struct its_cmd_block *cmd, |
| 355 | struct its_cmd_desc *desc) |
| 356 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 357 | struct its_collection *col; |
| 358 | |
| 359 | col = dev_event_to_col(desc->its_discard_cmd.dev, |
| 360 | desc->its_discard_cmd.event_id); |
| 361 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 362 | its_encode_cmd(cmd, GITS_CMD_DISCARD); |
| 363 | its_encode_devid(cmd, desc->its_discard_cmd.dev->device_id); |
| 364 | its_encode_event_id(cmd, desc->its_discard_cmd.event_id); |
| 365 | |
| 366 | its_fixup_cmd(cmd); |
| 367 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 368 | return col; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static struct its_collection *its_build_inv_cmd(struct its_cmd_block *cmd, |
| 372 | struct its_cmd_desc *desc) |
| 373 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 374 | struct its_collection *col; |
| 375 | |
| 376 | col = dev_event_to_col(desc->its_inv_cmd.dev, |
| 377 | desc->its_inv_cmd.event_id); |
| 378 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 379 | its_encode_cmd(cmd, GITS_CMD_INV); |
| 380 | its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id); |
| 381 | its_encode_event_id(cmd, desc->its_inv_cmd.event_id); |
| 382 | |
| 383 | its_fixup_cmd(cmd); |
| 384 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 385 | return col; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 388 | static struct its_collection *its_build_int_cmd(struct its_cmd_block *cmd, |
| 389 | struct its_cmd_desc *desc) |
| 390 | { |
| 391 | struct its_collection *col; |
| 392 | |
| 393 | col = dev_event_to_col(desc->its_int_cmd.dev, |
| 394 | desc->its_int_cmd.event_id); |
| 395 | |
| 396 | its_encode_cmd(cmd, GITS_CMD_INT); |
| 397 | its_encode_devid(cmd, desc->its_int_cmd.dev->device_id); |
| 398 | its_encode_event_id(cmd, desc->its_int_cmd.event_id); |
| 399 | |
| 400 | its_fixup_cmd(cmd); |
| 401 | |
| 402 | return col; |
| 403 | } |
| 404 | |
| 405 | static struct its_collection *its_build_clear_cmd(struct its_cmd_block *cmd, |
| 406 | struct its_cmd_desc *desc) |
| 407 | { |
| 408 | struct its_collection *col; |
| 409 | |
| 410 | col = dev_event_to_col(desc->its_clear_cmd.dev, |
| 411 | desc->its_clear_cmd.event_id); |
| 412 | |
| 413 | its_encode_cmd(cmd, GITS_CMD_CLEAR); |
| 414 | its_encode_devid(cmd, desc->its_clear_cmd.dev->device_id); |
| 415 | its_encode_event_id(cmd, desc->its_clear_cmd.event_id); |
| 416 | |
| 417 | its_fixup_cmd(cmd); |
| 418 | |
| 419 | return col; |
| 420 | } |
| 421 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 422 | static struct its_collection *its_build_invall_cmd(struct its_cmd_block *cmd, |
| 423 | struct its_cmd_desc *desc) |
| 424 | { |
| 425 | its_encode_cmd(cmd, GITS_CMD_INVALL); |
| 426 | its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id); |
| 427 | |
| 428 | its_fixup_cmd(cmd); |
| 429 | |
| 430 | return NULL; |
| 431 | } |
| 432 | |
| 433 | static u64 its_cmd_ptr_to_offset(struct its_node *its, |
| 434 | struct its_cmd_block *ptr) |
| 435 | { |
| 436 | return (ptr - its->cmd_base) * sizeof(*ptr); |
| 437 | } |
| 438 | |
| 439 | static int its_queue_full(struct its_node *its) |
| 440 | { |
| 441 | int widx; |
| 442 | int ridx; |
| 443 | |
| 444 | widx = its->cmd_write - its->cmd_base; |
| 445 | ridx = readl_relaxed(its->base + GITS_CREADR) / sizeof(struct its_cmd_block); |
| 446 | |
| 447 | /* This is incredibly unlikely to happen, unless the ITS locks up. */ |
| 448 | if (((widx + 1) % ITS_CMD_QUEUE_NR_ENTRIES) == ridx) |
| 449 | return 1; |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static struct its_cmd_block *its_allocate_entry(struct its_node *its) |
| 455 | { |
| 456 | struct its_cmd_block *cmd; |
| 457 | u32 count = 1000000; /* 1s! */ |
| 458 | |
| 459 | while (its_queue_full(its)) { |
| 460 | count--; |
| 461 | if (!count) { |
| 462 | pr_err_ratelimited("ITS queue not draining\n"); |
| 463 | return NULL; |
| 464 | } |
| 465 | cpu_relax(); |
| 466 | udelay(1); |
| 467 | } |
| 468 | |
| 469 | cmd = its->cmd_write++; |
| 470 | |
| 471 | /* Handle queue wrapping */ |
| 472 | if (its->cmd_write == (its->cmd_base + ITS_CMD_QUEUE_NR_ENTRIES)) |
| 473 | its->cmd_write = its->cmd_base; |
| 474 | |
Marc Zyngier | 34d677a | 2016-12-19 17:16:45 +0000 | [diff] [blame] | 475 | /* Clear command */ |
| 476 | cmd->raw_cmd[0] = 0; |
| 477 | cmd->raw_cmd[1] = 0; |
| 478 | cmd->raw_cmd[2] = 0; |
| 479 | cmd->raw_cmd[3] = 0; |
| 480 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 481 | return cmd; |
| 482 | } |
| 483 | |
| 484 | static struct its_cmd_block *its_post_commands(struct its_node *its) |
| 485 | { |
| 486 | u64 wr = its_cmd_ptr_to_offset(its, its->cmd_write); |
| 487 | |
| 488 | writel_relaxed(wr, its->base + GITS_CWRITER); |
| 489 | |
| 490 | return its->cmd_write; |
| 491 | } |
| 492 | |
| 493 | static void its_flush_cmd(struct its_node *its, struct its_cmd_block *cmd) |
| 494 | { |
| 495 | /* |
| 496 | * Make sure the commands written to memory are observable by |
| 497 | * the ITS. |
| 498 | */ |
| 499 | if (its->flags & ITS_FLAGS_CMDQ_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 500 | gic_flush_dcache_to_poc(cmd, sizeof(*cmd)); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 501 | else |
| 502 | dsb(ishst); |
| 503 | } |
| 504 | |
| 505 | static void its_wait_for_range_completion(struct its_node *its, |
| 506 | struct its_cmd_block *from, |
| 507 | struct its_cmd_block *to) |
| 508 | { |
| 509 | u64 rd_idx, from_idx, to_idx; |
| 510 | u32 count = 1000000; /* 1s! */ |
| 511 | |
| 512 | from_idx = its_cmd_ptr_to_offset(its, from); |
| 513 | to_idx = its_cmd_ptr_to_offset(its, to); |
| 514 | |
| 515 | while (1) { |
| 516 | rd_idx = readl_relaxed(its->base + GITS_CREADR); |
Marc Zyngier | 9bdd8b1 | 2017-08-19 10:16:02 +0100 | [diff] [blame] | 517 | |
| 518 | /* Direct case */ |
| 519 | if (from_idx < to_idx && rd_idx >= to_idx) |
| 520 | break; |
| 521 | |
| 522 | /* Wrapped case */ |
| 523 | if (from_idx >= to_idx && rd_idx >= to_idx && rd_idx < from_idx) |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 524 | break; |
| 525 | |
| 526 | count--; |
| 527 | if (!count) { |
| 528 | pr_err_ratelimited("ITS queue timeout\n"); |
| 529 | return; |
| 530 | } |
| 531 | cpu_relax(); |
| 532 | udelay(1); |
| 533 | } |
| 534 | } |
| 535 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 536 | /* Warning, macro hell follows */ |
| 537 | #define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \ |
| 538 | void name(struct its_node *its, \ |
| 539 | buildtype builder, \ |
| 540 | struct its_cmd_desc *desc) \ |
| 541 | { \ |
| 542 | struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \ |
| 543 | synctype *sync_obj; \ |
| 544 | unsigned long flags; \ |
| 545 | \ |
| 546 | raw_spin_lock_irqsave(&its->lock, flags); \ |
| 547 | \ |
| 548 | cmd = its_allocate_entry(its); \ |
| 549 | if (!cmd) { /* We're soooooo screewed... */ \ |
| 550 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 551 | return; \ |
| 552 | } \ |
| 553 | sync_obj = builder(cmd, desc); \ |
| 554 | its_flush_cmd(its, cmd); \ |
| 555 | \ |
| 556 | if (sync_obj) { \ |
| 557 | sync_cmd = its_allocate_entry(its); \ |
| 558 | if (!sync_cmd) \ |
| 559 | goto post; \ |
| 560 | \ |
| 561 | buildfn(sync_cmd, sync_obj); \ |
| 562 | its_flush_cmd(its, sync_cmd); \ |
| 563 | } \ |
| 564 | \ |
| 565 | post: \ |
| 566 | next_cmd = its_post_commands(its); \ |
| 567 | raw_spin_unlock_irqrestore(&its->lock, flags); \ |
| 568 | \ |
| 569 | its_wait_for_range_completion(its, cmd, next_cmd); \ |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Marc Zyngier | e4f9094 | 2016-12-19 17:56:32 +0000 | [diff] [blame] | 572 | static void its_build_sync_cmd(struct its_cmd_block *sync_cmd, |
| 573 | struct its_collection *sync_col) |
| 574 | { |
| 575 | its_encode_cmd(sync_cmd, GITS_CMD_SYNC); |
| 576 | its_encode_target(sync_cmd, sync_col->target_address); |
| 577 | |
| 578 | its_fixup_cmd(sync_cmd); |
| 579 | } |
| 580 | |
| 581 | static BUILD_SINGLE_CMD_FUNC(its_send_single_command, its_cmd_builder_t, |
| 582 | struct its_collection, its_build_sync_cmd) |
| 583 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 584 | static void its_send_int(struct its_device *dev, u32 event_id) |
| 585 | { |
| 586 | struct its_cmd_desc desc; |
| 587 | |
| 588 | desc.its_int_cmd.dev = dev; |
| 589 | desc.its_int_cmd.event_id = event_id; |
| 590 | |
| 591 | its_send_single_command(dev->its, its_build_int_cmd, &desc); |
| 592 | } |
| 593 | |
| 594 | static void its_send_clear(struct its_device *dev, u32 event_id) |
| 595 | { |
| 596 | struct its_cmd_desc desc; |
| 597 | |
| 598 | desc.its_clear_cmd.dev = dev; |
| 599 | desc.its_clear_cmd.event_id = event_id; |
| 600 | |
| 601 | its_send_single_command(dev->its, its_build_clear_cmd, &desc); |
| 602 | } |
| 603 | |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 604 | static void its_send_inv(struct its_device *dev, u32 event_id) |
| 605 | { |
| 606 | struct its_cmd_desc desc; |
| 607 | |
| 608 | desc.its_inv_cmd.dev = dev; |
| 609 | desc.its_inv_cmd.event_id = event_id; |
| 610 | |
| 611 | its_send_single_command(dev->its, its_build_inv_cmd, &desc); |
| 612 | } |
| 613 | |
| 614 | static void its_send_mapd(struct its_device *dev, int valid) |
| 615 | { |
| 616 | struct its_cmd_desc desc; |
| 617 | |
| 618 | desc.its_mapd_cmd.dev = dev; |
| 619 | desc.its_mapd_cmd.valid = !!valid; |
| 620 | |
| 621 | its_send_single_command(dev->its, its_build_mapd_cmd, &desc); |
| 622 | } |
| 623 | |
| 624 | static void its_send_mapc(struct its_node *its, struct its_collection *col, |
| 625 | int valid) |
| 626 | { |
| 627 | struct its_cmd_desc desc; |
| 628 | |
| 629 | desc.its_mapc_cmd.col = col; |
| 630 | desc.its_mapc_cmd.valid = !!valid; |
| 631 | |
| 632 | its_send_single_command(its, its_build_mapc_cmd, &desc); |
| 633 | } |
| 634 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 635 | 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] | 636 | { |
| 637 | struct its_cmd_desc desc; |
| 638 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 639 | desc.its_mapti_cmd.dev = dev; |
| 640 | desc.its_mapti_cmd.phys_id = irq_id; |
| 641 | desc.its_mapti_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 642 | |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 643 | its_send_single_command(dev->its, its_build_mapti_cmd, &desc); |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static void its_send_movi(struct its_device *dev, |
| 647 | struct its_collection *col, u32 id) |
| 648 | { |
| 649 | struct its_cmd_desc desc; |
| 650 | |
| 651 | desc.its_movi_cmd.dev = dev; |
| 652 | desc.its_movi_cmd.col = col; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 653 | desc.its_movi_cmd.event_id = id; |
Marc Zyngier | cc2d321 | 2014-11-24 14:35:11 +0000 | [diff] [blame] | 654 | |
| 655 | its_send_single_command(dev->its, its_build_movi_cmd, &desc); |
| 656 | } |
| 657 | |
| 658 | static void its_send_discard(struct its_device *dev, u32 id) |
| 659 | { |
| 660 | struct its_cmd_desc desc; |
| 661 | |
| 662 | desc.its_discard_cmd.dev = dev; |
| 663 | desc.its_discard_cmd.event_id = id; |
| 664 | |
| 665 | its_send_single_command(dev->its, its_build_discard_cmd, &desc); |
| 666 | } |
| 667 | |
| 668 | static void its_send_invall(struct its_node *its, struct its_collection *col) |
| 669 | { |
| 670 | struct its_cmd_desc desc; |
| 671 | |
| 672 | desc.its_invall_cmd.col = col; |
| 673 | |
| 674 | its_send_single_command(its, its_build_invall_cmd, &desc); |
| 675 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 676 | |
| 677 | /* |
| 678 | * irqchip functions - assumes MSI, mostly. |
| 679 | */ |
| 680 | |
| 681 | static inline u32 its_get_event_id(struct irq_data *d) |
| 682 | { |
| 683 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 684 | return d->hwirq - its_dev->event_map.lpi_base; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static void lpi_set_config(struct irq_data *d, bool enable) |
| 688 | { |
| 689 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 690 | irq_hw_number_t hwirq = d->hwirq; |
| 691 | u32 id = its_get_event_id(d); |
| 692 | u8 *cfg = page_address(gic_rdists->prop_page) + hwirq - 8192; |
| 693 | |
| 694 | if (enable) |
| 695 | *cfg |= LPI_PROP_ENABLED; |
| 696 | else |
| 697 | *cfg &= ~LPI_PROP_ENABLED; |
| 698 | |
| 699 | /* |
| 700 | * Make the above write visible to the redistributors. |
| 701 | * And yes, we're flushing exactly: One. Single. Byte. |
| 702 | * Humpf... |
| 703 | */ |
| 704 | if (gic_rdists->flags & RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 705 | gic_flush_dcache_to_poc(cfg, sizeof(*cfg)); |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 706 | else |
| 707 | dsb(ishst); |
| 708 | its_send_inv(its_dev, id); |
| 709 | } |
| 710 | |
| 711 | static void its_mask_irq(struct irq_data *d) |
| 712 | { |
| 713 | lpi_set_config(d, false); |
| 714 | } |
| 715 | |
| 716 | static void its_unmask_irq(struct irq_data *d) |
| 717 | { |
| 718 | lpi_set_config(d, true); |
| 719 | } |
| 720 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 721 | static int its_set_affinity(struct irq_data *d, const struct cpumask *mask_val, |
| 722 | bool force) |
| 723 | { |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 724 | unsigned int cpu; |
| 725 | const struct cpumask *cpu_mask = cpu_online_mask; |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 726 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 727 | struct its_collection *target_col; |
| 728 | u32 id = its_get_event_id(d); |
| 729 | |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 730 | /* lpi cannot be routed to a redistributor that is on a foreign node */ |
| 731 | if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 732 | if (its_dev->its->numa_node >= 0) { |
| 733 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
| 734 | if (!cpumask_intersects(mask_val, cpu_mask)) |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | cpu = cpumask_any_and(mask_val, cpu_mask); |
| 740 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 741 | if (cpu >= nr_cpu_ids) |
| 742 | return -EINVAL; |
| 743 | |
MaJun | 8b8d94a | 2017-05-18 16:19:13 +0800 | [diff] [blame] | 744 | /* don't set the affinity when the target cpu is same as current one */ |
| 745 | if (cpu != its_dev->event_map.col_map[id]) { |
| 746 | target_col = &its_dev->its->collections[cpu]; |
| 747 | its_send_movi(its_dev, target_col, id); |
| 748 | its_dev->event_map.col_map[id] = cpu; |
| 749 | } |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 750 | |
| 751 | return IRQ_SET_MASK_OK_DONE; |
| 752 | } |
| 753 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 754 | static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg) |
| 755 | { |
| 756 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 757 | struct its_node *its; |
| 758 | u64 addr; |
| 759 | |
| 760 | its = its_dev->its; |
| 761 | addr = its->phys_base + GITS_TRANSLATER; |
| 762 | |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 763 | msg->address_lo = lower_32_bits(addr); |
| 764 | msg->address_hi = upper_32_bits(addr); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 765 | msg->data = its_get_event_id(d); |
Robin Murphy | 44bb7e2 | 2016-09-12 17:13:59 +0100 | [diff] [blame] | 766 | |
| 767 | iommu_dma_map_msi_msg(d->irq, msg); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 770 | static int its_irq_set_irqchip_state(struct irq_data *d, |
| 771 | enum irqchip_irq_state which, |
| 772 | bool state) |
| 773 | { |
| 774 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 775 | u32 event = its_get_event_id(d); |
| 776 | |
| 777 | if (which != IRQCHIP_STATE_PENDING) |
| 778 | return -EINVAL; |
| 779 | |
| 780 | if (state) |
| 781 | its_send_int(its_dev, event); |
| 782 | else |
| 783 | its_send_clear(its_dev, event); |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 788 | static struct irq_chip its_irq_chip = { |
| 789 | .name = "ITS", |
| 790 | .irq_mask = its_mask_irq, |
| 791 | .irq_unmask = its_unmask_irq, |
Ashok Kumar | 004fa08 | 2016-02-11 05:38:53 -0800 | [diff] [blame] | 792 | .irq_eoi = irq_chip_eoi_parent, |
Marc Zyngier | c48ed51 | 2014-11-24 14:35:12 +0000 | [diff] [blame] | 793 | .irq_set_affinity = its_set_affinity, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 794 | .irq_compose_msi_msg = its_irq_compose_msi_msg, |
Marc Zyngier | 8d85dce | 2016-12-19 18:02:13 +0000 | [diff] [blame] | 795 | .irq_set_irqchip_state = its_irq_set_irqchip_state, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 796 | }; |
| 797 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 798 | /* |
| 799 | * How we allocate LPIs: |
| 800 | * |
| 801 | * The GIC has id_bits bits for interrupt identifiers. From there, we |
| 802 | * must subtract 8192 which are reserved for SGIs/PPIs/SPIs. Then, as |
| 803 | * we allocate LPIs by chunks of 32, we can shift the whole thing by 5 |
| 804 | * bits to the right. |
| 805 | * |
| 806 | * This gives us (((1UL << id_bits) - 8192) >> 5) possible allocations. |
| 807 | */ |
| 808 | #define IRQS_PER_CHUNK_SHIFT 5 |
| 809 | #define IRQS_PER_CHUNK (1 << IRQS_PER_CHUNK_SHIFT) |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 810 | #define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */ |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 811 | |
| 812 | static unsigned long *lpi_bitmap; |
| 813 | static u32 lpi_chunks; |
| 814 | static DEFINE_SPINLOCK(lpi_lock); |
| 815 | |
| 816 | static int its_lpi_to_chunk(int lpi) |
| 817 | { |
| 818 | return (lpi - 8192) >> IRQS_PER_CHUNK_SHIFT; |
| 819 | } |
| 820 | |
| 821 | static int its_chunk_to_lpi(int chunk) |
| 822 | { |
| 823 | return (chunk << IRQS_PER_CHUNK_SHIFT) + 8192; |
| 824 | } |
| 825 | |
Tomasz Nowicki | 04a0e4d | 2016-01-19 14:11:18 +0100 | [diff] [blame] | 826 | static int __init its_lpi_init(u32 id_bits) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 827 | { |
| 828 | lpi_chunks = its_lpi_to_chunk(1UL << id_bits); |
| 829 | |
| 830 | lpi_bitmap = kzalloc(BITS_TO_LONGS(lpi_chunks) * sizeof(long), |
| 831 | GFP_KERNEL); |
| 832 | if (!lpi_bitmap) { |
| 833 | lpi_chunks = 0; |
| 834 | return -ENOMEM; |
| 835 | } |
| 836 | |
| 837 | pr_info("ITS: Allocated %d chunks for LPIs\n", (int)lpi_chunks); |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static unsigned long *its_lpi_alloc_chunks(int nr_irqs, int *base, int *nr_ids) |
| 842 | { |
| 843 | unsigned long *bitmap = NULL; |
| 844 | int chunk_id; |
| 845 | int nr_chunks; |
| 846 | int i; |
| 847 | |
| 848 | nr_chunks = DIV_ROUND_UP(nr_irqs, IRQS_PER_CHUNK); |
| 849 | |
| 850 | spin_lock(&lpi_lock); |
| 851 | |
| 852 | do { |
| 853 | chunk_id = bitmap_find_next_zero_area(lpi_bitmap, lpi_chunks, |
| 854 | 0, nr_chunks, 0); |
| 855 | if (chunk_id < lpi_chunks) |
| 856 | break; |
| 857 | |
| 858 | nr_chunks--; |
| 859 | } while (nr_chunks > 0); |
| 860 | |
| 861 | if (!nr_chunks) |
| 862 | goto out; |
| 863 | |
| 864 | bitmap = kzalloc(BITS_TO_LONGS(nr_chunks * IRQS_PER_CHUNK) * sizeof (long), |
| 865 | GFP_ATOMIC); |
| 866 | if (!bitmap) |
| 867 | goto out; |
| 868 | |
| 869 | for (i = 0; i < nr_chunks; i++) |
| 870 | set_bit(chunk_id + i, lpi_bitmap); |
| 871 | |
| 872 | *base = its_chunk_to_lpi(chunk_id); |
| 873 | *nr_ids = nr_chunks * IRQS_PER_CHUNK; |
| 874 | |
| 875 | out: |
| 876 | spin_unlock(&lpi_lock); |
| 877 | |
Marc Zyngier | c8415b9 | 2015-10-02 16:44:05 +0100 | [diff] [blame] | 878 | if (!bitmap) |
| 879 | *base = *nr_ids = 0; |
| 880 | |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 881 | return bitmap; |
| 882 | } |
| 883 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 884 | static void its_lpi_free(struct event_lpi_map *map) |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 885 | { |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 886 | int base = map->lpi_base; |
| 887 | int nr_ids = map->nr_lpis; |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 888 | int lpi; |
| 889 | |
| 890 | spin_lock(&lpi_lock); |
| 891 | |
| 892 | for (lpi = base; lpi < (base + nr_ids); lpi += IRQS_PER_CHUNK) { |
| 893 | int chunk = its_lpi_to_chunk(lpi); |
| 894 | BUG_ON(chunk > lpi_chunks); |
| 895 | if (test_bit(chunk, lpi_bitmap)) { |
| 896 | clear_bit(chunk, lpi_bitmap); |
| 897 | } else { |
| 898 | pr_err("Bad LPI chunk %d\n", chunk); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | spin_unlock(&lpi_lock); |
| 903 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 904 | kfree(map->lpi_map); |
| 905 | kfree(map->col_map); |
Marc Zyngier | bf9529f | 2014-11-24 14:35:13 +0000 | [diff] [blame] | 906 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 907 | |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame^] | 908 | static struct page *its_allocate_prop_table(gfp_t gfp_flags) |
| 909 | { |
| 910 | struct page *prop_page; |
| 911 | |
| 912 | prop_page = alloc_pages(gfp_flags, get_order(LPI_PROPBASE_SZ)); |
| 913 | if (!prop_page) |
| 914 | return NULL; |
| 915 | |
| 916 | /* Priority 0xa0, Group-1, disabled */ |
| 917 | memset(page_address(prop_page), |
| 918 | LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1, |
| 919 | LPI_PROPBASE_SZ); |
| 920 | |
| 921 | /* Make sure the GIC will observe the written configuration */ |
| 922 | gic_flush_dcache_to_poc(page_address(prop_page), LPI_PROPBASE_SZ); |
| 923 | |
| 924 | return prop_page; |
| 925 | } |
| 926 | |
| 927 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 928 | static int __init its_alloc_lpi_tables(void) |
| 929 | { |
| 930 | phys_addr_t paddr; |
| 931 | |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 932 | lpi_id_bits = min_t(u32, gic_rdists->id_bits, ITS_MAX_LPI_NRBITS); |
Marc Zyngier | 0e5ccf9 | 2016-12-19 18:15:05 +0000 | [diff] [blame^] | 933 | gic_rdists->prop_page = its_allocate_prop_table(GFP_NOWAIT); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 934 | if (!gic_rdists->prop_page) { |
| 935 | pr_err("Failed to allocate PROPBASE\n"); |
| 936 | return -ENOMEM; |
| 937 | } |
| 938 | |
| 939 | paddr = page_to_phys(gic_rdists->prop_page); |
| 940 | pr_info("GIC: using LPI property table @%pa\n", &paddr); |
| 941 | |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 942 | return its_lpi_init(lpi_id_bits); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static const char *its_base_type_string[] = { |
| 946 | [GITS_BASER_TYPE_DEVICE] = "Devices", |
| 947 | [GITS_BASER_TYPE_VCPU] = "Virtual CPUs", |
Marc Zyngier | 4f46de9 | 2016-12-20 15:50:14 +0000 | [diff] [blame] | 948 | [GITS_BASER_TYPE_RESERVED3] = "Reserved (3)", |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 949 | [GITS_BASER_TYPE_COLLECTION] = "Interrupt Collections", |
| 950 | [GITS_BASER_TYPE_RESERVED5] = "Reserved (5)", |
| 951 | [GITS_BASER_TYPE_RESERVED6] = "Reserved (6)", |
| 952 | [GITS_BASER_TYPE_RESERVED7] = "Reserved (7)", |
| 953 | }; |
| 954 | |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 955 | static u64 its_read_baser(struct its_node *its, struct its_baser *baser) |
| 956 | { |
| 957 | u32 idx = baser - its->tables; |
| 958 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 959 | return gits_read_baser(its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static void its_write_baser(struct its_node *its, struct its_baser *baser, |
| 963 | u64 val) |
| 964 | { |
| 965 | u32 idx = baser - its->tables; |
| 966 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 967 | gits_write_baser(val, its->base + GITS_BASER + (idx << 3)); |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 968 | baser->val = its_read_baser(its, baser); |
| 969 | } |
| 970 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 971 | 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] | 972 | u64 cache, u64 shr, u32 psz, u32 order, |
| 973 | bool indirect) |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 974 | { |
| 975 | u64 val = its_read_baser(its, baser); |
| 976 | u64 esz = GITS_BASER_ENTRY_SIZE(val); |
| 977 | u64 type = GITS_BASER_TYPE(val); |
| 978 | u32 alloc_pages; |
| 979 | void *base; |
| 980 | u64 tmp; |
| 981 | |
| 982 | retry_alloc_baser: |
| 983 | alloc_pages = (PAGE_ORDER_TO_SIZE(order) / psz); |
| 984 | if (alloc_pages > GITS_BASER_PAGES_MAX) { |
| 985 | pr_warn("ITS@%pa: %s too large, reduce ITS pages %u->%u\n", |
| 986 | &its->phys_base, its_base_type_string[type], |
| 987 | alloc_pages, GITS_BASER_PAGES_MAX); |
| 988 | alloc_pages = GITS_BASER_PAGES_MAX; |
| 989 | order = get_order(GITS_BASER_PAGES_MAX * psz); |
| 990 | } |
| 991 | |
| 992 | base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order); |
| 993 | if (!base) |
| 994 | return -ENOMEM; |
| 995 | |
| 996 | retry_baser: |
| 997 | val = (virt_to_phys(base) | |
| 998 | (type << GITS_BASER_TYPE_SHIFT) | |
| 999 | ((esz - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | |
| 1000 | ((alloc_pages - 1) << GITS_BASER_PAGES_SHIFT) | |
| 1001 | cache | |
| 1002 | shr | |
| 1003 | GITS_BASER_VALID); |
| 1004 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1005 | val |= indirect ? GITS_BASER_INDIRECT : 0x0; |
| 1006 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1007 | switch (psz) { |
| 1008 | case SZ_4K: |
| 1009 | val |= GITS_BASER_PAGE_SIZE_4K; |
| 1010 | break; |
| 1011 | case SZ_16K: |
| 1012 | val |= GITS_BASER_PAGE_SIZE_16K; |
| 1013 | break; |
| 1014 | case SZ_64K: |
| 1015 | val |= GITS_BASER_PAGE_SIZE_64K; |
| 1016 | break; |
| 1017 | } |
| 1018 | |
| 1019 | its_write_baser(its, baser, val); |
| 1020 | tmp = baser->val; |
| 1021 | |
| 1022 | if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) { |
| 1023 | /* |
| 1024 | * Shareability didn't stick. Just use |
| 1025 | * whatever the read reported, which is likely |
| 1026 | * to be the only thing this redistributor |
| 1027 | * supports. If that's zero, make it |
| 1028 | * non-cacheable as well. |
| 1029 | */ |
| 1030 | shr = tmp & GITS_BASER_SHAREABILITY_MASK; |
| 1031 | if (!shr) { |
| 1032 | cache = GITS_BASER_nC; |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1033 | gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1034 | } |
| 1035 | goto retry_baser; |
| 1036 | } |
| 1037 | |
| 1038 | if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) { |
| 1039 | /* |
| 1040 | * Page size didn't stick. Let's try a smaller |
| 1041 | * size and retry. If we reach 4K, then |
| 1042 | * something is horribly wrong... |
| 1043 | */ |
| 1044 | free_pages((unsigned long)base, order); |
| 1045 | baser->base = NULL; |
| 1046 | |
| 1047 | switch (psz) { |
| 1048 | case SZ_16K: |
| 1049 | psz = SZ_4K; |
| 1050 | goto retry_alloc_baser; |
| 1051 | case SZ_64K: |
| 1052 | psz = SZ_16K; |
| 1053 | goto retry_alloc_baser; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | if (val != tmp) { |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 1058 | pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n", |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1059 | &its->phys_base, its_base_type_string[type], |
Vladimir Murzin | b11283e | 2016-11-02 11:54:03 +0000 | [diff] [blame] | 1060 | val, tmp); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1061 | free_pages((unsigned long)base, order); |
| 1062 | return -ENXIO; |
| 1063 | } |
| 1064 | |
| 1065 | baser->order = order; |
| 1066 | baser->base = base; |
| 1067 | baser->psz = psz; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1068 | tmp = indirect ? GITS_LVL1_ENTRY_SIZE : esz; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1069 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1070 | 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] | 1071 | &its->phys_base, (int)(PAGE_ORDER_TO_SIZE(order) / (int)tmp), |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1072 | its_base_type_string[type], |
| 1073 | (unsigned long)virt_to_phys(base), |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1074 | indirect ? "indirect" : "flat", (int)esz, |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1075 | psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT); |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1080 | static bool its_parse_baser_device(struct its_node *its, struct its_baser *baser, |
| 1081 | u32 psz, u32 *order) |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1082 | { |
| 1083 | u64 esz = GITS_BASER_ENTRY_SIZE(its_read_baser(its, baser)); |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 1084 | u64 val = GITS_BASER_InnerShareable | GITS_BASER_RaWaWb; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1085 | u32 ids = its->device_ids; |
| 1086 | u32 new_order = *order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1087 | bool indirect = false; |
| 1088 | |
| 1089 | /* No need to enable Indirection if memory requirement < (psz*2)bytes */ |
| 1090 | if ((esz << ids) > (psz * 2)) { |
| 1091 | /* |
| 1092 | * Find out whether hw supports a single or two-level table by |
| 1093 | * table by reading bit at offset '62' after writing '1' to it. |
| 1094 | */ |
| 1095 | its_write_baser(its, baser, val | GITS_BASER_INDIRECT); |
| 1096 | indirect = !!(baser->val & GITS_BASER_INDIRECT); |
| 1097 | |
| 1098 | if (indirect) { |
| 1099 | /* |
| 1100 | * The size of the lvl2 table is equal to ITS page size |
| 1101 | * which is 'psz'. For computing lvl1 table size, |
| 1102 | * subtract ID bits that sparse lvl2 table from 'ids' |
| 1103 | * which is reported by ITS hardware times lvl1 table |
| 1104 | * entry size. |
| 1105 | */ |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 1106 | ids -= ilog2(psz / (int)esz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1107 | esz = GITS_LVL1_ENTRY_SIZE; |
| 1108 | } |
| 1109 | } |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1110 | |
| 1111 | /* |
| 1112 | * Allocate as many entries as required to fit the |
| 1113 | * range of device IDs that the ITS can grok... The ID |
| 1114 | * space being incredibly sparse, this results in a |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1115 | * massive waste of memory if two-level device table |
| 1116 | * feature is not supported by hardware. |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1117 | */ |
| 1118 | new_order = max_t(u32, get_order(esz << ids), new_order); |
| 1119 | if (new_order >= MAX_ORDER) { |
| 1120 | new_order = MAX_ORDER - 1; |
Vladimir Murzin | d524eaa | 2016-11-02 11:54:04 +0000 | [diff] [blame] | 1121 | ids = ilog2(PAGE_ORDER_TO_SIZE(new_order) / (int)esz); |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1122 | pr_warn("ITS@%pa: Device Table too large, reduce ids %u->%u\n", |
| 1123 | &its->phys_base, its->device_ids, ids); |
| 1124 | } |
| 1125 | |
| 1126 | *order = new_order; |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1127 | |
| 1128 | return indirect; |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1129 | } |
| 1130 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1131 | static void its_free_tables(struct its_node *its) |
| 1132 | { |
| 1133 | int i; |
| 1134 | |
| 1135 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 1a485f4 | 2016-02-01 20:19:44 -0600 | [diff] [blame] | 1136 | if (its->tables[i].base) { |
| 1137 | free_pages((unsigned long)its->tables[i].base, |
| 1138 | its->tables[i].order); |
| 1139 | its->tables[i].base = NULL; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 1144 | static int its_alloc_tables(struct its_node *its) |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1145 | { |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 1146 | u64 typer = gic_read_typer(its->base + GITS_TYPER); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1147 | u32 ids = GITS_TYPER_DEVBITS(typer); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1148 | u64 shr = GITS_BASER_InnerShareable; |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 1149 | u64 cache = GITS_BASER_RaWaWb; |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1150 | u32 psz = SZ_64K; |
| 1151 | int err, i; |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 1152 | |
| 1153 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_22375) { |
| 1154 | /* |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1155 | * erratum 22375: only alloc 8MB table size |
| 1156 | * erratum 24313: ignore memory access type |
| 1157 | */ |
| 1158 | cache = GITS_BASER_nCnB; |
| 1159 | ids = 0x14; /* 20 bits, 8MB */ |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 1160 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1161 | |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 1162 | its->device_ids = ids; |
| 1163 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1164 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
Shanker Donthineni | 2d81d42 | 2016-06-06 18:17:28 -0500 | [diff] [blame] | 1165 | struct its_baser *baser = its->tables + i; |
| 1166 | u64 val = its_read_baser(its, baser); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1167 | u64 type = GITS_BASER_TYPE(val); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1168 | u32 order = get_order(psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1169 | bool indirect = false; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1170 | |
| 1171 | if (type == GITS_BASER_TYPE_NONE) |
| 1172 | continue; |
| 1173 | |
Shanker Donthineni | 4b75c45 | 2016-06-06 18:17:29 -0500 | [diff] [blame] | 1174 | if (type == GITS_BASER_TYPE_DEVICE) |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1175 | indirect = its_parse_baser_device(its, baser, psz, &order); |
Marc Zyngier | f54b97e | 2015-03-06 16:37:41 +0000 | [diff] [blame] | 1176 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1177 | err = its_setup_baser(its, baser, cache, shr, psz, order, indirect); |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1178 | if (err < 0) { |
| 1179 | its_free_tables(its); |
| 1180 | return err; |
Robert Richter | 30f2136 | 2015-09-21 22:58:34 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
Shanker Donthineni | 9347359 | 2016-06-06 18:17:30 -0500 | [diff] [blame] | 1183 | /* Update settings which will be used for next BASERn */ |
| 1184 | psz = baser->psz; |
| 1185 | cache = baser->val & GITS_BASER_CACHEABILITY_MASK; |
| 1186 | shr = baser->val & GITS_BASER_SHAREABILITY_MASK; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | return 0; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static int its_alloc_collections(struct its_node *its) |
| 1193 | { |
| 1194 | its->collections = kzalloc(nr_cpu_ids * sizeof(*its->collections), |
| 1195 | GFP_KERNEL); |
| 1196 | if (!its->collections) |
| 1197 | return -ENOMEM; |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | static void its_cpu_init_lpis(void) |
| 1203 | { |
| 1204 | void __iomem *rbase = gic_data_rdist_rd_base(); |
| 1205 | struct page *pend_page; |
| 1206 | u64 val, tmp; |
| 1207 | |
| 1208 | /* If we didn't allocate the pending table yet, do it now */ |
| 1209 | pend_page = gic_data_rdist()->pend_page; |
| 1210 | if (!pend_page) { |
| 1211 | phys_addr_t paddr; |
| 1212 | /* |
| 1213 | * The pending pages have to be at least 64kB aligned, |
| 1214 | * hence the 'max(LPI_PENDBASE_SZ, SZ_64K)' below. |
| 1215 | */ |
| 1216 | pend_page = alloc_pages(GFP_NOWAIT | __GFP_ZERO, |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 1217 | get_order(max_t(u32, LPI_PENDBASE_SZ, SZ_64K))); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1218 | if (!pend_page) { |
| 1219 | pr_err("Failed to allocate PENDBASE for CPU%d\n", |
| 1220 | smp_processor_id()); |
| 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | /* Make sure the GIC will observe the zero-ed page */ |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1225 | gic_flush_dcache_to_poc(page_address(pend_page), LPI_PENDBASE_SZ); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1226 | |
| 1227 | paddr = page_to_phys(pend_page); |
| 1228 | pr_info("CPU%d: using LPI pending table @%pa\n", |
| 1229 | smp_processor_id(), &paddr); |
| 1230 | gic_data_rdist()->pend_page = pend_page; |
| 1231 | } |
| 1232 | |
| 1233 | /* Disable LPIs */ |
| 1234 | val = readl_relaxed(rbase + GICR_CTLR); |
| 1235 | val &= ~GICR_CTLR_ENABLE_LPIS; |
| 1236 | writel_relaxed(val, rbase + GICR_CTLR); |
| 1237 | |
| 1238 | /* |
| 1239 | * Make sure any change to the table is observable by the GIC. |
| 1240 | */ |
| 1241 | dsb(sy); |
| 1242 | |
| 1243 | /* set PROPBASE */ |
| 1244 | val = (page_to_phys(gic_rdists->prop_page) | |
| 1245 | GICR_PROPBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 1246 | GICR_PROPBASER_RaWaWb | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1247 | ((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK)); |
| 1248 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1249 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
| 1250 | tmp = gicr_read_propbaser(rbase + GICR_PROPBASER); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1251 | |
| 1252 | if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1253 | if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) { |
| 1254 | /* |
| 1255 | * The HW reports non-shareable, we must |
| 1256 | * remove the cacheability attributes as |
| 1257 | * well. |
| 1258 | */ |
| 1259 | val &= ~(GICR_PROPBASER_SHAREABILITY_MASK | |
| 1260 | GICR_PROPBASER_CACHEABILITY_MASK); |
| 1261 | val |= GICR_PROPBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1262 | gicr_write_propbaser(val, rbase + GICR_PROPBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1263 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1264 | pr_info_once("GIC: using cache flushing for LPI property table\n"); |
| 1265 | gic_rdists->flags |= RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING; |
| 1266 | } |
| 1267 | |
| 1268 | /* set PENDBASE */ |
| 1269 | val = (page_to_phys(pend_page) | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 1270 | GICR_PENDBASER_InnerShareable | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 1271 | GICR_PENDBASER_RaWaWb); |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1272 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1273 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
| 1274 | tmp = gicr_read_pendbaser(rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1275 | |
| 1276 | if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) { |
| 1277 | /* |
| 1278 | * The HW reports non-shareable, we must remove the |
| 1279 | * cacheability attributes as well. |
| 1280 | */ |
| 1281 | val &= ~(GICR_PENDBASER_SHAREABILITY_MASK | |
| 1282 | GICR_PENDBASER_CACHEABILITY_MASK); |
| 1283 | val |= GICR_PENDBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1284 | gicr_write_pendbaser(val, rbase + GICR_PENDBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1285 | } |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1286 | |
| 1287 | /* Enable LPIs */ |
| 1288 | val = readl_relaxed(rbase + GICR_CTLR); |
| 1289 | val |= GICR_CTLR_ENABLE_LPIS; |
| 1290 | writel_relaxed(val, rbase + GICR_CTLR); |
| 1291 | |
| 1292 | /* Make sure the GIC has seen the above */ |
| 1293 | dsb(sy); |
| 1294 | } |
| 1295 | |
| 1296 | static void its_cpu_init_collection(void) |
| 1297 | { |
| 1298 | struct its_node *its; |
| 1299 | int cpu; |
| 1300 | |
| 1301 | spin_lock(&its_lock); |
| 1302 | cpu = smp_processor_id(); |
| 1303 | |
| 1304 | list_for_each_entry(its, &its_nodes, entry) { |
| 1305 | u64 target; |
| 1306 | |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1307 | /* avoid cross node collections and its mapping */ |
| 1308 | if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) { |
| 1309 | struct device_node *cpu_node; |
| 1310 | |
| 1311 | cpu_node = of_get_cpu_node(cpu, NULL); |
| 1312 | if (its->numa_node != NUMA_NO_NODE && |
| 1313 | its->numa_node != of_node_to_nid(cpu_node)) |
| 1314 | continue; |
| 1315 | } |
| 1316 | |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1317 | /* |
| 1318 | * We now have to bind each collection to its target |
| 1319 | * redistributor. |
| 1320 | */ |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 1321 | if (gic_read_typer(its->base + GITS_TYPER) & GITS_TYPER_PTA) { |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1322 | /* |
| 1323 | * This ITS wants the physical address of the |
| 1324 | * redistributor. |
| 1325 | */ |
| 1326 | target = gic_data_rdist()->phys_base; |
| 1327 | } else { |
| 1328 | /* |
| 1329 | * This ITS wants a linear CPU number. |
| 1330 | */ |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 1331 | target = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER); |
Marc Zyngier | 263fcd3 | 2015-03-27 14:15:02 +0000 | [diff] [blame] | 1332 | target = GICR_TYPER_CPU_NUMBER(target) << 16; |
Marc Zyngier | 1ac19ca | 2014-11-24 14:35:14 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | /* Perform collection mapping */ |
| 1336 | its->collections[cpu].target_address = target; |
| 1337 | its->collections[cpu].col_id = cpu; |
| 1338 | |
| 1339 | its_send_mapc(its, &its->collections[cpu], 1); |
| 1340 | its_send_invall(its, &its->collections[cpu]); |
| 1341 | } |
| 1342 | |
| 1343 | spin_unlock(&its_lock); |
| 1344 | } |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1345 | |
| 1346 | static struct its_device *its_find_device(struct its_node *its, u32 dev_id) |
| 1347 | { |
| 1348 | struct its_device *its_dev = NULL, *tmp; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1349 | unsigned long flags; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1350 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1351 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1352 | |
| 1353 | list_for_each_entry(tmp, &its->its_device_list, entry) { |
| 1354 | if (tmp->device_id == dev_id) { |
| 1355 | its_dev = tmp; |
| 1356 | break; |
| 1357 | } |
| 1358 | } |
| 1359 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1360 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1361 | |
| 1362 | return its_dev; |
| 1363 | } |
| 1364 | |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 1365 | static struct its_baser *its_get_baser(struct its_node *its, u32 type) |
| 1366 | { |
| 1367 | int i; |
| 1368 | |
| 1369 | for (i = 0; i < GITS_BASER_NR_REGS; i++) { |
| 1370 | if (GITS_BASER_TYPE(its->tables[i].val) == type) |
| 1371 | return &its->tables[i]; |
| 1372 | } |
| 1373 | |
| 1374 | return NULL; |
| 1375 | } |
| 1376 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1377 | static bool its_alloc_device_table(struct its_node *its, u32 dev_id) |
| 1378 | { |
| 1379 | struct its_baser *baser; |
| 1380 | struct page *page; |
| 1381 | u32 esz, idx; |
| 1382 | __le64 *table; |
| 1383 | |
| 1384 | baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE); |
| 1385 | |
| 1386 | /* Don't allow device id that exceeds ITS hardware limit */ |
| 1387 | if (!baser) |
| 1388 | return (ilog2(dev_id) < its->device_ids); |
| 1389 | |
| 1390 | /* Don't allow device id that exceeds single, flat table limit */ |
| 1391 | esz = GITS_BASER_ENTRY_SIZE(baser->val); |
| 1392 | if (!(baser->val & GITS_BASER_INDIRECT)) |
| 1393 | return (dev_id < (PAGE_ORDER_TO_SIZE(baser->order) / esz)); |
| 1394 | |
| 1395 | /* Compute 1st level table index & check if that exceeds table limit */ |
| 1396 | idx = dev_id >> ilog2(baser->psz / esz); |
| 1397 | if (idx >= (PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE)) |
| 1398 | return false; |
| 1399 | |
| 1400 | table = baser->base; |
| 1401 | |
| 1402 | /* Allocate memory for 2nd level table */ |
| 1403 | if (!table[idx]) { |
| 1404 | page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(baser->psz)); |
| 1405 | if (!page) |
| 1406 | return false; |
| 1407 | |
| 1408 | /* Flush Lvl2 table to PoC if hw doesn't support coherency */ |
| 1409 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1410 | gic_flush_dcache_to_poc(page_address(page), baser->psz); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1411 | |
| 1412 | table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID); |
| 1413 | |
| 1414 | /* Flush Lvl1 entry to PoC if hw doesn't support coherency */ |
| 1415 | if (!(baser->val & GITS_BASER_SHAREABILITY_MASK)) |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1416 | gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE); |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1417 | |
| 1418 | /* Ensure updated table contents are visible to ITS hardware */ |
| 1419 | dsb(sy); |
| 1420 | } |
| 1421 | |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1425 | static struct its_device *its_create_device(struct its_node *its, u32 dev_id, |
| 1426 | int nvecs) |
| 1427 | { |
| 1428 | struct its_device *dev; |
| 1429 | unsigned long *lpi_map; |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1430 | unsigned long flags; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1431 | u16 *col_map = NULL; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1432 | void *itt; |
| 1433 | int lpi_base; |
| 1434 | int nr_lpis; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 1435 | int nr_ites; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1436 | int sz; |
| 1437 | |
Shanker Donthineni | 3faf24e | 2016-06-06 18:17:32 -0500 | [diff] [blame] | 1438 | if (!its_alloc_device_table(its, dev_id)) |
Shanker Donthineni | 466b7d1 | 2016-03-09 22:10:49 -0600 | [diff] [blame] | 1439 | return NULL; |
| 1440 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1441 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 1442 | /* |
| 1443 | * At least one bit of EventID is being used, hence a minimum |
| 1444 | * of two entries. No, the architecture doesn't let you |
| 1445 | * express an ITT with a single entry. |
| 1446 | */ |
Will Deacon | 96555c4 | 2014-12-17 14:11:09 +0000 | [diff] [blame] | 1447 | nr_ites = max(2UL, roundup_pow_of_two(nvecs)); |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 1448 | sz = nr_ites * its->ite_size; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1449 | sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; |
Yun Wu | 6c83412 | 2015-03-06 16:37:46 +0000 | [diff] [blame] | 1450 | itt = kzalloc(sz, GFP_KERNEL); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1451 | lpi_map = its_lpi_alloc_chunks(nvecs, &lpi_base, &nr_lpis); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1452 | if (lpi_map) |
| 1453 | col_map = kzalloc(sizeof(*col_map) * nr_lpis, GFP_KERNEL); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1454 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1455 | if (!dev || !itt || !lpi_map || !col_map) { |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1456 | kfree(dev); |
| 1457 | kfree(itt); |
| 1458 | kfree(lpi_map); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1459 | kfree(col_map); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1460 | return NULL; |
| 1461 | } |
| 1462 | |
Vladimir Murzin | 328191c | 2016-11-02 11:54:05 +0000 | [diff] [blame] | 1463 | gic_flush_dcache_to_poc(itt, sz); |
Marc Zyngier | 5a9a891 | 2015-09-13 12:14:32 +0100 | [diff] [blame] | 1464 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1465 | dev->its = its; |
| 1466 | dev->itt = itt; |
Marc Zyngier | c848126 | 2014-12-12 10:51:24 +0000 | [diff] [blame] | 1467 | dev->nr_ites = nr_ites; |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1468 | dev->event_map.lpi_map = lpi_map; |
| 1469 | dev->event_map.col_map = col_map; |
| 1470 | dev->event_map.lpi_base = lpi_base; |
| 1471 | dev->event_map.nr_lpis = nr_lpis; |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1472 | dev->device_id = dev_id; |
| 1473 | INIT_LIST_HEAD(&dev->entry); |
| 1474 | |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1475 | raw_spin_lock_irqsave(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1476 | list_add(&dev->entry, &its->its_device_list); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1477 | raw_spin_unlock_irqrestore(&its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1478 | |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1479 | /* Map device to its ITT */ |
| 1480 | its_send_mapd(dev, 1); |
| 1481 | |
| 1482 | return dev; |
| 1483 | } |
| 1484 | |
| 1485 | static void its_free_device(struct its_device *its_dev) |
| 1486 | { |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1487 | unsigned long flags; |
| 1488 | |
| 1489 | raw_spin_lock_irqsave(&its_dev->its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1490 | list_del(&its_dev->entry); |
Marc Zyngier | 3e39e8f5 | 2015-03-06 16:37:43 +0000 | [diff] [blame] | 1491 | raw_spin_unlock_irqrestore(&its_dev->its->lock, flags); |
Marc Zyngier | 84a6a2e | 2014-11-24 14:35:15 +0000 | [diff] [blame] | 1492 | kfree(its_dev->itt); |
| 1493 | kfree(its_dev); |
| 1494 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1495 | |
| 1496 | static int its_alloc_device_irq(struct its_device *dev, irq_hw_number_t *hwirq) |
| 1497 | { |
| 1498 | int idx; |
| 1499 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1500 | idx = find_first_zero_bit(dev->event_map.lpi_map, |
| 1501 | dev->event_map.nr_lpis); |
| 1502 | if (idx == dev->event_map.nr_lpis) |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1503 | return -ENOSPC; |
| 1504 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1505 | *hwirq = dev->event_map.lpi_base + idx; |
| 1506 | set_bit(idx, dev->event_map.lpi_map); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1507 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1508 | return 0; |
| 1509 | } |
| 1510 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 1511 | static int its_msi_prepare(struct irq_domain *domain, struct device *dev, |
| 1512 | int nvec, msi_alloc_info_t *info) |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 1513 | { |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1514 | struct its_node *its; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1515 | struct its_device *its_dev; |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 1516 | struct msi_domain_info *msi_info; |
| 1517 | u32 dev_id; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1518 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 1519 | /* |
| 1520 | * We ignore "dev" entierely, and rely on the dev_id that has |
| 1521 | * been passed via the scratchpad. This limits this domain's |
| 1522 | * usefulness to upper layers that definitely know that they |
| 1523 | * are built on top of the ITS. |
| 1524 | */ |
| 1525 | dev_id = info->scratchpad[0].ul; |
| 1526 | |
| 1527 | msi_info = msi_get_domain_info(domain); |
| 1528 | its = msi_info->data; |
| 1529 | |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 1530 | its_dev = its_find_device(its, dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 1531 | if (its_dev) { |
| 1532 | /* |
| 1533 | * We already have seen this ID, probably through |
| 1534 | * another alias (PCI bridge of some sort). No need to |
| 1535 | * create the device. |
| 1536 | */ |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 1537 | pr_debug("Reusing ITT for devID %x\n", dev_id); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 1538 | goto out; |
| 1539 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1540 | |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 1541 | its_dev = its_create_device(its, dev_id, nvec); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1542 | if (!its_dev) |
| 1543 | return -ENOMEM; |
| 1544 | |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 1545 | pr_debug("ITT %d entries, %d bits\n", nvec, ilog2(nvec)); |
Marc Zyngier | e8137f4 | 2015-03-06 16:37:42 +0000 | [diff] [blame] | 1546 | out: |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1547 | info->scratchpad[0].ptr = its_dev; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1548 | return 0; |
| 1549 | } |
| 1550 | |
Marc Zyngier | 54456db | 2015-07-28 14:46:21 +0100 | [diff] [blame] | 1551 | static struct msi_domain_ops its_msi_domain_ops = { |
| 1552 | .msi_prepare = its_msi_prepare, |
| 1553 | }; |
| 1554 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1555 | static int its_irq_gic_domain_alloc(struct irq_domain *domain, |
| 1556 | unsigned int virq, |
| 1557 | irq_hw_number_t hwirq) |
| 1558 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 1559 | struct irq_fwspec fwspec; |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1560 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 1561 | if (irq_domain_get_of_node(domain->parent)) { |
| 1562 | fwspec.fwnode = domain->parent->fwnode; |
| 1563 | fwspec.param_count = 3; |
| 1564 | fwspec.param[0] = GIC_IRQ_TYPE_LPI; |
| 1565 | fwspec.param[1] = hwirq; |
| 1566 | fwspec.param[2] = IRQ_TYPE_EDGE_RISING; |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 1567 | } else if (is_fwnode_irqchip(domain->parent->fwnode)) { |
| 1568 | fwspec.fwnode = domain->parent->fwnode; |
| 1569 | fwspec.param_count = 2; |
| 1570 | fwspec.param[0] = hwirq; |
| 1571 | fwspec.param[1] = IRQ_TYPE_EDGE_RISING; |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 1572 | } else { |
| 1573 | return -EINVAL; |
| 1574 | } |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1575 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 1576 | return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | static int its_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 1580 | unsigned int nr_irqs, void *args) |
| 1581 | { |
| 1582 | msi_alloc_info_t *info = args; |
| 1583 | struct its_device *its_dev = info->scratchpad[0].ptr; |
| 1584 | irq_hw_number_t hwirq; |
| 1585 | int err; |
| 1586 | int i; |
| 1587 | |
| 1588 | for (i = 0; i < nr_irqs; i++) { |
| 1589 | err = its_alloc_device_irq(its_dev, &hwirq); |
| 1590 | if (err) |
| 1591 | return err; |
| 1592 | |
| 1593 | err = its_irq_gic_domain_alloc(domain, virq + i, hwirq); |
| 1594 | if (err) |
| 1595 | return err; |
| 1596 | |
| 1597 | irq_domain_set_hwirq_and_chip(domain, virq + i, |
| 1598 | hwirq, &its_irq_chip, its_dev); |
Marc Zyngier | f130420 | 2015-07-28 14:46:18 +0100 | [diff] [blame] | 1599 | pr_debug("ID:%d pID:%d vID:%d\n", |
| 1600 | (int)(hwirq - its_dev->event_map.lpi_base), |
| 1601 | (int) hwirq, virq + i); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | return 0; |
| 1605 | } |
| 1606 | |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1607 | static void its_irq_domain_activate(struct irq_domain *domain, |
| 1608 | struct irq_data *d) |
| 1609 | { |
| 1610 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1611 | u32 event = its_get_event_id(d); |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1612 | const struct cpumask *cpu_mask = cpu_online_mask; |
| 1613 | |
| 1614 | /* get the cpu_mask of local node */ |
| 1615 | if (its_dev->its->numa_node >= 0) |
| 1616 | cpu_mask = cpumask_of_node(its_dev->its->numa_node); |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1617 | |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1618 | /* Bind the LPI to the first possible CPU */ |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1619 | its_dev->event_map.col_map[event] = cpumask_first(cpu_mask); |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1620 | |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1621 | /* Map the GIC IRQ and event to the device */ |
Marc Zyngier | 6a25ad3 | 2016-12-20 15:52:26 +0000 | [diff] [blame] | 1622 | its_send_mapti(its_dev, d->hwirq, event); |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | static void its_irq_domain_deactivate(struct irq_domain *domain, |
| 1626 | struct irq_data *d) |
| 1627 | { |
| 1628 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1629 | u32 event = its_get_event_id(d); |
| 1630 | |
| 1631 | /* Stop the delivery of interrupts */ |
| 1632 | its_send_discard(its_dev, event); |
| 1633 | } |
| 1634 | |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1635 | static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq, |
| 1636 | unsigned int nr_irqs) |
| 1637 | { |
| 1638 | struct irq_data *d = irq_domain_get_irq_data(domain, virq); |
| 1639 | struct its_device *its_dev = irq_data_get_irq_chip_data(d); |
| 1640 | int i; |
| 1641 | |
| 1642 | for (i = 0; i < nr_irqs; i++) { |
| 1643 | struct irq_data *data = irq_domain_get_irq_data(domain, |
| 1644 | virq + i); |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1645 | u32 event = its_get_event_id(data); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1646 | |
| 1647 | /* Mark interrupt index as unused */ |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1648 | clear_bit(event, its_dev->event_map.lpi_map); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1649 | |
| 1650 | /* Nuke the entry in the domain */ |
Marc Zyngier | 2da3994 | 2014-12-12 10:51:22 +0000 | [diff] [blame] | 1651 | irq_domain_reset_irq_data(data); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /* If all interrupts have been freed, start mopping the floor */ |
Marc Zyngier | 591e5be | 2015-07-17 10:46:42 +0100 | [diff] [blame] | 1655 | if (bitmap_empty(its_dev->event_map.lpi_map, |
| 1656 | its_dev->event_map.nr_lpis)) { |
| 1657 | its_lpi_free(&its_dev->event_map); |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1658 | |
| 1659 | /* Unmap device/itt */ |
| 1660 | its_send_mapd(its_dev, 0); |
| 1661 | its_free_device(its_dev); |
| 1662 | } |
| 1663 | |
| 1664 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 1665 | } |
| 1666 | |
| 1667 | static const struct irq_domain_ops its_domain_ops = { |
| 1668 | .alloc = its_irq_domain_alloc, |
| 1669 | .free = its_irq_domain_free, |
Marc Zyngier | aca268d | 2014-12-12 10:51:23 +0000 | [diff] [blame] | 1670 | .activate = its_irq_domain_activate, |
| 1671 | .deactivate = its_irq_domain_deactivate, |
Marc Zyngier | b48ac83 | 2014-11-24 14:35:16 +0000 | [diff] [blame] | 1672 | }; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1673 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 1674 | static int its_force_quiescent(void __iomem *base) |
| 1675 | { |
| 1676 | u32 count = 1000000; /* 1s */ |
| 1677 | u32 val; |
| 1678 | |
| 1679 | val = readl_relaxed(base + GITS_CTLR); |
David Daney | 7611da8 | 2016-08-18 15:41:58 -0700 | [diff] [blame] | 1680 | /* |
| 1681 | * GIC architecture specification requires the ITS to be both |
| 1682 | * disabled and quiescent for writes to GITS_BASER<n> or |
| 1683 | * GITS_CBASER to not have UNPREDICTABLE results. |
| 1684 | */ |
| 1685 | if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE)) |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 1686 | return 0; |
| 1687 | |
| 1688 | /* Disable the generation of all interrupts to this ITS */ |
| 1689 | val &= ~GITS_CTLR_ENABLE; |
| 1690 | writel_relaxed(val, base + GITS_CTLR); |
| 1691 | |
| 1692 | /* Poll GITS_CTLR and wait until ITS becomes quiescent */ |
| 1693 | while (1) { |
| 1694 | val = readl_relaxed(base + GITS_CTLR); |
| 1695 | if (val & GITS_CTLR_QUIESCENT) |
| 1696 | return 0; |
| 1697 | |
| 1698 | count--; |
| 1699 | if (!count) |
| 1700 | return -EBUSY; |
| 1701 | |
| 1702 | cpu_relax(); |
| 1703 | udelay(1); |
| 1704 | } |
| 1705 | } |
| 1706 | |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 1707 | static void __maybe_unused its_enable_quirk_cavium_22375(void *data) |
| 1708 | { |
| 1709 | struct its_node *its = data; |
| 1710 | |
| 1711 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_22375; |
| 1712 | } |
| 1713 | |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1714 | static void __maybe_unused its_enable_quirk_cavium_23144(void *data) |
| 1715 | { |
| 1716 | struct its_node *its = data; |
| 1717 | |
| 1718 | its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_23144; |
| 1719 | } |
| 1720 | |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 1721 | static void __maybe_unused its_enable_quirk_qdf2400_e0065(void *data) |
| 1722 | { |
| 1723 | struct its_node *its = data; |
| 1724 | |
| 1725 | /* On QDF2400, the size of the ITE is 16Bytes */ |
| 1726 | its->ite_size = 16; |
| 1727 | } |
| 1728 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 1729 | static const struct gic_quirk its_quirks[] = { |
Robert Richter | 9410097 | 2015-09-21 22:58:38 +0200 | [diff] [blame] | 1730 | #ifdef CONFIG_CAVIUM_ERRATUM_22375 |
| 1731 | { |
| 1732 | .desc = "ITS: Cavium errata 22375, 24313", |
| 1733 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 1734 | .mask = 0xffff0fff, |
| 1735 | .init = its_enable_quirk_cavium_22375, |
| 1736 | }, |
| 1737 | #endif |
Ganapatrao Kulkarni | fbf8f40 | 2016-05-25 15:29:20 +0200 | [diff] [blame] | 1738 | #ifdef CONFIG_CAVIUM_ERRATUM_23144 |
| 1739 | { |
| 1740 | .desc = "ITS: Cavium erratum 23144", |
| 1741 | .iidr = 0xa100034c, /* ThunderX pass 1.x */ |
| 1742 | .mask = 0xffff0fff, |
| 1743 | .init = its_enable_quirk_cavium_23144, |
| 1744 | }, |
| 1745 | #endif |
Shanker Donthineni | 90922a2 | 2017-03-07 08:20:38 -0600 | [diff] [blame] | 1746 | #ifdef CONFIG_QCOM_QDF2400_ERRATUM_0065 |
| 1747 | { |
| 1748 | .desc = "ITS: QDF2400 erratum 0065", |
| 1749 | .iidr = 0x00001070, /* QDF2400 ITS rev 1.x */ |
| 1750 | .mask = 0xffffffff, |
| 1751 | .init = its_enable_quirk_qdf2400_e0065, |
| 1752 | }, |
| 1753 | #endif |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 1754 | { |
| 1755 | } |
| 1756 | }; |
| 1757 | |
| 1758 | static void its_enable_quirks(struct its_node *its) |
| 1759 | { |
| 1760 | u32 iidr = readl_relaxed(its->base + GITS_IIDR); |
| 1761 | |
| 1762 | gic_enable_quirks(iidr, its_quirks, its); |
| 1763 | } |
| 1764 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1765 | 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] | 1766 | { |
| 1767 | struct irq_domain *inner_domain; |
| 1768 | struct msi_domain_info *info; |
| 1769 | |
| 1770 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 1771 | if (!info) |
| 1772 | return -ENOMEM; |
| 1773 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1774 | inner_domain = irq_domain_create_tree(handle, &its_domain_ops, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 1775 | if (!inner_domain) { |
| 1776 | kfree(info); |
| 1777 | return -ENOMEM; |
| 1778 | } |
| 1779 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1780 | inner_domain->parent = its_parent; |
Marc Zyngier | 96f0d93 | 2017-06-22 11:42:50 +0100 | [diff] [blame] | 1781 | irq_domain_update_bus_token(inner_domain, DOMAIN_BUS_NEXUS); |
Eric Auger | 5976852 | 2017-01-19 20:58:00 +0000 | [diff] [blame] | 1782 | inner_domain->flags |= IRQ_DOMAIN_FLAG_MSI_REMAP; |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 1783 | info->ops = &its_msi_domain_ops; |
| 1784 | info->data = its; |
| 1785 | inner_domain->host_data = info; |
| 1786 | |
| 1787 | return 0; |
| 1788 | } |
| 1789 | |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 1790 | static int __init its_compute_its_list_map(struct resource *res, |
| 1791 | void __iomem *its_base) |
| 1792 | { |
| 1793 | int its_number; |
| 1794 | u32 ctlr; |
| 1795 | |
| 1796 | /* |
| 1797 | * This is assumed to be done early enough that we're |
| 1798 | * guaranteed to be single-threaded, hence no |
| 1799 | * locking. Should this change, we should address |
| 1800 | * this. |
| 1801 | */ |
| 1802 | its_number = find_first_zero_bit(&its_list_map, ITS_LIST_MAX); |
| 1803 | if (its_number >= ITS_LIST_MAX) { |
| 1804 | pr_err("ITS@%pa: No ITSList entry available!\n", |
| 1805 | &res->start); |
| 1806 | return -EINVAL; |
| 1807 | } |
| 1808 | |
| 1809 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 1810 | ctlr &= ~GITS_CTLR_ITS_NUMBER; |
| 1811 | ctlr |= its_number << GITS_CTLR_ITS_NUMBER_SHIFT; |
| 1812 | writel_relaxed(ctlr, its_base + GITS_CTLR); |
| 1813 | ctlr = readl_relaxed(its_base + GITS_CTLR); |
| 1814 | if ((ctlr & GITS_CTLR_ITS_NUMBER) != (its_number << GITS_CTLR_ITS_NUMBER_SHIFT)) { |
| 1815 | its_number = ctlr & GITS_CTLR_ITS_NUMBER; |
| 1816 | its_number >>= GITS_CTLR_ITS_NUMBER_SHIFT; |
| 1817 | } |
| 1818 | |
| 1819 | if (test_and_set_bit(its_number, &its_list_map)) { |
| 1820 | pr_err("ITS@%pa: Duplicate ITSList entry %d\n", |
| 1821 | &res->start, its_number); |
| 1822 | return -EINVAL; |
| 1823 | } |
| 1824 | |
| 1825 | return its_number; |
| 1826 | } |
| 1827 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1828 | static int __init its_probe_one(struct resource *res, |
| 1829 | struct fwnode_handle *handle, int numa_node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1830 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1831 | struct its_node *its; |
| 1832 | void __iomem *its_base; |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 1833 | u32 val, ctlr; |
| 1834 | u64 baser, tmp, typer; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1835 | int err; |
| 1836 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1837 | its_base = ioremap(res->start, resource_size(res)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1838 | if (!its_base) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1839 | pr_warn("ITS@%pa: Unable to map ITS registers\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1840 | return -ENOMEM; |
| 1841 | } |
| 1842 | |
| 1843 | val = readl_relaxed(its_base + GITS_PIDR2) & GIC_PIDR2_ARCH_MASK; |
| 1844 | if (val != 0x30 && val != 0x40) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1845 | pr_warn("ITS@%pa: No ITS detected, giving up\n", &res->start); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1846 | err = -ENODEV; |
| 1847 | goto out_unmap; |
| 1848 | } |
| 1849 | |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 1850 | err = its_force_quiescent(its_base); |
| 1851 | if (err) { |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1852 | pr_warn("ITS@%pa: Failed to quiesce, giving up\n", &res->start); |
Yun Wu | 4559fbb | 2015-03-06 16:37:50 +0000 | [diff] [blame] | 1853 | goto out_unmap; |
| 1854 | } |
| 1855 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1856 | pr_info("ITS %pR\n", res); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1857 | |
| 1858 | its = kzalloc(sizeof(*its), GFP_KERNEL); |
| 1859 | if (!its) { |
| 1860 | err = -ENOMEM; |
| 1861 | goto out_unmap; |
| 1862 | } |
| 1863 | |
| 1864 | raw_spin_lock_init(&its->lock); |
| 1865 | INIT_LIST_HEAD(&its->entry); |
| 1866 | INIT_LIST_HEAD(&its->its_device_list); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 1867 | typer = gic_read_typer(its_base + GITS_TYPER); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1868 | its->base = its_base; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1869 | its->phys_base = res->start; |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 1870 | its->ite_size = GITS_TYPER_ITT_ENTRY_SIZE(typer); |
| 1871 | its->is_v4 = !!(typer & GITS_TYPER_VLPIS); |
| 1872 | if (its->is_v4) { |
| 1873 | if (!(typer & GITS_TYPER_VMOVP)) { |
| 1874 | err = its_compute_its_list_map(res, its_base); |
| 1875 | if (err < 0) |
| 1876 | goto out_free_its; |
| 1877 | |
| 1878 | pr_info("ITS@%pa: Using ITS number %d\n", |
| 1879 | &res->start, err); |
| 1880 | } else { |
| 1881 | pr_info("ITS@%pa: Single VMOVP capable\n", &res->start); |
| 1882 | } |
| 1883 | } |
| 1884 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1885 | its->numa_node = numa_node; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1886 | |
Robert Richter | 5bc13c2 | 2017-02-01 18:38:25 +0100 | [diff] [blame] | 1887 | its->cmd_base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 1888 | get_order(ITS_CMD_QUEUE_SZ)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1889 | if (!its->cmd_base) { |
| 1890 | err = -ENOMEM; |
| 1891 | goto out_free_its; |
| 1892 | } |
| 1893 | its->cmd_write = its->cmd_base; |
| 1894 | |
Robert Richter | 67510cc | 2015-09-21 22:58:37 +0200 | [diff] [blame] | 1895 | its_enable_quirks(its); |
| 1896 | |
Shanker Donthineni | 0e0b0f6 | 2016-06-06 18:17:31 -0500 | [diff] [blame] | 1897 | err = its_alloc_tables(its); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1898 | if (err) |
| 1899 | goto out_free_cmd; |
| 1900 | |
| 1901 | err = its_alloc_collections(its); |
| 1902 | if (err) |
| 1903 | goto out_free_tables; |
| 1904 | |
| 1905 | baser = (virt_to_phys(its->cmd_base) | |
Shanker Donthineni | 2fd632a | 2017-01-25 21:51:41 -0600 | [diff] [blame] | 1906 | GITS_CBASER_RaWaWb | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1907 | GITS_CBASER_InnerShareable | |
| 1908 | (ITS_CMD_QUEUE_SZ / SZ_4K - 1) | |
| 1909 | GITS_CBASER_VALID); |
| 1910 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1911 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
| 1912 | tmp = gits_read_cbaser(its->base + GITS_CBASER); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1913 | |
Marc Zyngier | 4ad3e36 | 2015-03-27 14:15:04 +0000 | [diff] [blame] | 1914 | if ((tmp ^ baser) & GITS_CBASER_SHAREABILITY_MASK) { |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1915 | if (!(tmp & GITS_CBASER_SHAREABILITY_MASK)) { |
| 1916 | /* |
| 1917 | * The HW reports non-shareable, we must |
| 1918 | * remove the cacheability attributes as |
| 1919 | * well. |
| 1920 | */ |
| 1921 | baser &= ~(GITS_CBASER_SHAREABILITY_MASK | |
| 1922 | GITS_CBASER_CACHEABILITY_MASK); |
| 1923 | baser |= GITS_CBASER_nC; |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1924 | gits_write_cbaser(baser, its->base + GITS_CBASER); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1925 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1926 | pr_info("ITS: using cache flushing for cmd queue\n"); |
| 1927 | its->flags |= ITS_FLAGS_CMDQ_NEEDS_FLUSHING; |
| 1928 | } |
| 1929 | |
Vladimir Murzin | 0968a61 | 2016-11-02 11:54:06 +0000 | [diff] [blame] | 1930 | gits_write_cwriter(0, its->base + GITS_CWRITER); |
Marc Zyngier | 3dfa576 | 2016-12-19 17:25:54 +0000 | [diff] [blame] | 1931 | ctlr = readl_relaxed(its->base + GITS_CTLR); |
| 1932 | writel_relaxed(ctlr | GITS_CTLR_ENABLE, its->base + GITS_CTLR); |
Marc Zyngier | 241a386 | 2015-03-27 14:15:05 +0000 | [diff] [blame] | 1933 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1934 | err = its_init_domain(handle, its); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 1935 | if (err) |
| 1936 | goto out_free_tables; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1937 | |
| 1938 | spin_lock(&its_lock); |
| 1939 | list_add(&its->entry, &its_nodes); |
| 1940 | spin_unlock(&its_lock); |
| 1941 | |
| 1942 | return 0; |
| 1943 | |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1944 | out_free_tables: |
| 1945 | its_free_tables(its); |
| 1946 | out_free_cmd: |
Robert Richter | 5bc13c2 | 2017-02-01 18:38:25 +0100 | [diff] [blame] | 1947 | free_pages((unsigned long)its->cmd_base, get_order(ITS_CMD_QUEUE_SZ)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1948 | out_free_its: |
| 1949 | kfree(its); |
| 1950 | out_unmap: |
| 1951 | iounmap(its_base); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1952 | pr_err("ITS@%pa: failed probing (%d)\n", &res->start, err); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1953 | return err; |
| 1954 | } |
| 1955 | |
| 1956 | static bool gic_rdists_supports_plpis(void) |
| 1957 | { |
Marc Zyngier | 589ce5f | 2016-10-14 15:13:07 +0100 | [diff] [blame] | 1958 | 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] | 1959 | } |
| 1960 | |
| 1961 | int its_cpu_init(void) |
| 1962 | { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1963 | if (!list_empty(&its_nodes)) { |
Vladimir Murzin | 16acae7 | 2015-03-06 16:37:40 +0000 | [diff] [blame] | 1964 | if (!gic_rdists_supports_plpis()) { |
| 1965 | pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); |
| 1966 | return -ENXIO; |
| 1967 | } |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1968 | its_cpu_init_lpis(); |
| 1969 | its_cpu_init_collection(); |
| 1970 | } |
| 1971 | |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
Arvind Yadav | 935bba7 | 2017-06-22 16:05:30 +0530 | [diff] [blame] | 1975 | static const struct of_device_id its_device_id[] = { |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1976 | { .compatible = "arm,gic-v3-its", }, |
| 1977 | {}, |
| 1978 | }; |
| 1979 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1980 | static int __init its_of_probe(struct device_node *node) |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1981 | { |
| 1982 | struct device_node *np; |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1983 | struct resource res; |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1984 | |
| 1985 | for (np = of_find_matching_node(node, its_device_id); np; |
| 1986 | np = of_find_matching_node(np, its_device_id)) { |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 1987 | if (!of_property_read_bool(np, "msi-controller")) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 1988 | pr_warn("%pOF: no msi-controller property, ITS ignored\n", |
| 1989 | np); |
Tomasz Nowicki | d14ae5e | 2016-09-12 20:32:23 +0200 | [diff] [blame] | 1990 | continue; |
| 1991 | } |
| 1992 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1993 | if (of_address_to_resource(np, 0, &res)) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 1994 | pr_warn("%pOF: no regs?\n", np); |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 1995 | continue; |
| 1996 | } |
| 1997 | |
| 1998 | its_probe_one(&res, &np->fwnode, of_node_to_nid(np)); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 1999 | } |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 2000 | return 0; |
| 2001 | } |
| 2002 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2003 | #ifdef CONFIG_ACPI |
| 2004 | |
| 2005 | #define ACPI_GICV3_ITS_MEM_SIZE (SZ_128K) |
| 2006 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 2007 | #if defined(CONFIG_ACPI_NUMA) && (ACPI_CA_VERSION >= 0x20170531) |
| 2008 | struct its_srat_map { |
| 2009 | /* numa node id */ |
| 2010 | u32 numa_node; |
| 2011 | /* GIC ITS ID */ |
| 2012 | u32 its_id; |
| 2013 | }; |
| 2014 | |
| 2015 | static struct its_srat_map its_srat_maps[MAX_NUMNODES] __initdata; |
| 2016 | static int its_in_srat __initdata; |
| 2017 | |
| 2018 | static int __init acpi_get_its_numa_node(u32 its_id) |
| 2019 | { |
| 2020 | int i; |
| 2021 | |
| 2022 | for (i = 0; i < its_in_srat; i++) { |
| 2023 | if (its_id == its_srat_maps[i].its_id) |
| 2024 | return its_srat_maps[i].numa_node; |
| 2025 | } |
| 2026 | return NUMA_NO_NODE; |
| 2027 | } |
| 2028 | |
| 2029 | static int __init gic_acpi_parse_srat_its(struct acpi_subtable_header *header, |
| 2030 | const unsigned long end) |
| 2031 | { |
| 2032 | int node; |
| 2033 | struct acpi_srat_gic_its_affinity *its_affinity; |
| 2034 | |
| 2035 | its_affinity = (struct acpi_srat_gic_its_affinity *)header; |
| 2036 | if (!its_affinity) |
| 2037 | return -EINVAL; |
| 2038 | |
| 2039 | if (its_affinity->header.length < sizeof(*its_affinity)) { |
| 2040 | pr_err("SRAT: Invalid header length %d in ITS affinity\n", |
| 2041 | its_affinity->header.length); |
| 2042 | return -EINVAL; |
| 2043 | } |
| 2044 | |
| 2045 | if (its_in_srat >= MAX_NUMNODES) { |
| 2046 | pr_err("SRAT: ITS affinity exceeding max count[%d]\n", |
| 2047 | MAX_NUMNODES); |
| 2048 | return -EINVAL; |
| 2049 | } |
| 2050 | |
| 2051 | node = acpi_map_pxm_to_node(its_affinity->proximity_domain); |
| 2052 | |
| 2053 | if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) { |
| 2054 | pr_err("SRAT: Invalid NUMA node %d in ITS affinity\n", node); |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
| 2058 | its_srat_maps[its_in_srat].numa_node = node; |
| 2059 | its_srat_maps[its_in_srat].its_id = its_affinity->its_id; |
| 2060 | its_in_srat++; |
| 2061 | pr_info("SRAT: PXM %d -> ITS %d -> Node %d\n", |
| 2062 | its_affinity->proximity_domain, its_affinity->its_id, node); |
| 2063 | |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | static void __init acpi_table_parse_srat_its(void) |
| 2068 | { |
| 2069 | acpi_table_parse_entries(ACPI_SIG_SRAT, |
| 2070 | sizeof(struct acpi_table_srat), |
| 2071 | ACPI_SRAT_TYPE_GIC_ITS_AFFINITY, |
| 2072 | gic_acpi_parse_srat_its, 0); |
| 2073 | } |
| 2074 | #else |
| 2075 | static void __init acpi_table_parse_srat_its(void) { } |
| 2076 | static int __init acpi_get_its_numa_node(u32 its_id) { return NUMA_NO_NODE; } |
| 2077 | #endif |
| 2078 | |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2079 | static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header, |
| 2080 | const unsigned long end) |
| 2081 | { |
| 2082 | struct acpi_madt_generic_translator *its_entry; |
| 2083 | struct fwnode_handle *dom_handle; |
| 2084 | struct resource res; |
| 2085 | int err; |
| 2086 | |
| 2087 | its_entry = (struct acpi_madt_generic_translator *)header; |
| 2088 | memset(&res, 0, sizeof(res)); |
| 2089 | res.start = its_entry->base_address; |
| 2090 | res.end = its_entry->base_address + ACPI_GICV3_ITS_MEM_SIZE - 1; |
| 2091 | res.flags = IORESOURCE_MEM; |
| 2092 | |
| 2093 | dom_handle = irq_domain_alloc_fwnode((void *)its_entry->base_address); |
| 2094 | if (!dom_handle) { |
| 2095 | pr_err("ITS@%pa: Unable to allocate GICv3 ITS domain token\n", |
| 2096 | &res.start); |
| 2097 | return -ENOMEM; |
| 2098 | } |
| 2099 | |
| 2100 | err = iort_register_domain_token(its_entry->translation_id, dom_handle); |
| 2101 | if (err) { |
| 2102 | pr_err("ITS@%pa: Unable to register GICv3 ITS domain token (ITS ID %d) to IORT\n", |
| 2103 | &res.start, its_entry->translation_id); |
| 2104 | goto dom_err; |
| 2105 | } |
| 2106 | |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 2107 | err = its_probe_one(&res, dom_handle, |
| 2108 | acpi_get_its_numa_node(its_entry->translation_id)); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2109 | if (!err) |
| 2110 | return 0; |
| 2111 | |
| 2112 | iort_deregister_domain_token(its_entry->translation_id); |
| 2113 | dom_err: |
| 2114 | irq_domain_free_fwnode(dom_handle); |
| 2115 | return err; |
| 2116 | } |
| 2117 | |
| 2118 | static void __init its_acpi_probe(void) |
| 2119 | { |
Ganapatrao Kulkarni | dbd2b82 | 2017-06-22 11:40:12 +0530 | [diff] [blame] | 2120 | acpi_table_parse_srat_its(); |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2121 | acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR, |
| 2122 | gic_acpi_parse_madt_its, 0); |
| 2123 | } |
| 2124 | #else |
| 2125 | static void __init its_acpi_probe(void) { } |
| 2126 | #endif |
| 2127 | |
Tomasz Nowicki | db40f0a | 2016-09-12 20:32:24 +0200 | [diff] [blame] | 2128 | int __init its_init(struct fwnode_handle *handle, struct rdists *rdists, |
| 2129 | struct irq_domain *parent_domain) |
| 2130 | { |
| 2131 | struct device_node *of_node; |
| 2132 | |
| 2133 | its_parent = parent_domain; |
| 2134 | of_node = to_of_node(handle); |
| 2135 | if (of_node) |
| 2136 | its_of_probe(of_node); |
| 2137 | else |
Tomasz Nowicki | 3f010cf | 2016-09-12 20:32:25 +0200 | [diff] [blame] | 2138 | its_acpi_probe(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 2139 | |
| 2140 | if (list_empty(&its_nodes)) { |
| 2141 | pr_warn("ITS: No ITS available, not enabling LPIs\n"); |
| 2142 | return -ENXIO; |
| 2143 | } |
| 2144 | |
| 2145 | gic_rdists = rdists; |
Shanker Donthineni | 6c31e12 | 2017-06-22 18:19:14 -0500 | [diff] [blame] | 2146 | return its_alloc_lpi_tables(); |
Marc Zyngier | 4c21f3c | 2014-11-24 14:35:17 +0000 | [diff] [blame] | 2147 | } |