90 lines
3.3 KiB
Diff
90 lines
3.3 KiB
Diff
|
|
From ff4e67fa5ceb31f1dc686a661cbf37c1a81cd644 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Date: Sat, 11 Jan 2025 10:52:21 +0800
|
||
|
|
Subject: [PATCH] vfio/common: Introduce vfio_container_init/destroy helper
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
This adds two helper functions vfio_container_init/destroy which will be
|
||
|
|
used by both legacy and iommufd containers to do base container specific
|
||
|
|
initialization and release.
|
||
|
|
|
||
|
|
No functional change intended.
|
||
|
|
|
||
|
|
Suggested-by: Cédric Le Goater <clg@redhat.com>
|
||
|
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Reviewed-by: Cédric Le Goater <clg@redhat.com>
|
||
|
|
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
||
|
|
Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
|
||
|
|
---
|
||
|
|
hw/vfio/container-base.c | 9 +++++++++
|
||
|
|
hw/vfio/container.c | 4 +++-
|
||
|
|
include/hw/vfio/vfio-container-base.h | 4 ++++
|
||
|
|
3 files changed, 16 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
|
||
|
|
index 55d3a35fa4..e929435751 100644
|
||
|
|
--- a/hw/vfio/container-base.c
|
||
|
|
+++ b/hw/vfio/container-base.c
|
||
|
|
@@ -30,3 +30,12 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
||
|
|
g_assert(bcontainer->ops->dma_unmap);
|
||
|
|
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+void vfio_container_init(VFIOContainerBase *bcontainer, const VFIOIOMMUOps *ops)
|
||
|
|
+{
|
||
|
|
+ bcontainer->ops = ops;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
||
|
|
+{
|
||
|
|
+}
|
||
|
|
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
|
||
|
|
index 40e378e888..5a8c55056b 100644
|
||
|
|
--- a/hw/vfio/container.c
|
||
|
|
+++ b/hw/vfio/container.c
|
||
|
|
@@ -653,7 +653,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||
|
|
QLIST_INIT(&container->vrdl_list);
|
||
|
|
QLIST_INIT(&container->dma_list);
|
||
|
|
bcontainer = &container->bcontainer;
|
||
|
|
- bcontainer->ops = &vfio_legacy_ops;
|
||
|
|
+ vfio_container_init(bcontainer, &vfio_legacy_ops);
|
||
|
|
|
||
|
|
ret = vfio_init_container(container, group->fd, errp);
|
||
|
|
if (ret) {
|
||
|
|
@@ -765,6 +765,7 @@ put_space_exit:
|
||
|
|
static void vfio_disconnect_container(VFIOGroup *group)
|
||
|
|
{
|
||
|
|
VFIOContainer *container = group->container;
|
||
|
|
+ VFIOContainerBase *bcontainer = &container->bcontainer;
|
||
|
|
|
||
|
|
QLIST_REMOVE(group, container_next);
|
||
|
|
group->container = NULL;
|
||
|
|
@@ -803,6 +804,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
|
||
|
|
QLIST_REMOVE(giommu, giommu_next);
|
||
|
|
g_free(giommu);
|
||
|
|
}
|
||
|
|
+ vfio_container_destroy(bcontainer);
|
||
|
|
|
||
|
|
trace_vfio_disconnect_container(container->fd);
|
||
|
|
close(container->fd);
|
||
|
|
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
|
||
|
|
index 56b033f59f..577f52ccbc 100644
|
||
|
|
--- a/include/hw/vfio/vfio-container-base.h
|
||
|
|
+++ b/include/hw/vfio/vfio-container-base.h
|
||
|
|
@@ -38,6 +38,10 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
||
|
|
hwaddr iova, ram_addr_t size,
|
||
|
|
IOMMUTLBEntry *iotlb);
|
||
|
|
|
||
|
|
+void vfio_container_init(VFIOContainerBase *bcontainer,
|
||
|
|
+ const VFIOIOMMUOps *ops);
|
||
|
|
+void vfio_container_destroy(VFIOContainerBase *bcontainer);
|
||
|
|
+
|
||
|
|
struct VFIOIOMMUOps {
|
||
|
|
/* basic feature */
|
||
|
|
int (*dma_map)(VFIOContainerBase *bcontainer,
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|