From fc9d645243c585731832ba42aa960a4ebb6656ab Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Mon, 26 May 2025 21:38:28 +0800 Subject: [PATCH 08/12] lib/rpmsg/rpmsg_virtio: add last buffer check to fix low power issue add `last` argument to rpmsg_virtio_get_rx_buffer() to know whether current got rx buffer is the last buffer. When this is the last buffer, do not try to access the vring to avoid the low power issue. Signed-off-by: Bowen Wang --- lib/rpmsg/rpmsg_virtio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c index 6df5a52a48..4aba94e973 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ open-amp/lib/rpmsg/rpmsg_virtio.c @@ -216,21 +216,24 @@ static void *rpmsg_virtio_get_tx_buffer(struct rpmsg_virtio_device *rvdev, * @param rvdev Pointer to rpmsg device * @param len Size of received buffer * @param idx Index of buffer + * @param last Indicates whether this is the last buffer * * @return Pointer to received buffer */ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev, - uint32_t *len, uint16_t *idx) + uint32_t *len, uint16_t *idx, bool *last) { void *data = NULL; if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) { data = virtqueue_get_buffer(rvdev->rvq, len, idx); + *last = virtqueue_nused(rvdev->rvq) == 0; } if (VIRTIO_ROLE_IS_DEVICE(rvdev->vdev)) { data = virtqueue_get_first_avail_buffer(rvdev->rvq, idx, len); + *last = virtqueue_navail(rvdev->rvq) == 0; } /* Invalidate the buffer before returning it */ @@ -551,14 +554,15 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq) struct rpmsg_endpoint *ept; struct rpmsg_hdr *rp_hdr; bool release = false; + bool last = false; uint32_t len; uint16_t idx; int status; - while (1) { + while (!last) { /* Process the received data from remote node */ metal_mutex_acquire(&rdev->lock); - rp_hdr = rpmsg_virtio_get_rx_buffer(rvdev, &len, &idx); + rp_hdr = rpmsg_virtio_get_rx_buffer(rvdev, &len, &idx, &last); /* No more filled rx buffers */ if (!rp_hdr) { -- 2.34.1