From patchwork Tue Mar 17 03:50:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 12534 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2H3pZdB014488 for ; Tue, 17 Mar 2009 03:51:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762718AbZCQDu0 (ORCPT ); Mon, 16 Mar 2009 23:50:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762693AbZCQDuY (ORCPT ); Mon, 16 Mar 2009 23:50:24 -0400 Received: from mga01.intel.com ([192.55.52.88]:8708 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762678AbZCQDuW (ORCPT ); Mon, 16 Mar 2009 23:50:22 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 16 Mar 2009 20:42:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.38,375,1233561600"; d="scan'208";a="673489737" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.189]) by fmsmga001.fm.intel.com with ESMTP; 16 Mar 2009 20:54:06 -0700 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1LjQJl-0007HH-NL; Tue, 17 Mar 2009 11:50:17 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti , Anthony Liguori Cc: kvm@vger.kernel.org, Marcelo Tosatti , Sheng Yang Subject: [PATCH 01/16] kvm: ioctl for KVM_ASSIGN_DEV_IRQ and KVM_DEASSIGN_DEV_IRQ Date: Tue, 17 Mar 2009 11:50:02 +0800 Message-Id: <1237261817-27955-2-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.5.6.3 In-Reply-To: <1237261817-27955-1-git-send-email-sheng@linux.intel.com> References: <1237261817-27955-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marcelo Tosatti Signed-off-by: Marcelo Tosatti Signed-off-by: Sheng Yang --- libkvm/libkvm.c | 38 +++++++++++++++++++++++++++++++++++++- libkvm/libkvm.h | 21 +++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c index 7c65f31..f13cc03 100644 --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -1146,7 +1146,7 @@ int kvm_assign_pci_device(kvm_context_t kvm, return ret; } -int kvm_assign_irq(kvm_context_t kvm, +static int kvm_old_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq) { int ret; @@ -1157,6 +1157,42 @@ int kvm_assign_irq(kvm_context_t kvm, return ret; } + +#ifdef KVM_CAP_ASSIGN_DEV_IRQ +int kvm_assign_irq(kvm_context_t kvm, + struct kvm_assigned_irq *assigned_irq) +{ + int ret; + + ret = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_ASSIGN_DEV_IRQ); + if (ret > 0) { + ret = ioctl(kvm->vm_fd, KVM_ASSIGN_DEV_IRQ, assigned_irq); + if (ret < 0) + return -errno; + return ret; + } + + return kvm_old_assign_irq(kvm, assigned_irq); +} + +int kvm_deassign_irq(kvm_context_t kvm, + struct kvm_assigned_irq *assigned_irq) +{ + int ret; + + ret = ioctl(kvm->vm_fd, KVM_DEASSIGN_DEV_IRQ, assigned_irq); + if (ret < 0) + return -errno; + + return ret; +} +#else +int kvm_assign_irq(kvm_context_t kvm, + struct kvm_assigned_irq *assigned_irq) +{ + return kvm_old_assign_irq(kvm, assigned_irq); +} +#endif #endif #ifdef KVM_CAP_DEVICE_DEASSIGNMENT diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h index 0239cb6..3e5efe0 100644 --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -715,11 +715,10 @@ int kvm_assign_pci_device(kvm_context_t kvm, struct kvm_assigned_pci_dev *assigned_dev); /*! - * \brief Notifies host kernel about changes to IRQ for an assigned device + * \brief Assign IRQ for an assigned device * - * Used for PCI device assignment, this function notifies the host - * kernel about the changes in IRQ number for an assigned physical - * PCI device. + * Used for PCI device assignment, this function assigns IRQ numbers for + * an physical device and guest IRQ handling. * * \param kvm Pointer to the current kvm_context * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc @@ -727,6 +726,20 @@ int kvm_assign_pci_device(kvm_context_t kvm, int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq); +#ifdef KVM_CAP_ASSIGN_DEV_IRQ +/*! + * \brief Deassign IRQ for an assigned device + * + * Used for PCI device assignment, this function deassigns IRQ numbers + * for an assigned device. + * + * \param kvm Pointer to the current kvm_context + * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc + */ +int kvm_deassign_irq(kvm_context_t kvm, + struct kvm_assigned_irq *assigned_irq); +#endif + /*! * \brief Determines whether destroying memory regions is allowed *