diff options
author | Gregory Haskins <ghaskins@novell.com> | 2009-06-02 11:45:24 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-06-04 13:05:27 +0300 |
commit | 67e22ed9105fa74bcb707e2c83fd10095c06812f (patch) | |
tree | f391d51676b382a0d5147bda6699f3c375273e6f | |
parent | Merge branch 'master' of git://git.sv.gnu.org/qemu (diff) | |
download | qemu-kvm-67e22ed9105fa74bcb707e2c83fd10095c06812f.tar.gz qemu-kvm-67e22ed9105fa74bcb707e2c83fd10095c06812f.tar.bz2 qemu-kvm-67e22ed9105fa74bcb707e2c83fd10095c06812f.zip |
kvm: Add irqfd support
irqfd lets you create an eventfd based file-desriptor to inject interrupts
to a kvm guest. We associate one gsi per fd for fine-grained routing.
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | libkvm-all.c | 49 | ||||
-rw-r--r-- | libkvm-all.h | 14 |
2 files changed, 63 insertions, 0 deletions
diff --git a/libkvm-all.c b/libkvm-all.c index 1668e327a..6a684a576 100644 --- a/libkvm-all.c +++ b/libkvm-all.c @@ -1481,3 +1481,52 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm, return ret; } #endif + +#if defined(KVM_CAP_IRQFD) && defined(CONFIG_eventfd) + +#include <sys/eventfd.h> + +static int _kvm_irqfd(kvm_context_t kvm, int fd, int gsi, int flags) +{ + int r; + struct kvm_irqfd data = { + .fd = fd, + .gsi = gsi, + .flags = flags, + }; + + r = ioctl(kvm->vm_fd, KVM_IRQFD, &data); + if (r == -1) + r = -errno; + return r; +} + +int kvm_irqfd(kvm_context_t kvm, int gsi, int flags) +{ + int r; + int fd; + + if (!kvm_check_extension(kvm, KVM_CAP_IRQFD)) + return -ENOENT; + + fd = eventfd(0, 0); + if (fd < 0) + return -errno; + + r = _kvm_irqfd(kvm, fd, gsi, 0); + if (r < 0) { + close(fd); + return -errno; + } + + return fd; +} + +#else /* KVM_CAP_IRQFD */ + +int kvm_irqfd(kvm_context_t kvm, int gsi, int flags) +{ + return -ENOSYS; +} + +#endif /* KVM_CAP_IRQFD */ diff --git a/libkvm-all.h b/libkvm-all.h index 4821a1e4c..aca8ed6ac 100644 --- a/libkvm-all.h +++ b/libkvm-all.h @@ -856,6 +856,20 @@ int kvm_commit_irq_routes(kvm_context_t kvm); */ int kvm_get_irq_route_gsi(kvm_context_t kvm); +/*! + * \brief Create a file descriptor for injecting interrupts + * + * Creates an eventfd based file-descriptor that maps to a specific GSI + * in the guest. eventfd compliant signaling (write() from userspace, or + * eventfd_signal() from kernelspace) will cause the GSI to inject + * itself into the guest at the next available window. + * + * \param kvm Pointer to the current kvm_context + * \param gsi GSI to assign to this fd + * \param flags reserved, must be zero + */ +int kvm_irqfd(kvm_context_t kvm, int gsi, int flags); + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(kvm_context_t kvm, struct kvm_assigned_msix_nr *msix_nr); |