Skip to content

Commit bea9b79

Browse files
arnopoandersson
authored andcommitted
rpmsg: char: Add possibility to use default endpoint of the rpmsg device
Current implementation create/destroy a new endpoint on each rpmsg_eptdev_open/rpmsg_eptdev_release calls. For a rpmsg device created by the NS announcement a default endpoint is created. In this case we have to reuse the default rpmsg device endpoint associated to the channel instead of creating a new one. 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 default_ept field in rpmsg_eptdev structure.This pointer determines the behavior on rpmsg_eptdev_open and rpmsg_eptdev_release call. - If default_ept == NULL: 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 default_ept is set: use the rpmsg device default endpoint for the communication. Add protection in rpmsg_eptdev_ioctl to prevent to destroy a default endpoint. Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220124102524.295783-10-arnaud.pouliquen@foss.st.com
1 parent cc9da7d commit bea9b79

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static DEFINE_IDA(rpmsg_minor_ida);
5050
* @queue_lock: synchronization of @queue operations
5151
* @queue: incoming message queue
5252
* @readq: wait object for incoming queue
53+
* @default_ept: set to channel default endpoint if the default endpoint should be re-used
54+
* on device open to prevent endpoint address update.
5355
*/
5456
struct rpmsg_eptdev {
5557
struct device dev;
@@ -60,10 +62,12 @@ struct rpmsg_eptdev {
6062

6163
struct mutex ept_lock;
6264
struct rpmsg_endpoint *ept;
65+
struct rpmsg_endpoint *default_ept;
6366

6467
spinlock_t queue_lock;
6568
struct sk_buff_head queue;
6669
wait_queue_head_t readq;
70+
6771
};
6872

6973
int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
@@ -121,7 +125,15 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
121125

122126
get_device(dev);
123127

124-
ept = rpmsg_create_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo);
128+
/*
129+
* If the default_ept is set, the rpmsg device default endpoint is used.
130+
* Else a new endpoint is created on open that will be destroyed on release.
131+
*/
132+
if (eptdev->default_ept)
133+
ept = eptdev->default_ept;
134+
else
135+
ept = rpmsg_create_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo);
136+
125137
if (!ept) {
126138
dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
127139
put_device(dev);
@@ -142,7 +154,8 @@ static int rpmsg_eptdev_release(struct inode *inode, struct file *filp)
142154
/* Close the endpoint, if it's not already destroyed by the parent */
143155
mutex_lock(&eptdev->ept_lock);
144156
if (eptdev->ept) {
145-
rpmsg_destroy_ept(eptdev->ept);
157+
if (!eptdev->default_ept)
158+
rpmsg_destroy_ept(eptdev->ept);
146159
eptdev->ept = NULL;
147160
}
148161
mutex_unlock(&eptdev->ept_lock);
@@ -272,6 +285,10 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd,
272285
if (cmd != RPMSG_DESTROY_EPT_IOCTL)
273286
return -EINVAL;
274287

288+
/* Don't allow to destroy a default endpoint. */
289+
if (eptdev->default_ept)
290+
return -EINVAL;
291+
275292
return rpmsg_chrdev_eptdev_destroy(&eptdev->dev, NULL);
276293
}
277294

0 commit comments

Comments
 (0)