2013-03-05 08:34:42 +08:00
|
|
|
/*
|
|
|
|
* QEMU KVM support -- ARM specific functions.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Linaro Limited
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_KVM_ARM_H
|
|
|
|
#define QEMU_KVM_ARM_H
|
|
|
|
|
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "exec/memory.h"
|
2016-10-04 20:28:08 +08:00
|
|
|
#include "qemu/error-report.h"
|
2013-03-05 08:34:42 +08:00
|
|
|
|
2014-06-20 01:06:26 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_vcpu_init:
|
|
|
|
* @cs: CPUState
|
|
|
|
*
|
|
|
|
* Initialize (or reinitialize) the VCPU by invoking the
|
|
|
|
* KVM_ARM_VCPU_INIT ioctl with the CPU type and feature
|
|
|
|
* bitmask specified in the CPUState.
|
|
|
|
*
|
|
|
|
* Returns: 0 if success else < 0 error code
|
|
|
|
*/
|
|
|
|
int kvm_arm_vcpu_init(CPUState *cs);
|
|
|
|
|
2013-03-05 08:34:42 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_register_device:
|
|
|
|
* @mr: memory region for this device
|
|
|
|
* @devid: the KVM device ID
|
2014-02-27 01:20:00 +08:00
|
|
|
* @group: device control API group for setting addresses
|
|
|
|
* @attr: device control API address type
|
|
|
|
* @dev_fd: device control device file descriptor (or -1 if not supported)
|
2013-03-05 08:34:42 +08:00
|
|
|
*
|
|
|
|
* Remember the memory region @mr, and when it is mapped by the
|
|
|
|
* machine model, tell the kernel that base address using the
|
2014-02-27 01:20:00 +08:00
|
|
|
* KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid
|
|
|
|
* should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or
|
|
|
|
* the arm-vgic device in the device control API.
|
|
|
|
* The machine model may map
|
|
|
|
* and unmap the device multiple times; the kernel will only be told the final
|
|
|
|
* address at the point where machine init is complete.
|
2013-03-05 08:34:42 +08:00
|
|
|
*/
|
2014-02-27 01:20:00 +08:00
|
|
|
void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group,
|
|
|
|
uint64_t attr, int dev_fd);
|
2013-03-05 08:34:42 +08:00
|
|
|
|
2014-12-11 20:07:53 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_init_cpreg_list:
|
|
|
|
* @cs: CPUState
|
|
|
|
*
|
|
|
|
* Initialize the CPUState's cpreg list according to the kernel's
|
|
|
|
* definition of what CPU registers it knows about (and throw away
|
|
|
|
* the previous TCG-created cpreg list).
|
|
|
|
*
|
|
|
|
* Returns: 0 if success, else < 0 error code
|
|
|
|
*/
|
|
|
|
int kvm_arm_init_cpreg_list(ARMCPU *cpu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_reg_syncs_via_cpreg_list
|
|
|
|
* regidx: KVM register index
|
|
|
|
*
|
|
|
|
* Return true if this KVM register should be synchronized via the
|
|
|
|
* cpreg list of arbitrary system registers, false if it is synchronized
|
|
|
|
* by hand using code in kvm_arch_get/put_registers().
|
|
|
|
*/
|
|
|
|
bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx);
|
|
|
|
|
2015-07-21 18:18:45 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_cpreg_level
|
|
|
|
* regidx: KVM register index
|
|
|
|
*
|
|
|
|
* Return the level of this coprocessor/system register. Return value is
|
|
|
|
* either KVM_PUT_RUNTIME_STATE, KVM_PUT_RESET_STATE, or KVM_PUT_FULL_STATE.
|
|
|
|
*/
|
|
|
|
int kvm_arm_cpreg_level(uint64_t regidx);
|
|
|
|
|
2013-06-26 01:16:07 +08:00
|
|
|
/**
|
|
|
|
* write_list_to_kvmstate:
|
|
|
|
* @cpu: ARMCPU
|
2015-07-21 18:18:45 +08:00
|
|
|
* @level: the state level to sync
|
2013-06-26 01:16:07 +08:00
|
|
|
*
|
|
|
|
* For each register listed in the ARMCPU cpreg_indexes list, write
|
|
|
|
* its value from the cpreg_values list into the kernel (via ioctl).
|
|
|
|
* This updates KVM's working data structures from TCG data or
|
|
|
|
* from incoming migration state.
|
|
|
|
*
|
|
|
|
* Returns: true if all register values were updated correctly,
|
|
|
|
* false if some register was unknown to the kernel or could not
|
|
|
|
* be written (eg constant register with the wrong value).
|
|
|
|
* Note that we do not stop early on failure -- we will attempt
|
|
|
|
* writing all registers in the list.
|
|
|
|
*/
|
2015-07-21 18:18:45 +08:00
|
|
|
bool write_list_to_kvmstate(ARMCPU *cpu, int level);
|
2013-06-26 01:16:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* write_kvmstate_to_list:
|
|
|
|
* @cpu: ARMCPU
|
|
|
|
*
|
|
|
|
* For each register listed in the ARMCPU cpreg_indexes list, write
|
|
|
|
* its value from the kernel into the cpreg_values list. This is used to
|
|
|
|
* copy info from KVM's working data structures into TCG or
|
|
|
|
* for outbound migration.
|
|
|
|
*
|
|
|
|
* Returns: true if all register values were read correctly,
|
|
|
|
* false if some register was unknown or could not be read.
|
|
|
|
* Note that we do not stop early on failure -- we will attempt
|
|
|
|
* reading all registers in the list.
|
|
|
|
*/
|
|
|
|
bool write_kvmstate_to_list(ARMCPU *cpu);
|
|
|
|
|
2013-03-20 20:11:56 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_reset_vcpu:
|
|
|
|
* @cpu: ARMCPU
|
|
|
|
*
|
|
|
|
* Called at reset time to kernel registers to their initial values.
|
|
|
|
*/
|
|
|
|
void kvm_arm_reset_vcpu(ARMCPU *cpu);
|
|
|
|
|
2013-11-23 01:17:17 +08:00
|
|
|
#ifdef CONFIG_KVM
|
|
|
|
/**
|
|
|
|
* kvm_arm_create_scratch_host_vcpu:
|
|
|
|
* @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
|
|
|
|
* QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
|
2016-03-31 00:27:24 +08:00
|
|
|
* know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing
|
|
|
|
* an empty array.
|
2013-11-23 01:17:17 +08:00
|
|
|
* @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
|
2016-03-31 00:27:24 +08:00
|
|
|
* @init: filled in with the necessary values for creating a host
|
|
|
|
* vcpu. If NULL is provided, will not init the vCPU (though the cpufd
|
|
|
|
* will still be set up).
|
2013-11-23 01:17:17 +08:00
|
|
|
*
|
|
|
|
* Create a scratch vcpu in its own VM of the type preferred by the host
|
|
|
|
* kernel (as would be used for '-cpu host'), for purposes of probing it
|
|
|
|
* for capabilities.
|
|
|
|
*
|
|
|
|
* Returns: true on success (and fdarray and init are filled in),
|
|
|
|
* false on failure (and fdarray and init are not valid).
|
|
|
|
*/
|
|
|
|
bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
|
|
|
|
int *fdarray,
|
|
|
|
struct kvm_vcpu_init *init);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_destroy_scratch_host_vcpu:
|
|
|
|
* @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
|
|
|
|
*
|
|
|
|
* Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
|
|
|
|
*/
|
|
|
|
void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
|
|
|
|
|
|
|
|
#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
|
|
|
|
#define ARM_HOST_CPU_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(ARMHostCPUClass, (klass), TYPE_ARM_HOST_CPU)
|
|
|
|
#define ARM_HOST_CPU_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(ARMHostCPUClass, (obj), TYPE_ARM_HOST_CPU)
|
|
|
|
|
|
|
|
typedef struct ARMHostCPUClass {
|
|
|
|
/*< private >*/
|
|
|
|
ARMCPUClass parent_class;
|
|
|
|
/*< public >*/
|
|
|
|
|
|
|
|
uint64_t features;
|
|
|
|
uint32_t target;
|
|
|
|
const char *dtb_compatible;
|
|
|
|
} ARMHostCPUClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_get_host_cpu_features:
|
|
|
|
* @ahcc: ARMHostCPUClass to fill in
|
|
|
|
*
|
|
|
|
* Probe the capabilities of the host kernel's preferred CPU and fill
|
|
|
|
* in the ARMHostCPUClass struct accordingly.
|
|
|
|
*/
|
|
|
|
bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc);
|
|
|
|
|
2015-04-02 00:57:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_sync_mpstate_to_kvm
|
|
|
|
* @cpu: ARMCPU
|
|
|
|
*
|
|
|
|
* If supported set the KVM MP_STATE based on QEMU's model.
|
|
|
|
*/
|
|
|
|
int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_sync_mpstate_to_qemu
|
|
|
|
* @cpu: ARMCPU
|
|
|
|
*
|
|
|
|
* If supported get the MP_STATE from KVM and store in QEMU's model.
|
|
|
|
*/
|
|
|
|
int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
|
|
|
|
|
2015-09-24 08:29:37 +08:00
|
|
|
int kvm_arm_vgic_probe(void);
|
|
|
|
|
2017-09-04 22:21:54 +08:00
|
|
|
void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
|
|
|
|
void kvm_arm_pmu_init(CPUState *cs);
|
2016-06-14 22:59:12 +08:00
|
|
|
|
2015-09-24 08:29:37 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline int kvm_arm_vgic_probe(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-04 22:21:54 +08:00
|
|
|
static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) {}
|
|
|
|
static inline void kvm_arm_pmu_init(CPUState *cs) {}
|
2016-06-14 22:59:12 +08:00
|
|
|
|
2013-11-23 01:17:17 +08:00
|
|
|
#endif
|
|
|
|
|
2015-08-13 18:26:21 +08:00
|
|
|
static inline const char *gic_class_name(void)
|
|
|
|
{
|
|
|
|
return kvm_irqchip_in_kernel() ? "kvm-arm-gic" : "arm_gic";
|
|
|
|
}
|
|
|
|
|
2015-09-24 08:29:37 +08:00
|
|
|
/**
|
|
|
|
* gicv3_class_name
|
|
|
|
*
|
|
|
|
* Return name of GICv3 class to use depending on whether KVM acceleration is
|
|
|
|
* in use. May throw an error if the chosen implementation is not available.
|
|
|
|
*
|
|
|
|
* Returns: class name to use
|
|
|
|
*/
|
2016-10-04 20:28:08 +08:00
|
|
|
static inline const char *gicv3_class_name(void)
|
|
|
|
{
|
|
|
|
if (kvm_irqchip_in_kernel()) {
|
|
|
|
#ifdef TARGET_AARCH64
|
|
|
|
return "kvm-arm-gicv3";
|
|
|
|
#else
|
|
|
|
error_report("KVM GICv3 acceleration is not supported on this "
|
|
|
|
"platform");
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
return "arm-gicv3";
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 08:29:37 +08:00
|
|
|
|
2015-12-17 21:37:15 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_handle_debug:
|
|
|
|
* @cs: CPUState
|
|
|
|
* @debug_exit: debug part of the KVM exit structure
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the debug exception was handled.
|
|
|
|
*/
|
|
|
|
bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit);
|
|
|
|
|
2015-12-17 21:37:15 +08:00
|
|
|
/**
|
|
|
|
* kvm_arm_hw_debug_active:
|
|
|
|
* @cs: CPU State
|
|
|
|
*
|
|
|
|
* Return: TRUE if any hardware breakpoints in use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool kvm_arm_hw_debug_active(CPUState *cs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kvm_arm_copy_hw_debug_data:
|
|
|
|
*
|
|
|
|
* @ptr: kvm_guest_debug_arch structure
|
|
|
|
*
|
|
|
|
* Copy the architecture specific debug registers into the
|
|
|
|
* kvm_guest_debug ioctl structure.
|
|
|
|
*/
|
|
|
|
struct kvm_guest_debug_arch;
|
|
|
|
|
|
|
|
void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr);
|
|
|
|
|
2016-10-04 20:28:08 +08:00
|
|
|
/**
|
|
|
|
* its_class_name
|
|
|
|
*
|
|
|
|
* Return the ITS class name to use depending on whether KVM acceleration
|
|
|
|
* and KVM CAP_SIGNAL_MSI are supported
|
|
|
|
*
|
|
|
|
* Returns: class name to use or NULL
|
|
|
|
*/
|
|
|
|
static inline const char *its_class_name(void)
|
|
|
|
{
|
|
|
|
if (kvm_irqchip_in_kernel()) {
|
|
|
|
/* KVM implementation requires this capability */
|
|
|
|
return kvm_direct_msi_enabled() ? "arm-its-kvm" : NULL;
|
|
|
|
} else {
|
|
|
|
/* Software emulation is not implemented yet */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 08:34:42 +08:00
|
|
|
#endif
|