xref: /qemu/target/ppc/kvm_ppc.h (revision cf1c4cce7c0d53d2a778a4b124d02ea3a84f1663)
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);
3698efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY
37658fa66bSAlexey Kardashevskiy off_t kvmppc_alloc_rma(void **rma);
38da95324eSAlexey Kardashevskiy bool kvmppc_spapr_use_multitce(void);
39d6ee2a7cSAlexey Kardashevskiy void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
40d6ee2a7cSAlexey Kardashevskiy                               uint64_t bus_offset, uint32_t nb_table,
41d6ee2a7cSAlexey Kardashevskiy                               int *pfd, bool need_vfio);
420f5cb298SDavid Gibson int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
437f763a5dSDavid Gibson int kvmppc_reset_htab(int shift_hint);
447f763a5dSDavid Gibson uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
4598efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */
463b961124SStuart Yoder bool kvmppc_has_cap_epr(void);
47feaa64c4SDavid Gibson int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
487c43bca0SAneesh Kumar K.V bool kvmppc_has_cap_htab_fd(void);
49e68cb8b4SAlexey Kardashevskiy int kvmppc_get_htab_fd(bool write);
50e68cb8b4SAlexey Kardashevskiy int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
51e68cb8b4SAlexey Kardashevskiy int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
52e68cb8b4SAlexey Kardashevskiy                            uint16_t n_valid, uint16_t n_invalid);
531ad9f0a4SDavid Gibson void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n);
541ad9f0a4SDavid Gibson void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1);
5587a91de6SAlexander Graf bool kvmppc_has_cap_fixup_hcalls(void);
56bac3bf28SThomas Huth bool kvmppc_has_cap_htm(void);
57*cf1c4cceSSam Bobroff bool kvmppc_has_cap_mmu_radix(void);
58*cf1c4cceSSam Bobroff bool kvmppc_has_cap_mmu_hash_v3(void);
594d9392beSThomas Huth int kvmppc_enable_hwrng(void);
60e5c0d3ceSDavid Gibson int kvmppc_put_books_sregs(PowerPCCPU *cpu);
6152b2519cSThomas Huth PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
62c1385933SAneesh Kumar K.V 
63df587133SThomas Huth bool kvmppc_is_mem_backend_page_size_ok(char *obj_path);
64df587133SThomas Huth 
65921e28dbSAlexander Graf #else
66921e28dbSAlexander Graf 
67921e28dbSAlexander Graf static inline uint32_t kvmppc_get_tbfreq(void)
68921e28dbSAlexander Graf {
69921e28dbSAlexander Graf     return 0;
70921e28dbSAlexander Graf }
71921e28dbSAlexander Graf 
72ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_model(char **buf)
73ef951443SNikunj A Dadhania {
74ef951443SNikunj A Dadhania     return false;
75ef951443SNikunj A Dadhania }
76ef951443SNikunj A Dadhania 
77ef951443SNikunj A Dadhania static inline bool kvmppc_get_host_serial(char **buf)
78ef951443SNikunj A Dadhania {
79ef951443SNikunj A Dadhania     return false;
80ef951443SNikunj A Dadhania }
81ef951443SNikunj A Dadhania 
82921e28dbSAlexander Graf static inline uint64_t kvmppc_get_clockfreq(void)
83921e28dbSAlexander Graf {
84921e28dbSAlexander Graf     return 0;
85921e28dbSAlexander Graf }
86921e28dbSAlexander Graf 
876659394fSDavid Gibson static inline uint32_t kvmppc_get_vmx(void)
886659394fSDavid Gibson {
896659394fSDavid Gibson     return 0;
906659394fSDavid Gibson }
916659394fSDavid Gibson 
926659394fSDavid Gibson static inline uint32_t kvmppc_get_dfp(void)
936659394fSDavid Gibson {
946659394fSDavid Gibson     return 0;
956659394fSDavid Gibson }
966659394fSDavid Gibson 
971a61a9aeSStuart Yoder static inline int kvmppc_get_hasidle(CPUPPCState *env)
981a61a9aeSStuart Yoder {
991a61a9aeSStuart Yoder     return 0;
1001a61a9aeSStuart Yoder }
1011a61a9aeSStuart Yoder 
1021328c2bfSAndreas Färber static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len)
103921e28dbSAlexander Graf {
104921e28dbSAlexander Graf     return -1;
105921e28dbSAlexander Graf }
106921e28dbSAlexander Graf 
1071bc22652SAndreas Färber static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
108921e28dbSAlexander Graf {
109921e28dbSAlexander Graf     return -1;
110921e28dbSAlexander Graf }
111921e28dbSAlexander Graf 
112026bfd89SDavid Gibson static inline void kvmppc_enable_logical_ci_hcalls(void)
113026bfd89SDavid Gibson {
114026bfd89SDavid Gibson }
115026bfd89SDavid Gibson 
116ef9971ddSAlexey Kardashevskiy static inline void kvmppc_enable_set_mode_hcall(void)
117ef9971ddSAlexey Kardashevskiy {
118ef9971ddSAlexey Kardashevskiy }
119ef9971ddSAlexey Kardashevskiy 
1205145ad4fSNathan Whitehorn static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
1215145ad4fSNathan Whitehorn {
1225145ad4fSNathan Whitehorn }
1235145ad4fSNathan Whitehorn 
1241bc22652SAndreas Färber static inline void kvmppc_set_papr(PowerPCCPU *cpu)
125f61b4bedSAlexander Graf {
126f61b4bedSAlexander Graf }
127f61b4bedSAlexander Graf 
128d6e166c0SDavid Gibson static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr)
1296db5bb0fSAlexey Kardashevskiy {
1306db5bb0fSAlexey Kardashevskiy     return 0;
1316db5bb0fSAlexey Kardashevskiy }
1326db5bb0fSAlexey Kardashevskiy 
1335b95b8b9SAlexander Graf static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
1345b95b8b9SAlexander Graf {
1355b95b8b9SAlexander Graf }
1365b95b8b9SAlexander Graf 
137e97c3636SDavid Gibson static inline int kvmppc_smt_threads(void)
138e97c3636SDavid Gibson {
139e97c3636SDavid Gibson     return 1;
140e97c3636SDavid Gibson }
141e97c3636SDavid Gibson 
14231f2cb8fSBharat Bhushan static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
14331f2cb8fSBharat Bhushan {
14431f2cb8fSBharat Bhushan     return 0;
14531f2cb8fSBharat Bhushan }
14631f2cb8fSBharat Bhushan 
14731f2cb8fSBharat Bhushan static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
14831f2cb8fSBharat Bhushan {
14931f2cb8fSBharat Bhushan     return 0;
15031f2cb8fSBharat Bhushan }
15131f2cb8fSBharat Bhushan 
15231f2cb8fSBharat Bhushan static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
15331f2cb8fSBharat Bhushan {
15431f2cb8fSBharat Bhushan     return 0;
15531f2cb8fSBharat Bhushan }
15631f2cb8fSBharat Bhushan 
15731f2cb8fSBharat Bhushan static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
15831f2cb8fSBharat Bhushan {
15931f2cb8fSBharat Bhushan     return -1;
16031f2cb8fSBharat Bhushan }
16131f2cb8fSBharat Bhushan 
16298efaf75SDavid Gibson #ifndef CONFIG_USER_ONLY
163658fa66bSAlexey Kardashevskiy static inline off_t kvmppc_alloc_rma(void **rma)
164354ac20aSDavid Gibson {
165354ac20aSDavid Gibson     return 0;
166354ac20aSDavid Gibson }
167354ac20aSDavid Gibson 
168da95324eSAlexey Kardashevskiy static inline bool kvmppc_spapr_use_multitce(void)
169da95324eSAlexey Kardashevskiy {
170da95324eSAlexey Kardashevskiy     return false;
171da95324eSAlexey Kardashevskiy }
172da95324eSAlexey Kardashevskiy 
173d6ee2a7cSAlexey Kardashevskiy static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
174d6ee2a7cSAlexey Kardashevskiy                                             uint64_t bus_offset,
175d6ee2a7cSAlexey Kardashevskiy                                             uint32_t nb_table,
176d6ee2a7cSAlexey Kardashevskiy                                             int *pfd, bool need_vfio)
1770f5cb298SDavid Gibson {
1780f5cb298SDavid Gibson     return NULL;
1790f5cb298SDavid Gibson }
1800f5cb298SDavid Gibson 
1810f5cb298SDavid Gibson static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
182523e7b8aSAlexey Kardashevskiy                                           uint32_t nb_table)
1830f5cb298SDavid Gibson {
1840f5cb298SDavid Gibson     return -1;
1850f5cb298SDavid Gibson }
1867f763a5dSDavid Gibson 
1877f763a5dSDavid Gibson static inline int kvmppc_reset_htab(int shift_hint)
1887f763a5dSDavid Gibson {
189a3166f8fSBharata B Rao     return 0;
1907f763a5dSDavid Gibson }
1917f763a5dSDavid Gibson 
1927f763a5dSDavid Gibson static inline uint64_t kvmppc_rma_size(uint64_t current_size,
1937f763a5dSDavid Gibson                                        unsigned int hash_shift)
1947f763a5dSDavid Gibson {
1957f763a5dSDavid Gibson     return ram_size;
1967f763a5dSDavid Gibson }
1977f763a5dSDavid Gibson 
198df587133SThomas Huth static inline bool kvmppc_is_mem_backend_page_size_ok(char *obj_path)
199df587133SThomas Huth {
200df587133SThomas Huth     return true;
201df587133SThomas Huth }
202df587133SThomas Huth 
20398efaf75SDavid Gibson #endif /* !CONFIG_USER_ONLY */
2040f5cb298SDavid Gibson 
2053b961124SStuart Yoder static inline bool kvmppc_has_cap_epr(void)
2063b961124SStuart Yoder {
2073b961124SStuart Yoder     return false;
2083b961124SStuart Yoder }
209e68cb8b4SAlexey Kardashevskiy 
210feaa64c4SDavid Gibson static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
211feaa64c4SDavid Gibson                                                   const char *function)
212feaa64c4SDavid Gibson {
213feaa64c4SDavid Gibson     return -1;
214feaa64c4SDavid Gibson }
215feaa64c4SDavid Gibson 
2167c43bca0SAneesh Kumar K.V static inline bool kvmppc_has_cap_htab_fd(void)
2177c43bca0SAneesh Kumar K.V {
2187c43bca0SAneesh Kumar K.V     return false;
2197c43bca0SAneesh Kumar K.V }
2207c43bca0SAneesh Kumar K.V 
221e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_get_htab_fd(bool write)
222e68cb8b4SAlexey Kardashevskiy {
223e68cb8b4SAlexey Kardashevskiy     return -1;
224e68cb8b4SAlexey Kardashevskiy }
225e68cb8b4SAlexey Kardashevskiy 
226e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
227e68cb8b4SAlexey Kardashevskiy                                    int64_t max_ns)
228e68cb8b4SAlexey Kardashevskiy {
229e68cb8b4SAlexey Kardashevskiy     abort();
230e68cb8b4SAlexey Kardashevskiy }
231e68cb8b4SAlexey Kardashevskiy 
232e68cb8b4SAlexey Kardashevskiy static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
233e68cb8b4SAlexey Kardashevskiy                                          uint16_t n_valid, uint16_t n_invalid)
234e68cb8b4SAlexey Kardashevskiy {
235e68cb8b4SAlexey Kardashevskiy     abort();
236e68cb8b4SAlexey Kardashevskiy }
237e68cb8b4SAlexey Kardashevskiy 
2381ad9f0a4SDavid Gibson static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes,
2391ad9f0a4SDavid Gibson                                      hwaddr ptex, int n)
2407c43bca0SAneesh Kumar K.V {
2417c43bca0SAneesh Kumar K.V     abort();
2427c43bca0SAneesh Kumar K.V }
2437c43bca0SAneesh Kumar K.V 
2441ad9f0a4SDavid Gibson static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1)
245c1385933SAneesh Kumar K.V {
246c1385933SAneesh Kumar K.V     abort();
247c1385933SAneesh Kumar K.V }
248c1385933SAneesh Kumar K.V 
24987a91de6SAlexander Graf static inline bool kvmppc_has_cap_fixup_hcalls(void)
25087a91de6SAlexander Graf {
25187a91de6SAlexander Graf     abort();
25287a91de6SAlexander Graf }
25387a91de6SAlexander Graf 
254bac3bf28SThomas Huth static inline bool kvmppc_has_cap_htm(void)
255bac3bf28SThomas Huth {
256bac3bf28SThomas Huth     return false;
257bac3bf28SThomas Huth }
258bac3bf28SThomas Huth 
259*cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_radix(void)
260*cf1c4cceSSam Bobroff {
261*cf1c4cceSSam Bobroff     return false;
262*cf1c4cceSSam Bobroff }
263*cf1c4cceSSam Bobroff 
264*cf1c4cceSSam Bobroff static inline bool kvmppc_has_cap_mmu_hash_v3(void)
265*cf1c4cceSSam Bobroff {
266*cf1c4cceSSam Bobroff     return false;
267*cf1c4cceSSam Bobroff }
268*cf1c4cceSSam Bobroff 
2694d9392beSThomas Huth static inline int kvmppc_enable_hwrng(void)
2704d9392beSThomas Huth {
2714d9392beSThomas Huth     return -1;
2724d9392beSThomas Huth }
273e5c0d3ceSDavid Gibson 
274e5c0d3ceSDavid Gibson static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
275e5c0d3ceSDavid Gibson {
276e5c0d3ceSDavid Gibson     abort();
277e5c0d3ceSDavid Gibson }
27852b2519cSThomas Huth 
27952b2519cSThomas Huth static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
28052b2519cSThomas Huth {
28152b2519cSThomas Huth     return NULL;
28252b2519cSThomas Huth }
28352b2519cSThomas Huth 
284921e28dbSAlexander Graf #endif
285921e28dbSAlexander Graf 
286b45d63b6SBen Herrenschmidt #ifndef CONFIG_KVM
2873240dd9aSThomas Huth 
288b45d63b6SBen Herrenschmidt #define kvmppc_eieio() do { } while (0)
2893240dd9aSThomas Huth 
2903240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
2913240dd9aSThomas Huth {
2923240dd9aSThomas Huth }
2933240dd9aSThomas Huth 
2943240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
2953240dd9aSThomas Huth {
2963240dd9aSThomas Huth }
2973240dd9aSThomas Huth 
2983240dd9aSThomas Huth #else   /* CONFIG_KVM */
2993240dd9aSThomas Huth 
300b45d63b6SBen Herrenschmidt #define kvmppc_eieio() \
301b45d63b6SBen Herrenschmidt     do {                                          \
302b45d63b6SBen Herrenschmidt         if (kvm_enabled()) {                          \
303b45d63b6SBen Herrenschmidt             asm volatile("eieio" : : : "memory"); \
304b45d63b6SBen Herrenschmidt         } \
305b45d63b6SBen Herrenschmidt     } while (0)
3063240dd9aSThomas Huth 
3073240dd9aSThomas Huth /* Store data cache blocks back to memory */
3083240dd9aSThomas Huth static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3093240dd9aSThomas Huth {
3103240dd9aSThomas Huth     uint8_t *p;
3113240dd9aSThomas Huth 
3123240dd9aSThomas Huth     for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
3133240dd9aSThomas Huth         asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
3143240dd9aSThomas Huth     }
3153240dd9aSThomas Huth }
3163240dd9aSThomas Huth 
3173240dd9aSThomas Huth /* Invalidate instruction cache blocks */
3183240dd9aSThomas Huth static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
3193240dd9aSThomas Huth {
3203240dd9aSThomas Huth     uint8_t *p;
3213240dd9aSThomas Huth 
3223240dd9aSThomas Huth     for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
3233240dd9aSThomas Huth         asm volatile("icbi 0,%0" : : "r"(p));
3243240dd9aSThomas Huth     }
3253240dd9aSThomas Huth }
3263240dd9aSThomas Huth 
3273240dd9aSThomas Huth #endif  /* CONFIG_KVM */
328b45d63b6SBen Herrenschmidt 
3292a6a4076SMarkus Armbruster #endif /* KVM_PPC_H */
330