xref: /openbmc/qemu/linux-headers/asm-arm64/kvm.h (revision d525f73f9186a5bc641b8caf0b2c9bb94e5aa963)
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
78*d525f73fSChenyi Qiang #define KVM_ARM_DEVICE_TYPE_MASK	GENMASK(KVM_ARM_DEVICE_TYPE_SHIFT + 15, \
79*d525f73fSChenyi Qiang 						KVM_ARM_DEVICE_TYPE_SHIFT)
80c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_ID_SHIFT		16
81*d525f73fSChenyi Qiang #define KVM_ARM_DEVICE_ID_MASK		GENMASK(KVM_ARM_DEVICE_ID_SHIFT + 15, \
82*d525f73fSChenyi Qiang 						KVM_ARM_DEVICE_ID_SHIFT)
83c5daeae1SAlexey Kardashevskiy 
84c5daeae1SAlexey Kardashevskiy /* Supported device IDs */
85c5daeae1SAlexey Kardashevskiy #define KVM_ARM_DEVICE_VGIC_V2		0
86c5daeae1SAlexey Kardashevskiy 
87c5daeae1SAlexey Kardashevskiy /* Supported VGIC address types  */
88c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_DIST	0
89c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_ADDR_TYPE_CPU	1
90c5daeae1SAlexey Kardashevskiy 
91c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_DIST_SIZE		0x1000
92c5daeae1SAlexey Kardashevskiy #define KVM_VGIC_V2_CPU_SIZE		0x2000
93c5daeae1SAlexey Kardashevskiy 
9451628b18SChristian Borntraeger /* Supported VGICv3 address types  */
9551628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_DIST	2
9651628b18SChristian Borntraeger #define KVM_VGIC_V3_ADDR_TYPE_REDIST	3
97dbdfea92SCornelia Huck #define KVM_VGIC_ITS_ADDR_TYPE		4
9877d361b1SEric Auger #define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION	5
9951628b18SChristian Borntraeger 
10051628b18SChristian Borntraeger #define KVM_VGIC_V3_DIST_SIZE		SZ_64K
10151628b18SChristian Borntraeger #define KVM_VGIC_V3_REDIST_SIZE		(2 * SZ_64K)
102dbdfea92SCornelia Huck #define KVM_VGIC_V3_ITS_SIZE		(2 * SZ_64K)
10351628b18SChristian Borntraeger 
104c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
105c5daeae1SAlexey Kardashevskiy #define KVM_ARM_VCPU_EL1_32BIT		1 /* CPU running a 32bit VM */
106b061808dSAlexander Graf #define KVM_ARM_VCPU_PSCI_0_2		2 /* CPU uses PSCI v0.2 */
107b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3		3 /* Support guest PMUv3 */
108d9cb4336SCornelia Huck #define KVM_ARM_VCPU_SVE		4 /* enable SVE for this CPU */
109d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_ADDRESS	5 /* VCPU uses address authentication */
110d9cb4336SCornelia Huck #define KVM_ARM_VCPU_PTRAUTH_GENERIC	6 /* VCPU uses generic authentication */
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 
144*d525f73fSChenyi Qiang #define KVM_DEBUG_ARCH_HSR_HIGH_VALID	(1 << 0)
145c5daeae1SAlexey Kardashevskiy struct kvm_debug_exit_arch {
1463a824b15SPaolo Bonzini 	__u32 hsr;
147*d525f73fSChenyi 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 
16353ba2eeeSMatthew Rosato /*
16453ba2eeeSMatthew Rosato  * PMU filter structure. Describe a range of events with a particular
16553ba2eeeSMatthew Rosato  * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER.
16653ba2eeeSMatthew Rosato  */
16753ba2eeeSMatthew Rosato struct kvm_pmu_event_filter {
16853ba2eeeSMatthew Rosato 	__u16	base_event;
16953ba2eeeSMatthew Rosato 	__u16	nevents;
17053ba2eeeSMatthew Rosato 
17153ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_ALLOW	0
17253ba2eeeSMatthew Rosato #define KVM_PMU_EVENT_DENY	1
17353ba2eeeSMatthew Rosato 
17453ba2eeeSMatthew Rosato 	__u8	action;
17553ba2eeeSMatthew Rosato 	__u8	pad[3];
17653ba2eeeSMatthew Rosato };
17753ba2eeeSMatthew Rosato 
1788f3cd250SCornelia Huck /* for KVM_GET/SET_VCPU_EVENTS */
1798f3cd250SCornelia Huck struct kvm_vcpu_events {
1808f3cd250SCornelia Huck 	struct {
1818f3cd250SCornelia Huck 		__u8 serror_pending;
1828f3cd250SCornelia Huck 		__u8 serror_has_esr;
1832a886794SGreg Kurz 		__u8 ext_dabt_pending;
1848f3cd250SCornelia Huck 		/* Align it to 8 bytes */
1852a886794SGreg Kurz 		__u8 pad[5];
1868f3cd250SCornelia Huck 		__u64 serror_esr;
1878f3cd250SCornelia Huck 	} exception;
1888f3cd250SCornelia Huck 	__u32 reserved[12];
1898f3cd250SCornelia Huck };
1908f3cd250SCornelia Huck 
191327d4b7fSBharata B Rao struct kvm_arm_copy_mte_tags {
192327d4b7fSBharata B Rao 	__u64 guest_ipa;
193327d4b7fSBharata B Rao 	__u64 length;
194327d4b7fSBharata B Rao 	void *addr;
195327d4b7fSBharata B Rao 	__u64 flags;
196327d4b7fSBharata B Rao 	__u64 reserved[2];
197327d4b7fSBharata B Rao };
198327d4b7fSBharata B Rao 
199327d4b7fSBharata B Rao #define KVM_ARM_TAGS_TO_GUEST		0
200327d4b7fSBharata B Rao #define KVM_ARM_TAGS_FROM_GUEST		1
201327d4b7fSBharata B Rao 
202c5daeae1SAlexey Kardashevskiy /* If you need to interpret the index values, here is the key: */
203c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_MASK		0x000000000FFF0000
204c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_COPROC_SHIFT	16
205c5daeae1SAlexey Kardashevskiy 
206c5daeae1SAlexey Kardashevskiy /* Normal registers are mapped as coprocessor 16. */
207c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE		(0x0010 << KVM_REG_ARM_COPROC_SHIFT)
208c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_CORE_REG(name)	(offsetof(struct kvm_regs, name) / sizeof(__u32))
209c5daeae1SAlexey Kardashevskiy 
210c5daeae1SAlexey Kardashevskiy /* Some registers need more space to represent values. */
211c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX		(0x0011 << KVM_REG_ARM_COPROC_SHIFT)
212c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_MASK	0x000000000000FF00
213c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_SHIFT	8
214c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_ID_CCSIDR	(0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
215c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_MASK	0x00000000000000FF
216c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM_DEMUX_VAL_SHIFT	0
217c5daeae1SAlexey Kardashevskiy 
218c5daeae1SAlexey Kardashevskiy /* AArch64 system registers */
219c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG		(0x0013 << KVM_REG_ARM_COPROC_SHIFT)
220c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_MASK	0x000000000000c000
221c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP0_SHIFT	14
222c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_MASK	0x0000000000003800
223c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP1_SHIFT	11
224c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_MASK	0x0000000000000780
225c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRN_SHIFT	7
226c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_MASK	0x0000000000000078
227c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_CRM_SHIFT	3
228c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_MASK	0x0000000000000007
229c5daeae1SAlexey Kardashevskiy #define KVM_REG_ARM64_SYSREG_OP2_SHIFT	0
230c5daeae1SAlexey Kardashevskiy 
231876074c2SChristoffer Dall #define ARM64_SYS_REG_SHIFT_MASK(x,n) \
232876074c2SChristoffer Dall 	(((x) << KVM_REG_ARM64_SYSREG_ ## n ## _SHIFT) & \
233876074c2SChristoffer Dall 	KVM_REG_ARM64_SYSREG_ ## n ## _MASK)
234876074c2SChristoffer Dall 
235876074c2SChristoffer Dall #define __ARM64_SYS_REG(op0,op1,crn,crm,op2) \
236876074c2SChristoffer Dall 	(KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \
237876074c2SChristoffer Dall 	ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \
238876074c2SChristoffer Dall 	ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \
239876074c2SChristoffer Dall 	ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \
240876074c2SChristoffer Dall 	ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \
241876074c2SChristoffer Dall 	ARM64_SYS_REG_SHIFT_MASK(op2, OP2))
242876074c2SChristoffer Dall 
243876074c2SChristoffer Dall #define ARM64_SYS_REG(...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64)
244876074c2SChristoffer Dall 
245dd873966SEric Auger /* Physical Timer EL0 Registers */
246dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CTL		ARM64_SYS_REG(3, 3, 14, 2, 1)
247dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CVAL		ARM64_SYS_REG(3, 3, 14, 2, 2)
248dd873966SEric Auger #define KVM_REG_ARM_PTIMER_CNT		ARM64_SYS_REG(3, 3, 14, 0, 1)
249dd873966SEric Auger 
250ddda3748SCornelia Huck /*
251ddda3748SCornelia Huck  * EL0 Virtual Timer Registers
252ddda3748SCornelia Huck  *
253ddda3748SCornelia Huck  * WARNING:
254ddda3748SCornelia Huck  *      KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT are not defined
255ddda3748SCornelia Huck  *      with the appropriate register encodings.  Their values have been
256ddda3748SCornelia Huck  *      accidentally swapped.  As this is set API, the definitions here
257ddda3748SCornelia Huck  *      must be used, rather than ones derived from the encodings.
258ddda3748SCornelia Huck  */
259876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CTL		ARM64_SYS_REG(3, 3, 14, 3, 1)
260876074c2SChristoffer Dall #define KVM_REG_ARM_TIMER_CVAL		ARM64_SYS_REG(3, 3, 14, 0, 2)
261ddda3748SCornelia Huck #define KVM_REG_ARM_TIMER_CNT		ARM64_SYS_REG(3, 3, 14, 3, 2)
262876074c2SChristoffer Dall 
26365a6d8ddSPeter Maydell /* KVM-as-firmware specific pseudo-registers */
26465a6d8ddSPeter Maydell #define KVM_REG_ARM_FW			(0x0014 << KVM_REG_ARM_COPROC_SHIFT)
26565a6d8ddSPeter Maydell #define KVM_REG_ARM_FW_REG(r)		(KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
26665a6d8ddSPeter Maydell 					 KVM_REG_ARM_FW | ((r) & 0xffff))
26765a6d8ddSPeter Maydell #define KVM_REG_ARM_PSCI_VERSION	KVM_REG_ARM_FW_REG(0)
268f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1	KVM_REG_ARM_FW_REG(1)
269f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL		0
270f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL		1
271f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED	2
27253ba2eeeSMatthew Rosato 
27353ba2eeeSMatthew Rosato /*
27453ba2eeeSMatthew Rosato  * Only two states can be presented by the host kernel:
27553ba2eeeSMatthew Rosato  * - NOT_REQUIRED: the guest doesn't need to do anything
27653ba2eeeSMatthew Rosato  * - NOT_AVAIL: the guest isn't mitigated (it can still use SSBS if available)
27753ba2eeeSMatthew Rosato  *
27853ba2eeeSMatthew Rosato  * All the other values are deprecated. The host still accepts all
27953ba2eeeSMatthew Rosato  * values (they are ABI), but will narrow them to the above two.
28053ba2eeeSMatthew Rosato  */
281f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2	KVM_REG_ARM_FW_REG(2)
282f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL		0
283f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN		1
284f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL		2
285f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED	3
286f363d039SEric Auger #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED     	(1U << 4)
28765a6d8ddSPeter Maydell 
288e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3	KVM_REG_ARM_FW_REG(3)
289e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_AVAIL		0
290e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_AVAIL		1
291e4082063SAlex Williamson #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3_NOT_REQUIRED	2
292e4082063SAlex Williamson 
293d9cb4336SCornelia Huck /* SVE registers */
294d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE		(0x15 << KVM_REG_ARM_COPROC_SHIFT)
295d9cb4336SCornelia Huck 
296d9cb4336SCornelia Huck /* Z- and P-regs occupy blocks at the following offsets within this range: */
297d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG_BASE	0
298d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG_BASE	0x400
299d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR_BASE	0x600
300d9cb4336SCornelia Huck 
301d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_ZREGS		__SVE_NUM_ZREGS
302d9cb4336SCornelia Huck #define KVM_ARM64_SVE_NUM_PREGS		__SVE_NUM_PREGS
303d9cb4336SCornelia Huck 
304d9cb4336SCornelia Huck #define KVM_ARM64_SVE_MAX_SLICES	32
305d9cb4336SCornelia Huck 
306d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_ZREG(n, i)					\
307d9cb4336SCornelia Huck 	(KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_ZREG_BASE | \
308d9cb4336SCornelia Huck 	 KVM_REG_SIZE_U2048 |						\
309d9cb4336SCornelia Huck 	 (((n) & (KVM_ARM64_SVE_NUM_ZREGS - 1)) << 5) |			\
310d9cb4336SCornelia Huck 	 ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1)))
311d9cb4336SCornelia Huck 
312d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_PREG(n, i)					\
313d9cb4336SCornelia Huck 	(KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_PREG_BASE | \
314d9cb4336SCornelia Huck 	 KVM_REG_SIZE_U256 |						\
315d9cb4336SCornelia Huck 	 (((n) & (KVM_ARM64_SVE_NUM_PREGS - 1)) << 5) |			\
316d9cb4336SCornelia Huck 	 ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1)))
317d9cb4336SCornelia Huck 
318d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_FFR(i)					\
319d9cb4336SCornelia Huck 	(KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_FFR_BASE | \
320d9cb4336SCornelia Huck 	 KVM_REG_SIZE_U256 |						\
321d9cb4336SCornelia Huck 	 ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1)))
322d9cb4336SCornelia Huck 
323f363d039SEric Auger /*
324f363d039SEric Auger  * Register values for KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() and
325f363d039SEric Auger  * KVM_REG_ARM64_SVE_FFR() are represented in memory in an endianness-
326f363d039SEric Auger  * invariant layout which differs from the layout used for the FPSIMD
327f363d039SEric Auger  * V-registers on big-endian systems: see sigcontext.h for more explanation.
328f363d039SEric Auger  */
329f363d039SEric Auger 
330d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN
331d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX
332d9cb4336SCornelia Huck 
333d9cb4336SCornelia Huck /* Vector lengths pseudo-register: */
334d9cb4336SCornelia Huck #define KVM_REG_ARM64_SVE_VLS		(KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \
335d9cb4336SCornelia Huck 					 KVM_REG_SIZE_U512 | 0xffff)
336d9cb4336SCornelia Huck #define KVM_ARM64_SVE_VLS_WORDS	\
337d9cb4336SCornelia Huck 	((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1)
338d9cb4336SCornelia Huck 
339*d525f73fSChenyi Qiang /* Bitmap feature firmware registers */
340*d525f73fSChenyi Qiang #define KVM_REG_ARM_FW_FEAT_BMAP		(0x0016 << KVM_REG_ARM_COPROC_SHIFT)
341*d525f73fSChenyi Qiang #define KVM_REG_ARM_FW_FEAT_BMAP_REG(r)		(KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
342*d525f73fSChenyi Qiang 						KVM_REG_ARM_FW_FEAT_BMAP |	\
343*d525f73fSChenyi Qiang 						((r) & 0xffff))
344*d525f73fSChenyi Qiang 
345*d525f73fSChenyi Qiang #define KVM_REG_ARM_STD_BMAP			KVM_REG_ARM_FW_FEAT_BMAP_REG(0)
346*d525f73fSChenyi Qiang 
347*d525f73fSChenyi Qiang enum {
348*d525f73fSChenyi Qiang 	KVM_REG_ARM_STD_BIT_TRNG_V1_0	= 0,
349*d525f73fSChenyi Qiang };
350*d525f73fSChenyi Qiang 
351*d525f73fSChenyi Qiang #define KVM_REG_ARM_STD_HYP_BMAP		KVM_REG_ARM_FW_FEAT_BMAP_REG(1)
352*d525f73fSChenyi Qiang 
353*d525f73fSChenyi Qiang enum {
354*d525f73fSChenyi Qiang 	KVM_REG_ARM_STD_HYP_BIT_PV_TIME	= 0,
355*d525f73fSChenyi Qiang };
356*d525f73fSChenyi Qiang 
357*d525f73fSChenyi Qiang #define KVM_REG_ARM_VENDOR_HYP_BMAP		KVM_REG_ARM_FW_FEAT_BMAP_REG(2)
358*d525f73fSChenyi Qiang 
359*d525f73fSChenyi Qiang enum {
360*d525f73fSChenyi Qiang 	KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT	= 0,
361*d525f73fSChenyi Qiang 	KVM_REG_ARM_VENDOR_HYP_BIT_PTP		= 1,
362*d525f73fSChenyi Qiang };
363*d525f73fSChenyi Qiang 
364876074c2SChristoffer Dall /* Device Control API: ARM VGIC */
365876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_ADDR	0
366876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS	1
367876074c2SChristoffer Dall #define KVM_DEV_ARM_VGIC_GRP_CPU_REGS	2
368876074c2SChristoffer Dall #define   KVM_DEV_ARM_VGIC_CPUID_SHIFT	32
369876074c2SChristoffer Dall #define   KVM_DEV_ARM_VGIC_CPUID_MASK	(0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
3703a5eb5b4SPaolo Bonzini #define   KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32
3713a5eb5b4SPaolo Bonzini #define   KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \
3723a5eb5b4SPaolo Bonzini 			(0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)
373876074c2SChristoffer Dall #define   KVM_DEV_ARM_VGIC_OFFSET_SHIFT	0
374876074c2SChristoffer Dall #define   KVM_DEV_ARM_VGIC_OFFSET_MASK	(0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
3753a5eb5b4SPaolo Bonzini #define   KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff)
376444b1996SArd Biesheuvel #define KVM_DEV_ARM_VGIC_GRP_NR_IRQS	3
37751628b18SChristian Borntraeger #define KVM_DEV_ARM_VGIC_GRP_CTRL	4
3783a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5
3793a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6
3803a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO  7
38174c98e20SCornelia Huck #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8
3823a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT	10
3833a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \
3843a5eb5b4SPaolo Bonzini 			(0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
3853a5eb5b4SPaolo Bonzini #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK	0x3ff
3863a5eb5b4SPaolo Bonzini #define VGIC_LEVEL_INFO_LINE_LEVEL	0
3873a5eb5b4SPaolo Bonzini 
38851628b18SChristian Borntraeger #define   KVM_DEV_ARM_VGIC_CTRL_INIT		0
38974c98e20SCornelia Huck #define   KVM_DEV_ARM_ITS_SAVE_TABLES           1
39074c98e20SCornelia Huck #define   KVM_DEV_ARM_ITS_RESTORE_TABLES        2
39174c98e20SCornelia Huck #define   KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES	3
392dd873966SEric Auger #define   KVM_DEV_ARM_ITS_CTRL_RESET		4
393876074c2SChristoffer Dall 
394b89485a5SPaolo Bonzini /* Device Control API on vcpu fd */
395b89485a5SPaolo Bonzini #define KVM_ARM_VCPU_PMU_V3_CTRL	0
396b89485a5SPaolo Bonzini #define   KVM_ARM_VCPU_PMU_V3_IRQ	0
397b89485a5SPaolo Bonzini #define   KVM_ARM_VCPU_PMU_V3_INIT	1
39853ba2eeeSMatthew Rosato #define   KVM_ARM_VCPU_PMU_V3_FILTER	2
399e4082063SAlex Williamson #define   KVM_ARM_VCPU_PMU_V3_SET_PMU	3
4003272f0e2SChristian Borntraeger #define KVM_ARM_VCPU_TIMER_CTRL		1
4013272f0e2SChristian Borntraeger #define   KVM_ARM_VCPU_TIMER_IRQ_VTIMER		0
4023272f0e2SChristian Borntraeger #define   KVM_ARM_VCPU_TIMER_IRQ_PTIMER		1
4032a886794SGreg Kurz #define KVM_ARM_VCPU_PVTIME_CTRL	2
4042a886794SGreg Kurz #define   KVM_ARM_VCPU_PVTIME_IPA	0
405b89485a5SPaolo Bonzini 
406c5daeae1SAlexey Kardashevskiy /* KVM_IRQ_LINE irq field index values */
407f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_SHIFT		28
408f363d039SEric Auger #define KVM_ARM_IRQ_VCPU2_MASK		0xf
409c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SHIFT		24
410f363d039SEric Auger #define KVM_ARM_IRQ_TYPE_MASK		0xf
411c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_SHIFT		16
412c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_VCPU_MASK		0xff
413c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_SHIFT		0
414c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_NUM_MASK		0xffff
415c5daeae1SAlexey Kardashevskiy 
416c5daeae1SAlexey Kardashevskiy /* irq_type field */
417c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_CPU		0
418c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_SPI		1
419c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_TYPE_PPI		2
420c5daeae1SAlexey Kardashevskiy 
421c5daeae1SAlexey Kardashevskiy /* out-of-kernel GIC cpu interrupt injection irq_number field */
422c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_IRQ		0
423c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_CPU_FIQ		1
424c5daeae1SAlexey Kardashevskiy 
4257a52ce8aSCornelia Huck /*
4267a52ce8aSCornelia Huck  * This used to hold the highest supported SPI, but it is now obsolete
4277a52ce8aSCornelia Huck  * and only here to provide source code level compatibility with older
4287a52ce8aSCornelia Huck  * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS.
4297a52ce8aSCornelia Huck  */
430c5daeae1SAlexey Kardashevskiy #define KVM_ARM_IRQ_GIC_MAX		127
431c5daeae1SAlexey Kardashevskiy 
4327a52ce8aSCornelia Huck /* One single KVM irqchip, ie. the VGIC */
4337a52ce8aSCornelia Huck #define KVM_NR_IRQCHIPS          1
4347a52ce8aSCornelia Huck 
435c5daeae1SAlexey Kardashevskiy /* PSCI interface */
436c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_BASE		0x95c1ba5e
437c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN(n)			(KVM_PSCI_FN_BASE + (n))
438c5daeae1SAlexey Kardashevskiy 
439c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_SUSPEND		KVM_PSCI_FN(0)
440c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_OFF		KVM_PSCI_FN(1)
441c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_CPU_ON		KVM_PSCI_FN(2)
442c5daeae1SAlexey Kardashevskiy #define KVM_PSCI_FN_MIGRATE		KVM_PSCI_FN(3)
443c5daeae1SAlexey Kardashevskiy 
444b061808dSAlexander Graf #define KVM_PSCI_RET_SUCCESS		PSCI_RET_SUCCESS
445b061808dSAlexander Graf #define KVM_PSCI_RET_NI			PSCI_RET_NOT_SUPPORTED
446b061808dSAlexander Graf #define KVM_PSCI_RET_INVAL		PSCI_RET_INVALID_PARAMS
447b061808dSAlexander Graf #define KVM_PSCI_RET_DENIED		PSCI_RET_DENIED
448c5daeae1SAlexey Kardashevskiy 
449e4082063SAlex Williamson /* arm64-specific kvm_run::system_event flags */
450e4082063SAlex Williamson /*
451e4082063SAlex Williamson  * Reset caused by a PSCI v1.1 SYSTEM_RESET2 call.
452e4082063SAlex Williamson  * Valid only when the system event has a type of KVM_SYSTEM_EVENT_RESET.
453e4082063SAlex Williamson  */
454e4082063SAlex Williamson #define KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2	(1ULL << 0)
455e4082063SAlex Williamson 
456e4082063SAlex Williamson /* run->fail_entry.hardware_entry_failure_reason codes. */
457e4082063SAlex Williamson #define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED	(1ULL << 0)
458e4082063SAlex Williamson 
459c5daeae1SAlexey Kardashevskiy #endif
460c5daeae1SAlexey Kardashevskiy 
461c5daeae1SAlexey Kardashevskiy #endif /* __ARM_KVM_H__ */
462