1d76d1650Saurel32 /* 2d76d1650Saurel32 * Copyright 2008 IBM Corporation. 3d76d1650Saurel32 * Authors: Hollis Blanchard <hollisb@us.ibm.com> 4d76d1650Saurel32 * 5d76d1650Saurel32 * This work is licensed under the GNU GPL license version 2 or later. 6d76d1650Saurel32 * 7d76d1650Saurel32 */ 8d76d1650Saurel32 92a6a4076SMarkus Armbruster #ifndef KVM_PPC_H 102a6a4076SMarkus Armbruster #define KVM_PPC_H 11d76d1650Saurel32 122985b86bSAndreas Färber #define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU 132985b86bSAndreas Färber 14921e28dbSAlexander Graf #ifdef CONFIG_KVM 15921e28dbSAlexander Graf 16dc333cd6SAlexander Graf uint32_t kvmppc_get_tbfreq(void); 17eadaada1SAlexander Graf uint64_t kvmppc_get_clockfreq(void); 186659394fSDavid Gibson uint32_t kvmppc_get_vmx(void); 196659394fSDavid Gibson uint32_t kvmppc_get_dfp(void); 20ef951443SNikunj A Dadhania bool kvmppc_get_host_model(char **buf); 21ef951443SNikunj A Dadhania bool kvmppc_get_host_serial(char **buf); 221a61a9aeSStuart Yoder int kvmppc_get_hasidle(CPUPPCState *env); 231328c2bfSAndreas Färber int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len); 241bc22652SAndreas Färber int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level); 25026bfd89SDavid Gibson void kvmppc_enable_logical_ci_hcalls(void); 26ef9971ddSAlexey Kardashevskiy void kvmppc_enable_set_mode_hcall(void); 275145ad4fSNathan Whitehorn void kvmppc_enable_clear_ref_mod_hcalls(void); 281bc22652SAndreas Färber void kvmppc_set_papr(PowerPCCPU *cpu); 29d6e166c0SDavid Gibson int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr); 305b95b8b9SAlexander Graf void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy); 31e97c3636SDavid Gibson int kvmppc_smt_threads(void); 3231f2cb8fSBharat Bhushan int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits); 3331f2cb8fSBharat Bhushan int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits); 3431f2cb8fSBharat Bhushan int kvmppc_set_tcr(PowerPCCPU *cpu); 3531f2cb8fSBharat Bhushan int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu); 36b4db5413SSuraj Jitindar Singh target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, 37b4db5413SSuraj Jitindar Singh bool radix, bool gtse, 38b4db5413SSuraj Jitindar Singh uint64_t proc_tbl); 3998efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY 40658fa66bSAlexey Kardashevskiy off_t kvmppc_alloc_rma(void **rma); 41da95324eSAlexey Kardashevskiy bool kvmppc_spapr_use_multitce(void); 423dc410aeSAlexey Kardashevskiy int kvmppc_spapr_enable_inkernel_multitce(void); 43d6ee2a7cSAlexey Kardashevskiy void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift, 44d6ee2a7cSAlexey Kardashevskiy uint64_t bus_offset, uint32_t nb_table, 45d6ee2a7cSAlexey Kardashevskiy int *pfd, bool need_vfio); 460f5cb298SDavid Gibson int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size); 477f763a5dSDavid Gibson int kvmppc_reset_htab(int shift_hint); 487f763a5dSDavid Gibson uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift); 4998efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */ 503b961124SStuart Yoder bool kvmppc_has_cap_epr(void); 51feaa64c4SDavid Gibson int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function); 527c43bca0SAneesh Kumar K.V bool kvmppc_has_cap_htab_fd(void); 53e68cb8b4SAlexey Kardashevskiy int kvmppc_get_htab_fd(bool write); 54e68cb8b4SAlexey Kardashevskiy int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns); 55e68cb8b4SAlexey Kardashevskiy int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, 56e68cb8b4SAlexey Kardashevskiy uint16_t n_valid, uint16_t n_invalid); 571ad9f0a4SDavid Gibson void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n); 581ad9f0a4SDavid Gibson void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1); 5987a91de6SAlexander Graf bool kvmppc_has_cap_fixup_hcalls(void); 60bac3bf28SThomas Huth bool kvmppc_has_cap_htm(void); 61cf1c4cceSSam Bobroff bool kvmppc_has_cap_mmu_radix(void); 62cf1c4cceSSam Bobroff bool kvmppc_has_cap_mmu_hash_v3(void); 634d9392beSThomas Huth int kvmppc_enable_hwrng(void); 64e5c0d3ceSDavid Gibson int kvmppc_put_books_sregs(PowerPCCPU *cpu); 6552b2519cSThomas Huth PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void); 6630f4b05bSDavid Gibson void kvmppc_check_papr_resize_hpt(Error **errp); 67*b55d295eSDavid Gibson int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shift); 68*b55d295eSDavid Gibson int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shift); 69*b55d295eSDavid Gibson void kvmppc_update_sdr1(target_ulong sdr1); 70c1385933SAneesh Kumar K.V 71ec69355bSGreg Kurz bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); 72df587133SThomas Huth 73921e28dbSAlexander Graf #else 74921e28dbSAlexander Graf 75921e28dbSAlexander Graf static inline uint32_t kvmppc_get_tbfreq(void) 76921e28dbSAlexander Graf { 77921e28dbSAlexander Graf return 0; 78921e28dbSAlexander Graf } 79921e28dbSAlexander Graf 80ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_model(char **buf) 81ef951443SNikunj A Dadhania { 82ef951443SNikunj A Dadhania return false; 83ef951443SNikunj A Dadhania } 84ef951443SNikunj A Dadhania 85ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_serial(char **buf) 86ef951443SNikunj A Dadhania { 87ef951443SNikunj A Dadhania return false; 88ef951443SNikunj A Dadhania } 89ef951443SNikunj A Dadhania 90921e28dbSAlexander Graf static inline uint64_t kvmppc_get_clockfreq(void) 91921e28dbSAlexander Graf { 92921e28dbSAlexander Graf return 0; 93921e28dbSAlexander Graf } 94921e28dbSAlexander Graf 956659394fSDavid Gibson static inline uint32_t kvmppc_get_vmx(void) 966659394fSDavid Gibson { 976659394fSDavid Gibson return 0; 986659394fSDavid Gibson } 996659394fSDavid Gibson 1006659394fSDavid Gibson static inline uint32_t kvmppc_get_dfp(void) 1016659394fSDavid Gibson { 1026659394fSDavid Gibson return 0; 1036659394fSDavid Gibson } 1046659394fSDavid Gibson 1051a61a9aeSStuart Yoder static inline int kvmppc_get_hasidle(CPUPPCState *env) 1061a61a9aeSStuart Yoder { 1071a61a9aeSStuart Yoder return 0; 1081a61a9aeSStuart Yoder } 1091a61a9aeSStuart Yoder 1101328c2bfSAndreas Färber static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len) 111921e28dbSAlexander Graf { 112921e28dbSAlexander Graf return -1; 113921e28dbSAlexander Graf } 114921e28dbSAlexander Graf 1151bc22652SAndreas Färber static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level) 116921e28dbSAlexander Graf { 117921e28dbSAlexander Graf return -1; 118921e28dbSAlexander Graf } 119921e28dbSAlexander Graf 120026bfd89SDavid Gibson static inline void kvmppc_enable_logical_ci_hcalls(void) 121026bfd89SDavid Gibson { 122026bfd89SDavid Gibson } 123026bfd89SDavid Gibson 124ef9971ddSAlexey Kardashevskiy static inline void kvmppc_enable_set_mode_hcall(void) 125ef9971ddSAlexey Kardashevskiy { 126ef9971ddSAlexey Kardashevskiy } 127ef9971ddSAlexey Kardashevskiy 1285145ad4fSNathan Whitehorn static inline void kvmppc_enable_clear_ref_mod_hcalls(void) 1295145ad4fSNathan Whitehorn { 1305145ad4fSNathan Whitehorn } 1315145ad4fSNathan Whitehorn 1321bc22652SAndreas Färber static inline void kvmppc_set_papr(PowerPCCPU *cpu) 133f61b4bedSAlexander Graf { 134f61b4bedSAlexander Graf } 135f61b4bedSAlexander Graf 136d6e166c0SDavid Gibson static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr) 1376db5bb0fSAlexey Kardashevskiy { 1386db5bb0fSAlexey Kardashevskiy return 0; 1396db5bb0fSAlexey Kardashevskiy } 1406db5bb0fSAlexey Kardashevskiy 1415b95b8b9SAlexander Graf static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) 1425b95b8b9SAlexander Graf { 1435b95b8b9SAlexander Graf } 1445b95b8b9SAlexander Graf 145e97c3636SDavid Gibson static inline int kvmppc_smt_threads(void) 146e97c3636SDavid Gibson { 147e97c3636SDavid Gibson return 1; 148e97c3636SDavid Gibson } 149e97c3636SDavid Gibson 15031f2cb8fSBharat Bhushan static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits) 15131f2cb8fSBharat Bhushan { 15231f2cb8fSBharat Bhushan return 0; 15331f2cb8fSBharat Bhushan } 15431f2cb8fSBharat Bhushan 15531f2cb8fSBharat Bhushan static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits) 15631f2cb8fSBharat Bhushan { 15731f2cb8fSBharat Bhushan return 0; 15831f2cb8fSBharat Bhushan } 15931f2cb8fSBharat Bhushan 16031f2cb8fSBharat Bhushan static inline int kvmppc_set_tcr(PowerPCCPU *cpu) 16131f2cb8fSBharat Bhushan { 16231f2cb8fSBharat Bhushan return 0; 16331f2cb8fSBharat Bhushan } 16431f2cb8fSBharat Bhushan 16531f2cb8fSBharat Bhushan static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu) 16631f2cb8fSBharat Bhushan { 16731f2cb8fSBharat Bhushan return -1; 16831f2cb8fSBharat Bhushan } 16931f2cb8fSBharat Bhushan 170b4db5413SSuraj Jitindar Singh static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, 171b4db5413SSuraj Jitindar Singh bool radix, bool gtse, 172b4db5413SSuraj Jitindar Singh uint64_t proc_tbl) 173b4db5413SSuraj Jitindar Singh { 174b4db5413SSuraj Jitindar Singh return 0; 175b4db5413SSuraj Jitindar Singh } 176b4db5413SSuraj Jitindar Singh 17798efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY 178658fa66bSAlexey Kardashevskiy static inline off_t kvmppc_alloc_rma(void **rma) 179354ac20aSDavid Gibson { 180354ac20aSDavid Gibson return 0; 181354ac20aSDavid Gibson } 182354ac20aSDavid Gibson 183da95324eSAlexey Kardashevskiy static inline bool kvmppc_spapr_use_multitce(void) 184da95324eSAlexey Kardashevskiy { 185da95324eSAlexey Kardashevskiy return false; 186da95324eSAlexey Kardashevskiy } 187da95324eSAlexey Kardashevskiy 1883dc410aeSAlexey Kardashevskiy static inline int kvmppc_spapr_enable_inkernel_multitce(void) 1893dc410aeSAlexey Kardashevskiy { 1903dc410aeSAlexey Kardashevskiy return -1; 1913dc410aeSAlexey Kardashevskiy } 1923dc410aeSAlexey Kardashevskiy 193d6ee2a7cSAlexey Kardashevskiy static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift, 194d6ee2a7cSAlexey Kardashevskiy uint64_t bus_offset, 195d6ee2a7cSAlexey Kardashevskiy uint32_t nb_table, 196d6ee2a7cSAlexey Kardashevskiy int *pfd, bool need_vfio) 1970f5cb298SDavid Gibson { 1980f5cb298SDavid Gibson return NULL; 1990f5cb298SDavid Gibson } 2000f5cb298SDavid Gibson 2010f5cb298SDavid Gibson static inline int kvmppc_remove_spapr_tce(void *table, int pfd, 202523e7b8aSAlexey Kardashevskiy uint32_t nb_table) 2030f5cb298SDavid Gibson { 2040f5cb298SDavid Gibson return -1; 2050f5cb298SDavid Gibson } 2067f763a5dSDavid Gibson 2077f763a5dSDavid Gibson static inline int kvmppc_reset_htab(int shift_hint) 2087f763a5dSDavid Gibson { 209a3166f8fSBharata B Rao return 0; 2107f763a5dSDavid Gibson } 2117f763a5dSDavid Gibson 2127f763a5dSDavid Gibson static inline uint64_t kvmppc_rma_size(uint64_t current_size, 2137f763a5dSDavid Gibson unsigned int hash_shift) 2147f763a5dSDavid Gibson { 2157f763a5dSDavid Gibson return ram_size; 2167f763a5dSDavid Gibson } 2177f763a5dSDavid Gibson 218ec69355bSGreg Kurz static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) 219df587133SThomas Huth { 220df587133SThomas Huth return true; 221df587133SThomas Huth } 222df587133SThomas Huth 22398efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */ 2240f5cb298SDavid Gibson 2253b961124SStuart Yoder static inline bool kvmppc_has_cap_epr(void) 2263b961124SStuart Yoder { 2273b961124SStuart Yoder return false; 2283b961124SStuart Yoder } 229e68cb8b4SAlexey Kardashevskiy 230feaa64c4SDavid Gibson static inline int kvmppc_define_rtas_kernel_token(uint32_t token, 231feaa64c4SDavid Gibson const char *function) 232feaa64c4SDavid Gibson { 233feaa64c4SDavid Gibson return -1; 234feaa64c4SDavid Gibson } 235feaa64c4SDavid Gibson 2367c43bca0SAneesh Kumar K.V static inline bool kvmppc_has_cap_htab_fd(void) 2377c43bca0SAneesh Kumar K.V { 2387c43bca0SAneesh Kumar K.V return false; 2397c43bca0SAneesh Kumar K.V } 2407c43bca0SAneesh Kumar K.V 241e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_get_htab_fd(bool write) 242e68cb8b4SAlexey Kardashevskiy { 243e68cb8b4SAlexey Kardashevskiy return -1; 244e68cb8b4SAlexey Kardashevskiy } 245e68cb8b4SAlexey Kardashevskiy 246e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, 247e68cb8b4SAlexey Kardashevskiy int64_t max_ns) 248e68cb8b4SAlexey Kardashevskiy { 249e68cb8b4SAlexey Kardashevskiy abort(); 250e68cb8b4SAlexey Kardashevskiy } 251e68cb8b4SAlexey Kardashevskiy 252e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, 253e68cb8b4SAlexey Kardashevskiy uint16_t n_valid, uint16_t n_invalid) 254e68cb8b4SAlexey Kardashevskiy { 255e68cb8b4SAlexey Kardashevskiy abort(); 256e68cb8b4SAlexey Kardashevskiy } 257e68cb8b4SAlexey Kardashevskiy 2581ad9f0a4SDavid Gibson static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, 2591ad9f0a4SDavid Gibson hwaddr ptex, int n) 2607c43bca0SAneesh Kumar K.V { 2617c43bca0SAneesh Kumar K.V abort(); 2627c43bca0SAneesh Kumar K.V } 2637c43bca0SAneesh Kumar K.V 2641ad9f0a4SDavid Gibson static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1) 265c1385933SAneesh Kumar K.V { 266c1385933SAneesh Kumar K.V abort(); 267c1385933SAneesh Kumar K.V } 268c1385933SAneesh Kumar K.V 26987a91de6SAlexander Graf static inline bool kvmppc_has_cap_fixup_hcalls(void) 27087a91de6SAlexander Graf { 27187a91de6SAlexander Graf abort(); 27287a91de6SAlexander Graf } 27387a91de6SAlexander Graf 274bac3bf28SThomas Huth static inline bool kvmppc_has_cap_htm(void) 275bac3bf28SThomas Huth { 276bac3bf28SThomas Huth return false; 277bac3bf28SThomas Huth } 278bac3bf28SThomas Huth 279cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_radix(void) 280cf1c4cceSSam Bobroff { 281cf1c4cceSSam Bobroff return false; 282cf1c4cceSSam Bobroff } 283cf1c4cceSSam Bobroff 284cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_hash_v3(void) 285cf1c4cceSSam Bobroff { 286cf1c4cceSSam Bobroff return false; 287cf1c4cceSSam Bobroff } 288cf1c4cceSSam Bobroff 2894d9392beSThomas Huth static inline int kvmppc_enable_hwrng(void) 2904d9392beSThomas Huth { 2914d9392beSThomas Huth return -1; 2924d9392beSThomas Huth } 293e5c0d3ceSDavid Gibson 294e5c0d3ceSDavid Gibson static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu) 295e5c0d3ceSDavid Gibson { 296e5c0d3ceSDavid Gibson abort(); 297e5c0d3ceSDavid Gibson } 29852b2519cSThomas Huth 29952b2519cSThomas Huth static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) 30052b2519cSThomas Huth { 30152b2519cSThomas Huth return NULL; 30252b2519cSThomas Huth } 30352b2519cSThomas Huth 30430f4b05bSDavid Gibson static inline void kvmppc_check_papr_resize_hpt(Error **errp) 30530f4b05bSDavid Gibson { 30630f4b05bSDavid Gibson return; 30730f4b05bSDavid Gibson } 308*b55d295eSDavid Gibson 309*b55d295eSDavid Gibson static inline int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, 310*b55d295eSDavid Gibson target_ulong flags, int shift) 311*b55d295eSDavid Gibson { 312*b55d295eSDavid Gibson return -ENOSYS; 313*b55d295eSDavid Gibson } 314*b55d295eSDavid Gibson 315*b55d295eSDavid Gibson static inline int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, 316*b55d295eSDavid Gibson target_ulong flags, int shift) 317*b55d295eSDavid Gibson { 318*b55d295eSDavid Gibson return -ENOSYS; 319*b55d295eSDavid Gibson } 320*b55d295eSDavid Gibson 321*b55d295eSDavid Gibson static inline void kvmppc_update_sdr1(target_ulong sdr1) 322*b55d295eSDavid Gibson { 323*b55d295eSDavid Gibson abort(); 324*b55d295eSDavid Gibson } 325*b55d295eSDavid Gibson 326921e28dbSAlexander Graf #endif 327921e28dbSAlexander Graf 328b45d63b6SBen Herrenschmidt #ifndef CONFIG_KVM 3293240dd9aSThomas Huth 330b45d63b6SBen Herrenschmidt #define kvmppc_eieio() do { } while (0) 3313240dd9aSThomas Huth 3323240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3333240dd9aSThomas Huth { 3343240dd9aSThomas Huth } 3353240dd9aSThomas Huth 3363240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3373240dd9aSThomas Huth { 3383240dd9aSThomas Huth } 3393240dd9aSThomas Huth 3403240dd9aSThomas Huth #else /* CONFIG_KVM */ 3413240dd9aSThomas Huth 342b45d63b6SBen Herrenschmidt #define kvmppc_eieio() \ 343b45d63b6SBen Herrenschmidt do { \ 344b45d63b6SBen Herrenschmidt if (kvm_enabled()) { \ 345b45d63b6SBen Herrenschmidt asm volatile("eieio" : : : "memory"); \ 346b45d63b6SBen Herrenschmidt } \ 347b45d63b6SBen Herrenschmidt } while (0) 3483240dd9aSThomas Huth 3493240dd9aSThomas Huth /* Store data cache blocks back to memory */ 3503240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3513240dd9aSThomas Huth { 3523240dd9aSThomas Huth uint8_t *p; 3533240dd9aSThomas Huth 3543240dd9aSThomas Huth for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) { 3553240dd9aSThomas Huth asm volatile("dcbst 0,%0" : : "r"(p) : "memory"); 3563240dd9aSThomas Huth } 3573240dd9aSThomas Huth } 3583240dd9aSThomas Huth 3593240dd9aSThomas Huth /* Invalidate instruction cache blocks */ 3603240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3613240dd9aSThomas Huth { 3623240dd9aSThomas Huth uint8_t *p; 3633240dd9aSThomas Huth 3643240dd9aSThomas Huth for (p = addr; p < addr + len; p += cpu->env.icache_line_size) { 3653240dd9aSThomas Huth asm volatile("icbi 0,%0" : : "r"(p)); 3663240dd9aSThomas Huth } 3673240dd9aSThomas Huth } 3683240dd9aSThomas Huth 3693240dd9aSThomas Huth #endif /* CONFIG_KVM */ 370b45d63b6SBen Herrenschmidt 3712a6a4076SMarkus Armbruster #endif /* KVM_PPC_H */ 372