diff options
| author | Cédric Le Goater <clg@redhat.com> | 2025-03-26 08:51:09 +0100 |
|---|---|---|
| committer | Cédric Le Goater <clg@redhat.com> | 2025-04-25 09:01:37 +0200 |
| commit | 923b11411e0e68b460f6fd8e6a7f8ff11554e48c (patch) | |
| tree | 83c03b0171387bc9c3bf1392bad8ed92bc8e0e23 /hw/vfio/device.c | |
| parent | a997b506e715d96549869e2d0fca28a1a9f110dc (diff) | |
| download | focaccia-qemu-923b11411e0e68b460f6fd8e6a7f8ff11554e48c.tar.gz focaccia-qemu-923b11411e0e68b460f6fd8e6a7f8ff11554e48c.zip | |
vfio: Move vfio_de/attach_device() into device.c
These routines are VFIODevice related. Move their definitions into "device.c". Reviewed-by: John Levon <john.levon@nutanix.com> Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-24-clg@redhat.com Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-25-clg@redhat.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw/vfio/device.c')
| -rw-r--r-- | hw/vfio/device.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 25fdba10a8..179c9fb8de 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -331,3 +331,40 @@ VFIODevice *vfio_get_vfio_device(Object *obj) return NULL; } } + +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) +{ + const VFIOIOMMUClass *ops = + VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); + HostIOMMUDevice *hiod = NULL; + + if (vbasedev->iommufd) { + ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD)); + } + + assert(ops); + + + if (!vbasedev->mdev) { + hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); + vbasedev->hiod = hiod; + } + + if (!ops->attach_device(name, vbasedev, as, errp)) { + object_unref(hiod); + vbasedev->hiod = NULL; + return false; + } + + return true; +} + +void vfio_detach_device(VFIODevice *vbasedev) +{ + if (!vbasedev->bcontainer) { + return; + } + object_unref(vbasedev->hiod); + VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev); +} |