DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomasz Duszynski <tduszynski@marvell.com>
To: <dev@dpdk.org>, Anatoly Burakov <anatoly.burakov@intel.com>
Cc: <thomas@monjalon.net>, <jerinj@marvell.com>,
	Tomasz Duszynski <tduszynski@marvell.com>
Subject: [RFC PATCH 3/7] raw/vfio_platform: add platform probe and remove
Date: Fri, 23 Dec 2022 00:24:31 +0100	[thread overview]
Message-ID: <20221222232436.643514-4-tduszynski@marvell.com> (raw)
In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com>

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

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_ */
-- 
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 ` Tomasz Duszynski [this message]
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-4-tduszynski@marvell.com \
    --to=tduszynski@marvell.com \
    --cc=anatoly.burakov@intel.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).