rptun: rptun pm and rptun dump support cacheable memory

Should invalidate the memory when the data is located in shared
memory and write by remote core.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2024-02-23 19:57:25 +08:00
committed by Xiang Xiao
parent 3ea02c5992
commit 1a97fa73f0
2 changed files with 25 additions and 2 deletions
+19 -2
View File
@@ -180,9 +180,20 @@ static const struct rpmsg_ops_s g_rptun_rpmsg_ops =
static int rptun_buffer_nused(FAR struct rpmsg_virtio_device *rvdev, bool rx)
{
FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq;
uint16_t nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx;
uint16_t nused;
bool is_host = rpmsg_virtio_get_role(rvdev) == RPMSG_HOST;
if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
if (is_host)
{
RPTUN_INVALIDATE(vq->vq_ring.used->idx);
}
else
{
RPTUN_INVALIDATE(vq->vq_ring.avail->idx);
}
nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx;
if (is_host ^ rx)
{
return nused;
}
@@ -269,10 +280,12 @@ static inline void rptun_update_rx(FAR struct rptun_priv_s *priv)
if (rpmsg_virtio_get_role(rvdev) == RPMSG_HOST)
{
RPTUN_INVALIDATE(rvq->vq_ring.used->idx);
priv->headrx = rvq->vq_ring.used->idx;
}
else
{
RPTUN_INVALIDATE(rvq->vq_ring.avail->idx);
priv->headrx = rvq->vq_ring.avail->idx;
}
}
@@ -527,12 +540,16 @@ static void rptun_dump_buffer(FAR struct rpmsg_virtio_device *rvdev,
{
if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
{
RPTUN_INVALIDATE(vq->vq_ring.used->idx);
desc_idx = (vq->vq_ring.used->idx + i) & (vq->vq_nentries - 1);
RPTUN_INVALIDATE(vq->vq_ring.avail->ring[desc_idx]);
desc_idx = vq->vq_ring.avail->ring[desc_idx];
}
else
{
RPTUN_INVALIDATE(vq->vq_ring.avail->idx);
desc_idx = (vq->vq_ring.avail->idx + i) & (vq->vq_nentries - 1);
RPTUN_INVALIDATE(vq->vq_ring.used->ring[desc_idx].id);
desc_idx = vq->vq_ring.used->ring[desc_idx].id;
}
+6
View File
@@ -29,6 +29,7 @@
#ifdef CONFIG_RPTUN
#include <metal/cache.h>
#include <nuttx/rpmsg/rpmsg.h>
#include <openamp/remoteproc.h>
#include <openamp/rpmsg_virtio.h>
@@ -45,6 +46,11 @@
#define RPTUNIOC_RESET _RPTUNIOC(102)
#define RPTUN_NOTIFY_ALL (UINT32_MAX - 0)
#ifdef CONFIG_OPENAMP_CACHE
# define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x))
#else
# define RPTUN_INVALIDATE(x)
#endif
/* Access macros ************************************************************/