An iosignalfd 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.

For more details, see the kernel side patches submitted here:

http://lkml.org/lkml/2009/5/15/303

Signed-off-by: Gregory Haskins <ghask...@novell.com>
---

 kvm/libkvm/libkvm.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 kvm/libkvm/libkvm.h |   39 +++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
index ccab985..dc3414f 100644
--- a/kvm/libkvm/libkvm.c
+++ b/kvm/libkvm/libkvm.c
@@ -1501,3 +1501,71 @@ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int 
gsi, int flags)
 }
 
 #endif /* KVM_CAP_IRQFD */
+
+#ifdef KVM_CAP_IOSIGNALFD
+
+int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                         unsigned long addr, size_t len,
+                         int fd, int flags)
+{
+       int r;
+       int type = flags & IOSIGNALFD_FLAG_PIO; 
+       struct kvm_iosignalfd data = {
+               .cookie = cookie,
+               .addr   = addr,
+               .len    = len,
+               .fd     = fd,
+               .flags  = type ? KVM_IOSIGNALFD_FLAG_PIO : 0,
+       };
+
+       if (!kvm_check_extension(kvm, KVM_CAP_IOSIGNALFD))
+               return -ENOENT;
+
+       r = ioctl(kvm->vm_fd, KVM_IOSIGNALFD, &data);
+       if (r == -1)
+               r = -errno;
+       return r;
+}
+
+int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                           unsigned long addr, int flags)
+{
+       int r;
+       int type = flags & IOSIGNALFD_FLAG_PIO; 
+       int cvalid = flags & IOSIGNALFD_FLAG_COOKIE;
+       struct kvm_iosignalfd data = {
+               .cookie  = cookie,
+               .addr    = addr,
+               .flags   = KVM_IOSIGNALFD_FLAG_DEASSIGN |
+               (type ? KVM_IOSIGNALFD_FLAG_PIO : 0) |
+               (cvalid ? KVM_IOSIGNALFD_FLAG_COOKIE : 0),
+       };
+
+       if (!kvm_check_extension(kvm, KVM_CAP_IOSIGNALFD))
+               return -ENOENT;
+
+       r = ioctl(kvm->vm_fd, KVM_IOSIGNALFD, &data);
+       if (r == -1)
+               r = -errno;
+       return r;
+}
+
+#else /* KVM_CAP_IOSIGNALFD */
+
+int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                         unsigned long addr, size_t len,
+                         int fd, int flags)
+{
+       return -ENOENT;
+}
+
+int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                           unsigned long addr, int flags)
+{
+       return -ENOENT;
+}
+
+#endif /* KVM_CAP_IOSIGNALFD */
+
+
+
diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
index 3ccbe3d..ea81e55 100644
--- a/kvm/libkvm/libkvm.h
+++ b/kvm/libkvm/libkvm.h
@@ -882,6 +882,45 @@ int kvm_create_irqfd(kvm_context_t kvm, int gsi, int 
flags);
  */
 int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int gsi, int flags);
 
+enum {
+       iosignalfd_option_pio,
+       iosignalfd_option_cookie,
+};
+
+#define IOSIGNALFD_FLAG_PIO    (1 << iosignalfd_option_pio)
+#define IOSIGNALFD_FLAG_COOKIE (1 << iosignalfd_option_cookie)
+
+/*!
+ * \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 cookie A user-assigned cookie for optional use in deassign
+ * \param addr The IO address
+ * \param len The length of the IO region at the address
+ * \param fd The eventfd file-descriptor
+ * \param flags FLAG_PIO: PIO, else MMIO
+ */
+int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                         unsigned long addr, size_t len,
+                         int fd, int flags);
+
+/*!
+ * \brief Deassign an iosignalfd from a previously registered IO port
+ *
+ * Deassigns an iosignalfd previously registered with kvm_assign_iosignalfd()
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param cookie The cookie to (optionally) match (must specifcy FLAG_COOKIE)
+ * \param addr The IO address to deassign
+ * \param flags FLAG_PIO: PIO, else MMIO, FLAG_COOKIE: cookie is valid  
+ */
+int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long cookie,
+                           unsigned long addr, int flags);
+
 #ifdef KVM_CAP_DEVICE_MSIX
 int kvm_assign_set_msix_nr(kvm_context_t kvm,
                           struct kvm_assigned_msix_nr *msix_nr);

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to