From a65a83e044da0a65c9b2d24e398c8b474e5c0fab Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 2 Feb 2019 14:37:50 +0800 Subject: [PATCH] shouldn't generate any namespace message if the endpoint name is empty and add rpmsg_create_anon_ept to simplify the anonymous endpoint creation Signed-off-by: Xiang Xiao --- lib/include/openamp/rpmsg.h | 27 ++++++++++++++++++++++++++- lib/rpmsg/rpmsg.c | 22 ++++++++++++---------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/include/openamp/rpmsg.h b/lib/include/openamp/rpmsg.h index b7f521351..b4476e3f5 100644 --- a/lib/include/openamp/rpmsg.h +++ b/lib/include/openamp/rpmsg.h @@ -289,7 +289,7 @@ static inline void rpmsg_init_ept(struct rpmsg_endpoint *ept, rpmsg_ept_cb cb, rpmsg_ns_unbind_cb ns_unbind_cb) { - strncpy(ept->name, name, sizeof(ept->name)); + strncpy(ept->name, name ? name : "", sizeof(ept->name)); ept->addr = src; ept->dest_addr = dest; ept->cb = cb; @@ -326,6 +326,31 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev, const char *name, uint32_t src, uint32_t dest, rpmsg_ept_cb cb, rpmsg_ns_unbind_cb ns_unbind_cb); + +/** + * rpmsg_create_anon_ept - like rpmsg_create_ept but without name + * + * Create a RPMsg endpoint, initialize it with source address, + * remoteproc address and endpoint callback, and register it to + * the RPMsg device. + * + * @ept: pointer to rpmsg endpoint + * @src: local address of the endpoint + * @dest: target address of the endpoint + * @cb: endpoint callback + * + * In essence, an rpmsg endpoint represents a listener on the rpmsg bus, as + * it binds an rpmsg address with an rx callback handler. + */ + +static inline int rpmsg_create_anon_ept(struct rpmsg_endpoint *ept, + struct rpmsg_device *rdev, + uint32_t src, uint32_t dest, + rpmsg_ept_cb cb) +{ + return rpmsg_create_ept(ept, rdev, NULL, src, dest, cb, NULL); +} + /** * rpmsg_destroy_ept - destroy rpmsg endpoint and unregister it from rpmsg * device diff --git a/lib/rpmsg/rpmsg.c b/lib/rpmsg/rpmsg.c index 0c5195c8d..66f6267c5 100644 --- a/lib/rpmsg/rpmsg.c +++ b/lib/rpmsg/rpmsg.c @@ -227,15 +227,17 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev, rpmsg_init_ept(ept, name, addr, dest, cb, unbind_cb); rpmsg_register_endpoint(rdev, ept); - /* Send NS announcement to remote processor */ - metal_mutex_release(&rdev->lock); - if (rdev->support_ns && ept->dest_addr == RPMSG_ADDR_ANY) - status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE); - else if (rdev->support_ack && ept->dest_addr != RPMSG_ADDR_ANY) - status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK); - metal_mutex_acquire(&rdev->lock); - if (status) - rpmsg_unregister_endpoint(ept); + if (ept->name[0]) { + /* Send NS announcement to remote processor */ + metal_mutex_release(&rdev->lock); + if (rdev->support_ns && ept->dest_addr == RPMSG_ADDR_ANY) + status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE); + else if (rdev->support_ack && ept->dest_addr != RPMSG_ADDR_ANY) + status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK); + metal_mutex_acquire(&rdev->lock); + if (status) + rpmsg_unregister_endpoint(ept); + } ret_status: metal_mutex_release(&rdev->lock); @@ -258,7 +260,7 @@ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) return; rdev = ept->rdev; - if (rdev->support_ns && ept->addr != RPMSG_NS_EPT_ADDR) + if (ept->name[0] && rdev->support_ns && ept->addr != RPMSG_NS_EPT_ADDR) (void)rpmsg_send_ns_message(ept, RPMSG_NS_DESTROY); metal_mutex_acquire(&rdev->lock); rpmsg_unregister_endpoint(ept);