Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ns: acknowledge the received creation message #608

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/system/linux/machine/generic/platform_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int sk_unix_client(const char *descr)

memset(&addr, 0, sizeof addr);
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, descr + strlen(UNIX_PREFIX),
strlcpy(addr.sun_path, descr + strlen(UNIX_PREFIX),
sizeof addr.sun_path);
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) >= 0) {
printf("connected to %s\r\n", descr + strlen(UNIX_PREFIX));
Expand All @@ -178,7 +178,7 @@ static int sk_unix_server(const char *descr)
fd = socket(AF_UNIX, SOCK_STREAM, 0);

addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, descr + strlen(UNIXS_PREFIX),
strlcpy(addr.sun_path, descr + strlen(UNIXS_PREFIX),
sizeof addr.sun_path);
unlink(addr.sun_path);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
Expand Down
8 changes: 8 additions & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef void (*rpmsg_ept_release_cb)(struct rpmsg_endpoint *ept);
typedef void (*rpmsg_ns_unbind_cb)(struct rpmsg_endpoint *ept);
typedef void (*rpmsg_ns_bind_cb)(struct rpmsg_device *rdev,
const char *name, uint32_t dest);
typedef int (*rpmsg_notify_wait_cb)(struct rpmsg_device *rdev, uint32_t id);

/**
* @brief Structure that binds a local RPMsg address to its user
Expand Down Expand Up @@ -150,11 +151,18 @@ struct rpmsg_device {
/** Callback handler for name service announcement, called when remote ept is destroyed */
rpmsg_ns_bind_cb ns_unbind_cb;

/** callback handler for rpmsg service, called when service can't get tx buffer */
rpmsg_notify_wait_cb notify_wait_cb;

/** RPMsg device operations */

struct rpmsg_device_ops ops;

/** Create/destroy namespace message */
bool support_ns;

/** Ack namespace message */
bool support_ack;
};

/**
Expand Down
1 change: 1 addition & 0 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C" {

/* The feature bitmap for virtio rpmsg */
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
#define VIRTIO_RPMSG_F_ACK 1 /* RP supports name service acknowledge */

#ifdef VIRTIO_CACHED_BUFFERS
#warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE"
Expand Down
2 changes: 1 addition & 1 deletion lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void remoteproc_init_mem(struct remoteproc_mem *mem, const char *name,
if (!mem || !io || size == 0)
return;
if (name)
strncpy(mem->name, name, sizeof(mem->name));
strlcpy(mem->name, name, sizeof(mem->name));
else
mem->name[0] = 0;
mem->pa = pa;
Expand Down
17 changes: 14 additions & 3 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags)

ns_msg.flags = flags;
ns_msg.addr = ept->addr;
strncpy(ns_msg.name, ept->name, sizeof(ns_msg.name));
strlcpy(ns_msg.name, ept->name, sizeof(ns_msg.name));
ret = rpmsg_send_offchannel_raw(ept, ept->addr,
RPMSG_NS_EPT_ADDR,
&ns_msg, sizeof(ns_msg), true);
Expand Down Expand Up @@ -305,7 +305,7 @@ void rpmsg_register_endpoint(struct rpmsg_device *rdev,
rpmsg_ept_cb cb,
rpmsg_ns_unbind_cb ns_unbind_cb, void *priv)
{
strncpy(ept->name, name ? name : "", sizeof(ept->name));
strlcpy(ept->name, name ? name : "", sizeof(ept->name));
ept->refcnt = 1;
ept->addr = src;
ept->dest_addr = dest;
Expand Down Expand Up @@ -357,10 +357,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
rpmsg_register_endpoint(rdev, ept, name, addr, dest, cb, unbind_cb, ept->priv);
metal_mutex_release(&rdev->lock);

/* Send NS announcement to remote processor */
/* Send NS announcement/acknowledge to remote processor */
if (ept->name[0] && rdev->support_ns &&
ept->dest_addr == RPMSG_ADDR_ANY)
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE);
else if (ept->name[0] && rdev->support_ack &&
ept->dest_addr != RPMSG_ADDR_ANY)
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK);

if (status)
rpmsg_unregister_endpoint(ept);
Expand All @@ -385,3 +388,11 @@ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
(void)rpmsg_send_ns_message(ept, RPMSG_NS_DESTROY);
rpmsg_unregister_endpoint(ept);
}

int rpmsg_notify_wait(struct rpmsg_device *rdev, uint32_t id)
{
if (rdev->notify_wait_cb)
return rdev->notify_wait_cb(rdev, id);

return RPMSG_ERR_NXIO;
}
4 changes: 4 additions & 0 deletions lib/rpmsg/rpmsg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
RPMSG_NS_CREATE = 0,
/** A known remote service was just destroyed */
RPMSG_NS_DESTROY = 1,
/** Aknowledge the previous creation message*/

Check warning on line 47 in lib/rpmsg/rpmsg_internal.h

View workflow job for this annotation

GitHub Actions / checkpatch review

TYPO_SPELLING

lib/rpmsg/rpmsg_internal.h:47 'Aknowledge' may be misspelled - perhaps 'Acknowledge'?
RPMSG_NS_CREATE_ACK = 2,
};

/**
Expand Down Expand Up @@ -108,6 +110,8 @@
return rpmsg_get_endpoint(rdev, NULL, addr, RPMSG_ADDR_ANY);
}

int rpmsg_notify_wait(struct rpmsg_device *rdev, uint32_t id);

/**
* @internal
*
Expand Down
22 changes: 14 additions & 8 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,14 @@ static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev,
metal_mutex_release(&rdev->lock);
}

static int rpmsg_virtio_notify_wait(struct rpmsg_virtio_device *rvdev, struct virtqueue *vq)
static int rpmsg_virtio_notify_wait(struct rpmsg_virtio_device *rvdev,
struct virtqueue *vq)
{
struct virtio_vring_info *vring_info;

vring_info = &rvdev->vdev->vrings_info[vq->vq_queue_index];

if (!rvdev->notify_wait_cb)
return RPMSG_EOPNOTSUPP;

return rvdev->notify_wait_cb(&rvdev->rdev, vring_info->notifyid);
return rpmsg_notify_wait(&rvdev->rdev, vring_info->notifyid);
}

static void *rpmsg_virtio_get_tx_payload_buffer(struct rpmsg_device *rdev,
Expand Down Expand Up @@ -656,7 +654,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
*/
ept_to_release = _ept && _ept->release_cb;

if (ns_msg->flags & RPMSG_NS_DESTROY) {
if (ns_msg->flags == RPMSG_NS_DESTROY) {
if (_ept)
_ept->dest_addr = RPMSG_ADDR_ANY;
if (ept_to_release)
Expand All @@ -671,7 +669,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
rpmsg_ept_decref(_ept);
metal_mutex_release(&rdev->lock);
}
} else {
} else if (ns_msg->flags == RPMSG_NS_CREATE) {
if (!_ept) {
/*
* send callback to application, that can
Expand All @@ -685,7 +683,14 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
} else {
_ept->dest_addr = dest;
metal_mutex_release(&rdev->lock);
if (_ept->name[0] && rdev->support_ack)
rpmsg_send_ns_message(_ept, RPMSG_NS_CREATE_ACK);
}
} else { /* RPMSG_NS_CREATE_ACK */
/* save the received destination address */
if (_ept)
_ept->dest_addr = dest;
metal_mutex_release(&rdev->lock);
}

return RPMSG_SUCCESS;
Expand Down Expand Up @@ -828,6 +833,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
if (status)
return status;
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));
rdev->support_ack = !!(features & (1 << VIRTIO_RPMSG_F_ACK));

if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) {
/*
Expand Down Expand Up @@ -926,7 +932,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
* Create name service announcement endpoint if device supports name
* service announcement feature.
*/
if (rdev->support_ns) {
if (rdev->support_ns || rdev->support_ack) {
rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS",
RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR,
rpmsg_virtio_ns_callback, NULL, rvdev);
Expand Down
Loading