162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=============================================== 462306a36Sopenharmony_ciARM Virtual Interrupt Translation Service (ITS) 562306a36Sopenharmony_ci=============================================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciDevice types supported: 862306a36Sopenharmony_ci KVM_DEV_TYPE_ARM_VGIC_ITS ARM Interrupt Translation Service Controller 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciThe ITS allows MSI(-X) interrupts to be injected into guests. This extension is 1162306a36Sopenharmony_cioptional. Creating a virtual ITS controller also requires a host GICv3 (see 1262306a36Sopenharmony_ciarm-vgic-v3.txt), but does not depend on having physical ITS controllers. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciThere can be multiple ITS controllers per guest, each of them has to have 1562306a36Sopenharmony_cia separate, non-overlapping MMIO region. 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciGroups 1962306a36Sopenharmony_ci====== 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_ADDR 2262306a36Sopenharmony_ci------------------------- 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci Attributes: 2562306a36Sopenharmony_ci KVM_VGIC_ITS_ADDR_TYPE (rw, 64-bit) 2662306a36Sopenharmony_ci Base address in the guest physical address space of the GICv3 ITS 2762306a36Sopenharmony_ci control register frame. 2862306a36Sopenharmony_ci This address needs to be 64K aligned and the region covers 128K. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci Errors: 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci ======= ================================================= 3362306a36Sopenharmony_ci -E2BIG Address outside of addressable IPA range 3462306a36Sopenharmony_ci -EINVAL Incorrectly aligned address 3562306a36Sopenharmony_ci -EEXIST Address already configured 3662306a36Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr. 3762306a36Sopenharmony_ci -ENODEV Incorrect attribute or the ITS is not supported. 3862306a36Sopenharmony_ci ======= ================================================= 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_CTRL 4262306a36Sopenharmony_ci------------------------- 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci Attributes: 4562306a36Sopenharmony_ci KVM_DEV_ARM_VGIC_CTRL_INIT 4662306a36Sopenharmony_ci request the initialization of the ITS, no additional parameter in 4762306a36Sopenharmony_ci kvm_device_attr.addr. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci KVM_DEV_ARM_ITS_CTRL_RESET 5062306a36Sopenharmony_ci reset the ITS, no additional parameter in kvm_device_attr.addr. 5162306a36Sopenharmony_ci See "ITS Reset State" section. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci KVM_DEV_ARM_ITS_SAVE_TABLES 5462306a36Sopenharmony_ci save the ITS table data into guest RAM, at the location provisioned 5562306a36Sopenharmony_ci by the guest in corresponding registers/table entries. Should userspace 5662306a36Sopenharmony_ci require a form of dirty tracking to identify which pages are modified 5762306a36Sopenharmony_ci by the saving process, it should use a bitmap even if using another 5862306a36Sopenharmony_ci mechanism to track the memory dirtied by the vCPUs. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci The layout of the tables in guest memory defines an ABI. The entries 6162306a36Sopenharmony_ci are laid out in little endian format as described in the last paragraph. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci KVM_DEV_ARM_ITS_RESTORE_TABLES 6462306a36Sopenharmony_ci restore the ITS tables from guest RAM to ITS internal structures. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci The GICV3 must be restored before the ITS and all ITS registers but 6762306a36Sopenharmony_ci the GITS_CTLR must be restored before restoring the ITS tables. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci The GITS_IIDR read-only register must also be restored before 7062306a36Sopenharmony_ci calling KVM_DEV_ARM_ITS_RESTORE_TABLES as the IIDR revision field 7162306a36Sopenharmony_ci encodes the ABI revision. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci The expected ordering when restoring the GICv3/ITS is described in section 7462306a36Sopenharmony_ci "ITS Restore Sequence". 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci Errors: 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci ======= ========================================================== 7962306a36Sopenharmony_ci -ENXIO ITS not properly configured as required prior to setting 8062306a36Sopenharmony_ci this attribute 8162306a36Sopenharmony_ci -ENOMEM Memory shortage when allocating ITS internal data 8262306a36Sopenharmony_ci -EINVAL Inconsistent restored data 8362306a36Sopenharmony_ci -EFAULT Invalid guest ram access 8462306a36Sopenharmony_ci -EBUSY One or more VCPUS are running 8562306a36Sopenharmony_ci -EACCES The virtual ITS is backed by a physical GICv4 ITS, and the 8662306a36Sopenharmony_ci state is not available without GICv4.1 8762306a36Sopenharmony_ci ======= ========================================================== 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_ITS_REGS 9062306a36Sopenharmony_ci----------------------------- 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci Attributes: 9362306a36Sopenharmony_ci The attr field of kvm_device_attr encodes the offset of the 9462306a36Sopenharmony_ci ITS register, relative to the ITS control frame base address 9562306a36Sopenharmony_ci (ITS_base). 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci kvm_device_attr.addr points to a __u64 value whatever the width 9862306a36Sopenharmony_ci of the addressed register (32/64 bits). 64 bit registers can only 9962306a36Sopenharmony_ci be accessed with full length. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci Writes to read-only registers are ignored by the kernel except for: 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci - GITS_CREADR. It must be restored otherwise commands in the queue 10462306a36Sopenharmony_ci will be re-executed after restoring CWRITER. GITS_CREADR must be 10562306a36Sopenharmony_ci restored before restoring the GITS_CTLR which is likely to enable the 10662306a36Sopenharmony_ci ITS. Also it must be restored after GITS_CBASER since a write to 10762306a36Sopenharmony_ci GITS_CBASER resets GITS_CREADR. 10862306a36Sopenharmony_ci - GITS_IIDR. The Revision field encodes the table layout ABI revision. 10962306a36Sopenharmony_ci In the future we might implement direct injection of virtual LPIs. 11062306a36Sopenharmony_ci This will require an upgrade of the table layout and an evolution of 11162306a36Sopenharmony_ci the ABI. GITS_IIDR must be restored before calling 11262306a36Sopenharmony_ci KVM_DEV_ARM_ITS_RESTORE_TABLES. 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci For other registers, getting or setting a register has the same 11562306a36Sopenharmony_ci effect as reading/writing the register on real hardware. 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci Errors: 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci ======= ==================================================== 12062306a36Sopenharmony_ci -ENXIO Offset does not correspond to any supported register 12162306a36Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr 12262306a36Sopenharmony_ci -EINVAL Offset is not 64-bit aligned 12362306a36Sopenharmony_ci -EBUSY one or more VCPUS are running 12462306a36Sopenharmony_ci ======= ==================================================== 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ciITS Restore Sequence: 12762306a36Sopenharmony_ci--------------------- 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciThe following ordering must be followed when restoring the GIC and the ITS: 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cia) restore all guest memory and create vcpus 13262306a36Sopenharmony_cib) restore all redistributors 13362306a36Sopenharmony_cic) provide the ITS base address 13462306a36Sopenharmony_ci (KVM_DEV_ARM_VGIC_GRP_ADDR) 13562306a36Sopenharmony_cid) restore the ITS in the following order: 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci 1. Restore GITS_CBASER 13862306a36Sopenharmony_ci 2. Restore all other ``GITS_`` registers, except GITS_CTLR! 13962306a36Sopenharmony_ci 3. Load the ITS table data (KVM_DEV_ARM_ITS_RESTORE_TABLES) 14062306a36Sopenharmony_ci 4. Restore GITS_CTLR 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ciThen vcpus can be started. 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciITS Table ABI REV0: 14562306a36Sopenharmony_ci------------------- 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci Revision 0 of the ABI only supports the features of a virtual GICv3, and does 14862306a36Sopenharmony_ci not support a virtual GICv4 with support for direct injection of virtual 14962306a36Sopenharmony_ci interrupts for nested hypervisors. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci The device table and ITT are indexed by the DeviceID and EventID, 15262306a36Sopenharmony_ci respectively. The collection table is not indexed by CollectionID, and the 15362306a36Sopenharmony_ci entries in the collection are listed in no particular order. 15462306a36Sopenharmony_ci All entries are 8 bytes. 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci Device Table Entry (DTE):: 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | 15962306a36Sopenharmony_ci values: | V | next | ITT_addr | Size | 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci where: 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci - V indicates whether the entry is valid. If not, other fields 16462306a36Sopenharmony_ci are not meaningful. 16562306a36Sopenharmony_ci - next: equals to 0 if this entry is the last one; otherwise it 16662306a36Sopenharmony_ci corresponds to the DeviceID offset to the next DTE, capped by 16762306a36Sopenharmony_ci 2^14 -1. 16862306a36Sopenharmony_ci - ITT_addr matches bits [51:8] of the ITT address (256 Byte aligned). 16962306a36Sopenharmony_ci - Size specifies the supported number of bits for the EventID, 17062306a36Sopenharmony_ci minus one 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci Collection Table Entry (CTE):: 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | 17562306a36Sopenharmony_ci values: | V | RES0 | RDBase | ICID | 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci where: 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci - V indicates whether the entry is valid. If not, other fields are 18062306a36Sopenharmony_ci not meaningful. 18162306a36Sopenharmony_ci - RES0: reserved field with Should-Be-Zero-or-Preserved behavior. 18262306a36Sopenharmony_ci - RDBase is the PE number (GICR_TYPER.Processor_Number semantic), 18362306a36Sopenharmony_ci - ICID is the collection ID 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci Interrupt Translation Entry (ITE):: 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | 18862306a36Sopenharmony_ci values: | next | pINTID | ICID | 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci where: 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci - next: equals to 0 if this entry is the last one; otherwise it corresponds 19362306a36Sopenharmony_ci to the EventID offset to the next ITE capped by 2^16 -1. 19462306a36Sopenharmony_ci - pINTID is the physical LPI ID; if zero, it means the entry is not valid 19562306a36Sopenharmony_ci and other fields are not meaningful. 19662306a36Sopenharmony_ci - ICID is the collection ID 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ciITS Reset State: 19962306a36Sopenharmony_ci---------------- 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ciRESET returns the ITS to the same state that it was when first created and 20262306a36Sopenharmony_ciinitialized. When the RESET command returns, the following things are 20362306a36Sopenharmony_ciguaranteed: 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci- The ITS is not enabled and quiescent 20662306a36Sopenharmony_ci GITS_CTLR.Enabled = 0 .Quiescent=1 20762306a36Sopenharmony_ci- There is no internally cached state 20862306a36Sopenharmony_ci- No collection or device table are used 20962306a36Sopenharmony_ci GITS_BASER<n>.Valid = 0 21062306a36Sopenharmony_ci- GITS_CBASER = 0, GITS_CREADR = 0, GITS_CWRITER = 0 21162306a36Sopenharmony_ci- The ABI version is unchanged and remains the one set when the ITS 21262306a36Sopenharmony_ci device was first created. 213