mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
Enable kvm emulated watchdog
Enable the KVM emulated watchdog if KVM supports (use the capability enablement in watchdog handler). Also watchdog exit (KVM_EXIT_WATCHDOG) handling is added. Watchdog state machine is cleared whenever VM state changes to running. This is to handle the cases like return from debug halt etc. Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com> [agraf: rebase to current code base, fix non-kvm cases] Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
cae7f58641
commit
31f2cb8ff4
3 changed files with 139 additions and 4 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "hw/sysbus.h"
|
||||
#include "hw/ppc/spapr.h"
|
||||
#include "hw/ppc/spapr_vio.h"
|
||||
#include "sysemu/watchdog.h"
|
||||
|
||||
//#define DEBUG_KVM
|
||||
|
||||
|
@ -64,6 +65,7 @@ static int cap_spapr_tce;
|
|||
static int cap_hior;
|
||||
static int cap_one_reg;
|
||||
static int cap_epr;
|
||||
static int cap_ppc_watchdog;
|
||||
|
||||
/* XXX We have a race condition where we actually have a level triggered
|
||||
* interrupt, but the infrastructure can't expose that yet, so the guest
|
||||
|
@ -97,6 +99,7 @@ int kvm_arch_init(KVMState *s)
|
|||
cap_one_reg = kvm_check_extension(s, KVM_CAP_ONE_REG);
|
||||
cap_hior = kvm_check_extension(s, KVM_CAP_PPC_HIOR);
|
||||
cap_epr = kvm_check_extension(s, KVM_CAP_PPC_EPR);
|
||||
cap_ppc_watchdog = kvm_check_extension(s, KVM_CAP_PPC_BOOKE_WATCHDOG);
|
||||
|
||||
if (!cap_interrupt_level) {
|
||||
fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the "
|
||||
|
@ -1094,6 +1097,12 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
|
|||
run->epr.epr = ldl_phys(env->mpic_iack);
|
||||
ret = 0;
|
||||
break;
|
||||
case KVM_EXIT_WATCHDOG:
|
||||
dprintf("handle watchdog expiry\n");
|
||||
watchdog_perform_action();
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
|
||||
ret = -1;
|
||||
|
@ -1103,6 +1112,71 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
||||
{
|
||||
CPUState *cs = CPU(cpu);
|
||||
uint32_t bits = tsr_bits;
|
||||
struct kvm_one_reg reg = {
|
||||
.id = KVM_REG_PPC_OR_TSR,
|
||||
.addr = (uintptr_t) &bits,
|
||||
};
|
||||
|
||||
return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
|
||||
}
|
||||
|
||||
int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
||||
{
|
||||
|
||||
CPUState *cs = CPU(cpu);
|
||||
uint32_t bits = tsr_bits;
|
||||
struct kvm_one_reg reg = {
|
||||
.id = KVM_REG_PPC_CLEAR_TSR,
|
||||
.addr = (uintptr_t) &bits,
|
||||
};
|
||||
|
||||
return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
|
||||
}
|
||||
|
||||
int kvmppc_set_tcr(PowerPCCPU *cpu)
|
||||
{
|
||||
CPUState *cs = CPU(cpu);
|
||||
CPUPPCState *env = &cpu->env;
|
||||
uint32_t tcr = env->spr[SPR_BOOKE_TCR];
|
||||
|
||||
struct kvm_one_reg reg = {
|
||||
.id = KVM_REG_PPC_TCR,
|
||||
.addr = (uintptr_t) &tcr,
|
||||
};
|
||||
|
||||
return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
|
||||
}
|
||||
|
||||
int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
|
||||
{
|
||||
CPUState *cs = CPU(cpu);
|
||||
struct kvm_enable_cap encap = {};
|
||||
int ret;
|
||||
|
||||
if (!kvm_enabled()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!cap_ppc_watchdog) {
|
||||
printf("warning: KVM does not support watchdog");
|
||||
return -1;
|
||||
}
|
||||
|
||||
encap.cap = KVM_CAP_PPC_BOOKE_WATCHDOG;
|
||||
ret = kvm_vcpu_ioctl(cs, KVM_ENABLE_CAP, &encap);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "%s: couldn't enable KVM_CAP_PPC_BOOKE_WATCHDOG: %s\n",
|
||||
__func__, strerror(-ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_cpuinfo(const char *field, char *value, int len)
|
||||
{
|
||||
FILE *f;
|
||||
|
|
|
@ -25,6 +25,10 @@ int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
|
|||
void kvmppc_set_papr(PowerPCCPU *cpu);
|
||||
void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
|
||||
int kvmppc_smt_threads(void);
|
||||
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);
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
off_t kvmppc_alloc_rma(const char *name, MemoryRegion *sysmem);
|
||||
void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd);
|
||||
|
@ -90,6 +94,26 @@ static inline int kvmppc_smt_threads(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
static inline off_t kvmppc_alloc_rma(const char *name, MemoryRegion *sysmem)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue