[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 15/27] vfio/container: Implement attach/detach_device
From: |
Zhenzhong Duan |
Subject: |
[PATCH v2 15/27] vfio/container: Implement attach/detach_device |
Date: |
Mon, 16 Oct 2023 16:32:11 +0800 |
From: Eric Auger <eric.auger@redhat.com>
No fucntional change intended.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@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
- [PATCH v2 04/27] vfio/container: Switch to dma_map|unmap API, (continued)
- [PATCH v2 04/27] vfio/container: Switch to dma_map|unmap API, Zhenzhong Duan, 2023/10/16
- [PATCH v2 07/27] vfio/container: switch to IOMMU BE add/del_section_window, Zhenzhong Duan, 2023/10/16
- [PATCH v2 06/27] vfio/container: Move space field to base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 08/27] vfio/container: Move hostwin_list in base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 09/27] vfio/container: Switch to IOMMU BE set_dirty_page_tracking/query_dirty_bitmap API, Zhenzhong Duan, 2023/10/16
- [PATCH v2 10/27] vfio/container: Move per container device list in base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 11/27] vfio/container: Convert functions to base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 12/27] vfio/container: Move vrdl_list, pgsizes and dma_max_mappings to base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 13/27] vfio/container: Move listener to base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 14/27] vfio/container: Move dirty_pgsizes and max_dirty_bitmap_size to base container, Zhenzhong Duan, 2023/10/16
- [PATCH v2 15/27] vfio/container: Implement attach/detach_device,
Zhenzhong Duan <=
- [PATCH v2 16/27] Add iommufd configure option, Zhenzhong Duan, 2023/10/16
- [PATCH v2 17/27] backends/iommufd: Introduce the iommufd object, Zhenzhong Duan, 2023/10/16
- [PATCH v2 18/27] util/char_dev: Add open_cdev(), Zhenzhong Duan, 2023/10/16
- [PATCH v2 19/27] vfio/iommufd: Implement the iommufd backend, Zhenzhong Duan, 2023/10/16
- [PATCH v2 20/27] vfio/container: Bypass EEH if iommufd backend, Zhenzhong Duan, 2023/10/16
- [PATCH v2 21/27] vfio/pci: Adapt vfio pci hot reset support with iommufd BE, Zhenzhong Duan, 2023/10/16
- [PATCH v2 22/27] vfio/pci: Allow the selection of a given iommu backend, Zhenzhong Duan, 2023/10/16
- [PATCH v2 23/27] vfio/pci: Make vfio cdev pre-openable by passing a file handle, Zhenzhong Duan, 2023/10/16