162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci================================================== 462306a36Sopenharmony_ciARM Virtual Generic Interrupt Controller v2 (VGIC) 562306a36Sopenharmony_ci================================================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciDevice types supported: 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci - KVM_DEV_TYPE_ARM_VGIC_V2 ARM Generic Interrupt Controller v2.0 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciOnly one VGIC instance may be instantiated through either this API or the 1262306a36Sopenharmony_cilegacy KVM_CREATE_IRQCHIP API. The created VGIC will act as the VM interrupt 1362306a36Sopenharmony_cicontroller, requiring emulated user-space devices to inject interrupts to the 1462306a36Sopenharmony_ciVGIC instead of directly to CPUs. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciGICv3 implementations with hardware compatibility support allow creating a 1762306a36Sopenharmony_ciguest GICv2 through this interface. For information on creating a guest GICv3 1862306a36Sopenharmony_cidevice and guest ITS devices, see arm-vgic-v3.txt. It is not possible to 1962306a36Sopenharmony_cicreate both a GICv3 and GICv2 device on the same VM. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciGroups: 2362306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_ADDR 2462306a36Sopenharmony_ci Attributes: 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit) 2762306a36Sopenharmony_ci Base address in the guest physical address space of the GIC distributor 2862306a36Sopenharmony_ci register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2. 2962306a36Sopenharmony_ci This address needs to be 4K aligned and the region covers 4 KByte. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit) 3262306a36Sopenharmony_ci Base address in the guest physical address space of the GIC virtual cpu 3362306a36Sopenharmony_ci interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2. 3462306a36Sopenharmony_ci This address needs to be 4K aligned and the region covers 4 KByte. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci Errors: 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci ======= ============================================================= 3962306a36Sopenharmony_ci -E2BIG Address outside of addressable IPA range 4062306a36Sopenharmony_ci -EINVAL Incorrectly aligned address 4162306a36Sopenharmony_ci -EEXIST Address already configured 4262306a36Sopenharmony_ci -ENXIO The group or attribute is unknown/unsupported for this device 4362306a36Sopenharmony_ci or hardware support is missing. 4462306a36Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr. 4562306a36Sopenharmony_ci ======= ============================================================= 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS 4862306a36Sopenharmony_ci Attributes: 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci bits: | 63 .... 40 | 39 .. 32 | 31 .... 0 | 5362306a36Sopenharmony_ci values: | reserved | vcpu_index | offset | 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci All distributor regs are (rw, 32-bit) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci The offset is relative to the "Distributor base address" as defined in the 5862306a36Sopenharmony_ci GICv2 specs. Getting or setting such a register has the same effect as 5962306a36Sopenharmony_ci reading or writing the register on the actual hardware from the cpu whose 6062306a36Sopenharmony_ci index is specified with the vcpu_index field. Note that most distributor 6162306a36Sopenharmony_ci fields are not banked, but return the same value regardless of the 6262306a36Sopenharmony_ci vcpu_index used to access the register. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci GICD_IIDR.Revision is updated when the KVM implementation of an emulated 6562306a36Sopenharmony_ci GICv2 is changed in a way directly observable by the guest or userspace. 6662306a36Sopenharmony_ci Userspace should read GICD_IIDR from KVM and write back the read value to 6762306a36Sopenharmony_ci confirm its expected behavior is aligned with the KVM implementation. 6862306a36Sopenharmony_ci Userspace should set GICD_IIDR before setting any other registers (both 6962306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_CPU_REGS) to ensure 7062306a36Sopenharmony_ci the expected behavior. Unless GICD_IIDR has been set from userspace, writes 7162306a36Sopenharmony_ci to the interrupt group registers (GICD_IGROUPR) are ignored. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci Errors: 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci ======= ===================================================== 7662306a36Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 7762306a36Sopenharmony_ci -EBUSY One or more VCPUs are running 7862306a36Sopenharmony_ci -EINVAL Invalid vcpu_index supplied 7962306a36Sopenharmony_ci ======= ===================================================== 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CPU_REGS 8262306a36Sopenharmony_ci Attributes: 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci The attr field of kvm_device_attr encodes two values:: 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci bits: | 63 .... 40 | 39 .. 32 | 31 .... 0 | 8762306a36Sopenharmony_ci values: | reserved | vcpu_index | offset | 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci All CPU interface regs are (rw, 32-bit) 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci The offset specifies the offset from the "CPU interface base address" as 9262306a36Sopenharmony_ci defined in the GICv2 specs. Getting or setting such a register has the 9362306a36Sopenharmony_ci same effect as reading or writing the register on the actual hardware. 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci The Active Priorities Registers APRn are implementation defined, so we set a 9662306a36Sopenharmony_ci fixed format for our implementation that fits with the model of a "GICv2 9762306a36Sopenharmony_ci implementation without the security extensions" which we present to the 9862306a36Sopenharmony_ci guest. This interface always exposes four register APR[0-3] describing the 9962306a36Sopenharmony_ci maximum possible 128 preemption levels. The semantics of the register 10062306a36Sopenharmony_ci indicate if any interrupts in a given preemption level are in the active 10162306a36Sopenharmony_ci state by setting the corresponding bit. 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci Thus, preemption level X has one or more active interrupts if and only if: 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci APRn[X mod 32] == 0b1, where n = X / 32 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci Bits for undefined preemption levels are RAZ/WI. 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci Note that this differs from a CPU's view of the APRs on hardware in which 11062306a36Sopenharmony_ci a GIC without the security extensions expose group 0 and group 1 active 11162306a36Sopenharmony_ci priorities in separate register groups, whereas we show a combined view 11262306a36Sopenharmony_ci similar to GICv2's GICH_APR. 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci For historical reasons and to provide ABI compatibility with userspace we 11562306a36Sopenharmony_ci export the GICC_PMR register in the format of the GICH_VMCR.VMPriMask 11662306a36Sopenharmony_ci field in the lower 5 bits of a word, meaning that userspace must always 11762306a36Sopenharmony_ci use the lower 5 bits to communicate with the KVM device and must shift the 11862306a36Sopenharmony_ci value left by 3 places to obtain the actual priority mask level. 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci Errors: 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci ======= ===================================================== 12362306a36Sopenharmony_ci -ENXIO Getting or setting this register is not yet supported 12462306a36Sopenharmony_ci -EBUSY One or more VCPUs are running 12562306a36Sopenharmony_ci -EINVAL Invalid vcpu_index supplied 12662306a36Sopenharmony_ci ======= ===================================================== 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_NR_IRQS 12962306a36Sopenharmony_ci Attributes: 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci A value describing the number of interrupts (SGI, PPI and SPI) for 13262306a36Sopenharmony_ci this GIC instance, ranging from 64 to 1024, in increments of 32. 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci Errors: 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci ======= ============================================================= 13762306a36Sopenharmony_ci -EINVAL Value set is out of the expected range 13862306a36Sopenharmony_ci -EBUSY Value has already be set, or GIC has already been initialized 13962306a36Sopenharmony_ci with default values. 14062306a36Sopenharmony_ci ======= ============================================================= 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_GRP_CTRL 14362306a36Sopenharmony_ci Attributes: 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_CTRL_INIT 14662306a36Sopenharmony_ci request the initialization of the VGIC or ITS, no additional parameter 14762306a36Sopenharmony_ci in kvm_device_attr.addr. 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci Errors: 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci ======= ========================================================= 15262306a36Sopenharmony_ci -ENXIO VGIC not properly configured as required prior to calling 15362306a36Sopenharmony_ci this attribute 15462306a36Sopenharmony_ci -ENODEV no online VCPU 15562306a36Sopenharmony_ci -ENOMEM memory shortage when allocating vgic internal data 15662306a36Sopenharmony_ci ======= ========================================================= 157