2 * Copyright 2008 IBM Corporation.
3 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
5 * This work is licensed under the GNU GPL license version 2 or later.
12 #include "sysemu/kvm.h"
13 #include "exec/hwaddr.h"
18 uint32_t kvmppc_get_tbfreq(void);
19 uint64_t kvmppc_get_clockfreq(void);
20 bool kvmppc_get_host_model(char **buf
);
21 bool kvmppc_get_host_serial(char **buf
);
22 int kvmppc_get_hasidle(CPUPPCState
*env
);
23 int kvmppc_get_hypercall(CPUPPCState
*env
, uint8_t *buf
, int buf_len
);
24 int kvmppc_set_interrupt(PowerPCCPU
*cpu
, int irq
, int level
);
25 void kvmppc_enable_logical_ci_hcalls(void);
26 void kvmppc_enable_set_mode_hcall(void);
27 void kvmppc_enable_clear_ref_mod_hcalls(void);
28 void kvmppc_enable_h_page_init(void);
29 void kvmppc_enable_h_rpt_invalidate(void);
30 void kvmppc_set_papr(PowerPCCPU
*cpu
);
31 int kvmppc_set_compat(PowerPCCPU
*cpu
, uint32_t compat_pvr
);
32 void kvmppc_set_mpic_proxy(PowerPCCPU
*cpu
, int mpic_proxy
);
33 bool kvmppc_get_fwnmi(void);
34 int kvmppc_set_fwnmi(PowerPCCPU
*cpu
);
35 int kvmppc_smt_threads(void);
36 void kvmppc_error_append_smt_possible_hint(Error
*const *errp
);
37 int kvmppc_set_smt_threads(int smt
);
38 int kvmppc_clear_tsr_bits(PowerPCCPU
*cpu
, uint32_t tsr_bits
);
39 int kvmppc_or_tsr_bits(PowerPCCPU
*cpu
, uint32_t tsr_bits
);
40 int kvmppc_set_tcr(PowerPCCPU
*cpu
);
41 int kvmppc_booke_watchdog_enable(PowerPCCPU
*cpu
);
42 target_ulong
kvmppc_configure_v3_mmu(PowerPCCPU
*cpu
,
43 bool radix
, bool gtse
,
45 bool kvmppc_spapr_use_multitce(void);
46 int kvmppc_spapr_enable_inkernel_multitce(void);
47 void *kvmppc_create_spapr_tce(uint32_t liobn
, uint32_t page_shift
,
48 uint64_t bus_offset
, uint32_t nb_table
,
49 int *pfd
, bool need_vfio
);
50 int kvmppc_remove_spapr_tce(void *table
, int pfd
, uint32_t window_size
);
51 int kvmppc_reset_htab(int shift_hint
);
52 uint64_t kvmppc_vrma_limit(unsigned int hash_shift
);
53 bool kvmppc_has_cap_spapr_vfio(void);
54 bool kvmppc_has_cap_epr(void);
55 int kvmppc_define_rtas_kernel_token(uint32_t token
, const char *function
);
56 int kvmppc_get_htab_fd(bool write
, uint64_t index
, Error
**errp
);
57 int kvmppc_save_htab(QEMUFile
*f
, int fd
, size_t bufsize
, int64_t max_ns
);
58 int kvmppc_load_htab_chunk(QEMUFile
*f
, int fd
, uint32_t index
,
59 uint16_t n_valid
, uint16_t n_invalid
, Error
**errp
);
60 void kvmppc_read_hptes(ppc_hash_pte64_t
*hptes
, hwaddr ptex
, int n
);
61 void kvmppc_write_hpte(hwaddr ptex
, uint64_t pte0
, uint64_t pte1
);
62 bool kvmppc_has_cap_fixup_hcalls(void);
63 bool kvmppc_has_cap_htm(void);
64 bool kvmppc_has_cap_mmu_radix(void);
65 bool kvmppc_has_cap_mmu_hash_v3(void);
66 bool kvmppc_has_cap_xive(void);
67 int kvmppc_get_cap_safe_cache(void);
68 int kvmppc_get_cap_safe_bounds_check(void);
69 int kvmppc_get_cap_safe_indirect_branch(void);
70 int kvmppc_get_cap_count_cache_flush_assist(void);
71 bool kvmppc_has_cap_nested_kvm_hv(void);
72 int kvmppc_set_cap_nested_kvm_hv(int enable
);
73 int kvmppc_get_cap_large_decr(void);
74 int kvmppc_enable_cap_large_decr(PowerPCCPU
*cpu
, int enable
);
75 int kvmppc_has_cap_rpt_invalidate(void);
76 bool kvmppc_supports_ail_3(void);
77 int kvmppc_enable_hwrng(void);
78 int kvmppc_put_books_sregs(PowerPCCPU
*cpu
);
79 PowerPCCPUClass
*kvm_ppc_get_host_cpu_class(void);
80 void kvmppc_check_papr_resize_hpt(Error
**errp
);
81 int kvmppc_resize_hpt_prepare(PowerPCCPU
*cpu
, target_ulong flags
, int shift
);
82 int kvmppc_resize_hpt_commit(PowerPCCPU
*cpu
, target_ulong flags
, int shift
);
83 bool kvmppc_pvr_workaround_required(PowerPCCPU
*cpu
);
85 bool kvmppc_hpt_needs_host_contiguous_pages(void);
86 void kvm_check_mmu(PowerPCCPU
*cpu
, Error
**errp
);
87 void kvmppc_set_reg_ppc_online(PowerPCCPU
*cpu
, unsigned int online
);
88 void kvmppc_set_reg_tb_offset(PowerPCCPU
*cpu
, int64_t tb_offset
);
90 int kvm_handle_nmi(PowerPCCPU
*cpu
, struct kvm_run
*run
);
92 #define kvmppc_eieio() \
94 if (kvm_enabled()) { \
95 asm volatile("eieio" : : : "memory"); \
99 /* Store data cache blocks back to memory */
100 static inline void kvmppc_dcbst_range(PowerPCCPU
*cpu
, uint8_t *addr
, int len
)
104 for (p
= addr
; p
< addr
+ len
; p
+= cpu
->env
.dcache_line_size
) {
105 asm volatile("dcbst 0,%0" : : "r"(p
) : "memory");
109 /* Invalidate instruction cache blocks */
110 static inline void kvmppc_icbi_range(PowerPCCPU
*cpu
, uint8_t *addr
, int len
)
114 for (p
= addr
; p
< addr
+ len
; p
+= cpu
->env
.icache_line_size
) {
115 asm volatile("icbi 0,%0" : : "r"(p
));
119 #else /* !CONFIG_KVM */
121 static inline uint32_t kvmppc_get_tbfreq(void)
126 static inline bool kvmppc_get_host_model(char **buf
)
131 static inline bool kvmppc_get_host_serial(char **buf
)
136 static inline uint64_t kvmppc_get_clockfreq(void)
141 static inline uint32_t kvmppc_get_vmx(void)
146 static inline uint32_t kvmppc_get_dfp(void)
151 static inline int kvmppc_get_hasidle(CPUPPCState
*env
)
156 static inline int kvmppc_get_hypercall(CPUPPCState
*env
,
157 uint8_t *buf
, int buf_len
)
162 static inline int kvmppc_set_interrupt(PowerPCCPU
*cpu
, int irq
, int level
)
167 static inline void kvmppc_enable_logical_ci_hcalls(void)
171 static inline void kvmppc_enable_set_mode_hcall(void)
175 static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
179 static inline void kvmppc_enable_h_page_init(void)
183 static inline void kvmppc_enable_h_rpt_invalidate(void)
185 g_assert_not_reached();
188 static inline void kvmppc_set_papr(PowerPCCPU
*cpu
)
192 static inline int kvmppc_set_compat(PowerPCCPU
*cpu
, uint32_t compat_pvr
)
197 static inline void kvmppc_set_mpic_proxy(PowerPCCPU
*cpu
, int mpic_proxy
)
201 static inline bool kvmppc_get_fwnmi(void)
206 static inline int kvmppc_set_fwnmi(PowerPCCPU
*cpu
)
211 static inline int kvmppc_smt_threads(void)
216 static inline void kvmppc_error_append_smt_possible_hint(Error
*const *errp
)
221 static inline int kvmppc_set_smt_threads(int smt
)
226 static inline int kvmppc_or_tsr_bits(PowerPCCPU
*cpu
, uint32_t tsr_bits
)
231 static inline int kvmppc_clear_tsr_bits(PowerPCCPU
*cpu
, uint32_t tsr_bits
)
236 static inline int kvmppc_set_tcr(PowerPCCPU
*cpu
)
241 static inline int kvmppc_booke_watchdog_enable(PowerPCCPU
*cpu
)
246 static inline target_ulong
kvmppc_configure_v3_mmu(PowerPCCPU
*cpu
,
247 bool radix
, bool gtse
,
253 static inline void kvmppc_set_reg_ppc_online(PowerPCCPU
*cpu
,
259 static inline void kvmppc_set_reg_tb_offset(PowerPCCPU
*cpu
, int64_t tb_offset
)
263 static inline bool kvmppc_spapr_use_multitce(void)
268 static inline int kvmppc_spapr_enable_inkernel_multitce(void)
273 static inline void *kvmppc_create_spapr_tce(uint32_t liobn
, uint32_t page_shift
,
276 int *pfd
, bool need_vfio
)
281 static inline int kvmppc_remove_spapr_tce(void *table
, int pfd
,
287 static inline int kvmppc_reset_htab(int shift_hint
)
292 static inline uint64_t kvmppc_vrma_limit(unsigned int hash_shift
)
294 g_assert_not_reached();
297 static inline bool kvmppc_hpt_needs_host_contiguous_pages(void)
302 static inline void kvm_check_mmu(PowerPCCPU
*cpu
, Error
**errp
)
306 static inline bool kvmppc_has_cap_spapr_vfio(void)
311 static inline void kvmppc_read_hptes(ppc_hash_pte64_t
*hptes
,
317 static inline void kvmppc_write_hpte(hwaddr ptex
, uint64_t pte0
, uint64_t pte1
)
322 static inline bool kvmppc_has_cap_epr(void)
327 static inline int kvmppc_define_rtas_kernel_token(uint32_t token
,
328 const char *function
)
333 static inline int kvmppc_get_htab_fd(bool write
, uint64_t index
, Error
**errp
)
338 static inline int kvmppc_save_htab(QEMUFile
*f
, int fd
, size_t bufsize
,
344 static inline int kvmppc_load_htab_chunk(QEMUFile
*f
, int fd
, uint32_t index
,
345 uint16_t n_valid
, uint16_t n_invalid
,
351 static inline bool kvmppc_has_cap_fixup_hcalls(void)
356 static inline bool kvmppc_has_cap_htm(void)
361 static inline bool kvmppc_has_cap_mmu_radix(void)
366 static inline bool kvmppc_has_cap_mmu_hash_v3(void)
371 static inline bool kvmppc_has_cap_xive(void)
376 static inline int kvmppc_get_cap_safe_cache(void)
381 static inline int kvmppc_get_cap_safe_bounds_check(void)
386 static inline int kvmppc_get_cap_safe_indirect_branch(void)
391 static inline int kvmppc_get_cap_count_cache_flush_assist(void)
396 static inline bool kvmppc_has_cap_nested_kvm_hv(void)
401 static inline int kvmppc_set_cap_nested_kvm_hv(int enable
)
406 static inline int kvmppc_get_cap_large_decr(void)
411 static inline int kvmppc_enable_cap_large_decr(PowerPCCPU
*cpu
, int enable
)
416 static inline int kvmppc_has_cap_rpt_invalidate(void)
421 static inline bool kvmppc_supports_ail_3(void)
426 static inline int kvmppc_enable_hwrng(void)
431 static inline int kvmppc_put_books_sregs(PowerPCCPU
*cpu
)
436 static inline PowerPCCPUClass
*kvm_ppc_get_host_cpu_class(void)
441 static inline void kvmppc_check_papr_resize_hpt(Error
**errp
)
446 static inline int kvmppc_resize_hpt_prepare(PowerPCCPU
*cpu
,
447 target_ulong flags
, int shift
)
452 static inline int kvmppc_resize_hpt_commit(PowerPCCPU
*cpu
,
453 target_ulong flags
, int shift
)
458 static inline bool kvmppc_pvr_workaround_required(PowerPCCPU
*cpu
)
463 #define kvmppc_eieio() do { } while (0)
465 static inline void kvmppc_dcbst_range(PowerPCCPU
*cpu
, uint8_t *addr
, int len
)
469 static inline void kvmppc_icbi_range(PowerPCCPU
*cpu
, uint8_t *addr
, int len
)
473 #endif /* CONFIG_KVM */
475 #endif /* KVM_PPC_H */