[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH 3/4] Watchdog exit handling support
From: |
Bharat Bhushan |
Subject: |
[Qemu-ppc] [PATCH 3/4] Watchdog exit handling support |
Date: |
Thu, 28 Jun 2012 11:09:58 +0530 |
This patch adds the support to handle the exit caused by watchdog
(KVM_EXIT_WDT). In the handling we clear the TSR register.
Signed-off-by: Bharat Bhushan <address@hidden>
---
hw/ppc_booke.c | 5 +++++
linux-headers/linux/kvm.h | 1 +
target-ppc/cpu.h | 1 +
target-ppc/kvm.c | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/hw/ppc_booke.c b/hw/ppc_booke.c
index 837a5b6..a9fba15 100644
--- a/hw/ppc_booke.c
+++ b/hw/ppc_booke.c
@@ -203,6 +203,11 @@ static void booke_wdt_cb(void *opaque)
booke_timer->wdt_timer);
}
+void ppc_booke_wdt_clear_tsr(CPUPPCState *env, target_ulong tsr)
+{
+ env->spr[SPR_BOOKE_TSR] = tsr & ~(TSR_ENW | TSR_WIS | TSR_WRS_MASK);
+}
+
void store_booke_tsr(CPUPPCState *env, target_ulong val)
{
env->spr[SPR_BOOKE_TSR] &= ~val;
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 4b9e575..c1169ff 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -163,6 +163,7 @@ struct kvm_pit_config {
#define KVM_EXIT_OSI 18
#define KVM_EXIT_PAPR_HCALL 19
#define KVM_EXIT_S390_UCONTROL 20
+#define KVM_EXIT_WDT 21
/* For KVM_EXIT_INTERNAL_ERROR */
#define KVM_INTERNAL_ERROR_EMULATION 1
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index ca2fc21..78212b4 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1191,6 +1191,7 @@ void store_40x_dbcr0 (CPUPPCState *env, uint32_t val);
void store_40x_sler (CPUPPCState *env, uint32_t val);
void store_booke_tcr (CPUPPCState *env, target_ulong val);
void store_booke_tsr (CPUPPCState *env, target_ulong val);
+void ppc_booke_wdt_clear_tsr(CPUPPCState *env, target_ulong tsr);
void booke206_flush_tlb(CPUPPCState *env, int flags, const int check_iprot);
target_phys_addr_t booke206_tlb_to_page_size(CPUPPCState *env, ppcmas_tlb_t
*tlb);
int ppcmas_tlb_check(CPUPPCState *env, ppcmas_tlb_t *tlb,
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index b6ef72d..6a37e94 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -32,6 +32,7 @@
#include "device_tree.h"
#include "hw/sysbus.h"
#include "hw/spapr.h"
+#include "hw/watchdog.h"
#include "hw/sysbus.h"
#include "hw/spapr.h"
@@ -743,6 +744,37 @@ static int kvmppc_handle_dcr_write(CPUPPCState *env,
uint32_t dcrn, uint32_t dat
return 0;
}
+static int kvm_arch_handle_watchdog(CPUPPCState *env)
+{
+ int ret;
+ struct kvm_sregs sregs;
+
+ watchdog_perform_action();
+
+ /*
+ * Clear watchdog interrupt condition by clearing TSR.
+ * Similar logic needed to be implemented for watchdog emulation in qemu
+ */
+ if (cap_booke_sregs) {
+ ret = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ /* Clear TSR.ENW, TSR.WIS and TSR.WRS */
+ ppc_booke_wdt_clear_tsr(env, sregs.u.e.tsr);
+ sregs.u.e.tsr = env->spr[SPR_BOOKE_TSR];
+
+ sregs.u.e.update_special = KVM_SREGS_E_BASE | KVM_SREGS_E_UPDATE_TSR;
+ ret = kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int kvm_arch_handle_exit(CPUPPCState *env, struct kvm_run *run)
{
int ret;
@@ -769,6 +801,12 @@ int kvm_arch_handle_exit(CPUPPCState *env, struct kvm_run
*run)
ret = 1;
break;
#endif
+#ifdef KVM_EXIT_WDT
+ case KVM_EXIT_WDT:
+ dprintf("booke watchdog action\n");
+ ret = kvm_arch_handle_watchdog(env);
+ break;
+#endif
default:
fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
ret = -1;
--
1.7.0.4