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