From: Dawei Li <dawei.li@linux.dev>
To: andersson@kernel.org, mathieu.poirier@linaro.org
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
dawei.li@linux.dev, set_pte_at@outlook.com
Subject: [PATCH v4 2/3] rpmsg: char: Implement eptdev based on anonymous inode
Date: Mon, 9 Jun 2025 23:15:30 +0800 [thread overview]
Message-ID: <20250609151531.22621-3-dawei.li@linux.dev> (raw)
In-Reply-To: <20250609151531.22621-1-dawei.li@linux.dev>
Introduce new eptdev abstraction based on anonymous inode. The new API
is exactly same with legacy one except:
- It's anonymous and devnode/path free.
- Its fops->open() is empty.
Signed-off-by: Dawei Li <dawei.li@linux.dev>
---
drivers/rpmsg/rpmsg_char.c | 49 ++++++++++++++++++++++++++++++++++++++
drivers/rpmsg/rpmsg_char.h | 23 ++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 6c19f2146698..babc63cc4238 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -13,6 +13,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/anon_inodes.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
@@ -517,6 +518,54 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
}
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
+static const struct file_operations rpmsg_anonymous_eptdev_fops = {
+ .owner = THIS_MODULE,
+ .release = rpmsg_eptdev_release,
+ .read_iter = rpmsg_eptdev_read_iter,
+ .write_iter = rpmsg_eptdev_write_iter,
+ .poll = rpmsg_eptdev_poll,
+ .unlocked_ioctl = rpmsg_eptdev_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
+};
+
+int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo, unsigned int flags,
+ int *pfd)
+{
+ struct rpmsg_eptdev *eptdev;
+ int ret, fd;
+
+ /* Anonymous inode only supports these file flags */
+ if (flags & ~(O_ACCMODE | O_NONBLOCK | O_CLOEXEC))
+ return -EINVAL;
+
+ eptdev = rpmsg_eptdev_alloc(rpdev, parent, false);
+ if (IS_ERR(eptdev))
+ return PTR_ERR(eptdev);
+
+ ret = rpmsg_eptdev_add(eptdev, chinfo, false);
+ if (ret) {
+ dev_err(&eptdev->dev, "failed to add %s\n", eptdev->chinfo.name);
+ return ret;
+ }
+
+ fd = anon_inode_getfd("rpmsg-eptdev", &rpmsg_anonymous_eptdev_fops, eptdev, flags);
+ if (fd < 0) {
+ put_device(&eptdev->dev);
+ return fd;
+ }
+
+ mutex_lock(&eptdev->ept_lock);
+ ret = __rpmsg_eptdev_open(eptdev);
+ mutex_unlock(&eptdev->ept_lock);
+
+ if (!ret)
+ *pfd = fd;
+
+ return ret;
+}
+EXPORT_SYMBOL(rpmsg_anonymous_eptdev_create);
+
static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
{
struct rpmsg_channel_info chinfo;
diff --git a/drivers/rpmsg/rpmsg_char.h b/drivers/rpmsg/rpmsg_char.h
index 117d9cbc52f0..70ce2c511f13 100644
--- a/drivers/rpmsg/rpmsg_char.h
+++ b/drivers/rpmsg/rpmsg_char.h
@@ -19,6 +19,22 @@
int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
struct rpmsg_channel_info chinfo);
+/**
+ * rpmsg_anonymous_eptdev_create() - register anonymous device and its associated
+ * fd based on an endpoint
+ * @rpdev: prepared rpdev to be used for creating endpoints
+ * @parent: parent device
+ * @chinfo: associated endpoint channel information.
+ * @flag: file flag
+ * @pfd: fd in represent of endpoint device
+ *
+ * This function create a new rpmsg endpoint device and its associated fd to instantiate a new
+ * endpoint based on chinfo information.
+ */
+int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo, unsigned int flags,
+ int *pfd);
+
/**
* rpmsg_chrdev_eptdev_destroy() - destroy created char device endpoint.
* @data: private data associated to the endpoint device
@@ -36,6 +52,13 @@ static inline int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct
return -ENXIO;
}
+static inline int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo,
+ unsigned int flags, int *pfd)
+{
+ return -ENXIO;
+}
+
static inline int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
{
return -ENXIO;
--
2.25.1
next prev parent reply other threads:[~2025-06-09 15:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 15:15 [PATCH v4 0/3] rpmsg: Introduce RPMSG_CREATE_EPT_FD_IOCTL uAPI Dawei Li
2025-06-09 15:15 ` [PATCH v4 1/3] rpmsg: char: Reuse eptdev logic for anonymous device Dawei Li
2025-06-09 15:15 ` Dawei Li [this message]
2025-06-09 15:15 ` [PATCH v4 3/3] rpmsg: ctrl: Introduce RPMSG_CREATE_EPT_FD_IOCTL uAPI Dawei Li
2025-06-18 13:07 ` [PATCH v4 0/3] rpmsg: " Arnaud POULIQUEN
2025-06-19 14:43 ` Dawei Li
2025-06-20 7:52 ` Arnaud POULIQUEN
2025-06-22 4:12 ` Dawei Li
2025-06-30 7:54 ` Arnaud POULIQUEN
2025-07-01 14:16 ` Dawei Li
2025-07-02 7:48 ` Arnaud POULIQUEN
2025-07-03 13:35 ` Dawei Li
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=20250609151531.22621-3-dawei.li@linux.dev \
--to=dawei.li@linux.dev \
--cc=andersson@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=set_pte_at@outlook.com \
/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).