From: Eric Auger <eric.au...@redhat.com> No fucntional change intended.
Signed-off-by: Eric Auger <eric.au...@redhat.com> Signed-off-by: Yi Liu <yi.l....@intel.com> Signed-off-by: Yi Sun <yi.y....@linux.intel.com> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> --- hw/vfio/common.c | 22 ++++++++++++++++++++++ hw/vfio/container.c | 12 +++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index da1d64efca..ee2ebf4be9 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1552,3 +1552,25 @@ retry: return info; } + +int vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) +{ + const VFIOIOMMUBackendOpsClass *ops; + + ops = VFIO_IOMMU_BACKEND_OPS_CLASS( + object_class_by_name(TYPE_VFIO_IOMMU_BACKEND_LEGACY_OPS)); + if (!ops) { + error_setg(errp, "VFIO IOMMU Backend not found!"); + return -ENODEV; + } + return ops->attach_device(name, vbasedev, as, errp); +} + +void vfio_detach_device(VFIODevice *vbasedev) +{ + if (!vbasedev->bcontainer) { + return; + } + vbasedev->bcontainer->ops->detach_device(vbasedev); +} diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 9d5be749c7..c86accdb38 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1117,8 +1117,8 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) * @name and @vbasedev->name are likely to be different depending * on the type of the device, hence the need for passing @name */ -int vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) +static int vfio_legacy_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) { int groupid = vfio_device_groupid(vbasedev, errp); VFIODevice *vbasedev_iter; @@ -1158,14 +1158,10 @@ int vfio_attach_device(char *name, VFIODevice *vbasedev, return ret; } -void vfio_detach_device(VFIODevice *vbasedev) +static void vfio_legacy_detach_device(VFIODevice *vbasedev) { VFIOGroup *group = vbasedev->group; - if (!vbasedev->bcontainer) { - return; - } - QLIST_REMOVE(vbasedev, global_next); QLIST_REMOVE(vbasedev, container_next); vbasedev->bcontainer = NULL; @@ -1180,6 +1176,8 @@ static void vfio_iommu_backend_legacy_ops_class_init(ObjectClass *oc, ops->dma_map = vfio_legacy_dma_map; ops->dma_unmap = vfio_legacy_dma_unmap; + ops->attach_device = vfio_legacy_attach_device; + ops->detach_device = vfio_legacy_detach_device; ops->set_dirty_page_tracking = vfio_legacy_set_dirty_page_tracking; ops->query_dirty_bitmap = vfio_legacy_query_dirty_bitmap; ops->add_window = vfio_legacy_add_section_window; -- 2.34.1