Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and clean-up cache management #502

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ library for it project:
enabled on buffers.
* **WITH_DCACHE_RSC_TABLE** (default OFF): Build with data cache operations
enabled on resource table.
* **WITH_DCACHE** (default OFF): Build with all cache operations
arnopo marked this conversation as resolved.
Show resolved Hide resolved
enabled. When set to ON, cache operations for vrings, buffers and resource
table are enabled.
* **RPMSG_BUFFER_SIZE** (default 512): adjust the size of the RPMsg buffers.
The default value of the RPMsg size is compatible with the Linux Kernel hard
coded value. If you AMP configuration is Linux kernel host/ OpenAMP remote,
Expand Down
11 changes: 10 additions & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,31 @@ if (WITH_VIRTIO_MMIO_DRV)
add_definitions(-DWITH_VIRTIO_MMIO_DRV)
endif (WITH_VIRTIO_MMIO_DRV)

option (WITH_DCACHE "Build with all cache operations enabled" OFF)

if (WITH_DCACHE)
add_definitions(-DVIRTIO_USE_DCACHE)
endif (WITH_DCACHE)

option (WITH_DCACHE_VRINGS "Build with vrings cache operations enabled" OFF)

if (WITH_DCACHE_VRINGS)
add_definitions(-DVIRTIO_CACHED_VRINGS)
message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...)
endif (WITH_DCACHE_VRINGS)

option (WITH_DCACHE_BUFFERS "Build with vrings cache operations enabled" OFF)
option (WITH_DCACHE_BUFFERS "Build with buffers cache operations enabled" OFF)

if (WITH_DCACHE_BUFFERS)
add_definitions(-DVIRTIO_CACHED_BUFFERS)
message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...)
endif (WITH_DCACHE_BUFFERS)

option (WITH_DCACHE_RSC_TABLE "Build with resource table cache operations enabled" OFF)

if (WITH_DCACHE_RSC_TABLE)
add_definitions(-DVIRTIO_CACHED_RSC_TABLE)
message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...)
endif (WITH_DCACHE_RSC_TABLE)

# Set the complication flags
Expand Down
9 changes: 6 additions & 3 deletions lib/include/openamp/remoteproc_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ extern "C" {

/* cache invalidation helpers for resource table */
#ifdef VIRTIO_CACHED_RSC_TABLE
#define RSC_TABLE_FLUSH(x, s) metal_cache_flush(x, s)
#define RSC_TABLE_INVALIDATE(x, s) metal_cache_invalidate(x, s)
#warning "VIRTIO_CACHED_RSC_TABLE is deprecated, please use VIRTIO_USE_DCACHE"
#endif
#if defined(VIRTIO_CACHED_RSC_TABLE) || defined(VIRTIO_USE_DCACHE)
#define RSC_TABLE_FLUSH(x, s) CACHE_FLUSH(x, s)
#define RSC_TABLE_INVALIDATE(x, s) CACHE_INVALIDATE(x, s)
#else
#define RSC_TABLE_FLUSH(x, s) do { } while (0)
#define RSC_TABLE_INVALIDATE(x, s) do { } while (0)
#endif /* VIRTIO_CACHED_RSC_TABLE */
#endif /* VIRTIO_CACHED_RSC_TABLE || VIRTIO_USE_DCACHE */

/* define vdev notification function user should implement */
typedef int (*rpvdev_notify_func)(void *priv, uint32_t id);
Expand Down
12 changes: 12 additions & 0 deletions lib/include/openamp/rpmsg_virtio.h
Original file line number Diff line number Diff line change
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,17 @@ extern "C" {
/* The feature bitmap for virtio rpmsg */
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */

#ifdef VIRTIO_CACHED_BUFFERS
#warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE"
#endif
#if defined(VIRTIO_CACHED_BUFFERS) || defined(VIRTIO_USE_DCACHE)
#define BUFFER_FLUSH(x, s) CACHE_FLUSH(x, s)
#define BUFFER_INVALIDATE(x, s) 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 || VIRTIO_USE_DCACHE */

/**
* struct rpmsg_virtio_shm_pool - shared memory pool used for rpmsg buffers
* @base: base address of the memory pool
Expand Down
16 changes: 16 additions & 0 deletions lib/include/openamp/virtqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern "C" {
#include <openamp/virtio_ring.h>
#include <metal/alloc.h>
#include <metal/io.h>
#include <metal/cache.h>

/* Error Codes */
#define VQ_ERROR_BASE -3000
Expand Down Expand Up @@ -47,6 +48,21 @@ extern "C" {
/* Support to suppress interrupt until specific index is reached. */
#define VIRTIO_RING_F_EVENT_IDX (1 << 29)

/* cache invalidation helpers */
#define CACHE_FLUSH(x, s) metal_cache_flush(x, s)
#define CACHE_INVALIDATE(x, s) metal_cache_invalidate(x, s)

#ifdef VIRTIO_CACHED_VRINGS
#warning "VIRTIO_CACHED_VRINGS is deprecated, please use VIRTIO_USE_DCACHE"
#endif
#if defined(VIRTIO_CACHED_VRINGS) || defined(VIRTIO_USE_DCACHE)
#define VRING_FLUSH(x, s) CACHE_FLUSH(x, s)
#define VRING_INVALIDATE(x, s) CACHE_INVALIDATE(x, s)
#else
#define VRING_FLUSH(x, s) do { } while (0)
#define VRING_INVALIDATE(x, s) do { } while (0)
#endif /* VIRTIO_CACHED_VRINGS || VIRTIO_USE_DCACHE */

struct virtqueue_buf {
void *buf;
int len;
Expand Down
13 changes: 3 additions & 10 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
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
Loading