Add support for DMA map/unmap operations.

Signed-off-by: Tomasz Duszynski <tduszyn...@marvell.com>
---
 .../raw/vfio_platform/rte_pmd_vfio_platform.h | 40 +++++++++++
 drivers/raw/vfio_platform/version.map         |  2 +
 drivers/raw/vfio_platform/vfio_platform.c     | 67 +++++++++++++++++++
 3 files changed, 109 insertions(+)

diff --git a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h 
b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
index 377cebde08..e1c194c46d 100644
--- a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
+++ b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
@@ -82,6 +82,46 @@ __rte_experimental
 int
 rte_pmd_vfio_platform_container_destroy(int container);
 
+/**
+ * Map DMA memory.
+ *
+ * @param dev_id
+ *   Device identifier.
+ * @param addr
+ *   Virtual address to map.
+ * @param iova
+ *   IOVA address to map.
+ * @param len
+ *   Length of the memory segment being mapped.
+ *
+ * @return
+ *   0 on success
+ *   <0 on failure and rte_errno is set
+ */
+__rte_experimental
+int
+rte_pmd_vfio_platform_dma_map(uint16_t dev_id, void *addr, uint64_t iova, 
size_t len);
+
+/**
+ * Remove DMA memory mapping.
+ *
+ * @param dev_id
+ *   Device identifier.
+ * @param addr
+ *   Virtual address to map.
+ * @param iova
+ *   IOVA address to map.
+ * @param len
+ *   Length of the memory segment being mapped.
+ *
+ * @return
+ *   0 on success
+ *   <0 on failure and rte_errno is set
+ */
+__rte_experimental
+int
+rte_pmd_vfio_platform_dma_unmap(uint16_t dev_id, void *addr, uint64_t iova, 
size_t len);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/drivers/raw/vfio_platform/version.map 
b/drivers/raw/vfio_platform/version.map
index 2aea50f4c1..1b54459183 100644
--- a/drivers/raw/vfio_platform/version.map
+++ b/drivers/raw/vfio_platform/version.map
@@ -7,4 +7,6 @@ EXPERIMENTAL {
 
        rte_pmd_vfio_platform_container_create;
        rte_pmd_vfio_platform_container_destroy;
+       rte_pmd_vfio_platform_dma_map;
+       rte_pmd_vfio_platform_dma_unmap;
 };
diff --git a/drivers/raw/vfio_platform/vfio_platform.c 
b/drivers/raw/vfio_platform/vfio_platform.c
index 8148dce06b..966f9f177e 100644
--- a/drivers/raw/vfio_platform/vfio_platform.c
+++ b/drivers/raw/vfio_platform/vfio_platform.c
@@ -94,6 +94,45 @@ rte_pmd_vfio_platform_container_destroy(int container)
        return 0;
 }
 
+static struct rte_rawdev *
+rawdev_from_dev_id(uint16_t dev_id)
+{
+       if (!rte_rawdev_pmd_is_valid_dev(dev_id))
+               return NULL;
+
+       return &rte_rawdevs[dev_id];
+}
+
+int
+rte_pmd_vfio_platform_dma_map(uint16_t dev_id, void *addr, uint64_t iova, 
size_t len)
+{
+       struct rte_rawdev *rawdev;
+
+       rawdev = rawdev_from_dev_id(dev_id);
+       if (!rawdev) {
+               rte_errno = ENODEV;
+
+               return -1;
+       }
+
+       return rte_dev_dma_map(rawdev->device, addr, iova, len);
+}
+
+int
+rte_pmd_vfio_platform_dma_unmap(uint16_t dev_id, void *addr, uint64_t iova, 
size_t len)
+{
+       struct rte_rawdev *rawdev;
+
+       rawdev = rawdev_from_dev_id(dev_id);
+       if (!rawdev) {
+               rte_errno = ENODEV;
+
+               return -1;
+       }
+
+       return rte_dev_dma_unmap(rawdev->device, addr, iova, len);
+}
+
 static int
 vfio_rawdev_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info,
                         size_t dev_private_size)
@@ -371,9 +410,37 @@ vfio_platform_remove(struct rte_platform_device *pdev)
        return ret;
 }
 
+static int
+vfio_platform_dma_map(struct rte_platform_device *pdev, void *addr, uint64_t 
iova, size_t len)
+{
+       struct vfio_platform *plat = pdev->driver_data;
+       int ret;
+
+       ret = rte_vfio_container_dma_map(container_fd(plat->container), 
(uint64_t)addr, iova, len);
+       if (ret)
+               return -EFAULT;
+
+       return 0;
+}
+
+static int
+vfio_platform_dma_unmap(struct rte_platform_device *pdev, void *addr, uint64_t 
iova, size_t len)
+{
+       struct vfio_platform *plat = pdev->driver_data;
+       int ret;
+
+       ret = rte_vfio_container_dma_unmap(container_fd(plat->container), 
(uint64_t)addr, iova, len);
+       if (ret)
+               return -EFAULT;
+
+       return 0;
+}
+
 static struct rte_platform_driver vfio_platform = {
        .probe = vfio_platform_probe,
        .remove = vfio_platform_remove,
+       .dma_map = vfio_platform_dma_map,
+       .dma_unmap = vfio_platform_dma_unmap,
 };
 
 RTE_PMD_REGISTER_PLATFORM(vfio_platform, vfio_platform);
-- 
2.25.1

Reply via email to