From 89a8a3002fc0e8171b91f0d220608facbaa08342 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 15 Mar 2024 12:39:33 -0500 Subject: [PATCH] apps: Convert examples to rpmsg_get_{tx,rx}_buffer_size() The contents of app() in these examples is given a rpmsg_device. We should not have to know about the backing transport layer. We assume it is virtio and call into the virtio layer to get the buffer size. This information is now available from the rpmsg layer. Use those functions to make the app() agnostic to the backing layer. Signed-off-by: Andrew Davis --- apps/examples/echo/rpmsg-echo.c | 4 +-- apps/examples/echo/rpmsg-ping.c | 31 ++++++++++--------- apps/examples/nocopy_echo/rpmsg-nocopy-ping.c | 19 ++++++------ apps/tests/msg/rpmsg-flood-ping.c | 28 +++++++++-------- apps/tests/msg/rpmsg-nocopy-ping.c | 17 +++++----- apps/tests/msg/rpmsg-ping.c | 29 ++++++++--------- 6 files changed, 67 insertions(+), 61 deletions(-) diff --git a/apps/examples/echo/rpmsg-echo.c b/apps/examples/echo/rpmsg-echo.c index 68fafd0fc..0a1381084 100644 --- a/apps/examples/echo/rpmsg-echo.c +++ b/apps/examples/echo/rpmsg-echo.c @@ -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); diff --git a/apps/examples/echo/rpmsg-ping.c b/apps/examples/echo/rpmsg-ping.c index 83e469286..640fe84f8 100644 --- a/apps/examples/echo/rpmsg-ping.c +++ b/apps/examples/echo/rpmsg-ping.c @@ -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); @@ -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); diff --git a/apps/examples/nocopy_echo/rpmsg-nocopy-ping.c b/apps/examples/nocopy_echo/rpmsg-nocopy-ping.c index cc71c46b8..4621c220b 100644 --- a/apps/examples/nocopy_echo/rpmsg-nocopy-ping.c +++ b/apps/examples/nocopy_echo/rpmsg-nocopy-ping.c @@ -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, @@ -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; diff --git a/apps/tests/msg/rpmsg-flood-ping.c b/apps/tests/msg/rpmsg-flood-ping.c index b9c9740dd..e7c91d1a7 100644 --- a/apps/tests/msg/rpmsg-flood-ping.c +++ b/apps/tests/msg/rpmsg-flood-ping.c @@ -116,18 +116,6 @@ 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, @@ -135,7 +123,6 @@ int app (struct rpmsg_device *rdev, void *priv) rpmsg_endpoint_cb, rpmsg_service_unbind); if (ret) { LPERROR("Failed to create RPMsg endpoint.\r\n"); - metal_free_memory(i_payload); return ret; } @@ -143,6 +130,21 @@ int app (struct rpmsg_device *rdev, void *priv) 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; diff --git a/apps/tests/msg/rpmsg-nocopy-ping.c b/apps/tests/msg/rpmsg-nocopy-ping.c index 637bb5940..09c0b19f4 100644 --- a/apps/tests/msg/rpmsg-nocopy-ping.c +++ b/apps/tests/msg/rpmsg-nocopy-ping.c @@ -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, @@ -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); diff --git a/apps/tests/msg/rpmsg-ping.c b/apps/tests/msg/rpmsg-ping.c index 457ca31ce..a9d77c536 100644 --- a/apps/tests/msg/rpmsg-ping.c +++ b/apps/tests/msg/rpmsg-ping.c @@ -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); @@ -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); 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);