From patchwork Thu Jun 28 05:39:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 167794 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 B822B1008E8 for ; Thu, 28 Jun 2012 15:35:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751741Ab2F1Ffr (ORCPT ); Thu, 28 Jun 2012 01:35:47 -0400 Received: from ch1ehsobe006.messaging.microsoft.com ([216.32.181.186]:25546 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751682Ab2F1Ffr (ORCPT ); Thu, 28 Jun 2012 01:35:47 -0400 Received: from mail40-ch1-R.bigfish.com (10.43.68.236) by CH1EHSOBE017.bigfish.com (10.43.70.67) with Microsoft SMTP Server id 14.1.225.23; Thu, 28 Jun 2012 05:34:00 +0000 Received: from mail40-ch1 (localhost [127.0.0.1]) by mail40-ch1-R.bigfish.com (Postfix) with ESMTP id 84DB926005D; Thu, 28 Jun 2012 05:34:00 +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: 6 X-BigFish: VS6(zz853kzz1202h1082kzz8275bhz2dh2a8h668h839he5bhf0ah) Received: from mail40-ch1 (localhost.localdomain [127.0.0.1]) by mail40-ch1 (MessageSwitch) id 1340861639288913_20397; Thu, 28 Jun 2012 05:33:59 +0000 (UTC) Received: from CH1EHSMHS027.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.241]) by mail40-ch1.bigfish.com (Postfix) with ESMTP id 3A8F62A0046; Thu, 28 Jun 2012 05:33:59 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS027.bigfish.com (10.43.70.27) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 28 Jun 2012 05:33:59 +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:41 -0500 Received: from freescale.com ([10.232.15.72]) by az84smr01.freescale.net (8.14.3/8.14.0) with SMTP id q5S5ZaNj028236; Wed, 27 Jun 2012 22:35:38 -0700 Received: by freescale.com (sSMTP sendmail emulation); Thu, 28 Jun 2012 11:10:14 +0530 From: Bharat Bhushan To: , , CC: Bharat Bhushan , Bharat Bhushan Subject: [PATCH 4/4] Enable to use kvm emulated watchdog Date: Thu, 28 Jun 2012 11:09:59 +0530 Message-ID: <1340861999-31281-4-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 enable KVM emulated watchdog if KVM supports (use the capability enablement in watchdog handler). Signed-off-by: Bharat Bhushan --- linux-headers/linux/kvm.h | 1 + target-ppc/kvm.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletions(-) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index c1169ff..8a149db 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -619,6 +619,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_PPC_GET_SMMU_INFO 78 #define KVM_CAP_S390_COW 79 #define KVM_CAP_PPC_ALLOC_HTAB 80 +#define KVM_CAP_PPC_WDT 81 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 6a37e94..52f00b5 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -61,6 +61,7 @@ static int cap_booke_sregs; static int cap_ppc_smt; static int cap_ppc_rma; static int cap_spapr_tce; +static int cap_ppc_wdt; /* 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 @@ -87,6 +88,7 @@ int kvm_arch_init(KVMState *s) cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT); cap_ppc_rma = kvm_check_extension(s, KVM_CAP_PPC_RMA); cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE); + cap_ppc_wdt = kvm_check_extension(s, KVM_CAP_PPC_WDT); if (!cap_interrupt_level) { fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the " @@ -169,6 +171,25 @@ static int kvm_booke206_tlb_init(CPUPPCState *env) return 0; } +static int kvm_wdt_enable(CPUPPCState *env) +{ + int ret; + struct kvm_enable_cap encap = {}; + + if (!kvm_enabled() || !cap_ppc_wdt) { + return 0; + } + + encap.cap = KVM_CAP_PPC_WDT; + ret = kvm_vcpu_ioctl(env, KVM_ENABLE_CAP, &encap); + if (ret < 0) { + fprintf(stderr, "%s: couldn't enable KVM_CAP_PPC_WDT: %s\n", + __func__, strerror(-ret)); + return ret; + } + + return ret; +} #if defined(TARGET_PPC64) static void kvm_get_fallback_smmu_info(CPUPPCState *env, @@ -385,6 +406,11 @@ int kvm_arch_init_vcpu(CPUPPCState *cenv) return ret; } + ret = kvm_wdt_enable(cenv); + if (ret) { + return ret; + } + idle_timer = qemu_new_timer_ns(vm_clock, kvm_kick_env, cenv); /* Some targets support access to KVM's guest TLB. */ @@ -755,7 +781,7 @@ static int kvm_arch_handle_watchdog(CPUPPCState *env) * Clear watchdog interrupt condition by clearing TSR. * Similar logic needed to be implemented for watchdog emulation in qemu */ - if (cap_booke_sregs) { + if (cap_booke_sregs && cap_ppc_wdt) { ret = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); if (ret < 0) { return ret;