DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomasz Duszynski <tduszynski@marvell.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <jerinj@marvell.com>,
	Tomasz Duszynski <tduszynski@marvell.com>
Subject: [RFC PATCH 7/7] raw/vfio_platform: support DMA map/unmap
Date: Fri, 23 Dec 2022 00:24:35 +0100	[thread overview]
Message-ID: <20221222232436.643514-8-tduszynski@marvell.com> (raw)
In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com>

Add support for DMA map/unmap operations.

Signed-off-by: Tomasz Duszynski <tduszynski@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


  parent reply	other threads:[~2022-12-22 23:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 23:24 [RFC PATCH 0/7] support vfio platform PMD Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 1/7] lib: add helper to read strings from sysfs files Tomasz Duszynski
2022-12-23 16:40   ` Stephen Hemminger
2023-01-11 18:19     ` [EXT] " Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 2/7] raw/vfio_platform: add driver skeleton Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 3/7] raw/vfio_platform: add platform probe and remove Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 4/7] raw/vfio_platform: support rawdev close Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 5/7] raw/vfio_platform: support rawdev configure Tomasz Duszynski
2022-12-22 23:24 ` [RFC PATCH 6/7] raw/vfio_platform: support rawdev device info Tomasz Duszynski
2022-12-22 23:24 ` Tomasz Duszynski [this message]
2022-12-23  7:05 ` [RFC PATCH 0/7] support vfio platform PMD Xia, Chenbo
2023-01-12  8:14   ` Tomasz Duszynski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221222232436.643514-8-tduszynski@marvell.com \
    --to=tduszynski@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).