@@ -187,7 +187,6 @@ extern bool kvm_msi_use_devid;
#endif /* CONFIG_KVM_IS_POSSIBLE */
struct kvm_run;
-struct kvm_lapic_state;
struct kvm_irq_routing_entry;
typedef struct KVMCapabilityInfo {
@@ -223,20 +222,6 @@ int kvm_has_debugregs(void);
int kvm_max_nested_state_length(void);
int kvm_has_pit_state2(void);
int kvm_has_many_ioeventfds(void);
-int kvm_has_gsi_routing(void);
-int kvm_has_intx_set_mask(void);
-
-/**
- * kvm_arm_supports_user_irq
- *
- * Not all KVM implementations support notifications for kernel generated
- * interrupt events to user space. This function indicates whether the current
- * KVM implementation does support them.
- *
- * Returns: true if KVM supports using kernel generated IRQs from user space
- */
-bool kvm_arm_supports_user_irq(void);
-
int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
int kvm_on_sigbus(int code, void *addr);
@@ -395,17 +380,6 @@ int kvm_arch_release_virq_post(int virq);
int kvm_arch_msi_data_to_gsi(uint32_t data);
-int kvm_set_irq(KVMState *s, int irq, int level);
-int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
-
-void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
-
-void kvm_irqchip_add_change_notifier(Notifier *n);
-void kvm_irqchip_remove_change_notifier(Notifier *n);
-void kvm_irqchip_change_notify(void);
-
-void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
-
struct kvm_guest_debug;
struct kvm_debug_exit_arch;
@@ -479,56 +453,6 @@ void kvm_cpu_synchronize_state(CPUState *cpu);
void kvm_init_cpu_signals(CPUState *cpu);
-/**
- * kvm_irqchip_add_msi_route - Add MSI route for specific vector
- * @c: KVMRouteChange instance.
- * @vector: which vector to add. This can be either MSI/MSIX
- * vector. The function will automatically detect whether
- * MSI/MSIX is enabled, and fetch corresponding MSI
- * message.
- * @dev: Owner PCI device to add the route. If @dev is specified
- * as @NULL, an empty MSI message will be inited.
- * @return: virq (>=0) when success, errno (<0) when failed.
- */
-int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *dev);
-int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
- PCIDevice *dev);
-void kvm_irqchip_commit_routes(KVMState *s);
-
-static inline KVMRouteChange kvm_irqchip_begin_route_changes(KVMState *s)
-{
- return (KVMRouteChange) { .s = s, .changes = 0 };
-}
-
-static inline void kvm_irqchip_commit_route_changes(KVMRouteChange *c)
-{
- if (c->changes) {
- kvm_irqchip_commit_routes(c->s);
- c->changes = 0;
- }
-}
-
-void kvm_irqchip_release_virq(KVMState *s, int virq);
-
-int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter);
-int kvm_irqchip_add_hv_sint_route(KVMState *s, uint32_t vcpu, uint32_t sint);
-
-int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
- EventNotifier *rn, int virq);
-int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
- int virq);
-int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
- EventNotifier *rn, qemu_irq irq);
-int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
- qemu_irq irq);
-void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi);
-void kvm_pc_setup_irq_routing(bool pci_enabled);
-void kvm_init_irq_routing(KVMState *s);
-
-bool kvm_kernel_irqchip_allowed(void);
-bool kvm_kernel_irqchip_required(void);
-bool kvm_kernel_irqchip_split(void);
-
/**
* kvm_arch_irqchip_create:
* @KVMState: The KVMState pointer
new file mode 100644
@@ -0,0 +1,100 @@
+/*
+ * QEMU KVM IRQ helpers
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+/* header to be included in hardware (non-KVM-specific) code */
+
+#ifndef QEMU_KVM_IRQ_H
+#define QEMU_KVM_IRQ_H
+
+#include "qemu/notify.h"
+#include "sysemu/kvm.h"
+
+struct kvm_lapic_state;
+
+int kvm_has_gsi_routing(void);
+int kvm_has_intx_set_mask(void);
+
+/**
+ * kvm_arm_supports_user_irq
+ *
+ * Not all KVM implementations support notifications for kernel generated
+ * interrupt events to user space. This function indicates whether the current
+ * KVM implementation does support them.
+ *
+ * Returns: true if KVM supports using kernel generated IRQs from user space
+ */
+bool kvm_arm_supports_user_irq(void);
+
+void kvm_irqchip_add_change_notifier(Notifier *n);
+void kvm_irqchip_remove_change_notifier(Notifier *n);
+void kvm_irqchip_change_notify(void);
+
+/**
+ * kvm_irqchip_add_msi_route - Add MSI route for specific vector
+ * @c: KVMRouteChange instance.
+ * @vector: which vector to add. This can be either MSI/MSIX
+ * vector. The function will automatically detect whether
+ * MSI/MSIX is enabled, and fetch corresponding MSI
+ * message.
+ * @dev: Owner PCI device to add the route. If @dev is specified
+ * as @NULL, an empty MSI message will be inited.
+ * @return: virq (>=0) when success, errno (<0) when failed.
+ */
+int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *dev);
+int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
+ PCIDevice *dev);
+void kvm_irqchip_commit_routes(KVMState *s);
+
+static inline KVMRouteChange kvm_irqchip_begin_route_changes(KVMState *s)
+{
+ return (KVMRouteChange) { .s = s, .changes = 0 };
+}
+
+static inline void kvm_irqchip_commit_route_changes(KVMRouteChange *c)
+{
+ if (c->changes) {
+ kvm_irqchip_commit_routes(c->s);
+ c->changes = 0;
+ }
+}
+
+void kvm_irqchip_release_virq(KVMState *s, int virq);
+
+int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter);
+int kvm_irqchip_add_hv_sint_route(KVMState *s, uint32_t vcpu, uint32_t sint);
+
+int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
+ EventNotifier *rn, int virq);
+int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
+ int virq);
+int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
+ EventNotifier *rn, qemu_irq irq);
+int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
+ qemu_irq irq);
+void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi);
+void kvm_pc_setup_irq_routing(bool pci_enabled);
+void kvm_init_irq_routing(KVMState *s);
+
+bool kvm_kernel_irqchip_allowed(void);
+bool kvm_kernel_irqchip_required(void);
+bool kvm_kernel_irqchip_split(void);
+
+
+int kvm_set_irq(KVMState *s, int irq, int level);
+int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
+
+void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
+
+void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
+
+#endif
@@ -12,6 +12,7 @@
#define QEMU_KVM_I386_H
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#define kvm_apic_in_kernel() (kvm_irqchip_in_kernel())
@@ -28,6 +28,8 @@
#include "hw/pci/msix.h"
#include "hw/s390x/adapter.h"
#include "exec/gdbstub.h"
+#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/kvm_int.h"
#include "sysemu/runstate.h"
#include "sysemu/cpus.h"
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "hw/pci/msi.h"
KVMState *kvm_state;
@@ -48,6 +48,7 @@
#include "sysemu/tpm.h"
#include "sysemu/tcg.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/hvf.h"
#include "sysemu/qtest.h"
#include "hw/loader.h"
@@ -25,6 +25,7 @@
#include "hw/irq.h"
#include "hw/qdev-properties.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "kvm_arm.h"
static void a15mp_priv_set_irq(void *opaque, int irq, int level)
@@ -13,6 +13,7 @@
#include "qapi/error.h"
#include "exec/address-spaces.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "qemu/bitops.h"
#include "qemu/error-report.h"
#include "qemu/lockable.h"
@@ -33,6 +33,7 @@
#include "hw/i386/x86-iommu.h"
#include "hw/pci-host/q35.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/dma.h"
#include "sysemu/sysemu.h"
#include "hw/i386/apic_internal.h"
@@ -16,6 +16,7 @@
#include "hw/pci/msi.h"
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "kvm/kvm_i386.h"
static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
@@ -17,6 +17,7 @@
#include "hw/intc/kvm_irqcount.h"
#include "hw/irq.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "qom/object.h"
#define TYPE_KVM_I8259 "kvm-i8259"
@@ -16,6 +16,7 @@
#include "hw/intc/ioapic_internal.h"
#include "hw/intc/kvm_irqcount.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
/* PC Utility function */
void kvm_pc_setup_irq_routing(bool pci_enabled)
@@ -15,6 +15,7 @@
#include "sysemu/cpus.h"
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/runstate.h"
#include "hw/i386/apic_internal.h"
#include "hw/sysbus.h"
@@ -58,6 +58,7 @@
#include "sysemu/tcg.h"
#include "sysemu/numa.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/xen.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
@@ -26,6 +26,7 @@
#include "qemu/error-report.h"
#include "trace.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
iec_notify_fn fn, void *data)
@@ -28,6 +28,7 @@
#include "qemu/module.h"
#include "trace.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/qtest.h"
/* #define DEBUG_GIC */
@@ -27,6 +27,7 @@
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
static int gic_pre_save(void *opaque)
{
@@ -24,6 +24,7 @@
#include "qemu/module.h"
#include "migration/blocker.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "kvm_arm.h"
#include "gic_internal.h"
#include "vgic_common.h"
@@ -32,6 +32,7 @@
#include "gicv3_internal.h"
#include "hw/arm/linux-boot-if.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs)
@@ -25,6 +25,7 @@
#include "qemu/log.h"
#include "qemu/module.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
static int gicv3_its_pre_save(void *opaque)
{
@@ -25,6 +25,7 @@
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/runstate.h"
#include "kvm_arm.h"
#include "gicv3_internal.h"
@@ -31,6 +31,7 @@
#include "hw/pci/msi.h"
#include "hw/qdev-properties.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/sysemu.h"
#include "hw/i386/apic-msidef.h"
#include "hw/i386/x86-iommu.h"
@@ -31,6 +31,7 @@
#include "hw/qdev-properties.h"
#include "hw/sysbus.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qom/object.h"
@@ -17,6 +17,7 @@
#include "qemu/module.h"
#include "qapi/error.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "hw/s390x/s390_flic.h"
#include "hw/s390x/adapter.h"
#include "hw/s390x/css.h"
@@ -14,6 +14,7 @@
#include "target/ppc/cpu.h"
#include "sysemu/cpus.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/runstate.h"
#include "hw/ppc/spapr.h"
#include "hw/ppc/spapr_cpu_core.h"
@@ -39,6 +39,7 @@
#include "hw/intc/intc.h"
#include "hw/irq.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/reset.h"
void icp_pic_print_info(ICPState *icp, Monitor *mon)
@@ -29,6 +29,7 @@
#include "qapi/error.h"
#include "trace.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "hw/ppc/spapr.h"
#include "hw/ppc/spapr_cpu_core.h"
#include "hw/ppc/xics.h"
@@ -27,6 +27,7 @@
#include "hw/pci/msi.h"
#include "hw/pci/msix.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "migration/blocker.h"
#include "migration/vmstate.h"
#include "qemu/error-report.h"
@@ -29,6 +29,7 @@
#include "sysemu/block-backend-io.h"
#include "sysemu/sysemu.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
#include "kvm_ppc.h"
@@ -20,6 +20,7 @@
#include "hw/qdev-properties.h"
#include "cpu-models.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "trace.h"
@@ -22,6 +22,7 @@
#include "qom/object.h"
#include "qemu/event_notifier.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "util/event_notifier-posix.c"
static void probe_pci_info(PCIDevice *dev, Error **errp);
@@ -14,6 +14,7 @@
#include "qapi/error.h"
#include "exec/address-spaces.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "net/net.h"
#include "hw/virtio/virtio.h"
#include "migration/qemu-file-types.h"
@@ -36,6 +36,7 @@
#include "qemu/range.h"
#include "qemu/units.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/runstate.h"
#include "pci.h"
#include "trace.h"
@@ -35,6 +35,7 @@
#include "hw/platform-bus.h"
#include "hw/qdev-properties.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
/*
* Functions used whatever the injection method
@@ -34,6 +34,7 @@
#include "hw/pci/msix.h"
#include "hw/loader.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "hw/virtio/virtio-pci.h"
#include "qemu/range.h"
#include "hw/virtio/virtio-bus.h"
@@ -20,6 +20,7 @@
#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/kvm_int.h"
#include "kvm_arm.h"
#include "cpu.h"
@@ -28,6 +28,8 @@
#include "host-cpu.h"
#include "sysemu/sysemu.h"
#include "sysemu/hw_accel.h"
+#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/kvm_int.h"
#include "sysemu/runstate.h"
#include "kvm_i386.h"
@@ -14,6 +14,8 @@
#include "qemu/main-loop.h"
#include "qemu/error-report.h"
#include "hw/xen/xen.h"
+#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/kvm_int.h"
#include "sysemu/kvm_xen.h"
#include "kvm/kvm_i386.h"
@@ -26,6 +26,7 @@
#include "qemu/error-report.h"
#include "crypto/hash.h"
#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sev.h"
#include "sysemu/sysemu.h"
#include "sysemu/runstate.h"
@@ -27,6 +27,8 @@
#include "cpu.h"
#include "s390x-internal.h"
#include "kvm_s390x.h"
+#include "sysemu/kvm.h"
+#include "sysemu/kvm_irq.h"
#include "sysemu/kvm_int.h"
#include "qemu/cutils.h"
#include "qapi/error.h"
"sysemu/kvm.h" header is meant to contain the 'external' KVM API accessed by all the code base. KVM *internal* API aims to reside in "sysemu/kvm_int.h", accessible by files in accel/kvm/ and each target/ implementation. Hardware models should only access the external API. "sysemu/kvm.h" is quite big. Extract the KVM IRQ declarations to "sysemu/kvm_irq.h" to reduce this header complexity. This will ease extracting internal prototypes to "sysemu/kvm_int.h". Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/sysemu/kvm.h | 76 ------------------------- include/sysemu/kvm_irq.h | 100 +++++++++++++++++++++++++++++++++ target/i386/kvm/kvm_i386.h | 1 + accel/kvm/kvm-all.c | 2 + accel/stubs/kvm-stub.c | 1 + hw/arm/virt.c | 1 + hw/cpu/a15mpcore.c | 1 + hw/hyperv/hyperv.c | 1 + hw/i386/intel_iommu.c | 1 + hw/i386/kvm/apic.c | 1 + hw/i386/kvm/i8259.c | 1 + hw/i386/kvm/ioapic.c | 1 + hw/i386/kvmvapic.c | 1 + hw/i386/pc.c | 1 + hw/i386/x86-iommu.c | 1 + hw/intc/arm_gic.c | 1 + hw/intc/arm_gic_common.c | 1 + hw/intc/arm_gic_kvm.c | 1 + hw/intc/arm_gicv3_common.c | 1 + hw/intc/arm_gicv3_its_common.c | 1 + hw/intc/arm_gicv3_kvm.c | 1 + hw/intc/ioapic.c | 1 + hw/intc/openpic_kvm.c | 1 + hw/intc/s390_flic_kvm.c | 1 + hw/intc/spapr_xive_kvm.c | 1 + hw/intc/xics.c | 1 + hw/intc/xics_kvm.c | 1 + hw/misc/ivshmem.c | 1 + hw/ppc/e500.c | 1 + hw/ppc/spapr_irq.c | 1 + hw/remote/proxy.c | 1 + hw/s390x/virtio-ccw.c | 1 + hw/vfio/pci.c | 1 + hw/vfio/platform.c | 1 + hw/virtio/virtio-pci.c | 1 + target/arm/kvm.c | 1 + target/i386/kvm/kvm.c | 2 + target/i386/kvm/xen-emu.c | 2 + target/i386/sev.c | 1 + target/s390x/kvm/kvm.c | 2 + 40 files changed, 142 insertions(+), 76 deletions(-) create mode 100644 include/sysemu/kvm_irq.h