162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci============================================================== 462306a36Sopenharmony_ciARM Virtual Generic Interrupt Controller v3 and later (VGICv3) 562306a36Sopenharmony_ci============================================================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciDevice types supported: 962306a36Sopenharmony_ci - KVM_DEV_TYPE_ARM_VGIC_V3 ARM Generic Interrupt Controller v3.0 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciOnly one VGIC instance may be instantiated through this API. The created VGIC 1262306a36Sopenharmony_ciwill act as the VM interrupt controller, requiring emulated user-space devices 1362306a36Sopenharmony_cito inject interrupts to the VGIC instead of directly to CPUs. It is not 1462306a36Sopenharmony_cipossible to create both a GICv3 and GICv2 on the same VM. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciCreating a guest GICv3 device requires a host GICv3 as well. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciGroups: 2062306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_ADDR 2162306a36Sopenharmony_ci Attributes: 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit) 2462306a36Sopenharmony_ci Base address in the guest physical address space of the GICv3 distributor 2562306a36Sopenharmony_ci register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 2662306a36Sopenharmony_ci This address needs to be 64K aligned and the region covers 64 KByte. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit) 2962306a36Sopenharmony_ci Base address in the guest physical address space of the GICv3 3062306a36Sopenharmony_ci redistributor register mappings. There are two 64K pages for each 3162306a36Sopenharmony_ci VCPU and all of the redistributor pages are contiguous. 3262306a36Sopenharmony_ci Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 3362306a36Sopenharmony_ci This address needs to be 64K aligned. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION (rw, 64-bit) 3662306a36Sopenharmony_ci The attribute data pointed to by kvm_device_attr.addr is a __u64 value:: 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci bits: | 63 .... 52 | 51 .... 16 | 15 - 12 |11 - 0 3962306a36Sopenharmony_ci values: | count | base | flags | index 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci - index encodes the unique redistributor region index 4262306a36Sopenharmony_ci - flags: reserved for future use, currently 0 4362306a36Sopenharmony_ci - base field encodes bits [51:16] of the guest physical base address 4462306a36Sopenharmony_ci of the first redistributor in the region. 4562306a36Sopenharmony_ci - count encodes the number of redistributors in the region. Must be 4662306a36Sopenharmony_ci greater than 0. 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci There are two 64K pages for each redistributor in the region and 4962306a36Sopenharmony_ci redistributors are laid out contiguously within the region. Regions 5062306a36Sopenharmony_ci are filled with redistributors in the index order. The sum of all 5162306a36Sopenharmony_ci region count fields must be greater than or equal to the number of 5262306a36Sopenharmony_ci VCPUs. Redistributor regions must be registered in the incremental 5362306a36Sopenharmony_ci index order, starting from index 0. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci The characteristics of a specific redistributor region can be read 5662306a36Sopenharmony_ci by presetting the index field in the attr data. 5762306a36Sopenharmony_ci Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci It is invalid to mix calls with KVM_VGIC_V3_ADDR_TYPE_REDIST and 6062306a36Sopenharmony_ci KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION attributes. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci Errors: 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci ======= ============================================================= 6562306a36Sopenharmony_ci -E2BIG Address outside of addressable IPA range 6662306a36Sopenharmony_ci -EINVAL Incorrectly aligned address, bad redistributor region 6762306a36Sopenharmony_ci count/index, mixed redistributor region attribute usage 6862306a36Sopenharmony_ci -EEXIST Address already configured 6962306a36Sopenharmony_ci -ENOENT Attempt to read the characteristics of a non existing 7062306a36Sopenharmony_ci redistributor region 7162306a36Sopenharmony_ci -ENXIO The group or attribute is unknown/unsupported for this device 7262306a36Sopenharmony_ci or hardware support is missing. 7362306a36Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr. 7462306a36Sopenharmony_ci ======= ============================================================= 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 7862306a36Sopenharmony_ci Attributes: 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci bits: | 63 .... 32 | 31 .... 0 | 8362306a36Sopenharmony_ci values: | mpidr | offset | 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci All distributor regs are (rw, 32-bit) and kvm_device_attr.addr points to a 8662306a36Sopenharmony_ci __u32 value. 64-bit registers must be accessed by separately accessing the 8762306a36Sopenharmony_ci lower and higher word. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci Writes to read-only registers are ignored by the kernel. 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS accesses the main distributor registers. 9262306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_REDIST_REGS accesses the redistributor of the CPU 9362306a36Sopenharmony_ci specified by the mpidr. 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci The offset is relative to the "[Re]Distributor base address" as defined 9662306a36Sopenharmony_ci in the GICv3/4 specs. Getting or setting such a register has the same 9762306a36Sopenharmony_ci effect as reading or writing the register on real hardware, except for the 9862306a36Sopenharmony_ci following registers: GICD_STATUSR, GICR_STATUSR, GICD_ISPENDR, 9962306a36Sopenharmony_ci GICR_ISPENDR0, GICD_ICPENDR, and GICR_ICPENDR0. These registers behave 10062306a36Sopenharmony_ci differently when accessed via this interface compared to their 10162306a36Sopenharmony_ci architecturally defined behavior to allow software a full view of the 10262306a36Sopenharmony_ci VGIC's internal state. 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci The mpidr field is used to specify which 10562306a36Sopenharmony_ci redistributor is accessed. The mpidr is ignored for the distributor. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci The mpidr encoding is based on the affinity information in the 10862306a36Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 11162306a36Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci Note that distributor fields are not banked, but return the same value 11462306a36Sopenharmony_ci regardless of the mpidr used to access the register. 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci GICD_IIDR.Revision is updated when the KVM implementation is changed in a 11762306a36Sopenharmony_ci way directly observable by the guest or userspace. Userspace should read 11862306a36Sopenharmony_ci GICD_IIDR from KVM and write back the read value to confirm its expected 11962306a36Sopenharmony_ci behavior is aligned with the KVM implementation. Userspace should set 12062306a36Sopenharmony_ci GICD_IIDR before setting any other registers to ensure the expected 12162306a36Sopenharmony_ci behavior. 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci The GICD_STATUSR and GICR_STATUSR registers are architecturally defined such 12562306a36Sopenharmony_ci that a write of a clear bit has no effect, whereas a write with a set bit 12662306a36Sopenharmony_ci clears that value. To allow userspace to freely set the values of these two 12762306a36Sopenharmony_ci registers, setting the attributes with the register offsets for these two 12862306a36Sopenharmony_ci registers simply sets the non-reserved bits to the value written. 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci Accesses (reads and writes) to the GICD_ISPENDR register region and 13262306a36Sopenharmony_ci GICR_ISPENDR0 registers get/set the value of the latched pending state for 13362306a36Sopenharmony_ci the interrupts. 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci This is identical to the value returned by a guest read from ISPENDR for an 13662306a36Sopenharmony_ci edge triggered interrupt, but may differ for level triggered interrupts. 13762306a36Sopenharmony_ci For edge triggered interrupts, once an interrupt becomes pending (whether 13862306a36Sopenharmony_ci because of an edge detected on the input line or because of a guest write 13962306a36Sopenharmony_ci to ISPENDR) this state is "latched", and only cleared when either the 14062306a36Sopenharmony_ci interrupt is activated or when the guest writes to ICPENDR. A level 14162306a36Sopenharmony_ci triggered interrupt may be pending either because the level input is held 14262306a36Sopenharmony_ci high by a device, or because of a guest write to the ISPENDR register. Only 14362306a36Sopenharmony_ci ISPENDR writes are latched; if the device lowers the line level then the 14462306a36Sopenharmony_ci interrupt is no longer pending unless the guest also wrote to ISPENDR, and 14562306a36Sopenharmony_ci conversely writes to ICPENDR or activations of the interrupt do not clear 14662306a36Sopenharmony_ci the pending status if the line level is still being held high. (These 14762306a36Sopenharmony_ci rules are documented in the GICv3 specification descriptions of the ICPENDR 14862306a36Sopenharmony_ci and ISPENDR registers.) For a level triggered interrupt the value accessed 14962306a36Sopenharmony_ci here is that of the latch which is set by ISPENDR and cleared by ICPENDR or 15062306a36Sopenharmony_ci interrupt activation, whereas the value returned by a guest read from 15162306a36Sopenharmony_ci ISPENDR is the logical OR of the latch value and the input line level. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci Raw access to the latch state is provided to userspace so that it can save 15462306a36Sopenharmony_ci and restore the entire GIC internal state (which is defined by the 15562306a36Sopenharmony_ci combination of the current input line level and the latch state, and cannot 15662306a36Sopenharmony_ci be deduced from purely the line level and the value of the ISPENDR 15762306a36Sopenharmony_ci registers). 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci Accesses to GICD_ICPENDR register region and GICR_ICPENDR0 registers have 16062306a36Sopenharmony_ci RAZ/WI semantics, meaning that reads always return 0 and writes are always 16162306a36Sopenharmony_ci ignored. 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci Errors: 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci ====== ===================================================== 16662306a36Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 16762306a36Sopenharmony_ci -EBUSY One or more VCPUs are running 16862306a36Sopenharmony_ci ====== ===================================================== 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 17262306a36Sopenharmony_ci Attributes: 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci bits: | 63 .... 32 | 31 .... 16 | 15 .... 0 | 17762306a36Sopenharmony_ci values: | mpidr | RES | instr | 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci The mpidr field encodes the CPU ID based on the affinity information in the 18062306a36Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 18362306a36Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci The instr field encodes the system register to access based on the fields 18662306a36Sopenharmony_ci defined in the A64 instruction set encoding for system register access 18762306a36Sopenharmony_ci (RES means the bits are reserved for future use and should be zero):: 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci | 15 ... 14 | 13 ... 11 | 10 ... 7 | 6 ... 3 | 2 ... 0 | 19062306a36Sopenharmony_ci | Op 0 | Op1 | CRn | CRm | Op2 | 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci All system regs accessed through this API are (rw, 64-bit) and 19362306a36Sopenharmony_ci kvm_device_attr.addr points to a __u64 value. 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS accesses the CPU interface registers for the 19662306a36Sopenharmony_ci CPU specified by the mpidr field. 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci CPU interface registers access is not implemented for AArch32 mode. 19962306a36Sopenharmony_ci Error -ENXIO is returned when accessed in AArch32 mode. 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci Errors: 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci ======= ===================================================== 20462306a36Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 20562306a36Sopenharmony_ci -EBUSY VCPU is running 20662306a36Sopenharmony_ci -EINVAL Invalid mpidr or register value supplied 20762306a36Sopenharmony_ci ======= ===================================================== 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_NR_IRQS 21162306a36Sopenharmony_ci Attributes: 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci A value describing the number of interrupts (SGI, PPI and SPI) for 21462306a36Sopenharmony_ci this GIC instance, ranging from 64 to 1024, in increments of 32. 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci kvm_device_attr.addr points to a __u32 value. 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci Errors: 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci ======= ====================================== 22162306a36Sopenharmony_ci -EINVAL Value set is out of the expected range 22262306a36Sopenharmony_ci -EBUSY Value has already be set. 22362306a36Sopenharmony_ci ======= ====================================== 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CTRL 22762306a36Sopenharmony_ci Attributes: 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_CTRL_INIT 23062306a36Sopenharmony_ci request the initialization of the VGIC, no additional parameter in 23162306a36Sopenharmony_ci kvm_device_attr.addr. Must be called after all VCPUs have been created. 23262306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 23362306a36Sopenharmony_ci save all LPI pending bits into guest RAM pending tables. 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci The first kB of the pending table is not altered by this operation. 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci Errors: 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci ======= ======================================================== 24062306a36Sopenharmony_ci -ENXIO VGIC not properly configured as required prior to calling 24162306a36Sopenharmony_ci this attribute 24262306a36Sopenharmony_ci -ENODEV no online VCPU 24362306a36Sopenharmony_ci -ENOMEM memory shortage when allocating vgic internal data 24462306a36Sopenharmony_ci -EFAULT Invalid guest ram access 24562306a36Sopenharmony_ci -EBUSY One or more VCPUS are running 24662306a36Sopenharmony_ci ======= ======================================================== 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 25062306a36Sopenharmony_ci Attributes: 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci The attr field of kvm_device_attr encodes the following values:: 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci bits: | 63 .... 32 | 31 .... 10 | 9 .... 0 | 25562306a36Sopenharmony_ci values: | mpidr | info | vINTID | 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci The vINTID specifies which set of IRQs is reported on. 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci The info field specifies which information userspace wants to get or set 26062306a36Sopenharmony_ci using this interface. Currently we support the following info values: 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci VGIC_LEVEL_INFO_LINE_LEVEL: 26362306a36Sopenharmony_ci Get/Set the input level of the IRQ line for a set of 32 contiguously 26462306a36Sopenharmony_ci numbered interrupts. 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci vINTID must be a multiple of 32. 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci kvm_device_attr.addr points to a __u32 value which will contain a 26962306a36Sopenharmony_ci bitmap where a set bit means the interrupt level is asserted. 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci Bit[n] indicates the status for interrupt vINTID + n. 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci SGIs and any interrupt with a higher ID than the number of interrupts 27462306a36Sopenharmony_ci supported, will be RAZ/WI. LPIs are always edge-triggered and are 27562306a36Sopenharmony_ci therefore not supported by this interface. 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ci PPIs are reported per VCPU as specified in the mpidr field, and SPIs are 27862306a36Sopenharmony_ci reported with the same value regardless of the mpidr specified. 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci The mpidr field encodes the CPU ID based on the affinity information in the 28162306a36Sopenharmony_ci architecture defined MPIDR, and the field is encoded as follows:: 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 28462306a36Sopenharmony_ci | Aff3 | Aff2 | Aff1 | Aff0 | 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci Errors: 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci ======= ============================================= 28962306a36Sopenharmony_ci -EINVAL vINTID is not multiple of 32 or info field is 29062306a36Sopenharmony_ci not VGIC_LEVEL_INFO_LINE_LEVEL 29162306a36Sopenharmony_ci ======= ============================================= 292