[RFC,3/7] raw/vfio_platform: add platform probe and remove

Message ID 20221222232436.643514-4-tduszynski@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series support vfio platform PMD |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Tomasz Duszynski Dec. 22, 2022, 11:24 p.m. UTC
  Add platform bus probe and remove.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 drivers/raw/vfio_platform/vfio_platform.c | 56 +++++++++++++++++++++++
 drivers/raw/vfio_platform/vfio_platform.h | 35 ++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 drivers/raw/vfio_platform/vfio_platform.h
  

Patch

diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c
index 93558b310b..b056041892 100644
--- a/drivers/raw/vfio_platform/vfio_platform.c
+++ b/drivers/raw/vfio_platform/vfio_platform.c
@@ -9,9 +9,14 @@ 
 #include <rte_config.h>
 #include <rte_dev.h>
 #include <rte_errno.h>
+#include <rte_log.h>
 #include <rte_pmd_vfio_platform.h>
+#include <rte_rawdev.h>
+#include <rte_rawdev_pmd.h>
 #include <rte_vfio.h>
 
+#include "vfio_platform.h"
+
 static struct {
 	int container_fd;
 	int refcnt;
@@ -77,9 +82,60 @@  rte_pmd_vfio_platform_container_destroy(int container)
 	return 0;
 }
 
+static const struct rte_rawdev_ops vfio_platform_rawdev_ops = {
+};
+
+static int
+vfio_platform_probe(struct rte_platform_device *pdev)
+{
+	struct rte_platform_driver *pdrv = pdev->driver;
+	struct vfio_platform *plat;
+	struct rte_rawdev *rawdev;
+
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	rawdev = rte_rawdev_pmd_allocate(pdev->device.name, sizeof(*plat), rte_socket_id());
+	if (!rawdev)
+		return -ENOMEM;
+
+	rawdev->dev_ops = &vfio_platform_rawdev_ops;
+	rawdev->device = &pdev->device;
+	rawdev->driver_name = pdrv->driver.name;
+
+	plat = rawdev->dev_private;
+	plat->device = pdev;
+
+	pdev->driver_data = plat;
+
+	VFIO_PLATFORM_LOG(INFO, "probed %s\n", pdev->device.name);
+
+	return 0;
+}
+
+static int
+vfio_platform_remove(struct rte_platform_device *pdev)
+{
+	struct rte_rawdev *rawdev;
+	int ret;
+
+	rawdev = rte_rawdev_pmd_get_named_dev(pdev->device.name);
+	if (!rawdev)
+		return -ENODEV;
+
+	ret = rte_rawdev_pmd_release(rawdev);
+	if (ret == 0)
+		VFIO_PLATFORM_LOG(INFO, "removed %s\n", pdev->device.name);
+
+	return ret;
+}
+
 static struct rte_platform_driver vfio_platform = {
+	.probe = vfio_platform_probe,
+	.remove = vfio_platform_remove,
 };
 
 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");
+RTE_LOG_REGISTER_DEFAULT(vfio_platform_logtype, NOTICE);
diff --git a/drivers/raw/vfio_platform/vfio_platform.h b/drivers/raw/vfio_platform/vfio_platform.h
new file mode 100644
index 0000000000..f6b2316a26
--- /dev/null
+++ b/drivers/raw/vfio_platform/vfio_platform.h
@@ -0,0 +1,35 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Marvell.
+ */
+
+#ifndef _VFIO_PLATFORM_H_
+#define _VFIO_PLATFORM_H_
+
+#include <rte_bus_platform.h>
+#include <rte_common.h>
+#include <rte_dev.h>
+#include <rte_log.h>
+
+extern int vfio_platform_logtype;
+
+#define VFIO_PLATFORM_LOG(level, ...) \
+	rte_log(RTE_LOG_ ## level, vfio_platform_logtype, \
+		RTE_FMT("vfio platform: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
+			RTE_FMT_TAIL(__VA_ARGS__,)))
+
+struct vfio_platform_resource {
+	struct rte_mem_resource mem;
+	const char *name;
+};
+
+struct vfio_platform {
+	int dev_fd;
+	int group_fd;
+	int group;
+	int container;
+	struct rte_platform_device *device;
+	struct vfio_platform_resource *resource;
+	int num_resource;
+};
+
+#endif /* _VFIO_PLATFORM_H_ */