xref: /openbmc/linux/arch/powerpc/include/uapi/asm/kvm.h (revision c3617f72036c909e1f6086b5b9e364e0ef90a6da)
1*c3617f72SDavid Howells /*
2*c3617f72SDavid Howells  * This program is free software; you can redistribute it and/or modify
3*c3617f72SDavid Howells  * it under the terms of the GNU General Public License, version 2, as
4*c3617f72SDavid Howells  * published by the Free Software Foundation.
5*c3617f72SDavid Howells  *
6*c3617f72SDavid Howells  * This program is distributed in the hope that it will be useful,
7*c3617f72SDavid Howells  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8*c3617f72SDavid Howells  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9*c3617f72SDavid Howells  * GNU General Public License for more details.
10*c3617f72SDavid Howells  *
11*c3617f72SDavid Howells  * You should have received a copy of the GNU General Public License
12*c3617f72SDavid Howells  * along with this program; if not, write to the Free Software
13*c3617f72SDavid Howells  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14*c3617f72SDavid Howells  *
15*c3617f72SDavid Howells  * Copyright IBM Corp. 2007
16*c3617f72SDavid Howells  *
17*c3617f72SDavid Howells  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18*c3617f72SDavid Howells  */
19*c3617f72SDavid Howells 
20*c3617f72SDavid Howells #ifndef __LINUX_KVM_POWERPC_H
21*c3617f72SDavid Howells #define __LINUX_KVM_POWERPC_H
22*c3617f72SDavid Howells 
23*c3617f72SDavid Howells #include <linux/types.h>
24*c3617f72SDavid Howells 
25*c3617f72SDavid Howells /* Select powerpc specific features in <linux/kvm.h> */
26*c3617f72SDavid Howells #define __KVM_HAVE_SPAPR_TCE
27*c3617f72SDavid Howells #define __KVM_HAVE_PPC_SMT
28*c3617f72SDavid Howells 
29*c3617f72SDavid Howells struct kvm_regs {
30*c3617f72SDavid Howells 	__u64 pc;
31*c3617f72SDavid Howells 	__u64 cr;
32*c3617f72SDavid Howells 	__u64 ctr;
33*c3617f72SDavid Howells 	__u64 lr;
34*c3617f72SDavid Howells 	__u64 xer;
35*c3617f72SDavid Howells 	__u64 msr;
36*c3617f72SDavid Howells 	__u64 srr0;
37*c3617f72SDavid Howells 	__u64 srr1;
38*c3617f72SDavid Howells 	__u64 pid;
39*c3617f72SDavid Howells 
40*c3617f72SDavid Howells 	__u64 sprg0;
41*c3617f72SDavid Howells 	__u64 sprg1;
42*c3617f72SDavid Howells 	__u64 sprg2;
43*c3617f72SDavid Howells 	__u64 sprg3;
44*c3617f72SDavid Howells 	__u64 sprg4;
45*c3617f72SDavid Howells 	__u64 sprg5;
46*c3617f72SDavid Howells 	__u64 sprg6;
47*c3617f72SDavid Howells 	__u64 sprg7;
48*c3617f72SDavid Howells 
49*c3617f72SDavid Howells 	__u64 gpr[32];
50*c3617f72SDavid Howells };
51*c3617f72SDavid Howells 
52*c3617f72SDavid Howells #define KVM_SREGS_E_IMPL_NONE	0
53*c3617f72SDavid Howells #define KVM_SREGS_E_IMPL_FSL	1
54*c3617f72SDavid Howells 
55*c3617f72SDavid Howells #define KVM_SREGS_E_FSL_PIDn	(1 << 0) /* PID1/PID2 */
56*c3617f72SDavid Howells 
57*c3617f72SDavid Howells /*
58*c3617f72SDavid Howells  * Feature bits indicate which sections of the sregs struct are valid,
59*c3617f72SDavid Howells  * both in KVM_GET_SREGS and KVM_SET_SREGS.  On KVM_SET_SREGS, registers
60*c3617f72SDavid Howells  * corresponding to unset feature bits will not be modified.  This allows
61*c3617f72SDavid Howells  * restoring a checkpoint made without that feature, while keeping the
62*c3617f72SDavid Howells  * default values of the new registers.
63*c3617f72SDavid Howells  *
64*c3617f72SDavid Howells  * KVM_SREGS_E_BASE contains:
65*c3617f72SDavid Howells  * CSRR0/1 (refers to SRR2/3 on 40x)
66*c3617f72SDavid Howells  * ESR
67*c3617f72SDavid Howells  * DEAR
68*c3617f72SDavid Howells  * MCSR
69*c3617f72SDavid Howells  * TSR
70*c3617f72SDavid Howells  * TCR
71*c3617f72SDavid Howells  * DEC
72*c3617f72SDavid Howells  * TB
73*c3617f72SDavid Howells  * VRSAVE (USPRG0)
74*c3617f72SDavid Howells  */
75*c3617f72SDavid Howells #define KVM_SREGS_E_BASE		(1 << 0)
76*c3617f72SDavid Howells 
77*c3617f72SDavid Howells /*
78*c3617f72SDavid Howells  * KVM_SREGS_E_ARCH206 contains:
79*c3617f72SDavid Howells  *
80*c3617f72SDavid Howells  * PIR
81*c3617f72SDavid Howells  * MCSRR0/1
82*c3617f72SDavid Howells  * DECAR
83*c3617f72SDavid Howells  * IVPR
84*c3617f72SDavid Howells  */
85*c3617f72SDavid Howells #define KVM_SREGS_E_ARCH206		(1 << 1)
86*c3617f72SDavid Howells 
87*c3617f72SDavid Howells /*
88*c3617f72SDavid Howells  * Contains EPCR, plus the upper half of 64-bit registers
89*c3617f72SDavid Howells  * that are 32-bit on 32-bit implementations.
90*c3617f72SDavid Howells  */
91*c3617f72SDavid Howells #define KVM_SREGS_E_64			(1 << 2)
92*c3617f72SDavid Howells 
93*c3617f72SDavid Howells #define KVM_SREGS_E_SPRG8		(1 << 3)
94*c3617f72SDavid Howells #define KVM_SREGS_E_MCIVPR		(1 << 4)
95*c3617f72SDavid Howells 
96*c3617f72SDavid Howells /*
97*c3617f72SDavid Howells  * IVORs are used -- contains IVOR0-15, plus additional IVORs
98*c3617f72SDavid Howells  * in combination with an appropriate feature bit.
99*c3617f72SDavid Howells  */
100*c3617f72SDavid Howells #define KVM_SREGS_E_IVOR		(1 << 5)
101*c3617f72SDavid Howells 
102*c3617f72SDavid Howells /*
103*c3617f72SDavid Howells  * Contains MAS0-4, MAS6-7, TLBnCFG, MMUCFG.
104*c3617f72SDavid Howells  * Also TLBnPS if MMUCFG[MAVN] = 1.
105*c3617f72SDavid Howells  */
106*c3617f72SDavid Howells #define KVM_SREGS_E_ARCH206_MMU		(1 << 6)
107*c3617f72SDavid Howells 
108*c3617f72SDavid Howells /* DBSR, DBCR, IAC, DAC, DVC */
109*c3617f72SDavid Howells #define KVM_SREGS_E_DEBUG		(1 << 7)
110*c3617f72SDavid Howells 
111*c3617f72SDavid Howells /* Enhanced debug -- DSRR0/1, SPRG9 */
112*c3617f72SDavid Howells #define KVM_SREGS_E_ED			(1 << 8)
113*c3617f72SDavid Howells 
114*c3617f72SDavid Howells /* Embedded Floating Point (SPE) -- IVOR32-34 if KVM_SREGS_E_IVOR */
115*c3617f72SDavid Howells #define KVM_SREGS_E_SPE			(1 << 9)
116*c3617f72SDavid Howells 
117*c3617f72SDavid Howells /* External Proxy (EXP) -- EPR */
118*c3617f72SDavid Howells #define KVM_SREGS_EXP			(1 << 10)
119*c3617f72SDavid Howells 
120*c3617f72SDavid Howells /* External PID (E.PD) -- EPSC/EPLC */
121*c3617f72SDavid Howells #define KVM_SREGS_E_PD			(1 << 11)
122*c3617f72SDavid Howells 
123*c3617f72SDavid Howells /* Processor Control (E.PC) -- IVOR36-37 if KVM_SREGS_E_IVOR */
124*c3617f72SDavid Howells #define KVM_SREGS_E_PC			(1 << 12)
125*c3617f72SDavid Howells 
126*c3617f72SDavid Howells /* Page table (E.PT) -- EPTCFG */
127*c3617f72SDavid Howells #define KVM_SREGS_E_PT			(1 << 13)
128*c3617f72SDavid Howells 
129*c3617f72SDavid Howells /* Embedded Performance Monitor (E.PM) -- IVOR35 if KVM_SREGS_E_IVOR */
130*c3617f72SDavid Howells #define KVM_SREGS_E_PM			(1 << 14)
131*c3617f72SDavid Howells 
132*c3617f72SDavid Howells /*
133*c3617f72SDavid Howells  * Special updates:
134*c3617f72SDavid Howells  *
135*c3617f72SDavid Howells  * Some registers may change even while a vcpu is not running.
136*c3617f72SDavid Howells  * To avoid losing these changes, by default these registers are
137*c3617f72SDavid Howells  * not updated by KVM_SET_SREGS.  To force an update, set the bit
138*c3617f72SDavid Howells  * in u.e.update_special corresponding to the register to be updated.
139*c3617f72SDavid Howells  *
140*c3617f72SDavid Howells  * The update_special field is zero on return from KVM_GET_SREGS.
141*c3617f72SDavid Howells  *
142*c3617f72SDavid Howells  * When restoring a checkpoint, the caller can set update_special
143*c3617f72SDavid Howells  * to 0xffffffff to ensure that everything is restored, even new features
144*c3617f72SDavid Howells  * that the caller doesn't know about.
145*c3617f72SDavid Howells  */
146*c3617f72SDavid Howells #define KVM_SREGS_E_UPDATE_MCSR		(1 << 0)
147*c3617f72SDavid Howells #define KVM_SREGS_E_UPDATE_TSR		(1 << 1)
148*c3617f72SDavid Howells #define KVM_SREGS_E_UPDATE_DEC		(1 << 2)
149*c3617f72SDavid Howells #define KVM_SREGS_E_UPDATE_DBSR		(1 << 3)
150*c3617f72SDavid Howells 
151*c3617f72SDavid Howells /*
152*c3617f72SDavid Howells  * In KVM_SET_SREGS, reserved/pad fields must be left untouched from a
153*c3617f72SDavid Howells  * previous KVM_GET_REGS.
154*c3617f72SDavid Howells  *
155*c3617f72SDavid Howells  * Unless otherwise indicated, setting any register with KVM_SET_SREGS
156*c3617f72SDavid Howells  * directly sets its value.  It does not trigger any special semantics such
157*c3617f72SDavid Howells  * as write-one-to-clear.  Calling KVM_SET_SREGS on an unmodified struct
158*c3617f72SDavid Howells  * just received from KVM_GET_SREGS is always a no-op.
159*c3617f72SDavid Howells  */
160*c3617f72SDavid Howells struct kvm_sregs {
161*c3617f72SDavid Howells 	__u32 pvr;
162*c3617f72SDavid Howells 	union {
163*c3617f72SDavid Howells 		struct {
164*c3617f72SDavid Howells 			__u64 sdr1;
165*c3617f72SDavid Howells 			struct {
166*c3617f72SDavid Howells 				struct {
167*c3617f72SDavid Howells 					__u64 slbe;
168*c3617f72SDavid Howells 					__u64 slbv;
169*c3617f72SDavid Howells 				} slb[64];
170*c3617f72SDavid Howells 			} ppc64;
171*c3617f72SDavid Howells 			struct {
172*c3617f72SDavid Howells 				__u32 sr[16];
173*c3617f72SDavid Howells 				__u64 ibat[8];
174*c3617f72SDavid Howells 				__u64 dbat[8];
175*c3617f72SDavid Howells 			} ppc32;
176*c3617f72SDavid Howells 		} s;
177*c3617f72SDavid Howells 		struct {
178*c3617f72SDavid Howells 			union {
179*c3617f72SDavid Howells 				struct { /* KVM_SREGS_E_IMPL_FSL */
180*c3617f72SDavid Howells 					__u32 features; /* KVM_SREGS_E_FSL_ */
181*c3617f72SDavid Howells 					__u32 svr;
182*c3617f72SDavid Howells 					__u64 mcar;
183*c3617f72SDavid Howells 					__u32 hid0;
184*c3617f72SDavid Howells 
185*c3617f72SDavid Howells 					/* KVM_SREGS_E_FSL_PIDn */
186*c3617f72SDavid Howells 					__u32 pid1, pid2;
187*c3617f72SDavid Howells 				} fsl;
188*c3617f72SDavid Howells 				__u8 pad[256];
189*c3617f72SDavid Howells 			} impl;
190*c3617f72SDavid Howells 
191*c3617f72SDavid Howells 			__u32 features; /* KVM_SREGS_E_ */
192*c3617f72SDavid Howells 			__u32 impl_id;	/* KVM_SREGS_E_IMPL_ */
193*c3617f72SDavid Howells 			__u32 update_special; /* KVM_SREGS_E_UPDATE_ */
194*c3617f72SDavid Howells 			__u32 pir;	/* read-only */
195*c3617f72SDavid Howells 			__u64 sprg8;
196*c3617f72SDavid Howells 			__u64 sprg9;	/* E.ED */
197*c3617f72SDavid Howells 			__u64 csrr0;
198*c3617f72SDavid Howells 			__u64 dsrr0;	/* E.ED */
199*c3617f72SDavid Howells 			__u64 mcsrr0;
200*c3617f72SDavid Howells 			__u32 csrr1;
201*c3617f72SDavid Howells 			__u32 dsrr1;	/* E.ED */
202*c3617f72SDavid Howells 			__u32 mcsrr1;
203*c3617f72SDavid Howells 			__u32 esr;
204*c3617f72SDavid Howells 			__u64 dear;
205*c3617f72SDavid Howells 			__u64 ivpr;
206*c3617f72SDavid Howells 			__u64 mcivpr;
207*c3617f72SDavid Howells 			__u64 mcsr;	/* KVM_SREGS_E_UPDATE_MCSR */
208*c3617f72SDavid Howells 
209*c3617f72SDavid Howells 			__u32 tsr;	/* KVM_SREGS_E_UPDATE_TSR */
210*c3617f72SDavid Howells 			__u32 tcr;
211*c3617f72SDavid Howells 			__u32 decar;
212*c3617f72SDavid Howells 			__u32 dec;	/* KVM_SREGS_E_UPDATE_DEC */
213*c3617f72SDavid Howells 
214*c3617f72SDavid Howells 			/*
215*c3617f72SDavid Howells 			 * Userspace can read TB directly, but the
216*c3617f72SDavid Howells 			 * value reported here is consistent with "dec".
217*c3617f72SDavid Howells 			 *
218*c3617f72SDavid Howells 			 * Read-only.
219*c3617f72SDavid Howells 			 */
220*c3617f72SDavid Howells 			__u64 tb;
221*c3617f72SDavid Howells 
222*c3617f72SDavid Howells 			__u32 dbsr;	/* KVM_SREGS_E_UPDATE_DBSR */
223*c3617f72SDavid Howells 			__u32 dbcr[3];
224*c3617f72SDavid Howells 			__u32 iac[4];
225*c3617f72SDavid Howells 			__u32 dac[2];
226*c3617f72SDavid Howells 			__u32 dvc[2];
227*c3617f72SDavid Howells 			__u8 num_iac;	/* read-only */
228*c3617f72SDavid Howells 			__u8 num_dac;	/* read-only */
229*c3617f72SDavid Howells 			__u8 num_dvc;	/* read-only */
230*c3617f72SDavid Howells 			__u8 pad;
231*c3617f72SDavid Howells 
232*c3617f72SDavid Howells 			__u32 epr;	/* EXP */
233*c3617f72SDavid Howells 			__u32 vrsave;	/* a.k.a. USPRG0 */
234*c3617f72SDavid Howells 			__u32 epcr;	/* KVM_SREGS_E_64 */
235*c3617f72SDavid Howells 
236*c3617f72SDavid Howells 			__u32 mas0;
237*c3617f72SDavid Howells 			__u32 mas1;
238*c3617f72SDavid Howells 			__u64 mas2;
239*c3617f72SDavid Howells 			__u64 mas7_3;
240*c3617f72SDavid Howells 			__u32 mas4;
241*c3617f72SDavid Howells 			__u32 mas6;
242*c3617f72SDavid Howells 
243*c3617f72SDavid Howells 			__u32 ivor_low[16]; /* IVOR0-15 */
244*c3617f72SDavid Howells 			__u32 ivor_high[18]; /* IVOR32+, plus room to expand */
245*c3617f72SDavid Howells 
246*c3617f72SDavid Howells 			__u32 mmucfg;	/* read-only */
247*c3617f72SDavid Howells 			__u32 eptcfg;	/* E.PT, read-only */
248*c3617f72SDavid Howells 			__u32 tlbcfg[4];/* read-only */
249*c3617f72SDavid Howells 			__u32 tlbps[4]; /* read-only */
250*c3617f72SDavid Howells 
251*c3617f72SDavid Howells 			__u32 eplc, epsc; /* E.PD */
252*c3617f72SDavid Howells 		} e;
253*c3617f72SDavid Howells 		__u8 pad[1020];
254*c3617f72SDavid Howells 	} u;
255*c3617f72SDavid Howells };
256*c3617f72SDavid Howells 
257*c3617f72SDavid Howells struct kvm_fpu {
258*c3617f72SDavid Howells 	__u64 fpr[32];
259*c3617f72SDavid Howells };
260*c3617f72SDavid Howells 
261*c3617f72SDavid Howells struct kvm_debug_exit_arch {
262*c3617f72SDavid Howells };
263*c3617f72SDavid Howells 
264*c3617f72SDavid Howells /* for KVM_SET_GUEST_DEBUG */
265*c3617f72SDavid Howells struct kvm_guest_debug_arch {
266*c3617f72SDavid Howells };
267*c3617f72SDavid Howells 
268*c3617f72SDavid Howells /* definition of registers in kvm_run */
269*c3617f72SDavid Howells struct kvm_sync_regs {
270*c3617f72SDavid Howells };
271*c3617f72SDavid Howells 
272*c3617f72SDavid Howells #define KVM_INTERRUPT_SET	-1U
273*c3617f72SDavid Howells #define KVM_INTERRUPT_UNSET	-2U
274*c3617f72SDavid Howells #define KVM_INTERRUPT_SET_LEVEL	-3U
275*c3617f72SDavid Howells 
276*c3617f72SDavid Howells #define KVM_CPU_440		1
277*c3617f72SDavid Howells #define KVM_CPU_E500V2		2
278*c3617f72SDavid Howells #define KVM_CPU_3S_32		3
279*c3617f72SDavid Howells #define KVM_CPU_3S_64		4
280*c3617f72SDavid Howells #define KVM_CPU_E500MC		5
281*c3617f72SDavid Howells 
282*c3617f72SDavid Howells /* for KVM_CAP_SPAPR_TCE */
283*c3617f72SDavid Howells struct kvm_create_spapr_tce {
284*c3617f72SDavid Howells 	__u64 liobn;
285*c3617f72SDavid Howells 	__u32 window_size;
286*c3617f72SDavid Howells };
287*c3617f72SDavid Howells 
288*c3617f72SDavid Howells /* for KVM_ALLOCATE_RMA */
289*c3617f72SDavid Howells struct kvm_allocate_rma {
290*c3617f72SDavid Howells 	__u64 rma_size;
291*c3617f72SDavid Howells };
292*c3617f72SDavid Howells 
293*c3617f72SDavid Howells struct kvm_book3e_206_tlb_entry {
294*c3617f72SDavid Howells 	__u32 mas8;
295*c3617f72SDavid Howells 	__u32 mas1;
296*c3617f72SDavid Howells 	__u64 mas2;
297*c3617f72SDavid Howells 	__u64 mas7_3;
298*c3617f72SDavid Howells };
299*c3617f72SDavid Howells 
300*c3617f72SDavid Howells struct kvm_book3e_206_tlb_params {
301*c3617f72SDavid Howells 	/*
302*c3617f72SDavid Howells 	 * For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
303*c3617f72SDavid Howells 	 *
304*c3617f72SDavid Howells 	 * - The number of ways of TLB0 must be a power of two between 2 and
305*c3617f72SDavid Howells 	 *   16.
306*c3617f72SDavid Howells 	 * - TLB1 must be fully associative.
307*c3617f72SDavid Howells 	 * - The size of TLB0 must be a multiple of the number of ways, and
308*c3617f72SDavid Howells 	 *   the number of sets must be a power of two.
309*c3617f72SDavid Howells 	 * - The size of TLB1 may not exceed 64 entries.
310*c3617f72SDavid Howells 	 * - TLB0 supports 4 KiB pages.
311*c3617f72SDavid Howells 	 * - The page sizes supported by TLB1 are as indicated by
312*c3617f72SDavid Howells 	 *   TLB1CFG (if MMUCFG[MAVN] = 0) or TLB1PS (if MMUCFG[MAVN] = 1)
313*c3617f72SDavid Howells 	 *   as returned by KVM_GET_SREGS.
314*c3617f72SDavid Howells 	 * - TLB2 and TLB3 are reserved, and their entries in tlb_sizes[]
315*c3617f72SDavid Howells 	 *   and tlb_ways[] must be zero.
316*c3617f72SDavid Howells 	 *
317*c3617f72SDavid Howells 	 * tlb_ways[n] = tlb_sizes[n] means the array is fully associative.
318*c3617f72SDavid Howells 	 *
319*c3617f72SDavid Howells 	 * KVM will adjust TLBnCFG based on the sizes configured here,
320*c3617f72SDavid Howells 	 * though arrays greater than 2048 entries will have TLBnCFG[NENTRY]
321*c3617f72SDavid Howells 	 * set to zero.
322*c3617f72SDavid Howells 	 */
323*c3617f72SDavid Howells 	__u32 tlb_sizes[4];
324*c3617f72SDavid Howells 	__u32 tlb_ways[4];
325*c3617f72SDavid Howells 	__u32 reserved[8];
326*c3617f72SDavid Howells };
327*c3617f72SDavid Howells 
328*c3617f72SDavid Howells #define KVM_REG_PPC_HIOR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1)
329*c3617f72SDavid Howells 
330*c3617f72SDavid Howells #endif /* __LINUX_KVM_POWERPC_H */
331