[3/4] bus/vdev: add DMA mapping supprt
Checks
Commit Message
This patch enables VDEVs to implement their own DMA map
and unmap callbacks.
It will be used by Virtio-user PMD to support external
memory registered by applications like Seastar or VPP.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
drivers/bus/vdev/rte_bus_vdev.h | 24 ++++++++++++++++
drivers/bus/vdev/vdev.c | 50 +++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+)
@@ -53,6 +53,18 @@ rte_vdev_device_args(const struct rte_vdev_device *dev)
/** Double linked list of virtual device drivers. */
TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
+/**
+ * Virtual device DMA map function.
+ */
+typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
+ uint64_t iova, size_t len);
+
+/**
+ * Virtual device DMA unmap function.
+ */
+typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
+ uint64_t iova, size_t len);
+
/**
* Probe function called for each virtual device driver once.
*/
@@ -69,10 +81,22 @@ typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
struct rte_vdev_driver {
TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherited general driver. */
+ rte_vdev_dma_map_t *dma_map; /**<Virtual device DMA map function. */
+ rte_vdev_dma_unmap_t *dma_unmap; /**<Virtual device DMA unmap function. */
rte_vdev_probe_t *probe; /**< Virtual device probe function. */
rte_vdev_remove_t *remove; /**< Virtual device remove function. */
};
+/**
+ * @internal
+ * Helper macro for drivers that need to convert to struct rte_vdev_driver.
+ */
+#define RTE_DRV_TO_VDRV(ptr) \
+ container_of(ptr, struct rte_vdev_driver, driver)
+
+#define RTE_DRV_TO_VDRV_CONST(ptr) \
+ container_of(ptr, const struct rte_vdev_driver, driver)
+
/**
* Register a virtual device driver.
*
@@ -546,6 +546,54 @@ vdev_unplug(struct rte_device *dev)
return rte_vdev_uninit(dev->name);
}
+static int
+vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+ struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+ const struct rte_vdev_driver *vdrv;
+
+ if (!dev || !dev->driver) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver);
+ if (!vdrv) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ if (vdrv->dma_map)
+ return vdrv->dma_map(vdev, addr, iova, len);
+
+ rte_errno = ENOTSUP;
+ return -1;
+}
+
+static int
+vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+ struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+ const struct rte_vdev_driver *vdrv;
+
+ if (!dev || !dev->driver) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver);
+ if (!vdrv) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ if (vdrv->dma_map)
+ return vdrv->dma_unmap(vdev, addr, iova, len);
+
+ rte_errno = ENOTSUP;
+ return -1;
+}
+
static struct rte_bus rte_vdev_bus = {
.scan = vdev_scan,
.probe = vdev_probe,
@@ -553,6 +601,8 @@ static struct rte_bus rte_vdev_bus = {
.plug = vdev_plug,
.unplug = vdev_unplug,
.parse = vdev_parse,
+ .dma_map = vdev_dma_map,
+ .dma_unmap = vdev_dma_unmap,
.dev_iterate = rte_vdev_dev_iterate,
};