new file mode 100644
@@ -0,0 +1,26 @@
+/*
+ * VFIO helpers
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_HELPERS_H
+#define HW_VFIO_HELPERS_H
+
+#ifdef CONFIG_LINUX
+#include <linux/vfio.h>
+
+struct vfio_info_cap_header *
+vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
+struct vfio_info_cap_header *
+vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
+struct vfio_info_cap_header *
+vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
+
+#endif
+
+int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
+
+#endif /* HW_VFIO_HELPERS_H */
@@ -146,17 +146,10 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
uint32_t subtype, struct vfio_region_info **info);
bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
-struct vfio_info_cap_header *
-vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
unsigned int *avail);
-struct vfio_info_cap_header *
-vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
-struct vfio_info_cap_header *
-vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
#endif
-int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
bool vfio_devices_all_dirty_tracking_started(
const VFIOContainerBase *bcontainer);
bool
@@ -21,6 +21,7 @@
#include "hw/s390x/s390-pci-vfio.h"
#include "hw/vfio/pci.h"
#include "hw/vfio/vfio-container.h"
+#include "hw/vfio/helpers.h"
/*
* Get the current DMA available count from vfio. Returns true if vfio is
@@ -44,6 +44,7 @@
#include "system/tcg.h"
#include "system/tpm.h"
#include "migration.h"
+#include "helpers.h"
VFIODeviceList vfio_device_list =
QLIST_HEAD_INITIALIZER(vfio_device_list);
@@ -33,6 +33,7 @@
#include "qapi/error.h"
#include "pci.h"
#include "hw/vfio/vfio-container.h"
+#include "helpers.h"
#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
@@ -30,6 +30,7 @@
#include "qemu/error-report.h"
#include "qemu/units.h"
#include "monitor/monitor.h"
+#include "helpers.h"
/*
* Common VFIO interrupt disable
@@ -46,6 +46,7 @@
#include "system/iommufd.h"
#include "migration.h"
#include "hw/vfio/vfio-region.h"
+#include "helpers.h"
#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
@@ -30,6 +30,7 @@
#include "qemu/error-report.h"
#include "qemu/units.h"
#include "monitor/monitor.h"
+#include "helpers.h"
/*
* IO Port/MMIO - Beware of the endians, VFIO is always little endian
Gather all helper routine declarations into "helpers.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Signed-off-by: Cédric Le Goater <clg@redhat.com> --- hw/vfio/helpers.h | 26 ++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 7 ------- hw/s390x/s390-pci-vfio.c | 1 + hw/vfio/common.c | 1 + hw/vfio/container.c | 1 + hw/vfio/helpers.c | 1 + hw/vfio/pci.c | 1 + hw/vfio/region.c | 1 + 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 hw/vfio/helpers.h