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_GUEST_DEBUG 41c5daeae1SAlexey Kardashevskiy #define __KVM_HAVE_IRQ_LINE 42444b1996SArd Biesheuvel #define __KVM_HAVE_READONLY_MEM 438f3cd250SCornelia Huck #define __KVM_HAVE_VCPU_EVENTS 44c5daeae1SAlexey Kardashevskiy 4574c98e20SCornelia Huck #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 4674c98e20SCornelia Huck 47c5daeae1SAlexey Kardashevskiy #define KVM_REG_SIZE(id) \ 48c5daeae1SAlexey Kardashevskiy (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 49c5daeae1SAlexey Kardashevskiy 50c5daeae1SAlexey Kardashevskiy struct kvm_regs { 51c5daeae1SAlexey Kardashevskiy struct user_pt_regs regs; /* sp = sp_el0 */ 52c5daeae1SAlexey Kardashevskiy 53c5daeae1SAlexey Kardashevskiy __u64 sp_el1; 54c5daeae1SAlexey Kardashevskiy __u64 elr_el1; 55c5daeae1SAlexey Kardashevskiy 56c5daeae1SAlexey Kardashevskiy __u64 spsr[KVM_NR_SPSR]; 57c5daeae1SAlexey Kardashevskiy 58c5daeae1SAlexey Kardashevskiy struct user_fpsimd_state fp_regs; 59c5daeae1SAlexey Kardashevskiy }; 60c5daeae1SAlexey Kardashevskiy 613a824b15SPaolo Bonzini /* 623a824b15SPaolo Bonzini * Supported CPU Targets - Adding a new target type is not recommended, 633a824b15SPaolo Bonzini * unless there are some special registers not supported by the 643a824b15SPaolo Bonzini * genericv8 syreg table. 653a824b15SPaolo Bonzini */ 66c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_AEM_V8 0 67c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_FOUNDATION_V8 1 68c5daeae1SAlexey Kardashevskiy #define KVM_ARM_TARGET_CORTEX_A57 2 69876074c2SChristoffer Dall #define KVM_ARM_TARGET_XGENE_POTENZA 3 70b061808dSAlexander Graf #define KVM_ARM_TARGET_CORTEX_A53 4 713a824b15SPaolo Bonzini /* Generic ARM v8 target */ 723a824b15SPaolo Bonzini #define KVM_ARM_TARGET_GENERIC_V8 5 73c5daeae1SAlexey Kardashevskiy 743a824b15SPaolo Bonzini #define KVM_ARM_NUM_TARGETS 6 75c5daeae1SAlexey Kardashevskiy 76c5daeae1SAlexey Kardashevskiy /* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ 77c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_TYPE_SHIFT 0 78c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_TYPE_MASK (0xffff << KVM_ARM_DEVICE_TYPE_SHIFT) 79c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_ID_SHIFT 16 80c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_ID_MASK (0xffff << KVM_ARM_DEVICE_ID_SHIFT) 81c5daeae1SAlexey Kardashevskiy 82c5daeae1SAlexey Kardashevskiy /* Supported device IDs */ 83c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_VGIC_V2 0 84c5daeae1SAlexey Kardashevskiy 85c5daeae1SAlexey Kardashevskiy /* Supported VGIC address types */ 86c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_DIST 0 87c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_CPU 1 88c5daeae1SAlexey Kardashevskiy 89c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_DIST_SIZE 0x1000 90c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_CPU_SIZE 0x2000 91c5daeae1SAlexey Kardashevskiy 9251628b18SChristian Borntraeger /* Supported VGICv3 address types */ 9351628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_DIST 2 9451628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 95dbdfea92SCornelia Huck #define KVM_VGIC_ITS_ADDR_TYPE 4 9677d361b1SEric Auger #define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION 5 9751628b18SChristian Borntraeger 9851628b18SChristian Borntraeger #define KVM_VGIC_V3_DIST_SIZE SZ_64K 9951628b18SChristian Borntraeger #define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 100dbdfea92SCornelia Huck #define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) 10151628b18SChristian Borntraeger 102c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 103c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */ 104b061808dSAlexander Graf #define KVM_ARM_VCPU_PSCI_0_2 2 /* CPU uses PSCI v0.2 */ 105b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3 3 /* Support guest PMUv3 */ 106d9cb4336SCornelia Huck #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ 107d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ 108d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ 109c5daeae1SAlexey Kardashevskiy 110c5daeae1SAlexey Kardashevskiy struct kvm_vcpu_init { 111c5daeae1SAlexey Kardashevskiy __u32 target; 112c5daeae1SAlexey Kardashevskiy __u32 features[7]; 113c5daeae1SAlexey Kardashevskiy }; 114c5daeae1SAlexey Kardashevskiy 115c5daeae1SAlexey Kardashevskiy struct kvm_sregs { 116c5daeae1SAlexey Kardashevskiy }; 117c5daeae1SAlexey Kardashevskiy 118c5daeae1SAlexey Kardashevskiy struct kvm_fpu { 119c5daeae1SAlexey Kardashevskiy }; 120c5daeae1SAlexey Kardashevskiy 1213a824b15SPaolo Bonzini /* 1223a824b15SPaolo Bonzini * See v8 ARM ARM D7.3: Debug Registers 1233a824b15SPaolo Bonzini * 1243a824b15SPaolo Bonzini * The architectural limit is 16 debug registers of each type although 1253a824b15SPaolo Bonzini * in practice there are usually less (see ID_AA64DFR0_EL1). 1263a824b15SPaolo Bonzini * 1273a824b15SPaolo Bonzini * Although the control registers are architecturally defined as 32 1283a824b15SPaolo Bonzini * bits wide we use a 64 bit structure here to keep parity with 1293a824b15SPaolo Bonzini * KVM_GET/SET_ONE_REG behaviour which treats all system registers as 1303a824b15SPaolo Bonzini * 64 bit values. It also allows for the possibility of the 1313a824b15SPaolo Bonzini * architecture expanding the control registers without having to 1323a824b15SPaolo Bonzini * change the userspace ABI. 1333a824b15SPaolo Bonzini */ 1343a824b15SPaolo Bonzini #define KVM_ARM_MAX_DBG_REGS 16 135c5daeae1SAlexey Kardashevskiy struct kvm_guest_debug_arch { 1363a824b15SPaolo Bonzini __u64 dbg_bcr[KVM_ARM_MAX_DBG_REGS]; 1373a824b15SPaolo Bonzini __u64 dbg_bvr[KVM_ARM_MAX_DBG_REGS]; 1383a824b15SPaolo Bonzini __u64 dbg_wcr[KVM_ARM_MAX_DBG_REGS]; 1393a824b15SPaolo Bonzini __u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS]; 140c5daeae1SAlexey Kardashevskiy }; 141c5daeae1SAlexey Kardashevskiy 142c5daeae1SAlexey Kardashevskiy struct kvm_debug_exit_arch { 1433a824b15SPaolo Bonzini __u32 hsr; 1443a824b15SPaolo Bonzini __u64 far; /* used for watchpoints */ 145c5daeae1SAlexey Kardashevskiy }; 146c5daeae1SAlexey Kardashevskiy 1473a824b15SPaolo Bonzini /* 1483a824b15SPaolo Bonzini * Architecture specific defines for kvm_guest_debug->control 1493a824b15SPaolo Bonzini */ 1503a824b15SPaolo Bonzini 1513a824b15SPaolo Bonzini #define KVM_GUESTDBG_USE_SW_BP (1 << 16) 1523a824b15SPaolo Bonzini #define KVM_GUESTDBG_USE_HW (1 << 17) 1533a824b15SPaolo Bonzini 154c5daeae1SAlexey Kardashevskiy struct kvm_sync_regs { 15574c98e20SCornelia Huck /* Used with KVM_CAP_ARM_USER_IRQ */ 15674c98e20SCornelia Huck __u64 device_irq_level; 157c5daeae1SAlexey Kardashevskiy }; 158c5daeae1SAlexey Kardashevskiy 15953ba2eeeSMatthew Rosato /* 16053ba2eeeSMatthew Rosato * PMU filter structure. Describe a range of events with a particular 16153ba2eeeSMatthew Rosato * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER. 16253ba2eeeSMatthew Rosato */ 16353ba2eeeSMatthew Rosato struct kvm_pmu_event_filter { 16453ba2eeeSMatthew Rosato __u16 base_event; 16553ba2eeeSMatthew Rosato __u16 nevents; 16653ba2eeeSMatthew Rosato 16753ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_ALLOW 0 16853ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_DENY 1 16953ba2eeeSMatthew Rosato 17053ba2eeeSMatthew Rosato __u8 action; 17153ba2eeeSMatthew Rosato __u8 pad[3]; 17253ba2eeeSMatthew Rosato }; 17353ba2eeeSMatthew Rosato 1748f3cd250SCornelia Huck /* for KVM_GET/SET_VCPU_EVENTS */ 1758f3cd250SCornelia Huck struct kvm_vcpu_events { 1768f3cd250SCornelia Huck struct { 1778f3cd250SCornelia Huck __u8 serror_pending; 1788f3cd250SCornelia Huck __u8 serror_has_esr; 1792a886794SGreg Kurz __u8 ext_dabt_pending; 1808f3cd250SCornelia Huck /* Align it to 8 bytes */ 1812a886794SGreg Kurz __u8 pad[5]; 1828f3cd250SCornelia Huck __u64 serror_esr; 1838f3cd250SCornelia Huck } exception; 1848f3cd250SCornelia Huck __u32 reserved[12]; 1858f3cd250SCornelia Huck }; 1868f3cd250SCornelia Huck 187327d4b7fSBharata B Rao struct kvm_arm_copy_mte_tags { 188327d4b7fSBharata B Rao __u64 guest_ipa; 189327d4b7fSBharata B Rao __u64 length; 190327d4b7fSBharata B Rao void *addr; 191327d4b7fSBharata B Rao __u64 flags; 192327d4b7fSBharata B Rao __u64 reserved[2]; 193327d4b7fSBharata B Rao }; 194327d4b7fSBharata B Rao 195327d4b7fSBharata B Rao #define KVM_ARM_TAGS_TO_GUEST 0 196327d4b7fSBharata B Rao #define KVM_ARM_TAGS_FROM_GUEST 1 197327d4b7fSBharata B Rao 198c5daeae1SAlexey Kardashevskiy /* If you need to interpret the index values, here is the key: */ 199c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 200c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_SHIFT 16 201c5daeae1SAlexey Kardashevskiy 202c5daeae1SAlexey Kardashevskiy /* Normal registers are mapped as coprocessor 16. */ 203c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT) 204c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / sizeof(__u32)) 205c5daeae1SAlexey Kardashevskiy 206c5daeae1SAlexey Kardashevskiy /* Some registers need more space to represent values. */ 207c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT) 208c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00 209c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_SHIFT 8 210c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT) 211c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF 212c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_SHIFT 0 213c5daeae1SAlexey Kardashevskiy 214c5daeae1SAlexey Kardashevskiy /* AArch64 system registers */ 215c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG (0x0013 << KVM_REG_ARM_COPROC_SHIFT) 216c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_MASK 0x000000000000c000 217c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_SHIFT 14 218c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_MASK 0x0000000000003800 219c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_SHIFT 11 220c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_MASK 0x0000000000000780 221c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_SHIFT 7 222c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_MASK 0x0000000000000078 223c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_SHIFT 3 224c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_MASK 0x0000000000000007 225c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_SHIFT 0 226c5daeae1SAlexey Kardashevskiy 227876074c2SChristoffer Dall #define ARM64_SYS_REG_SHIFT_MASK(x,n) \ 228876074c2SChristoffer Dall (((x) << KVM_REG_ARM64_SYSREG_ ## n ## _SHIFT) & \ 229876074c2SChristoffer Dall KVM_REG_ARM64_SYSREG_ ## n ## _MASK) 230876074c2SChristoffer Dall 231876074c2SChristoffer Dall #define __ARM64_SYS_REG(op0,op1,crn,crm,op2) \ 232876074c2SChristoffer Dall (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ 233876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ 234876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ 235876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ 236876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ 237876074c2SChristoffer Dall ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) 238876074c2SChristoffer Dall 239876074c2SChristoffer Dall #define ARM64_SYS_REG(...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) 240876074c2SChristoffer Dall 241dd873966SEric Auger /* Physical Timer EL0 Registers */ 242dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CTL ARM64_SYS_REG(3, 3, 14, 2, 1) 243dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CVAL ARM64_SYS_REG(3, 3, 14, 2, 2) 244dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CNT ARM64_SYS_REG(3, 3, 14, 0, 1) 245dd873966SEric Auger 246ddda3748SCornelia Huck /* 247ddda3748SCornelia Huck * EL0 Virtual Timer Registers 248ddda3748SCornelia Huck * 249ddda3748SCornelia Huck * WARNING: 250ddda3748SCornelia Huck * KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT are not defined 251ddda3748SCornelia Huck * with the appropriate register encodings. Their values have been 252ddda3748SCornelia Huck * accidentally swapped. As this is set API, the definitions here 253ddda3748SCornelia Huck * must be used, rather than ones derived from the encodings. 254ddda3748SCornelia Huck */ 255876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1) 256876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2) 257ddda3748SCornelia Huck #define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2) 258876074c2SChristoffer Dall 25965a6d8ddSPeter Maydell /* KVM-as-firmware specific pseudo-registers */ 26065a6d8ddSPeter Maydell #define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT) 26165a6d8ddSPeter Maydell #define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ 26265a6d8ddSPeter Maydell KVM_REG_ARM_FW | ((r) & 0xffff)) 26365a6d8ddSPeter Maydell #define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) 264f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1 KVM_REG_ARM_FW_REG(1) 265f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL 0 266f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL 1 267f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED 2 26853ba2eeeSMatthew Rosato 26953ba2eeeSMatthew Rosato /* 27053ba2eeeSMatthew Rosato * Only two states can be presented by the host kernel: 27153ba2eeeSMatthew Rosato * - NOT_REQUIRED: the guest doesn't need to do anything 27253ba2eeeSMatthew Rosato * - NOT_AVAIL: the guest isn't mitigated (it can still use SSBS if available) 27353ba2eeeSMatthew Rosato * 27453ba2eeeSMatthew Rosato * All the other values are deprecated. The host still accepts all 27553ba2eeeSMatthew Rosato * values (they are ABI), but will narrow them to the above two. 27653ba2eeeSMatthew Rosato */ 277f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2 KVM_REG_ARM_FW_REG(2) 278f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL 0 279f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN 1 280f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL 2 281f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED 3 282f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED (1U << 4) 28365a6d8ddSPeter Maydell 284*e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3 KVM_REG_ARM_FW_REG(3) 285*e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL 0 286*e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_AVAIL 1 287*e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_REQUIRED 2 288*e4082063SAlex Williamson 289d9cb4336SCornelia Huck /* SVE registers */ 290d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) 291d9cb4336SCornelia Huck 292d9cb4336SCornelia Huck /* Z- and P-regs occupy blocks at the following offsets within this range: */ 293d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG_BASE 0 294d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG_BASE 0x400 295d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR_BASE 0x600 296d9cb4336SCornelia Huck 297d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_ZREGS __SVE_NUM_ZREGS 298d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_PREGS __SVE_NUM_PREGS 299d9cb4336SCornelia Huck 300d9cb4336SCornelia Huck #define KVM_ARM64_SVE_MAX_SLICES 32 301d9cb4336SCornelia Huck 302d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG(n, i) \ 303d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_ZREG_BASE | \ 304d9cb4336SCornelia Huck KVM_REG_SIZE_U2048 | \ 305d9cb4336SCornelia Huck (((n) & (KVM_ARM64_SVE_NUM_ZREGS - 1)) << 5) | \ 306d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 307d9cb4336SCornelia Huck 308d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG(n, i) \ 309d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_PREG_BASE | \ 310d9cb4336SCornelia Huck KVM_REG_SIZE_U256 | \ 311d9cb4336SCornelia Huck (((n) & (KVM_ARM64_SVE_NUM_PREGS - 1)) << 5) | \ 312d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 313d9cb4336SCornelia Huck 314d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR(i) \ 315d9cb4336SCornelia Huck (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_FFR_BASE | \ 316d9cb4336SCornelia Huck KVM_REG_SIZE_U256 | \ 317d9cb4336SCornelia Huck ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 318d9cb4336SCornelia Huck 319f363d039SEric Auger /* 320f363d039SEric Auger * Register values for KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() and 321f363d039SEric Auger * KVM_REG_ARM64_SVE_FFR() are represented in memory in an endianness- 322f363d039SEric Auger * invariant layout which differs from the layout used for the FPSIMD 323f363d039SEric Auger * V-registers on big-endian systems: see sigcontext.h for more explanation. 324f363d039SEric Auger */ 325f363d039SEric Auger 326d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN 327d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX 328d9cb4336SCornelia Huck 329d9cb4336SCornelia Huck /* Vector lengths pseudo-register: */ 330d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ 331d9cb4336SCornelia Huck KVM_REG_SIZE_U512 | 0xffff) 332d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VLS_WORDS \ 333d9cb4336SCornelia Huck ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1) 334d9cb4336SCornelia Huck 335876074c2SChristoffer Dall /* Device Control API: ARM VGIC */ 336876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 337876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 338876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 339876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 340876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 3413a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 3423a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ 3433a5eb5b4SPaolo Bonzini (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT) 344876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 345876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 3463a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff) 347444b1996SArd Biesheuvel #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 34851628b18SChristian Borntraeger #define KVM_DEV_ARM_VGIC_GRP_CTRL 4 3493a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 3503a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 3513a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 35274c98e20SCornelia Huck #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 3533a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 3543a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ 3553a5eb5b4SPaolo Bonzini (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) 3563a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff 3573a5eb5b4SPaolo Bonzini #define VGIC_LEVEL_INFO_LINE_LEVEL 0 3583a5eb5b4SPaolo Bonzini 35951628b18SChristian Borntraeger #define KVM_DEV_ARM_VGIC_CTRL_INIT 0 36074c98e20SCornelia Huck #define KVM_DEV_ARM_ITS_SAVE_TABLES 1 36174c98e20SCornelia Huck #define KVM_DEV_ARM_ITS_RESTORE_TABLES 2 36274c98e20SCornelia Huck #define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 363dd873966SEric Auger #define KVM_DEV_ARM_ITS_CTRL_RESET 4 364876074c2SChristoffer Dall 365b89485a5SPaolo Bonzini /* Device Control API on vcpu fd */ 366b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_CTRL 0 367b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_IRQ 0 368b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_INIT 1 36953ba2eeeSMatthew Rosato #define KVM_ARM_VCPU_PMU_V3_FILTER 2 370*e4082063SAlex Williamson #define KVM_ARM_VCPU_PMU_V3_SET_PMU 3 3713272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_CTRL 1 3723272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 3733272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 3742a886794SGreg Kurz #define KVM_ARM_VCPU_PVTIME_CTRL 2 3752a886794SGreg Kurz #define KVM_ARM_VCPU_PVTIME_IPA 0 376b89485a5SPaolo Bonzini 377c5daeae1SAlexey Kardashevskiy /* KVM_IRQ_LINE irq field index values */ 378f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_SHIFT 28 379f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_MASK 0xf 380c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SHIFT 24 381f363d039SEric Auger #define KVM_ARM_IRQ_TYPE_MASK 0xf 382c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_SHIFT 16 383c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_MASK 0xff 384c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_SHIFT 0 385c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_MASK 0xffff 386c5daeae1SAlexey Kardashevskiy 387c5daeae1SAlexey Kardashevskiy /* irq_type field */ 388c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_CPU 0 389c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SPI 1 390c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_PPI 2 391c5daeae1SAlexey Kardashevskiy 392c5daeae1SAlexey Kardashevskiy /* out-of-kernel GIC cpu interrupt injection irq_number field */ 393c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_IRQ 0 394c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_FIQ 1 395c5daeae1SAlexey Kardashevskiy 3967a52ce8aSCornelia Huck /* 3977a52ce8aSCornelia Huck * This used to hold the highest supported SPI, but it is now obsolete 3987a52ce8aSCornelia Huck * and only here to provide source code level compatibility with older 3997a52ce8aSCornelia Huck * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS. 4007a52ce8aSCornelia Huck */ 401c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_GIC_MAX 127 402c5daeae1SAlexey Kardashevskiy 4037a52ce8aSCornelia Huck /* One single KVM irqchip, ie. the VGIC */ 4047a52ce8aSCornelia Huck #define KVM_NR_IRQCHIPS 1 4057a52ce8aSCornelia Huck 406c5daeae1SAlexey Kardashevskiy /* PSCI interface */ 407c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_BASE 0x95c1ba5e 408c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n)) 409c5daeae1SAlexey Kardashevskiy 410c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) 411c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) 412c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) 413c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) 414c5daeae1SAlexey Kardashevskiy 415b061808dSAlexander Graf #define KVM_PSCI_RET_SUCCESS PSCI_RET_SUCCESS 416b061808dSAlexander Graf #define KVM_PSCI_RET_NI PSCI_RET_NOT_SUPPORTED 417b061808dSAlexander Graf #define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS 418b061808dSAlexander Graf #define KVM_PSCI_RET_DENIED PSCI_RET_DENIED 419c5daeae1SAlexey Kardashevskiy 420*e4082063SAlex Williamson /* arm64-specific kvm_run::system_event flags */ 421*e4082063SAlex Williamson /* 422*e4082063SAlex Williamson * Reset caused by a PSCI v1.1 SYSTEM_RESET2 call. 423*e4082063SAlex Williamson * Valid only when the system event has a type of KVM_SYSTEM_EVENT_RESET. 424*e4082063SAlex Williamson */ 425*e4082063SAlex Williamson #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (1ULL << 0) 426*e4082063SAlex Williamson 427*e4082063SAlex Williamson /* run->fail_entry.hardware_entry_failure_reason codes. */ 428*e4082063SAlex Williamson #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0) 429*e4082063SAlex Williamson 430c5daeae1SAlexey Kardashevskiy #endif 431c5daeae1SAlexey Kardashevskiy 432c5daeae1SAlexey Kardashevskiy #endif /* __ARM_KVM_H__ */ 433