18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci============================================================== 48c2ecf20Sopenharmony_ciARM Virtual Generic Interrupt Controller v3 and later (VGICv3) 58c2ecf20Sopenharmony_ci============================================================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciDevice types supported: 98c2ecf20Sopenharmony_ci - KVM_DEV_TYPE_ARM_VGIC_V3 ARM Generic Interrupt Controller v3.0 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciOnly one VGIC instance may be instantiated through this API. The created VGIC 128c2ecf20Sopenharmony_ciwill act as the VM interrupt controller, requiring emulated user-space devices 138c2ecf20Sopenharmony_cito inject interrupts to the VGIC instead of directly to CPUs. It is not 148c2ecf20Sopenharmony_cipossible to create both a GICv3 and GICv2 on the same VM. 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciCreating a guest GICv3 device requires a host GICv3 as well. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciGroups: 208c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_ADDR 218c2ecf20Sopenharmony_ci Attributes: 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit) 248c2ecf20Sopenharmony_ci Base address in the guest physical address space of the GICv3 distributor 258c2ecf20Sopenharmony_ci register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 268c2ecf20Sopenharmony_ci This address needs to be 64K aligned and the region covers 64 KByte. 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit) 298c2ecf20Sopenharmony_ci Base address in the guest physical address space of the GICv3 308c2ecf20Sopenharmony_ci redistributor register mappings. There are two 64K pages for each 318c2ecf20Sopenharmony_ci VCPU and all of the redistributor pages are contiguous. 328c2ecf20Sopenharmony_ci Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 338c2ecf20Sopenharmony_ci This address needs to be 64K aligned. 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION (rw, 64-bit) 368c2ecf20Sopenharmony_ci The attribute data pointed to by kvm_device_attr.addr is a __u64 value:: 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci bits: | 63 .... 52 | 51 .... 16 | 15 - 12 |11 - 0 398c2ecf20Sopenharmony_ci values: | count | base | flags | index 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci - index encodes the unique redistributor region index 428c2ecf20Sopenharmony_ci - flags: reserved for future use, currently 0 438c2ecf20Sopenharmony_ci - base field encodes bits [51:16] of the guest physical base address 448c2ecf20Sopenharmony_ci of the first redistributor in the region. 458c2ecf20Sopenharmony_ci - count encodes the number of redistributors in the region. Must be 468c2ecf20Sopenharmony_ci greater than 0. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci There are two 64K pages for each redistributor in the region and 498c2ecf20Sopenharmony_ci redistributors are laid out contiguously within the region. Regions 508c2ecf20Sopenharmony_ci are filled with redistributors in the index order. The sum of all 518c2ecf20Sopenharmony_ci region count fields must be greater than or equal to the number of 528c2ecf20Sopenharmony_ci VCPUs. Redistributor regions must be registered in the incremental 538c2ecf20Sopenharmony_ci index order, starting from index 0. 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci The characteristics of a specific redistributor region can be read 568c2ecf20Sopenharmony_ci by presetting the index field in the attr data. 578c2ecf20Sopenharmony_ci Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci It is invalid to mix calls with KVM_VGIC_V3_ADDR_TYPE_REDIST and 608c2ecf20Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION attributes. 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci Errors: 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci ======= ============================================================= 658c2ecf20Sopenharmony_ci -E2BIG Address outside of addressable IPA range 668c2ecf20Sopenharmony_ci -EINVAL Incorrectly aligned address, bad redistributor region 678c2ecf20Sopenharmony_ci count/index, mixed redistributor region attribute usage 688c2ecf20Sopenharmony_ci -EEXIST Address already configured 698c2ecf20Sopenharmony_ci -ENOENT Attempt to read the characteristics of a non existing 708c2ecf20Sopenharmony_ci redistributor region 718c2ecf20Sopenharmony_ci -ENXIO The group or attribute is unknown/unsupported for this device 728c2ecf20Sopenharmony_ci or hardware support is missing. 738c2ecf20Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr. 748c2ecf20Sopenharmony_ci ======= ============================================================= 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 788c2ecf20Sopenharmony_ci Attributes: 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci bits: | 63 .... 32 | 31 .... 0 | 838c2ecf20Sopenharmony_ci values: | mpidr | offset | 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci All distributor regs are (rw, 32-bit) and kvm_device_attr.addr points to a 868c2ecf20Sopenharmony_ci __u32 value. 64-bit registers must be accessed by separately accessing the 878c2ecf20Sopenharmony_ci lower and higher word. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci Writes to read-only registers are ignored by the kernel. 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS accesses the main distributor registers. 928c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_REDIST_REGS accesses the redistributor of the CPU 938c2ecf20Sopenharmony_ci specified by the mpidr. 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci The offset is relative to the "[Re]Distributor base address" as defined 968c2ecf20Sopenharmony_ci in the GICv3/4 specs. Getting or setting such a register has the same 978c2ecf20Sopenharmony_ci effect as reading or writing the register on real hardware, except for the 988c2ecf20Sopenharmony_ci following registers: GICD_STATUSR, GICR_STATUSR, GICD_ISPENDR, 998c2ecf20Sopenharmony_ci GICR_ISPENDR0, GICD_ICPENDR, and GICR_ICPENDR0. These registers behave 1008c2ecf20Sopenharmony_ci differently when accessed via this interface compared to their 1018c2ecf20Sopenharmony_ci architecturally defined behavior to allow software a full view of the 1028c2ecf20Sopenharmony_ci VGIC's internal state. 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci The mpidr field is used to specify which 1058c2ecf20Sopenharmony_ci redistributor is accessed. The mpidr is ignored for the distributor. 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci The mpidr encoding is based on the affinity information in the 1088c2ecf20Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 1118c2ecf20Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci Note that distributor fields are not banked, but return the same value 1148c2ecf20Sopenharmony_ci regardless of the mpidr used to access the register. 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci GICD_IIDR.Revision is updated when the KVM implementation is changed in a 1178c2ecf20Sopenharmony_ci way directly observable by the guest or userspace. Userspace should read 1188c2ecf20Sopenharmony_ci GICD_IIDR from KVM and write back the read value to confirm its expected 1198c2ecf20Sopenharmony_ci behavior is aligned with the KVM implementation. Userspace should set 1208c2ecf20Sopenharmony_ci GICD_IIDR before setting any other registers to ensure the expected 1218c2ecf20Sopenharmony_ci behavior. 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci The GICD_STATUSR and GICR_STATUSR registers are architecturally defined such 1258c2ecf20Sopenharmony_ci that a write of a clear bit has no effect, whereas a write with a set bit 1268c2ecf20Sopenharmony_ci clears that value. To allow userspace to freely set the values of these two 1278c2ecf20Sopenharmony_ci registers, setting the attributes with the register offsets for these two 1288c2ecf20Sopenharmony_ci registers simply sets the non-reserved bits to the value written. 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci Accesses (reads and writes) to the GICD_ISPENDR register region and 1328c2ecf20Sopenharmony_ci GICR_ISPENDR0 registers get/set the value of the latched pending state for 1338c2ecf20Sopenharmony_ci the interrupts. 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci This is identical to the value returned by a guest read from ISPENDR for an 1368c2ecf20Sopenharmony_ci edge triggered interrupt, but may differ for level triggered interrupts. 1378c2ecf20Sopenharmony_ci For edge triggered interrupts, once an interrupt becomes pending (whether 1388c2ecf20Sopenharmony_ci because of an edge detected on the input line or because of a guest write 1398c2ecf20Sopenharmony_ci to ISPENDR) this state is "latched", and only cleared when either the 1408c2ecf20Sopenharmony_ci interrupt is activated or when the guest writes to ICPENDR. A level 1418c2ecf20Sopenharmony_ci triggered interrupt may be pending either because the level input is held 1428c2ecf20Sopenharmony_ci high by a device, or because of a guest write to the ISPENDR register. Only 1438c2ecf20Sopenharmony_ci ISPENDR writes are latched; if the device lowers the line level then the 1448c2ecf20Sopenharmony_ci interrupt is no longer pending unless the guest also wrote to ISPENDR, and 1458c2ecf20Sopenharmony_ci conversely writes to ICPENDR or activations of the interrupt do not clear 1468c2ecf20Sopenharmony_ci the pending status if the line level is still being held high. (These 1478c2ecf20Sopenharmony_ci rules are documented in the GICv3 specification descriptions of the ICPENDR 1488c2ecf20Sopenharmony_ci and ISPENDR registers.) For a level triggered interrupt the value accessed 1498c2ecf20Sopenharmony_ci here is that of the latch which is set by ISPENDR and cleared by ICPENDR or 1508c2ecf20Sopenharmony_ci interrupt activation, whereas the value returned by a guest read from 1518c2ecf20Sopenharmony_ci ISPENDR is the logical OR of the latch value and the input line level. 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci Raw access to the latch state is provided to userspace so that it can save 1548c2ecf20Sopenharmony_ci and restore the entire GIC internal state (which is defined by the 1558c2ecf20Sopenharmony_ci combination of the current input line level and the latch state, and cannot 1568c2ecf20Sopenharmony_ci be deduced from purely the line level and the value of the ISPENDR 1578c2ecf20Sopenharmony_ci registers). 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci Accesses to GICD_ICPENDR register region and GICR_ICPENDR0 registers have 1608c2ecf20Sopenharmony_ci RAZ/WI semantics, meaning that reads always return 0 and writes are always 1618c2ecf20Sopenharmony_ci ignored. 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci Errors: 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci ====== ===================================================== 1668c2ecf20Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 1678c2ecf20Sopenharmony_ci -EBUSY One or more VCPUs are running 1688c2ecf20Sopenharmony_ci ====== ===================================================== 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 1728c2ecf20Sopenharmony_ci Attributes: 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci bits: | 63 .... 32 | 31 .... 16 | 15 .... 0 | 1778c2ecf20Sopenharmony_ci values: | mpidr | RES | instr | 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci The mpidr field encodes the CPU ID based on the affinity information in the 1808c2ecf20Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 1838c2ecf20Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci The instr field encodes the system register to access based on the fields 1868c2ecf20Sopenharmony_ci defined in the A64 instruction set encoding for system register access 1878c2ecf20Sopenharmony_ci (RES means the bits are reserved for future use and should be zero):: 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci | 15 ... 14 | 13 ... 11 | 10 ... 7 | 6 ... 3 | 2 ... 0 | 1908c2ecf20Sopenharmony_ci | Op 0 | Op1 | CRn | CRm | Op2 | 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci All system regs accessed through this API are (rw, 64-bit) and 1938c2ecf20Sopenharmony_ci kvm_device_attr.addr points to a __u64 value. 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS accesses the CPU interface registers for the 1968c2ecf20Sopenharmony_ci CPU specified by the mpidr field. 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci CPU interface registers access is not implemented for AArch32 mode. 1998c2ecf20Sopenharmony_ci Error -ENXIO is returned when accessed in AArch32 mode. 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci Errors: 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci ======= ===================================================== 2048c2ecf20Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 2058c2ecf20Sopenharmony_ci -EBUSY VCPU is running 2068c2ecf20Sopenharmony_ci -EINVAL Invalid mpidr or register value supplied 2078c2ecf20Sopenharmony_ci ======= ===================================================== 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_NR_IRQS 2118c2ecf20Sopenharmony_ci Attributes: 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci A value describing the number of interrupts (SGI, PPI and SPI) for 2148c2ecf20Sopenharmony_ci this GIC instance, ranging from 64 to 1024, in increments of 32. 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci kvm_device_attr.addr points to a __u32 value. 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci Errors: 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci ======= ====================================== 2218c2ecf20Sopenharmony_ci -EINVAL Value set is out of the expected range 2228c2ecf20Sopenharmony_ci -EBUSY Value has already be set. 2238c2ecf20Sopenharmony_ci ======= ====================================== 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CTRL 2278c2ecf20Sopenharmony_ci Attributes: 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_CTRL_INIT 2308c2ecf20Sopenharmony_ci request the initialization of the VGIC, no additional parameter in 2318c2ecf20Sopenharmony_ci kvm_device_attr.addr. 2328c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 2338c2ecf20Sopenharmony_ci save all LPI pending bits into guest RAM pending tables. 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci The first kB of the pending table is not altered by this operation. 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci Errors: 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci ======= ======================================================== 2408c2ecf20Sopenharmony_ci -ENXIO VGIC not properly configured as required prior to calling 2418c2ecf20Sopenharmony_ci this attribute 2428c2ecf20Sopenharmony_ci -ENODEV no online VCPU 2438c2ecf20Sopenharmony_ci -ENOMEM memory shortage when allocating vgic internal data 2448c2ecf20Sopenharmony_ci -EFAULT Invalid guest ram access 2458c2ecf20Sopenharmony_ci -EBUSY One or more VCPUS are running 2468c2ecf20Sopenharmony_ci ======= ======================================================== 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 2508c2ecf20Sopenharmony_ci Attributes: 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci The attr field of kvm_device_attr encodes the following values:: 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci bits: | 63 .... 32 | 31 .... 10 | 9 .... 0 | 2558c2ecf20Sopenharmony_ci values: | mpidr | info | vINTID | 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci The vINTID specifies which set of IRQs is reported on. 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci The info field specifies which information userspace wants to get or set 2608c2ecf20Sopenharmony_ci using this interface. Currently we support the following info values: 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci VGIC_LEVEL_INFO_LINE_LEVEL: 2638c2ecf20Sopenharmony_ci Get/Set the input level of the IRQ line for a set of 32 contiguously 2648c2ecf20Sopenharmony_ci numbered interrupts. 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci vINTID must be a multiple of 32. 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci kvm_device_attr.addr points to a __u32 value which will contain a 2698c2ecf20Sopenharmony_ci bitmap where a set bit means the interrupt level is asserted. 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci Bit[n] indicates the status for interrupt vINTID + n. 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci SGIs and any interrupt with a higher ID than the number of interrupts 2748c2ecf20Sopenharmony_ci supported, will be RAZ/WI. LPIs are always edge-triggered and are 2758c2ecf20Sopenharmony_ci therefore not supported by this interface. 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci PPIs are reported per VCPU as specified in the mpidr field, and SPIs are 2788c2ecf20Sopenharmony_ci reported with the same value regardless of the mpidr specified. 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci The mpidr field encodes the CPU ID based on the affinity information in the 2818c2ecf20Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 2848c2ecf20Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci Errors: 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci ======= ============================================= 2898c2ecf20Sopenharmony_ci -EINVAL vINTID is not multiple of 32 or info field is 2908c2ecf20Sopenharmony_ci not VGIC_LEVEL_INFO_LINE_LEVEL 2918c2ecf20Sopenharmony_ci ======= ============================================= 292