DPDK patches and discussions
 help / color / mirror / Atom feed
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 6/7] raw/vfio_platform: support rawdev device info
Date: Fri, 23 Dec 2022 00:24:34 +0100	[thread overview]
Message-ID: <20221222232436.643514-7-tduszynski@marvell.com> (raw)
In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com>

Add support for querying rawdev device info.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 .../raw/vfio_platform/rte_pmd_vfio_platform.h | 34 ++++++++++++++
 drivers/raw/vfio_platform/vfio_platform.c     | 45 +++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
index b595171af6..377cebde08 100644
--- a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
+++ b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h
@@ -17,6 +17,40 @@
 extern "C" {
 #endif
 
+#include <rte_compat.h>
+#include <rte_dev.h>
+
+/**
+ * vfio platform device region info
+ *
+ * Caller uses that to retrieve information about device memory regions.
+ * Caller provides either resource name or an index, both of which can
+ * be extracted from the device tree. The former is equivalent to
+ * 'reg-names' property while the latter is a 0-based index into 'reg'
+ * array.
+ */
+struct vfio_platform_dev_region_info {
+	/**< mmapped memory resource */
+	struct rte_mem_resource mem;
+	/**< name of the resource */
+	const char *name;
+	/**< index of the resource */
+	int index;
+};
+
+enum vfio_platform_info {
+	INFO_REGION_INDEX,
+	INFO_REGION_NAME,
+};
+
+/**< vfio platform device info */
+struct vfio_platform_dev_info {
+	/**< Type of device info */
+	enum vfio_platform_info type;
+	/**< Memory region info */
+	struct vfio_platform_dev_region_info reg_info;
+};
+
 /** vfio platform device configuration */
 struct vfio_platform_dev_config {
 	/** logical value representing the vfio container */
diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c
index ab5b96a0b0..8148dce06b 100644
--- a/drivers/raw/vfio_platform/vfio_platform.c
+++ b/drivers/raw/vfio_platform/vfio_platform.c
@@ -94,6 +94,50 @@ rte_pmd_vfio_platform_container_destroy(int container)
 	return 0;
 }
 
+static int
+vfio_rawdev_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info,
+			 size_t dev_private_size)
+{
+	struct vfio_platform_dev_info *info = (struct vfio_platform_dev_info *)dev_info;
+	struct vfio_platform_dev_region_info *reg_info = &info->reg_info;
+	struct vfio_platform *plat = dev->dev_private;
+	int i;
+
+	if (dev_private_size != sizeof(*info))
+		return -EINVAL;
+
+	if (plat->num_resource == 0)
+		return -ENODATA;
+
+	switch (info->type) {
+	case INFO_REGION_INDEX:
+		if (reg_info->index < 0 || reg_info->index >= plat->num_resource)
+			return -EINVAL;
+
+		i = reg_info->index;
+		break;
+	case INFO_REGION_NAME:
+		if (!reg_info->name)
+			return -EINVAL;
+
+		for (i = 0; i < plat->num_resource; i++) {
+			if (!strcmp(reg_info->name, plat->resource[i].name))
+				break;
+		}
+
+		if (i == plat->num_resource)
+			return -ENODATA;
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	memcpy(&reg_info->mem, &plat->resource[i].mem, sizeof(reg_info->mem));
+
+	return 0;
+}
+
 static char *
 of_resource_name(const char *dev_name, int index)
 {
@@ -277,6 +321,7 @@ vfio_rawdev_dev_close(struct rte_rawdev *dev)
 }
 
 static const struct rte_rawdev_ops vfio_platform_rawdev_ops = {
+	.dev_info_get = vfio_rawdev_dev_info_get,
 	.dev_configure = vfio_rawdev_dev_configure,
 	.dev_close = vfio_rawdev_dev_close,
 };
-- 
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 ` [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 ` Tomasz Duszynski [this message]
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-7-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 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).