18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=============================================== 48c2ecf20Sopenharmony_ciARM Virtual Interrupt Translation Service (ITS) 58c2ecf20Sopenharmony_ci=============================================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciDevice types supported: 88c2ecf20Sopenharmony_ci KVM_DEV_TYPE_ARM_VGIC_ITS ARM Interrupt Translation Service Controller 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciThe ITS allows MSI(-X) interrupts to be injected into guests. This extension is 118c2ecf20Sopenharmony_cioptional. Creating a virtual ITS controller also requires a host GICv3 (see 128c2ecf20Sopenharmony_ciarm-vgic-v3.txt), but does not depend on having physical ITS controllers. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciThere can be multiple ITS controllers per guest, each of them has to have 158c2ecf20Sopenharmony_cia separate, non-overlapping MMIO region. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciGroups 198c2ecf20Sopenharmony_ci====== 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_ADDR 228c2ecf20Sopenharmony_ci------------------------- 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci Attributes: 258c2ecf20Sopenharmony_ci KVM_VGIC_ITS_ADDR_TYPE (rw, 64-bit) 268c2ecf20Sopenharmony_ci Base address in the guest physical address space of the GICv3 ITS 278c2ecf20Sopenharmony_ci control register frame. 288c2ecf20Sopenharmony_ci This address needs to be 64K aligned and the region covers 128K. 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci Errors: 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci ======= ================================================= 338c2ecf20Sopenharmony_ci -E2BIG Address outside of addressable IPA range 348c2ecf20Sopenharmony_ci -EINVAL Incorrectly aligned address 358c2ecf20Sopenharmony_ci -EEXIST Address already configured 368c2ecf20Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr. 378c2ecf20Sopenharmony_ci -ENODEV Incorrect attribute or the ITS is not supported. 388c2ecf20Sopenharmony_ci ======= ================================================= 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_CTRL 428c2ecf20Sopenharmony_ci------------------------- 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci Attributes: 458c2ecf20Sopenharmony_ci KVM_DEV_ARM_VGIC_CTRL_INIT 468c2ecf20Sopenharmony_ci request the initialization of the ITS, no additional parameter in 478c2ecf20Sopenharmony_ci kvm_device_attr.addr. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci KVM_DEV_ARM_ITS_CTRL_RESET 508c2ecf20Sopenharmony_ci reset the ITS, no additional parameter in kvm_device_attr.addr. 518c2ecf20Sopenharmony_ci See "ITS Reset State" section. 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci KVM_DEV_ARM_ITS_SAVE_TABLES 548c2ecf20Sopenharmony_ci save the ITS table data into guest RAM, at the location provisioned 558c2ecf20Sopenharmony_ci by the guest in corresponding registers/table entries. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci The layout of the tables in guest memory defines an ABI. The entries 588c2ecf20Sopenharmony_ci are laid out in little endian format as described in the last paragraph. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci KVM_DEV_ARM_ITS_RESTORE_TABLES 618c2ecf20Sopenharmony_ci restore the ITS tables from guest RAM to ITS internal structures. 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci The GICV3 must be restored before the ITS and all ITS registers but 648c2ecf20Sopenharmony_ci the GITS_CTLR must be restored before restoring the ITS tables. 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci The GITS_IIDR read-only register must also be restored before 678c2ecf20Sopenharmony_ci calling KVM_DEV_ARM_ITS_RESTORE_TABLES as the IIDR revision field 688c2ecf20Sopenharmony_ci encodes the ABI revision. 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci The expected ordering when restoring the GICv3/ITS is described in section 718c2ecf20Sopenharmony_ci "ITS Restore Sequence". 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci Errors: 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci ======= ========================================================== 768c2ecf20Sopenharmony_ci -ENXIO ITS not properly configured as required prior to setting 778c2ecf20Sopenharmony_ci this attribute 788c2ecf20Sopenharmony_ci -ENOMEM Memory shortage when allocating ITS internal data 798c2ecf20Sopenharmony_ci -EINVAL Inconsistent restored data 808c2ecf20Sopenharmony_ci -EFAULT Invalid guest ram access 818c2ecf20Sopenharmony_ci -EBUSY One or more VCPUS are running 828c2ecf20Sopenharmony_ci -EACCES The virtual ITS is backed by a physical GICv4 ITS, and the 838c2ecf20Sopenharmony_ci state is not available 848c2ecf20Sopenharmony_ci ======= ========================================================== 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciKVM_DEV_ARM_VGIC_GRP_ITS_REGS 878c2ecf20Sopenharmony_ci----------------------------- 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci Attributes: 908c2ecf20Sopenharmony_ci The attr field of kvm_device_attr encodes the offset of the 918c2ecf20Sopenharmony_ci ITS register, relative to the ITS control frame base address 928c2ecf20Sopenharmony_ci (ITS_base). 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci kvm_device_attr.addr points to a __u64 value whatever the width 958c2ecf20Sopenharmony_ci of the addressed register (32/64 bits). 64 bit registers can only 968c2ecf20Sopenharmony_ci be accessed with full length. 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci Writes to read-only registers are ignored by the kernel except for: 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci - GITS_CREADR. It must be restored otherwise commands in the queue 1018c2ecf20Sopenharmony_ci will be re-executed after restoring CWRITER. GITS_CREADR must be 1028c2ecf20Sopenharmony_ci restored before restoring the GITS_CTLR which is likely to enable the 1038c2ecf20Sopenharmony_ci ITS. Also it must be restored after GITS_CBASER since a write to 1048c2ecf20Sopenharmony_ci GITS_CBASER resets GITS_CREADR. 1058c2ecf20Sopenharmony_ci - GITS_IIDR. The Revision field encodes the table layout ABI revision. 1068c2ecf20Sopenharmony_ci In the future we might implement direct injection of virtual LPIs. 1078c2ecf20Sopenharmony_ci This will require an upgrade of the table layout and an evolution of 1088c2ecf20Sopenharmony_ci the ABI. GITS_IIDR must be restored before calling 1098c2ecf20Sopenharmony_ci KVM_DEV_ARM_ITS_RESTORE_TABLES. 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci For other registers, getting or setting a register has the same 1128c2ecf20Sopenharmony_ci effect as reading/writing the register on real hardware. 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci Errors: 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci ======= ==================================================== 1178c2ecf20Sopenharmony_ci -ENXIO Offset does not correspond to any supported register 1188c2ecf20Sopenharmony_ci -EFAULT Invalid user pointer for attr->addr 1198c2ecf20Sopenharmony_ci -EINVAL Offset is not 64-bit aligned 1208c2ecf20Sopenharmony_ci -EBUSY one or more VCPUS are running 1218c2ecf20Sopenharmony_ci ======= ==================================================== 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciITS Restore Sequence: 1248c2ecf20Sopenharmony_ci--------------------- 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciThe following ordering must be followed when restoring the GIC and the ITS: 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cia) restore all guest memory and create vcpus 1298c2ecf20Sopenharmony_cib) restore all redistributors 1308c2ecf20Sopenharmony_cic) provide the ITS base address 1318c2ecf20Sopenharmony_ci (KVM_DEV_ARM_VGIC_GRP_ADDR) 1328c2ecf20Sopenharmony_cid) restore the ITS in the following order: 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci 1. Restore GITS_CBASER 1358c2ecf20Sopenharmony_ci 2. Restore all other ``GITS_`` registers, except GITS_CTLR! 1368c2ecf20Sopenharmony_ci 3. Load the ITS table data (KVM_DEV_ARM_ITS_RESTORE_TABLES) 1378c2ecf20Sopenharmony_ci 4. Restore GITS_CTLR 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciThen vcpus can be started. 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ciITS Table ABI REV0: 1428c2ecf20Sopenharmony_ci------------------- 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci Revision 0 of the ABI only supports the features of a virtual GICv3, and does 1458c2ecf20Sopenharmony_ci not support a virtual GICv4 with support for direct injection of virtual 1468c2ecf20Sopenharmony_ci interrupts for nested hypervisors. 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci The device table and ITT are indexed by the DeviceID and EventID, 1498c2ecf20Sopenharmony_ci respectively. The collection table is not indexed by CollectionID, and the 1508c2ecf20Sopenharmony_ci entries in the collection are listed in no particular order. 1518c2ecf20Sopenharmony_ci All entries are 8 bytes. 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci Device Table Entry (DTE):: 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | 1568c2ecf20Sopenharmony_ci values: | V | next | ITT_addr | Size | 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci where: 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci - V indicates whether the entry is valid. If not, other fields 1618c2ecf20Sopenharmony_ci are not meaningful. 1628c2ecf20Sopenharmony_ci - next: equals to 0 if this entry is the last one; otherwise it 1638c2ecf20Sopenharmony_ci corresponds to the DeviceID offset to the next DTE, capped by 1648c2ecf20Sopenharmony_ci 2^14 -1. 1658c2ecf20Sopenharmony_ci - ITT_addr matches bits [51:8] of the ITT address (256 Byte aligned). 1668c2ecf20Sopenharmony_ci - Size specifies the supported number of bits for the EventID, 1678c2ecf20Sopenharmony_ci minus one 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci Collection Table Entry (CTE):: 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | 1728c2ecf20Sopenharmony_ci values: | V | RES0 | RDBase | ICID | 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci where: 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci - V indicates whether the entry is valid. If not, other fields are 1778c2ecf20Sopenharmony_ci not meaningful. 1788c2ecf20Sopenharmony_ci - RES0: reserved field with Should-Be-Zero-or-Preserved behavior. 1798c2ecf20Sopenharmony_ci - RDBase is the PE number (GICR_TYPER.Processor_Number semantic), 1808c2ecf20Sopenharmony_ci - ICID is the collection ID 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci Interrupt Translation Entry (ITE):: 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | 1858c2ecf20Sopenharmony_ci values: | next | pINTID | ICID | 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci where: 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci - next: equals to 0 if this entry is the last one; otherwise it corresponds 1908c2ecf20Sopenharmony_ci to the EventID offset to the next ITE capped by 2^16 -1. 1918c2ecf20Sopenharmony_ci - pINTID is the physical LPI ID; if zero, it means the entry is not valid 1928c2ecf20Sopenharmony_ci and other fields are not meaningful. 1938c2ecf20Sopenharmony_ci - ICID is the collection ID 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ciITS Reset State: 1968c2ecf20Sopenharmony_ci---------------- 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ciRESET returns the ITS to the same state that it was when first created and 1998c2ecf20Sopenharmony_ciinitialized. When the RESET command returns, the following things are 2008c2ecf20Sopenharmony_ciguaranteed: 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci- The ITS is not enabled and quiescent 2038c2ecf20Sopenharmony_ci GITS_CTLR.Enabled = 0 .Quiescent=1 2048c2ecf20Sopenharmony_ci- There is no internally cached state 2058c2ecf20Sopenharmony_ci- No collection or device table are used 2068c2ecf20Sopenharmony_ci GITS_BASER<n>.Valid = 0 2078c2ecf20Sopenharmony_ci- GITS_CBASER = 0, GITS_CREADR = 0, GITS_CWRITER = 0 2088c2ecf20Sopenharmony_ci- The ABI version is unchanged and remains the one set when the ITS 2098c2ecf20Sopenharmony_ci device was first created. 210