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