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

Support the two phase creation handshake #160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ struct rpmsg_device {

/** Create/destroy namespace message */
bool support_ns;
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
5 changes: 4 additions & 1 deletion lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
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, NULL);
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 Down
2 changes: 2 additions & 0 deletions lib/rpmsg/rpmsg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum rpmsg_ns_flags {
RPMSG_NS_CREATE = 0,
/** A known remote service was just destroyed */
RPMSG_NS_DESTROY = 1,
/** Acknowledge the previous creation message */
RPMSG_NS_CREATE_ACK = 2,
};

/**
Expand Down
16 changes: 13 additions & 3 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,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 +671,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 +685,15 @@ 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);
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
}

return RPMSG_SUCCESS;
Expand Down Expand Up @@ -827,7 +835,9 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
status = virtio_get_features(rvdev->vdev, &features);
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 +936,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) {
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
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