On 2/10/25 15:32, Philippe Mathieu-Daudé wrote:
On 30/1/25 14:43, Cédric Le Goater wrote:
This helper will be useful in the listener handlers to extract the
VFIO device from a memory region using memory_region_owner(). At the
moment, we only care for PCI passthrough devices. If the need arises,
we will add more.

Signed-off-by: Cédric Le Goater <c...@redhat.com>
---
  include/hw/vfio/vfio-common.h |  1 +
  hw/vfio/helpers.c             | 10 ++++++++++
  2 files changed, 11 insertions(+)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 
0c60be5b15c70168f4f94ad7054d9bd750a162d3..ac35136a11051b079cd9d04e6becd344a0e0f7e7
 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -252,6 +252,7 @@ bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error 
**errp);
  bool vfio_attach_device(char *name, VFIODevice *vbasedev,
                          AddressSpace *as, Error **errp);
  void vfio_detach_device(VFIODevice *vbasedev);
+VFIODevice *vfio_get_vfio_device(Object *obj);
  int vfio_kvm_device_add_fd(int fd, Error **errp);
  int vfio_kvm_device_del_fd(int fd, Error **errp);
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index 
913796f437f84eece8711cb4b4b654a44040d17c..4b255d4f3a9e81f55df00c68fc71da769fd5bd04
 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -23,6 +23,7 @@
  #include <sys/ioctl.h>
  #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/pci.h"
  #include "hw/hw.h"
  #include "trace.h"
  #include "qapi/error.h"
@@ -728,3 +729,12 @@ bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error 
**errp)
      return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp);
  }
+
+VFIODevice *vfio_get_vfio_device(Object *obj)

Can't we take a VFIOPCIDevice argument?

It could be some other VFIO (AP, Plateform) device type and we wouldn't
need to do the cast below in that case.


Thanks,

C.




+{
+    if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) {
+        return &VFIO_PCI(obj)->vbasedev;
+    } else {
+        return NULL;
+    }
+}



Reply via email to