render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame qemu-kvm-add-API-to-set-ioeventfd.patch

Justin M. Forbes 272dfe
This adds API to set ioeventfd to kvm,
Justin M. Forbes 272dfe
as well as stubs for non-eventfd case,
Justin M. Forbes 272dfe
making it possible for users to use this API
Justin M. Forbes 272dfe
without ifdefs.
Justin M. Forbes 272dfe
Justin M. Forbes 272dfe
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Justin M. Forbes 272dfe
---
Justin M. Forbes 272dfe
 kvm-all.c |   20 ++++++++++++++++++++
Justin M. Forbes 272dfe
 kvm.h     |   16 ++++++++++++++++
Justin M. Forbes 272dfe
 2 files changed, 36 insertions(+), 0 deletions(-)
Justin M. Forbes 272dfe
Justin M. Forbes 272dfe
diff --git a/kvm-all.c b/kvm-all.c
Justin M. Forbes 272dfe
index 0423fff..efdf40c 100644
Justin M. Forbes 272dfe
--- a/kvm-all.c
Justin M. Forbes 272dfe
+++ b/kvm-all.c
Justin M. Forbes 272dfe
@@ -1102,4 +1102,24 @@ void kvm_remove_all_breakpoints(CPUState *current_env)
Justin M. Forbes 272dfe
 }
Justin M. Forbes 272dfe
 #endif /* !KVM_CAP_SET_GUEST_DEBUG */
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+#ifdef KVM_IOEVENTFD
Justin M. Forbes 272dfe
+int kvm_set_ioeventfd(uint16_t addr, uint16_t data, int fd, bool assigned)
Justin M. Forbes 272dfe
+{
Justin M. Forbes 272dfe
+    struct kvm_ioeventfd kick = {
Justin M. Forbes 272dfe
+        .datamatch = data,
Justin M. Forbes 272dfe
+        .addr = addr,
Justin M. Forbes 272dfe
+        .len = 2,
Justin M. Forbes 272dfe
+        .flags = KVM_IOEVENTFD_FLAG_DATAMATCH | KVM_IOEVENTFD_FLAG_PIO,
Justin M. Forbes 272dfe
+        .fd = fd,
Justin M. Forbes 272dfe
+    };
Justin M. Forbes 272dfe
+    int r;
Justin M. Forbes 272dfe
+    if (!assigned)
Justin M. Forbes 272dfe
+        kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
Justin M. Forbes 272dfe
+    r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
Justin M. Forbes 272dfe
+    if (r < 0)
Justin M. Forbes 272dfe
+        return r;
Justin M. Forbes 272dfe
+    return 0;
Justin M. Forbes 272dfe
+}
Justin M. Forbes 272dfe
+#endif
Justin M. Forbes 272dfe
+
Justin M. Forbes 272dfe
 #include "qemu-kvm.c"
Justin M. Forbes 272dfe
diff --git a/kvm.h b/kvm.h
Justin M. Forbes 272dfe
index 9fa4e25..e98b5c8 100644
Justin M. Forbes 272dfe
--- a/kvm.h
Justin M. Forbes 272dfe
+++ b/kvm.h
Justin M. Forbes 272dfe
@@ -14,6 +14,8 @@
Justin M. Forbes 272dfe
 #ifndef QEMU_KVM_H
Justin M. Forbes 272dfe
 #define QEMU_KVM_H
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+#include <stdbool.h>
Justin M. Forbes 272dfe
+#include <errno.h>
Justin M. Forbes 272dfe
 #include "config.h"
Justin M. Forbes 272dfe
 #include "qemu-queue.h"
Justin M. Forbes 272dfe
 #include "qemu-kvm.h"
Justin M. Forbes 272dfe
@@ -21,6 +23,10 @@
Justin M. Forbes 272dfe
 #ifdef KVM_UPSTREAM
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
 #ifdef CONFIG_KVM
Justin M. Forbes 272dfe
+#include <linux/kvm.h>
Justin M. Forbes 272dfe
+#endif
Justin M. Forbes 272dfe
+
Justin M. Forbes 272dfe
+#ifdef CONFIG_KVM
Justin M. Forbes 272dfe
 extern int kvm_allowed;
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
 #define kvm_enabled() (kvm_allowed)
Justin M. Forbes 272dfe
@@ -151,4 +157,14 @@ static inline void cpu_synchronize_state(CPUState *env)
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
 #endif
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+#if defined(KVM_IOEVENTFD) && defined(CONFIG_KVM)
Justin M. Forbes 272dfe
+int kvm_set_ioeventfd(uint16_t addr, uint16_t data, int fd, bool assigned);
Justin M. Forbes 272dfe
+#else
Justin M. Forbes 272dfe
+static inline
Justin M. Forbes 272dfe
+int kvm_set_ioeventfd(uint16_t data, uint16_t addr, int fd, bool assigned)
Justin M. Forbes 272dfe
+{
Justin M. Forbes 272dfe
+    return -ENOSYS;
Justin M. Forbes 272dfe
+}
Justin M. Forbes 272dfe
+#endif
Justin M. Forbes 272dfe
+
Justin M. Forbes 272dfe
 #endif
Justin M. Forbes 272dfe
-- 
Justin M. Forbes 272dfe
1.6.6.144.g5c3af