vfio: combine container_create and group_bind
Checks
Commit Message
From: BillXiang <xiangwencheng@dayudpu.com>
For multi-devices in one group we can only create and bind to one
container. With this new function, device driver does not need to
save the binding info additionally between different devices.
Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
---
lib/eal/include/rte_vfio.h | 16 ++++++++++++++++
lib/eal/linux/eal_vfio.c | 24 ++++++++++++++++++++++++
lib/eal/version.map | 1 +
3 files changed, 41 insertions(+)
@@ -407,6 +407,22 @@ int
rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr,
uint64_t iova, uint64_t len);
+/**
+ * Get vfio group fd bound with container fd for certain iommu group.
+ *
+ * @param iommu_group_num
+ * iommu group num
+ * @param vfio_group_fd
+ * vfio group fd of the iommu group.
+ * @param vfio_container_fd
+ * vfio container fd of the iommu group.
+ * @return
+ * 0 if successful
+ * <0 if failed
+ */
+int
+rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd);
+
#ifdef __cplusplus
}
#endif
@@ -2196,3 +2196,27 @@ rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova,
return container_dma_unmap(vfio_cfg, vaddr, iova, len);
}
+
+int
+rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd)
+{
+ struct vfio_config *vfio_cfg;
+ vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num);
+ /* do not create new container if the group has bound with one */
+ if (vfio_cfg) {
+ *vfio_container_fd = vfio_cfg->vfio_container_fd;
+ } else {
+ *vfio_container_fd = rte_vfio_container_create();
+ if (*vfio_container_fd < 0)
+ goto err;
+
+ vfio_cfg = get_vfio_cfg_by_container_fd(*vfio_container_fd);
+ }
+ *vfio_group_fd = vfio_get_group_fd(vfio_cfg, iommu_group_num);
+ if (*vfio_group_fd < 0)
+ goto err;
+
+ return 0;
+err:
+ return -1;
+}
@@ -338,6 +338,7 @@ DPDK_24 {
rte_vfio_noiommu_is_enabled; # WINDOWS_NO_EXPORT
rte_vfio_release_device; # WINDOWS_NO_EXPORT
rte_vfio_setup_device; # WINDOWS_NO_EXPORT
+ rte_vfio_get_fd;
rte_zmalloc;
rte_zmalloc_socket;