19ed24f4bSMarc Zyngier /* SPDX-License-Identifier: GPL-2.0-only */ 29ed24f4bSMarc Zyngier /* 39ed24f4bSMarc Zyngier * Copyright (C) 2015, 2016 ARM Ltd. 49ed24f4bSMarc Zyngier */ 59ed24f4bSMarc Zyngier #ifndef __KVM_ARM_VGIC_NEW_H__ 69ed24f4bSMarc Zyngier #define __KVM_ARM_VGIC_NEW_H__ 79ed24f4bSMarc Zyngier 89ed24f4bSMarc Zyngier #include <linux/irqchip/arm-gic-common.h> 99ed24f4bSMarc Zyngier 109ed24f4bSMarc Zyngier #define PRODUCT_ID_KVM 0x4b /* ASCII code K */ 119ed24f4bSMarc Zyngier #define IMPLEMENTER_ARM 0x43b 129ed24f4bSMarc Zyngier 139ed24f4bSMarc Zyngier #define VGIC_ADDR_UNDEF (-1) 149ed24f4bSMarc Zyngier #define IS_VGIC_ADDR_UNDEF(_x) ((_x) == VGIC_ADDR_UNDEF) 159ed24f4bSMarc Zyngier 169ed24f4bSMarc Zyngier #define INTERRUPT_ID_BITS_SPIS 10 179ed24f4bSMarc Zyngier #define INTERRUPT_ID_BITS_ITS 16 189ed24f4bSMarc Zyngier #define VGIC_PRI_BITS 5 199ed24f4bSMarc Zyngier 209ed24f4bSMarc Zyngier #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) 219ed24f4bSMarc Zyngier 229ed24f4bSMarc Zyngier #define VGIC_AFFINITY_0_SHIFT 0 239ed24f4bSMarc Zyngier #define VGIC_AFFINITY_0_MASK (0xffUL << VGIC_AFFINITY_0_SHIFT) 249ed24f4bSMarc Zyngier #define VGIC_AFFINITY_1_SHIFT 8 259ed24f4bSMarc Zyngier #define VGIC_AFFINITY_1_MASK (0xffUL << VGIC_AFFINITY_1_SHIFT) 269ed24f4bSMarc Zyngier #define VGIC_AFFINITY_2_SHIFT 16 279ed24f4bSMarc Zyngier #define VGIC_AFFINITY_2_MASK (0xffUL << VGIC_AFFINITY_2_SHIFT) 289ed24f4bSMarc Zyngier #define VGIC_AFFINITY_3_SHIFT 24 299ed24f4bSMarc Zyngier #define VGIC_AFFINITY_3_MASK (0xffUL << VGIC_AFFINITY_3_SHIFT) 309ed24f4bSMarc Zyngier 319ed24f4bSMarc Zyngier #define VGIC_AFFINITY_LEVEL(reg, level) \ 329ed24f4bSMarc Zyngier ((((reg) & VGIC_AFFINITY_## level ##_MASK) \ 339ed24f4bSMarc Zyngier >> VGIC_AFFINITY_## level ##_SHIFT) << MPIDR_LEVEL_SHIFT(level)) 349ed24f4bSMarc Zyngier 359ed24f4bSMarc Zyngier /* 369ed24f4bSMarc Zyngier * The Userspace encodes the affinity differently from the MPIDR, 379ed24f4bSMarc Zyngier * Below macro converts vgic userspace format to MPIDR reg format. 389ed24f4bSMarc Zyngier */ 399ed24f4bSMarc Zyngier #define VGIC_TO_MPIDR(val) (VGIC_AFFINITY_LEVEL(val, 0) | \ 409ed24f4bSMarc Zyngier VGIC_AFFINITY_LEVEL(val, 1) | \ 419ed24f4bSMarc Zyngier VGIC_AFFINITY_LEVEL(val, 2) | \ 429ed24f4bSMarc Zyngier VGIC_AFFINITY_LEVEL(val, 3)) 439ed24f4bSMarc Zyngier 449ed24f4bSMarc Zyngier /* 45039aeb9dSLinus Torvalds * As per Documentation/virt/kvm/devices/arm-vgic-v3.rst, 469ed24f4bSMarc Zyngier * below macros are defined for CPUREG encoding. 479ed24f4bSMarc Zyngier */ 489ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP0_MASK 0x000000000000c000 499ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP0_SHIFT 14 509ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP1_MASK 0x0000000000003800 519ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP1_SHIFT 11 529ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_CRN_MASK 0x0000000000000780 539ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_CRN_SHIFT 7 549ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_CRM_MASK 0x0000000000000078 559ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_CRM_SHIFT 3 569ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP2_MASK 0x0000000000000007 579ed24f4bSMarc Zyngier #define KVM_REG_ARM_VGIC_SYSREG_OP2_SHIFT 0 589ed24f4bSMarc Zyngier 599ed24f4bSMarc Zyngier #define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM_VGIC_SYSREG_OP0_MASK | \ 609ed24f4bSMarc Zyngier KVM_REG_ARM_VGIC_SYSREG_OP1_MASK | \ 619ed24f4bSMarc Zyngier KVM_REG_ARM_VGIC_SYSREG_CRN_MASK | \ 629ed24f4bSMarc Zyngier KVM_REG_ARM_VGIC_SYSREG_CRM_MASK | \ 639ed24f4bSMarc Zyngier KVM_REG_ARM_VGIC_SYSREG_OP2_MASK) 649ed24f4bSMarc Zyngier 659ed24f4bSMarc Zyngier /* 66039aeb9dSLinus Torvalds * As per Documentation/virt/kvm/devices/arm-vgic-its.rst, 679ed24f4bSMarc Zyngier * below macros are defined for ITS table entry encoding. 689ed24f4bSMarc Zyngier */ 699ed24f4bSMarc Zyngier #define KVM_ITS_CTE_VALID_SHIFT 63 709ed24f4bSMarc Zyngier #define KVM_ITS_CTE_VALID_MASK BIT_ULL(63) 719ed24f4bSMarc Zyngier #define KVM_ITS_CTE_RDBASE_SHIFT 16 729ed24f4bSMarc Zyngier #define KVM_ITS_CTE_ICID_MASK GENMASK_ULL(15, 0) 739ed24f4bSMarc Zyngier #define KVM_ITS_ITE_NEXT_SHIFT 48 749ed24f4bSMarc Zyngier #define KVM_ITS_ITE_PINTID_SHIFT 16 759ed24f4bSMarc Zyngier #define KVM_ITS_ITE_PINTID_MASK GENMASK_ULL(47, 16) 769ed24f4bSMarc Zyngier #define KVM_ITS_ITE_ICID_MASK GENMASK_ULL(15, 0) 779ed24f4bSMarc Zyngier #define KVM_ITS_DTE_VALID_SHIFT 63 789ed24f4bSMarc Zyngier #define KVM_ITS_DTE_VALID_MASK BIT_ULL(63) 799ed24f4bSMarc Zyngier #define KVM_ITS_DTE_NEXT_SHIFT 49 809ed24f4bSMarc Zyngier #define KVM_ITS_DTE_NEXT_MASK GENMASK_ULL(62, 49) 819ed24f4bSMarc Zyngier #define KVM_ITS_DTE_ITTADDR_SHIFT 5 829ed24f4bSMarc Zyngier #define KVM_ITS_DTE_ITTADDR_MASK GENMASK_ULL(48, 5) 839ed24f4bSMarc Zyngier #define KVM_ITS_DTE_SIZE_MASK GENMASK_ULL(4, 0) 849ed24f4bSMarc Zyngier #define KVM_ITS_L1E_VALID_MASK BIT_ULL(63) 859ed24f4bSMarc Zyngier /* we only support 64 kB translation table page size */ 869ed24f4bSMarc Zyngier #define KVM_ITS_L1E_ADDR_MASK GENMASK_ULL(51, 16) 879ed24f4bSMarc Zyngier 889ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_INDEX_MASK GENMASK_ULL(11, 0) 899ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_FLAGS_MASK GENMASK_ULL(15, 12) 909ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_FLAGS_SHIFT 12 919ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_BASE_MASK GENMASK_ULL(51, 16) 929ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_COUNT_MASK GENMASK_ULL(63, 52) 939ed24f4bSMarc Zyngier #define KVM_VGIC_V3_RDIST_COUNT_SHIFT 52 949ed24f4bSMarc Zyngier 959ed24f4bSMarc Zyngier #ifdef CONFIG_DEBUG_SPINLOCK 969ed24f4bSMarc Zyngier #define DEBUG_SPINLOCK_BUG_ON(p) BUG_ON(p) 979ed24f4bSMarc Zyngier #else 989ed24f4bSMarc Zyngier #define DEBUG_SPINLOCK_BUG_ON(p) 999ed24f4bSMarc Zyngier #endif 1009ed24f4bSMarc Zyngier 1019ed24f4bSMarc Zyngier /* Requires the irq_lock to be held by the caller. */ 1029ed24f4bSMarc Zyngier static inline bool irq_is_pending(struct vgic_irq *irq) 1039ed24f4bSMarc Zyngier { 1049ed24f4bSMarc Zyngier if (irq->config == VGIC_CONFIG_EDGE) 1059ed24f4bSMarc Zyngier return irq->pending_latch; 1069ed24f4bSMarc Zyngier else 1079ed24f4bSMarc Zyngier return irq->pending_latch || irq->line_level; 1089ed24f4bSMarc Zyngier } 1099ed24f4bSMarc Zyngier 1109ed24f4bSMarc Zyngier static inline bool vgic_irq_is_mapped_level(struct vgic_irq *irq) 1119ed24f4bSMarc Zyngier { 1129ed24f4bSMarc Zyngier return irq->config == VGIC_CONFIG_LEVEL && irq->hw; 1139ed24f4bSMarc Zyngier } 1149ed24f4bSMarc Zyngier 1159ed24f4bSMarc Zyngier static inline int vgic_irq_get_lr_count(struct vgic_irq *irq) 1169ed24f4bSMarc Zyngier { 1179ed24f4bSMarc Zyngier /* Account for the active state as an interrupt */ 1189ed24f4bSMarc Zyngier if (vgic_irq_is_sgi(irq->intid) && irq->source) 1199ed24f4bSMarc Zyngier return hweight8(irq->source) + irq->active; 1209ed24f4bSMarc Zyngier 1219ed24f4bSMarc Zyngier return irq_is_pending(irq) || irq->active; 1229ed24f4bSMarc Zyngier } 1239ed24f4bSMarc Zyngier 1249ed24f4bSMarc Zyngier static inline bool vgic_irq_is_multi_sgi(struct vgic_irq *irq) 1259ed24f4bSMarc Zyngier { 1269ed24f4bSMarc Zyngier return vgic_irq_get_lr_count(irq) > 1; 1279ed24f4bSMarc Zyngier } 1289ed24f4bSMarc Zyngier 1299ed24f4bSMarc Zyngier /* 1309ed24f4bSMarc Zyngier * This struct provides an intermediate representation of the fields contained 1319ed24f4bSMarc Zyngier * in the GICH_VMCR and ICH_VMCR registers, such that code exporting the GIC 1329ed24f4bSMarc Zyngier * state to userspace can generate either GICv2 or GICv3 CPU interface 1339ed24f4bSMarc Zyngier * registers regardless of the hardware backed GIC used. 1349ed24f4bSMarc Zyngier */ 1359ed24f4bSMarc Zyngier struct vgic_vmcr { 1369ed24f4bSMarc Zyngier u32 grpen0; 1379ed24f4bSMarc Zyngier u32 grpen1; 1389ed24f4bSMarc Zyngier 1399ed24f4bSMarc Zyngier u32 ackctl; 1409ed24f4bSMarc Zyngier u32 fiqen; 1419ed24f4bSMarc Zyngier u32 cbpr; 1429ed24f4bSMarc Zyngier u32 eoim; 1439ed24f4bSMarc Zyngier 1449ed24f4bSMarc Zyngier u32 abpr; 1459ed24f4bSMarc Zyngier u32 bpr; 1469ed24f4bSMarc Zyngier u32 pmr; /* Priority mask field in the GICC_PMR and 1479ed24f4bSMarc Zyngier * ICC_PMR_EL1 priority field format */ 1489ed24f4bSMarc Zyngier }; 1499ed24f4bSMarc Zyngier 1509ed24f4bSMarc Zyngier struct vgic_reg_attr { 1519ed24f4bSMarc Zyngier struct kvm_vcpu *vcpu; 1529ed24f4bSMarc Zyngier gpa_t addr; 1539ed24f4bSMarc Zyngier }; 1549ed24f4bSMarc Zyngier 1559ed24f4bSMarc Zyngier int vgic_v3_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr, 1569ed24f4bSMarc Zyngier struct vgic_reg_attr *reg_attr); 1579ed24f4bSMarc Zyngier int vgic_v2_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr, 1589ed24f4bSMarc Zyngier struct vgic_reg_attr *reg_attr); 1599ed24f4bSMarc Zyngier const struct vgic_register_region * 1609ed24f4bSMarc Zyngier vgic_get_mmio_region(struct kvm_vcpu *vcpu, struct vgic_io_device *iodev, 1619ed24f4bSMarc Zyngier gpa_t addr, int len); 1629ed24f4bSMarc Zyngier struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, 1639ed24f4bSMarc Zyngier u32 intid); 1649ed24f4bSMarc Zyngier void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq); 1659ed24f4bSMarc Zyngier void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq); 1669ed24f4bSMarc Zyngier bool vgic_get_phys_line_level(struct vgic_irq *irq); 1679ed24f4bSMarc Zyngier void vgic_irq_set_phys_pending(struct vgic_irq *irq, bool pending); 1689ed24f4bSMarc Zyngier void vgic_irq_set_phys_active(struct vgic_irq *irq, bool active); 1699ed24f4bSMarc Zyngier bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq, 1709ed24f4bSMarc Zyngier unsigned long flags); 1719ed24f4bSMarc Zyngier void vgic_kick_vcpus(struct kvm *kvm); 1729ed24f4bSMarc Zyngier 1739ed24f4bSMarc Zyngier int vgic_check_ioaddr(struct kvm *kvm, phys_addr_t *ioaddr, 1749ed24f4bSMarc Zyngier phys_addr_t addr, phys_addr_t alignment); 1759ed24f4bSMarc Zyngier 1769ed24f4bSMarc Zyngier void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu); 1779ed24f4bSMarc Zyngier void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); 1789ed24f4bSMarc Zyngier void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr); 1799ed24f4bSMarc Zyngier void vgic_v2_set_underflow(struct kvm_vcpu *vcpu); 1809ed24f4bSMarc Zyngier void vgic_v2_set_npie(struct kvm_vcpu *vcpu); 1819ed24f4bSMarc Zyngier int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr); 1829ed24f4bSMarc Zyngier int vgic_v2_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, 1839ed24f4bSMarc Zyngier int offset, u32 *val); 1849ed24f4bSMarc Zyngier int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write, 1859ed24f4bSMarc Zyngier int offset, u32 *val); 1869ed24f4bSMarc Zyngier void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 1879ed24f4bSMarc Zyngier void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 1889ed24f4bSMarc Zyngier void vgic_v2_enable(struct kvm_vcpu *vcpu); 1899ed24f4bSMarc Zyngier int vgic_v2_probe(const struct gic_kvm_info *info); 1909ed24f4bSMarc Zyngier int vgic_v2_map_resources(struct kvm *kvm); 1919ed24f4bSMarc Zyngier int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address, 1929ed24f4bSMarc Zyngier enum vgic_type); 1939ed24f4bSMarc Zyngier 1949ed24f4bSMarc Zyngier void vgic_v2_init_lrs(void); 1959ed24f4bSMarc Zyngier void vgic_v2_load(struct kvm_vcpu *vcpu); 1969ed24f4bSMarc Zyngier void vgic_v2_put(struct kvm_vcpu *vcpu); 1979ed24f4bSMarc Zyngier void vgic_v2_vmcr_sync(struct kvm_vcpu *vcpu); 1989ed24f4bSMarc Zyngier 1999ed24f4bSMarc Zyngier void vgic_v2_save_state(struct kvm_vcpu *vcpu); 2009ed24f4bSMarc Zyngier void vgic_v2_restore_state(struct kvm_vcpu *vcpu); 2019ed24f4bSMarc Zyngier 2029ed24f4bSMarc Zyngier static inline void vgic_get_irq_kref(struct vgic_irq *irq) 2039ed24f4bSMarc Zyngier { 2049ed24f4bSMarc Zyngier if (irq->intid < VGIC_MIN_LPI) 2059ed24f4bSMarc Zyngier return; 2069ed24f4bSMarc Zyngier 2079ed24f4bSMarc Zyngier kref_get(&irq->refcount); 2089ed24f4bSMarc Zyngier } 2099ed24f4bSMarc Zyngier 2109ed24f4bSMarc Zyngier void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu); 2119ed24f4bSMarc Zyngier void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr); 2129ed24f4bSMarc Zyngier void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr); 2139ed24f4bSMarc Zyngier void vgic_v3_set_underflow(struct kvm_vcpu *vcpu); 2149ed24f4bSMarc Zyngier void vgic_v3_set_npie(struct kvm_vcpu *vcpu); 2159ed24f4bSMarc Zyngier void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 2169ed24f4bSMarc Zyngier void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 2179ed24f4bSMarc Zyngier void vgic_v3_enable(struct kvm_vcpu *vcpu); 2189ed24f4bSMarc Zyngier int vgic_v3_probe(const struct gic_kvm_info *info); 2199ed24f4bSMarc Zyngier int vgic_v3_map_resources(struct kvm *kvm); 2209ed24f4bSMarc Zyngier int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq); 2219ed24f4bSMarc Zyngier int vgic_v3_save_pending_tables(struct kvm *kvm); 2229ed24f4bSMarc Zyngier int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count); 2239ed24f4bSMarc Zyngier int vgic_register_redist_iodev(struct kvm_vcpu *vcpu); 2249ed24f4bSMarc Zyngier bool vgic_v3_check_base(struct kvm *kvm); 2259ed24f4bSMarc Zyngier 2269ed24f4bSMarc Zyngier void vgic_v3_load(struct kvm_vcpu *vcpu); 2279ed24f4bSMarc Zyngier void vgic_v3_put(struct kvm_vcpu *vcpu); 2289ed24f4bSMarc Zyngier void vgic_v3_vmcr_sync(struct kvm_vcpu *vcpu); 2299ed24f4bSMarc Zyngier 2309ed24f4bSMarc Zyngier bool vgic_has_its(struct kvm *kvm); 2319ed24f4bSMarc Zyngier int kvm_vgic_register_its_device(void); 2329ed24f4bSMarc Zyngier void vgic_enable_lpis(struct kvm_vcpu *vcpu); 2339ed24f4bSMarc Zyngier void vgic_flush_pending_lpis(struct kvm_vcpu *vcpu); 2349ed24f4bSMarc Zyngier int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi); 2359ed24f4bSMarc Zyngier int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr); 2369ed24f4bSMarc Zyngier int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, 2379ed24f4bSMarc Zyngier int offset, u32 *val); 2389ed24f4bSMarc Zyngier int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write, 2399ed24f4bSMarc Zyngier int offset, u32 *val); 2409ed24f4bSMarc Zyngier int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write, 2419ed24f4bSMarc Zyngier u64 id, u64 *val); 2429ed24f4bSMarc Zyngier int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, bool is_write, u64 id, 2439ed24f4bSMarc Zyngier u64 *reg); 2449ed24f4bSMarc Zyngier int vgic_v3_line_level_info_uaccess(struct kvm_vcpu *vcpu, bool is_write, 2459ed24f4bSMarc Zyngier u32 intid, u64 *val); 2469ed24f4bSMarc Zyngier int kvm_register_vgic_device(unsigned long type); 2479ed24f4bSMarc Zyngier void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 2489ed24f4bSMarc Zyngier void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 2499ed24f4bSMarc Zyngier int vgic_lazy_init(struct kvm *kvm); 2509ed24f4bSMarc Zyngier int vgic_init(struct kvm *kvm); 2519ed24f4bSMarc Zyngier 2529ed24f4bSMarc Zyngier void vgic_debug_init(struct kvm *kvm); 2539ed24f4bSMarc Zyngier void vgic_debug_destroy(struct kvm *kvm); 2549ed24f4bSMarc Zyngier 2559ed24f4bSMarc Zyngier bool lock_all_vcpus(struct kvm *kvm); 2569ed24f4bSMarc Zyngier void unlock_all_vcpus(struct kvm *kvm); 2579ed24f4bSMarc Zyngier 2589ed24f4bSMarc Zyngier static inline int vgic_v3_max_apr_idx(struct kvm_vcpu *vcpu) 2599ed24f4bSMarc Zyngier { 2609ed24f4bSMarc Zyngier struct vgic_cpu *cpu_if = &vcpu->arch.vgic_cpu; 2619ed24f4bSMarc Zyngier 2629ed24f4bSMarc Zyngier /* 2639ed24f4bSMarc Zyngier * num_pri_bits are initialized with HW supported values. 2649ed24f4bSMarc Zyngier * We can rely safely on num_pri_bits even if VM has not 2659ed24f4bSMarc Zyngier * restored ICC_CTLR_EL1 before restoring APnR registers. 2669ed24f4bSMarc Zyngier */ 2679ed24f4bSMarc Zyngier switch (cpu_if->num_pri_bits) { 2689ed24f4bSMarc Zyngier case 7: return 3; 2699ed24f4bSMarc Zyngier case 6: return 1; 2709ed24f4bSMarc Zyngier default: return 0; 2719ed24f4bSMarc Zyngier } 2729ed24f4bSMarc Zyngier } 2739ed24f4bSMarc Zyngier 2749ed24f4bSMarc Zyngier static inline bool 2759ed24f4bSMarc Zyngier vgic_v3_redist_region_full(struct vgic_redist_region *region) 2769ed24f4bSMarc Zyngier { 2779ed24f4bSMarc Zyngier if (!region->count) 2789ed24f4bSMarc Zyngier return false; 2799ed24f4bSMarc Zyngier 2809ed24f4bSMarc Zyngier return (region->free_index >= region->count); 2819ed24f4bSMarc Zyngier } 2829ed24f4bSMarc Zyngier 2839ed24f4bSMarc Zyngier struct vgic_redist_region *vgic_v3_rdist_free_slot(struct list_head *rdregs); 2849ed24f4bSMarc Zyngier 2859ed24f4bSMarc Zyngier static inline size_t 2869ed24f4bSMarc Zyngier vgic_v3_rd_region_size(struct kvm *kvm, struct vgic_redist_region *rdreg) 2879ed24f4bSMarc Zyngier { 2889ed24f4bSMarc Zyngier if (!rdreg->count) 2899ed24f4bSMarc Zyngier return atomic_read(&kvm->online_vcpus) * KVM_VGIC_V3_REDIST_SIZE; 2909ed24f4bSMarc Zyngier else 2919ed24f4bSMarc Zyngier return rdreg->count * KVM_VGIC_V3_REDIST_SIZE; 2929ed24f4bSMarc Zyngier } 2939ed24f4bSMarc Zyngier 2949ed24f4bSMarc Zyngier struct vgic_redist_region *vgic_v3_rdist_region_from_index(struct kvm *kvm, 2959ed24f4bSMarc Zyngier u32 index); 296*e5a35635SEric Auger void vgic_v3_free_redist_region(struct vgic_redist_region *rdreg); 2979ed24f4bSMarc Zyngier 2989ed24f4bSMarc Zyngier bool vgic_v3_rdist_overlap(struct kvm *kvm, gpa_t base, size_t size); 2999ed24f4bSMarc Zyngier 3009ed24f4bSMarc Zyngier static inline bool vgic_dist_overlap(struct kvm *kvm, gpa_t base, size_t size) 3019ed24f4bSMarc Zyngier { 3029ed24f4bSMarc Zyngier struct vgic_dist *d = &kvm->arch.vgic; 3039ed24f4bSMarc Zyngier 3049ed24f4bSMarc Zyngier return (base + size > d->vgic_dist_base) && 3059ed24f4bSMarc Zyngier (base < d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE); 3069ed24f4bSMarc Zyngier } 3079ed24f4bSMarc Zyngier 3089ed24f4bSMarc Zyngier int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr); 3099ed24f4bSMarc Zyngier int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its, 3109ed24f4bSMarc Zyngier u32 devid, u32 eventid, struct vgic_irq **irq); 3119ed24f4bSMarc Zyngier struct vgic_its *vgic_msi_to_its(struct kvm *kvm, struct kvm_msi *msi); 3129ed24f4bSMarc Zyngier int vgic_its_inject_cached_translation(struct kvm *kvm, struct kvm_msi *msi); 3139ed24f4bSMarc Zyngier void vgic_lpi_translation_cache_init(struct kvm *kvm); 3149ed24f4bSMarc Zyngier void vgic_lpi_translation_cache_destroy(struct kvm *kvm); 3159ed24f4bSMarc Zyngier void vgic_its_invalidate_cache(struct kvm *kvm); 3169ed24f4bSMarc Zyngier 3179ed24f4bSMarc Zyngier bool vgic_supports_direct_msis(struct kvm *kvm); 3189ed24f4bSMarc Zyngier int vgic_v4_init(struct kvm *kvm); 3199ed24f4bSMarc Zyngier void vgic_v4_teardown(struct kvm *kvm); 3209ed24f4bSMarc Zyngier void vgic_v4_configure_vsgis(struct kvm *kvm); 3219ed24f4bSMarc Zyngier 3229ed24f4bSMarc Zyngier #endif 323