Skip to content

Commit

Permalink
shouldn't generate any namespace message if the endpoint name is empty
Browse files Browse the repository at this point in the history
and add rpmsg_create_anon_ept to simplify the anonymous endpoint creation

Signed-off-by: Xiang Xiao <[email protected]>
  • Loading branch information
xiaoxiang781216 committed Feb 2, 2019
1 parent 6cd4215 commit a65a83e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
27 changes: 26 additions & 1 deletion lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a65a83e

Please sign in to comment.