nuttx/openamp/0014-rpmsg-add-cache-flash-when-hold-rx-buffer.patch

66 lines
2.1 KiB
Diff
Raw Permalink Normal View History

From 0f3f00d2ecb1f7de470e6eaeeb74ba0ba9b66eea Mon Sep 17 00:00:00 2001
From: ligd <liguiding1@xiaomi.com>
Date: Mon, 13 Feb 2023 20:34:56 +0800
Subject: [PATCH 4/6] rpmsg: add cache flash when hold rx buffer
Assume we have 2 cpus, and use cached shram buffer
CPU0 CPU1
1. send tx bufferX
2. recv rx bufferX
3. set idx to hdr->reserved
4. handled rx bufferX
5. return bufferX
6. reuse tx bufferX
7. dirty cache auto flushed, hdr changed
8. buffer X meet error
Change-Id: If6c347d121ced0c59b6172a490098689b9b7ffd7
---
lib/rpmsg/rpmsg_virtio.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/rpmsg/rpmsg_virtio.c open-amp/lib/rpmsg/rpmsg_virtio.c
index fcf24cd..1a510e6 100644
--- a/lib/rpmsg/rpmsg_virtio.c
+++ open-amp/lib/rpmsg/rpmsg_virtio.c
@@ -321,7 +321,7 @@ static void rpmsg_virtio_hold_rx_buffer(struct rpmsg_device *rdev, void *rxbuf)
rp_hdr = RPMSG_LOCATE_HDR(rxbuf);
/* Set held status to keep buffer */
- rp_hdr->reserved |= RPMSG_BUF_HELD;
+ rp_hdr->reserved = RPMSG_BUF_HELD;
}
static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev,
@@ -553,8 +553,6 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq)
metal_mutex_release(&rdev->lock);
while (rp_hdr) {
- rp_hdr->reserved = idx;
-
/* Get the channel node from the remote device channels list. */
metal_mutex_acquire(&rdev->lock);
ept = rpmsg_get_ept_from_addr(rdev, rp_hdr->dst);
@@ -578,7 +576,15 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq)
metal_mutex_acquire(&rdev->lock);
/* Check whether callback wants to hold buffer */
- if (!(rp_hdr->reserved & RPMSG_BUF_HELD)) {
+ if (rp_hdr->reserved & RPMSG_BUF_HELD) {
+ /* Yes, save idx. */
+ rp_hdr->reserved |= idx;
+
+#ifdef VIRTIO_CACHED_BUFFERS
+ metal_cache_flush(rp_hdr, sizeof(struct rpmsg_hdr));
+#endif
+
+ } else {
/* No, return used buffers. */
rpmsg_virtio_return_buffer(rvdev, rp_hdr, len, idx);
}
--
2.25.1