On 7/31/25 13:24, Philippe Mathieu-Daudé wrote:
On 31/7/25 10:49, Duan, Zhenzhong wrote:
-----Original Message-----
From: Philippe Mathieu-Daudé <phi...@linaro.org>
Subject: Re: [PATCH] vfio: Introduce helper vfio_device_to_vfio_pci()
Hi,
On 31/7/25 05:31, Zhenzhong Duan wrote:
Introduce helper vfio_device_to_vfio_pci() to transform from VFIODevice to
VFIOPCIDevice, also to hide low level VFIO_DEVICE_TYPE_PCI type check.
Suggested-by: Cédric Le Goater <c...@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>
---
include/hw/vfio/vfio-device.h | 1 +
hw/vfio/container.c | 4 ++--
hw/vfio/device.c | 10 +++++++++-
hw/vfio/iommufd.c | 4 ++--
hw/vfio/listener.c | 4 ++--
5 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 6e4d5ccdac..00df40d997 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -157,6 +157,7 @@ bool vfio_device_attach_by_iommu_type(const
char *iommu_type, char *name,
Error **errp);
void vfio_device_detach(VFIODevice *vbasedev);
VFIODevice *vfio_get_vfio_device(Object *obj);
+struct VFIOPCIDevice *vfio_device_to_vfio_pci(VFIODevice *vbasedev);
Please return the typedef (like in the implementation), not the struct.
That will break build. VFIOPCIDevice is defined in internal header
hw/vfio/pci.h,
while include/hw/vfio/vfio-device.h is public header, I'm not sure if it's
right way to include internal header in public header.
Moving the following line:
OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
from hw/vfio/pci.h to include/hw/vfio/vfio-device.h should be enough.
I rather not. These are 2 differents subcomponents.
vfio_device_to_vfio_pci() could be moved.
Thanks,
C.