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); 66c1385933SAneesh Kumar K.V 67*ec69355bSGreg Kurz bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path); 68df587133SThomas Huth 69921e28dbSAlexander Graf #else 70921e28dbSAlexander Graf 71921e28dbSAlexander Graf static inline uint32_t kvmppc_get_tbfreq(void) 72921e28dbSAlexander Graf { 73921e28dbSAlexander Graf return 0; 74921e28dbSAlexander Graf } 75921e28dbSAlexander Graf 76ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_model(char **buf) 77ef951443SNikunj A Dadhania { 78ef951443SNikunj A Dadhania return false; 79ef951443SNikunj A Dadhania } 80ef951443SNikunj A Dadhania 81ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_serial(char **buf) 82ef951443SNikunj A Dadhania { 83ef951443SNikunj A Dadhania return false; 84ef951443SNikunj A Dadhania } 85ef951443SNikunj A Dadhania 86921e28dbSAlexander Graf static inline uint64_t kvmppc_get_clockfreq(void) 87921e28dbSAlexander Graf { 88921e28dbSAlexander Graf return 0; 89921e28dbSAlexander Graf } 90921e28dbSAlexander Graf 916659394fSDavid Gibson static inline uint32_t kvmppc_get_vmx(void) 926659394fSDavid Gibson { 936659394fSDavid Gibson return 0; 946659394fSDavid Gibson } 956659394fSDavid Gibson 966659394fSDavid Gibson static inline uint32_t kvmppc_get_dfp(void) 976659394fSDavid Gibson { 986659394fSDavid Gibson return 0; 996659394fSDavid Gibson } 1006659394fSDavid Gibson 1011a61a9aeSStuart Yoder static inline int kvmppc_get_hasidle(CPUPPCState *env) 1021a61a9aeSStuart Yoder { 1031a61a9aeSStuart Yoder return 0; 1041a61a9aeSStuart Yoder } 1051a61a9aeSStuart Yoder 1061328c2bfSAndreas Färber static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len) 107921e28dbSAlexander Graf { 108921e28dbSAlexander Graf return -1; 109921e28dbSAlexander Graf } 110921e28dbSAlexander Graf 1111bc22652SAndreas Färber static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level) 112921e28dbSAlexander Graf { 113921e28dbSAlexander Graf return -1; 114921e28dbSAlexander Graf } 115921e28dbSAlexander Graf 116026bfd89SDavid Gibson static inline void kvmppc_enable_logical_ci_hcalls(void) 117026bfd89SDavid Gibson { 118026bfd89SDavid Gibson } 119026bfd89SDavid Gibson 120ef9971ddSAlexey Kardashevskiy static inline void kvmppc_enable_set_mode_hcall(void) 121ef9971ddSAlexey Kardashevskiy { 122ef9971ddSAlexey Kardashevskiy } 123ef9971ddSAlexey Kardashevskiy 1245145ad4fSNathan Whitehorn static inline void kvmppc_enable_clear_ref_mod_hcalls(void) 1255145ad4fSNathan Whitehorn { 1265145ad4fSNathan Whitehorn } 1275145ad4fSNathan Whitehorn 1281bc22652SAndreas Färber static inline void kvmppc_set_papr(PowerPCCPU *cpu) 129f61b4bedSAlexander Graf { 130f61b4bedSAlexander Graf } 131f61b4bedSAlexander Graf 132d6e166c0SDavid Gibson static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr) 1336db5bb0fSAlexey Kardashevskiy { 1346db5bb0fSAlexey Kardashevskiy return 0; 1356db5bb0fSAlexey Kardashevskiy } 1366db5bb0fSAlexey Kardashevskiy 1375b95b8b9SAlexander Graf static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) 1385b95b8b9SAlexander Graf { 1395b95b8b9SAlexander Graf } 1405b95b8b9SAlexander Graf 141e97c3636SDavid Gibson static inline int kvmppc_smt_threads(void) 142e97c3636SDavid Gibson { 143e97c3636SDavid Gibson return 1; 144e97c3636SDavid Gibson } 145e97c3636SDavid Gibson 14631f2cb8fSBharat Bhushan static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits) 14731f2cb8fSBharat Bhushan { 14831f2cb8fSBharat Bhushan return 0; 14931f2cb8fSBharat Bhushan } 15031f2cb8fSBharat Bhushan 15131f2cb8fSBharat Bhushan static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits) 15231f2cb8fSBharat Bhushan { 15331f2cb8fSBharat Bhushan return 0; 15431f2cb8fSBharat Bhushan } 15531f2cb8fSBharat Bhushan 15631f2cb8fSBharat Bhushan static inline int kvmppc_set_tcr(PowerPCCPU *cpu) 15731f2cb8fSBharat Bhushan { 15831f2cb8fSBharat Bhushan return 0; 15931f2cb8fSBharat Bhushan } 16031f2cb8fSBharat Bhushan 16131f2cb8fSBharat Bhushan static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu) 16231f2cb8fSBharat Bhushan { 16331f2cb8fSBharat Bhushan return -1; 16431f2cb8fSBharat Bhushan } 16531f2cb8fSBharat Bhushan 166b4db5413SSuraj Jitindar Singh static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, 167b4db5413SSuraj Jitindar Singh bool radix, bool gtse, 168b4db5413SSuraj Jitindar Singh uint64_t proc_tbl) 169b4db5413SSuraj Jitindar Singh { 170b4db5413SSuraj Jitindar Singh return 0; 171b4db5413SSuraj Jitindar Singh } 172b4db5413SSuraj Jitindar Singh 17398efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY 174658fa66bSAlexey Kardashevskiy static inline off_t kvmppc_alloc_rma(void **rma) 175354ac20aSDavid Gibson { 176354ac20aSDavid Gibson return 0; 177354ac20aSDavid Gibson } 178354ac20aSDavid Gibson 179da95324eSAlexey Kardashevskiy static inline bool kvmppc_spapr_use_multitce(void) 180da95324eSAlexey Kardashevskiy { 181da95324eSAlexey Kardashevskiy return false; 182da95324eSAlexey Kardashevskiy } 183da95324eSAlexey Kardashevskiy 1843dc410aeSAlexey Kardashevskiy static inline int kvmppc_spapr_enable_inkernel_multitce(void) 1853dc410aeSAlexey Kardashevskiy { 1863dc410aeSAlexey Kardashevskiy return -1; 1873dc410aeSAlexey Kardashevskiy } 1883dc410aeSAlexey Kardashevskiy 189d6ee2a7cSAlexey Kardashevskiy static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift, 190d6ee2a7cSAlexey Kardashevskiy uint64_t bus_offset, 191d6ee2a7cSAlexey Kardashevskiy uint32_t nb_table, 192d6ee2a7cSAlexey Kardashevskiy int *pfd, bool need_vfio) 1930f5cb298SDavid Gibson { 1940f5cb298SDavid Gibson return NULL; 1950f5cb298SDavid Gibson } 1960f5cb298SDavid Gibson 1970f5cb298SDavid Gibson static inline int kvmppc_remove_spapr_tce(void *table, int pfd, 198523e7b8aSAlexey Kardashevskiy uint32_t nb_table) 1990f5cb298SDavid Gibson { 2000f5cb298SDavid Gibson return -1; 2010f5cb298SDavid Gibson } 2027f763a5dSDavid Gibson 2037f763a5dSDavid Gibson static inline int kvmppc_reset_htab(int shift_hint) 2047f763a5dSDavid Gibson { 205a3166f8fSBharata B Rao return 0; 2067f763a5dSDavid Gibson } 2077f763a5dSDavid Gibson 2087f763a5dSDavid Gibson static inline uint64_t kvmppc_rma_size(uint64_t current_size, 2097f763a5dSDavid Gibson unsigned int hash_shift) 2107f763a5dSDavid Gibson { 2117f763a5dSDavid Gibson return ram_size; 2127f763a5dSDavid Gibson } 2137f763a5dSDavid Gibson 214*ec69355bSGreg Kurz static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) 215df587133SThomas Huth { 216df587133SThomas Huth return true; 217df587133SThomas Huth } 218df587133SThomas Huth 21998efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */ 2200f5cb298SDavid Gibson 2213b961124SStuart Yoder static inline bool kvmppc_has_cap_epr(void) 2223b961124SStuart Yoder { 2233b961124SStuart Yoder return false; 2243b961124SStuart Yoder } 225e68cb8b4SAlexey Kardashevskiy 226feaa64c4SDavid Gibson static inline int kvmppc_define_rtas_kernel_token(uint32_t token, 227feaa64c4SDavid Gibson const char *function) 228feaa64c4SDavid Gibson { 229feaa64c4SDavid Gibson return -1; 230feaa64c4SDavid Gibson } 231feaa64c4SDavid Gibson 2327c43bca0SAneesh Kumar K.V static inline bool kvmppc_has_cap_htab_fd(void) 2337c43bca0SAneesh Kumar K.V { 2347c43bca0SAneesh Kumar K.V return false; 2357c43bca0SAneesh Kumar K.V } 2367c43bca0SAneesh Kumar K.V 237e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_get_htab_fd(bool write) 238e68cb8b4SAlexey Kardashevskiy { 239e68cb8b4SAlexey Kardashevskiy return -1; 240e68cb8b4SAlexey Kardashevskiy } 241e68cb8b4SAlexey Kardashevskiy 242e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, 243e68cb8b4SAlexey Kardashevskiy int64_t max_ns) 244e68cb8b4SAlexey Kardashevskiy { 245e68cb8b4SAlexey Kardashevskiy abort(); 246e68cb8b4SAlexey Kardashevskiy } 247e68cb8b4SAlexey Kardashevskiy 248e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, 249e68cb8b4SAlexey Kardashevskiy uint16_t n_valid, uint16_t n_invalid) 250e68cb8b4SAlexey Kardashevskiy { 251e68cb8b4SAlexey Kardashevskiy abort(); 252e68cb8b4SAlexey Kardashevskiy } 253e68cb8b4SAlexey Kardashevskiy 2541ad9f0a4SDavid Gibson static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, 2551ad9f0a4SDavid Gibson hwaddr ptex, int n) 2567c43bca0SAneesh Kumar K.V { 2577c43bca0SAneesh Kumar K.V abort(); 2587c43bca0SAneesh Kumar K.V } 2597c43bca0SAneesh Kumar K.V 2601ad9f0a4SDavid Gibson static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1) 261c1385933SAneesh Kumar K.V { 262c1385933SAneesh Kumar K.V abort(); 263c1385933SAneesh Kumar K.V } 264c1385933SAneesh Kumar K.V 26587a91de6SAlexander Graf static inline bool kvmppc_has_cap_fixup_hcalls(void) 26687a91de6SAlexander Graf { 26787a91de6SAlexander Graf abort(); 26887a91de6SAlexander Graf } 26987a91de6SAlexander Graf 270bac3bf28SThomas Huth static inline bool kvmppc_has_cap_htm(void) 271bac3bf28SThomas Huth { 272bac3bf28SThomas Huth return false; 273bac3bf28SThomas Huth } 274bac3bf28SThomas Huth 275cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_radix(void) 276cf1c4cceSSam Bobroff { 277cf1c4cceSSam Bobroff return false; 278cf1c4cceSSam Bobroff } 279cf1c4cceSSam Bobroff 280cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_hash_v3(void) 281cf1c4cceSSam Bobroff { 282cf1c4cceSSam Bobroff return false; 283cf1c4cceSSam Bobroff } 284cf1c4cceSSam Bobroff 2854d9392beSThomas Huth static inline int kvmppc_enable_hwrng(void) 2864d9392beSThomas Huth { 2874d9392beSThomas Huth return -1; 2884d9392beSThomas Huth } 289e5c0d3ceSDavid Gibson 290e5c0d3ceSDavid Gibson static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu) 291e5c0d3ceSDavid Gibson { 292e5c0d3ceSDavid Gibson abort(); 293e5c0d3ceSDavid Gibson } 29452b2519cSThomas Huth 29552b2519cSThomas Huth static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) 29652b2519cSThomas Huth { 29752b2519cSThomas Huth return NULL; 29852b2519cSThomas Huth } 29952b2519cSThomas Huth 300921e28dbSAlexander Graf #endif 301921e28dbSAlexander Graf 302b45d63b6SBen Herrenschmidt #ifndef CONFIG_KVM 3033240dd9aSThomas Huth 304b45d63b6SBen Herrenschmidt #define kvmppc_eieio() do { } while (0) 3053240dd9aSThomas Huth 3063240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3073240dd9aSThomas Huth { 3083240dd9aSThomas Huth } 3093240dd9aSThomas Huth 3103240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3113240dd9aSThomas Huth { 3123240dd9aSThomas Huth } 3133240dd9aSThomas Huth 3143240dd9aSThomas Huth #else /* CONFIG_KVM */ 3153240dd9aSThomas Huth 316b45d63b6SBen Herrenschmidt #define kvmppc_eieio() \ 317b45d63b6SBen Herrenschmidt do { \ 318b45d63b6SBen Herrenschmidt if (kvm_enabled()) { \ 319b45d63b6SBen Herrenschmidt asm volatile("eieio" : : : "memory"); \ 320b45d63b6SBen Herrenschmidt } \ 321b45d63b6SBen Herrenschmidt } while (0) 3223240dd9aSThomas Huth 3233240dd9aSThomas Huth /* Store data cache blocks back to memory */ 3243240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3253240dd9aSThomas Huth { 3263240dd9aSThomas Huth uint8_t *p; 3273240dd9aSThomas Huth 3283240dd9aSThomas Huth for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) { 3293240dd9aSThomas Huth asm volatile("dcbst 0,%0" : : "r"(p) : "memory"); 3303240dd9aSThomas Huth } 3313240dd9aSThomas Huth } 3323240dd9aSThomas Huth 3333240dd9aSThomas Huth /* Invalidate instruction cache blocks */ 3343240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len) 3353240dd9aSThomas Huth { 3363240dd9aSThomas Huth uint8_t *p; 3373240dd9aSThomas Huth 3383240dd9aSThomas Huth for (p = addr; p < addr + len; p += cpu->env.icache_line_size) { 3393240dd9aSThomas Huth asm volatile("icbi 0,%0" : : "r"(p)); 3403240dd9aSThomas Huth } 3413240dd9aSThomas Huth } 3423240dd9aSThomas Huth 3433240dd9aSThomas Huth #endif /* CONFIG_KVM */ 344b45d63b6SBen Herrenschmidt 3452a6a4076SMarkus Armbruster #endif /* KVM_PPC_H */ 346