From: Jason Gunthorpe <[email protected]>

Update the exporters to use a SGT mapping type and the new style mapping
type API. None of these exporters do anything with attach->peer2peer or
importer_ops->allow_peer2peer and they all follow the same pattern.

Change all the places that need to get the SGT's DMA device for DMA API
use to use dma_buf_sgt_dma_device().

This is all a mechanical change of moving the map_dma_buf/unmap_dma_buf
into DMA_BUF_SIMPLE_SGT_EXP_MATCH() arguments and switching
attach->dev to dma_buf_sgt_dma_device(attach).

Signed-off-by: Jason Gunthorpe <[email protected]>
[ added converters for newly added amdxdna, panfrost and panthor exporters - 
apopple ]
Signed-off-by: Alistair Popple <[email protected]>
---
 drivers/accel/amdxdna/amdxdna_cbuf.c          |  8 ++++----
 drivers/accel/amdxdna/amdxdna_gem.c           |  5 +++--
 drivers/accel/amdxdna/amdxdna_ubuf.c          |  8 ++++----
 drivers/accel/ivpu/ivpu_gem_userptr.c         | 11 +++++++----
 drivers/dma-buf/heaps/cma_heap.c              | 12 +++++++-----
 drivers/dma-buf/heaps/system_heap.c           | 13 ++++++++-----
 drivers/dma-buf/udmabuf.c                     |  8 ++++----
 drivers/gpu/drm/armada/armada_gem.c           | 12 +++++++-----
 drivers/gpu/drm/drm_prime.c                   |  9 +++++----
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c    |  8 +++++---
 .../gpu/drm/i915/gem/selftests/mock_dmabuf.c  |  8 ++++----
 drivers/gpu/drm/msm/msm_gem_prime.c           |  7 +++++--
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c     |  5 +++--
 drivers/gpu/drm/panfrost/panfrost_gem.c       | 13 +++++++++----
 drivers/gpu/drm/panthor/panthor_gem.c         | 11 +++++++----
 drivers/gpu/drm/tegra/gem.c                   | 12 +++++++-----
 drivers/gpu/drm/virtio/virtgpu_prime.c        | 11 +++++++----
 drivers/iommu/iommufd/selftest.c              | 18 +++---------------
 .../common/videobuf2/videobuf2-dma-contig.c   | 15 ++++++++-------
 .../media/common/videobuf2/videobuf2-dma-sg.c | 14 +++++++++-----
 .../common/videobuf2/videobuf2-vmalloc.c      | 13 ++++++++-----
 drivers/misc/fastrpc.c                        | 12 +++++++-----
 drivers/tee/tee_heap.c                        | 13 +++++++------
 drivers/xen/gntdev-dmabuf.c                   | 19 +++++++++++--------
 samples/vfio-mdev/mbochs.c                    | 10 +++++-----
 sound/soc/fsl/fsl_asrc_m2m.c                  | 12 +++++++-----
 26 files changed, 161 insertions(+), 126 deletions(-)

diff --git a/drivers/accel/amdxdna/amdxdna_cbuf.c 
b/drivers/accel/amdxdna/amdxdna_cbuf.c
index a504560aae98..2070a371903d 100644
--- a/drivers/accel/amdxdna/amdxdna_cbuf.c
+++ b/drivers/accel/amdxdna/amdxdna_cbuf.c
@@ -5,6 +5,7 @@
 
 #include <drm/drm_mm.h>
 #include <drm/drm_prime.h>
+#include <linux/dma-buf-mapping.h>
 
 #include "amdxdna_cbuf.h"
 #include "amdxdna_pci_drv.h"
@@ -85,7 +86,7 @@ static struct sg_table *amdxdna_cbuf_map(struct 
dma_buf_attachment *attach,
                                         enum dma_data_direction direction)
 {
        struct amdxdna_cbuf_priv *cbuf = attach->dmabuf->priv;
-       struct device *dev = attach->dev;
+       struct device *dev = dma_buf_sgt_dma_device(attach);
        struct scatterlist *sgl, *sg;
        int ret, n_entries, i;
        struct sg_table *sgt;
@@ -140,7 +141,7 @@ static void amdxdna_cbuf_unmap(struct dma_buf_attachment 
*attach,
                               struct sg_table *sgt,
                               enum dma_data_direction direction)
 {
-       dma_unmap_resource(attach->dev, sg_dma_address(sgt->sgl),
+       dma_unmap_resource(dma_buf_sgt_dma_device(attach), 
sg_dma_address(sgt->sgl),
                           drm_prime_get_contiguous_size(sgt), direction,
                           DMA_ATTR_SKIP_CPU_SYNC);
        sg_free_table(sgt);
@@ -210,12 +211,11 @@ static void amdxdna_cbuf_vunmap(struct dma_buf *dbuf, 
struct iosys_map *map)
 }
 
 static const struct dma_buf_ops amdxdna_cbuf_dmabuf_ops = {
-       .map_dma_buf = amdxdna_cbuf_map,
-       .unmap_dma_buf = amdxdna_cbuf_unmap,
        .release = amdxdna_cbuf_release,
        .mmap = amdxdna_cbuf_mmap,
        .vmap = amdxdna_cbuf_vmap,
        .vunmap = amdxdna_cbuf_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(amdxdna_cbuf_map, amdxdna_cbuf_unmap),
 };
 
 static int amdxdna_cbuf_clear(struct dma_buf *dbuf)
diff --git a/drivers/accel/amdxdna/amdxdna_gem.c 
b/drivers/accel/amdxdna/amdxdna_gem.c
index 4b0d58d0329b..6253a720cc22 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -11,6 +11,7 @@
 #include <drm/drm_print.h>
 #include <drm/gpu_scheduler.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-direct.h>
 #include <linux/iosys-map.h>
 #include <linux/pagemap.h>
@@ -559,12 +560,12 @@ static int amdxdna_gem_dmabuf_mmap(struct dma_buf 
*dma_buf, struct vm_area_struc
 static const struct dma_buf_ops amdxdna_dmabuf_ops = {
        .attach = drm_gem_map_attach,
        .detach = drm_gem_map_detach,
-       .map_dma_buf = drm_gem_map_dma_buf,
-       .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .mmap = amdxdna_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(drm_gem_map_dma_buf,
+                                    drm_gem_unmap_dma_buf),
 };
 
 static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, 
int flags)
diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c 
b/drivers/accel/amdxdna/amdxdna_ubuf.c
index 0e0cd69cd1fb..b81f947712e8 100644
--- a/drivers/accel/amdxdna/amdxdna_ubuf.c
+++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
@@ -7,6 +7,7 @@
 #include <drm/drm_device.h>
 #include <drm/drm_print.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/overflow.h>
 #include <linux/pagemap.h>
 #include <linux/vmalloc.h>
@@ -36,7 +37,7 @@ static struct sg_table *amdxdna_ubuf_map(struct 
dma_buf_attachment *attach,
        if (ret)
                goto err_free_sg;
 
-       ret = dma_map_sgtable(attach->dev, sg, direction, 0);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attach), sg, direction, 0);
        if (ret)
                goto err_free_table;
 
@@ -53,7 +54,7 @@ static void amdxdna_ubuf_unmap(struct dma_buf_attachment 
*attach,
                               struct sg_table *sg,
                               enum dma_data_direction direction)
 {
-       dma_unmap_sgtable(attach->dev, sg, direction, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attach), sg, direction, 0);
        sg_free_table(sg);
        kfree(sg);
 }
@@ -70,9 +71,8 @@ static void amdxdna_ubuf_release(struct dma_buf *dbuf)
 }
 
 static const struct dma_buf_ops amdxdna_ubuf_dmabuf_ops = {
-       .map_dma_buf = amdxdna_ubuf_map,
-       .unmap_dma_buf = amdxdna_ubuf_unmap,
        .release = amdxdna_ubuf_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(amdxdna_ubuf_map, amdxdna_ubuf_unmap),
 };
 
 struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
diff --git a/drivers/accel/ivpu/ivpu_gem_userptr.c 
b/drivers/accel/ivpu/ivpu_gem_userptr.c
index 7cbf3a4cdc73..7ca9d8d4f5a8 100644
--- a/drivers/accel/ivpu/ivpu_gem_userptr.c
+++ b/drivers/accel/ivpu/ivpu_gem_userptr.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/err.h>
 #include <linux/highmem.h>
 #include <linux/mm.h>
@@ -26,7 +27,8 @@ ivpu_gem_userptr_dmabuf_map(struct dma_buf_attachment 
*attachment,
        struct sg_table *sgt = attachment->dmabuf->priv;
        int ret;
 
-       ret = dma_map_sgtable(attachment->dev, sgt, direction, 
DMA_ATTR_SKIP_CPU_SYNC);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), sgt,
+                             direction, DMA_ATTR_SKIP_CPU_SYNC);
        if (ret)
                return ERR_PTR(ret);
 
@@ -37,7 +39,8 @@ static void ivpu_gem_userptr_dmabuf_unmap(struct 
dma_buf_attachment *attachment,
                                          struct sg_table *sgt,
                                          enum dma_data_direction direction)
 {
-       dma_unmap_sgtable(attachment->dev, sgt, direction, 
DMA_ATTR_SKIP_CPU_SYNC);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), sgt, direction,
+                         DMA_ATTR_SKIP_CPU_SYNC);
 }
 
 static void ivpu_gem_userptr_dmabuf_release(struct dma_buf *dma_buf)
@@ -56,9 +59,9 @@ static void ivpu_gem_userptr_dmabuf_release(struct dma_buf 
*dma_buf)
 }
 
 static const struct dma_buf_ops ivpu_gem_userptr_dmabuf_ops = {
-       .map_dma_buf = ivpu_gem_userptr_dmabuf_map,
-       .unmap_dma_buf = ivpu_gem_userptr_dmabuf_unmap,
        .release = ivpu_gem_userptr_dmabuf_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(ivpu_gem_userptr_dmabuf_map,
+                                    ivpu_gem_userptr_dmabuf_unmap),
 };
 
 static struct dma_buf *
diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 3fb4b946c91a..fa05c242f238 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -14,6 +14,7 @@
 
 #include <linux/cma.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-heap.h>
 #include <linux/dma-map-ops.h>
 #include <linux/err.h>
@@ -73,7 +74,7 @@ static int cma_heap_attach(struct dma_buf *dmabuf,
                return ret;
        }
 
-       a->dev = attachment->dev;
+       a->dev = dma_buf_sgt_dma_device(attachment);
        INIT_LIST_HEAD(&a->list);
        a->mapped = false;
 
@@ -107,7 +108,8 @@ static struct sg_table *cma_heap_map_dma_buf(struct 
dma_buf_attachment *attachme
        struct sg_table *table = &a->table;
        int ret;
 
-       ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), table,
+                             direction, 0);
        if (ret)
                return ERR_PTR(-ENOMEM);
        a->mapped = true;
@@ -121,7 +123,8 @@ static void cma_heap_unmap_dma_buf(struct 
dma_buf_attachment *attachment,
        struct dma_heap_attachment *a = attachment->priv;
 
        a->mapped = false;
-       dma_unmap_sgtable(attachment->dev, table, direction, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), table, direction,
+                         0);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
@@ -268,14 +271,13 @@ static void cma_heap_dma_buf_release(struct dma_buf 
*dmabuf)
 static const struct dma_buf_ops cma_heap_buf_ops = {
        .attach = cma_heap_attach,
        .detach = cma_heap_detach,
-       .map_dma_buf = cma_heap_map_dma_buf,
-       .unmap_dma_buf = cma_heap_unmap_dma_buf,
        .begin_cpu_access = cma_heap_dma_buf_begin_cpu_access,
        .end_cpu_access = cma_heap_dma_buf_end_cpu_access,
        .mmap = cma_heap_mmap,
        .vmap = cma_heap_vmap,
        .vunmap = cma_heap_vunmap,
        .release = cma_heap_dma_buf_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(cma_heap_map_dma_buf, 
cma_heap_unmap_dma_buf),
 };
 
 static struct dma_buf *cma_heap_allocate(struct dma_heap *heap,
diff --git a/drivers/dma-buf/heaps/system_heap.c 
b/drivers/dma-buf/heaps/system_heap.c
index c8959eadc71d..e954238463d4 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -12,6 +12,7 @@
 
 #include <linux/cc_platform.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-heap.h>
 #include <linux/err.h>
@@ -128,7 +129,7 @@ static int system_heap_attach(struct dma_buf *dmabuf,
                return ret;
        }
 
-       a->dev = attachment->dev;
+       a->dev = dma_buf_sgt_dma_device(attachment);
        INIT_LIST_HEAD(&a->list);
        a->mapped = false;
        a->cc_shared = buffer->cc_shared;
@@ -165,7 +166,8 @@ static struct sg_table *system_heap_map_dma_buf(struct 
dma_buf_attachment *attac
        int ret;
 
        attrs = cc_shared_buffer(a) ? DMA_ATTR_CC_SHARED : 0;
-       ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), table,
+                             direction, attrs);
        if (ret)
                return ERR_PTR(ret);
 
@@ -180,7 +182,8 @@ static void system_heap_unmap_dma_buf(struct 
dma_buf_attachment *attachment,
        struct dma_heap_attachment *a = attachment->priv;
 
        a->mapped = false;
-       dma_unmap_sgtable(attachment->dev, table, direction, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), table, direction,
+                         0);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
@@ -365,14 +368,14 @@ static void system_heap_dma_buf_release(struct dma_buf 
*dmabuf)
 static const struct dma_buf_ops system_heap_buf_ops = {
        .attach = system_heap_attach,
        .detach = system_heap_detach,
-       .map_dma_buf = system_heap_map_dma_buf,
-       .unmap_dma_buf = system_heap_unmap_dma_buf,
        .begin_cpu_access = system_heap_dma_buf_begin_cpu_access,
        .end_cpu_access = system_heap_dma_buf_end_cpu_access,
        .mmap = system_heap_mmap,
        .vmap = system_heap_vmap,
        .vunmap = system_heap_vunmap,
        .release = system_heap_dma_buf_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(system_heap_map_dma_buf,
+                                    system_heap_unmap_dma_buf),
 };
 
 static struct page *alloc_largest_available(unsigned long size,
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index df6dd0046242..911a3fa347b3 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -2,6 +2,7 @@
 #include <linux/cred.h>
 #include <linux/device.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-resv.h>
 #include <linux/highmem.h>
 #include <linux/init.h>
@@ -168,14 +169,14 @@ static void put_sg_table(struct device *dev, struct 
sg_table *sg,
 static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
                                    enum dma_data_direction direction)
 {
-       return get_sg_table(at->dev, at->dmabuf, direction);
+       return get_sg_table(dma_buf_sgt_dma_device(at), at->dmabuf, direction);
 }
 
 static void unmap_udmabuf(struct dma_buf_attachment *at,
                          struct sg_table *sg,
                          enum dma_data_direction direction)
 {
-       return put_sg_table(at->dev, sg, direction);
+       return put_sg_table(dma_buf_sgt_dma_device(at), sg, direction);
 }
 
 static void unpin_all_folios(struct udmabuf *ubuf)
@@ -256,14 +257,13 @@ static int end_cpu_udmabuf(struct dma_buf *buf,
 }
 
 static const struct dma_buf_ops udmabuf_ops = {
-       .map_dma_buf       = map_udmabuf,
-       .unmap_dma_buf     = unmap_udmabuf,
        .release           = release_udmabuf,
        .mmap              = mmap_udmabuf,
        .vmap              = vmap_udmabuf,
        .vunmap            = vunmap_udmabuf,
        .begin_cpu_access  = begin_cpu_udmabuf,
        .end_cpu_access    = end_cpu_udmabuf,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(map_udmabuf, unmap_udmabuf),
 };
 
 #define SEALS_WANTED (F_SEAL_SHRINK)
diff --git a/drivers/gpu/drm/armada/armada_gem.c 
b/drivers/gpu/drm/armada/armada_gem.c
index da7335cbe82d..5cea1eab6e5c 100644
--- a/drivers/gpu/drm/armada/armada_gem.c
+++ b/drivers/gpu/drm/armada/armada_gem.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 #include <linux/mman.h>
 #include <linux/shmem_fs.h>
@@ -387,6 +388,7 @@ static struct sg_table *
 armada_gem_prime_map_dma_buf(struct dma_buf_attachment *attach,
        enum dma_data_direction dir)
 {
+       struct device *dma_dev = dma_buf_sgt_dma_device(attach);
        struct drm_gem_object *obj = attach->dmabuf->priv;
        struct armada_gem_object *dobj = drm_to_armada_gem(obj);
        struct scatterlist *sg;
@@ -417,7 +419,7 @@ armada_gem_prime_map_dma_buf(struct dma_buf_attachment 
*attach,
                        sg_set_page(sg, page, PAGE_SIZE, 0);
                }
 
-               if (dma_map_sgtable(attach->dev, sgt, dir, 0))
+               if (dma_map_sgtable(dma_dev, sgt, dir, 0))
                        goto release;
        } else if (dobj->page) {
                /* Single contiguous page */
@@ -426,7 +428,7 @@ armada_gem_prime_map_dma_buf(struct dma_buf_attachment 
*attach,
 
                sg_set_page(sgt->sgl, dobj->page, dobj->obj.size, 0);
 
-               if (dma_map_sgtable(attach->dev, sgt, dir, 0))
+               if (dma_map_sgtable(dma_dev, sgt, dir, 0))
                        goto free_table;
        } else if (dobj->linear) {
                /* Single contiguous physical region - no struct page */
@@ -458,7 +460,7 @@ static void armada_gem_prime_unmap_dma_buf(struct 
dma_buf_attachment *attach,
        int i;
 
        if (!dobj->linear)
-               dma_unmap_sgtable(attach->dev, sgt, dir, 0);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(attach), sgt, dir, 0);
 
        if (dobj->obj.filp) {
                struct scatterlist *sg;
@@ -478,10 +480,10 @@ armada_gem_dmabuf_mmap(struct dma_buf *buf, struct 
vm_area_struct *vma)
 }
 
 static const struct dma_buf_ops armada_gem_prime_dmabuf_ops = {
-       .map_dma_buf    = armada_gem_prime_map_dma_buf,
-       .unmap_dma_buf  = armada_gem_prime_unmap_dma_buf,
        .release        = drm_gem_dmabuf_release,
        .mmap           = armada_gem_dmabuf_mmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(armada_gem_prime_map_dma_buf,
+                                    armada_gem_prime_unmap_dma_buf),
 };
 
 struct dma_buf *
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index cf53b8cab4da..d797598e42f7 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -693,7 +693,7 @@ struct sg_table *drm_gem_map_dma_buf(struct 
dma_buf_attachment *attach,
        if (IS_ERR(sgt))
                return sgt;
 
-       ret = dma_map_sgtable(attach->dev, sgt, dir,
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attach), sgt, dir,
                              DMA_ATTR_SKIP_CPU_SYNC);
        if (ret) {
                sg_free_table(sgt);
@@ -720,7 +720,8 @@ void drm_gem_unmap_dma_buf(struct dma_buf_attachment 
*attach,
        if (!sgt)
                return;
 
-       dma_unmap_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attach), sgt, dir,
+                         DMA_ATTR_SKIP_CPU_SYNC);
        sg_free_table(sgt);
        kfree(sgt);
 }
@@ -840,12 +841,12 @@ EXPORT_SYMBOL(drm_gem_dmabuf_mmap);
 static const struct dma_buf_ops drm_gem_prime_dmabuf_ops =  {
        .attach = drm_gem_map_attach,
        .detach = drm_gem_map_detach,
-       .map_dma_buf = drm_gem_map_dma_buf,
-       .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .mmap = drm_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(drm_gem_map_dma_buf,
+                                    drm_gem_unmap_dma_buf),
 };
 
 /**
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c 
b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index b43d34c7d641..5333e77e62e0 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/highmem.h>
 #include <linux/dma-resv.h>
 #include <linux/module.h>
@@ -52,7 +53,8 @@ static struct sg_table *i915_gem_map_dma_buf(struct 
dma_buf_attachment *attach,
                dst = sg_next(dst);
        }
 
-       ret = dma_map_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attach), sgt, dir,
+                             DMA_ATTR_SKIP_CPU_SYNC);
        if (ret)
                goto err_free_sg;
 
@@ -203,14 +205,14 @@ static void i915_gem_dmabuf_detach(struct dma_buf *dmabuf,
 static const struct dma_buf_ops i915_dmabuf_ops =  {
        .attach = i915_gem_dmabuf_attach,
        .detach = i915_gem_dmabuf_detach,
-       .map_dma_buf = i915_gem_map_dma_buf,
-       .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .mmap = i915_gem_dmabuf_mmap,
        .vmap = i915_gem_dmabuf_vmap,
        .vunmap = i915_gem_dmabuf_vunmap,
        .begin_cpu_access = i915_gem_begin_cpu_access,
        .end_cpu_access = i915_gem_end_cpu_access,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(i915_gem_map_dma_buf,
+                                    drm_gem_unmap_dma_buf),
 };
 
 struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int 
flags)
diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c 
b/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
index f2863da7f5c1..911d8f59011a 100644
--- a/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
@@ -4,6 +4,7 @@
  * Copyright © 2016 Intel Corporation
  */
 
+#include <linux/dma-buf-mapping.h>
 #include <linux/vmalloc.h>
 #include "mock_dmabuf.h"
 
@@ -29,7 +30,7 @@ static struct sg_table *mock_map_dma_buf(struct 
dma_buf_attachment *attachment,
                sg = sg_next(sg);
        }
 
-       err = dma_map_sgtable(attachment->dev, st, dir, 0);
+       err = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), st, dir, 0);
        if (err)
                goto err_st;
 
@@ -46,7 +47,7 @@ static void mock_unmap_dma_buf(struct dma_buf_attachment 
*attachment,
                               struct sg_table *st,
                               enum dma_data_direction dir)
 {
-       dma_unmap_sgtable(attachment->dev, st, dir, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), st, dir, 0);
        sg_free_table(st);
        kfree(st);
 }
@@ -88,12 +89,11 @@ static int mock_dmabuf_mmap(struct dma_buf *dma_buf, struct 
vm_area_struct *vma)
 }
 
 static const struct dma_buf_ops mock_dmabuf_ops =  {
-       .map_dma_buf = mock_map_dma_buf,
-       .unmap_dma_buf = mock_unmap_dma_buf,
        .release = mock_dmabuf_release,
        .mmap = mock_dmabuf_mmap,
        .vmap = mock_dmabuf_vmap,
        .vunmap = mock_dmabuf_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(mock_map_dma_buf, mock_unmap_dma_buf),
 };
 
 static struct dma_buf *mock_dmabuf(int npages)
diff --git a/drivers/gpu/drm/msm/msm_gem_prime.c 
b/drivers/gpu/drm/msm/msm_gem_prime.c
index beb7f22fd694..46cccbe5f378 100644
--- a/drivers/gpu/drm/msm/msm_gem_prime.c
+++ b/drivers/gpu/drm/msm/msm_gem_prime.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 
 #include <drm/drm_drv.h>
 #include <drm/drm_prime.h>
@@ -54,12 +55,12 @@ static void msm_gem_dmabuf_release(struct dma_buf *dma_buf)
 static const struct dma_buf_ops msm_gem_prime_dmabuf_ops =  {
        .attach = drm_gem_map_attach,
        .detach = drm_gem_map_detach,
-       .map_dma_buf = drm_gem_map_dma_buf,
-       .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = msm_gem_dmabuf_release,
        .mmap = drm_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(drm_gem_map_dma_buf,
+                                    drm_gem_unmap_dma_buf),
 };
 
 struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
@@ -132,3 +133,5 @@ void msm_gem_prime_unpin(struct drm_gem_object *obj)
 
        msm_gem_unpin_pages_locked(obj);
 }
+
+MODULE_IMPORT_NS("DMA_BUF");
diff --git a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c 
b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
index 30cf1cdc1aa3..23beaeefab67 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/highmem.h>
 
 #include <drm/drm_prime.h>
@@ -69,12 +70,12 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
 }
 
 static const struct dma_buf_ops omap_dmabuf_ops = {
-       .map_dma_buf = omap_gem_map_dma_buf,
-       .unmap_dma_buf = omap_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .begin_cpu_access = omap_gem_dmabuf_begin_cpu_access,
        .end_cpu_access = omap_gem_dmabuf_end_cpu_access,
        .mmap = omap_gem_dmabuf_mmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(omap_gem_map_dma_buf,
+                                    omap_gem_unmap_dma_buf),
 };
 
 struct dma_buf *omap_gem_prime_export(struct drm_gem_object *obj, int flags)
diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c 
b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 3a7fce428898..b1ce00989be4 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -6,6 +6,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 
 #include <drm/panfrost_drm.h>
@@ -15,6 +16,8 @@
 #include "panfrost_gem.h"
 #include "panfrost_mmu.h"
 
+MODULE_IMPORT_NS("DMA_BUF");
+
 void panfrost_gem_init(struct panfrost_device *pfdev)
 {
        int err;
@@ -318,7 +321,8 @@ panfrost_gem_prime_begin_cpu_access(struct dma_buf *dma_buf,
                struct sg_table *sgt = attach->priv;
 
                if (sgt)
-                       dma_sync_sgtable_for_cpu(attach->dev, sgt, dir);
+                       dma_sync_sgtable_for_cpu(dma_buf_sgt_dma_device(attach),
+                                                sgt, dir);
        }
        dma_resv_unlock(obj->resv);
 
@@ -339,7 +343,8 @@ panfrost_gem_prime_end_cpu_access(struct dma_buf *dma_buf,
                struct sg_table *sgt = attach->priv;
 
                if (sgt)
-                       dma_sync_sgtable_for_device(attach->dev, sgt, dir);
+                       
dma_sync_sgtable_for_device(dma_buf_sgt_dma_device(attach),
+                                                   sgt, dir);
        }
 
        if (shmem->vaddr)
@@ -355,14 +360,14 @@ panfrost_gem_prime_end_cpu_access(struct dma_buf *dma_buf,
 static const struct dma_buf_ops panfrost_dma_buf_ops = {
        .attach = drm_gem_map_attach,
        .detach = drm_gem_map_detach,
-       .map_dma_buf = panfrost_gem_prime_map_dma_buf,
-       .unmap_dma_buf = panfrost_gem_prime_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .mmap = drm_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
        .begin_cpu_access = panfrost_gem_prime_begin_cpu_access,
        .end_cpu_access = panfrost_gem_prime_end_cpu_access,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(panfrost_gem_prime_map_dma_buf,
+                                    panfrost_gem_prime_unmap_dma_buf),
 };
 
 static struct dma_buf *
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c 
b/drivers/gpu/drm/panthor/panthor_gem.c
index 72908be5e144..4478a37562e6 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -7,6 +7,7 @@
 #include <linux/cleanup.h>
 #include <linux/debugfs.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
 #include <linux/slab.h>
@@ -512,7 +513,8 @@ panthor_gem_prime_begin_cpu_access(struct dma_buf *dma_buf,
                struct sg_table *sgt = attach->priv;
 
                if (sgt)
-                       dma_sync_sgtable_for_cpu(attach->dev, sgt, dir);
+                       dma_sync_sgtable_for_cpu(dma_buf_sgt_dma_device(attach),
+                                                sgt, dir);
        }
        dma_resv_unlock(obj->resv);
 
@@ -533,7 +535,8 @@ panthor_gem_prime_end_cpu_access(struct dma_buf *dma_buf,
                struct sg_table *sgt = attach->priv;
 
                if (sgt)
-                       dma_sync_sgtable_for_device(attach->dev, sgt, dir);
+                       
dma_sync_sgtable_for_device(dma_buf_sgt_dma_device(attach),
+                                                   sgt, dir);
        }
 
        if (bo->cmap.vaddr)
@@ -549,14 +552,14 @@ panthor_gem_prime_end_cpu_access(struct dma_buf *dma_buf,
 static const struct dma_buf_ops panthor_dma_buf_ops = {
        .attach = drm_gem_map_attach,
        .detach = drm_gem_map_detach,
-       .map_dma_buf = panthor_gem_prime_map_dma_buf,
-       .unmap_dma_buf = panthor_gem_prime_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
        .mmap = drm_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
        .begin_cpu_access = panthor_gem_prime_begin_cpu_access,
        .end_cpu_access = panthor_gem_prime_end_cpu_access,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(panthor_gem_prime_map_dma_buf,
+                                    panthor_gem_prime_unmap_dma_buf),
 };
 
 static struct dma_buf *
diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
index f76af733ea79..feb783ceb0d1 100644
--- a/drivers/gpu/drm/tegra/gem.c
+++ b/drivers/gpu/drm/tegra/gem.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/iommu.h>
 #include <linux/module.h>
 #include <linux/pagemap.h>
@@ -630,6 +631,7 @@ static struct sg_table *
 tegra_gem_prime_map_dma_buf(struct dma_buf_attachment *attach,
                            enum dma_data_direction dir)
 {
+       struct device *dma_dev = dma_buf_sgt_dma_device(attach);
        struct drm_gem_object *gem = attach->dmabuf->priv;
        struct tegra_bo *bo = to_tegra_bo(gem);
        struct sg_table *sgt;
@@ -643,12 +645,12 @@ tegra_gem_prime_map_dma_buf(struct dma_buf_attachment 
*attach,
                                              0, gem->size, GFP_KERNEL) < 0)
                        goto free;
        } else {
-               if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova,
+               if (dma_get_sgtable(dma_dev, sgt, bo->vaddr, bo->iova,
                                    gem->size) < 0)
                        goto free;
        }
 
-       if (dma_map_sgtable(attach->dev, sgt, dir, 0))
+       if (dma_map_sgtable(dma_dev, sgt, dir, 0))
                goto free;
 
        return sgt;
@@ -667,7 +669,7 @@ static void tegra_gem_prime_unmap_dma_buf(struct 
dma_buf_attachment *attach,
        struct tegra_bo *bo = to_tegra_bo(gem);
 
        if (bo->pages)
-               dma_unmap_sgtable(attach->dev, sgt, dir, 0);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(attach), sgt, dir, 0);
 
        sg_free_table(sgt);
        kfree(sgt);
@@ -740,14 +742,14 @@ static void tegra_gem_prime_vunmap(struct dma_buf *buf, 
struct iosys_map *map)
 }
 
 static const struct dma_buf_ops tegra_gem_prime_dmabuf_ops = {
-       .map_dma_buf = tegra_gem_prime_map_dma_buf,
-       .unmap_dma_buf = tegra_gem_prime_unmap_dma_buf,
        .release = tegra_gem_prime_release,
        .begin_cpu_access = tegra_gem_prime_begin_cpu_access,
        .end_cpu_access = tegra_gem_prime_end_cpu_access,
        .mmap = tegra_gem_prime_mmap,
        .vmap = tegra_gem_prime_vmap,
        .vunmap = tegra_gem_prime_vunmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(tegra_gem_prime_map_dma_buf,
+                                    tegra_gem_prime_unmap_dma_buf),
 };
 
 struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,
diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c 
b/drivers/gpu/drm/virtio/virtgpu_prime.c
index ebf471044d06..3d5203ac19b6 100644
--- a/drivers/gpu/drm/virtio/virtgpu_prime.c
+++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -24,6 +24,7 @@
 
 #include <drm/drm_prime.h>
 #include <drm/drm_print.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/virtio_dma_buf.h>
 
 #include "virtgpu_drv.h"
@@ -54,7 +55,8 @@ virtgpu_gem_map_dma_buf(struct dma_buf_attachment *attach,
        struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
 
        if (virtio_gpu_is_vram(bo))
-               return virtio_gpu_vram_map_dma_buf(bo, attach->dev, dir);
+               return virtio_gpu_vram_map_dma_buf(
+                       bo, dma_buf_sgt_dma_device(attach), dir);
 
        return drm_gem_map_dma_buf(attach, dir);
 }
@@ -67,7 +69,8 @@ static void virtgpu_gem_unmap_dma_buf(struct 
dma_buf_attachment *attach,
        struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
 
        if (virtio_gpu_is_vram(bo)) {
-               virtio_gpu_vram_unmap_dma_buf(attach->dev, sgt, dir);
+               virtio_gpu_vram_unmap_dma_buf(dma_buf_sgt_dma_device(attach),
+                                             sgt, dir);
                return;
        }
 
@@ -78,12 +81,12 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = 
 {
        .ops = {
                .attach = virtio_dma_buf_attach,
                .detach = drm_gem_map_detach,
-               .map_dma_buf = virtgpu_gem_map_dma_buf,
-               .unmap_dma_buf = virtgpu_gem_unmap_dma_buf,
                .release = drm_gem_dmabuf_release,
                .mmap = drm_gem_dmabuf_mmap,
                .vmap = drm_gem_dmabuf_vmap,
                .vunmap = drm_gem_dmabuf_vunmap,
+               DMA_BUF_SIMPLE_SGT_EXP_MATCH(virtgpu_gem_map_dma_buf,
+                                            virtgpu_gem_unmap_dma_buf),
        },
        .device_attach = drm_gem_map_attach,
        .get_uuid = virtgpu_virtio_get_uuid,
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index f6da927461b5..f8afbbeb360f 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -6,6 +6,7 @@
 #include <linux/anon_inodes.h>
 #include <linux/debugfs.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-resv.h>
 #include <linux/fault-inject.h>
 #include <linux/file.h>
@@ -1962,17 +1963,6 @@ struct iommufd_test_dma_buf {
        bool revoked;
 };
 
-static int iommufd_test_dma_buf_attach(struct dma_buf *dmabuf,
-                                      struct dma_buf_attachment *attachment)
-{
-       return 0;
-}
-
-static void iommufd_test_dma_buf_detach(struct dma_buf *dmabuf,
-                                       struct dma_buf_attachment *attachment)
-{
-}
-
 static struct sg_table *
 iommufd_test_dma_buf_map(struct dma_buf_attachment *attachment,
                         enum dma_data_direction dir)
@@ -1995,11 +1985,9 @@ static void iommufd_test_dma_buf_release(struct dma_buf 
*dmabuf)
 }
 
 static const struct dma_buf_ops iommufd_test_dmabuf_ops = {
-       .attach = iommufd_test_dma_buf_attach,
-       .detach = iommufd_test_dma_buf_detach,
-       .map_dma_buf = iommufd_test_dma_buf_map,
        .release = iommufd_test_dma_buf_release,
-       .unmap_dma_buf = iommufd_test_dma_buf_unmap,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(iommufd_test_dma_buf_map,
+                                    iommufd_test_dma_buf_unmap),
 };
 
 int iommufd_test_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c 
b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index 9ce6284cd5f2..536f839258c6 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/module.h>
 #include <linux/refcount.h>
 #include <linux/scatterlist.h>
@@ -372,8 +373,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_sgtable(db_attach->dev, sgt, attach->dma_dir,
-                                 DMA_ATTR_SKIP_CPU_SYNC);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(db_attach), sgt,
+                                 attach->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
        sg_free_table(sgt);
        kfree(attach);
        db_attach->priv = NULL;
@@ -392,8 +393,8 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
-               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir,
-                                 DMA_ATTR_SKIP_CPU_SYNC);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(db_attach), sgt,
+                                 attach->dma_dir, DMA_ATTR_SKIP_CPU_SYNC);
                attach->dma_dir = DMA_NONE;
        }
 
@@ -401,7 +402,7 @@ 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()
         */
-       if (dma_map_sgtable(db_attach->dev, sgt, dma_dir,
+       if (dma_map_sgtable(dma_buf_sgt_dma_device(db_attach), sgt, dma_dir,
                            DMA_ATTR_SKIP_CPU_SYNC)) {
                pr_err("failed to map scatterlist\n");
                return ERR_PTR(-EIO);
@@ -462,13 +463,13 @@ static int vb2_dc_dmabuf_ops_mmap(struct dma_buf *dbuf,
 static const struct dma_buf_ops vb2_dc_dmabuf_ops = {
        .attach = vb2_dc_dmabuf_ops_attach,
        .detach = vb2_dc_dmabuf_ops_detach,
-       .map_dma_buf = vb2_dc_dmabuf_ops_map,
-       .unmap_dma_buf = vb2_dc_dmabuf_ops_unmap,
        .begin_cpu_access = vb2_dc_dmabuf_ops_begin_cpu_access,
        .end_cpu_access = vb2_dc_dmabuf_ops_end_cpu_access,
        .vmap = vb2_dc_dmabuf_ops_vmap,
        .mmap = vb2_dc_dmabuf_ops_mmap,
        .release = vb2_dc_dmabuf_ops_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(vb2_dc_dmabuf_ops_map,
+                                    vb2_dc_dmabuf_ops_unmap),
 };
 
 static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf)
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c 
b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index b1d0695cda26..fba2027e6e8d 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -10,6 +10,7 @@
  * the Free Software Foundation.
  */
 
+#include <linux/dma-buf-mapping.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/refcount.h>
@@ -417,7 +418,8 @@ static void vb2_dma_sg_dmabuf_ops_detach(struct dma_buf 
*dbuf,
 
        /* release the scatterlist cache */
        if (attach->dma_dir != DMA_NONE)
-               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir, 0);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(db_attach), sgt,
+                                 attach->dma_dir, 0);
        sg_free_table(sgt);
        kfree(attach);
        db_attach->priv = NULL;
@@ -436,12 +438,14 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
-               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir, 0);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(db_attach), sgt,
+                                 attach->dma_dir, 0);
                attach->dma_dir = DMA_NONE;
        }
 
        /* mapping to the client with new direction */
-       if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
+       if (dma_map_sgtable(dma_buf_sgt_dma_device(db_attach), sgt, dma_dir,
+                           0)) {
                pr_err("failed to map scatterlist\n");
                return ERR_PTR(-EIO);
        }
@@ -510,13 +514,13 @@ static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf 
*dbuf,
 static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
        .attach = vb2_dma_sg_dmabuf_ops_attach,
        .detach = vb2_dma_sg_dmabuf_ops_detach,
-       .map_dma_buf = vb2_dma_sg_dmabuf_ops_map,
-       .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap,
        .begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
        .end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
        .vmap = vb2_dma_sg_dmabuf_ops_vmap,
        .mmap = vb2_dma_sg_dmabuf_ops_mmap,
        .release = vb2_dma_sg_dmabuf_ops_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(vb2_dma_sg_dmabuf_ops_map,
+                                    vb2_dma_sg_dmabuf_ops_unmap),
 };
 
 static struct dma_buf *vb2_dma_sg_get_dmabuf(struct vb2_buffer *vb,
diff --git a/drivers/media/common/videobuf2/videobuf2-vmalloc.c 
b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
index 63f023696f3e..d79acf83286a 100644
--- a/drivers/media/common/videobuf2/videobuf2-vmalloc.c
+++ b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
@@ -10,6 +10,7 @@
  * the Free Software Foundation.
  */
 
+#include <linux/dma-buf-mapping.h>
 #include <linux/io.h>
 #include <linux/module.h>
 #include <linux/mm.h>
@@ -261,7 +262,8 @@ static void vb2_vmalloc_dmabuf_ops_detach(struct dma_buf 
*dbuf,
 
        /* release the scatterlist cache */
        if (attach->dma_dir != DMA_NONE)
-               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir, 0);
+               dma_unmap_sgtable(dma_buf_sgt_dma_device(db_attach), sgt,
+                                 attach->dma_dir, 0);
        sg_free_table(sgt);
        kfree(attach);
        db_attach->priv = NULL;
@@ -270,6 +272,7 @@ static void vb2_vmalloc_dmabuf_ops_detach(struct dma_buf 
*dbuf,
 static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
        struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
 {
+       struct device *dma_dev = dma_buf_sgt_dma_device(db_attach);
        struct vb2_vmalloc_attachment *attach = db_attach->priv;
        struct sg_table *sgt;
 
@@ -280,12 +283,12 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
 
        /* release any previous cache */
        if (attach->dma_dir != DMA_NONE) {
-               dma_unmap_sgtable(db_attach->dev, sgt, attach->dma_dir, 0);
+               dma_unmap_sgtable(dma_dev, sgt, attach->dma_dir, 0);
                attach->dma_dir = DMA_NONE;
        }
 
        /* mapping to the client with new direction */
-       if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
+       if (dma_map_sgtable(dma_dev, sgt, dma_dir, 0)) {
                pr_err("failed to map scatterlist\n");
                return ERR_PTR(-EIO);
        }
@@ -326,11 +329,11 @@ static int vb2_vmalloc_dmabuf_ops_mmap(struct dma_buf 
*dbuf,
 static const struct dma_buf_ops vb2_vmalloc_dmabuf_ops = {
        .attach = vb2_vmalloc_dmabuf_ops_attach,
        .detach = vb2_vmalloc_dmabuf_ops_detach,
-       .map_dma_buf = vb2_vmalloc_dmabuf_ops_map,
-       .unmap_dma_buf = vb2_vmalloc_dmabuf_ops_unmap,
        .vmap = vb2_vmalloc_dmabuf_ops_vmap,
        .mmap = vb2_vmalloc_dmabuf_ops_mmap,
        .release = vb2_vmalloc_dmabuf_ops_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(vb2_vmalloc_dmabuf_ops_map,
+                                    vb2_vmalloc_dmabuf_ops_unmap),
 };
 
 static struct dma_buf *vb2_vmalloc_get_dmabuf(struct vb2_buffer *vb,
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index d4fac2caca86..85fed3a12f9c 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -5,6 +5,7 @@
 #include <linux/completion.h>
 #include <linux/device.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-resv.h>
 #include <linux/idr.h>
@@ -778,7 +779,8 @@ fastrpc_map_dma_buf(struct dma_buf_attachment *attachment,
 
        table = &a->sgt;
 
-       ret = dma_map_sgtable(attachment->dev, table, dir, 0);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), table, dir,
+                             0);
        if (ret)
                table = ERR_PTR(ret);
        return table;
@@ -788,7 +790,7 @@ static void fastrpc_unmap_dma_buf(struct dma_buf_attachment 
*attach,
                                  struct sg_table *table,
                                  enum dma_data_direction dir)
 {
-       dma_unmap_sgtable(attach->dev, table, dir, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attach), table, dir, 0);
 }
 
 static void fastrpc_release(struct dma_buf *dmabuf)
@@ -818,7 +820,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,
                return -EINVAL;
        }
 
-       a->dev = attachment->dev;
+       a->dev = dma_buf_sgt_dma_device(attachment);
        INIT_LIST_HEAD(&a->node);
        attachment->priv = a;
 
@@ -866,11 +868,11 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,
 static const struct dma_buf_ops fastrpc_dma_buf_ops = {
        .attach = fastrpc_dma_buf_attach,
        .detach = fastrpc_dma_buf_detatch,
-       .map_dma_buf = fastrpc_map_dma_buf,
-       .unmap_dma_buf = fastrpc_unmap_dma_buf,
        .mmap = fastrpc_mmap,
        .vmap = fastrpc_vmap,
        .release = fastrpc_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(fastrpc_map_dma_buf,
+                                    fastrpc_unmap_dma_buf),
 };
 
 static dma_addr_t fastrpc_compute_dma_addr(struct fastrpc_user *fl, dma_addr_t 
sg_dma_addr)
diff --git a/drivers/tee/tee_heap.c b/drivers/tee/tee_heap.c
index 007c00156520..099b153087a3 100644
--- a/drivers/tee/tee_heap.c
+++ b/drivers/tee/tee_heap.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-heap.h>
 #include <linux/genalloc.h>
 #include <linux/module.h>
@@ -104,7 +105,7 @@ static int tee_heap_attach(struct dma_buf *dmabuf,
                return ret;
        }
 
-       a->dev = attachment->dev;
+       a->dev = dma_buf_sgt_dma_device(attachment);
        attachment->priv = a;
 
        return 0;
@@ -126,8 +127,8 @@ tee_heap_map_dma_buf(struct dma_buf_attachment *attachment,
        struct tee_heap_attachment *a = attachment->priv;
        int ret;
 
-       ret = dma_map_sgtable(attachment->dev, &a->table, direction,
-                             DMA_ATTR_SKIP_CPU_SYNC);
+       ret = dma_map_sgtable(dma_buf_sgt_dma_device(attachment), &a->table,
+                             direction, DMA_ATTR_SKIP_CPU_SYNC);
        if (ret)
                return ERR_PTR(ret);
 
@@ -142,7 +143,7 @@ static void tee_heap_unmap_dma_buf(struct 
dma_buf_attachment *attachment,
 
        WARN_ON(&a->table != table);
 
-       dma_unmap_sgtable(attachment->dev, table, direction,
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), table, direction,
                          DMA_ATTR_SKIP_CPU_SYNC);
 }
 
@@ -160,9 +161,9 @@ static void tee_heap_buf_free(struct dma_buf *dmabuf)
 static const struct dma_buf_ops tee_heap_buf_ops = {
        .attach = tee_heap_attach,
        .detach = tee_heap_detach,
-       .map_dma_buf = tee_heap_map_dma_buf,
-       .unmap_dma_buf = tee_heap_unmap_dma_buf,
        .release = tee_heap_buf_free,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(tee_heap_map_dma_buf,
+                                    tee_heap_unmap_dma_buf),
 };
 
 static struct dma_buf *tee_dma_heap_alloc(struct dma_heap *heap,
diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c
index 83b0df460894..028cd7295fd7 100644
--- a/drivers/xen/gntdev-dmabuf.c
+++ b/drivers/xen/gntdev-dmabuf.c
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-direct.h>
 #include <linux/slab.h>
 #include <linux/types.h>
@@ -241,9 +242,10 @@ static void dmabuf_exp_ops_detach(struct dma_buf *dma_buf,
 
                if (sgt) {
                        if (gntdev_dmabuf_attach->dir != DMA_NONE)
-                               dma_unmap_sgtable(attach->dev, sgt,
-                                                 gntdev_dmabuf_attach->dir,
-                                                 DMA_ATTR_SKIP_CPU_SYNC);
+                               dma_unmap_sgtable(
+                                       dma_buf_sgt_dma_device(attach), sgt,
+                                       gntdev_dmabuf_attach->dir,
+                                       DMA_ATTR_SKIP_CPU_SYNC);
                        sg_free_table(sgt);
                }
 
@@ -257,12 +259,13 @@ static struct sg_table *
 dmabuf_exp_ops_map_dma_buf(struct dma_buf_attachment *attach,
                           enum dma_data_direction dir)
 {
+       struct device *dma_dev = dma_buf_sgt_dma_device(attach);
        struct gntdev_dmabuf_attachment *gntdev_dmabuf_attach = attach->priv;
        struct gntdev_dmabuf *gntdev_dmabuf = attach->dmabuf->priv;
        struct sg_table *sgt;
 
        pr_debug("Mapping %d pages for dev %p\n", gntdev_dmabuf->nr_pages,
-                attach->dev);
+                dma_dev);
 
        if (dir == DMA_NONE || !gntdev_dmabuf_attach)
                return ERR_PTR(-EINVAL);
@@ -281,7 +284,7 @@ dmabuf_exp_ops_map_dma_buf(struct dma_buf_attachment 
*attach,
        sgt = dmabuf_pages_to_sgt(gntdev_dmabuf->pages,
                                  gntdev_dmabuf->nr_pages);
        if (!IS_ERR(sgt)) {
-               if (dma_map_sgtable(attach->dev, sgt, dir,
+               if (dma_map_sgtable(dma_dev, sgt, dir,
                                    DMA_ATTR_SKIP_CPU_SYNC)) {
                        sg_free_table(sgt);
                        kfree(sgt);
@@ -292,7 +295,7 @@ dmabuf_exp_ops_map_dma_buf(struct dma_buf_attachment 
*attach,
                }
        }
        if (IS_ERR(sgt))
-               pr_debug("Failed to map sg table for dev %p\n", attach->dev);
+               pr_debug("Failed to map sg table for dev %p\n", dma_dev);
        return sgt;
 }
 
@@ -338,9 +341,9 @@ static void dmabuf_exp_ops_release(struct dma_buf *dma_buf)
 static const struct dma_buf_ops dmabuf_exp_ops =  {
        .attach = dmabuf_exp_ops_attach,
        .detach = dmabuf_exp_ops_detach,
-       .map_dma_buf = dmabuf_exp_ops_map_dma_buf,
-       .unmap_dma_buf = dmabuf_exp_ops_unmap_dma_buf,
        .release = dmabuf_exp_ops_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(dmabuf_exp_ops_map_dma_buf,
+                                    dmabuf_exp_ops_unmap_dma_buf),
 };
 
 struct gntdev_dmabuf_export_args {
diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 64ea19253ee3..c2eaa14b9ddd 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -32,6 +32,7 @@
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
+#include <linux/dma-buf-mapping.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_rect.h>
 #include <drm/drm_modeset_lock.h>
@@ -872,7 +873,7 @@ static struct sg_table *mbochs_map_dmabuf(struct 
dma_buf_attachment *at,
        if (sg_alloc_table_from_pages(sg, dmabuf->pages, dmabuf->pagecount,
                                      0, dmabuf->mode.size, GFP_KERNEL) < 0)
                goto err2;
-       if (dma_map_sgtable(at->dev, sg, direction, 0))
+       if (dma_map_sgtable(dma_buf_sgt_dma_device(at), sg, direction, 0))
                goto err3;
 
        return sg;
@@ -894,7 +895,7 @@ static void mbochs_unmap_dmabuf(struct dma_buf_attachment 
*at,
 
        dev_dbg(dev, "%s: %d\n", __func__, dmabuf->id);
 
-       dma_unmap_sgtable(at->dev, sg, direction, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(at), sg, direction, 0);
        sg_free_table(sg);
        kfree(sg);
 }
@@ -918,11 +919,10 @@ static void mbochs_release_dmabuf(struct dma_buf *buf)
        mutex_unlock(&mdev_state->ops_lock);
 }
 
-static struct dma_buf_ops mbochs_dmabuf_ops = {
-       .map_dma_buf      = mbochs_map_dmabuf,
-       .unmap_dma_buf    = mbochs_unmap_dmabuf,
+static const struct dma_buf_ops mbochs_dmabuf_ops = {
        .release          = mbochs_release_dmabuf,
        .mmap             = mbochs_mmap_dmabuf,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(mbochs_map_dmabuf, mbochs_unmap_dmabuf),
 };
 
 static struct mbochs_dmabuf *mbochs_dmabuf_alloc(struct mdev_state *mdev_state,
diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c
index 4bc40f328f58..63cee7b2c206 100644
--- a/sound/soc/fsl/fsl_asrc_m2m.c
+++ b/sound/soc/fsl/fsl_asrc_m2m.c
@@ -7,6 +7,7 @@
 
 #include <linux/dma/imx-dma.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <sound/asound.h>
@@ -417,6 +418,7 @@ static int fsl_asrc_m2m_mmap(struct dma_buf *dmabuf, struct 
vm_area_struct *vma)
 static struct sg_table *fsl_asrc_m2m_map_dma_buf(struct dma_buf_attachment 
*attachment,
                                                 enum dma_data_direction 
direction)
 {
+       struct device *dma_dev = dma_buf_sgt_dma_device(attachment);
        struct snd_dma_buffer *dmab = attachment->dmabuf->priv;
        struct sg_table *sgt;
 
@@ -424,10 +426,10 @@ static struct sg_table *fsl_asrc_m2m_map_dma_buf(struct 
dma_buf_attachment *atta
        if (!sgt)
                return NULL;
 
-       if (dma_get_sgtable(attachment->dev, sgt, dmab->area, dmab->addr, 
dmab->bytes) < 0)
+       if (dma_get_sgtable(dma_dev, sgt, dmab->area, dmab->addr, dmab->bytes) 
< 0)
                goto free;
 
-       if (dma_map_sgtable(attachment->dev, sgt, direction, 0))
+       if (dma_map_sgtable(dma_dev, sgt, direction, 0))
                goto free;
 
        return sgt;
@@ -442,7 +444,7 @@ static void fsl_asrc_m2m_unmap_dma_buf(struct 
dma_buf_attachment *attachment,
                                       struct sg_table *table,
                                       enum dma_data_direction direction)
 {
-       dma_unmap_sgtable(attachment->dev, table, direction, 0);
+       dma_unmap_sgtable(dma_buf_sgt_dma_device(attachment), table, direction, 
0);
 }
 
 static void fsl_asrc_m2m_release(struct dma_buf *dmabuf)
@@ -452,9 +454,9 @@ static void fsl_asrc_m2m_release(struct dma_buf *dmabuf)
 
 static const struct dma_buf_ops fsl_asrc_m2m_dma_buf_ops = {
        .mmap = fsl_asrc_m2m_mmap,
-       .map_dma_buf = fsl_asrc_m2m_map_dma_buf,
-       .unmap_dma_buf = fsl_asrc_m2m_unmap_dma_buf,
        .release = fsl_asrc_m2m_release,
+       DMA_BUF_SIMPLE_SGT_EXP_MATCH(fsl_asrc_m2m_map_dma_buf,
+                                    fsl_asrc_m2m_unmap_dma_buf),
 };
 
 static int fsl_asrc_m2m_comp_task_create(struct snd_compr_stream *stream,
-- 
2.54.0

Reply via email to