From 95a9038ca6598460d85c853d12b027b4e256dff2 Mon Sep 17 00:00:00 2001 From: Iuliana Prodan Date: Tue, 18 Jul 2023 14:52:34 +0300 Subject: [PATCH] rpmsg: buffers flush/invalidate Do buffers flush and invalidate the same as with vrings and resource table: - add defines in header file; - call BUFFER_FLUSH/BUFFER_INVALIDATE where necessary. Signed-off-by: Iuliana Prodan --- lib/include/openamp/rpmsg_virtio.h | 9 +++++++++ lib/rpmsg/rpmsg_virtio.c | 13 +++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index e4da548..cd74498 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -29,6 +30,14 @@ extern "C" { /* The feature bitmap for virtio rpmsg */ #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#ifdef VIRTIO_CACHED_BUFFERS +#define BUFFER_FLUSH(x, s) metal_cache_flush(x, s) +#define BUFFER_INVALIDATE(x, s) metal_cache_invalidate(x, s) +#else +#define BUFFER_FLUSH(x, s) do { } while (0) +#define BUFFER_INVALIDATE(x, s) do { } while (0) +#endif /* VIRTIO_CACHED_BUFFERS */ + /** * struct rpmsg_virtio_shm_pool - shared memory pool used for rpmsg buffers * @base: base address of the memory pool diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index 0ec5193..ea4cc0d 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -9,7 +9,6 @@ */ #include -#include #include #include #include @@ -93,9 +92,7 @@ static void rpmsg_virtio_return_buffer(struct rpmsg_virtio_device *rvdev, { unsigned int role = rpmsg_virtio_get_role(rvdev); -#ifdef VIRTIO_CACHED_BUFFERS - metal_cache_invalidate(buffer, len); -#endif + BUFFER_INVALIDATE(buffer, len); #ifndef VIRTIO_DEVICE_ONLY if (role == RPMSG_HOST) { @@ -135,9 +132,7 @@ static int rpmsg_virtio_enqueue_buffer(struct rpmsg_virtio_device *rvdev, { unsigned int role = rpmsg_virtio_get_role(rvdev); -#ifdef VIRTIO_CACHED_BUFFERS - metal_cache_flush(buffer, len); -#endif /* VIRTIO_CACHED_BUFFERS */ + BUFFER_FLUSH(buffer, len); #ifndef VIRTIO_DEVICE_ONLY if (role == RPMSG_HOST) { @@ -245,11 +240,9 @@ static void *rpmsg_virtio_get_rx_buffer(struct rpmsg_virtio_device *rvdev, } #endif /*!VIRTIO_DRIVER_ONLY*/ -#ifdef VIRTIO_CACHED_BUFFERS /* Invalidate the buffer before returning it */ if (data) - metal_cache_invalidate(data, *len); -#endif /* VIRTIO_CACHED_BUFFERS */ + BUFFER_INVALIDATE(data, *len); return data; }