[RFC,2/7] raw/vfio_platform: add driver skeleton
Checks
Commit Message
Add driver skeleton which does not do anything beyond registering driver
itself to platform bus and providing means to create and destroy VFIO
container.
Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
doc/guides/rawdevs/index.rst | 1 +
doc/guides/rawdevs/vfio_platform.rst | 24 ++++++
drivers/raw/meson.build | 1 +
drivers/raw/vfio_platform/meson.build | 16 ++++
.../raw/vfio_platform/rte_pmd_vfio_platform.h | 49 +++++++++++
drivers/raw/vfio_platform/version.map | 10 +++
drivers/raw/vfio_platform/vfio_platform.c | 85 +++++++++++++++++++
7 files changed, 186 insertions(+)
create mode 100644 doc/guides/rawdevs/vfio_platform.rst
create mode 100644 drivers/raw/vfio_platform/meson.build
create mode 100644 drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
create mode 100644 drivers/raw/vfio_platform/version.map
create mode 100644 drivers/raw/vfio_platform/vfio_platform.c
@@ -16,3 +16,4 @@ application through rawdev API.
dpaa2_cmdif
ifpga
ntb
+ vfio_platform
new file mode 100644
@@ -0,0 +1,24 @@
+.. SPDX-License-Identifier: BSD-3-Clause
+ Copyright(c) 2023 Marvell.
+
+VFIO Platform driver
+====================
+
+VFIO platform driver allows to configure and manage kernel VFIO platform devices.
+These devices do not normally have built-in bus discovery capabilities, known
+for example from PCI bus, and reside behind an IOMMU.
+
+Features
+--------
+
+Following features are available:
+
+- bind to devices managed by kernel vfio-platform driver
+- expose device memory resources
+- map/unmap DMA memory
+
+Requirements
+------------
+
+Since PMD is backed by vfio and vfio-platform kernel drivers they need to be enabled
+in kernel config.
@@ -12,5 +12,6 @@ drivers = [
'ifpga',
'ntb',
'skeleton',
+ 'vfio_platform',
]
std_deps = ['rawdev']
new file mode 100644
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(C) 2023 Marvell.
+#
+
+if not is_linux
+ build = false
+ reason = 'only supported on Linux'
+endif
+
+deps += ['bus_platform', 'rawdev']
+sources = files(
+ 'vfio_platform.c',
+)
+headers = files(
+ 'rte_pmd_vfio_platform.h',
+)
new file mode 100644
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Marvell.
+ */
+
+#ifndef _RTE_PMD_VFIO_PLATFORM_H_
+#define _RTE_PMD_VFIO_PLATFORM_H_
+
+/**
+ * @file
+ *
+ * VFIO platform specific structures and interface.
+ *
+ * @b EXPERIMENTAL: this API may change or be removed without prior notice
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Create a new VFIO container.
+ *
+ * @return
+ * container on success
+ * <0 on failure
+ */
+__rte_experimental
+int
+rte_pmd_vfio_platform_container_create(void);
+
+/**
+ * Destroy previously created container.
+ *
+ * @param container
+ * Container to destroy.
+ *
+ * @return
+ * 0 on success
+ * <0 on failure
+ */
+__rte_experimental
+int
+rte_pmd_vfio_platform_container_destroy(int container);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PMD_VFIO_PLATFORM_H_ */
new file mode 100644
@@ -0,0 +1,10 @@
+DPDK_23 {
+ local: *;
+};
+
+EXPERIMENTAL {
+ global:
+
+ rte_pmd_vfio_platform_container_create;
+ rte_pmd_vfio_platform_container_destroy;
+};
new file mode 100644
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Marvell.
+ */
+
+#include <errno.h>
+
+#include <rte_bus_platform.h>
+#include <rte_common.h>
+#include <rte_config.h>
+#include <rte_dev.h>
+#include <rte_errno.h>
+#include <rte_pmd_vfio_platform.h>
+#include <rte_vfio.h>
+
+static struct {
+ int container_fd;
+ int refcnt;
+} container_tbl[RTE_MAX_VFIO_CONTAINERS];
+
+static int
+container_next_free_index(void)
+{
+ int i;
+
+ for (i = 0; i < (int)RTE_DIM(container_tbl); i++) {
+ if (container_tbl[i].refcnt == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+static void
+container_put(int index)
+{
+
+ if (container_tbl[index].refcnt == 0)
+ return;
+
+ if (--container_tbl[index].refcnt == 0)
+ rte_vfio_container_destroy(container_tbl[index].container_fd);
+}
+
+static void
+container_get(int index)
+{
+ container_tbl[index].refcnt++;
+}
+
+int
+rte_pmd_vfio_platform_container_create(void)
+{
+ int index, fd;
+
+ fd = rte_vfio_container_create();
+ if (fd < 0)
+ return -1;
+
+ index = container_next_free_index();
+ if (index < 0)
+ return -ENOSPC;
+
+ container_tbl[index].container_fd = fd;
+ container_get(index);
+
+ return index;
+}
+
+int
+rte_pmd_vfio_platform_container_destroy(int container)
+{
+ if ((unsigned int)container >= RTE_DIM(container_tbl))
+ return -EINVAL;
+
+ container_put(container);
+
+ return 0;
+}
+
+static struct rte_platform_driver vfio_platform = {
+};
+
+RTE_PMD_REGISTER_PLATFORM(vfio_platform, vfio_platform);
+RTE_PMD_REGISTER_ALIAS(vfio_platform, vfio-platform);
+RTE_PMD_REGISTER_KMOD_DEP(vfio_platform, "vfio-platform");