2008-12-16 13:43:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2008 IBM Corporation.
|
|
|
|
* Authors: Hollis Blanchard <hollisb@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the GNU GPL license version 2 or later.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __KVM_PPC_H__
|
|
|
|
#define __KVM_PPC_H__
|
|
|
|
|
2013-01-06 12:31:30 +04:00
|
|
|
#define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU
|
|
|
|
|
2011-07-21 04:54:51 +04:00
|
|
|
#ifdef CONFIG_KVM
|
|
|
|
|
2010-02-09 19:37:05 +03:00
|
|
|
uint32_t kvmppc_get_tbfreq(void);
|
2011-07-21 04:29:15 +04:00
|
|
|
uint64_t kvmppc_get_clockfreq(void);
|
pseries: Add device tree properties for VMX/VSX and DFP under kvm
Sufficiently recent PAPR specifications define properties "ibm,vmx"
and "ibm,dfp" on the CPU node which advertise whether the VMX vector
extensions (or the later VSX version) and/or the Decimal Floating
Point operations from IBM's recent POWER CPUs are available.
Currently we do not put these in the guest device tree and the guest
kernel will consequently assume they are not available. This is good,
because they are not supported under TCG. VMX is similar enough to
Altivec that it might be trivial to support, but VSX and DFP would
both require significant work to support in TCG.
However, when running under kvm on a host which supports these
instructions, there's no reason not to let the guest use them. This
patch, therefore, checks for the relevant support on the host CPU
and, if present, advertises them to the guest as well.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-10-10 22:31:01 +04:00
|
|
|
uint32_t kvmppc_get_vmx(void);
|
|
|
|
uint32_t kvmppc_get_dfp(void);
|
2014-07-09 14:38:37 +04:00
|
|
|
bool kvmppc_get_host_model(char **buf);
|
|
|
|
bool kvmppc_get_host_serial(char **buf);
|
2013-01-03 16:37:02 +04:00
|
|
|
int kvmppc_get_hasidle(CPUPPCState *env);
|
2012-03-14 04:38:22 +04:00
|
|
|
int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
|
2012-10-31 09:06:49 +04:00
|
|
|
int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
|
2015-05-07 08:33:59 +03:00
|
|
|
void kvmppc_enable_logical_ci_hcalls(void);
|
2015-09-08 04:25:13 +03:00
|
|
|
void kvmppc_enable_set_mode_hcall(void);
|
2012-10-31 09:06:49 +04:00
|
|
|
void kvmppc_set_papr(PowerPCCPU *cpu);
|
2014-05-23 06:26:58 +04:00
|
|
|
int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
|
2013-01-17 14:54:38 +04:00
|
|
|
void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
|
2011-09-30 01:39:10 +04:00
|
|
|
int kvmppc_smt_threads(void);
|
2013-02-24 22:16:21 +04:00
|
|
|
int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
|
int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
|
int kvmppc_set_tcr(PowerPCCPU *cpu);
|
|
|
|
int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
|
2011-10-23 21:25:04 +04:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2014-07-10 19:03:41 +04:00
|
|
|
off_t kvmppc_alloc_rma(void **rma);
|
2014-05-27 09:36:30 +04:00
|
|
|
bool kvmppc_spapr_use_multitce(void);
|
2014-06-10 09:39:21 +04:00
|
|
|
void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd,
|
2015-09-30 06:42:55 +03:00
|
|
|
bool need_vfio);
|
2011-09-30 01:39:12 +04:00
|
|
|
int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
|
2012-09-12 20:57:12 +04:00
|
|
|
int kvmppc_reset_htab(int shift_hint);
|
|
|
|
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
|
2011-10-23 21:25:04 +04:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
2013-03-30 10:40:49 +04:00
|
|
|
bool kvmppc_has_cap_epr(void);
|
2013-09-26 10:18:35 +04:00
|
|
|
int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
|
2014-02-20 21:52:24 +04:00
|
|
|
bool kvmppc_has_cap_htab_fd(void);
|
2013-07-18 23:33:03 +04:00
|
|
|
int kvmppc_get_htab_fd(bool write);
|
|
|
|
int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
|
|
|
|
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
|
|
|
|
uint16_t n_valid, uint16_t n_invalid);
|
2014-02-20 21:52:24 +04:00
|
|
|
uint64_t kvmppc_hash64_read_pteg(PowerPCCPU *cpu, target_ulong pte_index);
|
|
|
|
void kvmppc_hash64_free_pteg(uint64_t token);
|
2010-08-30 15:49:15 +04:00
|
|
|
|
2014-02-20 21:52:38 +04:00
|
|
|
void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index,
|
|
|
|
target_ulong pte0, target_ulong pte1);
|
2014-06-04 14:14:08 +04:00
|
|
|
bool kvmppc_has_cap_fixup_hcalls(void);
|
ppc/spapr: Implement H_RANDOM hypercall in QEMU
The PAPR interface defines a hypercall to pass high-quality
hardware generated random numbers to guests. Recent kernels can
already provide this hypercall to the guest if the right hardware
random number generator is available. But in case the user wants
to use another source like EGD, or QEMU is running with an older
kernel, we should also have this call in QEMU, so that guests that
do not support virtio-rng yet can get good random numbers, too.
This patch now adds a new pseudo-device to QEMU that either
directly provides this hypercall to the guest or is able to
enable the in-kernel hypercall if available. The in-kernel
hypercall can be enabled with the use-kvm property, e.g.:
qemu-system-ppc64 -device spapr-rng,use-kvm=true
For handling the hypercall in QEMU instead, a "RngBackend" is
required since the hypercall should provide "good" random data
instead of pseudo-random (like from a "simple" library function
like rand() or g_random_int()). Since there are multiple RngBackends
available, the user must select an appropriate back-end via the
"rng" property of the device, e.g.:
qemu-system-ppc64 -object rng-random,filename=/dev/hwrng,id=gid0 \
-device spapr-rng,rng=gid0 ...
See http://wiki.qemu-project.org/Features-Done/VirtIORNG for
other example of specifying RngBackends.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-17 11:49:41 +03:00
|
|
|
int kvmppc_enable_hwrng(void);
|
2016-03-08 03:33:46 +03:00
|
|
|
int kvmppc_put_books_sregs(PowerPCCPU *cpu);
|
2014-02-20 21:52:38 +04:00
|
|
|
|
2011-07-21 04:54:51 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline uint32_t kvmppc_get_tbfreq(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-09 14:38:37 +04:00
|
|
|
static inline bool kvmppc_get_host_model(char **buf)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool kvmppc_get_host_serial(char **buf)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-21 04:54:51 +04:00
|
|
|
static inline uint64_t kvmppc_get_clockfreq(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
pseries: Add device tree properties for VMX/VSX and DFP under kvm
Sufficiently recent PAPR specifications define properties "ibm,vmx"
and "ibm,dfp" on the CPU node which advertise whether the VMX vector
extensions (or the later VSX version) and/or the Decimal Floating
Point operations from IBM's recent POWER CPUs are available.
Currently we do not put these in the guest device tree and the guest
kernel will consequently assume they are not available. This is good,
because they are not supported under TCG. VMX is similar enough to
Altivec that it might be trivial to support, but VSX and DFP would
both require significant work to support in TCG.
However, when running under kvm on a host which supports these
instructions, there's no reason not to let the guest use them. This
patch, therefore, checks for the relevant support on the host CPU
and, if present, advertises them to the guest as well.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-10-10 22:31:01 +04:00
|
|
|
static inline uint32_t kvmppc_get_vmx(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t kvmppc_get_dfp(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-03 16:37:02 +04:00
|
|
|
static inline int kvmppc_get_hasidle(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len)
|
2011-07-21 04:54:51 +04:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:06:49 +04:00
|
|
|
static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
|
2011-07-21 04:54:51 +04:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:33:59 +03:00
|
|
|
static inline void kvmppc_enable_logical_ci_hcalls(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-08 04:25:13 +03:00
|
|
|
static inline void kvmppc_enable_set_mode_hcall(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:06:49 +04:00
|
|
|
static inline void kvmppc_set_papr(PowerPCCPU *cpu)
|
2011-08-09 19:57:37 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-23 06:26:58 +04:00
|
|
|
static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-17 14:54:38 +04:00
|
|
|
static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-30 01:39:10 +04:00
|
|
|
static inline int kvmppc_smt_threads(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-24 22:16:21 +04:00
|
|
|
static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-23 21:25:04 +04:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2014-07-10 19:03:41 +04:00
|
|
|
static inline off_t kvmppc_alloc_rma(void **rma)
|
2011-09-30 01:39:11 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-27 09:36:30 +04:00
|
|
|
static inline bool kvmppc_spapr_use_multitce(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-30 01:39:12 +04:00
|
|
|
static inline void *kvmppc_create_spapr_tce(uint32_t liobn,
|
2014-06-10 09:39:21 +04:00
|
|
|
uint32_t window_size, int *fd,
|
2016-05-04 09:52:21 +03:00
|
|
|
bool need_vfio)
|
2011-09-30 01:39:12 +04:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
|
2014-05-27 09:36:35 +04:00
|
|
|
uint32_t nb_table)
|
2011-09-30 01:39:12 +04:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 20:57:12 +04:00
|
|
|
|
|
|
|
static inline int kvmppc_reset_htab(int shift_hint)
|
|
|
|
{
|
2015-11-10 08:24:53 +03:00
|
|
|
return 0;
|
2012-09-12 20:57:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t kvmppc_rma_size(uint64_t current_size,
|
|
|
|
unsigned int hash_shift)
|
|
|
|
{
|
|
|
|
return ram_size;
|
|
|
|
}
|
|
|
|
|
2011-10-23 21:25:04 +04:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
2011-09-30 01:39:12 +04:00
|
|
|
|
2013-03-30 10:40:49 +04:00
|
|
|
static inline bool kvmppc_has_cap_epr(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-18 23:33:03 +04:00
|
|
|
|
2013-09-26 10:18:35 +04:00
|
|
|
static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
|
|
|
|
const char *function)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:52:24 +04:00
|
|
|
static inline bool kvmppc_has_cap_htab_fd(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:33:03 +04:00
|
|
|
static inline int kvmppc_get_htab_fd(bool write)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
|
|
|
|
int64_t max_ns)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
|
|
|
|
uint16_t n_valid, uint16_t n_invalid)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:52:24 +04:00
|
|
|
static inline uint64_t kvmppc_hash64_read_pteg(PowerPCCPU *cpu,
|
|
|
|
target_ulong pte_index)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kvmppc_hash64_free_pteg(uint64_t token)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:52:38 +04:00
|
|
|
static inline void kvmppc_hash64_write_pte(CPUPPCState *env,
|
|
|
|
target_ulong pte_index,
|
|
|
|
target_ulong pte0, target_ulong pte1)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2014-06-04 14:14:08 +04:00
|
|
|
static inline bool kvmppc_has_cap_fixup_hcalls(void)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
ppc/spapr: Implement H_RANDOM hypercall in QEMU
The PAPR interface defines a hypercall to pass high-quality
hardware generated random numbers to guests. Recent kernels can
already provide this hypercall to the guest if the right hardware
random number generator is available. But in case the user wants
to use another source like EGD, or QEMU is running with an older
kernel, we should also have this call in QEMU, so that guests that
do not support virtio-rng yet can get good random numbers, too.
This patch now adds a new pseudo-device to QEMU that either
directly provides this hypercall to the guest or is able to
enable the in-kernel hypercall if available. The in-kernel
hypercall can be enabled with the use-kvm property, e.g.:
qemu-system-ppc64 -device spapr-rng,use-kvm=true
For handling the hypercall in QEMU instead, a "RngBackend" is
required since the hypercall should provide "good" random data
instead of pseudo-random (like from a "simple" library function
like rand() or g_random_int()). Since there are multiple RngBackends
available, the user must select an appropriate back-end via the
"rng" property of the device, e.g.:
qemu-system-ppc64 -object rng-random,filename=/dev/hwrng,id=gid0 \
-device spapr-rng,rng=gid0 ...
See http://wiki.qemu-project.org/Features-Done/VirtIORNG for
other example of specifying RngBackends.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-17 11:49:41 +03:00
|
|
|
static inline int kvmppc_enable_hwrng(void)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-08 03:33:46 +03:00
|
|
|
|
|
|
|
static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
2011-07-21 04:54:51 +04:00
|
|
|
#endif
|
|
|
|
|
2011-04-01 08:15:30 +04:00
|
|
|
#ifndef CONFIG_KVM
|
2016-02-18 12:15:54 +03:00
|
|
|
|
2011-04-01 08:15:30 +04:00
|
|
|
#define kvmppc_eieio() do { } while (0)
|
2016-02-18 12:15:54 +03:00
|
|
|
|
|
|
|
static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_KVM */
|
|
|
|
|
2011-04-01 08:15:30 +04:00
|
|
|
#define kvmppc_eieio() \
|
|
|
|
do { \
|
|
|
|
if (kvm_enabled()) { \
|
|
|
|
asm volatile("eieio" : : : "memory"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2016-02-18 12:15:54 +03:00
|
|
|
|
|
|
|
/* Store data cache blocks back to memory */
|
|
|
|
static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
|
|
|
|
asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalidate instruction cache blocks */
|
|
|
|
static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
|
|
|
|
asm volatile("icbi 0,%0" : : "r"(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_KVM */
|
2011-04-01 08:15:30 +04:00
|
|
|
|
2010-08-30 15:49:15 +04:00
|
|
|
#ifndef KVM_INTERRUPT_SET
|
|
|
|
#define KVM_INTERRUPT_SET -1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef KVM_INTERRUPT_UNSET
|
|
|
|
#define KVM_INTERRUPT_UNSET -2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef KVM_INTERRUPT_SET_LEVEL
|
|
|
|
#define KVM_INTERRUPT_SET_LEVEL -3
|
|
|
|
#endif
|
2010-02-09 19:37:05 +03:00
|
|
|
|
2008-12-16 13:43:58 +03:00
|
|
|
#endif /* __KVM_PPC_H__ */
|