From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gregory Haskins Subject: [PATCH v7 2/2] qemu-kvm: add iofd support Date: Tue, 12 May 2009 14:32:32 -0400 Message-ID: <20090512183231.26356.81236.stgit@dev.haskins.net> References: <20090512183059.26356.94857.stgit@dev.haskins.net> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: avi@redhat.com To: kvm@vger.kernel.org Return-path: Received: from victor.provo.novell.com ([137.65.250.26]:59598 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752194AbZELSck (ORCPT ); Tue, 12 May 2009 14:32:40 -0400 In-Reply-To: <20090512183059.26356.94857.stgit@dev.haskins.net> Sender: kvm-owner@vger.kernel.org List-ID: An iofd allows an eventfd to attach to a specific PIO/MMIO region in the guest. Any guest-writes to that region will trigger an eventfd signal. Signed-off-by: Gregory Haskins --- kvm/libkvm/libkvm.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ kvm/libkvm/libkvm.h | 31 ++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-) diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c index 74a21a2..0139abd 100644 --- a/kvm/libkvm/libkvm.c +++ b/kvm/libkvm/libkvm.c @@ -1497,6 +1497,45 @@ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags) return r; } +int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, int type, int flags) +{ + int r; + struct kvm_iofd data = { + .addr = addr, + .len = len, + .fd = fd, + .flags = type ? KVM_IOFD_FLAG_PIO : 0, + }; + + if (!kvm_check_extension(kvm, KVM_CAP_EVENTFD)) + return -ENOENT; + + r = ioctl(kvm->vm_fd, KVM_IOFD, &data); + if (r == -1) + r = -errno; + return r; +} + +int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int type, int flags) +{ + int r; + struct kvm_iofd data = { + .addr = addr, + .len = len, + .flags = KVM_IOFD_FLAG_DEASSIGN | (type ? KVM_IOFD_FLAG_PIO : 0), + }; + + if (!kvm_check_extension(kvm, KVM_CAP_EVENTFD)) + return -ENOENT; + + r = ioctl(kvm->vm_fd, KVM_IOFD, &data); + if (r == -1) + r = -errno; + return r; +} + #else /* KVM_CAP_EVENTFD */ int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags) @@ -1509,4 +1548,17 @@ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags) return -ENOENT; } +int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, int type, int flags) +{ + return -ENOENT; +} + +int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int type, int flags) +{ + return -ENOENT; +} + #endif /* KVM_CAP_EVENTFD */ + diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h index 322b4cd..89c558a 100644 --- a/kvm/libkvm/libkvm.h +++ b/kvm/libkvm/libkvm.h @@ -881,6 +881,37 @@ int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags); */ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags); +/*! + * \brief Assign an eventfd to an IO port (PIO or MMIO) + * + * Assigns an eventfd based file-descriptor to a specific PIO or MMIO + * address range. Any guest writes to the specified range will generate + * an eventfd signal. + * + * \param kvm Pointer to the current kvm_context + * \param addr The IO address + * \param len The length of the IO region at the address + * \param fd The eventfd file-descriptor + * \param type MMIO=0, PIO=1 + * \param flags reserved, must be zero + */ +int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, int type, int flags); + +/*! + * \brief Deassign an iofd from a previously registered IO port + * + * Deassigns an iofd previously registered with kvm_assign_iofd() + * + * \param kvm Pointer to the current kvm_context + * \param addr The IO address + * \param len The length of the IO region at the address + * \param type MMIO=0, PIO=1 + * \param flags reserved, must be zero + */ +int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len, + int type, int flags); + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(kvm_context_t kvm, struct kvm_assigned_msix_nr *msix_nr);