Patchwork [dpdk-dev,v2,20/20] bus/fslmc: add function to map any addr via VFIO

login
register
mail settings
Submitter Shreyansh Jain
Date Jan. 11, 2019, 11:58 a.m.
Message ID <20190111115712.6482-21-shreyansh.jain@nxp.com>
Download mbox | patch
Permalink /patch/697615/
State New
Headers show

Comments

Shreyansh Jain - Jan. 11, 2019, 11:58 a.m.
From: Pankaj Chauhan <pankaj.chauhan@nxp.com>

This is required to map any accelerator memory
and PCI address to VFIO using QDMA.

Signed-off-by: Minghuan Lian <Minghuan.Lian@nxp.com>
Signed-off-by: Pankaj Chauhan <pankaj.chauhan@nxp.com>
---
 drivers/bus/fslmc/fslmc_vfio.c              | 43 +++++++++++++++++++++
 drivers/bus/fslmc/fslmc_vfio.h              |  1 +
 drivers/bus/fslmc/rte_bus_fslmc_version.map |  7 ++++
 3 files changed, 51 insertions(+)

Patch

diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index 1aae56fa9..786089334 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -50,6 +50,7 @@  static struct fslmc_vfio_group vfio_group;
 static struct fslmc_vfio_container vfio_container;
 static int container_device_fd;
 static char *g_container;
+static int fslmc_iommu_type;
 static uint32_t *msi_intr_vaddr;
 void *(*rte_mcp_ptr_list);
 
@@ -90,6 +91,9 @@  fslmc_get_container_group(int *groupid)
 		}
 	}
 
+	fslmc_iommu_type = (rte_vfio_noiommu_is_enabled() == 1) ?
+		RTE_VFIO_NOIOMMU : VFIO_TYPE1_IOMMU;
+
 	/* get group number */
 	ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES,
 				     g_container, groupid);
@@ -344,6 +348,45 @@  fslmc_dmamap_seg(const struct rte_memseg_list *msl __rte_unused,
 	return ret;
 }
 
+int rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size)
+{
+	int ret;
+	struct fslmc_vfio_group *group;
+	struct vfio_iommu_type1_dma_map dma_map = {
+		.argsz = sizeof(struct vfio_iommu_type1_dma_map),
+		.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
+	};
+
+	if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) {
+		DPAA2_BUS_DEBUG("Running in NOIOMMU mode");
+		return 0;
+	}
+
+	/* SET DMA MAP for IOMMU */
+	group = &vfio_group;
+	if (!group->container) {
+		DPAA2_BUS_ERR("Container is not connected");
+		return -1;
+	}
+
+	dma_map.size = size;
+	dma_map.vaddr = vaddr;
+	dma_map.iova = iova;
+
+	DPAA2_BUS_DEBUG("FSLMC VFIO dmamap 0x%"PRIx64":0x%"PRIx64","
+			" size 0x%"PRIx64"", (uint64_t)dma_map.vaddr,
+			(uint64_t)dma_map.iova, (uint64_t)dma_map.size);
+	ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA,
+		    &dma_map);
+	if (ret) {
+		DPAA2_BUS_ERR("Unable to map DMA address (errno = %d)",
+			      errno);
+		return ret;
+	}
+
+	return 0;
+}
+
 int rte_fslmc_vfio_dmamap(void)
 {
 	int i = 0, ret;
diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h
index 9e2c4feef..4e750d623 100644
--- a/drivers/bus/fslmc/fslmc_vfio.h
+++ b/drivers/bus/fslmc/fslmc_vfio.h
@@ -50,5 +50,6 @@  int fslmc_vfio_process_group(void);
 char *fslmc_get_container(void);
 int fslmc_get_container_group(int *gropuid);
 int rte_fslmc_vfio_dmamap(void);
+int rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size);
 
 #endif /* _FSLMC_VFIO_H_ */
diff --git a/drivers/bus/fslmc/rte_bus_fslmc_version.map b/drivers/bus/fslmc/rte_bus_fslmc_version.map
index dcc4e082e..c4192d978 100644
--- a/drivers/bus/fslmc/rte_bus_fslmc_version.map
+++ b/drivers/bus/fslmc/rte_bus_fslmc_version.map
@@ -129,3 +129,10 @@  DPDK_18.11 {
 	dpci_set_opr;
 
 } DPDK_18.05;
+
+DPDK_19.02 {
+	global:
+
+	rte_fslmc_vfio_mem_dmamap;
+
+} DPDK_18.11;