18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright SUSE Linux Products GmbH 2009
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Authors: Alexander Graf <agraf@suse.de>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __ASM_KVM_BOOK3S_ASM_H__
108c2ecf20Sopenharmony_ci#define __ASM_KVM_BOOK3S_ASM_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* XICS ICP register offsets */
138c2ecf20Sopenharmony_ci#define XICS_XIRR		4
148c2ecf20Sopenharmony_ci#define XICS_MFRR		0xc
158c2ecf20Sopenharmony_ci#define XICS_IPI		2	/* interrupt source # for IPIs */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* LPIDs we support with this build -- runtime limit may be lower */
188c2ecf20Sopenharmony_ci#define KVMPPC_NR_LPIDS			(LPID_RSVD + 1)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Maximum number of threads per physical core */
218c2ecf20Sopenharmony_ci#define MAX_SMT_THREADS		8
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* Maximum number of subcores per physical core */
248c2ecf20Sopenharmony_ci#define MAX_SUBCORES		4
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef __ASSEMBLY__
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HANDLER
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#include <asm/kvm_asm.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci.macro DO_KVM intno
338c2ecf20Sopenharmony_ci	.if (\intno == BOOK3S_INTERRUPT_SYSTEM_RESET) || \
348c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_MACHINE_CHECK) || \
358c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_DATA_STORAGE) || \
368c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_INST_STORAGE) || \
378c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_DATA_SEGMENT) || \
388c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_INST_SEGMENT) || \
398c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_EXTERNAL) || \
408c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_EXTERNAL_HV) || \
418c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_ALIGNMENT) || \
428c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_PROGRAM) || \
438c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_FP_UNAVAIL) || \
448c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_DECREMENTER) || \
458c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_SYSCALL) || \
468c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_TRACE) || \
478c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_PERFMON) || \
488c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_ALTIVEC) || \
498c2ecf20Sopenharmony_ci	    (\intno == BOOK3S_INTERRUPT_VSX)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	b	kvmppc_trampoline_\intno
528c2ecf20Sopenharmony_cikvmppc_resume_\intno:
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	.endif
558c2ecf20Sopenharmony_ci.endm
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#else
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci.macro DO_KVM intno
608c2ecf20Sopenharmony_ci.endm
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#endif /* CONFIG_KVM_BOOK3S_HANDLER */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#else  /*__ASSEMBLY__ */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistruct kvmppc_vcore;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Struct used for coordinating micro-threading (split-core) mode changes */
698c2ecf20Sopenharmony_cistruct kvm_split_mode {
708c2ecf20Sopenharmony_ci	unsigned long	rpr;
718c2ecf20Sopenharmony_ci	unsigned long	pmmar;
728c2ecf20Sopenharmony_ci	unsigned long	ldbar;
738c2ecf20Sopenharmony_ci	u8		subcore_size;
748c2ecf20Sopenharmony_ci	u8		do_nap;
758c2ecf20Sopenharmony_ci	u8		napped[MAX_SMT_THREADS];
768c2ecf20Sopenharmony_ci	struct kvmppc_vcore *vc[MAX_SUBCORES];
778c2ecf20Sopenharmony_ci	/* Bits for changing lpcr on P9 */
788c2ecf20Sopenharmony_ci	unsigned long	lpcr_req;
798c2ecf20Sopenharmony_ci	unsigned long	lpidr_req;
808c2ecf20Sopenharmony_ci	unsigned long	host_lpcr;
818c2ecf20Sopenharmony_ci	u32		do_set;
828c2ecf20Sopenharmony_ci	u32		do_restore;
838c2ecf20Sopenharmony_ci	union {
848c2ecf20Sopenharmony_ci		u32	allphases;
858c2ecf20Sopenharmony_ci		u8	phase[4];
868c2ecf20Sopenharmony_ci	} lpcr_sync;
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/*
908c2ecf20Sopenharmony_ci * This struct goes in the PACA on 64-bit processors.  It is used
918c2ecf20Sopenharmony_ci * to store host state that needs to be saved when we enter a guest
928c2ecf20Sopenharmony_ci * and restored when we exit, but isn't specific to any particular
938c2ecf20Sopenharmony_ci * guest or vcpu.  It also has some scratch fields used by the guest
948c2ecf20Sopenharmony_ci * exit code.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cistruct kvmppc_host_state {
978c2ecf20Sopenharmony_ci	ulong host_r1;
988c2ecf20Sopenharmony_ci	ulong host_r2;
998c2ecf20Sopenharmony_ci	ulong host_msr;
1008c2ecf20Sopenharmony_ci	ulong vmhandler;
1018c2ecf20Sopenharmony_ci	ulong scratch0;
1028c2ecf20Sopenharmony_ci	ulong scratch1;
1038c2ecf20Sopenharmony_ci	ulong scratch2;
1048c2ecf20Sopenharmony_ci	u8 in_guest;
1058c2ecf20Sopenharmony_ci	u8 restore_hid5;
1068c2ecf20Sopenharmony_ci	u8 napping;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
1098c2ecf20Sopenharmony_ci	u8 hwthread_req;
1108c2ecf20Sopenharmony_ci	u8 hwthread_state;
1118c2ecf20Sopenharmony_ci	u8 host_ipi;
1128c2ecf20Sopenharmony_ci	u8 ptid;		/* thread number within subcore when split */
1138c2ecf20Sopenharmony_ci	u8 tid;			/* thread number within whole core */
1148c2ecf20Sopenharmony_ci	u8 fake_suspend;
1158c2ecf20Sopenharmony_ci	struct kvm_vcpu *kvm_vcpu;
1168c2ecf20Sopenharmony_ci	struct kvmppc_vcore *kvm_vcore;
1178c2ecf20Sopenharmony_ci	void __iomem *xics_phys;
1188c2ecf20Sopenharmony_ci	void __iomem *xive_tima_phys;
1198c2ecf20Sopenharmony_ci	void __iomem *xive_tima_virt;
1208c2ecf20Sopenharmony_ci	u32 saved_xirr;
1218c2ecf20Sopenharmony_ci	u64 dabr;
1228c2ecf20Sopenharmony_ci	u64 host_mmcr[10];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER, MMCR3, SIER2/3 */
1238c2ecf20Sopenharmony_ci	u32 host_pmc[8];
1248c2ecf20Sopenharmony_ci	u64 host_purr;
1258c2ecf20Sopenharmony_ci	u64 host_spurr;
1268c2ecf20Sopenharmony_ci	u64 host_dscr;
1278c2ecf20Sopenharmony_ci	u64 dec_expires;
1288c2ecf20Sopenharmony_ci	struct kvm_split_mode *kvm_split_mode;
1298c2ecf20Sopenharmony_ci#endif
1308c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
1318c2ecf20Sopenharmony_ci	u64 cfar;
1328c2ecf20Sopenharmony_ci	u64 ppr;
1338c2ecf20Sopenharmony_ci	u64 host_fscr;
1348c2ecf20Sopenharmony_ci#endif
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistruct kvmppc_book3s_shadow_vcpu {
1388c2ecf20Sopenharmony_ci	bool in_use;
1398c2ecf20Sopenharmony_ci	ulong gpr[14];
1408c2ecf20Sopenharmony_ci	u32 cr;
1418c2ecf20Sopenharmony_ci	ulong xer;
1428c2ecf20Sopenharmony_ci	ulong ctr;
1438c2ecf20Sopenharmony_ci	ulong lr;
1448c2ecf20Sopenharmony_ci	ulong pc;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	ulong shadow_srr1;
1478c2ecf20Sopenharmony_ci	ulong fault_dar;
1488c2ecf20Sopenharmony_ci	u32 fault_dsisr;
1498c2ecf20Sopenharmony_ci	u32 last_inst;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_32
1528c2ecf20Sopenharmony_ci	u32     sr[16];			/* Guest SRs */
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	struct kvmppc_host_state hstate;
1558c2ecf20Sopenharmony_ci#endif
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
1588c2ecf20Sopenharmony_ci	u8 slb_max;			/* highest used guest slb entry */
1598c2ecf20Sopenharmony_ci	struct  {
1608c2ecf20Sopenharmony_ci		u64     esid;
1618c2ecf20Sopenharmony_ci		u64     vsid;
1628c2ecf20Sopenharmony_ci	} slb[64];			/* guest SLB */
1638c2ecf20Sopenharmony_ci	u64 shadow_fscr;
1648c2ecf20Sopenharmony_ci#endif
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#endif /*__ASSEMBLY__ */
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* Values for kvm_state */
1708c2ecf20Sopenharmony_ci#define KVM_HWTHREAD_IN_KERNEL	0
1718c2ecf20Sopenharmony_ci#define KVM_HWTHREAD_IN_IDLE	1
1728c2ecf20Sopenharmony_ci#define KVM_HWTHREAD_IN_KVM	2
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#endif /* __ASM_KVM_BOOK3S_ASM_H__ */
175