2 * Copyright (C) 2013-2017 ARM Limited, All Rights Reserved.
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
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.
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.
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/>.
18 #include <linux/acpi.h>
19 #include <linux/acpi_iort.h>
20 #include <linux/bitmap.h>
21 #include <linux/cpu.h>
22 #include <linux/delay.h>
23 #include <linux/dma-iommu.h>
24 #include <linux/interrupt.h>
25 #include <linux/irqdomain.h>
26 #include <linux/list.h>
27 #include <linux/list_sort.h>
28 #include <linux/log2.h>
30 #include <linux/msi.h>
32 #include <linux/of_address.h>
33 #include <linux/of_irq.h>
34 #include <linux/of_pci.h>
35 #include <linux/of_platform.h>
36 #include <linux/percpu.h>
37 #include <linux/slab.h>
38 #include <linux/syscore_ops.h>
40 #include <linux/irqchip.h>
41 #include <linux/irqchip/arm-gic-v3.h>
42 #include <linux/irqchip/arm-gic-v4.h>
44 #include <asm/cputype.h>
45 #include <asm/exception.h>
47 #include "irq-gic-common.h"
49 #define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0)
50 #define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1)
51 #define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2)
52 #define ITS_FLAGS_SAVE_SUSPEND_STATE (1ULL << 3)
54 #define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0)
56 static u32 lpi_id_bits
;
59 * We allocate memory for PROPBASE to cover 2 ^ lpi_id_bits LPIs to
60 * deal with (one configuration byte per interrupt). PENDBASE has to
61 * be 64kB aligned (one bit per LPI, plus 8192 bits for SPI/PPI/SGI).
63 #define LPI_NRBITS lpi_id_bits
64 #define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K)
65 #define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K)
67 #define LPI_PROP_DEFAULT_PRIO 0xa0
70 * Collection structure - just an ID, and a redistributor address to
71 * ping. We use one per CPU as a bag of interrupts assigned to this
74 struct its_collection
{
80 * The ITS_BASER structure - contains memory information, cached
81 * value of BASER register configuration and ITS page size.
93 * The ITS structure - contains most of the infrastructure, with the
94 * top-level MSI domain, the command queue, the collections, and the
95 * list of devices writing to it.
97 * dev_alloc_lock has to be taken for device allocations, while the
98 * spinlock must be taken to parse data structures such as the device
103 struct mutex dev_alloc_lock
;
104 struct list_head entry
;
106 phys_addr_t phys_base
;
107 struct its_cmd_block
*cmd_base
;
108 struct its_cmd_block
*cmd_write
;
109 struct its_baser tables
[GITS_BASER_NR_REGS
];
110 struct its_collection
*collections
;
111 struct fwnode_handle
*fwnode_handle
;
112 u64 (*get_msi_base
)(struct its_device
*its_dev
);
115 struct list_head its_device_list
;
117 unsigned long list_nr
;
121 unsigned int msi_domain_flags
;
122 u32 pre_its_base
; /* for Socionext Synquacer */
124 int vlpi_redist_offset
;
127 #define ITS_ITT_ALIGN SZ_256
129 /* The maximum number of VPEID bits supported by VLPI commands */
130 #define ITS_MAX_VPEID_BITS (16)
131 #define ITS_MAX_VPEID (1 << (ITS_MAX_VPEID_BITS))
133 /* Convert page order to size in bytes */
134 #define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o))
136 struct event_lpi_map
{
137 unsigned long *lpi_map
;
139 irq_hw_number_t lpi_base
;
141 struct mutex vlpi_lock
;
143 struct its_vlpi_map
*vlpi_maps
;
148 * The ITS view of a device - belongs to an ITS, owns an interrupt
149 * translation table, and a list of interrupts. If it some of its
150 * LPIs are injected into a guest (GICv4), the event_map.vm field
151 * indicates which one.
154 struct list_head entry
;
155 struct its_node
*its
;
156 struct event_lpi_map event_map
;
165 struct its_device
*dev
;
166 struct its_vpe
**vpes
;
170 static LIST_HEAD(its_nodes
);
171 static DEFINE_RAW_SPINLOCK(its_lock
);
172 static struct rdists
*gic_rdists
;
173 static struct irq_domain
*its_parent
;
175 static unsigned long its_list_map
;
176 static u16 vmovp_seq_num
;
177 static DEFINE_RAW_SPINLOCK(vmovp_lock
);
179 static DEFINE_IDA(its_vpeid_ida
);
181 #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist))
182 #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base)
183 #define gic_data_rdist_vlpi_base() (gic_data_rdist_rd_base() + SZ_128K)
185 static struct its_collection
*dev_event_to_col(struct its_device
*its_dev
,
188 struct its_node
*its
= its_dev
->its
;
190 return its
->collections
+ its_dev
->event_map
.col_map
[event
];
193 static struct its_collection
*valid_col(struct its_collection
*col
)
195 if (WARN_ON_ONCE(col
->target_address
& GENMASK_ULL(0, 15)))
201 static struct its_vpe
*valid_vpe(struct its_node
*its
, struct its_vpe
*vpe
)
203 if (valid_col(its
->collections
+ vpe
->col_idx
))
210 * ITS command descriptors - parameters to be encoded in a command
213 struct its_cmd_desc
{
216 struct its_device
*dev
;
221 struct its_device
*dev
;
226 struct its_device
*dev
;
231 struct its_device
*dev
;
236 struct its_collection
*col
;
241 struct its_device
*dev
;
247 struct its_device
*dev
;
248 struct its_collection
*col
;
253 struct its_device
*dev
;
258 struct its_collection
*col
;
267 struct its_collection
*col
;
273 struct its_device
*dev
;
281 struct its_device
*dev
;
288 struct its_collection
*col
;
296 * The ITS command block, which is what the ITS actually parses.
298 struct its_cmd_block
{
302 #define ITS_CMD_QUEUE_SZ SZ_64K
303 #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(struct its_cmd_block))
305 typedef struct its_collection
*(*its_cmd_builder_t
)(struct its_node
*,
306 struct its_cmd_block
*,
307 struct its_cmd_desc
*);
309 typedef struct its_vpe
*(*its_cmd_vbuilder_t
)(struct its_node
*,
310 struct its_cmd_block
*,
311 struct its_cmd_desc
*);
313 static void its_mask_encode(u64
*raw_cmd
, u64 val
, int h
, int l
)
315 u64 mask
= GENMASK_ULL(h
, l
);
317 *raw_cmd
|= (val
<< l
) & mask
;
320 static void its_encode_cmd(struct its_cmd_block
*cmd
, u8 cmd_nr
)
322 its_mask_encode(&cmd
->raw_cmd
[0], cmd_nr
, 7, 0);
325 static void its_encode_devid(struct its_cmd_block
*cmd
, u32 devid
)
327 its_mask_encode(&cmd
->raw_cmd
[0], devid
, 63, 32);
330 static void its_encode_event_id(struct its_cmd_block
*cmd
, u32 id
)
332 its_mask_encode(&cmd
->raw_cmd
[1], id
, 31, 0);
335 static void its_encode_phys_id(struct its_cmd_block
*cmd
, u32 phys_id
)
337 its_mask_encode(&cmd
->raw_cmd
[1], phys_id
, 63, 32);
340 static void its_encode_size(struct its_cmd_block
*cmd
, u8 size
)
342 its_mask_encode(&cmd
->raw_cmd
[1], size
, 4, 0);
345 static void its_encode_itt(struct its_cmd_block
*cmd
, u64 itt_addr
)
347 its_mask_encode(&cmd
->raw_cmd
[2], itt_addr
>> 8, 51, 8);
350 static void its_encode_valid(struct its_cmd_block
*cmd
, int valid
)
352 its_mask_encode(&cmd
->raw_cmd
[2], !!valid
, 63, 63);
355 static void its_encode_target(struct its_cmd_block
*cmd
, u64 target_addr
)
357 its_mask_encode(&cmd
->raw_cmd
[2], target_addr
>> 16, 51, 16);
360 static void its_encode_collection(struct its_cmd_block
*cmd
, u16 col
)
362 its_mask_encode(&cmd
->raw_cmd
[2], col
, 15, 0);
365 static void its_encode_vpeid(struct its_cmd_block
*cmd
, u16 vpeid
)
367 its_mask_encode(&cmd
->raw_cmd
[1], vpeid
, 47, 32);
370 static void its_encode_virt_id(struct its_cmd_block
*cmd
, u32 virt_id
)
372 its_mask_encode(&cmd
->raw_cmd
[2], virt_id
, 31, 0);
375 static void its_encode_db_phys_id(struct its_cmd_block
*cmd
, u32 db_phys_id
)
377 its_mask_encode(&cmd
->raw_cmd
[2], db_phys_id
, 63, 32);
380 static void its_encode_db_valid(struct its_cmd_block
*cmd
, bool db_valid
)
382 its_mask_encode(&cmd
->raw_cmd
[2], db_valid
, 0, 0);
385 static void its_encode_seq_num(struct its_cmd_block
*cmd
, u16 seq_num
)
387 its_mask_encode(&cmd
->raw_cmd
[0], seq_num
, 47, 32);
390 static void its_encode_its_list(struct its_cmd_block
*cmd
, u16 its_list
)
392 its_mask_encode(&cmd
->raw_cmd
[1], its_list
, 15, 0);
395 static void its_encode_vpt_addr(struct its_cmd_block
*cmd
, u64 vpt_pa
)
397 its_mask_encode(&cmd
->raw_cmd
[3], vpt_pa
>> 16, 51, 16);
400 static void its_encode_vpt_size(struct its_cmd_block
*cmd
, u8 vpt_size
)
402 its_mask_encode(&cmd
->raw_cmd
[3], vpt_size
, 4, 0);
405 static inline void its_fixup_cmd(struct its_cmd_block
*cmd
)
407 /* Let's fixup BE commands */
408 cmd
->raw_cmd
[0] = cpu_to_le64(cmd
->raw_cmd
[0]);
409 cmd
->raw_cmd
[1] = cpu_to_le64(cmd
->raw_cmd
[1]);
410 cmd
->raw_cmd
[2] = cpu_to_le64(cmd
->raw_cmd
[2]);
411 cmd
->raw_cmd
[3] = cpu_to_le64(cmd
->raw_cmd
[3]);
414 static struct its_collection
*its_build_mapd_cmd(struct its_node
*its
,
415 struct its_cmd_block
*cmd
,
416 struct its_cmd_desc
*desc
)
418 unsigned long itt_addr
;
419 u8 size
= ilog2(desc
->its_mapd_cmd
.dev
->nr_ites
);
421 itt_addr
= virt_to_phys(desc
->its_mapd_cmd
.dev
->itt
);
422 itt_addr
= ALIGN(itt_addr
, ITS_ITT_ALIGN
);
424 its_encode_cmd(cmd
, GITS_CMD_MAPD
);
425 its_encode_devid(cmd
, desc
->its_mapd_cmd
.dev
->device_id
);
426 its_encode_size(cmd
, size
- 1);
427 its_encode_itt(cmd
, itt_addr
);
428 its_encode_valid(cmd
, desc
->its_mapd_cmd
.valid
);
435 static struct its_collection
*its_build_mapc_cmd(struct its_node
*its
,
436 struct its_cmd_block
*cmd
,
437 struct its_cmd_desc
*desc
)
439 its_encode_cmd(cmd
, GITS_CMD_MAPC
);
440 its_encode_collection(cmd
, desc
->its_mapc_cmd
.col
->col_id
);
441 its_encode_target(cmd
, desc
->its_mapc_cmd
.col
->target_address
);
442 its_encode_valid(cmd
, desc
->its_mapc_cmd
.valid
);
446 return desc
->its_mapc_cmd
.col
;
449 static struct its_collection
*its_build_mapti_cmd(struct its_node
*its
,
450 struct its_cmd_block
*cmd
,
451 struct its_cmd_desc
*desc
)
453 struct its_collection
*col
;
455 col
= dev_event_to_col(desc
->its_mapti_cmd
.dev
,
456 desc
->its_mapti_cmd
.event_id
);
458 its_encode_cmd(cmd
, GITS_CMD_MAPTI
);
459 its_encode_devid(cmd
, desc
->its_mapti_cmd
.dev
->device_id
);
460 its_encode_event_id(cmd
, desc
->its_mapti_cmd
.event_id
);
461 its_encode_phys_id(cmd
, desc
->its_mapti_cmd
.phys_id
);
462 its_encode_collection(cmd
, col
->col_id
);
466 return valid_col(col
);
469 static struct its_collection
*its_build_movi_cmd(struct its_node
*its
,
470 struct its_cmd_block
*cmd
,
471 struct its_cmd_desc
*desc
)
473 struct its_collection
*col
;
475 col
= dev_event_to_col(desc
->its_movi_cmd
.dev
,
476 desc
->its_movi_cmd
.event_id
);
478 its_encode_cmd(cmd
, GITS_CMD_MOVI
);
479 its_encode_devid(cmd
, desc
->its_movi_cmd
.dev
->device_id
);
480 its_encode_event_id(cmd
, desc
->its_movi_cmd
.event_id
);
481 its_encode_collection(cmd
, desc
->its_movi_cmd
.col
->col_id
);
485 return valid_col(col
);
488 static struct its_collection
*its_build_discard_cmd(struct its_node
*its
,
489 struct its_cmd_block
*cmd
,
490 struct its_cmd_desc
*desc
)
492 struct its_collection
*col
;
494 col
= dev_event_to_col(desc
->its_discard_cmd
.dev
,
495 desc
->its_discard_cmd
.event_id
);
497 its_encode_cmd(cmd
, GITS_CMD_DISCARD
);
498 its_encode_devid(cmd
, desc
->its_discard_cmd
.dev
->device_id
);
499 its_encode_event_id(cmd
, desc
->its_discard_cmd
.event_id
);
503 return valid_col(col
);
506 static struct its_collection
*its_build_inv_cmd(struct its_node
*its
,
507 struct its_cmd_block
*cmd
,
508 struct its_cmd_desc
*desc
)
510 struct its_collection
*col
;
512 col
= dev_event_to_col(desc
->its_inv_cmd
.dev
,
513 desc
->its_inv_cmd
.event_id
);
515 its_encode_cmd(cmd
, GITS_CMD_INV
);
516 its_encode_devid(cmd
, desc
->its_inv_cmd
.dev
->device_id
);
517 its_encode_event_id(cmd
, desc
->its_inv_cmd
.event_id
);
521 return valid_col(col
);
524 static struct its_collection
*its_build_int_cmd(struct its_node
*its
,
525 struct its_cmd_block
*cmd
,
526 struct its_cmd_desc
*desc
)
528 struct its_collection
*col
;
530 col
= dev_event_to_col(desc
->its_int_cmd
.dev
,
531 desc
->its_int_cmd
.event_id
);
533 its_encode_cmd(cmd
, GITS_CMD_INT
);
534 its_encode_devid(cmd
, desc
->its_int_cmd
.dev
->device_id
);
535 its_encode_event_id(cmd
, desc
->its_int_cmd
.event_id
);
539 return valid_col(col
);
542 static struct its_collection
*its_build_clear_cmd(struct its_node
*its
,
543 struct its_cmd_block
*cmd
,
544 struct its_cmd_desc
*desc
)
546 struct its_collection
*col
;
548 col
= dev_event_to_col(desc
->its_clear_cmd
.dev
,
549 desc
->its_clear_cmd
.event_id
);
551 its_encode_cmd(cmd
, GITS_CMD_CLEAR
);
552 its_encode_devid(cmd
, desc
->its_clear_cmd
.dev
->device_id
);
553 its_encode_event_id(cmd
, desc
->its_clear_cmd
.event_id
);
557 return valid_col(col
);
560 static struct its_collection
*its_build_invall_cmd(struct its_node
*its
,
561 struct its_cmd_block
*cmd
,
562 struct its_cmd_desc
*desc
)
564 its_encode_cmd(cmd
, GITS_CMD_INVALL
);
565 its_encode_collection(cmd
, desc
->its_mapc_cmd
.col
->col_id
);
572 static struct its_vpe
*its_build_vinvall_cmd(struct its_node
*its
,
573 struct its_cmd_block
*cmd
,
574 struct its_cmd_desc
*desc
)
576 its_encode_cmd(cmd
, GITS_CMD_VINVALL
);
577 its_encode_vpeid(cmd
, desc
->its_vinvall_cmd
.vpe
->vpe_id
);
581 return valid_vpe(its
, desc
->its_vinvall_cmd
.vpe
);
584 static struct its_vpe
*its_build_vmapp_cmd(struct its_node
*its
,
585 struct its_cmd_block
*cmd
,
586 struct its_cmd_desc
*desc
)
588 unsigned long vpt_addr
;
591 vpt_addr
= virt_to_phys(page_address(desc
->its_vmapp_cmd
.vpe
->vpt_page
));
592 target
= desc
->its_vmapp_cmd
.col
->target_address
+ its
->vlpi_redist_offset
;
594 its_encode_cmd(cmd
, GITS_CMD_VMAPP
);
595 its_encode_vpeid(cmd
, desc
->its_vmapp_cmd
.vpe
->vpe_id
);
596 its_encode_valid(cmd
, desc
->its_vmapp_cmd
.valid
);
597 its_encode_target(cmd
, target
);
598 its_encode_vpt_addr(cmd
, vpt_addr
);
599 its_encode_vpt_size(cmd
, LPI_NRBITS
- 1);
603 return valid_vpe(its
, desc
->its_vmapp_cmd
.vpe
);
606 static struct its_vpe
*its_build_vmapti_cmd(struct its_node
*its
,
607 struct its_cmd_block
*cmd
,
608 struct its_cmd_desc
*desc
)
612 if (desc
->its_vmapti_cmd
.db_enabled
)
613 db
= desc
->its_vmapti_cmd
.vpe
->vpe_db_lpi
;
617 its_encode_cmd(cmd
, GITS_CMD_VMAPTI
);
618 its_encode_devid(cmd
, desc
->its_vmapti_cmd
.dev
->device_id
);
619 its_encode_vpeid(cmd
, desc
->its_vmapti_cmd
.vpe
->vpe_id
);
620 its_encode_event_id(cmd
, desc
->its_vmapti_cmd
.event_id
);
621 its_encode_db_phys_id(cmd
, db
);
622 its_encode_virt_id(cmd
, desc
->its_vmapti_cmd
.virt_id
);
626 return valid_vpe(its
, desc
->its_vmapti_cmd
.vpe
);
629 static struct its_vpe
*its_build_vmovi_cmd(struct its_node
*its
,
630 struct its_cmd_block
*cmd
,
631 struct its_cmd_desc
*desc
)
635 if (desc
->its_vmovi_cmd
.db_enabled
)
636 db
= desc
->its_vmovi_cmd
.vpe
->vpe_db_lpi
;
640 its_encode_cmd(cmd
, GITS_CMD_VMOVI
);
641 its_encode_devid(cmd
, desc
->its_vmovi_cmd
.dev
->device_id
);
642 its_encode_vpeid(cmd
, desc
->its_vmovi_cmd
.vpe
->vpe_id
);
643 its_encode_event_id(cmd
, desc
->its_vmovi_cmd
.event_id
);
644 its_encode_db_phys_id(cmd
, db
);
645 its_encode_db_valid(cmd
, true);
649 return valid_vpe(its
, desc
->its_vmovi_cmd
.vpe
);
652 static struct its_vpe
*its_build_vmovp_cmd(struct its_node
*its
,
653 struct its_cmd_block
*cmd
,
654 struct its_cmd_desc
*desc
)
658 target
= desc
->its_vmovp_cmd
.col
->target_address
+ its
->vlpi_redist_offset
;
659 its_encode_cmd(cmd
, GITS_CMD_VMOVP
);
660 its_encode_seq_num(cmd
, desc
->its_vmovp_cmd
.seq_num
);
661 its_encode_its_list(cmd
, desc
->its_vmovp_cmd
.its_list
);
662 its_encode_vpeid(cmd
, desc
->its_vmovp_cmd
.vpe
->vpe_id
);
663 its_encode_target(cmd
, target
);
667 return valid_vpe(its
, desc
->its_vmovp_cmd
.vpe
);
670 static u64
its_cmd_ptr_to_offset(struct its_node
*its
,
671 struct its_cmd_block
*ptr
)
673 return (ptr
- its
->cmd_base
) * sizeof(*ptr
);
676 static int its_queue_full(struct its_node
*its
)
681 widx
= its
->cmd_write
- its
->cmd_base
;
682 ridx
= readl_relaxed(its
->base
+ GITS_CREADR
) / sizeof(struct its_cmd_block
);
684 /* This is incredibly unlikely to happen, unless the ITS locks up. */
685 if (((widx
+ 1) % ITS_CMD_QUEUE_NR_ENTRIES
) == ridx
)
691 static struct its_cmd_block
*its_allocate_entry(struct its_node
*its
)
693 struct its_cmd_block
*cmd
;
694 u32 count
= 1000000; /* 1s! */
696 while (its_queue_full(its
)) {
699 pr_err_ratelimited("ITS queue not draining\n");
706 cmd
= its
->cmd_write
++;
708 /* Handle queue wrapping */
709 if (its
->cmd_write
== (its
->cmd_base
+ ITS_CMD_QUEUE_NR_ENTRIES
))
710 its
->cmd_write
= its
->cmd_base
;
721 static struct its_cmd_block
*its_post_commands(struct its_node
*its
)
723 u64 wr
= its_cmd_ptr_to_offset(its
, its
->cmd_write
);
725 writel_relaxed(wr
, its
->base
+ GITS_CWRITER
);
727 return its
->cmd_write
;
730 static void its_flush_cmd(struct its_node
*its
, struct its_cmd_block
*cmd
)
733 * Make sure the commands written to memory are observable by
736 if (its
->flags
& ITS_FLAGS_CMDQ_NEEDS_FLUSHING
)
737 gic_flush_dcache_to_poc(cmd
, sizeof(*cmd
));
742 static int its_wait_for_range_completion(struct its_node
*its
,
743 struct its_cmd_block
*from
,
744 struct its_cmd_block
*to
)
746 u64 rd_idx
, from_idx
, to_idx
;
747 u32 count
= 1000000; /* 1s! */
749 from_idx
= its_cmd_ptr_to_offset(its
, from
);
750 to_idx
= its_cmd_ptr_to_offset(its
, to
);
753 rd_idx
= readl_relaxed(its
->base
+ GITS_CREADR
);
756 if (from_idx
< to_idx
&& rd_idx
>= to_idx
)
760 if (from_idx
>= to_idx
&& rd_idx
>= to_idx
&& rd_idx
< from_idx
)
765 pr_err_ratelimited("ITS queue timeout (%llu %llu %llu)\n",
766 from_idx
, to_idx
, rd_idx
);
776 /* Warning, macro hell follows */
777 #define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \
778 void name(struct its_node *its, \
780 struct its_cmd_desc *desc) \
782 struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \
783 synctype *sync_obj; \
784 unsigned long flags; \
786 raw_spin_lock_irqsave(&its->lock, flags); \
788 cmd = its_allocate_entry(its); \
789 if (!cmd) { /* We're soooooo screewed... */ \
790 raw_spin_unlock_irqrestore(&its->lock, flags); \
793 sync_obj = builder(its, cmd, desc); \
794 its_flush_cmd(its, cmd); \
797 sync_cmd = its_allocate_entry(its); \
801 buildfn(its, sync_cmd, sync_obj); \
802 its_flush_cmd(its, sync_cmd); \
806 next_cmd = its_post_commands(its); \
807 raw_spin_unlock_irqrestore(&its->lock, flags); \
809 if (its_wait_for_range_completion(its, cmd, next_cmd)) \
810 pr_err_ratelimited("ITS cmd %ps failed\n", builder); \
813 static void its_build_sync_cmd(struct its_node
*its
,
814 struct its_cmd_block
*sync_cmd
,
815 struct its_collection
*sync_col
)
817 its_encode_cmd(sync_cmd
, GITS_CMD_SYNC
);
818 its_encode_target(sync_cmd
, sync_col
->target_address
);
820 its_fixup_cmd(sync_cmd
);
823 static BUILD_SINGLE_CMD_FUNC(its_send_single_command
, its_cmd_builder_t
,
824 struct its_collection
, its_build_sync_cmd
)
826 static void its_build_vsync_cmd(struct its_node
*its
,
827 struct its_cmd_block
*sync_cmd
,
828 struct its_vpe
*sync_vpe
)
830 its_encode_cmd(sync_cmd
, GITS_CMD_VSYNC
);
831 its_encode_vpeid(sync_cmd
, sync_vpe
->vpe_id
);
833 its_fixup_cmd(sync_cmd
);
836 static BUILD_SINGLE_CMD_FUNC(its_send_single_vcommand
, its_cmd_vbuilder_t
,
837 struct its_vpe
, its_build_vsync_cmd
)
839 static void its_send_int(struct its_device
*dev
, u32 event_id
)
841 struct its_cmd_desc desc
;
843 desc
.its_int_cmd
.dev
= dev
;
844 desc
.its_int_cmd
.event_id
= event_id
;
846 its_send_single_command(dev
->its
, its_build_int_cmd
, &desc
);
849 static void its_send_clear(struct its_device
*dev
, u32 event_id
)
851 struct its_cmd_desc desc
;
853 desc
.its_clear_cmd
.dev
= dev
;
854 desc
.its_clear_cmd
.event_id
= event_id
;
856 its_send_single_command(dev
->its
, its_build_clear_cmd
, &desc
);
859 static void its_send_inv(struct its_device
*dev
, u32 event_id
)
861 struct its_cmd_desc desc
;
863 desc
.its_inv_cmd
.dev
= dev
;
864 desc
.its_inv_cmd
.event_id
= event_id
;
866 its_send_single_command(dev
->its
, its_build_inv_cmd
, &desc
);
869 static void its_send_mapd(struct its_device
*dev
, int valid
)
871 struct its_cmd_desc desc
;
873 desc
.its_mapd_cmd
.dev
= dev
;
874 desc
.its_mapd_cmd
.valid
= !!valid
;
876 its_send_single_command(dev
->its
, its_build_mapd_cmd
, &desc
);
879 static void its_send_mapc(struct its_node
*its
, struct its_collection
*col
,
882 struct its_cmd_desc desc
;
884 desc
.its_mapc_cmd
.col
= col
;
885 desc
.its_mapc_cmd
.valid
= !!valid
;
887 its_send_single_command(its
, its_build_mapc_cmd
, &desc
);
890 static void its_send_mapti(struct its_device
*dev
, u32 irq_id
, u32 id
)
892 struct its_cmd_desc desc
;
894 desc
.its_mapti_cmd
.dev
= dev
;
895 desc
.its_mapti_cmd
.phys_id
= irq_id
;
896 desc
.its_mapti_cmd
.event_id
= id
;
898 its_send_single_command(dev
->its
, its_build_mapti_cmd
, &desc
);
901 static void its_send_movi(struct its_device
*dev
,
902 struct its_collection
*col
, u32 id
)
904 struct its_cmd_desc desc
;
906 desc
.its_movi_cmd
.dev
= dev
;
907 desc
.its_movi_cmd
.col
= col
;
908 desc
.its_movi_cmd
.event_id
= id
;
910 its_send_single_command(dev
->its
, its_build_movi_cmd
, &desc
);
913 static void its_send_discard(struct its_device
*dev
, u32 id
)
915 struct its_cmd_desc desc
;
917 desc
.its_discard_cmd
.dev
= dev
;
918 desc
.its_discard_cmd
.event_id
= id
;
920 its_send_single_command(dev
->its
, its_build_discard_cmd
, &desc
);
923 static void its_send_invall(struct its_node
*its
, struct its_collection
*col
)
925 struct its_cmd_desc desc
;
927 desc
.its_invall_cmd
.col
= col
;
929 its_send_single_command(its
, its_build_invall_cmd
, &desc
);
932 static void its_send_vmapti(struct its_device
*dev
, u32 id
)
934 struct its_vlpi_map
*map
= &dev
->event_map
.vlpi_maps
[id
];
935 struct its_cmd_desc desc
;
937 desc
.its_vmapti_cmd
.vpe
= map
->vpe
;
938 desc
.its_vmapti_cmd
.dev
= dev
;
939 desc
.its_vmapti_cmd
.virt_id
= map
->vintid
;
940 desc
.its_vmapti_cmd
.event_id
= id
;
941 desc
.its_vmapti_cmd
.db_enabled
= map
->db_enabled
;
943 its_send_single_vcommand(dev
->its
, its_build_vmapti_cmd
, &desc
);
946 static void its_send_vmovi(struct its_device
*dev
, u32 id
)
948 struct its_vlpi_map
*map
= &dev
->event_map
.vlpi_maps
[id
];
949 struct its_cmd_desc desc
;
951 desc
.its_vmovi_cmd
.vpe
= map
->vpe
;
952 desc
.its_vmovi_cmd
.dev
= dev
;
953 desc
.its_vmovi_cmd
.event_id
= id
;
954 desc
.its_vmovi_cmd
.db_enabled
= map
->db_enabled
;
956 its_send_single_vcommand(dev
->its
, its_build_vmovi_cmd
, &desc
);
959 static void its_send_vmapp(struct its_node
*its
,
960 struct its_vpe
*vpe
, bool valid
)
962 struct its_cmd_desc desc
;
964 desc
.its_vmapp_cmd
.vpe
= vpe
;
965 desc
.its_vmapp_cmd
.valid
= valid
;
966 desc
.its_vmapp_cmd
.col
= &its
->collections
[vpe
->col_idx
];
968 its_send_single_vcommand(its
, its_build_vmapp_cmd
, &desc
);
971 static void its_send_vmovp(struct its_vpe
*vpe
)
973 struct its_cmd_desc desc
;
974 struct its_node
*its
;
976 int col_id
= vpe
->col_idx
;
978 desc
.its_vmovp_cmd
.vpe
= vpe
;
979 desc
.its_vmovp_cmd
.its_list
= (u16
)its_list_map
;
982 its
= list_first_entry(&its_nodes
, struct its_node
, entry
);
983 desc
.its_vmovp_cmd
.seq_num
= 0;
984 desc
.its_vmovp_cmd
.col
= &its
->collections
[col_id
];
985 its_send_single_vcommand(its
, its_build_vmovp_cmd
, &desc
);
990 * Yet another marvel of the architecture. If using the
991 * its_list "feature", we need to make sure that all ITSs
992 * receive all VMOVP commands in the same order. The only way
993 * to guarantee this is to make vmovp a serialization point.
997 raw_spin_lock_irqsave(&vmovp_lock
, flags
);
999 desc
.its_vmovp_cmd
.seq_num
= vmovp_seq_num
++;
1002 list_for_each_entry(its
, &its_nodes
, entry
) {
1006 if (!vpe
->its_vm
->vlpi_count
[its
->list_nr
])
1009 desc
.its_vmovp_cmd
.col
= &its
->collections
[col_id
];
1010 its_send_single_vcommand(its
, its_build_vmovp_cmd
, &desc
);
1013 raw_spin_unlock_irqrestore(&vmovp_lock
, flags
);
1016 static void its_send_vinvall(struct its_node
*its
, struct its_vpe
*vpe
)
1018 struct its_cmd_desc desc
;
1020 desc
.its_vinvall_cmd
.vpe
= vpe
;
1021 its_send_single_vcommand(its
, its_build_vinvall_cmd
, &desc
);
1025 * irqchip functions - assumes MSI, mostly.
1028 static inline u32
its_get_event_id(struct irq_data
*d
)
1030 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1031 return d
->hwirq
- its_dev
->event_map
.lpi_base
;
1034 static void lpi_write_config(struct irq_data
*d
, u8 clr
, u8 set
)
1036 irq_hw_number_t hwirq
;
1037 struct page
*prop_page
;
1040 if (irqd_is_forwarded_to_vcpu(d
)) {
1041 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1042 u32 event
= its_get_event_id(d
);
1043 struct its_vlpi_map
*map
;
1045 prop_page
= its_dev
->event_map
.vm
->vprop_page
;
1046 map
= &its_dev
->event_map
.vlpi_maps
[event
];
1047 hwirq
= map
->vintid
;
1049 /* Remember the updated property */
1050 map
->properties
&= ~clr
;
1051 map
->properties
|= set
| LPI_PROP_GROUP1
;
1053 prop_page
= gic_rdists
->prop_page
;
1057 cfg
= page_address(prop_page
) + hwirq
- 8192;
1059 *cfg
|= set
| LPI_PROP_GROUP1
;
1062 * Make the above write visible to the redistributors.
1063 * And yes, we're flushing exactly: One. Single. Byte.
1066 if (gic_rdists
->flags
& RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING
)
1067 gic_flush_dcache_to_poc(cfg
, sizeof(*cfg
));
1072 static void lpi_update_config(struct irq_data
*d
, u8 clr
, u8 set
)
1074 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1076 lpi_write_config(d
, clr
, set
);
1077 its_send_inv(its_dev
, its_get_event_id(d
));
1080 static void its_vlpi_set_doorbell(struct irq_data
*d
, bool enable
)
1082 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1083 u32 event
= its_get_event_id(d
);
1085 if (its_dev
->event_map
.vlpi_maps
[event
].db_enabled
== enable
)
1088 its_dev
->event_map
.vlpi_maps
[event
].db_enabled
= enable
;
1091 * More fun with the architecture:
1093 * Ideally, we'd issue a VMAPTI to set the doorbell to its LPI
1094 * value or to 1023, depending on the enable bit. But that
1095 * would be issueing a mapping for an /existing/ DevID+EventID
1096 * pair, which is UNPREDICTABLE. Instead, let's issue a VMOVI
1097 * to the /same/ vPE, using this opportunity to adjust the
1098 * doorbell. Mouahahahaha. We loves it, Precious.
1100 its_send_vmovi(its_dev
, event
);
1103 static void its_mask_irq(struct irq_data
*d
)
1105 if (irqd_is_forwarded_to_vcpu(d
))
1106 its_vlpi_set_doorbell(d
, false);
1108 lpi_update_config(d
, LPI_PROP_ENABLED
, 0);
1111 static void its_unmask_irq(struct irq_data
*d
)
1113 if (irqd_is_forwarded_to_vcpu(d
))
1114 its_vlpi_set_doorbell(d
, true);
1116 lpi_update_config(d
, 0, LPI_PROP_ENABLED
);
1119 static int its_set_affinity(struct irq_data
*d
, const struct cpumask
*mask_val
,
1123 const struct cpumask
*cpu_mask
= cpu_online_mask
;
1124 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1125 struct its_collection
*target_col
;
1126 u32 id
= its_get_event_id(d
);
1128 /* A forwarded interrupt should use irq_set_vcpu_affinity */
1129 if (irqd_is_forwarded_to_vcpu(d
))
1132 /* lpi cannot be routed to a redistributor that is on a foreign node */
1133 if (its_dev
->its
->flags
& ITS_FLAGS_WORKAROUND_CAVIUM_23144
) {
1134 if (its_dev
->its
->numa_node
>= 0) {
1135 cpu_mask
= cpumask_of_node(its_dev
->its
->numa_node
);
1136 if (!cpumask_intersects(mask_val
, cpu_mask
))
1141 cpu
= cpumask_any_and(mask_val
, cpu_mask
);
1143 if (cpu
>= nr_cpu_ids
)
1146 /* don't set the affinity when the target cpu is same as current one */
1147 if (cpu
!= its_dev
->event_map
.col_map
[id
]) {
1148 target_col
= &its_dev
->its
->collections
[cpu
];
1149 its_send_movi(its_dev
, target_col
, id
);
1150 its_dev
->event_map
.col_map
[id
] = cpu
;
1151 irq_data_update_effective_affinity(d
, cpumask_of(cpu
));
1154 return IRQ_SET_MASK_OK_DONE
;
1157 static u64
its_irq_get_msi_base(struct its_device
*its_dev
)
1159 struct its_node
*its
= its_dev
->its
;
1161 return its
->phys_base
+ GITS_TRANSLATER
;
1164 static void its_irq_compose_msi_msg(struct irq_data
*d
, struct msi_msg
*msg
)
1166 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1167 struct its_node
*its
;
1171 addr
= its
->get_msi_base(its_dev
);
1173 msg
->address_lo
= lower_32_bits(addr
);
1174 msg
->address_hi
= upper_32_bits(addr
);
1175 msg
->data
= its_get_event_id(d
);
1177 iommu_dma_map_msi_msg(d
->irq
, msg
);
1180 static int its_irq_set_irqchip_state(struct irq_data
*d
,
1181 enum irqchip_irq_state which
,
1184 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1185 u32 event
= its_get_event_id(d
);
1187 if (which
!= IRQCHIP_STATE_PENDING
)
1191 its_send_int(its_dev
, event
);
1193 its_send_clear(its_dev
, event
);
1198 static void its_map_vm(struct its_node
*its
, struct its_vm
*vm
)
1200 unsigned long flags
;
1202 /* Not using the ITS list? Everything is always mapped. */
1206 raw_spin_lock_irqsave(&vmovp_lock
, flags
);
1209 * If the VM wasn't mapped yet, iterate over the vpes and get
1212 vm
->vlpi_count
[its
->list_nr
]++;
1214 if (vm
->vlpi_count
[its
->list_nr
] == 1) {
1217 for (i
= 0; i
< vm
->nr_vpes
; i
++) {
1218 struct its_vpe
*vpe
= vm
->vpes
[i
];
1219 struct irq_data
*d
= irq_get_irq_data(vpe
->irq
);
1221 /* Map the VPE to the first possible CPU */
1222 vpe
->col_idx
= cpumask_first(cpu_online_mask
);
1223 its_send_vmapp(its
, vpe
, true);
1224 its_send_vinvall(its
, vpe
);
1225 irq_data_update_effective_affinity(d
, cpumask_of(vpe
->col_idx
));
1229 raw_spin_unlock_irqrestore(&vmovp_lock
, flags
);
1232 static void its_unmap_vm(struct its_node
*its
, struct its_vm
*vm
)
1234 unsigned long flags
;
1236 /* Not using the ITS list? Everything is always mapped. */
1240 raw_spin_lock_irqsave(&vmovp_lock
, flags
);
1242 if (!--vm
->vlpi_count
[its
->list_nr
]) {
1245 for (i
= 0; i
< vm
->nr_vpes
; i
++)
1246 its_send_vmapp(its
, vm
->vpes
[i
], false);
1249 raw_spin_unlock_irqrestore(&vmovp_lock
, flags
);
1252 static int its_vlpi_map(struct irq_data
*d
, struct its_cmd_info
*info
)
1254 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1255 u32 event
= its_get_event_id(d
);
1261 mutex_lock(&its_dev
->event_map
.vlpi_lock
);
1263 if (!its_dev
->event_map
.vm
) {
1264 struct its_vlpi_map
*maps
;
1266 maps
= kcalloc(its_dev
->event_map
.nr_lpis
, sizeof(*maps
),
1273 its_dev
->event_map
.vm
= info
->map
->vm
;
1274 its_dev
->event_map
.vlpi_maps
= maps
;
1275 } else if (its_dev
->event_map
.vm
!= info
->map
->vm
) {
1280 /* Get our private copy of the mapping information */
1281 its_dev
->event_map
.vlpi_maps
[event
] = *info
->map
;
1283 if (irqd_is_forwarded_to_vcpu(d
)) {
1284 /* Already mapped, move it around */
1285 its_send_vmovi(its_dev
, event
);
1287 /* Ensure all the VPEs are mapped on this ITS */
1288 its_map_vm(its_dev
->its
, info
->map
->vm
);
1291 * Flag the interrupt as forwarded so that we can
1292 * start poking the virtual property table.
1294 irqd_set_forwarded_to_vcpu(d
);
1296 /* Write out the property to the prop table */
1297 lpi_write_config(d
, 0xff, info
->map
->properties
);
1299 /* Drop the physical mapping */
1300 its_send_discard(its_dev
, event
);
1302 /* and install the virtual one */
1303 its_send_vmapti(its_dev
, event
);
1305 /* Increment the number of VLPIs */
1306 its_dev
->event_map
.nr_vlpis
++;
1310 mutex_unlock(&its_dev
->event_map
.vlpi_lock
);
1314 static int its_vlpi_get(struct irq_data
*d
, struct its_cmd_info
*info
)
1316 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1317 u32 event
= its_get_event_id(d
);
1320 mutex_lock(&its_dev
->event_map
.vlpi_lock
);
1322 if (!its_dev
->event_map
.vm
||
1323 !its_dev
->event_map
.vlpi_maps
[event
].vm
) {
1328 /* Copy our mapping information to the incoming request */
1329 *info
->map
= its_dev
->event_map
.vlpi_maps
[event
];
1332 mutex_unlock(&its_dev
->event_map
.vlpi_lock
);
1336 static int its_vlpi_unmap(struct irq_data
*d
)
1338 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1339 u32 event
= its_get_event_id(d
);
1342 mutex_lock(&its_dev
->event_map
.vlpi_lock
);
1344 if (!its_dev
->event_map
.vm
|| !irqd_is_forwarded_to_vcpu(d
)) {
1349 /* Drop the virtual mapping */
1350 its_send_discard(its_dev
, event
);
1352 /* and restore the physical one */
1353 irqd_clr_forwarded_to_vcpu(d
);
1354 its_send_mapti(its_dev
, d
->hwirq
, event
);
1355 lpi_update_config(d
, 0xff, (LPI_PROP_DEFAULT_PRIO
|
1359 /* Potentially unmap the VM from this ITS */
1360 its_unmap_vm(its_dev
->its
, its_dev
->event_map
.vm
);
1363 * Drop the refcount and make the device available again if
1364 * this was the last VLPI.
1366 if (!--its_dev
->event_map
.nr_vlpis
) {
1367 its_dev
->event_map
.vm
= NULL
;
1368 kfree(its_dev
->event_map
.vlpi_maps
);
1372 mutex_unlock(&its_dev
->event_map
.vlpi_lock
);
1376 static int its_vlpi_prop_update(struct irq_data
*d
, struct its_cmd_info
*info
)
1378 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1380 if (!its_dev
->event_map
.vm
|| !irqd_is_forwarded_to_vcpu(d
))
1383 if (info
->cmd_type
== PROP_UPDATE_AND_INV_VLPI
)
1384 lpi_update_config(d
, 0xff, info
->config
);
1386 lpi_write_config(d
, 0xff, info
->config
);
1387 its_vlpi_set_doorbell(d
, !!(info
->config
& LPI_PROP_ENABLED
));
1392 static int its_irq_set_vcpu_affinity(struct irq_data
*d
, void *vcpu_info
)
1394 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
1395 struct its_cmd_info
*info
= vcpu_info
;
1398 if (!its_dev
->its
->is_v4
)
1401 /* Unmap request? */
1403 return its_vlpi_unmap(d
);
1405 switch (info
->cmd_type
) {
1407 return its_vlpi_map(d
, info
);
1410 return its_vlpi_get(d
, info
);
1412 case PROP_UPDATE_VLPI
:
1413 case PROP_UPDATE_AND_INV_VLPI
:
1414 return its_vlpi_prop_update(d
, info
);
1421 static struct irq_chip its_irq_chip
= {
1423 .irq_mask
= its_mask_irq
,
1424 .irq_unmask
= its_unmask_irq
,
1425 .irq_eoi
= irq_chip_eoi_parent
,
1426 .irq_set_affinity
= its_set_affinity
,
1427 .irq_compose_msi_msg
= its_irq_compose_msi_msg
,
1428 .irq_set_irqchip_state
= its_irq_set_irqchip_state
,
1429 .irq_set_vcpu_affinity
= its_irq_set_vcpu_affinity
,
1434 * How we allocate LPIs:
1436 * lpi_range_list contains ranges of LPIs that are to available to
1437 * allocate from. To allocate LPIs, just pick the first range that
1438 * fits the required allocation, and reduce it by the required
1439 * amount. Once empty, remove the range from the list.
1441 * To free a range of LPIs, add a free range to the list, sort it and
1442 * merge the result if the new range happens to be adjacent to an
1443 * already free block.
1445 * The consequence of the above is that allocation is cost is low, but
1446 * freeing is expensive. We assumes that freeing rarely occurs.
1448 #define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */
1450 static DEFINE_MUTEX(lpi_range_lock
);
1451 static LIST_HEAD(lpi_range_list
);
1454 struct list_head entry
;
1459 static struct lpi_range
*mk_lpi_range(u32 base
, u32 span
)
1461 struct lpi_range
*range
;
1463 range
= kzalloc(sizeof(*range
), GFP_KERNEL
);
1465 INIT_LIST_HEAD(&range
->entry
);
1466 range
->base_id
= base
;
1473 static int lpi_range_cmp(void *priv
, struct list_head
*a
, struct list_head
*b
)
1475 struct lpi_range
*ra
, *rb
;
1477 ra
= container_of(a
, struct lpi_range
, entry
);
1478 rb
= container_of(b
, struct lpi_range
, entry
);
1480 return ra
->base_id
- rb
->base_id
;
1483 static void merge_lpi_ranges(void)
1485 struct lpi_range
*range
, *tmp
;
1487 list_for_each_entry_safe(range
, tmp
, &lpi_range_list
, entry
) {
1488 if (!list_is_last(&range
->entry
, &lpi_range_list
) &&
1489 (tmp
->base_id
== (range
->base_id
+ range
->span
))) {
1490 tmp
->base_id
= range
->base_id
;
1491 tmp
->span
+= range
->span
;
1492 list_del(&range
->entry
);
1498 static int alloc_lpi_range(u32 nr_lpis
, u32
*base
)
1500 struct lpi_range
*range
, *tmp
;
1503 mutex_lock(&lpi_range_lock
);
1505 list_for_each_entry_safe(range
, tmp
, &lpi_range_list
, entry
) {
1506 if (range
->span
>= nr_lpis
) {
1507 *base
= range
->base_id
;
1508 range
->base_id
+= nr_lpis
;
1509 range
->span
-= nr_lpis
;
1511 if (range
->span
== 0) {
1512 list_del(&range
->entry
);
1521 mutex_unlock(&lpi_range_lock
);
1523 pr_debug("ITS: alloc %u:%u\n", *base
, nr_lpis
);
1527 static int free_lpi_range(u32 base
, u32 nr_lpis
)
1529 struct lpi_range
*new;
1532 mutex_lock(&lpi_range_lock
);
1534 new = mk_lpi_range(base
, nr_lpis
);
1540 list_add(&new->entry
, &lpi_range_list
);
1541 list_sort(NULL
, &lpi_range_list
, lpi_range_cmp
);
1544 mutex_unlock(&lpi_range_lock
);
1548 static int __init
its_lpi_init(u32 id_bits
)
1550 u32 lpis
= (1UL << id_bits
) - 8192;
1554 numlpis
= 1UL << GICD_TYPER_NUM_LPIS(gic_rdists
->gicd_typer
);
1556 if (numlpis
> 2 && !WARN_ON(numlpis
> lpis
)) {
1558 pr_info("ITS: Using hypervisor restricted LPI range [%u]\n",
1563 * Initializing the allocator is just the same as freeing the
1564 * full range of LPIs.
1566 err
= free_lpi_range(8192, lpis
);
1567 pr_debug("ITS: Allocator initialized for %u LPIs\n", lpis
);
1571 static unsigned long *its_lpi_alloc(int nr_irqs
, u32
*base
, int *nr_ids
)
1573 unsigned long *bitmap
= NULL
;
1577 err
= alloc_lpi_range(nr_irqs
, base
);
1582 } while (nr_irqs
> 0);
1590 bitmap
= kcalloc(BITS_TO_LONGS(nr_irqs
), sizeof (long), GFP_ATOMIC
);
1598 *base
= *nr_ids
= 0;
1603 static void its_lpi_free(unsigned long *bitmap
, u32 base
, u32 nr_ids
)
1605 WARN_ON(free_lpi_range(base
, nr_ids
));
1609 static struct page
*its_allocate_prop_table(gfp_t gfp_flags
)
1611 struct page
*prop_page
;
1613 prop_page
= alloc_pages(gfp_flags
, get_order(LPI_PROPBASE_SZ
));
1617 /* Priority 0xa0, Group-1, disabled */
1618 memset(page_address(prop_page
),
1619 LPI_PROP_DEFAULT_PRIO
| LPI_PROP_GROUP1
,
1622 /* Make sure the GIC will observe the written configuration */
1623 gic_flush_dcache_to_poc(page_address(prop_page
), LPI_PROPBASE_SZ
);
1628 static void its_free_prop_table(struct page
*prop_page
)
1630 free_pages((unsigned long)page_address(prop_page
),
1631 get_order(LPI_PROPBASE_SZ
));
1634 static int __init
its_alloc_lpi_tables(void)
1638 lpi_id_bits
= min_t(u32
, GICD_TYPER_ID_BITS(gic_rdists
->gicd_typer
),
1639 ITS_MAX_LPI_NRBITS
);
1640 gic_rdists
->prop_page
= its_allocate_prop_table(GFP_NOWAIT
);
1641 if (!gic_rdists
->prop_page
) {
1642 pr_err("Failed to allocate PROPBASE\n");
1646 paddr
= page_to_phys(gic_rdists
->prop_page
);
1647 pr_info("GIC: using LPI property table @%pa\n", &paddr
);
1649 return its_lpi_init(lpi_id_bits
);
1652 static const char *its_base_type_string
[] = {
1653 [GITS_BASER_TYPE_DEVICE
] = "Devices",
1654 [GITS_BASER_TYPE_VCPU
] = "Virtual CPUs",
1655 [GITS_BASER_TYPE_RESERVED3
] = "Reserved (3)",
1656 [GITS_BASER_TYPE_COLLECTION
] = "Interrupt Collections",
1657 [GITS_BASER_TYPE_RESERVED5
] = "Reserved (5)",
1658 [GITS_BASER_TYPE_RESERVED6
] = "Reserved (6)",
1659 [GITS_BASER_TYPE_RESERVED7
] = "Reserved (7)",
1662 static u64
its_read_baser(struct its_node
*its
, struct its_baser
*baser
)
1664 u32 idx
= baser
- its
->tables
;
1666 return gits_read_baser(its
->base
+ GITS_BASER
+ (idx
<< 3));
1669 static void its_write_baser(struct its_node
*its
, struct its_baser
*baser
,
1672 u32 idx
= baser
- its
->tables
;
1674 gits_write_baser(val
, its
->base
+ GITS_BASER
+ (idx
<< 3));
1675 baser
->val
= its_read_baser(its
, baser
);
1678 static int its_setup_baser(struct its_node
*its
, struct its_baser
*baser
,
1679 u64 cache
, u64 shr
, u32 psz
, u32 order
,
1682 u64 val
= its_read_baser(its
, baser
);
1683 u64 esz
= GITS_BASER_ENTRY_SIZE(val
);
1684 u64 type
= GITS_BASER_TYPE(val
);
1685 u64 baser_phys
, tmp
;
1690 alloc_pages
= (PAGE_ORDER_TO_SIZE(order
) / psz
);
1691 if (alloc_pages
> GITS_BASER_PAGES_MAX
) {
1692 pr_warn("ITS@%pa: %s too large, reduce ITS pages %u->%u\n",
1693 &its
->phys_base
, its_base_type_string
[type
],
1694 alloc_pages
, GITS_BASER_PAGES_MAX
);
1695 alloc_pages
= GITS_BASER_PAGES_MAX
;
1696 order
= get_order(GITS_BASER_PAGES_MAX
* psz
);
1699 base
= (void *)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
, order
);
1703 baser_phys
= virt_to_phys(base
);
1705 /* Check if the physical address of the memory is above 48bits */
1706 if (IS_ENABLED(CONFIG_ARM64_64K_PAGES
) && (baser_phys
>> 48)) {
1708 /* 52bit PA is supported only when PageSize=64K */
1709 if (psz
!= SZ_64K
) {
1710 pr_err("ITS: no 52bit PA support when psz=%d\n", psz
);
1711 free_pages((unsigned long)base
, order
);
1715 /* Convert 52bit PA to 48bit field */
1716 baser_phys
= GITS_BASER_PHYS_52_to_48(baser_phys
);
1721 (type
<< GITS_BASER_TYPE_SHIFT
) |
1722 ((esz
- 1) << GITS_BASER_ENTRY_SIZE_SHIFT
) |
1723 ((alloc_pages
- 1) << GITS_BASER_PAGES_SHIFT
) |
1728 val
|= indirect
? GITS_BASER_INDIRECT
: 0x0;
1732 val
|= GITS_BASER_PAGE_SIZE_4K
;
1735 val
|= GITS_BASER_PAGE_SIZE_16K
;
1738 val
|= GITS_BASER_PAGE_SIZE_64K
;
1742 its_write_baser(its
, baser
, val
);
1745 if ((val
^ tmp
) & GITS_BASER_SHAREABILITY_MASK
) {
1747 * Shareability didn't stick. Just use
1748 * whatever the read reported, which is likely
1749 * to be the only thing this redistributor
1750 * supports. If that's zero, make it
1751 * non-cacheable as well.
1753 shr
= tmp
& GITS_BASER_SHAREABILITY_MASK
;
1755 cache
= GITS_BASER_nC
;
1756 gic_flush_dcache_to_poc(base
, PAGE_ORDER_TO_SIZE(order
));
1761 if ((val
^ tmp
) & GITS_BASER_PAGE_SIZE_MASK
) {
1763 * Page size didn't stick. Let's try a smaller
1764 * size and retry. If we reach 4K, then
1765 * something is horribly wrong...
1767 free_pages((unsigned long)base
, order
);
1773 goto retry_alloc_baser
;
1776 goto retry_alloc_baser
;
1781 pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n",
1782 &its
->phys_base
, its_base_type_string
[type
],
1784 free_pages((unsigned long)base
, order
);
1788 baser
->order
= order
;
1791 tmp
= indirect
? GITS_LVL1_ENTRY_SIZE
: esz
;
1793 pr_info("ITS@%pa: allocated %d %s @%lx (%s, esz %d, psz %dK, shr %d)\n",
1794 &its
->phys_base
, (int)(PAGE_ORDER_TO_SIZE(order
) / (int)tmp
),
1795 its_base_type_string
[type
],
1796 (unsigned long)virt_to_phys(base
),
1797 indirect
? "indirect" : "flat", (int)esz
,
1798 psz
/ SZ_1K
, (int)shr
>> GITS_BASER_SHAREABILITY_SHIFT
);
1803 static bool its_parse_indirect_baser(struct its_node
*its
,
1804 struct its_baser
*baser
,
1805 u32 psz
, u32
*order
, u32 ids
)
1807 u64 tmp
= its_read_baser(its
, baser
);
1808 u64 type
= GITS_BASER_TYPE(tmp
);
1809 u64 esz
= GITS_BASER_ENTRY_SIZE(tmp
);
1810 u64 val
= GITS_BASER_InnerShareable
| GITS_BASER_RaWaWb
;
1811 u32 new_order
= *order
;
1812 bool indirect
= false;
1814 /* No need to enable Indirection if memory requirement < (psz*2)bytes */
1815 if ((esz
<< ids
) > (psz
* 2)) {
1817 * Find out whether hw supports a single or two-level table by
1818 * table by reading bit at offset '62' after writing '1' to it.
1820 its_write_baser(its
, baser
, val
| GITS_BASER_INDIRECT
);
1821 indirect
= !!(baser
->val
& GITS_BASER_INDIRECT
);
1825 * The size of the lvl2 table is equal to ITS page size
1826 * which is 'psz'. For computing lvl1 table size,
1827 * subtract ID bits that sparse lvl2 table from 'ids'
1828 * which is reported by ITS hardware times lvl1 table
1831 ids
-= ilog2(psz
/ (int)esz
);
1832 esz
= GITS_LVL1_ENTRY_SIZE
;
1837 * Allocate as many entries as required to fit the
1838 * range of device IDs that the ITS can grok... The ID
1839 * space being incredibly sparse, this results in a
1840 * massive waste of memory if two-level device table
1841 * feature is not supported by hardware.
1843 new_order
= max_t(u32
, get_order(esz
<< ids
), new_order
);
1844 if (new_order
>= MAX_ORDER
) {
1845 new_order
= MAX_ORDER
- 1;
1846 ids
= ilog2(PAGE_ORDER_TO_SIZE(new_order
) / (int)esz
);
1847 pr_warn("ITS@%pa: %s Table too large, reduce ids %u->%u\n",
1848 &its
->phys_base
, its_base_type_string
[type
],
1849 its
->device_ids
, ids
);
1857 static void its_free_tables(struct its_node
*its
)
1861 for (i
= 0; i
< GITS_BASER_NR_REGS
; i
++) {
1862 if (its
->tables
[i
].base
) {
1863 free_pages((unsigned long)its
->tables
[i
].base
,
1864 its
->tables
[i
].order
);
1865 its
->tables
[i
].base
= NULL
;
1870 static int its_alloc_tables(struct its_node
*its
)
1872 u64 shr
= GITS_BASER_InnerShareable
;
1873 u64 cache
= GITS_BASER_RaWaWb
;
1877 if (its
->flags
& ITS_FLAGS_WORKAROUND_CAVIUM_22375
)
1878 /* erratum 24313: ignore memory access type */
1879 cache
= GITS_BASER_nCnB
;
1881 for (i
= 0; i
< GITS_BASER_NR_REGS
; i
++) {
1882 struct its_baser
*baser
= its
->tables
+ i
;
1883 u64 val
= its_read_baser(its
, baser
);
1884 u64 type
= GITS_BASER_TYPE(val
);
1885 u32 order
= get_order(psz
);
1886 bool indirect
= false;
1889 case GITS_BASER_TYPE_NONE
:
1892 case GITS_BASER_TYPE_DEVICE
:
1893 indirect
= its_parse_indirect_baser(its
, baser
,
1898 case GITS_BASER_TYPE_VCPU
:
1899 indirect
= its_parse_indirect_baser(its
, baser
,
1901 ITS_MAX_VPEID_BITS
);
1905 err
= its_setup_baser(its
, baser
, cache
, shr
, psz
, order
, indirect
);
1907 its_free_tables(its
);
1911 /* Update settings which will be used for next BASERn */
1913 cache
= baser
->val
& GITS_BASER_CACHEABILITY_MASK
;
1914 shr
= baser
->val
& GITS_BASER_SHAREABILITY_MASK
;
1920 static int its_alloc_collections(struct its_node
*its
)
1924 its
->collections
= kcalloc(nr_cpu_ids
, sizeof(*its
->collections
),
1926 if (!its
->collections
)
1929 for (i
= 0; i
< nr_cpu_ids
; i
++)
1930 its
->collections
[i
].target_address
= ~0ULL;
1935 static struct page
*its_allocate_pending_table(gfp_t gfp_flags
)
1937 struct page
*pend_page
;
1939 * The pending pages have to be at least 64kB aligned,
1940 * hence the 'max(LPI_PENDBASE_SZ, SZ_64K)' below.
1942 pend_page
= alloc_pages(gfp_flags
| __GFP_ZERO
,
1943 get_order(max_t(u32
, LPI_PENDBASE_SZ
, SZ_64K
)));
1947 /* Make sure the GIC will observe the zero-ed page */
1948 gic_flush_dcache_to_poc(page_address(pend_page
), LPI_PENDBASE_SZ
);
1953 static void its_free_pending_table(struct page
*pt
)
1955 free_pages((unsigned long)page_address(pt
),
1956 get_order(max_t(u32
, LPI_PENDBASE_SZ
, SZ_64K
)));
1959 static u64
its_clear_vpend_valid(void __iomem
*vlpi_base
)
1961 u32 count
= 1000000; /* 1s! */
1965 val
= gits_read_vpendbaser(vlpi_base
+ GICR_VPENDBASER
);
1966 val
&= ~GICR_VPENDBASER_Valid
;
1967 gits_write_vpendbaser(val
, vlpi_base
+ GICR_VPENDBASER
);
1970 val
= gits_read_vpendbaser(vlpi_base
+ GICR_VPENDBASER
);
1971 clean
= !(val
& GICR_VPENDBASER_Dirty
);
1977 } while (!clean
&& count
);
1982 static void its_cpu_init_lpis(void)
1984 void __iomem
*rbase
= gic_data_rdist_rd_base();
1985 struct page
*pend_page
;
1988 /* If we didn't allocate the pending table yet, do it now */
1989 pend_page
= gic_data_rdist()->pend_page
;
1993 pend_page
= its_allocate_pending_table(GFP_NOWAIT
);
1995 pr_err("Failed to allocate PENDBASE for CPU%d\n",
1996 smp_processor_id());
2000 paddr
= page_to_phys(pend_page
);
2001 pr_info("CPU%d: using LPI pending table @%pa\n",
2002 smp_processor_id(), &paddr
);
2003 gic_data_rdist()->pend_page
= pend_page
;
2007 val
= (page_to_phys(gic_rdists
->prop_page
) |
2008 GICR_PROPBASER_InnerShareable
|
2009 GICR_PROPBASER_RaWaWb
|
2010 ((LPI_NRBITS
- 1) & GICR_PROPBASER_IDBITS_MASK
));
2012 gicr_write_propbaser(val
, rbase
+ GICR_PROPBASER
);
2013 tmp
= gicr_read_propbaser(rbase
+ GICR_PROPBASER
);
2015 if ((tmp
^ val
) & GICR_PROPBASER_SHAREABILITY_MASK
) {
2016 if (!(tmp
& GICR_PROPBASER_SHAREABILITY_MASK
)) {
2018 * The HW reports non-shareable, we must
2019 * remove the cacheability attributes as
2022 val
&= ~(GICR_PROPBASER_SHAREABILITY_MASK
|
2023 GICR_PROPBASER_CACHEABILITY_MASK
);
2024 val
|= GICR_PROPBASER_nC
;
2025 gicr_write_propbaser(val
, rbase
+ GICR_PROPBASER
);
2027 pr_info_once("GIC: using cache flushing for LPI property table\n");
2028 gic_rdists
->flags
|= RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING
;
2032 val
= (page_to_phys(pend_page
) |
2033 GICR_PENDBASER_InnerShareable
|
2034 GICR_PENDBASER_RaWaWb
);
2036 gicr_write_pendbaser(val
, rbase
+ GICR_PENDBASER
);
2037 tmp
= gicr_read_pendbaser(rbase
+ GICR_PENDBASER
);
2039 if (!(tmp
& GICR_PENDBASER_SHAREABILITY_MASK
)) {
2041 * The HW reports non-shareable, we must remove the
2042 * cacheability attributes as well.
2044 val
&= ~(GICR_PENDBASER_SHAREABILITY_MASK
|
2045 GICR_PENDBASER_CACHEABILITY_MASK
);
2046 val
|= GICR_PENDBASER_nC
;
2047 gicr_write_pendbaser(val
, rbase
+ GICR_PENDBASER
);
2051 val
= readl_relaxed(rbase
+ GICR_CTLR
);
2052 val
|= GICR_CTLR_ENABLE_LPIS
;
2053 writel_relaxed(val
, rbase
+ GICR_CTLR
);
2055 if (gic_rdists
->has_vlpis
) {
2056 void __iomem
*vlpi_base
= gic_data_rdist_vlpi_base();
2059 * It's possible for CPU to receive VLPIs before it is
2060 * sheduled as a vPE, especially for the first CPU, and the
2061 * VLPI with INTID larger than 2^(IDbits+1) will be considered
2062 * as out of range and dropped by GIC.
2063 * So we initialize IDbits to known value to avoid VLPI drop.
2065 val
= (LPI_NRBITS
- 1) & GICR_VPROPBASER_IDBITS_MASK
;
2066 pr_debug("GICv4: CPU%d: Init IDbits to 0x%llx for GICR_VPROPBASER\n",
2067 smp_processor_id(), val
);
2068 gits_write_vpropbaser(val
, vlpi_base
+ GICR_VPROPBASER
);
2071 * Also clear Valid bit of GICR_VPENDBASER, in case some
2072 * ancient programming gets left in and has possibility of
2073 * corrupting memory.
2075 val
= its_clear_vpend_valid(vlpi_base
);
2076 WARN_ON(val
& GICR_VPENDBASER_Dirty
);
2079 /* Make sure the GIC has seen the above */
2083 static void its_cpu_init_collection(struct its_node
*its
)
2085 int cpu
= smp_processor_id();
2088 /* avoid cross node collections and its mapping */
2089 if (its
->flags
& ITS_FLAGS_WORKAROUND_CAVIUM_23144
) {
2090 struct device_node
*cpu_node
;
2092 cpu_node
= of_get_cpu_node(cpu
, NULL
);
2093 if (its
->numa_node
!= NUMA_NO_NODE
&&
2094 its
->numa_node
!= of_node_to_nid(cpu_node
))
2099 * We now have to bind each collection to its target
2102 if (gic_read_typer(its
->base
+ GITS_TYPER
) & GITS_TYPER_PTA
) {
2104 * This ITS wants the physical address of the
2107 target
= gic_data_rdist()->phys_base
;
2109 /* This ITS wants a linear CPU number. */
2110 target
= gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER
);
2111 target
= GICR_TYPER_CPU_NUMBER(target
) << 16;
2114 /* Perform collection mapping */
2115 its
->collections
[cpu
].target_address
= target
;
2116 its
->collections
[cpu
].col_id
= cpu
;
2118 its_send_mapc(its
, &its
->collections
[cpu
], 1);
2119 its_send_invall(its
, &its
->collections
[cpu
]);
2122 static void its_cpu_init_collections(void)
2124 struct its_node
*its
;
2126 raw_spin_lock(&its_lock
);
2128 list_for_each_entry(its
, &its_nodes
, entry
)
2129 its_cpu_init_collection(its
);
2131 raw_spin_unlock(&its_lock
);
2134 static struct its_device
*its_find_device(struct its_node
*its
, u32 dev_id
)
2136 struct its_device
*its_dev
= NULL
, *tmp
;
2137 unsigned long flags
;
2139 raw_spin_lock_irqsave(&its
->lock
, flags
);
2141 list_for_each_entry(tmp
, &its
->its_device_list
, entry
) {
2142 if (tmp
->device_id
== dev_id
) {
2148 raw_spin_unlock_irqrestore(&its
->lock
, flags
);
2153 static struct its_baser
*its_get_baser(struct its_node
*its
, u32 type
)
2157 for (i
= 0; i
< GITS_BASER_NR_REGS
; i
++) {
2158 if (GITS_BASER_TYPE(its
->tables
[i
].val
) == type
)
2159 return &its
->tables
[i
];
2165 static bool its_alloc_table_entry(struct its_baser
*baser
, u32 id
)
2171 /* Don't allow device id that exceeds single, flat table limit */
2172 esz
= GITS_BASER_ENTRY_SIZE(baser
->val
);
2173 if (!(baser
->val
& GITS_BASER_INDIRECT
))
2174 return (id
< (PAGE_ORDER_TO_SIZE(baser
->order
) / esz
));
2176 /* Compute 1st level table index & check if that exceeds table limit */
2177 idx
= id
>> ilog2(baser
->psz
/ esz
);
2178 if (idx
>= (PAGE_ORDER_TO_SIZE(baser
->order
) / GITS_LVL1_ENTRY_SIZE
))
2181 table
= baser
->base
;
2183 /* Allocate memory for 2nd level table */
2185 page
= alloc_pages(GFP_KERNEL
| __GFP_ZERO
, get_order(baser
->psz
));
2189 /* Flush Lvl2 table to PoC if hw doesn't support coherency */
2190 if (!(baser
->val
& GITS_BASER_SHAREABILITY_MASK
))
2191 gic_flush_dcache_to_poc(page_address(page
), baser
->psz
);
2193 table
[idx
] = cpu_to_le64(page_to_phys(page
) | GITS_BASER_VALID
);
2195 /* Flush Lvl1 entry to PoC if hw doesn't support coherency */
2196 if (!(baser
->val
& GITS_BASER_SHAREABILITY_MASK
))
2197 gic_flush_dcache_to_poc(table
+ idx
, GITS_LVL1_ENTRY_SIZE
);
2199 /* Ensure updated table contents are visible to ITS hardware */
2206 static bool its_alloc_device_table(struct its_node
*its
, u32 dev_id
)
2208 struct its_baser
*baser
;
2210 baser
= its_get_baser(its
, GITS_BASER_TYPE_DEVICE
);
2212 /* Don't allow device id that exceeds ITS hardware limit */
2214 return (ilog2(dev_id
) < its
->device_ids
);
2216 return its_alloc_table_entry(baser
, dev_id
);
2219 static bool its_alloc_vpe_table(u32 vpe_id
)
2221 struct its_node
*its
;
2224 * Make sure the L2 tables are allocated on *all* v4 ITSs. We
2225 * could try and only do it on ITSs corresponding to devices
2226 * that have interrupts targeted at this VPE, but the
2227 * complexity becomes crazy (and you have tons of memory
2230 list_for_each_entry(its
, &its_nodes
, entry
) {
2231 struct its_baser
*baser
;
2236 baser
= its_get_baser(its
, GITS_BASER_TYPE_VCPU
);
2240 if (!its_alloc_table_entry(baser
, vpe_id
))
2247 static struct its_device
*its_create_device(struct its_node
*its
, u32 dev_id
,
2248 int nvecs
, bool alloc_lpis
)
2250 struct its_device
*dev
;
2251 unsigned long *lpi_map
= NULL
;
2252 unsigned long flags
;
2253 u16
*col_map
= NULL
;
2260 if (!its_alloc_device_table(its
, dev_id
))
2263 if (WARN_ON(!is_power_of_2(nvecs
)))
2264 nvecs
= roundup_pow_of_two(nvecs
);
2266 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2268 * Even if the device wants a single LPI, the ITT must be
2269 * sized as a power of two (and you need at least one bit...).
2271 nr_ites
= max(2, nvecs
);
2272 sz
= nr_ites
* its
->ite_size
;
2273 sz
= max(sz
, ITS_ITT_ALIGN
) + ITS_ITT_ALIGN
- 1;
2274 itt
= kzalloc(sz
, GFP_KERNEL
);
2276 lpi_map
= its_lpi_alloc(nvecs
, &lpi_base
, &nr_lpis
);
2278 col_map
= kcalloc(nr_lpis
, sizeof(*col_map
),
2281 col_map
= kcalloc(nr_ites
, sizeof(*col_map
), GFP_KERNEL
);
2286 if (!dev
|| !itt
|| !col_map
|| (!lpi_map
&& alloc_lpis
)) {
2294 gic_flush_dcache_to_poc(itt
, sz
);
2298 dev
->nr_ites
= nr_ites
;
2299 dev
->event_map
.lpi_map
= lpi_map
;
2300 dev
->event_map
.col_map
= col_map
;
2301 dev
->event_map
.lpi_base
= lpi_base
;
2302 dev
->event_map
.nr_lpis
= nr_lpis
;
2303 mutex_init(&dev
->event_map
.vlpi_lock
);
2304 dev
->device_id
= dev_id
;
2305 INIT_LIST_HEAD(&dev
->entry
);
2307 raw_spin_lock_irqsave(&its
->lock
, flags
);
2308 list_add(&dev
->entry
, &its
->its_device_list
);
2309 raw_spin_unlock_irqrestore(&its
->lock
, flags
);
2311 /* Map device to its ITT */
2312 its_send_mapd(dev
, 1);
2317 static void its_free_device(struct its_device
*its_dev
)
2319 unsigned long flags
;
2321 raw_spin_lock_irqsave(&its_dev
->its
->lock
, flags
);
2322 list_del(&its_dev
->entry
);
2323 raw_spin_unlock_irqrestore(&its_dev
->its
->lock
, flags
);
2324 kfree(its_dev
->itt
);
2328 static int its_alloc_device_irq(struct its_device
*dev
, int nvecs
, irq_hw_number_t
*hwirq
)
2332 idx
= bitmap_find_free_region(dev
->event_map
.lpi_map
,
2333 dev
->event_map
.nr_lpis
,
2334 get_count_order(nvecs
));
2338 *hwirq
= dev
->event_map
.lpi_base
+ idx
;
2339 set_bit(idx
, dev
->event_map
.lpi_map
);
2344 static int its_msi_prepare(struct irq_domain
*domain
, struct device
*dev
,
2345 int nvec
, msi_alloc_info_t
*info
)
2347 struct its_node
*its
;
2348 struct its_device
*its_dev
;
2349 struct msi_domain_info
*msi_info
;
2354 * We ignore "dev" entierely, and rely on the dev_id that has
2355 * been passed via the scratchpad. This limits this domain's
2356 * usefulness to upper layers that definitely know that they
2357 * are built on top of the ITS.
2359 dev_id
= info
->scratchpad
[0].ul
;
2361 msi_info
= msi_get_domain_info(domain
);
2362 its
= msi_info
->data
;
2364 if (!gic_rdists
->has_direct_lpi
&&
2366 vpe_proxy
.dev
->its
== its
&&
2367 dev_id
== vpe_proxy
.dev
->device_id
) {
2368 /* Bad luck. Get yourself a better implementation */
2369 WARN_ONCE(1, "DevId %x clashes with GICv4 VPE proxy device\n",
2374 mutex_lock(&its
->dev_alloc_lock
);
2375 its_dev
= its_find_device(its
, dev_id
);
2378 * We already have seen this ID, probably through
2379 * another alias (PCI bridge of some sort). No need to
2380 * create the device.
2382 its_dev
->shared
= true;
2383 pr_debug("Reusing ITT for devID %x\n", dev_id
);
2387 its_dev
= its_create_device(its
, dev_id
, nvec
, true);
2393 pr_debug("ITT %d entries, %d bits\n", nvec
, ilog2(nvec
));
2395 mutex_unlock(&its
->dev_alloc_lock
);
2396 info
->scratchpad
[0].ptr
= its_dev
;
2400 static struct msi_domain_ops its_msi_domain_ops
= {
2401 .msi_prepare
= its_msi_prepare
,
2404 static int its_irq_gic_domain_alloc(struct irq_domain
*domain
,
2406 irq_hw_number_t hwirq
)
2408 struct irq_fwspec fwspec
;
2410 if (irq_domain_get_of_node(domain
->parent
)) {
2411 fwspec
.fwnode
= domain
->parent
->fwnode
;
2412 fwspec
.param_count
= 3;
2413 fwspec
.param
[0] = GIC_IRQ_TYPE_LPI
;
2414 fwspec
.param
[1] = hwirq
;
2415 fwspec
.param
[2] = IRQ_TYPE_EDGE_RISING
;
2416 } else if (is_fwnode_irqchip(domain
->parent
->fwnode
)) {
2417 fwspec
.fwnode
= domain
->parent
->fwnode
;
2418 fwspec
.param_count
= 2;
2419 fwspec
.param
[0] = hwirq
;
2420 fwspec
.param
[1] = IRQ_TYPE_EDGE_RISING
;
2425 return irq_domain_alloc_irqs_parent(domain
, virq
, 1, &fwspec
);
2428 static int its_irq_domain_alloc(struct irq_domain
*domain
, unsigned int virq
,
2429 unsigned int nr_irqs
, void *args
)
2431 msi_alloc_info_t
*info
= args
;
2432 struct its_device
*its_dev
= info
->scratchpad
[0].ptr
;
2433 irq_hw_number_t hwirq
;
2437 err
= its_alloc_device_irq(its_dev
, nr_irqs
, &hwirq
);
2441 for (i
= 0; i
< nr_irqs
; i
++) {
2442 err
= its_irq_gic_domain_alloc(domain
, virq
+ i
, hwirq
+ i
);
2446 irq_domain_set_hwirq_and_chip(domain
, virq
+ i
,
2447 hwirq
+ i
, &its_irq_chip
, its_dev
);
2448 irqd_set_single_target(irq_desc_get_irq_data(irq_to_desc(virq
+ i
)));
2449 pr_debug("ID:%d pID:%d vID:%d\n",
2450 (int)(hwirq
+ i
- its_dev
->event_map
.lpi_base
),
2451 (int)(hwirq
+ i
), virq
+ i
);
2457 static int its_irq_domain_activate(struct irq_domain
*domain
,
2458 struct irq_data
*d
, bool reserve
)
2460 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
2461 u32 event
= its_get_event_id(d
);
2462 const struct cpumask
*cpu_mask
= cpu_online_mask
;
2465 /* get the cpu_mask of local node */
2466 if (its_dev
->its
->numa_node
>= 0)
2467 cpu_mask
= cpumask_of_node(its_dev
->its
->numa_node
);
2469 /* Bind the LPI to the first possible CPU */
2470 cpu
= cpumask_first_and(cpu_mask
, cpu_online_mask
);
2471 if (cpu
>= nr_cpu_ids
) {
2472 if (its_dev
->its
->flags
& ITS_FLAGS_WORKAROUND_CAVIUM_23144
)
2475 cpu
= cpumask_first(cpu_online_mask
);
2478 its_dev
->event_map
.col_map
[event
] = cpu
;
2479 irq_data_update_effective_affinity(d
, cpumask_of(cpu
));
2481 /* Map the GIC IRQ and event to the device */
2482 its_send_mapti(its_dev
, d
->hwirq
, event
);
2486 static void its_irq_domain_deactivate(struct irq_domain
*domain
,
2489 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
2490 u32 event
= its_get_event_id(d
);
2492 /* Stop the delivery of interrupts */
2493 its_send_discard(its_dev
, event
);
2496 static void its_irq_domain_free(struct irq_domain
*domain
, unsigned int virq
,
2497 unsigned int nr_irqs
)
2499 struct irq_data
*d
= irq_domain_get_irq_data(domain
, virq
);
2500 struct its_device
*its_dev
= irq_data_get_irq_chip_data(d
);
2501 struct its_node
*its
= its_dev
->its
;
2504 for (i
= 0; i
< nr_irqs
; i
++) {
2505 struct irq_data
*data
= irq_domain_get_irq_data(domain
,
2507 u32 event
= its_get_event_id(data
);
2509 /* Mark interrupt index as unused */
2510 clear_bit(event
, its_dev
->event_map
.lpi_map
);
2512 /* Nuke the entry in the domain */
2513 irq_domain_reset_irq_data(data
);
2516 mutex_lock(&its
->dev_alloc_lock
);
2519 * If all interrupts have been freed, start mopping the
2520 * floor. This is conditionned on the device not being shared.
2522 if (!its_dev
->shared
&&
2523 bitmap_empty(its_dev
->event_map
.lpi_map
,
2524 its_dev
->event_map
.nr_lpis
)) {
2525 its_lpi_free(its_dev
->event_map
.lpi_map
,
2526 its_dev
->event_map
.lpi_base
,
2527 its_dev
->event_map
.nr_lpis
);
2528 kfree(its_dev
->event_map
.col_map
);
2530 /* Unmap device/itt */
2531 its_send_mapd(its_dev
, 0);
2532 its_free_device(its_dev
);
2535 mutex_unlock(&its
->dev_alloc_lock
);
2537 irq_domain_free_irqs_parent(domain
, virq
, nr_irqs
);
2540 static const struct irq_domain_ops its_domain_ops
= {
2541 .alloc
= its_irq_domain_alloc
,
2542 .free
= its_irq_domain_free
,
2543 .activate
= its_irq_domain_activate
,
2544 .deactivate
= its_irq_domain_deactivate
,
2550 * If a GICv4 doesn't implement Direct LPIs (which is extremely
2551 * likely), the only way to perform an invalidate is to use a fake
2552 * device to issue an INV command, implying that the LPI has first
2553 * been mapped to some event on that device. Since this is not exactly
2554 * cheap, we try to keep that mapping around as long as possible, and
2555 * only issue an UNMAP if we're short on available slots.
2557 * Broken by design(tm).
2559 static void its_vpe_db_proxy_unmap_locked(struct its_vpe
*vpe
)
2561 /* Already unmapped? */
2562 if (vpe
->vpe_proxy_event
== -1)
2565 its_send_discard(vpe_proxy
.dev
, vpe
->vpe_proxy_event
);
2566 vpe_proxy
.vpes
[vpe
->vpe_proxy_event
] = NULL
;
2569 * We don't track empty slots at all, so let's move the
2570 * next_victim pointer if we can quickly reuse that slot
2571 * instead of nuking an existing entry. Not clear that this is
2572 * always a win though, and this might just generate a ripple
2573 * effect... Let's just hope VPEs don't migrate too often.
2575 if (vpe_proxy
.vpes
[vpe_proxy
.next_victim
])
2576 vpe_proxy
.next_victim
= vpe
->vpe_proxy_event
;
2578 vpe
->vpe_proxy_event
= -1;
2581 static void its_vpe_db_proxy_unmap(struct its_vpe
*vpe
)
2583 if (!gic_rdists
->has_direct_lpi
) {
2584 unsigned long flags
;
2586 raw_spin_lock_irqsave(&vpe_proxy
.lock
, flags
);
2587 its_vpe_db_proxy_unmap_locked(vpe
);
2588 raw_spin_unlock_irqrestore(&vpe_proxy
.lock
, flags
);
2592 static void its_vpe_db_proxy_map_locked(struct its_vpe
*vpe
)
2594 /* Already mapped? */
2595 if (vpe
->vpe_proxy_event
!= -1)
2598 /* This slot was already allocated. Kick the other VPE out. */
2599 if (vpe_proxy
.vpes
[vpe_proxy
.next_victim
])
2600 its_vpe_db_proxy_unmap_locked(vpe_proxy
.vpes
[vpe_proxy
.next_victim
]);
2602 /* Map the new VPE instead */
2603 vpe_proxy
.vpes
[vpe_proxy
.next_victim
] = vpe
;
2604 vpe
->vpe_proxy_event
= vpe_proxy
.next_victim
;
2605 vpe_proxy
.next_victim
= (vpe_proxy
.next_victim
+ 1) % vpe_proxy
.dev
->nr_ites
;
2607 vpe_proxy
.dev
->event_map
.col_map
[vpe
->vpe_proxy_event
] = vpe
->col_idx
;
2608 its_send_mapti(vpe_proxy
.dev
, vpe
->vpe_db_lpi
, vpe
->vpe_proxy_event
);
2611 static void its_vpe_db_proxy_move(struct its_vpe
*vpe
, int from
, int to
)
2613 unsigned long flags
;
2614 struct its_collection
*target_col
;
2616 if (gic_rdists
->has_direct_lpi
) {
2617 void __iomem
*rdbase
;
2619 rdbase
= per_cpu_ptr(gic_rdists
->rdist
, from
)->rd_base
;
2620 gic_write_lpir(vpe
->vpe_db_lpi
, rdbase
+ GICR_CLRLPIR
);
2621 while (gic_read_lpir(rdbase
+ GICR_SYNCR
) & 1)
2627 raw_spin_lock_irqsave(&vpe_proxy
.lock
, flags
);
2629 its_vpe_db_proxy_map_locked(vpe
);
2631 target_col
= &vpe_proxy
.dev
->its
->collections
[to
];
2632 its_send_movi(vpe_proxy
.dev
, target_col
, vpe
->vpe_proxy_event
);
2633 vpe_proxy
.dev
->event_map
.col_map
[vpe
->vpe_proxy_event
] = to
;
2635 raw_spin_unlock_irqrestore(&vpe_proxy
.lock
, flags
);
2638 static int its_vpe_set_affinity(struct irq_data
*d
,
2639 const struct cpumask
*mask_val
,
2642 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
2643 int cpu
= cpumask_first(mask_val
);
2646 * Changing affinity is mega expensive, so let's be as lazy as
2647 * we can and only do it if we really have to. Also, if mapped
2648 * into the proxy device, we need to move the doorbell
2649 * interrupt to its new location.
2651 if (vpe
->col_idx
!= cpu
) {
2652 int from
= vpe
->col_idx
;
2655 its_send_vmovp(vpe
);
2656 its_vpe_db_proxy_move(vpe
, from
, cpu
);
2659 irq_data_update_effective_affinity(d
, cpumask_of(cpu
));
2661 return IRQ_SET_MASK_OK_DONE
;
2664 static void its_vpe_schedule(struct its_vpe
*vpe
)
2666 void __iomem
*vlpi_base
= gic_data_rdist_vlpi_base();
2669 /* Schedule the VPE */
2670 val
= virt_to_phys(page_address(vpe
->its_vm
->vprop_page
)) &
2671 GENMASK_ULL(51, 12);
2672 val
|= (LPI_NRBITS
- 1) & GICR_VPROPBASER_IDBITS_MASK
;
2673 val
|= GICR_VPROPBASER_RaWb
;
2674 val
|= GICR_VPROPBASER_InnerShareable
;
2675 gits_write_vpropbaser(val
, vlpi_base
+ GICR_VPROPBASER
);
2677 val
= virt_to_phys(page_address(vpe
->vpt_page
)) &
2678 GENMASK_ULL(51, 16);
2679 val
|= GICR_VPENDBASER_RaWaWb
;
2680 val
|= GICR_VPENDBASER_NonShareable
;
2682 * There is no good way of finding out if the pending table is
2683 * empty as we can race against the doorbell interrupt very
2684 * easily. So in the end, vpe->pending_last is only an
2685 * indication that the vcpu has something pending, not one
2686 * that the pending table is empty. A good implementation
2687 * would be able to read its coarse map pretty quickly anyway,
2688 * making this a tolerable issue.
2690 val
|= GICR_VPENDBASER_PendingLast
;
2691 val
|= vpe
->idai
? GICR_VPENDBASER_IDAI
: 0;
2692 val
|= GICR_VPENDBASER_Valid
;
2693 gits_write_vpendbaser(val
, vlpi_base
+ GICR_VPENDBASER
);
2696 static void its_vpe_deschedule(struct its_vpe
*vpe
)
2698 void __iomem
*vlpi_base
= gic_data_rdist_vlpi_base();
2701 val
= its_clear_vpend_valid(vlpi_base
);
2703 if (unlikely(val
& GICR_VPENDBASER_Dirty
)) {
2704 pr_err_ratelimited("ITS virtual pending table not cleaning\n");
2706 vpe
->pending_last
= true;
2708 vpe
->idai
= !!(val
& GICR_VPENDBASER_IDAI
);
2709 vpe
->pending_last
= !!(val
& GICR_VPENDBASER_PendingLast
);
2713 static void its_vpe_invall(struct its_vpe
*vpe
)
2715 struct its_node
*its
;
2717 list_for_each_entry(its
, &its_nodes
, entry
) {
2721 if (its_list_map
&& !vpe
->its_vm
->vlpi_count
[its
->list_nr
])
2725 * Sending a VINVALL to a single ITS is enough, as all
2726 * we need is to reach the redistributors.
2728 its_send_vinvall(its
, vpe
);
2733 static int its_vpe_set_vcpu_affinity(struct irq_data
*d
, void *vcpu_info
)
2735 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
2736 struct its_cmd_info
*info
= vcpu_info
;
2738 switch (info
->cmd_type
) {
2740 its_vpe_schedule(vpe
);
2743 case DESCHEDULE_VPE
:
2744 its_vpe_deschedule(vpe
);
2748 its_vpe_invall(vpe
);
2756 static void its_vpe_send_cmd(struct its_vpe
*vpe
,
2757 void (*cmd
)(struct its_device
*, u32
))
2759 unsigned long flags
;
2761 raw_spin_lock_irqsave(&vpe_proxy
.lock
, flags
);
2763 its_vpe_db_proxy_map_locked(vpe
);
2764 cmd(vpe_proxy
.dev
, vpe
->vpe_proxy_event
);
2766 raw_spin_unlock_irqrestore(&vpe_proxy
.lock
, flags
);
2769 static void its_vpe_send_inv(struct irq_data
*d
)
2771 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
2773 if (gic_rdists
->has_direct_lpi
) {
2774 void __iomem
*rdbase
;
2776 rdbase
= per_cpu_ptr(gic_rdists
->rdist
, vpe
->col_idx
)->rd_base
;
2777 gic_write_lpir(vpe
->vpe_db_lpi
, rdbase
+ GICR_INVLPIR
);
2778 while (gic_read_lpir(rdbase
+ GICR_SYNCR
) & 1)
2781 its_vpe_send_cmd(vpe
, its_send_inv
);
2785 static void its_vpe_mask_irq(struct irq_data
*d
)
2788 * We need to unmask the LPI, which is described by the parent
2789 * irq_data. Instead of calling into the parent (which won't
2790 * exactly do the right thing, let's simply use the
2791 * parent_data pointer. Yes, I'm naughty.
2793 lpi_write_config(d
->parent_data
, LPI_PROP_ENABLED
, 0);
2794 its_vpe_send_inv(d
);
2797 static void its_vpe_unmask_irq(struct irq_data
*d
)
2799 /* Same hack as above... */
2800 lpi_write_config(d
->parent_data
, 0, LPI_PROP_ENABLED
);
2801 its_vpe_send_inv(d
);
2804 static int its_vpe_set_irqchip_state(struct irq_data
*d
,
2805 enum irqchip_irq_state which
,
2808 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
2810 if (which
!= IRQCHIP_STATE_PENDING
)
2813 if (gic_rdists
->has_direct_lpi
) {
2814 void __iomem
*rdbase
;
2816 rdbase
= per_cpu_ptr(gic_rdists
->rdist
, vpe
->col_idx
)->rd_base
;
2818 gic_write_lpir(vpe
->vpe_db_lpi
, rdbase
+ GICR_SETLPIR
);
2820 gic_write_lpir(vpe
->vpe_db_lpi
, rdbase
+ GICR_CLRLPIR
);
2821 while (gic_read_lpir(rdbase
+ GICR_SYNCR
) & 1)
2826 its_vpe_send_cmd(vpe
, its_send_int
);
2828 its_vpe_send_cmd(vpe
, its_send_clear
);
2834 static struct irq_chip its_vpe_irq_chip
= {
2835 .name
= "GICv4-vpe",
2836 .irq_mask
= its_vpe_mask_irq
,
2837 .irq_unmask
= its_vpe_unmask_irq
,
2838 .irq_eoi
= irq_chip_eoi_parent
,
2839 .irq_set_affinity
= its_vpe_set_affinity
,
2840 .irq_set_irqchip_state
= its_vpe_set_irqchip_state
,
2841 .irq_set_vcpu_affinity
= its_vpe_set_vcpu_affinity
,
2844 static int its_vpe_id_alloc(void)
2846 return ida_simple_get(&its_vpeid_ida
, 0, ITS_MAX_VPEID
, GFP_KERNEL
);
2849 static void its_vpe_id_free(u16 id
)
2851 ida_simple_remove(&its_vpeid_ida
, id
);
2854 static int its_vpe_init(struct its_vpe
*vpe
)
2856 struct page
*vpt_page
;
2859 /* Allocate vpe_id */
2860 vpe_id
= its_vpe_id_alloc();
2865 vpt_page
= its_allocate_pending_table(GFP_KERNEL
);
2867 its_vpe_id_free(vpe_id
);
2871 if (!its_alloc_vpe_table(vpe_id
)) {
2872 its_vpe_id_free(vpe_id
);
2873 its_free_pending_table(vpe
->vpt_page
);
2877 vpe
->vpe_id
= vpe_id
;
2878 vpe
->vpt_page
= vpt_page
;
2879 vpe
->vpe_proxy_event
= -1;
2884 static void its_vpe_teardown(struct its_vpe
*vpe
)
2886 its_vpe_db_proxy_unmap(vpe
);
2887 its_vpe_id_free(vpe
->vpe_id
);
2888 its_free_pending_table(vpe
->vpt_page
);
2891 static void its_vpe_irq_domain_free(struct irq_domain
*domain
,
2893 unsigned int nr_irqs
)
2895 struct its_vm
*vm
= domain
->host_data
;
2898 irq_domain_free_irqs_parent(domain
, virq
, nr_irqs
);
2900 for (i
= 0; i
< nr_irqs
; i
++) {
2901 struct irq_data
*data
= irq_domain_get_irq_data(domain
,
2903 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(data
);
2905 BUG_ON(vm
!= vpe
->its_vm
);
2907 clear_bit(data
->hwirq
, vm
->db_bitmap
);
2908 its_vpe_teardown(vpe
);
2909 irq_domain_reset_irq_data(data
);
2912 if (bitmap_empty(vm
->db_bitmap
, vm
->nr_db_lpis
)) {
2913 its_lpi_free(vm
->db_bitmap
, vm
->db_lpi_base
, vm
->nr_db_lpis
);
2914 its_free_prop_table(vm
->vprop_page
);
2918 static int its_vpe_irq_domain_alloc(struct irq_domain
*domain
, unsigned int virq
,
2919 unsigned int nr_irqs
, void *args
)
2921 struct its_vm
*vm
= args
;
2922 unsigned long *bitmap
;
2923 struct page
*vprop_page
;
2924 int base
, nr_ids
, i
, err
= 0;
2928 bitmap
= its_lpi_alloc(roundup_pow_of_two(nr_irqs
), &base
, &nr_ids
);
2932 if (nr_ids
< nr_irqs
) {
2933 its_lpi_free(bitmap
, base
, nr_ids
);
2937 vprop_page
= its_allocate_prop_table(GFP_KERNEL
);
2939 its_lpi_free(bitmap
, base
, nr_ids
);
2943 vm
->db_bitmap
= bitmap
;
2944 vm
->db_lpi_base
= base
;
2945 vm
->nr_db_lpis
= nr_ids
;
2946 vm
->vprop_page
= vprop_page
;
2948 for (i
= 0; i
< nr_irqs
; i
++) {
2949 vm
->vpes
[i
]->vpe_db_lpi
= base
+ i
;
2950 err
= its_vpe_init(vm
->vpes
[i
]);
2953 err
= its_irq_gic_domain_alloc(domain
, virq
+ i
,
2954 vm
->vpes
[i
]->vpe_db_lpi
);
2957 irq_domain_set_hwirq_and_chip(domain
, virq
+ i
, i
,
2958 &its_vpe_irq_chip
, vm
->vpes
[i
]);
2964 its_vpe_irq_domain_free(domain
, virq
, i
- 1);
2966 its_lpi_free(bitmap
, base
, nr_ids
);
2967 its_free_prop_table(vprop_page
);
2973 static int its_vpe_irq_domain_activate(struct irq_domain
*domain
,
2974 struct irq_data
*d
, bool reserve
)
2976 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
2977 struct its_node
*its
;
2979 /* If we use the list map, we issue VMAPP on demand... */
2983 /* Map the VPE to the first possible CPU */
2984 vpe
->col_idx
= cpumask_first(cpu_online_mask
);
2986 list_for_each_entry(its
, &its_nodes
, entry
) {
2990 its_send_vmapp(its
, vpe
, true);
2991 its_send_vinvall(its
, vpe
);
2994 irq_data_update_effective_affinity(d
, cpumask_of(vpe
->col_idx
));
2999 static void its_vpe_irq_domain_deactivate(struct irq_domain
*domain
,
3002 struct its_vpe
*vpe
= irq_data_get_irq_chip_data(d
);
3003 struct its_node
*its
;
3006 * If we use the list map, we unmap the VPE once no VLPIs are
3007 * associated with the VM.
3012 list_for_each_entry(its
, &its_nodes
, entry
) {
3016 its_send_vmapp(its
, vpe
, false);
3020 static const struct irq_domain_ops its_vpe_domain_ops
= {
3021 .alloc
= its_vpe_irq_domain_alloc
,
3022 .free
= its_vpe_irq_domain_free
,
3023 .activate
= its_vpe_irq_domain_activate
,
3024 .deactivate
= its_vpe_irq_domain_deactivate
,
3027 static int its_force_quiescent(void __iomem
*base
)
3029 u32 count
= 1000000; /* 1s */
3032 val
= readl_relaxed(base
+ GITS_CTLR
);
3034 * GIC architecture specification requires the ITS to be both
3035 * disabled and quiescent for writes to GITS_BASER<n> or
3036 * GITS_CBASER to not have UNPREDICTABLE results.
3038 if ((val
& GITS_CTLR_QUIESCENT
) && !(val
& GITS_CTLR_ENABLE
))
3041 /* Disable the generation of all interrupts to this ITS */
3042 val
&= ~(GITS_CTLR_ENABLE
| GITS_CTLR_ImDe
);
3043 writel_relaxed(val
, base
+ GITS_CTLR
);
3045 /* Poll GITS_CTLR and wait until ITS becomes quiescent */
3047 val
= readl_relaxed(base
+ GITS_CTLR
);
3048 if (val
& GITS_CTLR_QUIESCENT
)
3060 static bool __maybe_unused
its_enable_quirk_cavium_22375(void *data
)
3062 struct its_node
*its
= data
;
3064 /* erratum 22375: only alloc 8MB table size */
3065 its
->device_ids
= 0x14; /* 20 bits, 8MB */
3066 its
->flags
|= ITS_FLAGS_WORKAROUND_CAVIUM_22375
;
3071 static bool __maybe_unused
its_enable_quirk_cavium_23144(void *data
)
3073 struct its_node
*its
= data
;
3075 its
->flags
|= ITS_FLAGS_WORKAROUND_CAVIUM_23144
;
3080 static bool __maybe_unused
its_enable_quirk_qdf2400_e0065(void *data
)
3082 struct its_node
*its
= data
;
3084 /* On QDF2400, the size of the ITE is 16Bytes */
3090 static u64
its_irq_get_msi_base_pre_its(struct its_device
*its_dev
)
3092 struct its_node
*its
= its_dev
->its
;
3095 * The Socionext Synquacer SoC has a so-called 'pre-ITS',
3096 * which maps 32-bit writes targeted at a separate window of
3097 * size '4 << device_id_bits' onto writes to GITS_TRANSLATER
3098 * with device ID taken from bits [device_id_bits + 1:2] of
3099 * the window offset.
3101 return its
->pre_its_base
+ (its_dev
->device_id
<< 2);
3104 static bool __maybe_unused
its_enable_quirk_socionext_synquacer(void *data
)
3106 struct its_node
*its
= data
;
3107 u32 pre_its_window
[2];
3110 if (!fwnode_property_read_u32_array(its
->fwnode_handle
,
3111 "socionext,synquacer-pre-its",
3113 ARRAY_SIZE(pre_its_window
))) {
3115 its
->pre_its_base
= pre_its_window
[0];
3116 its
->get_msi_base
= its_irq_get_msi_base_pre_its
;
3118 ids
= ilog2(pre_its_window
[1]) - 2;
3119 if (its
->device_ids
> ids
)
3120 its
->device_ids
= ids
;
3122 /* the pre-ITS breaks isolation, so disable MSI remapping */
3123 its
->msi_domain_flags
&= ~IRQ_DOMAIN_FLAG_MSI_REMAP
;
3129 static bool __maybe_unused
its_enable_quirk_hip07_161600802(void *data
)
3131 struct its_node
*its
= data
;
3134 * Hip07 insists on using the wrong address for the VLPI
3135 * page. Trick it into doing the right thing...
3137 its
->vlpi_redist_offset
= SZ_128K
;
3141 static const struct gic_quirk its_quirks
[] = {
3142 #ifdef CONFIG_CAVIUM_ERRATUM_22375
3144 .desc
= "ITS: Cavium errata 22375, 24313",
3145 .iidr
= 0xa100034c, /* ThunderX pass 1.x */
3147 .init
= its_enable_quirk_cavium_22375
,
3150 #ifdef CONFIG_CAVIUM_ERRATUM_23144
3152 .desc
= "ITS: Cavium erratum 23144",
3153 .iidr
= 0xa100034c, /* ThunderX pass 1.x */
3155 .init
= its_enable_quirk_cavium_23144
,
3158 #ifdef CONFIG_QCOM_QDF2400_ERRATUM_0065
3160 .desc
= "ITS: QDF2400 erratum 0065",
3161 .iidr
= 0x00001070, /* QDF2400 ITS rev 1.x */
3163 .init
= its_enable_quirk_qdf2400_e0065
,
3166 #ifdef CONFIG_SOCIONEXT_SYNQUACER_PREITS
3169 * The Socionext Synquacer SoC incorporates ARM's own GIC-500
3170 * implementation, but with a 'pre-ITS' added that requires
3171 * special handling in software.
3173 .desc
= "ITS: Socionext Synquacer pre-ITS",
3176 .init
= its_enable_quirk_socionext_synquacer
,
3179 #ifdef CONFIG_HISILICON_ERRATUM_161600802
3181 .desc
= "ITS: Hip07 erratum 161600802",
3184 .init
= its_enable_quirk_hip07_161600802
,
3191 static void its_enable_quirks(struct its_node
*its
)
3193 u32 iidr
= readl_relaxed(its
->base
+ GITS_IIDR
);
3195 gic_enable_quirks(iidr
, its_quirks
, its
);
3198 static int its_save_disable(void)
3200 struct its_node
*its
;
3203 raw_spin_lock(&its_lock
);
3204 list_for_each_entry(its
, &its_nodes
, entry
) {
3207 if (!(its
->flags
& ITS_FLAGS_SAVE_SUSPEND_STATE
))
3211 its
->ctlr_save
= readl_relaxed(base
+ GITS_CTLR
);
3212 err
= its_force_quiescent(base
);
3214 pr_err("ITS@%pa: failed to quiesce: %d\n",
3215 &its
->phys_base
, err
);
3216 writel_relaxed(its
->ctlr_save
, base
+ GITS_CTLR
);
3220 its
->cbaser_save
= gits_read_cbaser(base
+ GITS_CBASER
);
3225 list_for_each_entry_continue_reverse(its
, &its_nodes
, entry
) {
3228 if (!(its
->flags
& ITS_FLAGS_SAVE_SUSPEND_STATE
))
3232 writel_relaxed(its
->ctlr_save
, base
+ GITS_CTLR
);
3235 raw_spin_unlock(&its_lock
);
3240 static void its_restore_enable(void)
3242 struct its_node
*its
;
3245 raw_spin_lock(&its_lock
);
3246 list_for_each_entry(its
, &its_nodes
, entry
) {
3250 if (!(its
->flags
& ITS_FLAGS_SAVE_SUSPEND_STATE
))
3256 * Make sure that the ITS is disabled. If it fails to quiesce,
3257 * don't restore it since writing to CBASER or BASER<n>
3258 * registers is undefined according to the GIC v3 ITS
3261 ret
= its_force_quiescent(base
);
3263 pr_err("ITS@%pa: failed to quiesce on resume: %d\n",
3264 &its
->phys_base
, ret
);
3268 gits_write_cbaser(its
->cbaser_save
, base
+ GITS_CBASER
);
3271 * Writing CBASER resets CREADR to 0, so make CWRITER and
3272 * cmd_write line up with it.
3274 its
->cmd_write
= its
->cmd_base
;
3275 gits_write_cwriter(0, base
+ GITS_CWRITER
);
3277 /* Restore GITS_BASER from the value cache. */
3278 for (i
= 0; i
< GITS_BASER_NR_REGS
; i
++) {
3279 struct its_baser
*baser
= &its
->tables
[i
];
3281 if (!(baser
->val
& GITS_BASER_VALID
))
3284 its_write_baser(its
, baser
, baser
->val
);
3286 writel_relaxed(its
->ctlr_save
, base
+ GITS_CTLR
);
3289 * Reinit the collection if it's stored in the ITS. This is
3290 * indicated by the col_id being less than the HCC field.
3291 * CID < HCC as specified in the GIC v3 Documentation.
3293 if (its
->collections
[smp_processor_id()].col_id
<
3294 GITS_TYPER_HCC(gic_read_typer(base
+ GITS_TYPER
)))
3295 its_cpu_init_collection(its
);
3297 raw_spin_unlock(&its_lock
);
3300 static struct syscore_ops its_syscore_ops
= {
3301 .suspend
= its_save_disable
,
3302 .resume
= its_restore_enable
,
3305 static int its_init_domain(struct fwnode_handle
*handle
, struct its_node
*its
)
3307 struct irq_domain
*inner_domain
;
3308 struct msi_domain_info
*info
;
3310 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
3314 inner_domain
= irq_domain_create_tree(handle
, &its_domain_ops
, its
);
3315 if (!inner_domain
) {
3320 inner_domain
->parent
= its_parent
;
3321 irq_domain_update_bus_token(inner_domain
, DOMAIN_BUS_NEXUS
);
3322 inner_domain
->flags
|= its
->msi_domain_flags
;
3323 info
->ops
= &its_msi_domain_ops
;
3325 inner_domain
->host_data
= info
;
3330 static int its_init_vpe_domain(void)
3332 struct its_node
*its
;
3336 if (gic_rdists
->has_direct_lpi
) {
3337 pr_info("ITS: Using DirectLPI for VPE invalidation\n");
3341 /* Any ITS will do, even if not v4 */
3342 its
= list_first_entry(&its_nodes
, struct its_node
, entry
);
3344 entries
= roundup_pow_of_two(nr_cpu_ids
);
3345 vpe_proxy
.vpes
= kcalloc(entries
, sizeof(*vpe_proxy
.vpes
),
3347 if (!vpe_proxy
.vpes
) {
3348 pr_err("ITS: Can't allocate GICv4 proxy device array\n");
3352 /* Use the last possible DevID */
3353 devid
= GENMASK(its
->device_ids
- 1, 0);
3354 vpe_proxy
.dev
= its_create_device(its
, devid
, entries
, false);
3355 if (!vpe_proxy
.dev
) {
3356 kfree(vpe_proxy
.vpes
);
3357 pr_err("ITS: Can't allocate GICv4 proxy device\n");
3361 BUG_ON(entries
> vpe_proxy
.dev
->nr_ites
);
3363 raw_spin_lock_init(&vpe_proxy
.lock
);
3364 vpe_proxy
.next_victim
= 0;
3365 pr_info("ITS: Allocated DevID %x as GICv4 proxy device (%d slots)\n",
3366 devid
, vpe_proxy
.dev
->nr_ites
);
3371 static int __init
its_compute_its_list_map(struct resource
*res
,
3372 void __iomem
*its_base
)
3378 * This is assumed to be done early enough that we're
3379 * guaranteed to be single-threaded, hence no
3380 * locking. Should this change, we should address
3383 its_number
= find_first_zero_bit(&its_list_map
, GICv4_ITS_LIST_MAX
);
3384 if (its_number
>= GICv4_ITS_LIST_MAX
) {
3385 pr_err("ITS@%pa: No ITSList entry available!\n",
3390 ctlr
= readl_relaxed(its_base
+ GITS_CTLR
);
3391 ctlr
&= ~GITS_CTLR_ITS_NUMBER
;
3392 ctlr
|= its_number
<< GITS_CTLR_ITS_NUMBER_SHIFT
;
3393 writel_relaxed(ctlr
, its_base
+ GITS_CTLR
);
3394 ctlr
= readl_relaxed(its_base
+ GITS_CTLR
);
3395 if ((ctlr
& GITS_CTLR_ITS_NUMBER
) != (its_number
<< GITS_CTLR_ITS_NUMBER_SHIFT
)) {
3396 its_number
= ctlr
& GITS_CTLR_ITS_NUMBER
;
3397 its_number
>>= GITS_CTLR_ITS_NUMBER_SHIFT
;
3400 if (test_and_set_bit(its_number
, &its_list_map
)) {
3401 pr_err("ITS@%pa: Duplicate ITSList entry %d\n",
3402 &res
->start
, its_number
);
3409 static int __init
its_probe_one(struct resource
*res
,
3410 struct fwnode_handle
*handle
, int numa_node
)
3412 struct its_node
*its
;
3413 void __iomem
*its_base
;
3415 u64 baser
, tmp
, typer
;
3418 its_base
= ioremap(res
->start
, resource_size(res
));
3420 pr_warn("ITS@%pa: Unable to map ITS registers\n", &res
->start
);
3424 val
= readl_relaxed(its_base
+ GITS_PIDR2
) & GIC_PIDR2_ARCH_MASK
;
3425 if (val
!= 0x30 && val
!= 0x40) {
3426 pr_warn("ITS@%pa: No ITS detected, giving up\n", &res
->start
);
3431 err
= its_force_quiescent(its_base
);
3433 pr_warn("ITS@%pa: Failed to quiesce, giving up\n", &res
->start
);
3437 pr_info("ITS %pR\n", res
);
3439 its
= kzalloc(sizeof(*its
), GFP_KERNEL
);
3445 raw_spin_lock_init(&its
->lock
);
3446 mutex_init(&its
->dev_alloc_lock
);
3447 INIT_LIST_HEAD(&its
->entry
);
3448 INIT_LIST_HEAD(&its
->its_device_list
);
3449 typer
= gic_read_typer(its_base
+ GITS_TYPER
);
3450 its
->base
= its_base
;
3451 its
->phys_base
= res
->start
;
3452 its
->ite_size
= GITS_TYPER_ITT_ENTRY_SIZE(typer
);
3453 its
->device_ids
= GITS_TYPER_DEVBITS(typer
);
3454 its
->is_v4
= !!(typer
& GITS_TYPER_VLPIS
);
3456 if (!(typer
& GITS_TYPER_VMOVP
)) {
3457 err
= its_compute_its_list_map(res
, its_base
);
3463 pr_info("ITS@%pa: Using ITS number %d\n",
3466 pr_info("ITS@%pa: Single VMOVP capable\n", &res
->start
);
3470 its
->numa_node
= numa_node
;
3472 its
->cmd_base
= (void *)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
3473 get_order(ITS_CMD_QUEUE_SZ
));
3474 if (!its
->cmd_base
) {
3478 its
->cmd_write
= its
->cmd_base
;
3479 its
->fwnode_handle
= handle
;
3480 its
->get_msi_base
= its_irq_get_msi_base
;
3481 its
->msi_domain_flags
= IRQ_DOMAIN_FLAG_MSI_REMAP
;
3483 its_enable_quirks(its
);
3485 err
= its_alloc_tables(its
);
3489 err
= its_alloc_collections(its
);
3491 goto out_free_tables
;
3493 baser
= (virt_to_phys(its
->cmd_base
) |
3494 GITS_CBASER_RaWaWb
|
3495 GITS_CBASER_InnerShareable
|
3496 (ITS_CMD_QUEUE_SZ
/ SZ_4K
- 1) |
3499 gits_write_cbaser(baser
, its
->base
+ GITS_CBASER
);
3500 tmp
= gits_read_cbaser(its
->base
+ GITS_CBASER
);
3502 if ((tmp
^ baser
) & GITS_CBASER_SHAREABILITY_MASK
) {
3503 if (!(tmp
& GITS_CBASER_SHAREABILITY_MASK
)) {
3505 * The HW reports non-shareable, we must
3506 * remove the cacheability attributes as
3509 baser
&= ~(GITS_CBASER_SHAREABILITY_MASK
|
3510 GITS_CBASER_CACHEABILITY_MASK
);
3511 baser
|= GITS_CBASER_nC
;
3512 gits_write_cbaser(baser
, its
->base
+ GITS_CBASER
);
3514 pr_info("ITS: using cache flushing for cmd queue\n");
3515 its
->flags
|= ITS_FLAGS_CMDQ_NEEDS_FLUSHING
;
3518 gits_write_cwriter(0, its
->base
+ GITS_CWRITER
);
3519 ctlr
= readl_relaxed(its
->base
+ GITS_CTLR
);
3520 ctlr
|= GITS_CTLR_ENABLE
;
3522 ctlr
|= GITS_CTLR_ImDe
;
3523 writel_relaxed(ctlr
, its
->base
+ GITS_CTLR
);
3525 if (GITS_TYPER_HCC(typer
))
3526 its
->flags
|= ITS_FLAGS_SAVE_SUSPEND_STATE
;
3528 err
= its_init_domain(handle
, its
);
3530 goto out_free_tables
;
3532 raw_spin_lock(&its_lock
);
3533 list_add(&its
->entry
, &its_nodes
);
3534 raw_spin_unlock(&its_lock
);
3539 its_free_tables(its
);
3541 free_pages((unsigned long)its
->cmd_base
, get_order(ITS_CMD_QUEUE_SZ
));
3546 pr_err("ITS@%pa: failed probing (%d)\n", &res
->start
, err
);
3550 static bool gic_rdists_supports_plpis(void)
3552 return !!(gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER
) & GICR_TYPER_PLPIS
);
3555 static int redist_disable_lpis(void)
3557 void __iomem
*rbase
= gic_data_rdist_rd_base();
3558 u64 timeout
= USEC_PER_SEC
;
3562 * If coming via a CPU hotplug event, we don't need to disable
3563 * LPIs before trying to re-enable them. They are already
3564 * configured and all is well in the world. Detect this case
3565 * by checking the allocation of the pending table for the
3568 if (gic_data_rdist()->pend_page
)
3571 if (!gic_rdists_supports_plpis()) {
3572 pr_info("CPU%d: LPIs not supported\n", smp_processor_id());
3576 val
= readl_relaxed(rbase
+ GICR_CTLR
);
3577 if (!(val
& GICR_CTLR_ENABLE_LPIS
))
3580 pr_warn("CPU%d: Booted with LPIs enabled, memory probably corrupted\n",
3581 smp_processor_id());
3582 add_taint(TAINT_CRAP
, LOCKDEP_STILL_OK
);
3585 val
&= ~GICR_CTLR_ENABLE_LPIS
;
3586 writel_relaxed(val
, rbase
+ GICR_CTLR
);
3588 /* Make sure any change to GICR_CTLR is observable by the GIC */
3592 * Software must observe RWP==0 after clearing GICR_CTLR.EnableLPIs
3593 * from 1 to 0 before programming GICR_PEND{PROP}BASER registers.
3594 * Error out if we time out waiting for RWP to clear.
3596 while (readl_relaxed(rbase
+ GICR_CTLR
) & GICR_CTLR_RWP
) {
3598 pr_err("CPU%d: Timeout while disabling LPIs\n",
3599 smp_processor_id());
3607 * After it has been written to 1, it is IMPLEMENTATION
3608 * DEFINED whether GICR_CTLR.EnableLPI becomes RES1 or can be
3609 * cleared to 0. Error out if clearing the bit failed.
3611 if (readl_relaxed(rbase
+ GICR_CTLR
) & GICR_CTLR_ENABLE_LPIS
) {
3612 pr_err("CPU%d: Failed to disable LPIs\n", smp_processor_id());
3619 int its_cpu_init(void)
3621 if (!list_empty(&its_nodes
)) {
3624 ret
= redist_disable_lpis();
3628 its_cpu_init_lpis();
3629 its_cpu_init_collections();
3635 static const struct of_device_id its_device_id
[] = {
3636 { .compatible
= "arm,gic-v3-its", },
3640 static int __init
its_of_probe(struct device_node
*node
)
3642 struct device_node
*np
;
3643 struct resource res
;
3645 for (np
= of_find_matching_node(node
, its_device_id
); np
;
3646 np
= of_find_matching_node(np
, its_device_id
)) {
3647 if (!of_device_is_available(np
))
3649 if (!of_property_read_bool(np
, "msi-controller")) {
3650 pr_warn("%pOF: no msi-controller property, ITS ignored\n",
3655 if (of_address_to_resource(np
, 0, &res
)) {
3656 pr_warn("%pOF: no regs?\n", np
);
3660 its_probe_one(&res
, &np
->fwnode
, of_node_to_nid(np
));
3667 #define ACPI_GICV3_ITS_MEM_SIZE (SZ_128K)
3669 #ifdef CONFIG_ACPI_NUMA
3670 struct its_srat_map
{
3677 static struct its_srat_map
*its_srat_maps __initdata
;
3678 static int its_in_srat __initdata
;
3680 static int __init
acpi_get_its_numa_node(u32 its_id
)
3684 for (i
= 0; i
< its_in_srat
; i
++) {
3685 if (its_id
== its_srat_maps
[i
].its_id
)
3686 return its_srat_maps
[i
].numa_node
;
3688 return NUMA_NO_NODE
;
3691 static int __init
gic_acpi_match_srat_its(struct acpi_subtable_header
*header
,
3692 const unsigned long end
)
3697 static int __init
gic_acpi_parse_srat_its(struct acpi_subtable_header
*header
,
3698 const unsigned long end
)
3701 struct acpi_srat_gic_its_affinity
*its_affinity
;
3703 its_affinity
= (struct acpi_srat_gic_its_affinity
*)header
;
3707 if (its_affinity
->header
.length
< sizeof(*its_affinity
)) {
3708 pr_err("SRAT: Invalid header length %d in ITS affinity\n",
3709 its_affinity
->header
.length
);
3713 node
= acpi_map_pxm_to_node(its_affinity
->proximity_domain
);
3715 if (node
== NUMA_NO_NODE
|| node
>= MAX_NUMNODES
) {
3716 pr_err("SRAT: Invalid NUMA node %d in ITS affinity\n", node
);
3720 its_srat_maps
[its_in_srat
].numa_node
= node
;
3721 its_srat_maps
[its_in_srat
].its_id
= its_affinity
->its_id
;
3723 pr_info("SRAT: PXM %d -> ITS %d -> Node %d\n",
3724 its_affinity
->proximity_domain
, its_affinity
->its_id
, node
);
3729 static void __init
acpi_table_parse_srat_its(void)
3733 count
= acpi_table_parse_entries(ACPI_SIG_SRAT
,
3734 sizeof(struct acpi_table_srat
),
3735 ACPI_SRAT_TYPE_GIC_ITS_AFFINITY
,
3736 gic_acpi_match_srat_its
, 0);
3740 its_srat_maps
= kmalloc_array(count
, sizeof(struct its_srat_map
),
3742 if (!its_srat_maps
) {
3743 pr_warn("SRAT: Failed to allocate memory for its_srat_maps!\n");
3747 acpi_table_parse_entries(ACPI_SIG_SRAT
,
3748 sizeof(struct acpi_table_srat
),
3749 ACPI_SRAT_TYPE_GIC_ITS_AFFINITY
,
3750 gic_acpi_parse_srat_its
, 0);
3753 /* free the its_srat_maps after ITS probing */
3754 static void __init
acpi_its_srat_maps_free(void)
3756 kfree(its_srat_maps
);
3759 static void __init
acpi_table_parse_srat_its(void) { }
3760 static int __init
acpi_get_its_numa_node(u32 its_id
) { return NUMA_NO_NODE
; }
3761 static void __init
acpi_its_srat_maps_free(void) { }
3764 static int __init
gic_acpi_parse_madt_its(struct acpi_subtable_header
*header
,
3765 const unsigned long end
)
3767 struct acpi_madt_generic_translator
*its_entry
;
3768 struct fwnode_handle
*dom_handle
;
3769 struct resource res
;
3772 its_entry
= (struct acpi_madt_generic_translator
*)header
;
3773 memset(&res
, 0, sizeof(res
));
3774 res
.start
= its_entry
->base_address
;
3775 res
.end
= its_entry
->base_address
+ ACPI_GICV3_ITS_MEM_SIZE
- 1;
3776 res
.flags
= IORESOURCE_MEM
;
3778 dom_handle
= irq_domain_alloc_fwnode((void *)its_entry
->base_address
);
3780 pr_err("ITS@%pa: Unable to allocate GICv3 ITS domain token\n",
3785 err
= iort_register_domain_token(its_entry
->translation_id
, res
.start
,
3788 pr_err("ITS@%pa: Unable to register GICv3 ITS domain token (ITS ID %d) to IORT\n",
3789 &res
.start
, its_entry
->translation_id
);
3793 err
= its_probe_one(&res
, dom_handle
,
3794 acpi_get_its_numa_node(its_entry
->translation_id
));
3798 iort_deregister_domain_token(its_entry
->translation_id
);
3800 irq_domain_free_fwnode(dom_handle
);
3804 static void __init
its_acpi_probe(void)
3806 acpi_table_parse_srat_its();
3807 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR
,
3808 gic_acpi_parse_madt_its
, 0);
3809 acpi_its_srat_maps_free();
3812 static void __init
its_acpi_probe(void) { }
3815 int __init
its_init(struct fwnode_handle
*handle
, struct rdists
*rdists
,
3816 struct irq_domain
*parent_domain
)
3818 struct device_node
*of_node
;
3819 struct its_node
*its
;
3820 bool has_v4
= false;
3823 its_parent
= parent_domain
;
3824 of_node
= to_of_node(handle
);
3826 its_of_probe(of_node
);
3830 if (list_empty(&its_nodes
)) {
3831 pr_warn("ITS: No ITS available, not enabling LPIs\n");
3835 gic_rdists
= rdists
;
3836 err
= its_alloc_lpi_tables();
3840 list_for_each_entry(its
, &its_nodes
, entry
)
3841 has_v4
|= its
->is_v4
;
3843 if (has_v4
& rdists
->has_vlpis
) {
3844 if (its_init_vpe_domain() ||
3845 its_init_v4(parent_domain
, &its_vpe_domain_ops
)) {
3846 rdists
->has_vlpis
= false;
3847 pr_err("ITS: Disabling GICv4 support\n");
3851 register_syscore_ops(&its_syscore_ops
);