blob: 4d2789eef6efaf58c4d1c12042fa64bf0079a883 [file] [log] [blame]
aurel32d76d1652008-12-16 10:43:58 +00001/*
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
Markus Armbruster2a6a4072016-06-29 13:47:03 +02009#ifndef KVM_PPC_H
10#define KVM_PPC_H
aurel32d76d1652008-12-16 10:43:58 +000011
Igor Mammedovc9137062017-08-30 15:24:29 +020012#define TYPE_HOST_POWERPC_CPU POWERPC_CPU_TYPE_NAME("host")
Andreas Färber2985b862013-01-06 08:31:30 +000013
Alexander Graf921e28d2011-07-21 02:54:51 +020014#ifdef CONFIG_KVM
15
Alexander Grafdc333cd2010-02-09 17:37:05 +010016uint32_t kvmppc_get_tbfreq(void);
Alexander Grafeadaada2011-07-21 02:29:15 +020017uint64_t kvmppc_get_clockfreq(void);
Nikunj A Dadhaniaef951442014-07-09 16:08:37 +053018bool kvmppc_get_host_model(char **buf);
19bool kvmppc_get_host_serial(char **buf);
Stuart Yoder1a61a9a2013-01-03 12:37:02 +000020int kvmppc_get_hasidle(CPUPPCState *env);
Andreas Färber1328c2b2012-03-14 01:38:22 +010021int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
Andreas Färber1bc22652012-10-31 06:06:49 +010022int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
David Gibson026bfd82015-05-07 15:33:59 +100023void kvmppc_enable_logical_ci_hcalls(void);
Alexey Kardashevskiyef9971d2015-09-08 11:25:13 +100024void kvmppc_enable_set_mode_hcall(void);
Nathan Whitehorn5145ad42016-08-30 01:02:47 +000025void kvmppc_enable_clear_ref_mod_hcalls(void);
Andreas Färber1bc22652012-10-31 06:06:49 +010026void kvmppc_set_papr(PowerPCCPU *cpu);
David Gibsond6e166c2016-10-28 22:09:37 +110027int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
Alexander Graf5b95b8b2013-01-17 11:54:38 +010028void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
David Gibsone97c3632011-09-29 21:39:10 +000029int kvmppc_smt_threads(void);
Sam Bobrofffa98fbf2017-08-18 15:50:22 +100030void kvmppc_hint_smt_possible(Error **errp);
31int kvmppc_set_smt_threads(int smt);
Bharat Bhushan31f2cb82013-02-24 18:16:21 +000032int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
33int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
34int kvmppc_set_tcr(PowerPCCPU *cpu);
35int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
Suraj Jitindar Singhb4db5412017-03-20 10:46:46 +110036target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
37 bool radix, bool gtse,
38 uint64_t proc_tbl);
David Gibson98efaf72011-10-23 17:25:04 +000039#ifndef CONFIG_USER_ONLY
Alexey Kardashevskiy658fa662014-07-11 01:03:41 +100040off_t kvmppc_alloc_rma(void **rma);
Alexey Kardashevskiyda953242014-05-27 15:36:30 +100041bool kvmppc_spapr_use_multitce(void);
Alexey Kardashevskiy3dc410a2017-03-27 16:22:19 +110042int kvmppc_spapr_enable_inkernel_multitce(void);
Alexey Kardashevskiyd6ee2a72017-03-10 12:41:13 +110043void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
44 uint64_t bus_offset, uint32_t nb_table,
45 int *pfd, bool need_vfio);
David Gibson0f5cb292011-09-29 21:39:12 +000046int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
David Gibson7f763a52012-09-12 16:57:12 +000047int kvmppc_reset_htab(int shift_hint);
48uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
Alexey Kardashevskiy9ded7802018-02-06 11:08:24 -070049bool kvmppc_has_cap_spapr_vfio(void);
David Gibson98efaf72011-10-23 17:25:04 +000050#endif /* !CONFIG_USER_ONLY */
Stuart Yoder3b961122013-03-30 06:40:49 +000051bool kvmppc_has_cap_epr(void);
David Gibsonfeaa64c2013-09-26 16:18:35 +100052int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
Greg Kurz14b0d742017-09-15 15:16:20 +020053int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp);
Alexey Kardashevskiye68cb8b2013-07-18 14:33:03 -050054int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
55int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
56 uint16_t n_valid, uint16_t n_invalid);
David Gibson1ad9f0a2017-02-27 15:34:19 +110057void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n);
58void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1);
Alexander Graf87a91de2014-06-04 12:14:08 +020059bool kvmppc_has_cap_fixup_hcalls(void);
Thomas Huthbac3bf22016-09-28 13:16:30 +020060bool kvmppc_has_cap_htm(void);
Sam Bobroffcf1c4cc2017-03-20 10:46:44 +110061bool kvmppc_has_cap_mmu_radix(void);
62bool kvmppc_has_cap_mmu_hash_v3(void);
Suraj Jitindar Singh8acc2ae2018-01-19 15:59:59 +110063int kvmppc_get_cap_safe_cache(void);
64int kvmppc_get_cap_safe_bounds_check(void);
65int kvmppc_get_cap_safe_indirect_branch(void);
Thomas Huth4d9392b2015-09-17 10:49:41 +020066int kvmppc_enable_hwrng(void);
David Gibsone5c0d3c2016-03-08 11:33:46 +110067int kvmppc_put_books_sregs(PowerPCCPU *cpu);
Thomas Huth52b25192016-06-07 17:39:38 +020068PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
David Gibson30f4b052017-05-12 15:46:11 +100069void kvmppc_check_papr_resize_hpt(Error **errp);
David Gibsonb55d2952017-07-12 17:56:55 +100070int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shift);
71int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shift);
Daniel Henrique Barbozac363a372017-08-09 17:43:46 -030072bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu);
Aneesh Kumar K.Vc1385932014-02-20 18:52:38 +010073
Greg Kurzec693552017-06-06 18:12:24 +020074bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path);
Thomas Huthdf587132017-02-15 10:21:44 +010075
Alexander Graf921e28d2011-07-21 02:54:51 +020076#else
77
78static inline uint32_t kvmppc_get_tbfreq(void)
79{
80 return 0;
81}
82
Nikunj A Dadhaniaef951442014-07-09 16:08:37 +053083static inline bool kvmppc_get_host_model(char **buf)
84{
85 return false;
86}
87
88static inline bool kvmppc_get_host_serial(char **buf)
89{
90 return false;
91}
92
Alexander Graf921e28d2011-07-21 02:54:51 +020093static inline uint64_t kvmppc_get_clockfreq(void)
94{
95 return 0;
96}
97
David Gibson66593942011-10-10 18:31:01 +000098static inline uint32_t kvmppc_get_vmx(void)
99{
100 return 0;
101}
102
103static inline uint32_t kvmppc_get_dfp(void)
104{
105 return 0;
106}
107
Stuart Yoder1a61a9a2013-01-03 12:37:02 +0000108static inline int kvmppc_get_hasidle(CPUPPCState *env)
109{
110 return 0;
111}
112
Andreas Färber1328c2b2012-03-14 01:38:22 +0100113static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len)
Alexander Graf921e28d2011-07-21 02:54:51 +0200114{
115 return -1;
116}
117
Andreas Färber1bc22652012-10-31 06:06:49 +0100118static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
Alexander Graf921e28d2011-07-21 02:54:51 +0200119{
120 return -1;
121}
122
David Gibson026bfd82015-05-07 15:33:59 +1000123static inline void kvmppc_enable_logical_ci_hcalls(void)
124{
125}
126
Alexey Kardashevskiyef9971d2015-09-08 11:25:13 +1000127static inline void kvmppc_enable_set_mode_hcall(void)
128{
129}
130
Nathan Whitehorn5145ad42016-08-30 01:02:47 +0000131static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
132{
133}
134
Andreas Färber1bc22652012-10-31 06:06:49 +0100135static inline void kvmppc_set_papr(PowerPCCPU *cpu)
Alexander Graff61b4be2011-08-09 17:57:37 +0200136{
137}
138
David Gibsond6e166c2016-10-28 22:09:37 +1100139static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr)
Alexey Kardashevskiy6db5bb02014-05-23 12:26:58 +1000140{
141 return 0;
142}
143
Alexander Graf5b95b8b2013-01-17 11:54:38 +0100144static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
145{
146}
147
David Gibsone97c3632011-09-29 21:39:10 +0000148static inline int kvmppc_smt_threads(void)
149{
150 return 1;
151}
152
Sam Bobrofffa98fbf2017-08-18 15:50:22 +1000153static inline void kvmppc_hint_smt_possible(Error **errp)
154{
155 return;
156}
157
158static inline int kvmppc_set_smt_threads(int smt)
159{
160 return 0;
161}
162
Bharat Bhushan31f2cb82013-02-24 18:16:21 +0000163static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
164{
165 return 0;
166}
167
168static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
169{
170 return 0;
171}
172
173static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
174{
175 return 0;
176}
177
178static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
179{
180 return -1;
181}
182
Suraj Jitindar Singhb4db5412017-03-20 10:46:46 +1100183static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
184 bool radix, bool gtse,
185 uint64_t proc_tbl)
186{
187 return 0;
188}
189
David Gibson98efaf72011-10-23 17:25:04 +0000190#ifndef CONFIG_USER_ONLY
Alexey Kardashevskiy658fa662014-07-11 01:03:41 +1000191static inline off_t kvmppc_alloc_rma(void **rma)
David Gibson354ac202011-09-29 21:39:11 +0000192{
193 return 0;
194}
195
Alexey Kardashevskiyda953242014-05-27 15:36:30 +1000196static inline bool kvmppc_spapr_use_multitce(void)
197{
198 return false;
199}
200
Alexey Kardashevskiy3dc410a2017-03-27 16:22:19 +1100201static inline int kvmppc_spapr_enable_inkernel_multitce(void)
202{
203 return -1;
204}
205
Alexey Kardashevskiyd6ee2a72017-03-10 12:41:13 +1100206static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
207 uint64_t bus_offset,
208 uint32_t nb_table,
209 int *pfd, bool need_vfio)
David Gibson0f5cb292011-09-29 21:39:12 +0000210{
211 return NULL;
212}
213
214static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
Alexey Kardashevskiy523e7b82014-05-27 15:36:35 +1000215 uint32_t nb_table)
David Gibson0f5cb292011-09-29 21:39:12 +0000216{
217 return -1;
218}
David Gibson7f763a52012-09-12 16:57:12 +0000219
220static inline int kvmppc_reset_htab(int shift_hint)
221{
Bharata B Raoa3166f82015-11-10 10:54:53 +0530222 return 0;
David Gibson7f763a52012-09-12 16:57:12 +0000223}
224
225static inline uint64_t kvmppc_rma_size(uint64_t current_size,
226 unsigned int hash_shift)
227{
228 return ram_size;
229}
230
Greg Kurzec693552017-06-06 18:12:24 +0200231static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
Thomas Huthdf587132017-02-15 10:21:44 +0100232{
233 return true;
234}
235
Alexey Kardashevskiy9ded7802018-02-06 11:08:24 -0700236static inline bool kvmppc_has_cap_spapr_vfio(void)
237{
238 return false;
239}
240
David Gibson98efaf72011-10-23 17:25:04 +0000241#endif /* !CONFIG_USER_ONLY */
David Gibson0f5cb292011-09-29 21:39:12 +0000242
Stuart Yoder3b961122013-03-30 06:40:49 +0000243static inline bool kvmppc_has_cap_epr(void)
244{
245 return false;
246}
Alexey Kardashevskiye68cb8b2013-07-18 14:33:03 -0500247
David Gibsonfeaa64c2013-09-26 16:18:35 +1000248static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
249 const char *function)
250{
251 return -1;
252}
253
Greg Kurz14b0d742017-09-15 15:16:20 +0200254static inline int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp)
Alexey Kardashevskiye68cb8b2013-07-18 14:33:03 -0500255{
256 return -1;
257}
258
259static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
260 int64_t max_ns)
261{
262 abort();
263}
264
265static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
266 uint16_t n_valid, uint16_t n_invalid)
267{
268 abort();
269}
270
David Gibson1ad9f0a2017-02-27 15:34:19 +1100271static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes,
272 hwaddr ptex, int n)
Aneesh Kumar K.V7c43bca2014-02-20 18:52:24 +0100273{
274 abort();
275}
276
David Gibson1ad9f0a2017-02-27 15:34:19 +1100277static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1)
Aneesh Kumar K.Vc1385932014-02-20 18:52:38 +0100278{
279 abort();
280}
281
Alexander Graf87a91de2014-06-04 12:14:08 +0200282static inline bool kvmppc_has_cap_fixup_hcalls(void)
283{
284 abort();
285}
286
Thomas Huthbac3bf22016-09-28 13:16:30 +0200287static inline bool kvmppc_has_cap_htm(void)
288{
289 return false;
290}
291
Sam Bobroffcf1c4cc2017-03-20 10:46:44 +1100292static inline bool kvmppc_has_cap_mmu_radix(void)
293{
294 return false;
295}
296
297static inline bool kvmppc_has_cap_mmu_hash_v3(void)
298{
299 return false;
300}
301
Suraj Jitindar Singh8acc2ae2018-01-19 15:59:59 +1100302static inline int kvmppc_get_cap_safe_cache(void)
303{
304 return 0;
305}
306
307static inline int kvmppc_get_cap_safe_bounds_check(void)
308{
309 return 0;
310}
311
312static inline int kvmppc_get_cap_safe_indirect_branch(void)
313{
314 return 0;
315}
316
Thomas Huth4d9392b2015-09-17 10:49:41 +0200317static inline int kvmppc_enable_hwrng(void)
318{
319 return -1;
320}
David Gibsone5c0d3c2016-03-08 11:33:46 +1100321
322static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
323{
324 abort();
325}
Thomas Huth52b25192016-06-07 17:39:38 +0200326
327static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
328{
329 return NULL;
330}
331
David Gibson30f4b052017-05-12 15:46:11 +1000332static inline void kvmppc_check_papr_resize_hpt(Error **errp)
333{
334 return;
335}
David Gibsonb55d2952017-07-12 17:56:55 +1000336
337static inline int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu,
338 target_ulong flags, int shift)
339{
340 return -ENOSYS;
341}
342
343static inline int kvmppc_resize_hpt_commit(PowerPCCPU *cpu,
344 target_ulong flags, int shift)
345{
346 return -ENOSYS;
347}
348
Alexander Graf921e28d2011-07-21 02:54:51 +0200349#endif
350
Ben Herrenschmidtb45d63b2011-04-01 15:15:30 +1100351#ifndef CONFIG_KVM
Thomas Huth3240dd92016-02-18 10:15:54 +0100352
Ben Herrenschmidtb45d63b2011-04-01 15:15:30 +1100353#define kvmppc_eieio() do { } while (0)
Thomas Huth3240dd92016-02-18 10:15:54 +0100354
355static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
356{
357}
358
359static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
360{
361}
362
363#else /* CONFIG_KVM */
364
Ben Herrenschmidtb45d63b2011-04-01 15:15:30 +1100365#define kvmppc_eieio() \
366 do { \
367 if (kvm_enabled()) { \
368 asm volatile("eieio" : : : "memory"); \
369 } \
370 } while (0)
Thomas Huth3240dd92016-02-18 10:15:54 +0100371
372/* Store data cache blocks back to memory */
373static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
374{
375 uint8_t *p;
376
377 for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
378 asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
379 }
380}
381
382/* Invalidate instruction cache blocks */
383static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
384{
385 uint8_t *p;
386
387 for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
388 asm volatile("icbi 0,%0" : : "r"(p));
389 }
390}
391
392#endif /* CONFIG_KVM */
Ben Herrenschmidtb45d63b2011-04-01 15:15:30 +1100393
Markus Armbruster2a6a4072016-06-29 13:47:03 +0200394#endif /* KVM_PPC_H */