Skip to content

Commit

Permalink
rpmsg: buffers flush/invalidate
Browse files Browse the repository at this point in the history
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 <iuliana.prodan@nxp.com>
  • Loading branch information
iuliana-prodan authored and arnopo committed Sep 18, 2023
1 parent ca0747e commit 95a9038
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 9 additions & 0 deletions lib/include/openamp/rpmsg_virtio.h
Expand Up @@ -14,6 +14,7 @@

#include <metal/io.h>
#include <metal/mutex.h>
#include <metal/cache.h>
#include <openamp/rpmsg.h>
#include <openamp/virtio.h>

Expand All @@ -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
Expand Down
13 changes: 3 additions & 10 deletions lib/rpmsg/rpmsg_virtio.c
Expand Up @@ -9,7 +9,6 @@
*/

#include <metal/alloc.h>
#include <metal/cache.h>
#include <metal/sleep.h>
#include <metal/utilities.h>
#include <openamp/rpmsg_virtio.h>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 95a9038

Please sign in to comment.