]> Pileus Git - ~andy/linux/blob - arch/powerpc/include/asm/kvm_host.h
KVM: PPC: Convert SRR0 and SRR1 to shared page
[~andy/linux] / arch / powerpc / include / asm / kvm_host.h
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 IBM Corp. 2007
16  *
17  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18  */
19
20 #ifndef __POWERPC_KVM_HOST_H__
21 #define __POWERPC_KVM_HOST_H__
22
23 #include <linux/mutex.h>
24 #include <linux/hrtimer.h>
25 #include <linux/interrupt.h>
26 #include <linux/types.h>
27 #include <linux/kvm_types.h>
28 #include <linux/kvm_para.h>
29 #include <asm/kvm_asm.h>
30
31 #define KVM_MAX_VCPUS 1
32 #define KVM_MEMORY_SLOTS 32
33 /* memory slots that does not exposed to userspace */
34 #define KVM_PRIVATE_MEM_SLOTS 4
35
36 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
37
38 /* We don't currently support large pages. */
39 #define KVM_HPAGE_GFN_SHIFT(x)  0
40 #define KVM_NR_PAGE_SIZES       1
41 #define KVM_PAGES_PER_HPAGE(x)  (1UL<<31)
42
43 #define HPTEG_CACHE_NUM                 (1 << 15)
44 #define HPTEG_HASH_BITS_PTE             13
45 #define HPTEG_HASH_BITS_VPTE            13
46 #define HPTEG_HASH_BITS_VPTE_LONG       5
47 #define HPTEG_HASH_NUM_PTE              (1 << HPTEG_HASH_BITS_PTE)
48 #define HPTEG_HASH_NUM_VPTE             (1 << HPTEG_HASH_BITS_VPTE)
49 #define HPTEG_HASH_NUM_VPTE_LONG        (1 << HPTEG_HASH_BITS_VPTE_LONG)
50
51 struct kvm;
52 struct kvm_run;
53 struct kvm_vcpu;
54
55 struct kvm_vm_stat {
56         u32 remote_tlb_flush;
57 };
58
59 struct kvm_vcpu_stat {
60         u32 sum_exits;
61         u32 mmio_exits;
62         u32 dcr_exits;
63         u32 signal_exits;
64         u32 light_exits;
65         /* Account for special types of light exits: */
66         u32 itlb_real_miss_exits;
67         u32 itlb_virt_miss_exits;
68         u32 dtlb_real_miss_exits;
69         u32 dtlb_virt_miss_exits;
70         u32 syscall_exits;
71         u32 isi_exits;
72         u32 dsi_exits;
73         u32 emulated_inst_exits;
74         u32 dec_exits;
75         u32 ext_intr_exits;
76         u32 halt_wakeup;
77 #ifdef CONFIG_PPC_BOOK3S
78         u32 pf_storage;
79         u32 pf_instruc;
80         u32 sp_storage;
81         u32 sp_instruc;
82         u32 queue_intr;
83         u32 ld;
84         u32 ld_slow;
85         u32 st;
86         u32 st_slow;
87 #endif
88 };
89
90 enum kvm_exit_types {
91         MMIO_EXITS,
92         DCR_EXITS,
93         SIGNAL_EXITS,
94         ITLB_REAL_MISS_EXITS,
95         ITLB_VIRT_MISS_EXITS,
96         DTLB_REAL_MISS_EXITS,
97         DTLB_VIRT_MISS_EXITS,
98         SYSCALL_EXITS,
99         ISI_EXITS,
100         DSI_EXITS,
101         EMULATED_INST_EXITS,
102         EMULATED_MTMSRWE_EXITS,
103         EMULATED_WRTEE_EXITS,
104         EMULATED_MTSPR_EXITS,
105         EMULATED_MFSPR_EXITS,
106         EMULATED_MTMSR_EXITS,
107         EMULATED_MFMSR_EXITS,
108         EMULATED_TLBSX_EXITS,
109         EMULATED_TLBWE_EXITS,
110         EMULATED_RFI_EXITS,
111         DEC_EXITS,
112         EXT_INTR_EXITS,
113         HALT_WAKEUP,
114         USR_PR_INST,
115         FP_UNAVAIL,
116         DEBUG_EXITS,
117         TIMEINGUEST,
118         __NUMBER_OF_KVM_EXIT_TYPES
119 };
120
121 /* allow access to big endian 32bit upper/lower parts and 64bit var */
122 struct kvmppc_exit_timing {
123         union {
124                 u64 tv64;
125                 struct {
126                         u32 tbu, tbl;
127                 } tv32;
128         };
129 };
130
131 struct kvm_arch {
132 };
133
134 struct kvmppc_pte {
135         ulong eaddr;
136         u64 vpage;
137         ulong raddr;
138         bool may_read           : 1;
139         bool may_write          : 1;
140         bool may_execute        : 1;
141 };
142
143 struct kvmppc_mmu {
144         /* book3s_64 only */
145         void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
146         u64  (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
147         u64  (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
148         void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
149         void (*slbia)(struct kvm_vcpu *vcpu);
150         /* book3s */
151         void (*mtsrin)(struct kvm_vcpu *vcpu, u32 srnum, ulong value);
152         u32  (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
153         int  (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr, struct kvmppc_pte *pte, bool data);
154         void (*reset_msr)(struct kvm_vcpu *vcpu);
155         void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
156         int  (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
157         u64  (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
158         bool (*is_dcbz32)(struct kvm_vcpu *vcpu);
159 };
160
161 struct hpte_cache {
162         struct hlist_node list_pte;
163         struct hlist_node list_vpte;
164         struct hlist_node list_vpte_long;
165         u64 host_va;
166         u64 pfn;
167         ulong slot;
168         struct kvmppc_pte pte;
169 };
170
171 struct kvm_vcpu_arch {
172         ulong host_stack;
173         u32 host_pid;
174 #ifdef CONFIG_PPC_BOOK3S
175         ulong host_msr;
176         ulong host_r2;
177         void *host_retip;
178         ulong trampoline_lowmem;
179         ulong trampoline_enter;
180         ulong highmem_handler;
181         ulong rmcall;
182         ulong host_paca_phys;
183         struct kvmppc_mmu mmu;
184 #endif
185
186         ulong gpr[32];
187
188         u64 fpr[32];
189         u64 fpscr;
190
191 #ifdef CONFIG_ALTIVEC
192         vector128 vr[32];
193         vector128 vscr;
194 #endif
195
196 #ifdef CONFIG_VSX
197         u64 vsr[32];
198 #endif
199
200 #ifdef CONFIG_PPC_BOOK3S
201         /* For Gekko paired singles */
202         u32 qpr[32];
203 #endif
204
205 #ifdef CONFIG_BOOKE
206         ulong pc;
207         ulong ctr;
208         ulong lr;
209
210         ulong xer;
211         u32 cr;
212 #endif
213
214 #ifdef CONFIG_PPC_BOOK3S
215         ulong shadow_msr;
216         ulong hflags;
217         ulong guest_owned_ext;
218 #endif
219         u32 mmucr;
220         ulong sprg0;
221         ulong sprg1;
222         ulong sprg2;
223         ulong sprg3;
224         ulong sprg4;
225         ulong sprg5;
226         ulong sprg6;
227         ulong sprg7;
228         ulong csrr0;
229         ulong csrr1;
230         ulong dsrr0;
231         ulong dsrr1;
232         ulong esr;
233         u32 dec;
234         u32 decar;
235         u32 tbl;
236         u32 tbu;
237         u32 tcr;
238         u32 tsr;
239         u32 ivor[64];
240         ulong ivpr;
241         u32 pir;
242         u32 pvr;
243
244         u32 shadow_pid;
245         u32 pid;
246         u32 swap_pid;
247
248         u32 ccr0;
249         u32 ccr1;
250         u32 dbcr0;
251         u32 dbcr1;
252         u32 dbsr;
253
254 #ifdef CONFIG_KVM_EXIT_TIMING
255         struct kvmppc_exit_timing timing_exit;
256         struct kvmppc_exit_timing timing_last_enter;
257         u32 last_exit_type;
258         u32 timing_count_type[__NUMBER_OF_KVM_EXIT_TYPES];
259         u64 timing_sum_duration[__NUMBER_OF_KVM_EXIT_TYPES];
260         u64 timing_sum_quad_duration[__NUMBER_OF_KVM_EXIT_TYPES];
261         u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
262         u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
263         u64 timing_last_exit;
264         struct dentry *debugfs_exit_timing;
265 #endif
266
267 #ifdef CONFIG_BOOKE
268         u32 last_inst;
269         ulong fault_dear;
270         ulong fault_esr;
271         ulong queued_dear;
272         ulong queued_esr;
273 #endif
274         gpa_t paddr_accessed;
275
276         u8 io_gpr; /* GPR used as IO source/target */
277         u8 mmio_is_bigendian;
278         u8 mmio_sign_extend;
279         u8 dcr_needed;
280         u8 dcr_is_write;
281         u8 osi_needed;
282         u8 osi_enabled;
283
284         u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
285
286         struct hrtimer dec_timer;
287         struct tasklet_struct tasklet;
288         u64 dec_jiffies;
289         unsigned long pending_exceptions;
290         struct kvm_vcpu_arch_shared *shared;
291
292 #ifdef CONFIG_PPC_BOOK3S
293         struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE];
294         struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE];
295         struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG];
296         int hpte_cache_count;
297 #endif
298 };
299
300 #endif /* __POWERPC_KVM_HOST_H__ */