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

remoteproc: do cache invalidation before reading rsc_table status #500

Merged
merged 2 commits into from
Jul 17, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ library for it project:
enabled on vrings.
* **WITH_DCACHE_BUFFERS** (default OFF): Build with data cache operations
enabled on buffers.
* **WITH_DCACHE_RSC_TABLE** (default OFF): Build with data cache operations
enabled on resource table.
* **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
6 changes: 6 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ if (WITH_DCACHE_BUFFERS)
add_definitions(-DVIRTIO_CACHED_BUFFERS)
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)
arnopo marked this conversation as resolved.
Show resolved Hide resolved
endif (WITH_DCACHE_RSC_TABLE)

# Set the complication flags
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")

Expand Down
10 changes: 10 additions & 0 deletions lib/include/openamp/remoteproc_virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <metal/io.h>
#include <metal/list.h>
#include <openamp/virtio.h>
#include <metal/cache.h>

#if defined __cplusplus
extern "C" {
Expand All @@ -23,6 +24,15 @@ extern "C" {
/* maximum number of vring descriptors for a vdev limited by 16-bit data type */
#define RPROC_MAX_VRING_DESC USHRT_MAX

/* 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)
#else
#define RSC_TABLE_FLUSH(x, s) do { } while (0)
#define RSC_TABLE_INVALIDATE(x, s) do { } while (0)
#endif /* VIRTIO_CACHED_RSC_TABLE */

/* define vdev notification function user should implement */
typedef int (*rpvdev_notify_func)(void *priv, uint32_t id);

Expand Down
10 changes: 9 additions & 1 deletion lib/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static unsigned char rproc_virtio_get_status(struct virtio_device *vdev)
rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
vdev_rsc = rpvdev->vdev_rsc;
io = rpvdev->vdev_rsc_io;
RSC_TABLE_INVALIDATE(vdev_rsc, sizeof(struct fw_rsc_vdev));
status = metal_io_read8(io,
metal_io_virt_to_offset(io, &vdev_rsc->status));
return status;
Expand All @@ -59,6 +60,7 @@ static void rproc_virtio_set_status(struct virtio_device *vdev,
metal_io_write8(io,
metal_io_virt_to_offset(io, &vdev_rsc->status),
status);
RSC_TABLE_FLUSH(vdev_rsc, sizeof(struct fw_rsc_vdev));
rpvdev->notify(rpvdev->priv, vdev->notifyid);
}
#endif
Expand All @@ -73,6 +75,7 @@ static uint32_t rproc_virtio_get_dfeatures(struct virtio_device *vdev)
rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
vdev_rsc = rpvdev->vdev_rsc;
io = rpvdev->vdev_rsc_io;
RSC_TABLE_INVALIDATE(vdev_rsc, sizeof(struct fw_rsc_vdev));
features = metal_io_read32(io,
metal_io_virt_to_offset(io, &vdev_rsc->dfeatures));

Expand All @@ -90,6 +93,7 @@ static uint32_t rproc_virtio_get_features(struct virtio_device *vdev)
rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
vdev_rsc = rpvdev->vdev_rsc;
io = rpvdev->vdev_rsc_io;
RSC_TABLE_INVALIDATE(vdev_rsc, sizeof(struct fw_rsc_vdev));
gfeatures = metal_io_read32(io,
metal_io_virt_to_offset(io, &vdev_rsc->gfeatures));
dfeatures = rproc_virtio_get_dfeatures(vdev);
Expand All @@ -111,6 +115,7 @@ static void rproc_virtio_set_features(struct virtio_device *vdev,
metal_io_write32(io,
metal_io_virt_to_offset(io, &vdev_rsc->gfeatures),
features);
RSC_TABLE_FLUSH(vdev_rsc, sizeof(struct fw_rsc_vdev));
rpvdev->notify(rpvdev->priv, vdev->notifyid);
}

Expand Down Expand Up @@ -138,10 +143,12 @@ static void rproc_virtio_read_config(struct virtio_device *vdev,
config = (char *)(&vdev_rsc->vring[vdev->vrings_num]);
io = rpvdev->vdev_rsc_io;

if (offset + length <= vdev_rsc->config_len)
if (offset + length <= vdev_rsc->config_len) {
RSC_TABLE_INVALIDATE(config + offset, length);
metal_io_block_read(io,
metal_io_virt_to_offset(io, config + offset),
dst, length);
}
}

#ifndef VIRTIO_DEVICE_ONLY
Expand All @@ -162,6 +169,7 @@ static void rproc_virtio_write_config(struct virtio_device *vdev,
metal_io_block_write(io,
metal_io_virt_to_offset(io, config + offset),
src, length);
RSC_TABLE_FLUSH(config + offset, length);
rpvdev->notify(rpvdev->priv, vdev->notifyid);
}
}
Expand Down