diff mbox series

[v8,13/13] rpmsg: core: Send a ns announcement when a default endpoint is created

Message ID 20211207080843.21222-14-arnaud.pouliquen@foss.st.com (mailing list archive)
State Superseded
Headers show
Series Restructure the rpmsg_char driver and introduce rpmsg_ctrl driver | expand

Commit Message

Arnaud POULIQUEN Dec. 7, 2021, 8:08 a.m. UTC
When a channel is created by user space application with the
RPMSG_CREATE_DEV_IOCTL controls, a ns announcement has to be sent
(depending on backend) to inform the remote side that a new service
is available.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
 drivers/rpmsg/rpmsg_core.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 3f86512147e8..27aad6baf7c5 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -145,6 +145,9 @@  EXPORT_SYMBOL(rpmsg_destroy_ept);
  *
  * This function returns a pointer to an endpoint created and assigned as the default
  * endpoint of the rpmsg device.
+ * If we need to, we also announce about this channel to the remote
+ * processor. This announcement is needed in case the driver is exposing an rpmsg service that has
+ * been created locally.
  *
  * Drivers should provide their @rpdev channel (so the new endpoint would belong
  * to the same remote processor their channel belongs to), an rx callback
@@ -161,6 +164,7 @@  struct rpmsg_endpoint *rpmsg_create_default_ept(struct rpmsg_device *rpdev,
 						struct rpmsg_channel_info chinfo)
 {
 	struct rpmsg_endpoint *ept;
+	int err;
 
 	if (WARN_ON(!rpdev))
 		return NULL;
@@ -183,6 +187,17 @@  struct rpmsg_endpoint *rpmsg_create_default_ept(struct rpmsg_device *rpdev,
 	rpdev->ept = ept;
 	rpdev->src = ept->addr;
 
+	if (rpdev->ops->announce_create) {
+		err = rpdev->ops->announce_create(rpdev);
+		if (err) {
+			rpmsg_destroy_ept(ept);
+			rpdev->ept = NULL;
+			rpdev->src = RPMSG_ADDR_ANY;
+
+			return NULL;
+		}
+	}
+
 	return ept;
 }
 EXPORT_SYMBOL(rpmsg_create_default_ept);