Add vfio_device_get_feature() as a common helper to retrieve
VFIO device features.

No functional change intended.

Signed-off-by: Shameer Kolothum <[email protected]>
---
 hw/vfio/container.c           |  2 +-
 hw/vfio/device.c              | 10 ++++++++++
 hw/vfio/listener.c            |  4 ++--
 include/hw/vfio/vfio-device.h |  3 +++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 5993d90545..b0cbcf0f4a 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -208,7 +208,7 @@ static int vfio_device_dma_logging_report(VFIODevice 
*vbasedev, hwaddr iova,
     feature->flags = VFIO_DEVICE_FEATURE_GET |
                      VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT;
 
-    return vbasedev->io_ops->device_feature(vbasedev, feature);
+    return vfio_device_get_feature(vbasedev, feature);
 }
 
 static int vfio_container_iommu_query_dirty_bitmap(
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 100532f35d..0d9f42a1f0 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -516,6 +516,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
     vbasedev->bcontainer = NULL;
 }
 
+
 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
 {
     VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
@@ -527,6 +528,15 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice 
*vbasedev)
     return false;
 }
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature)
+{
+    if (!vbasedev->io_ops || !vbasedev->io_ops->device_feature) {
+        return -EINVAL;
+    }
+    return vbasedev->io_ops->device_feature(vbasedev, feature);
+}
+
 /*
  * Traditional ioctl() based io
  */
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index 7af0107535..d00fc87f3b 100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -879,7 +879,7 @@ static void vfio_devices_dma_logging_stop(VFIOContainer 
*bcontainer)
             continue;
         }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
 
         if (ret != 0) {
             warn_report("%s: Failed to stop DMA logging, err %d (%s)",
@@ -984,7 +984,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainer 
*bcontainer,
             continue;
         }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
         if (ret) {
             error_setg_errno(errp, -ret, "%s: Failed to start DMA logging",
                              vbasedev->name);
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 0bc877ff62..315dbb742a 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -259,6 +259,9 @@ void vfio_device_unprepare(VFIODevice *vbasedev);
 
 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev);
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature);
+
 int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                                 struct vfio_region_info **info);
 int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
-- 
2.43.0


Reply via email to