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

Add RPMsg API to get buffer size #565

Merged
merged 3 commits into from
Apr 9, 2024
Merged
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/examples/echo/rpmsg-echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ int app(struct rpmsg_device *rdev, void *priv)

LPRINTF("Successfully created rpmsg endpoint.\r\n");

LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while(1) {
platform_poll(priv);
Expand Down
31 changes: 16 additions & 15 deletions apps/examples/echo/rpmsg-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,20 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);

if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
return ret;
}

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
Expand All @@ -116,22 +127,12 @@ int app (struct rpmsg_device *rdev, void *priv)

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);

if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

LPRINTF("RPMsg driver TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg driver RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
Expand Down
19 changes: 10 additions & 9 deletions apps/examples/nocopy_echo/rpmsg-nocopy-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ static int app(struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if ((int32_t)max_size < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
Expand All @@ -142,8 +134,17 @@ static int app(struct rpmsg_device *rdev, void *priv)

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);

LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if ((int32_t)max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

for (i = 0, size = PAYLOAD_MIN_SIZE; i < num_payloads; i++, size++) {
struct _payload *i_payload;

Expand Down
28 changes: 15 additions & 13 deletions apps/tests/msg/rpmsg-flood-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,35 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" and validate its integrity ..\r\n");

num_pkgs = NUMS_PACKAGES;
max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
i_payload = (struct _payload *)metal_allocate_memory(max_size);

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, APP_EPT_ADDR,
RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
i_payload = (struct _payload *)metal_allocate_memory(max_size);

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);

memset(&(i_payload->data[0]), 0xA5, max_size);
for (s = PAYLOAD_MIN_SIZE; s <= max_size; s++) {
int size;
Expand Down
17 changes: 9 additions & 8 deletions apps/tests/msg/rpmsg-nocopy-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ int app(struct rpmsg_device *rdev, void *priv)
int expect_rnum = 0;
void *buff_list[MAX_NB_TX_BUFF];

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (((int)max_size) < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
Expand All @@ -155,6 +147,15 @@ int app(struct rpmsg_device *rdev, void *priv)

LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if (((int)max_size) <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

LPRINTF(" 1 - Get some TX buffers\r\n");
for (i = 0; i < MAX_NB_TX_BUFF; i++)
buff_list[i] = rpmsg_get_tx_payload_buffer(&lept, &max_size, 1);
Expand Down
29 changes: 15 additions & 14 deletions apps/tests/msg/rpmsg-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
return ret;
}

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
Expand All @@ -121,21 +131,12 @@ int app (struct rpmsg_device *rdev, void *priv)

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewing the code I just see that an error returned rpmsg_send error not return a test failed. t
Could you also fix that by managing a ret variable and using go out?

if (!i_payload) {
		LPERROR("memory allocation failed.\r\n");
		ret = -1;
		goto out;
}
[...]
	if (ret) {
		LPERROR("Failed to create RPMsg endpoint.\r\n");
		ret = -1;
		goto free_mem:
	}
[...]
free_mem:
	    metal_free_memory(i_payload);
out:		
	LPRINTF("**********************************\r\n");
	LPRINTF(" Test Results: Error count = %d \r\n", err_cnt);
	LPRINTF("**********************************\r\n");
	/* Destroy the RPMsg endpoint */
	rpmsg_destroy_ept(&lept);
	LPRINTF("Quitting application .. Echo test end\r\n");
	return ret;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into that and it will introduce more churn than I'd think should be part of this series. Would it be better to address that issue in a separate PR?

return -1;
}

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

LPRINTF("RPMsg driver TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg driver RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
Expand Down
30 changes: 30 additions & 0 deletions lib/include/openamp/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ struct rpmsg_device_ops {

/** Release RPMsg TX buffer */
int (*release_tx_buffer)(struct rpmsg_device *rdev, void *txbuf);

/** Get RPMsg RX buffer size */
int (*get_rx_buffer_size)(struct rpmsg_device *rdev);

/** Get RPMsg TX buffer size */
int (*get_tx_buffer_size)(struct rpmsg_device *rdev);
};

/** @brief Representation of a RPMsg device */
Expand Down Expand Up @@ -404,6 +410,30 @@ void *rpmsg_get_tx_payload_buffer(struct rpmsg_endpoint *ept,
*/
int rpmsg_release_tx_buffer(struct rpmsg_endpoint *ept, void *txbuf);

/**
* @brief Get RPMsg Tx buffer size
*
* @param ept The rpmsg endpoint
*
* @return
* - Next available Tx buffer size on success
* - RPMSG_ERR_PARAM on invalid parameter
* - RPMSG_ERR_PERM if service not implemented
*/
int rpmsg_get_tx_buffer_size(struct rpmsg_endpoint *ept);

/**
* @brief Get RPMsg Rx buffer size
*
* @param ept The rpmsg endpoint
*
* @return
* - Next available Rx buffer size on success
* - RPMSG_ERR_PARAM on invalid parameter
* - RPMSG_ERR_PERM if service not implemented
*/
int rpmsg_get_rx_buffer_size(struct rpmsg_endpoint *ept);

/**
* @brief Send a message in tx buffer reserved by
* rpmsg_get_tx_payload_buffer() across to the remote processor.
Expand Down
30 changes: 30 additions & 0 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ void *rpmsg_get_tx_payload_buffer(struct rpmsg_endpoint *ept,
return NULL;
}

int rpmsg_get_tx_buffer_size(struct rpmsg_endpoint *ept)
{
struct rpmsg_device *rdev;

if (!ept || !ept->rdev)
return RPMSG_ERR_PARAM;

rdev = ept->rdev;

if (rdev->ops.get_tx_buffer_size)
return rdev->ops.get_tx_buffer_size(rdev);

return RPMSG_EOPNOTSUPP;
}

int rpmsg_get_rx_buffer_size(struct rpmsg_endpoint *ept)
{
struct rpmsg_device *rdev;

if (!ept || !ept->rdev)
return RPMSG_ERR_PARAM;

rdev = ept->rdev;

if (rdev->ops.get_rx_buffer_size)
return rdev->ops.get_rx_buffer_size(rdev);

return RPMSG_EOPNOTSUPP;
}

int rpmsg_send_offchannel_nocopy(struct rpmsg_endpoint *ept, uint32_t src,
uint32_t dst, const void *data, int len)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,8 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
rdev->ops.get_tx_payload_buffer = rpmsg_virtio_get_tx_payload_buffer;
rdev->ops.send_offchannel_nocopy = rpmsg_virtio_send_offchannel_nocopy;
rdev->ops.release_tx_buffer = rpmsg_virtio_release_tx_buffer;
rdev->ops.get_rx_buffer_size = rpmsg_virtio_get_rx_buffer_size;
rdev->ops.get_tx_buffer_size = rpmsg_virtio_get_tx_buffer_size;
role = rpmsg_virtio_get_role(rvdev);

#ifndef VIRTIO_DEVICE_ONLY
Expand Down
Loading