xref: /linux/arch/powerpc/include/uapi/asm/kvm_para.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License, version 2, as
5  * published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15  *
16  * Copyright IBM Corp. 2008
17  *
18  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19  */
20 
21 #ifndef _UAPI__POWERPC_KVM_PARA_H__
22 #define _UAPI__POWERPC_KVM_PARA_H__
23 
24 #include <linux/types.h>
25 
26 /*
27  * Additions to this struct must only occur at the end, and should be
28  * accompanied by a KVM_MAGIC_FEAT flag to advertise that they are present
29  * (albeit not necessarily relevant to the current target hardware platform).
30  *
31  * Struct fields are always 32 or 64 bit aligned, depending on them being 32
32  * or 64 bit wide respectively.
33  *
34  * See Documentation/virt/kvm/ppc-pv.rst
35  */
36 struct kvm_vcpu_arch_shared {
37 	__u64 scratch1;
38 	__u64 scratch2;
39 	__u64 scratch3;
40 	__u64 critical;		/* Guest may not get interrupts if == r1 */
41 	__u64 sprg0;
42 	__u64 sprg1;
43 	__u64 sprg2;
44 	__u64 sprg3;
45 	__u64 srr0;
46 	__u64 srr1;
47 	__u64 dar;		/* dear on BookE */
48 	__u64 msr;
49 	__u32 dsisr;
50 	__u32 int_pending;	/* Tells the guest if we have an interrupt */
51 	__u32 sr[16];
52 	__u32 mas0;
53 	__u32 mas1;
54 	__u64 mas7_3;
55 	__u64 mas2;
56 	__u32 mas4;
57 	__u32 mas6;
58 	__u32 esr;
59 	__u32 pir;
60 
61 	/*
62 	 * SPRG4-7 are user-readable, so we can only keep these consistent
63 	 * between the shared area and the real registers when there's an
64 	 * intervening exit to KVM.  This also applies to SPRG3 on some
65 	 * chips.
66 	 *
67 	 * This suffices for access by guest userspace, since in PR-mode
68 	 * KVM, an exit must occur when changing the guest's MSR[PR].
69 	 * If the guest kernel writes to SPRG3-7 via the shared area, it
70 	 * must also use the shared area for reading while in kernel space.
71 	 */
72 	__u64 sprg4;
73 	__u64 sprg5;
74 	__u64 sprg6;
75 	__u64 sprg7;
76 };
77 
78 #define KVM_SC_MAGIC_R0		0x4b564d21 /* "KVM!" */
79 
80 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
81 
82 #include <asm/epapr_hcalls.h>
83 
84 #define KVM_FEATURE_MAGIC_PAGE	1
85 
86 /* Magic page flags from host to guest */
87 
88 #define KVM_MAGIC_FEAT_SR		(1 << 0)
89 
90 /* MASn, ESR, PIR, and high SPRGs */
91 #define KVM_MAGIC_FEAT_MAS0_TO_SPRG7	(1 << 1)
92 
93 /* Magic page flags from guest to host */
94 
95 #define MAGIC_PAGE_FLAG_NOT_MAPPED_NX	(1 << 0)
96 
97 
98 #endif /* _UAPI__POWERPC_KVM_PARA_H__ */
99