18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
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/asm/kvm_host.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
118c2ecf20Sopenharmony_ci#ifndef __ARM64_KVM_HOST_H__
128c2ecf20Sopenharmony_ci#define __ARM64_KVM_HOST_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/arm-smccc.h>
158c2ecf20Sopenharmony_ci#include <linux/bitmap.h>
168c2ecf20Sopenharmony_ci#include <linux/types.h>
178c2ecf20Sopenharmony_ci#include <linux/jump_label.h>
188c2ecf20Sopenharmony_ci#include <linux/kvm_types.h>
198c2ecf20Sopenharmony_ci#include <linux/percpu.h>
208c2ecf20Sopenharmony_ci#include <asm/arch_gicv3.h>
218c2ecf20Sopenharmony_ci#include <asm/barrier.h>
228c2ecf20Sopenharmony_ci#include <asm/cpufeature.h>
238c2ecf20Sopenharmony_ci#include <asm/cputype.h>
248c2ecf20Sopenharmony_ci#include <asm/daifflags.h>
258c2ecf20Sopenharmony_ci#include <asm/fpsimd.h>
268c2ecf20Sopenharmony_ci#include <asm/kvm.h>
278c2ecf20Sopenharmony_ci#include <asm/kvm_asm.h>
288c2ecf20Sopenharmony_ci#include <asm/thread_info.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define __KVM_HAVE_ARCH_INTC_INITIALIZED
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define KVM_USER_MEM_SLOTS 512
338c2ecf20Sopenharmony_ci#define KVM_HALT_POLL_NS_DEFAULT 500000
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <kvm/arm_vgic.h>
368c2ecf20Sopenharmony_ci#include <kvm/arm_arch_timer.h>
378c2ecf20Sopenharmony_ci#include <kvm/arm_pmu.h>
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define KVM_VCPU_MAX_FEATURES 7
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define KVM_REQ_SLEEP \
448c2ecf20Sopenharmony_ci	KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
458c2ecf20Sopenharmony_ci#define KVM_REQ_IRQ_PENDING	KVM_ARCH_REQ(1)
468c2ecf20Sopenharmony_ci#define KVM_REQ_VCPU_RESET	KVM_ARCH_REQ(2)
478c2ecf20Sopenharmony_ci#define KVM_REQ_RECORD_STEAL	KVM_ARCH_REQ(3)
488c2ecf20Sopenharmony_ci#define KVM_REQ_RELOAD_GICv4	KVM_ARCH_REQ(4)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
518c2ecf20Sopenharmony_ci				     KVM_DIRTY_LOG_INITIALLY_SET)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciDECLARE_STATIC_KEY_FALSE(userspace_irqchip_in_use);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciextern unsigned int kvm_sve_max_vl;
568c2ecf20Sopenharmony_ciint kvm_arm_init_sve(void);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciint __attribute_const__ kvm_target_cpu(void);
598c2ecf20Sopenharmony_ciint kvm_reset_vcpu(struct kvm_vcpu *vcpu);
608c2ecf20Sopenharmony_civoid kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu);
618c2ecf20Sopenharmony_ciint kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext);
628c2ecf20Sopenharmony_civoid __extended_idmap_trampoline(phys_addr_t boot_pgd, phys_addr_t idmap_start);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct kvm_vmid {
658c2ecf20Sopenharmony_ci	/* The VMID generation used for the virt. memory system */
668c2ecf20Sopenharmony_ci	u64    vmid_gen;
678c2ecf20Sopenharmony_ci	u32    vmid;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct kvm_s2_mmu {
718c2ecf20Sopenharmony_ci	struct kvm_vmid vmid;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	/*
748c2ecf20Sopenharmony_ci	 * stage2 entry level table
758c2ecf20Sopenharmony_ci	 *
768c2ecf20Sopenharmony_ci	 * Two kvm_s2_mmu structures in the same VM can point to the same
778c2ecf20Sopenharmony_ci	 * pgd here.  This happens when running a guest using a
788c2ecf20Sopenharmony_ci	 * translation regime that isn't affected by its own stage-2
798c2ecf20Sopenharmony_ci	 * translation, such as a non-VHE hypervisor running at vEL2, or
808c2ecf20Sopenharmony_ci	 * for vEL1/EL0 with vHCR_EL2.VM == 0.  In that case, we use the
818c2ecf20Sopenharmony_ci	 * canonical stage-2 page tables.
828c2ecf20Sopenharmony_ci	 */
838c2ecf20Sopenharmony_ci	phys_addr_t	pgd_phys;
848c2ecf20Sopenharmony_ci	struct kvm_pgtable *pgt;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* The last vcpu id that ran on each physical CPU */
878c2ecf20Sopenharmony_ci	int __percpu *last_vcpu_ran;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	struct kvm *kvm;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct kvm_arch {
938c2ecf20Sopenharmony_ci	struct kvm_s2_mmu mmu;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	/* VTCR_EL2 value for this VM */
968c2ecf20Sopenharmony_ci	u64    vtcr;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	/* The maximum number of vCPUs depends on the used GIC model */
998c2ecf20Sopenharmony_ci	int max_vcpus;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/* Interrupt controller */
1028c2ecf20Sopenharmony_ci	struct vgic_dist	vgic;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	/* Mandated version of PSCI */
1058c2ecf20Sopenharmony_ci	u32 psci_version;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/*
1088c2ecf20Sopenharmony_ci	 * If we encounter a data abort without valid instruction syndrome
1098c2ecf20Sopenharmony_ci	 * information, report this to user space.  User space can (and
1108c2ecf20Sopenharmony_ci	 * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is
1118c2ecf20Sopenharmony_ci	 * supported.
1128c2ecf20Sopenharmony_ci	 */
1138c2ecf20Sopenharmony_ci	bool return_nisv_io_abort_to_user;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	/*
1168c2ecf20Sopenharmony_ci	 * VM-wide PMU filter, implemented as a bitmap and big enough for
1178c2ecf20Sopenharmony_ci	 * up to 2^10 events (ARMv8.0) or 2^16 events (ARMv8.1+).
1188c2ecf20Sopenharmony_ci	 */
1198c2ecf20Sopenharmony_ci	unsigned long *pmu_filter;
1208c2ecf20Sopenharmony_ci	unsigned int pmuver;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	u8 pfr0_csv2;
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct kvm_vcpu_fault_info {
1268c2ecf20Sopenharmony_ci	u32 esr_el2;		/* Hyp Syndrom Register */
1278c2ecf20Sopenharmony_ci	u64 far_el2;		/* Hyp Fault Address Register */
1288c2ecf20Sopenharmony_ci	u64 hpfar_el2;		/* Hyp IPA Fault Address Register */
1298c2ecf20Sopenharmony_ci	u64 disr_el1;		/* Deferred [SError] Status Register */
1308c2ecf20Sopenharmony_ci};
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cienum vcpu_sysreg {
1338c2ecf20Sopenharmony_ci	__INVALID_SYSREG__,   /* 0 is reserved as an invalid value */
1348c2ecf20Sopenharmony_ci	MPIDR_EL1,	/* MultiProcessor Affinity Register */
1358c2ecf20Sopenharmony_ci	CSSELR_EL1,	/* Cache Size Selection Register */
1368c2ecf20Sopenharmony_ci	SCTLR_EL1,	/* System Control Register */
1378c2ecf20Sopenharmony_ci	ACTLR_EL1,	/* Auxiliary Control Register */
1388c2ecf20Sopenharmony_ci	CPACR_EL1,	/* Coprocessor Access Control */
1398c2ecf20Sopenharmony_ci	ZCR_EL1,	/* SVE Control */
1408c2ecf20Sopenharmony_ci	TTBR0_EL1,	/* Translation Table Base Register 0 */
1418c2ecf20Sopenharmony_ci	TTBR1_EL1,	/* Translation Table Base Register 1 */
1428c2ecf20Sopenharmony_ci	TCR_EL1,	/* Translation Control Register */
1438c2ecf20Sopenharmony_ci	ESR_EL1,	/* Exception Syndrome Register */
1448c2ecf20Sopenharmony_ci	AFSR0_EL1,	/* Auxiliary Fault Status Register 0 */
1458c2ecf20Sopenharmony_ci	AFSR1_EL1,	/* Auxiliary Fault Status Register 1 */
1468c2ecf20Sopenharmony_ci	FAR_EL1,	/* Fault Address Register */
1478c2ecf20Sopenharmony_ci	MAIR_EL1,	/* Memory Attribute Indirection Register */
1488c2ecf20Sopenharmony_ci	VBAR_EL1,	/* Vector Base Address Register */
1498c2ecf20Sopenharmony_ci	CONTEXTIDR_EL1,	/* Context ID Register */
1508c2ecf20Sopenharmony_ci	TPIDR_EL0,	/* Thread ID, User R/W */
1518c2ecf20Sopenharmony_ci	TPIDRRO_EL0,	/* Thread ID, User R/O */
1528c2ecf20Sopenharmony_ci	TPIDR_EL1,	/* Thread ID, Privileged */
1538c2ecf20Sopenharmony_ci	AMAIR_EL1,	/* Aux Memory Attribute Indirection Register */
1548c2ecf20Sopenharmony_ci	CNTKCTL_EL1,	/* Timer Control Register (EL1) */
1558c2ecf20Sopenharmony_ci	PAR_EL1,	/* Physical Address Register */
1568c2ecf20Sopenharmony_ci	MDSCR_EL1,	/* Monitor Debug System Control Register */
1578c2ecf20Sopenharmony_ci	MDCCINT_EL1,	/* Monitor Debug Comms Channel Interrupt Enable Reg */
1588c2ecf20Sopenharmony_ci	DISR_EL1,	/* Deferred Interrupt Status Register */
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	/* Performance Monitors Registers */
1618c2ecf20Sopenharmony_ci	PMCR_EL0,	/* Control Register */
1628c2ecf20Sopenharmony_ci	PMSELR_EL0,	/* Event Counter Selection Register */
1638c2ecf20Sopenharmony_ci	PMEVCNTR0_EL0,	/* Event Counter Register (0-30) */
1648c2ecf20Sopenharmony_ci	PMEVCNTR30_EL0 = PMEVCNTR0_EL0 + 30,
1658c2ecf20Sopenharmony_ci	PMCCNTR_EL0,	/* Cycle Counter Register */
1668c2ecf20Sopenharmony_ci	PMEVTYPER0_EL0,	/* Event Type Register (0-30) */
1678c2ecf20Sopenharmony_ci	PMEVTYPER30_EL0 = PMEVTYPER0_EL0 + 30,
1688c2ecf20Sopenharmony_ci	PMCCFILTR_EL0,	/* Cycle Count Filter Register */
1698c2ecf20Sopenharmony_ci	PMCNTENSET_EL0,	/* Count Enable Set Register */
1708c2ecf20Sopenharmony_ci	PMINTENSET_EL1,	/* Interrupt Enable Set Register */
1718c2ecf20Sopenharmony_ci	PMOVSSET_EL0,	/* Overflow Flag Status Set Register */
1728c2ecf20Sopenharmony_ci	PMSWINC_EL0,	/* Software Increment Register */
1738c2ecf20Sopenharmony_ci	PMUSERENR_EL0,	/* User Enable Register */
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	/* Pointer Authentication Registers in a strict increasing order. */
1768c2ecf20Sopenharmony_ci	APIAKEYLO_EL1,
1778c2ecf20Sopenharmony_ci	APIAKEYHI_EL1,
1788c2ecf20Sopenharmony_ci	APIBKEYLO_EL1,
1798c2ecf20Sopenharmony_ci	APIBKEYHI_EL1,
1808c2ecf20Sopenharmony_ci	APDAKEYLO_EL1,
1818c2ecf20Sopenharmony_ci	APDAKEYHI_EL1,
1828c2ecf20Sopenharmony_ci	APDBKEYLO_EL1,
1838c2ecf20Sopenharmony_ci	APDBKEYHI_EL1,
1848c2ecf20Sopenharmony_ci	APGAKEYLO_EL1,
1858c2ecf20Sopenharmony_ci	APGAKEYHI_EL1,
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	ELR_EL1,
1888c2ecf20Sopenharmony_ci	SP_EL1,
1898c2ecf20Sopenharmony_ci	SPSR_EL1,
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	CNTVOFF_EL2,
1928c2ecf20Sopenharmony_ci	CNTV_CVAL_EL0,
1938c2ecf20Sopenharmony_ci	CNTV_CTL_EL0,
1948c2ecf20Sopenharmony_ci	CNTP_CVAL_EL0,
1958c2ecf20Sopenharmony_ci	CNTP_CTL_EL0,
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	/* 32bit specific registers. Keep them at the end of the range */
1988c2ecf20Sopenharmony_ci	DACR32_EL2,	/* Domain Access Control Register */
1998c2ecf20Sopenharmony_ci	IFSR32_EL2,	/* Instruction Fault Status Register */
2008c2ecf20Sopenharmony_ci	FPEXC32_EL2,	/* Floating-Point Exception Control Register */
2018c2ecf20Sopenharmony_ci	DBGVCR32_EL2,	/* Debug Vector Catch Register */
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	NR_SYS_REGS	/* Nothing after this line! */
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/* 32bit mapping */
2078c2ecf20Sopenharmony_ci#define c0_MPIDR	(MPIDR_EL1 * 2)	/* MultiProcessor ID Register */
2088c2ecf20Sopenharmony_ci#define c0_CSSELR	(CSSELR_EL1 * 2)/* Cache Size Selection Register */
2098c2ecf20Sopenharmony_ci#define c1_SCTLR	(SCTLR_EL1 * 2)	/* System Control Register */
2108c2ecf20Sopenharmony_ci#define c1_ACTLR	(ACTLR_EL1 * 2)	/* Auxiliary Control Register */
2118c2ecf20Sopenharmony_ci#define c1_CPACR	(CPACR_EL1 * 2)	/* Coprocessor Access Control */
2128c2ecf20Sopenharmony_ci#define c2_TTBR0	(TTBR0_EL1 * 2)	/* Translation Table Base Register 0 */
2138c2ecf20Sopenharmony_ci#define c2_TTBR0_high	(c2_TTBR0 + 1)	/* TTBR0 top 32 bits */
2148c2ecf20Sopenharmony_ci#define c2_TTBR1	(TTBR1_EL1 * 2)	/* Translation Table Base Register 1 */
2158c2ecf20Sopenharmony_ci#define c2_TTBR1_high	(c2_TTBR1 + 1)	/* TTBR1 top 32 bits */
2168c2ecf20Sopenharmony_ci#define c2_TTBCR	(TCR_EL1 * 2)	/* Translation Table Base Control R. */
2178c2ecf20Sopenharmony_ci#define c2_TTBCR2	(c2_TTBCR + 1)	/* Translation Table Base Control R. 2 */
2188c2ecf20Sopenharmony_ci#define c3_DACR		(DACR32_EL2 * 2)/* Domain Access Control Register */
2198c2ecf20Sopenharmony_ci#define c5_DFSR		(ESR_EL1 * 2)	/* Data Fault Status Register */
2208c2ecf20Sopenharmony_ci#define c5_IFSR		(IFSR32_EL2 * 2)/* Instruction Fault Status Register */
2218c2ecf20Sopenharmony_ci#define c5_ADFSR	(AFSR0_EL1 * 2)	/* Auxiliary Data Fault Status R */
2228c2ecf20Sopenharmony_ci#define c5_AIFSR	(AFSR1_EL1 * 2)	/* Auxiliary Instr Fault Status R */
2238c2ecf20Sopenharmony_ci#define c6_DFAR		(FAR_EL1 * 2)	/* Data Fault Address Register */
2248c2ecf20Sopenharmony_ci#define c6_IFAR		(c6_DFAR + 1)	/* Instruction Fault Address Register */
2258c2ecf20Sopenharmony_ci#define c7_PAR		(PAR_EL1 * 2)	/* Physical Address Register */
2268c2ecf20Sopenharmony_ci#define c7_PAR_high	(c7_PAR + 1)	/* PAR top 32 bits */
2278c2ecf20Sopenharmony_ci#define c10_PRRR	(MAIR_EL1 * 2)	/* Primary Region Remap Register */
2288c2ecf20Sopenharmony_ci#define c10_NMRR	(c10_PRRR + 1)	/* Normal Memory Remap Register */
2298c2ecf20Sopenharmony_ci#define c12_VBAR	(VBAR_EL1 * 2)	/* Vector Base Address Register */
2308c2ecf20Sopenharmony_ci#define c13_CID		(CONTEXTIDR_EL1 * 2)	/* Context ID Register */
2318c2ecf20Sopenharmony_ci#define c13_TID_URW	(TPIDR_EL0 * 2)	/* Thread ID, User R/W */
2328c2ecf20Sopenharmony_ci#define c13_TID_URO	(TPIDRRO_EL0 * 2)/* Thread ID, User R/O */
2338c2ecf20Sopenharmony_ci#define c13_TID_PRIV	(TPIDR_EL1 * 2)	/* Thread ID, Privileged */
2348c2ecf20Sopenharmony_ci#define c10_AMAIR0	(AMAIR_EL1 * 2)	/* Aux Memory Attr Indirection Reg */
2358c2ecf20Sopenharmony_ci#define c10_AMAIR1	(c10_AMAIR0 + 1)/* Aux Memory Attr Indirection Reg */
2368c2ecf20Sopenharmony_ci#define c14_CNTKCTL	(CNTKCTL_EL1 * 2) /* Timer Control Register (PL1) */
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define cp14_DBGDSCRext	(MDSCR_EL1 * 2)
2398c2ecf20Sopenharmony_ci#define cp14_DBGBCR0	(DBGBCR0_EL1 * 2)
2408c2ecf20Sopenharmony_ci#define cp14_DBGBVR0	(DBGBVR0_EL1 * 2)
2418c2ecf20Sopenharmony_ci#define cp14_DBGBXVR0	(cp14_DBGBVR0 + 1)
2428c2ecf20Sopenharmony_ci#define cp14_DBGWCR0	(DBGWCR0_EL1 * 2)
2438c2ecf20Sopenharmony_ci#define cp14_DBGWVR0	(DBGWVR0_EL1 * 2)
2448c2ecf20Sopenharmony_ci#define cp14_DBGDCCINT	(MDCCINT_EL1 * 2)
2458c2ecf20Sopenharmony_ci#define cp14_DBGVCR	(DBGVCR32_EL2 * 2)
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci#define NR_COPRO_REGS	(NR_SYS_REGS * 2)
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistruct kvm_cpu_context {
2508c2ecf20Sopenharmony_ci	struct user_pt_regs regs;	/* sp = sp_el0 */
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	u64	spsr_abt;
2538c2ecf20Sopenharmony_ci	u64	spsr_und;
2548c2ecf20Sopenharmony_ci	u64	spsr_irq;
2558c2ecf20Sopenharmony_ci	u64	spsr_fiq;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	struct user_fpsimd_state fp_regs;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	union {
2608c2ecf20Sopenharmony_ci		u64 sys_regs[NR_SYS_REGS];
2618c2ecf20Sopenharmony_ci		u32 copro[NR_COPRO_REGS];
2628c2ecf20Sopenharmony_ci	};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	struct kvm_vcpu *__hyp_running_vcpu;
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistruct kvm_pmu_events {
2688c2ecf20Sopenharmony_ci	u32 events_host;
2698c2ecf20Sopenharmony_ci	u32 events_guest;
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistruct kvm_host_data {
2738c2ecf20Sopenharmony_ci	struct kvm_cpu_context host_ctxt;
2748c2ecf20Sopenharmony_ci	struct kvm_pmu_events pmu_events;
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistruct vcpu_reset_state {
2788c2ecf20Sopenharmony_ci	unsigned long	pc;
2798c2ecf20Sopenharmony_ci	unsigned long	r0;
2808c2ecf20Sopenharmony_ci	bool		be;
2818c2ecf20Sopenharmony_ci	bool		reset;
2828c2ecf20Sopenharmony_ci};
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistruct kvm_vcpu_arch {
2858c2ecf20Sopenharmony_ci	struct kvm_cpu_context ctxt;
2868c2ecf20Sopenharmony_ci	void *sve_state;
2878c2ecf20Sopenharmony_ci	unsigned int sve_max_vl;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	/* Stage 2 paging state used by the hardware on next switch */
2908c2ecf20Sopenharmony_ci	struct kvm_s2_mmu *hw_mmu;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	/* HYP configuration */
2938c2ecf20Sopenharmony_ci	u64 hcr_el2;
2948c2ecf20Sopenharmony_ci	u32 mdcr_el2;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	/* Exception Information */
2978c2ecf20Sopenharmony_ci	struct kvm_vcpu_fault_info fault;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	/* State of various workarounds, see kvm_asm.h for bit assignment */
3008c2ecf20Sopenharmony_ci	u64 workaround_flags;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	/* Miscellaneous vcpu state flags */
3038c2ecf20Sopenharmony_ci	u64 flags;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	/*
3068c2ecf20Sopenharmony_ci	 * We maintain more than a single set of debug registers to support
3078c2ecf20Sopenharmony_ci	 * debugging the guest from the host and to maintain separate host and
3088c2ecf20Sopenharmony_ci	 * guest state during world switches. vcpu_debug_state are the debug
3098c2ecf20Sopenharmony_ci	 * registers of the vcpu as the guest sees them.  host_debug_state are
3108c2ecf20Sopenharmony_ci	 * the host registers which are saved and restored during
3118c2ecf20Sopenharmony_ci	 * world switches. external_debug_state contains the debug
3128c2ecf20Sopenharmony_ci	 * values we want to debug the guest. This is set via the
3138c2ecf20Sopenharmony_ci	 * KVM_SET_GUEST_DEBUG ioctl.
3148c2ecf20Sopenharmony_ci	 *
3158c2ecf20Sopenharmony_ci	 * debug_ptr points to the set of debug registers that should be loaded
3168c2ecf20Sopenharmony_ci	 * onto the hardware when running the guest.
3178c2ecf20Sopenharmony_ci	 */
3188c2ecf20Sopenharmony_ci	struct kvm_guest_debug_arch *debug_ptr;
3198c2ecf20Sopenharmony_ci	struct kvm_guest_debug_arch vcpu_debug_state;
3208c2ecf20Sopenharmony_ci	struct kvm_guest_debug_arch external_debug_state;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	struct thread_info *host_thread_info;	/* hyp VA */
3238c2ecf20Sopenharmony_ci	struct user_fpsimd_state *host_fpsimd_state;	/* hyp VA */
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	struct {
3268c2ecf20Sopenharmony_ci		/* {Break,watch}point registers */
3278c2ecf20Sopenharmony_ci		struct kvm_guest_debug_arch regs;
3288c2ecf20Sopenharmony_ci		/* Statistical profiling extension */
3298c2ecf20Sopenharmony_ci		u64 pmscr_el1;
3308c2ecf20Sopenharmony_ci	} host_debug_state;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	/* VGIC state */
3338c2ecf20Sopenharmony_ci	struct vgic_cpu vgic_cpu;
3348c2ecf20Sopenharmony_ci	struct arch_timer_cpu timer_cpu;
3358c2ecf20Sopenharmony_ci	struct kvm_pmu pmu;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	/*
3388c2ecf20Sopenharmony_ci	 * Anything that is not used directly from assembly code goes
3398c2ecf20Sopenharmony_ci	 * here.
3408c2ecf20Sopenharmony_ci	 */
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	/*
3438c2ecf20Sopenharmony_ci	 * Guest registers we preserve during guest debugging.
3448c2ecf20Sopenharmony_ci	 *
3458c2ecf20Sopenharmony_ci	 * These shadow registers are updated by the kvm_handle_sys_reg
3468c2ecf20Sopenharmony_ci	 * trap handler if the guest accesses or updates them while we
3478c2ecf20Sopenharmony_ci	 * are using guest debug.
3488c2ecf20Sopenharmony_ci	 */
3498c2ecf20Sopenharmony_ci	struct {
3508c2ecf20Sopenharmony_ci		u32	mdscr_el1;
3518c2ecf20Sopenharmony_ci	} guest_debug_preserved;
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	/* vcpu power-off state */
3548c2ecf20Sopenharmony_ci	bool power_off;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	/* Don't run the guest (internal implementation need) */
3578c2ecf20Sopenharmony_ci	bool pause;
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	/* Cache some mmu pages needed inside spinlock regions */
3608c2ecf20Sopenharmony_ci	struct kvm_mmu_memory_cache mmu_page_cache;
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	/* Target CPU and feature flags */
3638c2ecf20Sopenharmony_ci	int target;
3648c2ecf20Sopenharmony_ci	DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES);
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	/* Detect first run of a vcpu */
3678c2ecf20Sopenharmony_ci	bool has_run_once;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* Virtual SError ESR to restore when HCR_EL2.VSE is set */
3708c2ecf20Sopenharmony_ci	u64 vsesr_el2;
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	/* Additional reset state */
3738c2ecf20Sopenharmony_ci	struct vcpu_reset_state	reset_state;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	/* True when deferrable sysregs are loaded on the physical CPU,
3768c2ecf20Sopenharmony_ci	 * see kvm_vcpu_load_sysregs_vhe and kvm_vcpu_put_sysregs_vhe. */
3778c2ecf20Sopenharmony_ci	bool sysregs_loaded_on_cpu;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	/* Guest PV state */
3808c2ecf20Sopenharmony_ci	struct {
3818c2ecf20Sopenharmony_ci		u64 last_steal;
3828c2ecf20Sopenharmony_ci		gpa_t base;
3838c2ecf20Sopenharmony_ci	} steal;
3848c2ecf20Sopenharmony_ci};
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci/* Pointer to the vcpu's SVE FFR for sve_{save,load}_state() */
3878c2ecf20Sopenharmony_ci#define vcpu_sve_pffr(vcpu) ((void *)((char *)((vcpu)->arch.sve_state) + \
3888c2ecf20Sopenharmony_ci				      sve_ffr_offset((vcpu)->arch.sve_max_vl)))
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define vcpu_sve_state_size(vcpu) ({					\
3918c2ecf20Sopenharmony_ci	size_t __size_ret;						\
3928c2ecf20Sopenharmony_ci	unsigned int __vcpu_vq;						\
3938c2ecf20Sopenharmony_ci									\
3948c2ecf20Sopenharmony_ci	if (WARN_ON(!sve_vl_valid((vcpu)->arch.sve_max_vl))) {		\
3958c2ecf20Sopenharmony_ci		__size_ret = 0;						\
3968c2ecf20Sopenharmony_ci	} else {							\
3978c2ecf20Sopenharmony_ci		__vcpu_vq = sve_vq_from_vl((vcpu)->arch.sve_max_vl);	\
3988c2ecf20Sopenharmony_ci		__size_ret = SVE_SIG_REGS_SIZE(__vcpu_vq);		\
3998c2ecf20Sopenharmony_ci	}								\
4008c2ecf20Sopenharmony_ci									\
4018c2ecf20Sopenharmony_ci	__size_ret;							\
4028c2ecf20Sopenharmony_ci})
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/* vcpu_arch flags field values: */
4058c2ecf20Sopenharmony_ci#define KVM_ARM64_DEBUG_DIRTY		(1 << 0)
4068c2ecf20Sopenharmony_ci#define KVM_ARM64_FP_ENABLED		(1 << 1) /* guest FP regs loaded */
4078c2ecf20Sopenharmony_ci#define KVM_ARM64_FP_HOST		(1 << 2) /* host FP regs loaded */
4088c2ecf20Sopenharmony_ci#define KVM_ARM64_HOST_SVE_IN_USE	(1 << 3) /* backup for host TIF_SVE */
4098c2ecf20Sopenharmony_ci#define KVM_ARM64_HOST_SVE_ENABLED	(1 << 4) /* SVE enabled for EL0 */
4108c2ecf20Sopenharmony_ci#define KVM_ARM64_GUEST_HAS_SVE		(1 << 5) /* SVE exposed to guest */
4118c2ecf20Sopenharmony_ci#define KVM_ARM64_VCPU_SVE_FINALIZED	(1 << 6) /* SVE config completed */
4128c2ecf20Sopenharmony_ci#define KVM_ARM64_GUEST_HAS_PTRAUTH	(1 << 7) /* PTRAUTH exposed to guest */
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci#define vcpu_has_sve(vcpu) (system_supports_sve() && \
4158c2ecf20Sopenharmony_ci			    ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_SVE))
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_PTR_AUTH
4188c2ecf20Sopenharmony_ci#define vcpu_has_ptrauth(vcpu)						\
4198c2ecf20Sopenharmony_ci	((cpus_have_final_cap(ARM64_HAS_ADDRESS_AUTH) ||		\
4208c2ecf20Sopenharmony_ci	  cpus_have_final_cap(ARM64_HAS_GENERIC_AUTH)) &&		\
4218c2ecf20Sopenharmony_ci	 (vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_PTRAUTH)
4228c2ecf20Sopenharmony_ci#else
4238c2ecf20Sopenharmony_ci#define vcpu_has_ptrauth(vcpu)		false
4248c2ecf20Sopenharmony_ci#endif
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci#define vcpu_gp_regs(v)		(&(v)->arch.ctxt.regs)
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/*
4298c2ecf20Sopenharmony_ci * Only use __vcpu_sys_reg/ctxt_sys_reg if you know you want the
4308c2ecf20Sopenharmony_ci * memory backed version of a register, and not the one most recently
4318c2ecf20Sopenharmony_ci * accessed by a running VCPU.  For example, for userspace access or
4328c2ecf20Sopenharmony_ci * for system registers that are never context switched, but only
4338c2ecf20Sopenharmony_ci * emulated.
4348c2ecf20Sopenharmony_ci */
4358c2ecf20Sopenharmony_ci#define __ctxt_sys_reg(c,r)	(&(c)->sys_regs[(r)])
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci#define ctxt_sys_reg(c,r)	(*__ctxt_sys_reg(c,r))
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci#define __vcpu_sys_reg(v,r)	(ctxt_sys_reg(&(v)->arch.ctxt, (r)))
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ciu64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg);
4428c2ecf20Sopenharmony_civoid vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci/*
4458c2ecf20Sopenharmony_ci * CP14 and CP15 live in the same array, as they are backed by the
4468c2ecf20Sopenharmony_ci * same system registers.
4478c2ecf20Sopenharmony_ci */
4488c2ecf20Sopenharmony_ci#define CPx_BIAS		IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci#define vcpu_cp14(v,r)		((v)->arch.ctxt.copro[(r) ^ CPx_BIAS])
4518c2ecf20Sopenharmony_ci#define vcpu_cp15(v,r)		((v)->arch.ctxt.copro[(r) ^ CPx_BIAS])
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_cistruct kvm_vm_stat {
4548c2ecf20Sopenharmony_ci	ulong remote_tlb_flush;
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistruct kvm_vcpu_stat {
4588c2ecf20Sopenharmony_ci	u64 halt_successful_poll;
4598c2ecf20Sopenharmony_ci	u64 halt_attempted_poll;
4608c2ecf20Sopenharmony_ci	u64 halt_poll_success_ns;
4618c2ecf20Sopenharmony_ci	u64 halt_poll_fail_ns;
4628c2ecf20Sopenharmony_ci	u64 halt_poll_invalid;
4638c2ecf20Sopenharmony_ci	u64 halt_wakeup;
4648c2ecf20Sopenharmony_ci	u64 hvc_exit_stat;
4658c2ecf20Sopenharmony_ci	u64 wfe_exit_stat;
4668c2ecf20Sopenharmony_ci	u64 wfi_exit_stat;
4678c2ecf20Sopenharmony_ci	u64 mmio_exit_user;
4688c2ecf20Sopenharmony_ci	u64 mmio_exit_kernel;
4698c2ecf20Sopenharmony_ci	u64 exits;
4708c2ecf20Sopenharmony_ci};
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ciint kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
4738c2ecf20Sopenharmony_ciunsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
4748c2ecf20Sopenharmony_ciint kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
4758c2ecf20Sopenharmony_ciint kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
4768c2ecf20Sopenharmony_ciint kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
4778c2ecf20Sopenharmony_ciint __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
4788c2ecf20Sopenharmony_ci			      struct kvm_vcpu_events *events);
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ciint __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
4818c2ecf20Sopenharmony_ci			      struct kvm_vcpu_events *events);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci#define KVM_ARCH_WANT_MMU_NOTIFIER
4848c2ecf20Sopenharmony_ciint kvm_unmap_hva_range(struct kvm *kvm,
4858c2ecf20Sopenharmony_ci			unsigned long start, unsigned long end, unsigned flags);
4868c2ecf20Sopenharmony_ciint kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
4878c2ecf20Sopenharmony_ciint kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
4888c2ecf20Sopenharmony_ciint kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_civoid kvm_arm_halt_guest(struct kvm *kvm);
4918c2ecf20Sopenharmony_civoid kvm_arm_resume_guest(struct kvm *kvm);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci#define kvm_call_hyp_nvhe(f, ...)						\
4948c2ecf20Sopenharmony_ci	({								\
4958c2ecf20Sopenharmony_ci		struct arm_smccc_res res;				\
4968c2ecf20Sopenharmony_ci									\
4978c2ecf20Sopenharmony_ci		arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(f),		\
4988c2ecf20Sopenharmony_ci				  ##__VA_ARGS__, &res);			\
4998c2ecf20Sopenharmony_ci		WARN_ON(res.a0 != SMCCC_RET_SUCCESS);			\
5008c2ecf20Sopenharmony_ci									\
5018c2ecf20Sopenharmony_ci		res.a1;							\
5028c2ecf20Sopenharmony_ci	})
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci/*
5058c2ecf20Sopenharmony_ci * The couple of isb() below are there to guarantee the same behaviour
5068c2ecf20Sopenharmony_ci * on VHE as on !VHE, where the eret to EL1 acts as a context
5078c2ecf20Sopenharmony_ci * synchronization event.
5088c2ecf20Sopenharmony_ci */
5098c2ecf20Sopenharmony_ci#define kvm_call_hyp(f, ...)						\
5108c2ecf20Sopenharmony_ci	do {								\
5118c2ecf20Sopenharmony_ci		if (has_vhe()) {					\
5128c2ecf20Sopenharmony_ci			f(__VA_ARGS__);					\
5138c2ecf20Sopenharmony_ci			isb();						\
5148c2ecf20Sopenharmony_ci		} else {						\
5158c2ecf20Sopenharmony_ci			kvm_call_hyp_nvhe(f, ##__VA_ARGS__);		\
5168c2ecf20Sopenharmony_ci		}							\
5178c2ecf20Sopenharmony_ci	} while(0)
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci#define kvm_call_hyp_ret(f, ...)					\
5208c2ecf20Sopenharmony_ci	({								\
5218c2ecf20Sopenharmony_ci		typeof(f(__VA_ARGS__)) ret;				\
5228c2ecf20Sopenharmony_ci									\
5238c2ecf20Sopenharmony_ci		if (has_vhe()) {					\
5248c2ecf20Sopenharmony_ci			ret = f(__VA_ARGS__);				\
5258c2ecf20Sopenharmony_ci			isb();						\
5268c2ecf20Sopenharmony_ci		} else {						\
5278c2ecf20Sopenharmony_ci			ret = kvm_call_hyp_nvhe(f, ##__VA_ARGS__);	\
5288c2ecf20Sopenharmony_ci		}							\
5298c2ecf20Sopenharmony_ci									\
5308c2ecf20Sopenharmony_ci		ret;							\
5318c2ecf20Sopenharmony_ci	})
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_civoid force_vm_exit(const cpumask_t *mask);
5348c2ecf20Sopenharmony_civoid kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ciint handle_exit(struct kvm_vcpu *vcpu, int exception_index);
5378c2ecf20Sopenharmony_civoid handle_exit_early(struct kvm_vcpu *vcpu, int exception_index);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci/* MMIO helpers */
5408c2ecf20Sopenharmony_civoid kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
5418c2ecf20Sopenharmony_ciunsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ciint kvm_handle_mmio_return(struct kvm_vcpu *vcpu);
5448c2ecf20Sopenharmony_ciint io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa);
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ciint kvm_perf_init(void);
5478c2ecf20Sopenharmony_ciint kvm_perf_teardown(void);
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cilong kvm_hypercall_pv_features(struct kvm_vcpu *vcpu);
5508c2ecf20Sopenharmony_cigpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu);
5518c2ecf20Sopenharmony_civoid kvm_update_stolen_time(struct kvm_vcpu *vcpu);
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_cibool kvm_arm_pvtime_supported(void);
5548c2ecf20Sopenharmony_ciint kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu,
5558c2ecf20Sopenharmony_ci			    struct kvm_device_attr *attr);
5568c2ecf20Sopenharmony_ciint kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,
5578c2ecf20Sopenharmony_ci			    struct kvm_device_attr *attr);
5588c2ecf20Sopenharmony_ciint kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu,
5598c2ecf20Sopenharmony_ci			    struct kvm_device_attr *attr);
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_cistatic inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch)
5628c2ecf20Sopenharmony_ci{
5638c2ecf20Sopenharmony_ci	vcpu_arch->steal.base = GPA_INVALID;
5648c2ecf20Sopenharmony_ci}
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_cistatic inline bool kvm_arm_is_pvtime_enabled(struct kvm_vcpu_arch *vcpu_arch)
5678c2ecf20Sopenharmony_ci{
5688c2ecf20Sopenharmony_ci	return (vcpu_arch->steal.base != GPA_INVALID);
5698c2ecf20Sopenharmony_ci}
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_civoid kvm_set_sei_esr(struct kvm_vcpu *vcpu, u64 syndrome);
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_cistruct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ciDECLARE_KVM_HYP_PER_CPU(struct kvm_host_data, kvm_host_data);
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_cistatic inline void kvm_init_host_cpu_context(struct kvm_cpu_context *cpu_ctxt)
5788c2ecf20Sopenharmony_ci{
5798c2ecf20Sopenharmony_ci	/* The host's MPIDR is immutable, so let's set it up at boot time */
5808c2ecf20Sopenharmony_ci	ctxt_sys_reg(cpu_ctxt, MPIDR_EL1) = read_cpuid_mpidr();
5818c2ecf20Sopenharmony_ci}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_cistatic inline bool kvm_arch_requires_vhe(void)
5848c2ecf20Sopenharmony_ci{
5858c2ecf20Sopenharmony_ci	/*
5868c2ecf20Sopenharmony_ci	 * The Arm architecture specifies that implementation of SVE
5878c2ecf20Sopenharmony_ci	 * requires VHE also to be implemented.  The KVM code for arm64
5888c2ecf20Sopenharmony_ci	 * relies on this when SVE is present:
5898c2ecf20Sopenharmony_ci	 */
5908c2ecf20Sopenharmony_ci	if (system_supports_sve())
5918c2ecf20Sopenharmony_ci		return true;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	return false;
5948c2ecf20Sopenharmony_ci}
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_civoid kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu);
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_cistatic inline void kvm_arch_hardware_unsetup(void) {}
5998c2ecf20Sopenharmony_cistatic inline void kvm_arch_sync_events(struct kvm *kvm) {}
6008c2ecf20Sopenharmony_cistatic inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
6018c2ecf20Sopenharmony_cistatic inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_civoid kvm_arm_init_debug(void);
6048c2ecf20Sopenharmony_civoid kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu);
6058c2ecf20Sopenharmony_civoid kvm_arm_setup_debug(struct kvm_vcpu *vcpu);
6068c2ecf20Sopenharmony_civoid kvm_arm_clear_debug(struct kvm_vcpu *vcpu);
6078c2ecf20Sopenharmony_civoid kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu);
6088c2ecf20Sopenharmony_ciint kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu,
6098c2ecf20Sopenharmony_ci			       struct kvm_device_attr *attr);
6108c2ecf20Sopenharmony_ciint kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu,
6118c2ecf20Sopenharmony_ci			       struct kvm_device_attr *attr);
6128c2ecf20Sopenharmony_ciint kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu,
6138c2ecf20Sopenharmony_ci			       struct kvm_device_attr *attr);
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci/* Guest/host FPSIMD coordination helpers */
6168c2ecf20Sopenharmony_ciint kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu);
6178c2ecf20Sopenharmony_civoid kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu);
6188c2ecf20Sopenharmony_civoid kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu);
6198c2ecf20Sopenharmony_civoid kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_cistatic inline bool kvm_pmu_counter_deferred(struct perf_event_attr *attr)
6228c2ecf20Sopenharmony_ci{
6238c2ecf20Sopenharmony_ci	return (!has_vhe() && attr->exclude_host);
6248c2ecf20Sopenharmony_ci}
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM /* Avoid conflicts with core headers if CONFIG_KVM=n */
6278c2ecf20Sopenharmony_cistatic inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
6288c2ecf20Sopenharmony_ci{
6298c2ecf20Sopenharmony_ci	return kvm_arch_vcpu_run_map_fp(vcpu);
6308c2ecf20Sopenharmony_ci}
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_civoid kvm_set_pmu_events(u32 set, struct perf_event_attr *attr);
6338c2ecf20Sopenharmony_civoid kvm_clr_pmu_events(u32 clr);
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_civoid kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
6368c2ecf20Sopenharmony_civoid kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
6378c2ecf20Sopenharmony_ci#else
6388c2ecf20Sopenharmony_cistatic inline void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) {}
6398c2ecf20Sopenharmony_cistatic inline void kvm_clr_pmu_events(u32 clr) {}
6408c2ecf20Sopenharmony_ci#endif
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_civoid kvm_vcpu_load_sysregs_vhe(struct kvm_vcpu *vcpu);
6438c2ecf20Sopenharmony_civoid kvm_vcpu_put_sysregs_vhe(struct kvm_vcpu *vcpu);
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ciint kvm_set_ipa_limit(void);
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci#define __KVM_HAVE_ARCH_VM_ALLOC
6488c2ecf20Sopenharmony_cistruct kvm *kvm_arch_alloc_vm(void);
6498c2ecf20Sopenharmony_civoid kvm_arch_free_vm(struct kvm *kvm);
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ciint kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type);
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ciint kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature);
6548c2ecf20Sopenharmony_cibool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci#define kvm_arm_vcpu_sve_finalized(vcpu) \
6578c2ecf20Sopenharmony_ci	((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED)
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci#endif /* __ARM64_KVM_HOST_H__ */
660