[PATCH v2 10/23] drm: Check the SGT ops for drm_gem_map_dma_buf()
Alistair Popple
apopple at nvidia.com
Wed Nov 4 22:40:45 PST 2026
From: Jason Gunthorpe <jgg at nvidia.com>
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 <jgg at nvidia.com>
Signed-off-by: Alistair Popple <apopple at nvidia.com>
---
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 e27bda3423ed..c5184ca602bc 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.54.0
More information about the Linux-nvme
mailing list