1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2, as
4  * published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14  *
15  * Copyright SUSE Linux Products GmbH 2009
16  *
17  * Authors: Alexander Graf <agraf@suse.de>
18  */
19 
20 #ifndef __ASM_KVM_BOOK3S_ASM_H__
21 #define __ASM_KVM_BOOK3S_ASM_H__
22 
23 /* XICS ICP register offsets */
24 #define XICS_XIRR		4
25 #define XICS_MFRR		0xc
26 #define XICS_IPI		2	/* interrupt source # for IPIs */
27 
28 /* LPIDs we support with this build -- runtime limit may be lower */
29 #define KVMPPC_NR_LPIDS			(LPID_RSVD + 1)
30 
31 /* Maximum number of threads per physical core */
32 #define MAX_SMT_THREADS		8
33 
34 /* Maximum number of subcores per physical core */
35 #define MAX_SUBCORES		4
36 
37 #ifdef __ASSEMBLY__
38 
39 #ifdef CONFIG_KVM_BOOK3S_HANDLER
40 
41 #include <asm/kvm_asm.h>
42 
43 .macro DO_KVM intno
44 	.if (\intno == BOOK3S_INTERRUPT_SYSTEM_RESET) || \
45 	    (\intno == BOOK3S_INTERRUPT_MACHINE_CHECK) || \
46 	    (\intno == BOOK3S_INTERRUPT_DATA_STORAGE) || \
47 	    (\intno == BOOK3S_INTERRUPT_INST_STORAGE) || \
48 	    (\intno == BOOK3S_INTERRUPT_DATA_SEGMENT) || \
49 	    (\intno == BOOK3S_INTERRUPT_INST_SEGMENT) || \
50 	    (\intno == BOOK3S_INTERRUPT_EXTERNAL) || \
51 	    (\intno == BOOK3S_INTERRUPT_EXTERNAL_HV) || \
52 	    (\intno == BOOK3S_INTERRUPT_ALIGNMENT) || \
53 	    (\intno == BOOK3S_INTERRUPT_PROGRAM) || \
54 	    (\intno == BOOK3S_INTERRUPT_FP_UNAVAIL) || \
55 	    (\intno == BOOK3S_INTERRUPT_DECREMENTER) || \
56 	    (\intno == BOOK3S_INTERRUPT_SYSCALL) || \
57 	    (\intno == BOOK3S_INTERRUPT_TRACE) || \
58 	    (\intno == BOOK3S_INTERRUPT_PERFMON) || \
59 	    (\intno == BOOK3S_INTERRUPT_ALTIVEC) || \
60 	    (\intno == BOOK3S_INTERRUPT_VSX)
61 
62 	b	kvmppc_trampoline_\intno
63 kvmppc_resume_\intno:
64 
65 	.endif
66 .endm
67 
68 #else
69 
70 .macro DO_KVM intno
71 .endm
72 
73 #endif /* CONFIG_KVM_BOOK3S_HANDLER */
74 
75 #else  /*__ASSEMBLY__ */
76 
77 struct kvmppc_vcore;
78 
79 /* Struct used for coordinating micro-threading (split-core) mode changes */
80 struct kvm_split_mode {
81 	unsigned long	rpr;
82 	unsigned long	pmmar;
83 	unsigned long	ldbar;
84 	u8		subcore_size;
85 	u8		do_nap;
86 	u8		napped[MAX_SMT_THREADS];
87 	struct kvmppc_vcore *vc[MAX_SUBCORES];
88 	/* Bits for changing lpcr on P9 */
89 	unsigned long	lpcr_req;
90 	unsigned long	lpidr_req;
91 	unsigned long	host_lpcr;
92 	u32		do_set;
93 	u32		do_restore;
94 	union {
95 		u32	allphases;
96 		u8	phase[4];
97 	} lpcr_sync;
98 };
99 
100 /*
101  * This struct goes in the PACA on 64-bit processors.  It is used
102  * to store host state that needs to be saved when we enter a guest
103  * and restored when we exit, but isn't specific to any particular
104  * guest or vcpu.  It also has some scratch fields used by the guest
105  * exit code.
106  */
107 struct kvmppc_host_state {
108 	ulong host_r1;
109 	ulong host_r2;
110 	ulong host_msr;
111 	ulong vmhandler;
112 	ulong scratch0;
113 	ulong scratch1;
114 	ulong scratch2;
115 	u8 in_guest;
116 	u8 restore_hid5;
117 	u8 napping;
118 
119 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
120 	u8 hwthread_req;
121 	u8 hwthread_state;
122 	u8 host_ipi;
123 	u8 ptid;		/* thread number within subcore when split */
124 	u8 tid;			/* thread number within whole core */
125 	u8 fake_suspend;
126 	struct kvm_vcpu *kvm_vcpu;
127 	struct kvmppc_vcore *kvm_vcore;
128 	void __iomem *xics_phys;
129 	void __iomem *xive_tima_phys;
130 	void __iomem *xive_tima_virt;
131 	u32 saved_xirr;
132 	u64 dabr;
133 	u64 host_mmcr[7];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */
134 	u32 host_pmc[8];
135 	u64 host_purr;
136 	u64 host_spurr;
137 	u64 host_dscr;
138 	u64 dec_expires;
139 	struct kvm_split_mode *kvm_split_mode;
140 #endif
141 #ifdef CONFIG_PPC_BOOK3S_64
142 	u64 cfar;
143 	u64 ppr;
144 	u64 host_fscr;
145 #endif
146 };
147 
148 struct kvmppc_book3s_shadow_vcpu {
149 	bool in_use;
150 	ulong gpr[14];
151 	u32 cr;
152 	ulong xer;
153 	ulong ctr;
154 	ulong lr;
155 	ulong pc;
156 
157 	ulong shadow_srr1;
158 	ulong fault_dar;
159 	u32 fault_dsisr;
160 	u32 last_inst;
161 
162 #ifdef CONFIG_PPC_BOOK3S_32
163 	u32     sr[16];			/* Guest SRs */
164 
165 	struct kvmppc_host_state hstate;
166 #endif
167 
168 #ifdef CONFIG_PPC_BOOK3S_64
169 	u8 slb_max;			/* highest used guest slb entry */
170 	struct  {
171 		u64     esid;
172 		u64     vsid;
173 	} slb[64];			/* guest SLB */
174 	u64 shadow_fscr;
175 #endif
176 };
177 
178 #endif /*__ASSEMBLY__ */
179 
180 /* Values for kvm_state */
181 #define KVM_HWTHREAD_IN_KERNEL	0
182 #define KVM_HWTHREAD_IN_IDLE	1
183 #define KVM_HWTHREAD_IN_KVM	2
184 
185 #endif /* __ASM_KVM_BOOK3S_ASM_H__ */
186