18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2012,2013 - ARM Ltd 48c2ecf20Sopenharmony_ci * Author: Marc Zyngier <marc.zyngier@arm.com> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Derived from arch/arm/include/uapi/asm/kvm.h: 78c2ecf20Sopenharmony_ci * Copyright (C) 2012 - Virtual Open Systems and Columbia University 88c2ecf20Sopenharmony_ci * Author: Christoffer Dall <c.dall@virtualopensystems.com> 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 118c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as 128c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, 158c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 168c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 178c2ecf20Sopenharmony_ci * GNU General Public License for more details. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 208c2ecf20Sopenharmony_ci * along with this program. If not, see <http://www.gnu.org/licenses/>. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#ifndef __ARM_KVM_H__ 248c2ecf20Sopenharmony_ci#define __ARM_KVM_H__ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define KVM_SPSR_EL1 0 278c2ecf20Sopenharmony_ci#define KVM_SPSR_SVC KVM_SPSR_EL1 288c2ecf20Sopenharmony_ci#define KVM_SPSR_ABT 1 298c2ecf20Sopenharmony_ci#define KVM_SPSR_UND 2 308c2ecf20Sopenharmony_ci#define KVM_SPSR_IRQ 3 318c2ecf20Sopenharmony_ci#define KVM_SPSR_FIQ 4 328c2ecf20Sopenharmony_ci#define KVM_NR_SPSR 5 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 358c2ecf20Sopenharmony_ci#include <linux/psci.h> 368c2ecf20Sopenharmony_ci#include <linux/types.h> 378c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 388c2ecf20Sopenharmony_ci#include <asm/sve_context.h> 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define __KVM_HAVE_GUEST_DEBUG 418c2ecf20Sopenharmony_ci#define __KVM_HAVE_IRQ_LINE 428c2ecf20Sopenharmony_ci#define __KVM_HAVE_READONLY_MEM 438c2ecf20Sopenharmony_ci#define __KVM_HAVE_VCPU_EVENTS 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define KVM_REG_SIZE(id) \ 488c2ecf20Sopenharmony_ci (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistruct kvm_regs { 518c2ecf20Sopenharmony_ci struct user_pt_regs regs; /* sp = sp_el0 */ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci __u64 sp_el1; 548c2ecf20Sopenharmony_ci __u64 elr_el1; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci __u64 spsr[KVM_NR_SPSR]; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci struct user_fpsimd_state fp_regs; 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* 628c2ecf20Sopenharmony_ci * Supported CPU Targets - Adding a new target type is not recommended, 638c2ecf20Sopenharmony_ci * unless there are some special registers not supported by the 648c2ecf20Sopenharmony_ci * genericv8 syreg table. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_AEM_V8 0 678c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_FOUNDATION_V8 1 688c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_CORTEX_A57 2 698c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_XGENE_POTENZA 3 708c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_CORTEX_A53 4 718c2ecf20Sopenharmony_ci/* Generic ARM v8 target */ 728c2ecf20Sopenharmony_ci#define KVM_ARM_TARGET_GENERIC_V8 5 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define KVM_ARM_NUM_TARGETS 6 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ 778c2ecf20Sopenharmony_ci#define KVM_ARM_DEVICE_TYPE_SHIFT 0 788c2ecf20Sopenharmony_ci#define KVM_ARM_DEVICE_TYPE_MASK (0xffff << KVM_ARM_DEVICE_TYPE_SHIFT) 798c2ecf20Sopenharmony_ci#define KVM_ARM_DEVICE_ID_SHIFT 16 808c2ecf20Sopenharmony_ci#define KVM_ARM_DEVICE_ID_MASK (0xffff << KVM_ARM_DEVICE_ID_SHIFT) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* Supported device IDs */ 838c2ecf20Sopenharmony_ci#define KVM_ARM_DEVICE_VGIC_V2 0 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* Supported VGIC address types */ 868c2ecf20Sopenharmony_ci#define KVM_VGIC_V2_ADDR_TYPE_DIST 0 878c2ecf20Sopenharmony_ci#define KVM_VGIC_V2_ADDR_TYPE_CPU 1 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define KVM_VGIC_V2_DIST_SIZE 0x1000 908c2ecf20Sopenharmony_ci#define KVM_VGIC_V2_CPU_SIZE 0x2000 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* Supported VGICv3 address types */ 938c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_ADDR_TYPE_DIST 2 948c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 958c2ecf20Sopenharmony_ci#define KVM_VGIC_ITS_ADDR_TYPE 4 968c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION 5 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_DIST_SIZE SZ_64K 998c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 1008c2ecf20Sopenharmony_ci#define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 1038c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */ 1048c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PSCI_0_2 2 /* CPU uses PSCI v0.2 */ 1058c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PMU_V3 3 /* Support guest PMUv3 */ 1068c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ 1078c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ 1088c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct kvm_vcpu_init { 1118c2ecf20Sopenharmony_ci __u32 target; 1128c2ecf20Sopenharmony_ci __u32 features[7]; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct kvm_sregs { 1168c2ecf20Sopenharmony_ci}; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistruct kvm_fpu { 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* 1228c2ecf20Sopenharmony_ci * See v8 ARM ARM D7.3: Debug Registers 1238c2ecf20Sopenharmony_ci * 1248c2ecf20Sopenharmony_ci * The architectural limit is 16 debug registers of each type although 1258c2ecf20Sopenharmony_ci * in practice there are usually less (see ID_AA64DFR0_EL1). 1268c2ecf20Sopenharmony_ci * 1278c2ecf20Sopenharmony_ci * Although the control registers are architecturally defined as 32 1288c2ecf20Sopenharmony_ci * bits wide we use a 64 bit structure here to keep parity with 1298c2ecf20Sopenharmony_ci * KVM_GET/SET_ONE_REG behaviour which treats all system registers as 1308c2ecf20Sopenharmony_ci * 64 bit values. It also allows for the possibility of the 1318c2ecf20Sopenharmony_ci * architecture expanding the control registers without having to 1328c2ecf20Sopenharmony_ci * change the userspace ABI. 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_ci#define KVM_ARM_MAX_DBG_REGS 16 1358c2ecf20Sopenharmony_cistruct kvm_guest_debug_arch { 1368c2ecf20Sopenharmony_ci __u64 dbg_bcr[KVM_ARM_MAX_DBG_REGS]; 1378c2ecf20Sopenharmony_ci __u64 dbg_bvr[KVM_ARM_MAX_DBG_REGS]; 1388c2ecf20Sopenharmony_ci __u64 dbg_wcr[KVM_ARM_MAX_DBG_REGS]; 1398c2ecf20Sopenharmony_ci __u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS]; 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistruct kvm_debug_exit_arch { 1438c2ecf20Sopenharmony_ci __u32 hsr; 1448c2ecf20Sopenharmony_ci __u64 far; /* used for watchpoints */ 1458c2ecf20Sopenharmony_ci}; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* 1488c2ecf20Sopenharmony_ci * Architecture specific defines for kvm_guest_debug->control 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define KVM_GUESTDBG_USE_SW_BP (1 << 16) 1528c2ecf20Sopenharmony_ci#define KVM_GUESTDBG_USE_HW (1 << 17) 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistruct kvm_sync_regs { 1558c2ecf20Sopenharmony_ci /* Used with KVM_CAP_ARM_USER_IRQ */ 1568c2ecf20Sopenharmony_ci __u64 device_irq_level; 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistruct kvm_arch_memory_slot { 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* 1638c2ecf20Sopenharmony_ci * PMU filter structure. Describe a range of events with a particular 1648c2ecf20Sopenharmony_ci * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER. 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_cistruct kvm_pmu_event_filter { 1678c2ecf20Sopenharmony_ci __u16 base_event; 1688c2ecf20Sopenharmony_ci __u16 nevents; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define KVM_PMU_EVENT_ALLOW 0 1718c2ecf20Sopenharmony_ci#define KVM_PMU_EVENT_DENY 1 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci __u8 action; 1748c2ecf20Sopenharmony_ci __u8 pad[3]; 1758c2ecf20Sopenharmony_ci}; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* for KVM_GET/SET_VCPU_EVENTS */ 1788c2ecf20Sopenharmony_cistruct kvm_vcpu_events { 1798c2ecf20Sopenharmony_ci struct { 1808c2ecf20Sopenharmony_ci __u8 serror_pending; 1818c2ecf20Sopenharmony_ci __u8 serror_has_esr; 1828c2ecf20Sopenharmony_ci __u8 ext_dabt_pending; 1838c2ecf20Sopenharmony_ci /* Align it to 8 bytes */ 1848c2ecf20Sopenharmony_ci __u8 pad[5]; 1858c2ecf20Sopenharmony_ci __u64 serror_esr; 1868c2ecf20Sopenharmony_ci } exception; 1878c2ecf20Sopenharmony_ci __u32 reserved[12]; 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci/* If you need to interpret the index values, here is the key: */ 1918c2ecf20Sopenharmony_ci#define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 1928c2ecf20Sopenharmony_ci#define KVM_REG_ARM_COPROC_SHIFT 16 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/* Normal registers are mapped as coprocessor 16. */ 1958c2ecf20Sopenharmony_ci#define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT) 1968c2ecf20Sopenharmony_ci#define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / sizeof(__u32)) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci/* Some registers need more space to represent values. */ 1998c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX (0x0011 << KVM_REG_ARM_COPROC_SHIFT) 2008c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX_ID_MASK 0x000000000000FF00 2018c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX_ID_SHIFT 8 2028c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX_ID_CCSIDR (0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT) 2038c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX_VAL_MASK 0x00000000000000FF 2048c2ecf20Sopenharmony_ci#define KVM_REG_ARM_DEMUX_VAL_SHIFT 0 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci/* AArch64 system registers */ 2078c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG (0x0013 << KVM_REG_ARM_COPROC_SHIFT) 2088c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP0_MASK 0x000000000000c000 2098c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP0_SHIFT 14 2108c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP1_MASK 0x0000000000003800 2118c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP1_SHIFT 11 2128c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_CRN_MASK 0x0000000000000780 2138c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_CRN_SHIFT 7 2148c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_CRM_MASK 0x0000000000000078 2158c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_CRM_SHIFT 3 2168c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP2_MASK 0x0000000000000007 2178c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SYSREG_OP2_SHIFT 0 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#define ARM64_SYS_REG_SHIFT_MASK(x,n) \ 2208c2ecf20Sopenharmony_ci (((x) << KVM_REG_ARM64_SYSREG_ ## n ## _SHIFT) & \ 2218c2ecf20Sopenharmony_ci KVM_REG_ARM64_SYSREG_ ## n ## _MASK) 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#define __ARM64_SYS_REG(op0,op1,crn,crm,op2) \ 2248c2ecf20Sopenharmony_ci (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ 2258c2ecf20Sopenharmony_ci ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ 2268c2ecf20Sopenharmony_ci ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ 2278c2ecf20Sopenharmony_ci ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ 2288c2ecf20Sopenharmony_ci ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ 2298c2ecf20Sopenharmony_ci ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#define ARM64_SYS_REG(...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/* Physical Timer EL0 Registers */ 2348c2ecf20Sopenharmony_ci#define KVM_REG_ARM_PTIMER_CTL ARM64_SYS_REG(3, 3, 14, 2, 1) 2358c2ecf20Sopenharmony_ci#define KVM_REG_ARM_PTIMER_CVAL ARM64_SYS_REG(3, 3, 14, 2, 2) 2368c2ecf20Sopenharmony_ci#define KVM_REG_ARM_PTIMER_CNT ARM64_SYS_REG(3, 3, 14, 0, 1) 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci/* 2398c2ecf20Sopenharmony_ci * EL0 Virtual Timer Registers 2408c2ecf20Sopenharmony_ci * 2418c2ecf20Sopenharmony_ci * WARNING: 2428c2ecf20Sopenharmony_ci * KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT are not defined 2438c2ecf20Sopenharmony_ci * with the appropriate register encodings. Their values have been 2448c2ecf20Sopenharmony_ci * accidentally swapped. As this is set API, the definitions here 2458c2ecf20Sopenharmony_ci * must be used, rather than ones derived from the encodings. 2468c2ecf20Sopenharmony_ci */ 2478c2ecf20Sopenharmony_ci#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1) 2488c2ecf20Sopenharmony_ci#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2) 2498c2ecf20Sopenharmony_ci#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2) 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci/* KVM-as-firmware specific pseudo-registers */ 2528c2ecf20Sopenharmony_ci#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT) 2538c2ecf20Sopenharmony_ci#define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ 2548c2ecf20Sopenharmony_ci KVM_REG_ARM_FW | ((r) & 0xffff)) 2558c2ecf20Sopenharmony_ci#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) 2568c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1 KVM_REG_ARM_FW_REG(1) 2578c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL 0 2588c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL 1 2598c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED 2 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci/* 2628c2ecf20Sopenharmony_ci * Only two states can be presented by the host kernel: 2638c2ecf20Sopenharmony_ci * - NOT_REQUIRED: the guest doesn't need to do anything 2648c2ecf20Sopenharmony_ci * - NOT_AVAIL: the guest isn't mitigated (it can still use SSBS if available) 2658c2ecf20Sopenharmony_ci * 2668c2ecf20Sopenharmony_ci * All the other values are deprecated. The host still accepts all 2678c2ecf20Sopenharmony_ci * values (they are ABI), but will narrow them to the above two. 2688c2ecf20Sopenharmony_ci */ 2698c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2 KVM_REG_ARM_FW_REG(2) 2708c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL 0 2718c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN 1 2728c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL 2 2738c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED 3 2748c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED (1U << 4) 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3 KVM_REG_ARM_FW_REG(3) 2778c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL 0 2788c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_AVAIL 1 2798c2ecf20Sopenharmony_ci#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_REQUIRED 2 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/* SVE registers */ 2828c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci/* Z- and P-regs occupy blocks at the following offsets within this range: */ 2858c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_ZREG_BASE 0 2868c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_PREG_BASE 0x400 2878c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_FFR_BASE 0x600 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_NUM_ZREGS __SVE_NUM_ZREGS 2908c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_NUM_PREGS __SVE_NUM_PREGS 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_MAX_SLICES 32 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_ZREG(n, i) \ 2958c2ecf20Sopenharmony_ci (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_ZREG_BASE | \ 2968c2ecf20Sopenharmony_ci KVM_REG_SIZE_U2048 | \ 2978c2ecf20Sopenharmony_ci (((n) & (KVM_ARM64_SVE_NUM_ZREGS - 1)) << 5) | \ 2988c2ecf20Sopenharmony_ci ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_PREG(n, i) \ 3018c2ecf20Sopenharmony_ci (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_PREG_BASE | \ 3028c2ecf20Sopenharmony_ci KVM_REG_SIZE_U256 | \ 3038c2ecf20Sopenharmony_ci (((n) & (KVM_ARM64_SVE_NUM_PREGS - 1)) << 5) | \ 3048c2ecf20Sopenharmony_ci ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_FFR(i) \ 3078c2ecf20Sopenharmony_ci (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_FFR_BASE | \ 3088c2ecf20Sopenharmony_ci KVM_REG_SIZE_U256 | \ 3098c2ecf20Sopenharmony_ci ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci/* 3128c2ecf20Sopenharmony_ci * Register values for KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() and 3138c2ecf20Sopenharmony_ci * KVM_REG_ARM64_SVE_FFR() are represented in memory in an endianness- 3148c2ecf20Sopenharmony_ci * invariant layout which differs from the layout used for the FPSIMD 3158c2ecf20Sopenharmony_ci * V-registers on big-endian systems: see sigcontext.h for more explanation. 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN 3198c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* Vector lengths pseudo-register: */ 3228c2ecf20Sopenharmony_ci#define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ 3238c2ecf20Sopenharmony_ci KVM_REG_SIZE_U512 | 0xffff) 3248c2ecf20Sopenharmony_ci#define KVM_ARM64_SVE_VLS_WORDS \ 3258c2ecf20Sopenharmony_ci ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1) 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci/* Device Control API: ARM VGIC */ 3288c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_ADDR 0 3298c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 3308c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 3318c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 3328c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 3338c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 3348c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ 3358c2ecf20Sopenharmony_ci (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT) 3368c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 3378c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 3388c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff) 3398c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 3408c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 3418c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 3428c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 3438c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 3448c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 3458c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 3468c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ 3478c2ecf20Sopenharmony_ci (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) 3488c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff 3498c2ecf20Sopenharmony_ci#define VGIC_LEVEL_INFO_LINE_LEVEL 0 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 3528c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_ITS_SAVE_TABLES 1 3538c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2 3548c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 3558c2ecf20Sopenharmony_ci#define KVM_DEV_ARM_ITS_CTRL_RESET 4 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci/* Device Control API on vcpu fd */ 3588c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PMU_V3_CTRL 0 3598c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PMU_V3_IRQ 0 3608c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PMU_V3_INIT 1 3618c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PMU_V3_FILTER 2 3628c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_TIMER_CTRL 1 3638c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 3648c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 3658c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PVTIME_CTRL 2 3668c2ecf20Sopenharmony_ci#define KVM_ARM_VCPU_PVTIME_IPA 0 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/* KVM_IRQ_LINE irq field index values */ 3698c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_VCPU2_SHIFT 28 3708c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_VCPU2_MASK 0xf 3718c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_TYPE_SHIFT 24 3728c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_TYPE_MASK 0xf 3738c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_VCPU_SHIFT 16 3748c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_VCPU_MASK 0xff 3758c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_NUM_SHIFT 0 3768c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_NUM_MASK 0xffff 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci/* irq_type field */ 3798c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_TYPE_CPU 0 3808c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_TYPE_SPI 1 3818c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_TYPE_PPI 2 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci/* out-of-kernel GIC cpu interrupt injection irq_number field */ 3848c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_CPU_IRQ 0 3858c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_CPU_FIQ 1 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci/* 3888c2ecf20Sopenharmony_ci * This used to hold the highest supported SPI, but it is now obsolete 3898c2ecf20Sopenharmony_ci * and only here to provide source code level compatibility with older 3908c2ecf20Sopenharmony_ci * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS. 3918c2ecf20Sopenharmony_ci */ 3928c2ecf20Sopenharmony_ci#ifndef __KERNEL__ 3938c2ecf20Sopenharmony_ci#define KVM_ARM_IRQ_GIC_MAX 127 3948c2ecf20Sopenharmony_ci#endif 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci/* One single KVM irqchip, ie. the VGIC */ 3978c2ecf20Sopenharmony_ci#define KVM_NR_IRQCHIPS 1 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci/* PSCI interface */ 4008c2ecf20Sopenharmony_ci#define KVM_PSCI_FN_BASE 0x95c1ba5e 4018c2ecf20Sopenharmony_ci#define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n)) 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci#define KVM_PSCI_FN_CPU_SUSPEND KVM_PSCI_FN(0) 4048c2ecf20Sopenharmony_ci#define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) 4058c2ecf20Sopenharmony_ci#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) 4068c2ecf20Sopenharmony_ci#define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci#define KVM_PSCI_RET_SUCCESS PSCI_RET_SUCCESS 4098c2ecf20Sopenharmony_ci#define KVM_PSCI_RET_NI PSCI_RET_NOT_SUPPORTED 4108c2ecf20Sopenharmony_ci#define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS 4118c2ecf20Sopenharmony_ci#define KVM_PSCI_RET_DENIED PSCI_RET_DENIED 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci#endif 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci#endif /* __ARM_KVM_H__ */ 416