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 2/7] raw/vfio_platform: add driver skeleton
Date: Fri, 23 Dec 2022 00:24:30 +0100 [thread overview]
Message-ID: <20221222232436.643514-3-tduszynski@marvell.com> (raw)
In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com>
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
diff --git a/doc/guides/rawdevs/index.rst b/doc/guides/rawdevs/index.rst
index f34315f051..b95c155b48 100644
--- a/doc/guides/rawdevs/index.rst
+++ b/doc/guides/rawdevs/index.rst
@@ -16,3 +16,4 @@ application through rawdev API.
dpaa2_cmdif
ifpga
ntb
+ vfio_platform
diff --git a/doc/guides/rawdevs/vfio_platform.rst b/doc/guides/rawdevs/vfio_platform.rst
new file mode 100644
index 0000000000..97443a85fb
--- /dev/null
+++ b/doc/guides/rawdevs/vfio_platform.rst
@@ -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.
diff --git a/drivers/raw/meson.build b/drivers/raw/meson.build
index 05cad143fe..a3e1126c98 100644
--- a/drivers/raw/meson.build
+++ b/drivers/raw/meson.build
@@ -12,5 +12,6 @@ drivers = [
'ifpga',
'ntb',
'skeleton',
+ 'vfio_platform',
]
std_deps = ['rawdev']
diff --git a/drivers/raw/vfio_platform/meson.build b/drivers/raw/vfio_platform/meson.build
new file mode 100644
index 0000000000..a03836d890
--- /dev/null
+++ b/drivers/raw/vfio_platform/meson.build
@@ -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',
+)
diff --git a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
new file mode 100644
index 0000000000..307a20d9fc
--- /dev/null
+++ b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
@@ -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_ */
diff --git a/drivers/raw/vfio_platform/version.map b/drivers/raw/vfio_platform/version.map
new file mode 100644
index 0000000000..2aea50f4c1
--- /dev/null
+++ b/drivers/raw/vfio_platform/version.map
@@ -0,0 +1,10 @@
+DPDK_23 {
+ local: *;
+};
+
+EXPERIMENTAL {
+ global:
+
+ rte_pmd_vfio_platform_container_create;
+ rte_pmd_vfio_platform_container_destroy;
+};
diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c
new file mode 100644
index 0000000000..93558b310b
--- /dev/null
+++ b/drivers/raw/vfio_platform/vfio_platform.c
@@ -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");
--
2.25.1
next prev 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 ` Tomasz Duszynski [this message]
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 ` [RFC PATCH 7/7] raw/vfio_platform: support DMA map/unmap Tomasz Duszynski
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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.