1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============================================================== 4*4882a593SmuzhiyunARM Virtual Generic Interrupt Controller v3 and later (VGICv3) 5*4882a593Smuzhiyun============================================================== 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunDevice types supported: 9*4882a593Smuzhiyun - KVM_DEV_TYPE_ARM_VGIC_V3 ARM Generic Interrupt Controller v3.0 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunOnly one VGIC instance may be instantiated through this API. The created VGIC 12*4882a593Smuzhiyunwill act as the VM interrupt controller, requiring emulated user-space devices 13*4882a593Smuzhiyunto inject interrupts to the VGIC instead of directly to CPUs. It is not 14*4882a593Smuzhiyunpossible to create both a GICv3 and GICv2 on the same VM. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunCreating a guest GICv3 device requires a host GICv3 as well. 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunGroups: 20*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_ADDR 21*4882a593Smuzhiyun Attributes: 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit) 24*4882a593Smuzhiyun Base address in the guest physical address space of the GICv3 distributor 25*4882a593Smuzhiyun register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 26*4882a593Smuzhiyun This address needs to be 64K aligned and the region covers 64 KByte. 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit) 29*4882a593Smuzhiyun Base address in the guest physical address space of the GICv3 30*4882a593Smuzhiyun redistributor register mappings. There are two 64K pages for each 31*4882a593Smuzhiyun VCPU and all of the redistributor pages are contiguous. 32*4882a593Smuzhiyun Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 33*4882a593Smuzhiyun This address needs to be 64K aligned. 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION (rw, 64-bit) 36*4882a593Smuzhiyun The attribute data pointed to by kvm_device_attr.addr is a __u64 value:: 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun bits: | 63 .... 52 | 51 .... 16 | 15 - 12 |11 - 0 39*4882a593Smuzhiyun values: | count | base | flags | index 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun - index encodes the unique redistributor region index 42*4882a593Smuzhiyun - flags: reserved for future use, currently 0 43*4882a593Smuzhiyun - base field encodes bits [51:16] of the guest physical base address 44*4882a593Smuzhiyun of the first redistributor in the region. 45*4882a593Smuzhiyun - count encodes the number of redistributors in the region. Must be 46*4882a593Smuzhiyun greater than 0. 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun There are two 64K pages for each redistributor in the region and 49*4882a593Smuzhiyun redistributors are laid out contiguously within the region. Regions 50*4882a593Smuzhiyun are filled with redistributors in the index order. The sum of all 51*4882a593Smuzhiyun region count fields must be greater than or equal to the number of 52*4882a593Smuzhiyun VCPUs. Redistributor regions must be registered in the incremental 53*4882a593Smuzhiyun index order, starting from index 0. 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun The characteristics of a specific redistributor region can be read 56*4882a593Smuzhiyun by presetting the index field in the attr data. 57*4882a593Smuzhiyun Only valid for KVM_DEV_TYPE_ARM_VGIC_V3. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun It is invalid to mix calls with KVM_VGIC_V3_ADDR_TYPE_REDIST and 60*4882a593Smuzhiyun KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION attributes. 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun Errors: 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun ======= ============================================================= 65*4882a593Smuzhiyun -E2BIG Address outside of addressable IPA range 66*4882a593Smuzhiyun -EINVAL Incorrectly aligned address, bad redistributor region 67*4882a593Smuzhiyun count/index, mixed redistributor region attribute usage 68*4882a593Smuzhiyun -EEXIST Address already configured 69*4882a593Smuzhiyun -ENOENT Attempt to read the characteristics of a non existing 70*4882a593Smuzhiyun redistributor region 71*4882a593Smuzhiyun -ENXIO The group or attribute is unknown/unsupported for this device 72*4882a593Smuzhiyun or hardware support is missing. 73*4882a593Smuzhiyun -EFAULT Invalid user pointer for attr->addr. 74*4882a593Smuzhiyun ======= ============================================================= 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_DIST_REGS, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 78*4882a593Smuzhiyun Attributes: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun The attr field of kvm_device_attr encodes two values:: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun bits: | 63 .... 32 | 31 .... 0 | 83*4882a593Smuzhiyun values: | mpidr | offset | 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun All distributor regs are (rw, 32-bit) and kvm_device_attr.addr points to a 86*4882a593Smuzhiyun __u32 value. 64-bit registers must be accessed by separately accessing the 87*4882a593Smuzhiyun lower and higher word. 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun Writes to read-only registers are ignored by the kernel. 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_DIST_REGS accesses the main distributor registers. 92*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_REDIST_REGS accesses the redistributor of the CPU 93*4882a593Smuzhiyun specified by the mpidr. 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun The offset is relative to the "[Re]Distributor base address" as defined 96*4882a593Smuzhiyun in the GICv3/4 specs. Getting or setting such a register has the same 97*4882a593Smuzhiyun effect as reading or writing the register on real hardware, except for the 98*4882a593Smuzhiyun following registers: GICD_STATUSR, GICR_STATUSR, GICD_ISPENDR, 99*4882a593Smuzhiyun GICR_ISPENDR0, GICD_ICPENDR, and GICR_ICPENDR0. These registers behave 100*4882a593Smuzhiyun differently when accessed via this interface compared to their 101*4882a593Smuzhiyun architecturally defined behavior to allow software a full view of the 102*4882a593Smuzhiyun VGIC's internal state. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun The mpidr field is used to specify which 105*4882a593Smuzhiyun redistributor is accessed. The mpidr is ignored for the distributor. 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun The mpidr encoding is based on the affinity information in the 108*4882a593Smuzhiyun architecture defined MPIDR, and the field is encoded as follows:: 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 111*4882a593Smuzhiyun | Aff3 | Aff2 | Aff1 | Aff0 | 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun Note that distributor fields are not banked, but return the same value 114*4882a593Smuzhiyun regardless of the mpidr used to access the register. 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun GICD_IIDR.Revision is updated when the KVM implementation is changed in a 117*4882a593Smuzhiyun way directly observable by the guest or userspace. Userspace should read 118*4882a593Smuzhiyun GICD_IIDR from KVM and write back the read value to confirm its expected 119*4882a593Smuzhiyun behavior is aligned with the KVM implementation. Userspace should set 120*4882a593Smuzhiyun GICD_IIDR before setting any other registers to ensure the expected 121*4882a593Smuzhiyun behavior. 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun The GICD_STATUSR and GICR_STATUSR registers are architecturally defined such 125*4882a593Smuzhiyun that a write of a clear bit has no effect, whereas a write with a set bit 126*4882a593Smuzhiyun clears that value. To allow userspace to freely set the values of these two 127*4882a593Smuzhiyun registers, setting the attributes with the register offsets for these two 128*4882a593Smuzhiyun registers simply sets the non-reserved bits to the value written. 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun Accesses (reads and writes) to the GICD_ISPENDR register region and 132*4882a593Smuzhiyun GICR_ISPENDR0 registers get/set the value of the latched pending state for 133*4882a593Smuzhiyun the interrupts. 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun This is identical to the value returned by a guest read from ISPENDR for an 136*4882a593Smuzhiyun edge triggered interrupt, but may differ for level triggered interrupts. 137*4882a593Smuzhiyun For edge triggered interrupts, once an interrupt becomes pending (whether 138*4882a593Smuzhiyun because of an edge detected on the input line or because of a guest write 139*4882a593Smuzhiyun to ISPENDR) this state is "latched", and only cleared when either the 140*4882a593Smuzhiyun interrupt is activated or when the guest writes to ICPENDR. A level 141*4882a593Smuzhiyun triggered interrupt may be pending either because the level input is held 142*4882a593Smuzhiyun high by a device, or because of a guest write to the ISPENDR register. Only 143*4882a593Smuzhiyun ISPENDR writes are latched; if the device lowers the line level then the 144*4882a593Smuzhiyun interrupt is no longer pending unless the guest also wrote to ISPENDR, and 145*4882a593Smuzhiyun conversely writes to ICPENDR or activations of the interrupt do not clear 146*4882a593Smuzhiyun the pending status if the line level is still being held high. (These 147*4882a593Smuzhiyun rules are documented in the GICv3 specification descriptions of the ICPENDR 148*4882a593Smuzhiyun and ISPENDR registers.) For a level triggered interrupt the value accessed 149*4882a593Smuzhiyun here is that of the latch which is set by ISPENDR and cleared by ICPENDR or 150*4882a593Smuzhiyun interrupt activation, whereas the value returned by a guest read from 151*4882a593Smuzhiyun ISPENDR is the logical OR of the latch value and the input line level. 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun Raw access to the latch state is provided to userspace so that it can save 154*4882a593Smuzhiyun and restore the entire GIC internal state (which is defined by the 155*4882a593Smuzhiyun combination of the current input line level and the latch state, and cannot 156*4882a593Smuzhiyun be deduced from purely the line level and the value of the ISPENDR 157*4882a593Smuzhiyun registers). 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun Accesses to GICD_ICPENDR register region and GICR_ICPENDR0 registers have 160*4882a593Smuzhiyun RAZ/WI semantics, meaning that reads always return 0 and writes are always 161*4882a593Smuzhiyun ignored. 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun Errors: 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun ====== ===================================================== 166*4882a593Smuzhiyun -ENXIO Getting or setting this register is not yet supported 167*4882a593Smuzhiyun -EBUSY One or more VCPUs are running 168*4882a593Smuzhiyun ====== ===================================================== 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 172*4882a593Smuzhiyun Attributes: 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun The attr field of kvm_device_attr encodes two values:: 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun bits: | 63 .... 32 | 31 .... 16 | 15 .... 0 | 177*4882a593Smuzhiyun values: | mpidr | RES | instr | 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun The mpidr field encodes the CPU ID based on the affinity information in the 180*4882a593Smuzhiyun architecture defined MPIDR, and the field is encoded as follows:: 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 183*4882a593Smuzhiyun | Aff3 | Aff2 | Aff1 | Aff0 | 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun The instr field encodes the system register to access based on the fields 186*4882a593Smuzhiyun defined in the A64 instruction set encoding for system register access 187*4882a593Smuzhiyun (RES means the bits are reserved for future use and should be zero):: 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun | 15 ... 14 | 13 ... 11 | 10 ... 7 | 6 ... 3 | 2 ... 0 | 190*4882a593Smuzhiyun | Op 0 | Op1 | CRn | CRm | Op2 | 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun All system regs accessed through this API are (rw, 64-bit) and 193*4882a593Smuzhiyun kvm_device_attr.addr points to a __u64 value. 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS accesses the CPU interface registers for the 196*4882a593Smuzhiyun CPU specified by the mpidr field. 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun CPU interface registers access is not implemented for AArch32 mode. 199*4882a593Smuzhiyun Error -ENXIO is returned when accessed in AArch32 mode. 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun Errors: 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun ======= ===================================================== 204*4882a593Smuzhiyun -ENXIO Getting or setting this register is not yet supported 205*4882a593Smuzhiyun -EBUSY VCPU is running 206*4882a593Smuzhiyun -EINVAL Invalid mpidr or register value supplied 207*4882a593Smuzhiyun ======= ===================================================== 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_NR_IRQS 211*4882a593Smuzhiyun Attributes: 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun A value describing the number of interrupts (SGI, PPI and SPI) for 214*4882a593Smuzhiyun this GIC instance, ranging from 64 to 1024, in increments of 32. 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun kvm_device_attr.addr points to a __u32 value. 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun Errors: 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun ======= ====================================== 221*4882a593Smuzhiyun -EINVAL Value set is out of the expected range 222*4882a593Smuzhiyun -EBUSY Value has already be set. 223*4882a593Smuzhiyun ======= ====================================== 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_CTRL 227*4882a593Smuzhiyun Attributes: 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_CTRL_INIT 230*4882a593Smuzhiyun request the initialization of the VGIC, no additional parameter in 231*4882a593Smuzhiyun kvm_device_attr.addr. 232*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 233*4882a593Smuzhiyun save all LPI pending bits into guest RAM pending tables. 234*4882a593Smuzhiyun 235*4882a593Smuzhiyun The first kB of the pending table is not altered by this operation. 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun Errors: 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun ======= ======================================================== 240*4882a593Smuzhiyun -ENXIO VGIC not properly configured as required prior to calling 241*4882a593Smuzhiyun this attribute 242*4882a593Smuzhiyun -ENODEV no online VCPU 243*4882a593Smuzhiyun -ENOMEM memory shortage when allocating vgic internal data 244*4882a593Smuzhiyun -EFAULT Invalid guest ram access 245*4882a593Smuzhiyun -EBUSY One or more VCPUS are running 246*4882a593Smuzhiyun ======= ======================================================== 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 250*4882a593Smuzhiyun Attributes: 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun The attr field of kvm_device_attr encodes the following values:: 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun bits: | 63 .... 32 | 31 .... 10 | 9 .... 0 | 255*4882a593Smuzhiyun values: | mpidr | info | vINTID | 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun The vINTID specifies which set of IRQs is reported on. 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun The info field specifies which information userspace wants to get or set 260*4882a593Smuzhiyun using this interface. Currently we support the following info values: 261*4882a593Smuzhiyun 262*4882a593Smuzhiyun VGIC_LEVEL_INFO_LINE_LEVEL: 263*4882a593Smuzhiyun Get/Set the input level of the IRQ line for a set of 32 contiguously 264*4882a593Smuzhiyun numbered interrupts. 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun vINTID must be a multiple of 32. 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun kvm_device_attr.addr points to a __u32 value which will contain a 269*4882a593Smuzhiyun bitmap where a set bit means the interrupt level is asserted. 270*4882a593Smuzhiyun 271*4882a593Smuzhiyun Bit[n] indicates the status for interrupt vINTID + n. 272*4882a593Smuzhiyun 273*4882a593Smuzhiyun SGIs and any interrupt with a higher ID than the number of interrupts 274*4882a593Smuzhiyun supported, will be RAZ/WI. LPIs are always edge-triggered and are 275*4882a593Smuzhiyun therefore not supported by this interface. 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun PPIs are reported per VCPU as specified in the mpidr field, and SPIs are 278*4882a593Smuzhiyun reported with the same value regardless of the mpidr specified. 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun The mpidr field encodes the CPU ID based on the affinity information in the 281*4882a593Smuzhiyun architecture defined MPIDR, and the field is encoded as follows:: 282*4882a593Smuzhiyun 283*4882a593Smuzhiyun | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | 284*4882a593Smuzhiyun | Aff3 | Aff2 | Aff1 | Aff0 | 285*4882a593Smuzhiyun 286*4882a593Smuzhiyun Errors: 287*4882a593Smuzhiyun 288*4882a593Smuzhiyun ======= ============================================= 289*4882a593Smuzhiyun -EINVAL vINTID is not multiple of 32 or info field is 290*4882a593Smuzhiyun not VGIC_LEVEL_INFO_LINE_LEVEL 291*4882a593Smuzhiyun ======= ============================================= 292