master
h 483 lines 11 KB
Raw
1 /*
2 * Copyright 2008 IBM Corporation.
3 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
4 *
5 * This work is licensed under the GNU GPL license version 2 or later.
6 *
7 */
8
9 #ifndef KVM_PPC_H
10 #define KVM_PPC_H
11
12 #include "system/kvm.h"
13 #include "exec/hwaddr.h"
14 #include "cpu.h"
15
16 #ifdef CONFIG_USER_ONLY
17 #error Cannot include kvm_ppc.h from user emulation
18 #endif
19
20 #ifdef CONFIG_KVM
21
22 uint32_t kvmppc_get_tbfreq(void);
23 uint64_t kvmppc_get_clockfreq(void);
24 int kvmppc_get_hasidle(CPUPPCState *env);
25 int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
26 int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
27 void kvmppc_enable_logical_ci_hcalls(void);
28 void kvmppc_enable_set_mode_hcall(void);
29 void kvmppc_enable_clear_ref_mod_hcalls(void);
30 void kvmppc_enable_h_page_init(void);
31 void kvmppc_enable_h_rpt_invalidate(void);
32 void kvmppc_set_papr(PowerPCCPU *cpu);
33 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
34 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
35 bool kvmppc_get_fwnmi(void);
36 int kvmppc_set_fwnmi(PowerPCCPU *cpu);
37 int kvmppc_smt_threads(void);
38 void kvmppc_error_append_smt_possible_hint(Error *const *errp);
39 int kvmppc_set_smt_threads(int smt);
40 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
41 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
42 int kvmppc_set_tcr(PowerPCCPU *cpu);
43 int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
44 target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
45 bool radix, bool gtse,
46 uint64_t proc_tbl);
47 bool kvmppc_spapr_use_multitce(void);
48 int kvmppc_spapr_enable_inkernel_multitce(void);
49 void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
50 uint64_t bus_offset, uint32_t nb_table,
51 int *pfd, bool need_vfio);
52 int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
53 int kvmppc_reset_htab(int shift_hint);
54 uint64_t kvmppc_vrma_limit(unsigned int hash_shift);
55 bool kvmppc_has_cap_spapr_vfio(void);
56 bool kvmppc_has_cap_epr(void);
57 int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
58 int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp);
59 int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
60 int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
61 uint16_t n_valid, uint16_t n_invalid, Error **errp);
62 void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n);
63 void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1);
64 bool kvmppc_has_cap_fixup_hcalls(void);
65 bool kvmppc_has_cap_htm(void);
66 bool kvmppc_has_cap_mmu_radix(void);
67 bool kvmppc_has_cap_mmu_hash_v3(void);
68 bool kvmppc_has_cap_xive(void);
69 bool kvmppc_has_cap_dawr1(void);
70 int kvmppc_set_cap_dawr1(int enable);
71 int kvmppc_get_cap_safe_cache(void);
72 int kvmppc_get_cap_safe_bounds_check(void);
73 int kvmppc_get_cap_safe_indirect_branch(void);
74 int kvmppc_get_cap_count_cache_flush_assist(void);
75 bool kvmppc_has_cap_nested_kvm_hv(void);
76 int kvmppc_set_cap_nested_kvm_hv(int enable);
77 int kvmppc_get_cap_large_decr(void);
78 int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable);
79 int kvmppc_has_cap_rpt_invalidate(void);
80 bool kvmppc_supports_ail_3(void);
81 int kvmppc_enable_hwrng(void);
82 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
83 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
84
85 uint32_t kvm_ppc_host_compat_pvr(void);
86 void kvmppc_check_papr_resize_hpt(Error **errp);
87 int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shift);
88 int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shift);
89 bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu);
90
91 bool kvmppc_hpt_needs_host_contiguous_pages(void);
92 void kvm_check_mmu(PowerPCCPU *cpu, Error **errp);
93 void kvmppc_set_reg_ppc_online(PowerPCCPU *cpu, unsigned int online);
94 void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu, int64_t tb_offset);
95
96 int kvm_handle_nmi(PowerPCCPU *cpu, struct kvm_run *run);
97
98 #define kvmppc_eieio() \
99 do { \
100 if (kvm_enabled()) { \
101 asm volatile("eieio" : : : "memory"); \
102 } \
103 } while (0)
104
105 /* Store data cache blocks back to memory */
106 static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
107 {
108 uint8_t *p;
109
110 for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
111 asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
112 }
113 }
114
115 /* Invalidate instruction cache blocks */
116 static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
117 {
118 uint8_t *p;
119
120 for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
121 asm volatile("icbi 0,%0" : : "r"(p));
122 }
123 }
124
125 #else /* !CONFIG_KVM */
126
127 static inline uint32_t kvmppc_get_tbfreq(void)
128 {
129 return 0;
130 }
131
132 static inline uint64_t kvmppc_get_clockfreq(void)
133 {
134 return 0;
135 }
136
137 static inline uint32_t kvmppc_get_vmx(void)
138 {
139 return 0;
140 }
141
142 static inline uint32_t kvmppc_get_dfp(void)
143 {
144 return 0;
145 }
146
147 static inline int kvmppc_get_hasidle(CPUPPCState *env)
148 {
149 return 0;
150 }
151
152 static inline int kvmppc_get_hypercall(CPUPPCState *env,
153 uint8_t *buf, int buf_len)
154 {
155 return -1;
156 }
157
158 static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
159 {
160 return -1;
161 }
162
163 static inline void kvmppc_enable_logical_ci_hcalls(void)
164 {
165 }
166
167 static inline void kvmppc_enable_set_mode_hcall(void)
168 {
169 }
170
171 static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
172 {
173 }
174
175 static inline void kvmppc_enable_h_page_init(void)
176 {
177 }
178
179 static inline void kvmppc_enable_h_rpt_invalidate(void)
180 {
181 g_assert_not_reached();
182 }
183
184 static inline void kvmppc_set_papr(PowerPCCPU *cpu)
185 {
186 }
187
188 static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr)
189 {
190 return 0;
191 }
192
193 static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
194 {
195 }
196
197 static inline bool kvmppc_get_fwnmi(void)
198 {
199 return false;
200 }
201
202 static inline int kvmppc_set_fwnmi(PowerPCCPU *cpu)
203 {
204 return -1;
205 }
206
207 static inline int kvmppc_smt_threads(void)
208 {
209 return 1;
210 }
211
212 static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp)
213 {
214 }
215
216 static inline int kvmppc_set_smt_threads(int smt)
217 {
218 return 0;
219 }
220
221 static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
222 {
223 return 0;
224 }
225
226 static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
227 {
228 return 0;
229 }
230
231 static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
232 {
233 return 0;
234 }
235
236 static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
237 {
238 return -1;
239 }
240
241 static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
242 bool radix, bool gtse,
243 uint64_t proc_tbl)
244 {
245 return 0;
246 }
247
248 static inline void kvmppc_set_reg_ppc_online(PowerPCCPU *cpu,
249 unsigned int online)
250 {
251 }
252
253 static inline void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu, int64_t tb_offset)
254 {
255 }
256
257 static inline bool kvmppc_spapr_use_multitce(void)
258 {
259 return false;
260 }
261
262 static inline int kvmppc_spapr_enable_inkernel_multitce(void)
263 {
264 return -1;
265 }
266
267 static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
268 uint64_t bus_offset,
269 uint32_t nb_table,
270 int *pfd, bool need_vfio)
271 {
272 return NULL;
273 }
274
275 static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
276 uint32_t nb_table)
277 {
278 return -1;
279 }
280
281 static inline int kvmppc_reset_htab(int shift_hint)
282 {
283 return 0;
284 }
285
286 static inline uint64_t kvmppc_vrma_limit(unsigned int hash_shift)
287 {
288 g_assert_not_reached();
289 }
290
291 static inline bool kvmppc_hpt_needs_host_contiguous_pages(void)
292 {
293 return false;
294 }
295
296 static inline void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
297 {
298 }
299
300 static inline bool kvmppc_has_cap_spapr_vfio(void)
301 {
302 return false;
303 }
304
305 static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes,
306 hwaddr ptex, int n)
307 {
308 abort();
309 }
310
311 static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1)
312 {
313 abort();
314 }
315
316 static inline bool kvmppc_has_cap_epr(void)
317 {
318 return false;
319 }
320
321 static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
322 const char *function)
323 {
324 return -1;
325 }
326
327 static inline int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp)
328 {
329 return -1;
330 }
331
332 static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
333 int64_t max_ns)
334 {
335 abort();
336 }
337
338 static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
339 uint16_t n_valid, uint16_t n_invalid,
340 Error **errp)
341 {
342 abort();
343 }
344
345 static inline bool kvmppc_has_cap_fixup_hcalls(void)
346 {
347 abort();
348 }
349
350 static inline bool kvmppc_has_cap_htm(void)
351 {
352 return false;
353 }
354
355 static inline bool kvmppc_has_cap_mmu_radix(void)
356 {
357 return false;
358 }
359
360 static inline bool kvmppc_has_cap_mmu_hash_v3(void)
361 {
362 return false;
363 }
364
365 static inline bool kvmppc_has_cap_xive(void)
366 {
367 return false;
368 }
369
370 static inline bool kvmppc_has_cap_dawr1(void)
371 {
372 return false;
373 }
374
375 static inline int kvmppc_set_cap_dawr1(int enable)
376 {
377 abort();
378 }
379
380 static inline int kvmppc_get_cap_safe_cache(void)
381 {
382 return 0;
383 }
384
385 static inline int kvmppc_get_cap_safe_bounds_check(void)
386 {
387 return 0;
388 }
389
390 static inline int kvmppc_get_cap_safe_indirect_branch(void)
391 {
392 return 0;
393 }
394
395 static inline int kvmppc_get_cap_count_cache_flush_assist(void)
396 {
397 return 0;
398 }
399
400 static inline bool kvmppc_has_cap_nested_kvm_hv(void)
401 {
402 return false;
403 }
404
405 static inline int kvmppc_set_cap_nested_kvm_hv(int enable)
406 {
407 return -1;
408 }
409
410 static inline int kvmppc_get_cap_large_decr(void)
411 {
412 return 0;
413 }
414
415 static inline int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable)
416 {
417 return -1;
418 }
419
420 static inline int kvmppc_has_cap_rpt_invalidate(void)
421 {
422 return false;
423 }
424
425 static inline bool kvmppc_supports_ail_3(void)
426 {
427 return false;
428 }
429
430 static inline int kvmppc_enable_hwrng(void)
431 {
432 return -1;
433 }
434
435 static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
436 {
437 abort();
438 }
439
440 static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
441 {
442 return NULL;
443 }
444
445 static inline uint32_t kvm_ppc_host_compat_pvr(void)
446 {
447 return 0;
448 }
449
450 static inline void kvmppc_check_papr_resize_hpt(Error **errp)
451 {
452 }
453
454 static inline int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu,
455 target_ulong flags, int shift)
456 {
457 return -ENOSYS;
458 }
459
460 static inline int kvmppc_resize_hpt_commit(PowerPCCPU *cpu,
461 target_ulong flags, int shift)
462 {
463 return -ENOSYS;
464 }
465
466 static inline bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu)
467 {
468 return false;
469 }
470
471 #define kvmppc_eieio() do { } while (0)
472
473 static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
474 {
475 }
476
477 static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
478 {
479 }
480
481 #endif /* CONFIG_KVM */
482
483 #endif /* KVM_PPC_H */