From 3536cceb412f4d183145e12406a51fc728f5801a Mon Sep 17 00:00:00 2001 From: "mason.huo" Date: Tue, 7 Jun 2022 10:51:31 +0800 Subject: [PATCH] media: starfive: Fix isp line cache coherence issue The isp app uses the mmap buffer mode which needs to sync the cache before isp controller writes data into the buffer. Add L2 cache flushing before sending data to user space, so that make sure the cache coherence. Signed-off-by: mason.huo --- drivers/media/platform/starfive/v4l2_driver/stf_video.c | 3 +++ drivers/media/platform/starfive/v4l2_driver/stf_video.h | 1 + drivers/media/platform/starfive/v4l2_driver/stf_vin.c | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/drivers/media/platform/starfive/v4l2_driver/stf_video.c b/drivers/media/platform/starfive/v4l2_driver/stf_video.c index 888e822..cc0d3e8 100644 --- a/drivers/media/platform/starfive/v4l2_driver/stf_video.c +++ b/drivers/media/platform/starfive/v4l2_driver/stf_video.c @@ -305,11 +305,13 @@ static int video_buf_init(struct vb2_buffer *vb) //struct sg_table *sgt; dma_addr_t *paddr; unsigned int i; + buffer->sizeimage = 0; if (video->is_mp) { for (i = 0; i < fmt_mp->num_planes; i++) { paddr = vb2_plane_cookie(vb, i); buffer->addr[i] = *paddr; + buffer->sizeimage += vb2_plane_size(vb, i); } if (fmt_mp->num_planes == 1 @@ -322,6 +324,7 @@ static int video_buf_init(struct vb2_buffer *vb) fmt_mp->height; } else { paddr = vb2_plane_cookie(vb, 0); + buffer->sizeimage = vb2_plane_size(vb, 0); buffer->addr[0] = *paddr; if (fmt->pixelformat == V4L2_PIX_FMT_NV12 || fmt->pixelformat == V4L2_PIX_FMT_NV21 diff --git a/drivers/media/platform/starfive/v4l2_driver/stf_video.h b/drivers/media/platform/starfive/v4l2_driver/stf_video.h index d1b8e4d02..fb21b92 100755 --- a/drivers/media/platform/starfive/v4l2_driver/stf_video.h +++ b/drivers/media/platform/starfive/v4l2_driver/stf_video.h @@ -25,6 +25,7 @@ struct stfcamss_buffer { struct vb2_v4l2_buffer vb; dma_addr_t addr[3]; struct list_head queue; + int sizeimage; }; struct stfcamss_video; diff --git a/drivers/media/platform/starfive/v4l2_driver/stf_vin.c b/drivers/media/platform/starfive/v4l2_driver/stf_vin.c index d88e577..15cae80 100644 --- a/drivers/media/platform/starfive/v4l2_driver/stf_vin.c +++ b/drivers/media/platform/starfive/v4l2_driver/stf_vin.c @@ -1210,6 +1210,7 @@ static void vin_buf_flush(struct vin_output *output, } } +extern void sifive_l2_flush64_range(unsigned long start, unsigned long len); static void vin_buffer_done(struct vin_line *line, struct vin_params *params) { struct stfcamss_buffer *ready_buf; @@ -1226,6 +1227,14 @@ static void vin_buffer_done(struct vin_line *line, struct vin_params *params) while ((ready_buf = vin_buf_get_ready(output))) { ready_buf->vb.vb2_buf.timestamp = ts; ready_buf->vb.sequence = output->sequence++; + + /* The stf_isp_ctrl currently buffered with mmap, + * which will not update cache by default. + * Flush L2 cache to make sure data is updated. + */ + if (ready_buf->vb.vb2_buf.memory == VB2_MEMORY_MMAP) + sifive_l2_flush64_range(ready_buf->addr[0], ready_buf->sizeimage); + vb2_buffer_done(&ready_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); } -- 2.7.4