summaryrefslogtreecommitdiff
path: root/drivers/bus/fslmc
diff options
context:
space:
mode:
authorAnatoly Burakov <anatoly.burakov@intel.com>2018-04-11 13:30:01 +0100
committerThomas Monjalon <thomas@monjalon.net>2018-04-11 19:48:06 +0200
commit49a28baed2121d8ba5b92538b8da0d2fc2ebf74f (patch)
tree5cc871ea05b66dc620703b97c4d52b988dc7e1b7 /drivers/bus/fslmc
parent2b9f98d8a596fa552313fd4a79d182d062a26305 (diff)
downloaddpdk-49a28baed2121d8ba5b92538b8da0d2fc2ebf74f.zip
dpdk-49a28baed2121d8ba5b92538b8da0d2fc2ebf74f.tar.gz
dpdk-49a28baed2121d8ba5b92538b8da0d2fc2ebf74f.tar.xz
bus/fslmc: use memseg walk instead of iteration
Reduce dependency on internal details of EAL memory subsystem, and simplify code. Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com> Tested-by: Santosh Shukla <santosh.shukla@caviumnetworks.com> Tested-by: Hemant Agrawal <hemant.agrawal@nxp.com> Tested-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
Diffstat (limited to 'drivers/bus/fslmc')
-rw-r--r--drivers/bus/fslmc/fslmc_vfio.c78
1 files changed, 41 insertions, 37 deletions
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index 4291871..0c048dc 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -189,17 +189,51 @@ static int vfio_map_irq_region(struct fslmc_vfio_group *group)
return -errno;
}
-int rte_fslmc_vfio_dmamap(void)
+static int
+fslmc_vfio_map(const struct rte_memseg *ms, void *arg)
{
- int ret;
+ int *n_segs = arg;
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,
};
+ int ret;
+
+ dma_map.size = ms->len;
+ dma_map.vaddr = ms->addr_64;
+#ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
+ dma_map.iova = ms->iova;
+#else
+ dma_map.iova = dma_map.vaddr;
+#endif
+
+ /* SET DMA MAP for IOMMU */
+ group = &vfio_group;
+
+ if (!group->container) {
+ DPAA2_BUS_ERR("Container is not connected ");
+ return -1;
+ }
+
+ DPAA2_BUS_DEBUG("-->Initial SHM Virtual ADDR %llX",
+ dma_map.vaddr);
+ DPAA2_BUS_DEBUG("-----> DMA size 0x%llX", dma_map.size);
+ ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA,
+ &dma_map);
+ if (ret) {
+ DPAA2_BUS_ERR("VFIO_IOMMU_MAP_DMA API(errno = %d)",
+ errno);
+ return -1;
+ }
+ (*n_segs)++;
+ return 0;
+}
- int i;
+int rte_fslmc_vfio_dmamap(void)
+{
const struct rte_memseg *memseg;
+ int i = 0;
if (is_dma_done)
return 0;
@@ -210,51 +244,21 @@ int rte_fslmc_vfio_dmamap(void)
return -ENODEV;
}
- for (i = 0; i < RTE_MAX_MEMSEG; i++) {
- if (memseg[i].addr == NULL && memseg[i].len == 0) {
- DPAA2_BUS_DEBUG("Total %d segments found", i);
- break;
- }
-
- dma_map.size = memseg[i].len;
- dma_map.vaddr = memseg[i].addr_64;
-#ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
- dma_map.iova = memseg[i].iova;
-#else
- dma_map.iova = dma_map.vaddr;
-#endif
-
- /* SET DMA MAP for IOMMU */
- group = &vfio_group;
-
- if (!group->container) {
- DPAA2_BUS_ERR("Container is not connected");
- return -1;
- }
-
- DPAA2_BUS_DEBUG("-->Initial SHM Virtual ADDR %llX",
- dma_map.vaddr);
- DPAA2_BUS_DEBUG("-----> DMA size 0x%llX", 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;
- }
- }
+ if (rte_memseg_walk(fslmc_vfio_map, &i) < 0)
+ return -1;
/* Verifying that at least single segment is available */
if (i <= 0) {
DPAA2_BUS_ERR("No Segments found for VFIO Mapping");
return -1;
}
+ DPAA2_BUS_DEBUG("Total %d segments found.", i);
/* TODO - This is a W.A. as VFIO currently does not add the mapping of
* the interrupt region to SMMU. This should be removed once the
* support is added in the Kernel.
*/
- vfio_map_irq_region(group);
+ vfio_map_irq_region(&vfio_group);
is_dma_done = 1;