xref: /qemu/target/ppc/kvm_ppc.h (revision 30f4b05bd090564181554d0890605eb2c143e4ea)
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);
66*30f4b05bSDavid Gibson void kvmppc_check_papr_resize_hpt(Error **errp);
67c1385933SAneesh Kumar K.V 
68ec69355bSGreg Kurz bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path);
69df587133SThomas Huth 
70921e28dbSAlexander Graf #else
71921e28dbSAlexander Graf 
72921e28dbSAlexander Graf static inline uint32_t kvmppc_get_tbfreq(void)
73921e28dbSAlexander Graf {
74921e28dbSAlexander Graf     return 0;
75921e28dbSAlexander Graf }
76921e28dbSAlexander Graf 
77ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_model(char **buf)
78ef951443SNikunj A Dadhania {
79ef951443SNikunj A Dadhania     return false;
80ef951443SNikunj A Dadhania }
81ef951443SNikunj A Dadhania 
82ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_serial(char **buf)
83ef951443SNikunj A Dadhania {
84ef951443SNikunj A Dadhania     return false;
85ef951443SNikunj A Dadhania }
86ef951443SNikunj A Dadhania 
87921e28dbSAlexander Graf static inline uint64_t kvmppc_get_clockfreq(void)
88921e28dbSAlexander Graf {
89921e28dbSAlexander Graf     return 0;
90921e28dbSAlexander Graf }
91921e28dbSAlexander Graf 
926659394fSDavid Gibson static inline uint32_t kvmppc_get_vmx(void)
936659394fSDavid Gibson {
946659394fSDavid Gibson     return 0;
956659394fSDavid Gibson }
966659394fSDavid Gibson 
976659394fSDavid Gibson static inline uint32_t kvmppc_get_dfp(void)
986659394fSDavid Gibson {
996659394fSDavid Gibson     return 0;
1006659394fSDavid Gibson }
1016659394fSDavid Gibson 
1021a61a9aeSStuart Yoder static inline int kvmppc_get_hasidle(CPUPPCState *env)
1031a61a9aeSStuart Yoder {
1041a61a9aeSStuart Yoder     return 0;
1051a61a9aeSStuart Yoder }
1061a61a9aeSStuart Yoder 
1071328c2bfSAndreas Färber static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len)
108921e28dbSAlexander Graf {
109921e28dbSAlexander Graf     return -1;
110921e28dbSAlexander Graf }
111921e28dbSAlexander Graf 
1121bc22652SAndreas Färber static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
113921e28dbSAlexander Graf {
114921e28dbSAlexander Graf     return -1;
115921e28dbSAlexander Graf }
116921e28dbSAlexander Graf 
117026bfd89SDavid Gibson static inline void kvmppc_enable_logical_ci_hcalls(void)
118026bfd89SDavid Gibson {
119026bfd89SDavid Gibson }
120026bfd89SDavid Gibson 
121ef9971ddSAlexey Kardashevskiy static inline void kvmppc_enable_set_mode_hcall(void)
122ef9971ddSAlexey Kardashevskiy {
123ef9971ddSAlexey Kardashevskiy }
124ef9971ddSAlexey Kardashevskiy 
1255145ad4fSNathan Whitehorn static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
1265145ad4fSNathan Whitehorn {
1275145ad4fSNathan Whitehorn }
1285145ad4fSNathan Whitehorn 
1291bc22652SAndreas Färber static inline void kvmppc_set_papr(PowerPCCPU *cpu)
130f61b4bedSAlexander Graf {
131f61b4bedSAlexander Graf }
132f61b4bedSAlexander Graf 
133d6e166c0SDavid Gibson static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr)
1346db5bb0fSAlexey Kardashevskiy {
1356db5bb0fSAlexey Kardashevskiy     return 0;
1366db5bb0fSAlexey Kardashevskiy }
1376db5bb0fSAlexey Kardashevskiy 
1385b95b8b9SAlexander Graf static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
1395b95b8b9SAlexander Graf {
1405b95b8b9SAlexander Graf }
1415b95b8b9SAlexander Graf 
142e97c3636SDavid Gibson static inline int kvmppc_smt_threads(void)
143e97c3636SDavid Gibson {
144e97c3636SDavid Gibson     return 1;
145e97c3636SDavid Gibson }
146e97c3636SDavid Gibson 
14731f2cb8fSBharat Bhushan static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
14831f2cb8fSBharat Bhushan {
14931f2cb8fSBharat Bhushan     return 0;
15031f2cb8fSBharat Bhushan }
15131f2cb8fSBharat Bhushan 
15231f2cb8fSBharat Bhushan static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
15331f2cb8fSBharat Bhushan {
15431f2cb8fSBharat Bhushan     return 0;
15531f2cb8fSBharat Bhushan }
15631f2cb8fSBharat Bhushan 
15731f2cb8fSBharat Bhushan static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
15831f2cb8fSBharat Bhushan {
15931f2cb8fSBharat Bhushan     return 0;
16031f2cb8fSBharat Bhushan }
16131f2cb8fSBharat Bhushan 
16231f2cb8fSBharat Bhushan static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
16331f2cb8fSBharat Bhushan {
16431f2cb8fSBharat Bhushan     return -1;
16531f2cb8fSBharat Bhushan }
16631f2cb8fSBharat Bhushan 
167b4db5413SSuraj Jitindar Singh static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
168b4db5413SSuraj Jitindar Singh                                      bool radix, bool gtse,
169b4db5413SSuraj Jitindar Singh                                      uint64_t proc_tbl)
170b4db5413SSuraj Jitindar Singh {
171b4db5413SSuraj Jitindar Singh     return 0;
172b4db5413SSuraj Jitindar Singh }
173b4db5413SSuraj Jitindar Singh 
17498efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY
175658fa66bSAlexey Kardashevskiy static inline off_t kvmppc_alloc_rma(void **rma)
176354ac20aSDavid Gibson {
177354ac20aSDavid Gibson     return 0;
178354ac20aSDavid Gibson }
179354ac20aSDavid Gibson 
180da95324eSAlexey Kardashevskiy static inline bool kvmppc_spapr_use_multitce(void)
181da95324eSAlexey Kardashevskiy {
182da95324eSAlexey Kardashevskiy     return false;
183da95324eSAlexey Kardashevskiy }
184da95324eSAlexey Kardashevskiy 
1853dc410aeSAlexey Kardashevskiy static inline int kvmppc_spapr_enable_inkernel_multitce(void)
1863dc410aeSAlexey Kardashevskiy {
1873dc410aeSAlexey Kardashevskiy     return -1;
1883dc410aeSAlexey Kardashevskiy }
1893dc410aeSAlexey Kardashevskiy 
190d6ee2a7cSAlexey Kardashevskiy static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
191d6ee2a7cSAlexey Kardashevskiy                                             uint64_t bus_offset,
192d6ee2a7cSAlexey Kardashevskiy                                             uint32_t nb_table,
193d6ee2a7cSAlexey Kardashevskiy                                             int *pfd, bool need_vfio)
1940f5cb298SDavid Gibson {
1950f5cb298SDavid Gibson     return NULL;
1960f5cb298SDavid Gibson }
1970f5cb298SDavid Gibson 
1980f5cb298SDavid Gibson static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
199523e7b8aSAlexey Kardashevskiy                                           uint32_t nb_table)
2000f5cb298SDavid Gibson {
2010f5cb298SDavid Gibson     return -1;
2020f5cb298SDavid Gibson }
2037f763a5dSDavid Gibson 
2047f763a5dSDavid Gibson static inline int kvmppc_reset_htab(int shift_hint)
2057f763a5dSDavid Gibson {
206a3166f8fSBharata B Rao     return 0;
2077f763a5dSDavid Gibson }
2087f763a5dSDavid Gibson 
2097f763a5dSDavid Gibson static inline uint64_t kvmppc_rma_size(uint64_t current_size,
2107f763a5dSDavid Gibson                                        unsigned int hash_shift)
2117f763a5dSDavid Gibson {
2127f763a5dSDavid Gibson     return ram_size;
2137f763a5dSDavid Gibson }
2147f763a5dSDavid Gibson 
215ec69355bSGreg Kurz static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
216df587133SThomas Huth {
217df587133SThomas Huth     return true;
218df587133SThomas Huth }
219df587133SThomas Huth 
22098efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */
2210f5cb298SDavid Gibson 
2223b961124SStuart Yoder static inline bool kvmppc_has_cap_epr(void)
2233b961124SStuart Yoder {
2243b961124SStuart Yoder     return false;
2253b961124SStuart Yoder }
226e68cb8b4SAlexey Kardashevskiy 
227feaa64c4SDavid Gibson static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
228feaa64c4SDavid Gibson                                                   const char *function)
229feaa64c4SDavid Gibson {
230feaa64c4SDavid Gibson     return -1;
231feaa64c4SDavid Gibson }
232feaa64c4SDavid Gibson 
2337c43bca0SAneesh Kumar K.V static inline bool kvmppc_has_cap_htab_fd(void)
2347c43bca0SAneesh Kumar K.V {
2357c43bca0SAneesh Kumar K.V     return false;
2367c43bca0SAneesh Kumar K.V }
2377c43bca0SAneesh Kumar K.V 
238e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_get_htab_fd(bool write)
239e68cb8b4SAlexey Kardashevskiy {
240e68cb8b4SAlexey Kardashevskiy     return -1;
241e68cb8b4SAlexey Kardashevskiy }
242e68cb8b4SAlexey Kardashevskiy 
243e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
244e68cb8b4SAlexey Kardashevskiy                                    int64_t max_ns)
245e68cb8b4SAlexey Kardashevskiy {
246e68cb8b4SAlexey Kardashevskiy     abort();
247e68cb8b4SAlexey Kardashevskiy }
248e68cb8b4SAlexey Kardashevskiy 
249e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
250e68cb8b4SAlexey Kardashevskiy                                          uint16_t n_valid, uint16_t n_invalid)
251e68cb8b4SAlexey Kardashevskiy {
252e68cb8b4SAlexey Kardashevskiy     abort();
253e68cb8b4SAlexey Kardashevskiy }
254e68cb8b4SAlexey Kardashevskiy 
2551ad9f0a4SDavid Gibson static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes,
2561ad9f0a4SDavid Gibson                                      hwaddr ptex, int n)
2577c43bca0SAneesh Kumar K.V {
2587c43bca0SAneesh Kumar K.V     abort();
2597c43bca0SAneesh Kumar K.V }
2607c43bca0SAneesh Kumar K.V 
2611ad9f0a4SDavid Gibson static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1)
262c1385933SAneesh Kumar K.V {
263c1385933SAneesh Kumar K.V     abort();
264c1385933SAneesh Kumar K.V }
265c1385933SAneesh Kumar K.V 
26687a91de6SAlexander Graf static inline bool kvmppc_has_cap_fixup_hcalls(void)
26787a91de6SAlexander Graf {
26887a91de6SAlexander Graf     abort();
26987a91de6SAlexander Graf }
27087a91de6SAlexander Graf 
271bac3bf28SThomas Huth static inline bool kvmppc_has_cap_htm(void)
272bac3bf28SThomas Huth {
273bac3bf28SThomas Huth     return false;
274bac3bf28SThomas Huth }
275bac3bf28SThomas Huth 
276cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_radix(void)
277cf1c4cceSSam Bobroff {
278cf1c4cceSSam Bobroff     return false;
279cf1c4cceSSam Bobroff }
280cf1c4cceSSam Bobroff 
281cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_hash_v3(void)
282cf1c4cceSSam Bobroff {
283cf1c4cceSSam Bobroff     return false;
284cf1c4cceSSam Bobroff }
285cf1c4cceSSam Bobroff 
2864d9392beSThomas Huth static inline int kvmppc_enable_hwrng(void)
2874d9392beSThomas Huth {
2884d9392beSThomas Huth     return -1;
2894d9392beSThomas Huth }
290e5c0d3ceSDavid Gibson 
291e5c0d3ceSDavid Gibson static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
292e5c0d3ceSDavid Gibson {
293e5c0d3ceSDavid Gibson     abort();
294e5c0d3ceSDavid Gibson }
29552b2519cSThomas Huth 
29652b2519cSThomas Huth static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
29752b2519cSThomas Huth {
29852b2519cSThomas Huth     return NULL;
29952b2519cSThomas Huth }
30052b2519cSThomas Huth 
301*30f4b05bSDavid Gibson static inline void kvmppc_check_papr_resize_hpt(Error **errp)
302*30f4b05bSDavid Gibson {
303*30f4b05bSDavid Gibson     return;
304*30f4b05bSDavid Gibson }
305921e28dbSAlexander Graf #endif
306921e28dbSAlexander Graf 
307b45d63b6SBen Herrenschmidt #ifndef CONFIG_KVM
3083240dd9aSThomas Huth 
309b45d63b6SBen Herrenschmidt #define kvmppc_eieio() do { } while (0)
3103240dd9aSThomas Huth 
3113240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3123240dd9aSThomas Huth {
3133240dd9aSThomas Huth }
3143240dd9aSThomas Huth 
3153240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3163240dd9aSThomas Huth {
3173240dd9aSThomas Huth }
3183240dd9aSThomas Huth 
3193240dd9aSThomas Huth #else   /* CONFIG_KVM */
3203240dd9aSThomas Huth 
321b45d63b6SBen Herrenschmidt #define kvmppc_eieio() \
322b45d63b6SBen Herrenschmidt     do {                                          \
323b45d63b6SBen Herrenschmidt         if (kvm_enabled()) {                          \
324b45d63b6SBen Herrenschmidt             asm volatile("eieio" : : : "memory"); \
325b45d63b6SBen Herrenschmidt         } \
326b45d63b6SBen Herrenschmidt     } while (0)
3273240dd9aSThomas Huth 
3283240dd9aSThomas Huth /* Store data cache blocks back to memory */
3293240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3303240dd9aSThomas Huth {
3313240dd9aSThomas Huth     uint8_t *p;
3323240dd9aSThomas Huth 
3333240dd9aSThomas Huth     for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
3343240dd9aSThomas Huth         asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
3353240dd9aSThomas Huth     }
3363240dd9aSThomas Huth }
3373240dd9aSThomas Huth 
3383240dd9aSThomas Huth /* Invalidate instruction cache blocks */
3393240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3403240dd9aSThomas Huth {
3413240dd9aSThomas Huth     uint8_t *p;
3423240dd9aSThomas Huth 
3433240dd9aSThomas Huth     for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
3443240dd9aSThomas Huth         asm volatile("icbi 0,%0" : : "r"(p));
3453240dd9aSThomas Huth     }
3463240dd9aSThomas Huth }
3473240dd9aSThomas Huth 
3483240dd9aSThomas Huth #endif  /* CONFIG_KVM */
349b45d63b6SBen Herrenschmidt 
3502a6a4076SMarkus Armbruster #endif /* KVM_PPC_H */
351