18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci==================================================
48c2ecf20Sopenharmony_ciARM Virtual Generic Interrupt Controller v2 (VGIC)
58c2ecf20Sopenharmony_ci==================================================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciDevice types supported:
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci  - KVM_DEV_TYPE_ARM_VGIC_V2     ARM Generic Interrupt Controller v2.0
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciOnly one VGIC instance may be instantiated through either this API or the
128c2ecf20Sopenharmony_cilegacy KVM_CREATE_IRQCHIP API.  The created VGIC will act as the VM interrupt
138c2ecf20Sopenharmony_cicontroller, requiring emulated user-space devices to inject interrupts to the
148c2ecf20Sopenharmony_ciVGIC instead of directly to CPUs.
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ciGICv3 implementations with hardware compatibility support allow creating a
178c2ecf20Sopenharmony_ciguest GICv2 through this interface.  For information on creating a guest GICv3
188c2ecf20Sopenharmony_cidevice and guest ITS devices, see arm-vgic-v3.txt.  It is not possible to
198c2ecf20Sopenharmony_cicreate both a GICv3 and GICv2 device on the same VM.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciGroups:
238c2ecf20Sopenharmony_ci  KVM_DEV_ARM_VGIC_GRP_ADDR
248c2ecf20Sopenharmony_ci   Attributes:
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci    KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit)
278c2ecf20Sopenharmony_ci      Base address in the guest physical address space of the GIC distributor
288c2ecf20Sopenharmony_ci      register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
298c2ecf20Sopenharmony_ci      This address needs to be 4K aligned and the region covers 4 KByte.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci    KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit)
328c2ecf20Sopenharmony_ci      Base address in the guest physical address space of the GIC virtual cpu
338c2ecf20Sopenharmony_ci      interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
348c2ecf20Sopenharmony_ci      This address needs to be 4K aligned and the region covers 4 KByte.
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci  Errors:
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci    =======  =============================================================
398c2ecf20Sopenharmony_ci    -E2BIG   Address outside of addressable IPA range
408c2ecf20Sopenharmony_ci    -EINVAL  Incorrectly aligned address
418c2ecf20Sopenharmony_ci    -EEXIST  Address already configured
428c2ecf20Sopenharmony_ci    -ENXIO   The group or attribute is unknown/unsupported for this device
438c2ecf20Sopenharmony_ci             or hardware support is missing.
448c2ecf20Sopenharmony_ci    -EFAULT  Invalid user pointer for attr->addr.
458c2ecf20Sopenharmony_ci    =======  =============================================================
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci  KVM_DEV_ARM_VGIC_GRP_DIST_REGS
488c2ecf20Sopenharmony_ci   Attributes:
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci    The attr field of kvm_device_attr encodes two values::
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci      bits:     | 63   ....  40 | 39 ..  32  |  31   ....    0 |
538c2ecf20Sopenharmony_ci      values:   |    reserved   | vcpu_index |      offset     |
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci    All distributor regs are (rw, 32-bit)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci    The offset is relative to the "Distributor base address" as defined in the
588c2ecf20Sopenharmony_ci    GICv2 specs.  Getting or setting such a register has the same effect as
598c2ecf20Sopenharmony_ci    reading or writing the register on the actual hardware from the cpu whose
608c2ecf20Sopenharmony_ci    index is specified with the vcpu_index field.  Note that most distributor
618c2ecf20Sopenharmony_ci    fields are not banked, but return the same value regardless of the
628c2ecf20Sopenharmony_ci    vcpu_index used to access the register.
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci    GICD_IIDR.Revision is updated when the KVM implementation of an emulated
658c2ecf20Sopenharmony_ci    GICv2 is changed in a way directly observable by the guest or userspace.
668c2ecf20Sopenharmony_ci    Userspace should read GICD_IIDR from KVM and write back the read value to
678c2ecf20Sopenharmony_ci    confirm its expected behavior is aligned with the KVM implementation.
688c2ecf20Sopenharmony_ci    Userspace should set GICD_IIDR before setting any other registers (both
698c2ecf20Sopenharmony_ci    KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_CPU_REGS) to ensure
708c2ecf20Sopenharmony_ci    the expected behavior. Unless GICD_IIDR has been set from userspace, writes
718c2ecf20Sopenharmony_ci    to the interrupt group registers (GICD_IGROUPR) are ignored.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci  Errors:
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci    =======  =====================================================
768c2ecf20Sopenharmony_ci    -ENXIO   Getting or setting this register is not yet supported
778c2ecf20Sopenharmony_ci    -EBUSY   One or more VCPUs are running
788c2ecf20Sopenharmony_ci    -EINVAL  Invalid vcpu_index supplied
798c2ecf20Sopenharmony_ci    =======  =====================================================
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci  KVM_DEV_ARM_VGIC_GRP_CPU_REGS
828c2ecf20Sopenharmony_ci   Attributes:
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci    The attr field of kvm_device_attr encodes two values::
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci      bits:     | 63   ....  40 | 39 ..  32  |  31   ....    0 |
878c2ecf20Sopenharmony_ci      values:   |    reserved   | vcpu_index |      offset     |
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci    All CPU interface regs are (rw, 32-bit)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci    The offset specifies the offset from the "CPU interface base address" as
928c2ecf20Sopenharmony_ci    defined in the GICv2 specs.  Getting or setting such a register has the
938c2ecf20Sopenharmony_ci    same effect as reading or writing the register on the actual hardware.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci    The Active Priorities Registers APRn are implementation defined, so we set a
968c2ecf20Sopenharmony_ci    fixed format for our implementation that fits with the model of a "GICv2
978c2ecf20Sopenharmony_ci    implementation without the security extensions" which we present to the
988c2ecf20Sopenharmony_ci    guest.  This interface always exposes four register APR[0-3] describing the
998c2ecf20Sopenharmony_ci    maximum possible 128 preemption levels.  The semantics of the register
1008c2ecf20Sopenharmony_ci    indicate if any interrupts in a given preemption level are in the active
1018c2ecf20Sopenharmony_ci    state by setting the corresponding bit.
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci    Thus, preemption level X has one or more active interrupts if and only if:
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci      APRn[X mod 32] == 0b1,  where n = X / 32
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci    Bits for undefined preemption levels are RAZ/WI.
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci    Note that this differs from a CPU's view of the APRs on hardware in which
1108c2ecf20Sopenharmony_ci    a GIC without the security extensions expose group 0 and group 1 active
1118c2ecf20Sopenharmony_ci    priorities in separate register groups, whereas we show a combined view
1128c2ecf20Sopenharmony_ci    similar to GICv2's GICH_APR.
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci    For historical reasons and to provide ABI compatibility with userspace we
1158c2ecf20Sopenharmony_ci    export the GICC_PMR register in the format of the GICH_VMCR.VMPriMask
1168c2ecf20Sopenharmony_ci    field in the lower 5 bits of a word, meaning that userspace must always
1178c2ecf20Sopenharmony_ci    use the lower 5 bits to communicate with the KVM device and must shift the
1188c2ecf20Sopenharmony_ci    value left by 3 places to obtain the actual priority mask level.
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci  Errors:
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci    =======  =====================================================
1238c2ecf20Sopenharmony_ci    -ENXIO   Getting or setting this register is not yet supported
1248c2ecf20Sopenharmony_ci    -EBUSY   One or more VCPUs are running
1258c2ecf20Sopenharmony_ci    -EINVAL  Invalid vcpu_index supplied
1268c2ecf20Sopenharmony_ci    =======  =====================================================
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci  KVM_DEV_ARM_VGIC_GRP_NR_IRQS
1298c2ecf20Sopenharmony_ci   Attributes:
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci    A value describing the number of interrupts (SGI, PPI and SPI) for
1328c2ecf20Sopenharmony_ci    this GIC instance, ranging from 64 to 1024, in increments of 32.
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci  Errors:
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci    =======  =============================================================
1378c2ecf20Sopenharmony_ci    -EINVAL  Value set is out of the expected range
1388c2ecf20Sopenharmony_ci    -EBUSY   Value has already be set, or GIC has already been initialized
1398c2ecf20Sopenharmony_ci             with default values.
1408c2ecf20Sopenharmony_ci    =======  =============================================================
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci  KVM_DEV_ARM_VGIC_GRP_CTRL
1438c2ecf20Sopenharmony_ci   Attributes:
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci    KVM_DEV_ARM_VGIC_CTRL_INIT
1468c2ecf20Sopenharmony_ci      request the initialization of the VGIC or ITS, no additional parameter
1478c2ecf20Sopenharmony_ci      in kvm_device_attr.addr.
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci  Errors:
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci    =======  =========================================================
1528c2ecf20Sopenharmony_ci    -ENXIO   VGIC not properly configured as required prior to calling
1538c2ecf20Sopenharmony_ci             this attribute
1548c2ecf20Sopenharmony_ci    -ENODEV  no online VCPU
1558c2ecf20Sopenharmony_ci    -ENOMEM  memory shortage when allocating vgic internal data
1568c2ecf20Sopenharmony_ci    =======  =========================================================
157