Merge tag 'drm-misc-next-2020-10-27' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / drivers / media / common / videobuf2 / videobuf2-dma-contig.c
index a1eb8279b113ad53f5533a78a9a0d553a3899788..a7f61ba854405f63fa0a4842a5589d9dab076a68 100644 (file)
@@ -42,11 +42,6 @@ struct vb2_dc_buf {
        struct dma_buf_attachment       *db_attach;
 };
 
-static inline bool vb2_dc_buffer_consistent(unsigned long attr)
-{
-       return !(attr & DMA_ATTR_NON_CONSISTENT);
-}
-
 /*********************************************/
 /*        scatterlist table functions        */
 /*********************************************/
@@ -58,10 +53,10 @@ static unsigned long vb2_dc_get_contiguous_size(struct sg_table *sgt)
        unsigned int i;
        unsigned long size = 0;
 
-       for_each_sg(sgt->sgl, s, sgt->nents, i) {
+       for_each_sgtable_dma_sg(sgt, s, i) {
                if (sg_dma_address(s) != expected)
                        break;
-               expected = sg_dma_address(s) + sg_dma_len(s);
+               expected += sg_dma_len(s);
                size += sg_dma_len(s);
        }
        return size;
@@ -107,8 +102,7 @@ static void vb2_dc_prepare(void *buf_priv)
        if (!sgt)
                return;
 
-       dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents,
-                              buf->dma_dir);
+       dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir);
 }
 
 static void vb2_dc_finish(void *buf_priv)
@@ -119,7 +113,7 @@ static void vb2_dc_finish(void *buf_priv)
        if (!sgt)
                return;
 
-       dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir);
+       dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir);
 }
 
 /*********************************************/
@@ -279,8 +273,8 @@ static void vb2_dc_dmabuf_ops_detach(struct dma_buf *dbuf,
                 * memory locations do not require any explicit cache
                 * maintenance prior or after being used by the device.
                 */
-               dma_unmap_sg_attrs(db_attach->dev, sgt->sgl, sgt->orig_nents,
-                                  attach->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
+               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir,
+                                 DMA_ATTR_SKIP_CPU_SYNC);
        sg_free_table(sgt);
        kfree(attach);
        db_attach->priv = NULL;
@@ -305,8 +299,8 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
-               dma_unmap_sg_attrs(db_attach->dev, sgt->sgl, sgt->orig_nents,
-                                  attach->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
+               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir,
+                                 DMA_ATTR_SKIP_CPU_SYNC);
                attach->dma_dir = DMA_NONE;
        }
 
@@ -314,9 +308,8 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
         * mapping to the client with new direction, no cache sync
         * required see comment in vb2_dc_dmabuf_ops_detach()
         */
-       sgt->nents = dma_map_sg_attrs(db_attach->dev, sgt->sgl, sgt->orig_nents,
-                                     dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
-       if (!sgt->nents) {
+       if (dma_map_sgtable(db_attach->dev, sgt, dma_dir,
+                           DMA_ATTR_SKIP_CPU_SYNC)) {
                pr_err("failed to map scatterlist\n");
                mutex_unlock(lock);
                return ERR_PTR(-EIO);
@@ -345,13 +338,6 @@ static int
 vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf,
                                   enum dma_data_direction direction)
 {
-       struct vb2_dc_buf *buf = dbuf->priv;
-       struct sg_table *sgt = buf->dma_sgt;
-
-       if (vb2_dc_buffer_consistent(buf->attrs))
-               return 0;
-
-       dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
        return 0;
 }
 
@@ -359,13 +345,6 @@ static int
 vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf,
                                 enum dma_data_direction direction)
 {
-       struct vb2_dc_buf *buf = dbuf->priv;
-       struct sg_table *sgt = buf->dma_sgt;
-
-       if (vb2_dc_buffer_consistent(buf->attrs))
-               return 0;
-
-       dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
        return 0;
 }
 
@@ -461,8 +440,8 @@ static void vb2_dc_put_userptr(void *buf_priv)
                 * No need to sync to CPU, it's already synced to the CPU
                 * since the finish() memop will have been called before this.
                 */
-               dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
-                                  buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
+               dma_unmap_sgtable(buf->dev, sgt, buf->dma_dir,
+                                 DMA_ATTR_SKIP_CPU_SYNC);
                pages = frame_vector_pages(buf->vec);
                /* sgt should exist only if vector contains pages... */
                BUG_ON(IS_ERR(pages));
@@ -559,9 +538,8 @@ static void *vb2_dc_get_userptr(struct device *dev, unsigned long vaddr,
         * No need to sync to the device, this will happen later when the
         * prepare() memop is called.
         */
-       sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
-                                     buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
-       if (sgt->nents <= 0) {
+       if (dma_map_sgtable(buf->dev, sgt, buf->dma_dir,
+                           DMA_ATTR_SKIP_CPU_SYNC)) {
                pr_err("failed to map scatterlist\n");
                ret = -EIO;
                goto fail_sgt_init;
@@ -583,8 +561,7 @@ out:
        return buf;
 
 fail_map_sg:
-       dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
-                          buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
+       dma_unmap_sgtable(buf->dev, sgt, buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
 
 fail_sgt_init:
        sg_free_table(sgt);