1dd873966SEric Auger /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2c5daeae1SAlexey Kardashevskiy /* 3c5daeae1SAlexey Kardashevskiy * Copyright (C) 2012,2013 - ARM Ltd 4c5daeae1SAlexey Kardashevskiy * Author: Marc Zyngier <marc.zyngier@arm.com> 5c5daeae1SAlexey Kardashevskiy * 6c5daeae1SAlexey Kardashevskiy * Derived from arch/arm/include/uapi/asm/kvm.h: 7c5daeae1SAlexey Kardashevskiy * Copyright (C) 2012 - Virtual Open Systems and Columbia University 8c5daeae1SAlexey Kardashevskiy * Author: Christoffer Dall <c.dall@virtualopensystems.com> 9c5daeae1SAlexey Kardashevskiy * 10c5daeae1SAlexey Kardashevskiy * This program is free software; you can redistribute it and/or modify 11c5daeae1SAlexey Kardashevskiy * it under the terms of the GNU General Public License version 2 as 12c5daeae1SAlexey Kardashevskiy * published by the Free Software Foundation. 13c5daeae1SAlexey Kardashevskiy * 14c5daeae1SAlexey Kardashevskiy * This program is distributed in the hope that it will be useful, 15c5daeae1SAlexey Kardashevskiy * but WITHOUT ANY WARRANTY; without even the implied warranty of 16c5daeae1SAlexey Kardashevskiy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17c5daeae1SAlexey Kardashevskiy * GNU General Public License for more details. 18c5daeae1SAlexey Kardashevskiy * 19c5daeae1SAlexey Kardashevskiy * You should have received a copy of the GNU General Public License 20c5daeae1SAlexey Kardashevskiy * along with this program. If not, see <http://www.gnu.org/licenses/>. 21c5daeae1SAlexey Kardashevskiy */ 22c5daeae1SAlexey Kardashevskiy 23c5daeae1SAlexey Kardashevskiy #ifndef __ARM_KVM_H__ 24c5daeae1SAlexey Kardashevskiy #define __ARM_KVM_H__ 25c5daeae1SAlexey Kardashevskiy 26c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_EL1 0 27c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_SVC KVM_SPSR_EL1 28c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_ABT 1 29c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_UND 2 30c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_IRQ 3 31c5daeae1SAlexey Kardashevskiy #define KVM_SPSR_FIQ 4 32c5daeae1SAlexey Kardashevskiy #define KVM_NR_SPSR 5 33c5daeae1SAlexey Kardashevskiy 34c5daeae1SAlexey Kardashevskiy #ifndef __ASSEMBLY__ 35b061808dSAlexander Graf #include <linux/psci.h> 36fff02bc0SPaolo Bonzini #include <linux/types.h> 37c5daeae1SAlexey Kardashevskiy #include <asm/ptrace.h> 38d9cb4336SCornelia Huck #include <asm/sve_context.h> 39c5daeae1SAlexey Kardashevskiy 40c5daeae1SAlexey Kardashevskiy #define __KVM_HAVE_IRQ_LINE 418f3cd250SCornelia Huck #define __KVM_HAVE_VCPU_EVENTS 42c5daeae1SAlexey Kardashevskiy 4374c98e20SCornelia Huck #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 4493d7620cSAvihai Horon #define KVM_DIRTY_LOG_PAGE_OFFSET 64 4574c98e20SCornelia Huck 46c5daeae1SAlexey Kardashevskiy #define KVM_REG_SIZE(id) \ 47c5daeae1SAlexey Kardashevskiy (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 48c5daeae1SAlexey Kardashevskiy 49c5daeae1SAlexey Kardashevskiy struct kvm_regs { 50c5daeae1SAlexey Kardashevskiy struct user_pt_regs regs; /* sp = sp_el0 */ 51c5daeae1SAlexey Kardashevskiy 52c5daeae1SAlexey Kardashevskiy __u64 sp_el1; 53c5daeae1SAlexey Kardashevskiy __u64 elr_el1; 54c5daeae1SAlexey Kardashevskiy 55c5daeae1SAlexey Kardashevskiy __u64 spsr[KVM_NR_SPSR]; 56c5daeae1SAlexey Kardashevskiy 57c5daeae1SAlexey Kardashevskiy struct user_fpsimd_state fp_regs; 58c5daeae1SAlexey Kardashevskiy }; 59c5daeae1SAlexey Kardashevskiy 603a824b15SPaolo Bonzini /* 613a824b15SPaolo Bonzini * Supported CPU Targets - Adding a new target type is not recommended, 623a824b15SPaolo Bonzini * unless there are some special registers not supported by the 633a824b15SPaolo Bonzini * genericv8 syreg table. 643a824b15SPaolo Bonzini */ 65c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_AEM_V8 0 66c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_FOUNDATION_V8 1 67c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_CORTEX_A57 2 68876074c2SChristoffer Dall #define KVM_ARM_TARGET_XGENE_POTENZA 3 69b061808dSAlexander Graf #define KVM_ARM_TARGET_CORTEX_A53 4 703a824b15SPaolo Bonzini /* Generic ARM v8 target */ 713a824b15SPaolo Bonzini #define KVM_ARM_TARGET_GENERIC_V8 5 72c5daeae1SAlexey Kardashevskiy 733a824b15SPaolo Bonzini #define KVM_ARM_NUM_TARGETS 6 74c5daeae1SAlexey Kardashevskiy 75c5daeae1SAlexey Kardashevskiy /* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ 76c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_TYPE_SHIFT 0 77*ab0c7fb2SPaolo Bonzini #define KVM_ARM_DEVICE_TYPE_MASK __GENMASK(KVM_ARM_DEVICE_TYPE_SHIFT + 15, \ 78d525f73fSChenyi Qiang KVM_ARM_DEVICE_TYPE_SHIFT) 79c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_ID_SHIFT 16 80*ab0c7fb2SPaolo Bonzini #define KVM_ARM_DEVICE_ID_MASK __GENMASK(KVM_ARM_DEVICE_ID_SHIFT + 15, \ 81d525f73fSChenyi Qiang KVM_ARM_DEVICE_ID_SHIFT) 82c5daeae1SAlexey Kardashevskiy 83c5daeae1SAlexey Kardashevskiy /* Supported device IDs */ 84c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_VGIC_V2 0 85c5daeae1SAlexey Kardashevskiy 86c5daeae1SAlexey Kardashevskiy /* Supported VGIC address types */ 87c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_DIST 0 88c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_CPU 1 89c5daeae1SAlexey Kardashevskiy 90c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_DIST_SIZE 0x1000 91c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_CPU_SIZE 0x2000 92c5daeae1SAlexey Kardashevskiy 9351628b18SChristian Borntraeger /* Supported VGICv3 address types */ 9451628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_DIST 2 9551628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 96dbdfea92SCornelia Huck #define KVM_VGIC_ITS_ADDR_TYPE 4 9777d361b1SEric Auger #define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION 5 9851628b18SChristian Borntraeger 9951628b18SChristian Borntraeger #define KVM_VGIC_V3_DIST_SIZE SZ_64K 10051628b18SChristian Borntraeger #define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 101dbdfea92SCornelia Huck #define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) 10251628b18SChristian Borntraeger 103c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 104c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */ 105b061808dSAlexander Graf #define KVM_ARM_VCPU_PSCI_0_2 2 /* CPU uses PSCI v0.2 */ 106b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3 3 /* Support guest PMUv3 */ 107d9cb4336SCornelia Huck #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ 108d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ 109d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ 110c5c0fdbeSDavid 'Digit' Turner #define KVM_ARM_VCPU_HAS_EL2 7 /* Support nested virtualization */ 111c5daeae1SAlexey Kardashevskiy 112c5daeae1SAlexey Kardashevskiy struct kvm_vcpu_init { 113c5daeae1SAlexey Kardashevskiy __u32 target; 114c5daeae1SAlexey Kardashevskiy __u32 features[7]; 115c5daeae1SAlexey Kardashevskiy }; 116c5daeae1SAlexey Kardashevskiy 117c5daeae1SAlexey Kardashevskiy struct kvm_sregs { 118c5daeae1SAlexey Kardashevskiy }; 119c5daeae1SAlexey Kardashevskiy 120c5daeae1SAlexey Kardashevskiy struct kvm_fpu { 121c5daeae1SAlexey Kardashevskiy }; 122c5daeae1SAlexey Kardashevskiy 1233a824b15SPaolo Bonzini /* 1243a824b15SPaolo Bonzini * See v8 ARM ARM D7.3: Debug Registers 1253a824b15SPaolo Bonzini * 1263a824b15SPaolo Bonzini * The architectural limit is 16 debug registers of each type although 1273a824b15SPaolo Bonzini * in practice there are usually less (see ID_AA64DFR0_EL1). 1283a824b15SPaolo Bonzini * 1293a824b15SPaolo Bonzini * Although the control registers are architecturally defined as 32 1303a824b15SPaolo Bonzini * bits wide we use a 64 bit structure here to keep parity with 1313a824b15SPaolo Bonzini * KVM_GET/SET_ONE_REG behaviour which treats all system registers as 1323a824b15SPaolo Bonzini * 64 bit values. It also allows for the possibility of the 1333a824b15SPaolo Bonzini * architecture expanding the control registers without having to 1343a824b15SPaolo Bonzini * change the userspace ABI. 1353a824b15SPaolo Bonzini */ 1363a824b15SPaolo Bonzini #define KVM_ARM_MAX_DBG_REGS 16 137c5daeae1SAlexey Kardashevskiy struct kvm_guest_debug_arch { 1383a824b15SPaolo Bonzini __u64 dbg_bcr[KVM_ARM_MAX_DBG_REGS]; 1393a824b15SPaolo Bonzini __u64 dbg_bvr[KVM_ARM_MAX_DBG_REGS]; 1403a824b15SPaolo Bonzini __u64 dbg_wcr[KVM_ARM_MAX_DBG_REGS]; 1413a824b15SPaolo Bonzini __u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS]; 142c5daeae1SAlexey Kardashevskiy }; 143c5daeae1SAlexey Kardashevskiy 144d525f73fSChenyi Qiang #define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0) 145c5daeae1SAlexey Kardashevskiy struct kvm_debug_exit_arch { 1463a824b15SPaolo Bonzini __u32 hsr; 147d525f73fSChenyi Qiang __u32 hsr_high; /* ESR_EL2[61:32] */ 1483a824b15SPaolo Bonzini __u64 far; /* used for watchpoints */ 149c5daeae1SAlexey Kardashevskiy }; 150c5daeae1SAlexey Kardashevskiy 1513a824b15SPaolo Bonzini /* 1523a824b15SPaolo Bonzini * Architecture specific defines for kvm_guest_debug->control 1533a824b15SPaolo Bonzini */ 1543a824b15SPaolo Bonzini 1553a824b15SPaolo Bonzini #define KVM_GUESTDBG_USE_SW_BP (1 << 16) 1563a824b15SPaolo Bonzini #define KVM_GUESTDBG_USE_HW (1 << 17) 1573a824b15SPaolo Bonzini 158c5daeae1SAlexey Kardashevskiy struct kvm_sync_regs { 15974c98e20SCornelia Huck /* Used with KVM_CAP_ARM_USER_IRQ */ 16074c98e20SCornelia Huck __u64 device_irq_level; 161c5daeae1SAlexey Kardashevskiy }; 162c5daeae1SAlexey Kardashevskiy 163*ab0c7fb2SPaolo Bonzini /* Bits for run->s.regs.device_irq_level */ 164*ab0c7fb2SPaolo Bonzini #define KVM_ARM_DEV_EL1_VTIMER (1 << 0) 165*ab0c7fb2SPaolo Bonzini #define KVM_ARM_DEV_EL1_PTIMER (1 << 1) 166*ab0c7fb2SPaolo Bonzini #define KVM_ARM_DEV_PMU (1 << 2) 167*ab0c7fb2SPaolo Bonzini 16853ba2eeeSMatthew Rosato /* 16953ba2eeeSMatthew Rosato * PMU filter structure. Describe a range of events with a particular 17053ba2eeeSMatthew Rosato * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER. 17153ba2eeeSMatthew Rosato */ 17253ba2eeeSMatthew Rosato struct kvm_pmu_event_filter { 17353ba2eeeSMatthew Rosato __u16 base_event; 17453ba2eeeSMatthew Rosato __u16 nevents; 17553ba2eeeSMatthew Rosato 17653ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_ALLOW 0 17753ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_DENY 1 17853ba2eeeSMatthew Rosato 17953ba2eeeSMatthew Rosato __u8 action; 18053ba2eeeSMatthew Rosato __u8 pad[3]; 18153ba2eeeSMatthew Rosato }; 18253ba2eeeSMatthew Rosato 1838f3cd250SCornelia Huck /* for KVM_GET/SET_VCPU_EVENTS */ 1848f3cd250SCornelia Huck struct kvm_vcpu_events { 1858f3cd250SCornelia Huck struct { 1868f3cd250SCornelia Huck __u8 serror_pending; 1878f3cd250SCornelia Huck __u8 serror_has_esr; 1882a886794SGreg Kurz __u8 ext_dabt_pending; 1898f3cd250SCornelia Huck /* Align it to 8 bytes */ 1902a886794SGreg Kurz __u8 pad[5]; 1918f3cd250SCornelia Huck __u64 serror_esr; 1928f3cd250SCornelia Huck } exception; 1938f3cd250SCornelia Huck __u32 reserved[12]; 1948f3cd250SCornelia Huck }; 1958f3cd250SCornelia Huck 196327d4b7fSBharata B Rao struct kvm_arm_copy_mte_tags { 197327d4b7fSBharata B Rao __u64 guest_ipa; 198327d4b7fSBharata B Rao __u64 length; 199327d4b7fSBharata B Rao void *addr; 200327d4b7fSBharata B Rao __u64 flags; 201327d4b7fSBharata B Rao __u64 reserved[2]; 202327d4b7fSBharata B Rao }; 203327d4b7fSBharata B Rao 204d0bf492fSCédric Le Goater /* 205d0bf492fSCédric Le Goater * Counter/Timer offset structure. Describe the virtual/physical offset. 206d0bf492fSCédric Le Goater * To be used with KVM_ARM_SET_COUNTER_OFFSET. 207d0bf492fSCédric Le Goater */ 208d0bf492fSCédric Le Goater struct kvm_arm_counter_offset { 209d0bf492fSCédric Le Goater __u64 counter_offset; 210d0bf492fSCédric Le Goater __u64 reserved; 211d0bf492fSCédric Le Goater }; 212d0bf492fSCédric Le Goater 213327d4b7fSBharata B Rao #define KVM_ARM_TAGS_TO_GUEST 0 214327d4b7fSBharata B Rao #define KVM_ARM_TAGS_FROM_GUEST 1 215327d4b7fSBharata B Rao 216c5daeae1SAlexey Kardashevskiy /* If you need to interpret the index values, here is the key: */ 217c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 218c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_SHIFT 16 219c5daeae1SAlexey Kardashevskiy 220c5daeae1SAlexey Kardashevskiy /* Normal registers are mapped as coprocessor 16. */ 221c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT) 222c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / sizeof(__u32)) 223c5daeae1SAlexey Kardashevskiy 224c5daeae1SAlexey Kardashevskiy /* Some registers need more space to represent values. */ 225c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT) 226c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00 227c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_SHIFT 8 228c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT) 229c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF 230c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_SHIFT 0 231c5daeae1SAlexey Kardashevskiy 232c5daeae1SAlexey Kardashevskiy /* AArch64 system registers */ 233c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG (0x0013 << KVM_REG_ARM_COPROC_SHIFT) 234c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_MASK 0x000000000000c000 235c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_SHIFT 14 236c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_MASK 0x0000000000003800 237c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_SHIFT 11 238c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_MASK 0x0000000000000780 239c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_SHIFT 7 240c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_MASK 0x0000000000000078 241c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_SHIFT 3 242c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_MASK 0x0000000000000007 243c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_SHIFT 0 244c5daeae1SAlexey Kardashevskiy 245876074c2SChristoffer Dall #define ARM64_SYS_REG_SHIFT_MASK(x,n) \ 246876074c2SChristoffer Dall (((x) << KVM_REG_ARM64_SYSREG_ ## n ## _SHIFT) & \ 247876074c2SChristoffer Dall KVM_REG_ARM64_SYSREG_ ## n ## _MASK) 248876074c2SChristoffer Dall 249876074c2SChristoffer Dall #define __ARM64_SYS_REG(op0,op1,crn,crm,op2) \ 250876074c2SChristoffer Dall (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ 251876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ 252876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ 253876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ 254876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ 255876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) 256876074c2SChristoffer Dall 257876074c2SChristoffer Dall #define ARM64_SYS_REG(...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) 258876074c2SChristoffer Dall 259dd873966SEric Auger /* Physical Timer EL0 Registers */ 260dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CTL ARM64_SYS_REG(3, 3, 14, 2, 1) 261dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CVAL ARM64_SYS_REG(3, 3, 14, 2, 2) 262dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CNT ARM64_SYS_REG(3, 3, 14, 0, 1) 263dd873966SEric Auger 264ddda3748SCornelia Huck /* 265ddda3748SCornelia Huck * EL0 Virtual Timer Registers 266ddda3748SCornelia Huck * 267ddda3748SCornelia Huck * WARNING: 268ddda3748SCornelia Huck * KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT are not defined 269ddda3748SCornelia Huck * with the appropriate register encodings. Their values have been 270ddda3748SCornelia Huck * accidentally swapped. As this is set API, the definitions here 271ddda3748SCornelia Huck * must be used, rather than ones derived from the encodings. 272ddda3748SCornelia Huck */ 273876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1) 274876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2) 275ddda3748SCornelia Huck #define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2) 276876074c2SChristoffer Dall 27765a6d8ddSPeter Maydell /* KVM-as-firmware specific pseudo-registers */ 27865a6d8ddSPeter Maydell #define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT) 27965a6d8ddSPeter Maydell #define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ 28065a6d8ddSPeter Maydell KVM_REG_ARM_FW | ((r) & 0xffff)) 28165a6d8ddSPeter Maydell #define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) 282f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1 KVM_REG_ARM_FW_REG(1) 283f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL 0 284f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL 1 285f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED 2 28653ba2eeeSMatthew Rosato 28753ba2eeeSMatthew Rosato /* 28853ba2eeeSMatthew Rosato * Only two states can be presented by the host kernel: 28953ba2eeeSMatthew Rosato * - NOT_REQUIRED: the guest doesn't need to do anything 29053ba2eeeSMatthew Rosato * - NOT_AVAIL: the guest isn't mitigated (it can still use SSBS if available) 29153ba2eeeSMatthew Rosato * 29253ba2eeeSMatthew Rosato * All the other values are deprecated. The host still accepts all 29353ba2eeeSMatthew Rosato * values (they are ABI), but will narrow them to the above two. 29453ba2eeeSMatthew Rosato */ 295f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2 KVM_REG_ARM_FW_REG(2) 296f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL 0 297f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN 1 298f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL 2 299f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED 3 300f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED (1U << 4) 30165a6d8ddSPeter Maydell 302e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3 KVM_REG_ARM_FW_REG(3) 303e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL 0 304e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_AVAIL 1 305e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_REQUIRED 2 306e4082063SAlex Williamson 307d9cb4336SCornelia Huck /* SVE registers */ 308d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) 309d9cb4336SCornelia Huck 310d9cb4336SCornelia Huck /* Z- and P-regs occupy blocks at the following offsets within this range: */ 311d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG_BASE 0 312d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG_BASE 0x400 313d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR_BASE 0x600 314d9cb4336SCornelia Huck 315d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_ZREGS __SVE_NUM_ZREGS 316d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_PREGS __SVE_NUM_PREGS 317d9cb4336SCornelia Huck 318d9cb4336SCornelia Huck #define KVM_ARM64_SVE_MAX_SLICES 32 319d9cb4336SCornelia Huck 320d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG(n, i) \ 321d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_ZREG_BASE | \ 322d9cb4336SCornelia Huck KVM_REG_SIZE_U2048 | \ 323d9cb4336SCornelia Huck (((n) & (KVM_ARM64_SVE_NUM_ZREGS - 1)) << 5) | \ 324d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 325d9cb4336SCornelia Huck 326d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG(n, i) \ 327d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_PREG_BASE | \ 328d9cb4336SCornelia Huck KVM_REG_SIZE_U256 | \ 329d9cb4336SCornelia Huck (((n) & (KVM_ARM64_SVE_NUM_PREGS - 1)) << 5) | \ 330d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 331d9cb4336SCornelia Huck 332d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR(i) \ 333d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_FFR_BASE | \ 334d9cb4336SCornelia Huck KVM_REG_SIZE_U256 | \ 335d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 336d9cb4336SCornelia Huck 337f363d039SEric Auger /* 338f363d039SEric Auger * Register values for KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() and 339f363d039SEric Auger * KVM_REG_ARM64_SVE_FFR() are represented in memory in an endianness- 340f363d039SEric Auger * invariant layout which differs from the layout used for the FPSIMD 341f363d039SEric Auger * V-registers on big-endian systems: see sigcontext.h for more explanation. 342f363d039SEric Auger */ 343f363d039SEric Auger 344d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN 345d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX 346d9cb4336SCornelia Huck 347d9cb4336SCornelia Huck /* Vector lengths pseudo-register: */ 348d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ 349d9cb4336SCornelia Huck KVM_REG_SIZE_U512 | 0xffff) 350d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VLS_WORDS \ 351d9cb4336SCornelia Huck ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1) 352d9cb4336SCornelia Huck 353d525f73fSChenyi Qiang /* Bitmap feature firmware registers */ 354d525f73fSChenyi Qiang #define KVM_REG_ARM_FW_FEAT_BMAP (0x0016 << KVM_REG_ARM_COPROC_SHIFT) 355d525f73fSChenyi Qiang #define KVM_REG_ARM_FW_FEAT_BMAP_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ 356d525f73fSChenyi Qiang KVM_REG_ARM_FW_FEAT_BMAP | \ 357d525f73fSChenyi Qiang ((r) & 0xffff)) 358d525f73fSChenyi Qiang 359d525f73fSChenyi Qiang #define KVM_REG_ARM_STD_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(0) 360d525f73fSChenyi Qiang 361d525f73fSChenyi Qiang enum { 362d525f73fSChenyi Qiang KVM_REG_ARM_STD_BIT_TRNG_V1_0 = 0, 363d525f73fSChenyi Qiang }; 364d525f73fSChenyi Qiang 365d525f73fSChenyi Qiang #define KVM_REG_ARM_STD_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(1) 366d525f73fSChenyi Qiang 367d525f73fSChenyi Qiang enum { 368d525f73fSChenyi Qiang KVM_REG_ARM_STD_HYP_BIT_PV_TIME = 0, 369d525f73fSChenyi Qiang }; 370d525f73fSChenyi Qiang 371d525f73fSChenyi Qiang #define KVM_REG_ARM_VENDOR_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(2) 372d525f73fSChenyi Qiang 373d525f73fSChenyi Qiang enum { 374d525f73fSChenyi Qiang KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT = 0, 375d525f73fSChenyi Qiang KVM_REG_ARM_VENDOR_HYP_BIT_PTP = 1, 376d525f73fSChenyi Qiang }; 377d525f73fSChenyi Qiang 378d0bf492fSCédric Le Goater /* Device Control API on vm fd */ 379d0bf492fSCédric Le Goater #define KVM_ARM_VM_SMCCC_CTRL 0 380d0bf492fSCédric Le Goater #define KVM_ARM_VM_SMCCC_FILTER 0 381d0bf492fSCédric Le Goater 382876074c2SChristoffer Dall /* Device Control API: ARM VGIC */ 383876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 384876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 385876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 386876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 387876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 3883a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 3893a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ 3903a5eb5b4SPaolo Bonzini (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT) 391876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 392876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 3933a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff) 394444b1996SArd Biesheuvel #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 39551628b18SChristian Borntraeger #define KVM_DEV_ARM_VGIC_GRP_CTRL 4 3963a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 3973a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 3983a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 39974c98e20SCornelia Huck #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 4003a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 4013a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ 4023a5eb5b4SPaolo Bonzini (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) 4033a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff 4043a5eb5b4SPaolo Bonzini #define VGIC_LEVEL_INFO_LINE_LEVEL 0 4053a5eb5b4SPaolo Bonzini 40651628b18SChristian Borntraeger #define KVM_DEV_ARM_VGIC_CTRL_INIT 0 40774c98e20SCornelia Huck #define KVM_DEV_ARM_ITS_SAVE_TABLES 1 40874c98e20SCornelia Huck #define KVM_DEV_ARM_ITS_RESTORE_TABLES 2 40974c98e20SCornelia Huck #define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 410dd873966SEric Auger #define KVM_DEV_ARM_ITS_CTRL_RESET 4 411876074c2SChristoffer Dall 412b89485a5SPaolo Bonzini /* Device Control API on vcpu fd */ 413b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_CTRL 0 414b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_IRQ 0 415b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_INIT 1 41653ba2eeeSMatthew Rosato #define KVM_ARM_VCPU_PMU_V3_FILTER 2 417e4082063SAlex Williamson #define KVM_ARM_VCPU_PMU_V3_SET_PMU 3 4183272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_CTRL 1 4193272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 4203272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 421d0bf492fSCédric Le Goater #define KVM_ARM_VCPU_TIMER_IRQ_HVTIMER 2 422d0bf492fSCédric Le Goater #define KVM_ARM_VCPU_TIMER_IRQ_HPTIMER 3 4232a886794SGreg Kurz #define KVM_ARM_VCPU_PVTIME_CTRL 2 4242a886794SGreg Kurz #define KVM_ARM_VCPU_PVTIME_IPA 0 425b89485a5SPaolo Bonzini 426c5daeae1SAlexey Kardashevskiy /* KVM_IRQ_LINE irq field index values */ 427f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_SHIFT 28 428f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_MASK 0xf 429c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SHIFT 24 430f363d039SEric Auger #define KVM_ARM_IRQ_TYPE_MASK 0xf 431c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_SHIFT 16 432c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_MASK 0xff 433c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_SHIFT 0 434c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_MASK 0xffff 435c5daeae1SAlexey Kardashevskiy 436c5daeae1SAlexey Kardashevskiy /* irq_type field */ 437c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_CPU 0 438c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SPI 1 439c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_PPI 2 440c5daeae1SAlexey Kardashevskiy 441c5daeae1SAlexey Kardashevskiy /* out-of-kernel GIC cpu interrupt injection irq_number field */ 442c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_IRQ 0 443c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_FIQ 1 444c5daeae1SAlexey Kardashevskiy 4457a52ce8aSCornelia Huck /* 4467a52ce8aSCornelia Huck * This used to hold the highest supported SPI, but it is now obsolete 4477a52ce8aSCornelia Huck * and only here to provide source code level compatibility with older 4487a52ce8aSCornelia Huck * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS. 4497a52ce8aSCornelia Huck */ 450c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_GIC_MAX 127 451c5daeae1SAlexey Kardashevskiy 4527a52ce8aSCornelia Huck /* One single KVM irqchip, ie. the VGIC */ 4537a52ce8aSCornelia Huck #define KVM_NR_IRQCHIPS 1 4547a52ce8aSCornelia Huck 455c5daeae1SAlexey Kardashevskiy /* PSCI interface */ 456c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_BASE 0x95c1ba5e 457c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n)) 458c5daeae1SAlexey Kardashevskiy 459c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) 460c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) 461c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) 462c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) 463c5daeae1SAlexey Kardashevskiy 464b061808dSAlexander Graf #define KVM_PSCI_RET_SUCCESS PSCI_RET_SUCCESS 465b061808dSAlexander Graf #define KVM_PSCI_RET_NI PSCI_RET_NOT_SUPPORTED 466b061808dSAlexander Graf #define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS 467b061808dSAlexander Graf #define KVM_PSCI_RET_DENIED PSCI_RET_DENIED 468c5daeae1SAlexey Kardashevskiy 469e4082063SAlex Williamson /* arm64-specific kvm_run::system_event flags */ 470e4082063SAlex Williamson /* 471e4082063SAlex Williamson * Reset caused by a PSCI v1.1 SYSTEM_RESET2 call. 472e4082063SAlex Williamson * Valid only when the system event has a type of KVM_SYSTEM_EVENT_RESET. 473e4082063SAlex Williamson */ 474e4082063SAlex Williamson #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (1ULL << 0) 475e4082063SAlex Williamson 476e4082063SAlex Williamson /* run->fail_entry.hardware_entry_failure_reason codes. */ 477e4082063SAlex Williamson #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) 478e4082063SAlex Williamson 479d0bf492fSCédric Le Goater enum kvm_smccc_filter_action { 480d0bf492fSCédric Le Goater KVM_SMCCC_FILTER_HANDLE = 0, 481d0bf492fSCédric Le Goater KVM_SMCCC_FILTER_DENY, 482d0bf492fSCédric Le Goater KVM_SMCCC_FILTER_FWD_TO_USER, 483d0bf492fSCédric Le Goater 484d0bf492fSCédric Le Goater }; 485d0bf492fSCédric Le Goater 486d0bf492fSCédric Le Goater struct kvm_smccc_filter { 487d0bf492fSCédric Le Goater __u32 base; 488d0bf492fSCédric Le Goater __u32 nr_functions; 489d0bf492fSCédric Le Goater __u8 action; 490d0bf492fSCédric Le Goater __u8 pad[15]; 491d0bf492fSCédric Le Goater }; 492d0bf492fSCédric Le Goater 493d0bf492fSCédric Le Goater /* arm64-specific KVM_EXIT_HYPERCALL flags */ 494d0bf492fSCédric Le Goater #define KVM_HYPERCALL_EXIT_SMC (1U << 0) 495d0bf492fSCédric Le Goater #define KVM_HYPERCALL_EXIT_16BIT (1U << 1) 496d0bf492fSCédric Le Goater 497efb91426SDaniel Henrique Barboza /* 498efb91426SDaniel Henrique Barboza * Get feature ID registers userspace writable mask. 499efb91426SDaniel Henrique Barboza * 500efb91426SDaniel Henrique Barboza * From DDI0487J.a, D19.2.66 ("ID_AA64MMFR2_EL1, AArch64 Memory Model 501efb91426SDaniel Henrique Barboza * Feature Register 2"): 502efb91426SDaniel Henrique Barboza * 503efb91426SDaniel Henrique Barboza * "The Feature ID space is defined as the System register space in 504efb91426SDaniel Henrique Barboza * AArch64 with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, 505efb91426SDaniel Henrique Barboza * op2=={0-7}." 506efb91426SDaniel Henrique Barboza * 507efb91426SDaniel Henrique Barboza * This covers all currently known R/O registers that indicate 508efb91426SDaniel Henrique Barboza * anything useful feature wise, including the ID registers. 509efb91426SDaniel Henrique Barboza * 510efb91426SDaniel Henrique Barboza * If we ever need to introduce a new range, it will be described as 511efb91426SDaniel Henrique Barboza * such in the range field. 512efb91426SDaniel Henrique Barboza */ 513efb91426SDaniel Henrique Barboza #define KVM_ARM_FEATURE_ID_RANGE_IDX(op0, op1, crn, crm, op2) \ 514efb91426SDaniel Henrique Barboza ({ \ 515efb91426SDaniel Henrique Barboza __u64 __op1 = (op1) & 3; \ 516efb91426SDaniel Henrique Barboza __op1 -= (__op1 == 3); \ 517efb91426SDaniel Henrique Barboza (__op1 << 6 | ((crm) & 7) << 3 | (op2)); \ 518efb91426SDaniel Henrique Barboza }) 519efb91426SDaniel Henrique Barboza 520efb91426SDaniel Henrique Barboza #define KVM_ARM_FEATURE_ID_RANGE 0 521efb91426SDaniel Henrique Barboza #define KVM_ARM_FEATURE_ID_RANGE_SIZE (3 * 8 * 8) 522efb91426SDaniel Henrique Barboza 523efb91426SDaniel Henrique Barboza struct reg_mask_range { 524efb91426SDaniel Henrique Barboza __u64 addr; /* Pointer to mask array */ 525efb91426SDaniel Henrique Barboza __u32 range; /* Requested range */ 526efb91426SDaniel Henrique Barboza __u32 reserved[13]; 527efb91426SDaniel Henrique Barboza }; 528efb91426SDaniel Henrique Barboza 529c5daeae1SAlexey Kardashevskiy #endif 530c5daeae1SAlexey Kardashevskiy 531c5daeae1SAlexey Kardashevskiy #endif /* __ARM_KVM_H__ */ 532