From patchwork Wed Apr 21 17:53:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cam Macdonell X-Patchwork-Id: 50663 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 CD4D3B6EEB for ; Thu, 22 Apr 2010 04:01:34 +1000 (EST) Received: from localhost ([127.0.0.1]:46559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4eCe-0001UK-Id for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2010 13:59:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4e7d-0006WO-Fe for qemu-devel@nongnu.org; Wed, 21 Apr 2010 13:54:01 -0400 Received: from [140.186.70.92] (port=34455 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4e7X-0006SY-O7 for qemu-devel@nongnu.org; Wed, 21 Apr 2010 13:54:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4e7L-000238-M0 for qemu-devel@nongnu.org; Wed, 21 Apr 2010 13:53:55 -0400 Received: from fleet.cs.ualberta.ca ([129.128.22.22]:58900) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4e7L-00020x-Dg for qemu-devel@nongnu.org; Wed, 21 Apr 2010 13:53:43 -0400 Received: from localhost.localdomain (st-brides.cs.ualberta.ca [129.128.23.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.cs.ualberta.ca (Postfix) with ESMTP id 2FF332801F; Wed, 21 Apr 2010 11:53:32 -0600 (MDT) From: Cam Macdonell To: kvm@vger.kernel.org Date: Wed, 21 Apr 2010 11:53:27 -0600 Message-Id: <1271872408-22842-4-git-send-email-cam@cs.ualberta.ca> X-Mailer: git-send-email 1.6.2.5 In-Reply-To: <1271872408-22842-3-git-send-email-cam@cs.ualberta.ca> References: <1271872408-22842-1-git-send-email-cam@cs.ualberta.ca> <1271872408-22842-2-git-send-email-cam@cs.ualberta.ca> <1271872408-22842-3-git-send-email-cam@cs.ualberta.ca> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Cam Macdonell , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v5 3/5] Add functions for assigning ioeventfd and irqfds. 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 Generic functions to assign irqfds and ioeventfds. --- kvm-all.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ kvm.h | 14 ++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index fb8d4b8..d5c7775 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1193,6 +1193,50 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset) } #ifdef KVM_IOEVENTFD +int kvm_set_irqfd(int fd, uint16_t vector, uint32_t gsi) +{ + struct kvm_irqfd call = { }; + int r; + + call.fd = fd; + call.gsi = gsi; + + if (!kvm_enabled()) + return -ENOSYS; + r = kvm_vm_ioctl(kvm_state, KVM_IRQFD, &call); + + if (r < 0) { + return r; + } + return 0; +} + +int kvm_set_ioeventfd_mmio_long(int fd, uint32_t addr, uint32_t val, bool assign) +{ + + int ret; + struct kvm_ioeventfd iofd; + + iofd.datamatch = val; + iofd.addr = addr; + iofd.len = 4; + iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH; + iofd.fd = fd; + + if (!kvm_enabled()) + return -ENOSYS; + if (!assign) + iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN; + + ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &iofd); + + if (ret < 0) { + return ret; + } + + return 0; +} + int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign) { struct kvm_ioeventfd kick = { diff --git a/kvm.h b/kvm.h index c63e314..831d68f 100644 --- a/kvm.h +++ b/kvm.h @@ -174,9 +174,23 @@ static inline void cpu_synchronize_post_init(CPUState *env) } #if defined(KVM_IOEVENTFD) && defined(CONFIG_KVM) +int kvm_set_irqfd(int fd, uint16_t vector, uint32_t gsi); +int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign); int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); #else static inline +int kvm_set_irqfd(PCIDevice* pdev, uint16_t vector, int fd) +{ + return -ENOSYS; +} + +static inline +int kvm_set_ioeventfd_mmio_long(int fd, uint16_t adr, uint16_t val, bool assign) +{ + return -ENOSYS; +} + +static inline int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign) { return -ENOSYS;