When the next patch converts exporters to use SGT natively, the
dma_buf->ops->map_dma_buf will become NULL. Additionally check
sgt_exp_ops to see the new location.

Signed-off-by: Jason Gunthorpe <[email protected]>
---
 drivers/gpu/drm/drm_prime.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 21809a82187b12..d093a888b0df8f 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -28,6 +28,7 @@
 
 #include <linux/export.h>
 #include <linux/dma-buf.h>
+#include <linux/dma-buf-mapping.h>
 #include <linux/rbtree.h>
 #include <linux/module.h>
 
@@ -587,6 +588,18 @@ int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, 
void *data,
  * option for sharing lots of buffers for rendering.
  */
 
+static bool is_gem_map_dma_buf(struct dma_buf_attachment *attach)
+{
+       const struct dma_buf_mapping_sgt_exp_ops *sgt_exp_ops =
+               dma_buf_get_sgt_ops(attach);
+
+       if (attach->dmabuf->ops->map_dma_buf == drm_gem_map_dma_buf)
+               return true;
+       if (sgt_exp_ops && sgt_exp_ops->map_dma_buf == drm_gem_map_dma_buf)
+               return true;
+       return false;
+}
+
 /**
  * drm_gem_map_attach - dma_buf attach implementation for GEM
  * @dma_buf: buffer to attach device to
@@ -608,7 +621,7 @@ int drm_gem_map_attach(struct dma_buf *dma_buf,
         * drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers
         * that implement their own ->map_dma_buf() do not.
         */
-       if (dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf &&
+       if (is_gem_map_dma_buf(attach) &&
            !obj->funcs->get_sg_table)
                return -ENOSYS;
 
-- 
2.43.0

Reply via email to