From: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
Ohad Ben-Cohen <ohad@wizery.com>,
Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: <linux-remoteproc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<arnaud.pouliquen@foss.st.com>
Subject: [PATCH v3 4/6] rpmsg: char: Add possibility to create and reuse default endpoint
Date: Thu, 29 Apr 2021 15:55:05 +0200 [thread overview]
Message-ID: <20210429135507.8264-5-arnaud.pouliquen@foss.st.com> (raw)
In-Reply-To: <20210429135507.8264-1-arnaud.pouliquen@foss.st.com>
This patch prepares the introduction of a rpmsg channel device for the
char device. The rpmsg channel device will require a default endpoint to
communicate to the remote processor.
Add the use_default_ept field in rpmsg_eptdev structure. This boolean
determines the behavior on rpmsg_eptdev_open and rpmsg_eptdev_release call.
- If use_default_ept == false:
Use the legacy behavior by creating a new endpoint each time
rpmsg_eptdev_open is called and release it when rpmsg_eptdev_release
is called on /dev/rpmsgX device open/close.
- if use_default_ept == true:
create a endpoint only on first rpmsg_eptdev_open call (if no default
endpoint already exists) and associate it to the default endpoint.
The endpoint is released when the rpmsg device is removed.
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
Update from V2
This patch is a merge of two patches proposed in V2
rpmsg: char: Introduce __rpmsg_chrdev_create_eptdev function
rpmsg: char: No dynamic endpoint management for the default one
With the introduction of the use_default_ept to determine the behaviour
on rpmsg_eptdev_open/release.
---
drivers/rpmsg/rpmsg_char.c | 46 +++++++++++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 3b07a050b75e..5c6a7da6e4d7 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -38,6 +38,8 @@ static DEFINE_IDA(rpmsg_minor_ida);
* @queue_lock: synchronization of @queue operations
* @queue: incoming message queue
* @readq: wait object for incoming queue
+ * @use_default_ept: specify if the endpoint has to be created at each device opening or
+ * if the default endpoint should be reused.
*/
struct rpmsg_eptdev {
struct device dev;
@@ -52,6 +54,8 @@ struct rpmsg_eptdev {
spinlock_t queue_lock;
struct sk_buff_head queue;
wait_queue_head_t readq;
+
+ bool use_default_ept;
};
int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
@@ -109,11 +113,29 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
get_device(dev);
- ept = rpmsg_create_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo);
- if (!ept) {
- dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
- put_device(dev);
- return -EINVAL;
+ /*
+ * If the rpmsg device default endpoint is used, create it only the first time then reuse
+ * it. Else a new endpoint is created on open that will be destroyed on release.
+ */
+ if (eptdev->use_default_ept && rpdev->ept) {
+ ept = rpdev->ept;
+ } else {
+ ept = rpmsg_create_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo);
+ if (!ept) {
+ dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
+ put_device(dev);
+ return -EINVAL;
+ }
+
+ if (eptdev->use_default_ept) {
+ /*
+ * Assign the new endpoint as default endpoint and update the channel
+ * info source to reflect the allocation in the rpmsg class.
+ */
+ rpdev->ept = ept;
+ rpdev->src = ept->addr;
+ eptdev->chinfo.src = rpdev->src;
+ }
}
eptdev->ept = ept;
@@ -130,7 +152,8 @@ static int rpmsg_eptdev_release(struct inode *inode, struct file *filp)
/* Close the endpoint, if it's not already destroyed by the parent */
mutex_lock(&eptdev->ept_lock);
if (eptdev->ept) {
- rpmsg_destroy_ept(eptdev->ept);
+ if (!eptdev->use_default_ept)
+ rpmsg_destroy_ept(eptdev->ept);
eptdev->ept = NULL;
}
mutex_unlock(&eptdev->ept_lock);
@@ -316,8 +339,8 @@ static void rpmsg_eptdev_release_device(struct device *dev)
kfree(eptdev);
}
-int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
- struct rpmsg_channel_info chinfo)
+static int __rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo, bool use_default_ept)
{
struct rpmsg_eptdev *eptdev;
struct device *dev;
@@ -330,6 +353,7 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
dev = &eptdev->dev;
eptdev->rpdev = rpdev;
eptdev->chinfo = chinfo;
+ eptdev->use_default_ept = use_default_ept;
mutex_init(&eptdev->ept_lock);
spin_lock_init(&eptdev->queue_lock);
@@ -381,6 +405,12 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
return ret;
}
+
+int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo)
+{
+ return __rpmsg_chrdev_eptdev_create(rpdev, parent, chinfo, false);
+}
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
static int rpmsg_chrdev_init(void)
--
2.17.1
next prev parent reply other threads:[~2021-04-29 13:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 13:55 [PATCH v3 0/6] Restructure the rpmsg char and introduce the rpmsg-raw channel Arnaud Pouliquen
2021-04-29 13:55 ` [PATCH v3 1/6] rpmsg: char: Export eptdev create an destroy functions Arnaud Pouliquen
2021-05-04 15:52 ` Mathieu Poirier
2021-04-29 13:55 ` [PATCH v3 2/6] rpmsg: Move the rpmsg control device from rpmsg_char to rpmsg_ctrl Arnaud Pouliquen
2021-05-04 16:09 ` Mathieu Poirier
2021-04-29 13:55 ` [PATCH v3 3/6] rpmsg: Update rpmsg_chrdev_register_device function Arnaud Pouliquen
2021-05-04 16:14 ` Mathieu Poirier
2021-04-29 13:55 ` Arnaud Pouliquen [this message]
2021-04-29 13:55 ` [PATCH v3 5/6] rpmsg: char: Introduce a rpmsg driver for the rpmsg char device Arnaud Pouliquen
2021-05-05 16:41 ` Mathieu Poirier
2021-05-05 18:25 ` Arnaud POULIQUEN
2021-05-06 16:11 ` Mathieu Poirier
2021-05-07 9:30 ` Arnaud POULIQUEN
2021-05-07 16:31 ` Mathieu Poirier
2021-05-17 10:04 ` Arnaud POULIQUEN
2021-05-17 15:47 ` Mathieu Poirier
2021-05-07 8:17 ` Julien Massot
2021-05-07 16:35 ` Mathieu Poirier
2021-04-29 13:55 ` [PATCH v3 6/6] rpmsg: char: Return error if user tries to destroy a default endpoint Arnaud Pouliquen
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=20210429135507.8264-5-arnaud.pouliquen@foss.st.com \
--to=arnaud.pouliquen@foss.st.com \
--cc=bjorn.andersson@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mathieu.poirier@linaro.org \
--cc=ohad@wizery.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).