[RAMEN9610-12270] media: smfc: force unshareable for HWFC buffer
authorCho KyongHo <pullip.cho@samsung.com>
Mon, 18 Feb 2019 04:19:34 +0000 (13:19 +0900)
committerhskang <hs1218.kang@samsung.com>
Wed, 20 Feb 2019 01:00:40 +0000 (10:00 +0900)
Camera driver has no chance to maintain its destination buffer before
reading the buffer by SMFC if HWFC is enabled because SMFC starts
reading the buffer before MSCS finishes writing to the buffer.
Therefore, we should make SMFC read the buffer with the unshareable
attribute.

Change-Id: I9e9e326ecaa742fba1995a1bfc3f2ff60e68ef37
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
drivers/media/platform/exynos/smfc/smfc.c

index 75bacb2d32ab9e432d4c7df7cb527d05c668b00e..cb975b1f6e296d464c8ce054d29f1f4c71ef855c 100644 (file)
@@ -261,18 +261,6 @@ static int smfc_vb2_buf_prepare(struct vb2_buffer *vb)
                                        return -EINVAL;
                                }
                        }
-
-                       /*
-                        * FIXME: handle this
-                        * There is no chance to clean CPU caches if HWFC is
-                        * enabled because the compression starts before the
-                        * image producer completes writing.
-                        * Therefore, the image producer (MCSC) and the read DMA
-                        * of JPEG/SMFC should access the memory with the same
-                        * shareability attributes.
-                       if (ctx->enable_hwfc)
-                               clean_cache = false;
-                        */
                } else {
                        /* buffer contains JPEG stream to decompress */
                        int ret = smfc_parse_jpeg_header(ctx, vb);
@@ -357,6 +345,31 @@ static void smfc_vb2_stop_streaming(struct vb2_queue *vq)
        vb2_wait_for_all_buffers(vq);
 }
 
+static int smfc_vb2_dma_sg_flags(struct vb2_buffer *vb)
+{
+       int flags = 0;
+       struct vb2_queue *vq = vb->vb2_queue;
+
+       /*
+        * There is no chance to clean CPU caches if HWFC is
+        * enabled because the compression starts before the
+        * image producer completes writing.
+        * Therefore, the image producer (MCSC) and the read DMA
+        * of JPEG/SMFC should access the memory with the same
+        * shareability attributes.
+        * MCSC does use shareable memory access for now. Let's make
+        * unshareable to the shared buffer with MSCS here.
+        */
+       if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
+               struct smfc_ctx *ctx = vq->drv_priv;
+
+               if (!!(ctx->flags & SMFC_CTX_COMPRESS) && ctx->enable_hwfc)
+                       flags = VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED;
+       }
+
+       return flags;
+}
+
 static struct vb2_ops smfc_vb2_ops = {
        .queue_setup    = smfc_vb2_queue_setup,
        .buf_prepare    = smfc_vb2_buf_prepare,
@@ -366,6 +379,7 @@ static struct vb2_ops smfc_vb2_ops = {
        .wait_finish    = vb2_ops_wait_finish,
        .wait_prepare   = vb2_ops_wait_prepare,
        .stop_streaming = smfc_vb2_stop_streaming,
+       .mem_flags      = smfc_vb2_dma_sg_flags,
 };
 
 static int smfc_queue_init(void *priv, struct vb2_queue *src_vq,