From patchwork Thu Jun 28 05:39:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 167793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C7C2A1007F0 for ; Thu, 28 Jun 2012 15:35:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598Ab2F1Ffl (ORCPT ); Thu, 28 Jun 2012 01:35:41 -0400 Received: from ch1ehsobe004.messaging.microsoft.com ([216.32.181.184]:49181 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751152Ab2F1Ffk (ORCPT ); Thu, 28 Jun 2012 01:35:40 -0400 Received: from mail2-ch1-R.bigfish.com (10.43.68.239) by CH1EHSOBE014.bigfish.com (10.43.70.64) with Microsoft SMTP Server id 14.1.225.23; Thu, 28 Jun 2012 05:33:55 +0000 Received: from mail2-ch1 (localhost [127.0.0.1]) by mail2-ch1-R.bigfish.com (Postfix) with ESMTP id C660E26021F; Thu, 28 Jun 2012 05:33:54 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VS3(zzzz1202h1082kzz8275bhz2dh2a8h668h839he5bhf0ah) Received: from mail2-ch1 (localhost.localdomain [127.0.0.1]) by mail2-ch1 (MessageSwitch) id 134086163241524_19212; Thu, 28 Jun 2012 05:33:52 +0000 (UTC) Received: from CH1EHSMHS002.bigfish.com (snatpool2.int.messaging.microsoft.com [10.43.68.238]) by mail2-ch1.bigfish.com (Postfix) with ESMTP id 08A0B200044; Thu, 28 Jun 2012 05:33:52 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS002.bigfish.com (10.43.70.2) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 28 Jun 2012 05:33:52 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.298.5; Thu, 28 Jun 2012 00:35:36 -0500 Received: from freescale.com ([10.232.15.72]) by az84smr01.freescale.net (8.14.3/8.14.0) with SMTP id q5S5ZWBU028185; Wed, 27 Jun 2012 22:35:33 -0700 Received: by freescale.com (sSMTP sendmail emulation); Thu, 28 Jun 2012 11:10:10 +0530 From: Bharat Bhushan To: , , CC: Bharat Bhushan , Bharat Bhushan Subject: [PATCH 3/4] Watchdog exit handling support Date: Thu, 28 Jun 2012 11:09:58 +0530 Message-ID: <1340861999-31281-3-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1340861999-31281-1-git-send-email-Bharat.Bhushan@freescale.com> References: <1340861999-31281-1-git-send-email-Bharat.Bhushan@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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 --- 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;