From patchwork Tue Mar 2 18:43:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 46690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 979A7B7D48 for ; Wed, 3 Mar 2010 05:56:48 +1100 (EST) Received: from localhost ([127.0.0.1]:52572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmXFP-0001km-5d for incoming@patchwork.ozlabs.org; Tue, 02 Mar 2010 13:55:11 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmX7M-0005qv-FX for qemu-devel@nongnu.org; Tue, 02 Mar 2010 13:46:52 -0500 Received: from [199.232.76.173] (port=39592 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmX7L-0005qh-On for qemu-devel@nongnu.org; Tue, 02 Mar 2010 13:46:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmX7K-0003ow-7z for qemu-devel@nongnu.org; Tue, 02 Mar 2010 13:46:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3422) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NmX7J-0003os-RB for qemu-devel@nongnu.org; Tue, 02 Mar 2010 13:46:50 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o22IkmHI009925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Mar 2010 13:46:48 -0500 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o22Ikj6t002900; Tue, 2 Mar 2010 13:46:46 -0500 Date: Tue, 2 Mar 2010 20:43:27 +0200 From: "Michael S. Tsirkin" To: Anthony Liguori , qemu-devel@nongnu.org Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: amit.shah@redhat.com, kraxel@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCHv3 02/12] kvm: add API to set ioeventfd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Comment on kvm usage: rather than require users to do if (kvm_enabled()) and/or ifdefs, this patch adds an API that, internally, is defined to stub function on non-kvm build, and checks kvm_enabled for non-kvm run. While rest of qemu code still uses if (kvm_enabled()), I think this approach is cleaner, and we should convert rest of code to it long term. Signed-off-by: Michael S. Tsirkin --- kvm-all.c | 22 ++++++++++++++++++++++ kvm.h | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 1a02076..f54af71 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1138,3 +1138,25 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset) return r; } + +#ifdef KVM_IOEVENTFD +int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign) +{ + struct kvm_ioeventfd kick = { + .datamatch = val, + .addr = addr, + .len = 2, + .flags = KVM_IOEVENTFD_FLAG_DATAMATCH | KVM_IOEVENTFD_FLAG_PIO, + .fd = fd, + }; + int r; + if (!kvm_enabled()) + return -ENOSYS; + if (!assign) + kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN; + r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick); + if (r < 0) + return r; + return 0; +} +#endif diff --git a/kvm.h b/kvm.h index a74dfcb..45d087b 100644 --- a/kvm.h +++ b/kvm.h @@ -14,10 +14,16 @@ #ifndef QEMU_KVM_H #define QEMU_KVM_H +#include +#include #include "config.h" #include "qemu-queue.h" #ifdef CONFIG_KVM +#include +#endif + +#ifdef CONFIG_KVM extern int kvm_allowed; #define kvm_enabled() (kvm_allowed) @@ -135,4 +141,14 @@ static inline void cpu_synchronize_state(CPUState *env) } } +#if defined(KVM_IOEVENTFD) && defined(CONFIG_KVM) +int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); +#else +static inline +int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign) +{ + return -ENOSYS; +} +#endif + #endif