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 4/7] raw/vfio_platform: support rawdev close
Date: Fri, 23 Dec 2022 00:24:32 +0100	[thread overview]
Message-ID: <20221222232436.643514-5-tduszynski@marvell.com> (raw)
In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com>

Add support for closing raw device allocated during platform probe.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 drivers/raw/vfio_platform/vfio_platform.c | 49 +++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c
index b056041892..ae0572dc99 100644
--- a/drivers/raw/vfio_platform/vfio_platform.c
+++ b/drivers/raw/vfio_platform/vfio_platform.c
@@ -3,6 +3,8 @@
  */
 
 #include <errno.h>
+#include <sys/mman.h>
+#include <unistd.h>
 
 #include <rte_bus_platform.h>
 #include <rte_common.h>
@@ -17,6 +19,8 @@
 
 #include "vfio_platform.h"
 
+#define VFIO_PLATFORM_SYSFS_BASE "/sys/bus/platform/devices"
+
 static struct {
 	int container_fd;
 	int refcnt;
@@ -52,6 +56,12 @@ container_get(int index)
 	container_tbl[index].refcnt++;
 }
 
+static int
+container_fd(int index)
+{
+	return container_tbl[index].container_fd;
+}
+
 int
 rte_pmd_vfio_platform_container_create(void)
 {
@@ -82,7 +92,46 @@ rte_pmd_vfio_platform_container_destroy(int container)
 	return 0;
 }
 
+static void
+device_release_maps(struct vfio_platform *plat)
+{
+	struct vfio_platform_resource *res;
+	int i;
+
+	for (i = 0; i < plat->num_resource; i++) {
+		res = &plat->resource[i];
+		munmap(res->mem.addr, res->mem.len);
+		free((void *)(size_t)res->name);
+	}
+
+	free(plat->resource);
+	plat->resource = NULL;
+	plat->num_resource = 0;
+}
+
+static void
+device_release(struct vfio_platform *plat)
+{
+	device_release_maps(plat);
+	rte_vfio_release_device(VFIO_PLATFORM_SYSFS_BASE, plat->device->name, plat->dev_fd);
+	rte_vfio_container_group_unbind(container_fd(plat->container), plat->group);
+	close(plat->group_fd);
+	rte_vfio_clear_group(plat->group_fd);
+	container_put(plat->container);
+}
+
+static int
+vfio_rawdev_dev_close(struct rte_rawdev *dev)
+{
+	struct vfio_platform *plat = dev->dev_private;
+
+	device_release(plat);
+
+	return 0;
+}
+
 static const struct rte_rawdev_ops vfio_platform_rawdev_ops = {
+	.dev_close = vfio_rawdev_dev_close,
 };
 
 static int
-- 
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 ` Tomasz Duszynski [this message]
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-5-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).