From: Farah Kassabri <[email protected]> Instead of driver-specific code, use the new drm helper drm_gem_prime_self_import() to detect self-import of a dma-buf in Xe.
Expose the helper within Xe as xe_dma_buf_to_gem() for future use. Signed-off-by: Farah Kassabri <[email protected]> Signed-off-by: Niranjana Vishwanathapura <[email protected]> Reviewed-by: Matthew Brost <[email protected]> --- drivers/gpu/drm/xe/xe_dma_buf.c | 23 +++++++++++++---------- drivers/gpu/drm/xe/xe_dma_buf.h | 2 ++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index 6a85b292dee7..4e1b447f4235 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -239,6 +239,12 @@ static const struct dma_buf_ops xe_dmabuf_ops = { .vunmap = drm_gem_dmabuf_vunmap, }; +struct drm_gem_object *xe_dma_buf_to_gem(struct drm_device *dev, + struct dma_buf *dma_buf) +{ + return drm_gem_prime_self_import(dev, dma_buf, &xe_dmabuf_ops); +} + struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags) { struct xe_bo *bo = gem_to_xe_bo(obj); @@ -372,17 +378,14 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev, struct dma_buf_attachment *attach; struct drm_gem_object *obj; - if (dma_buf->ops == &xe_dmabuf_ops) { - obj = dma_buf->priv; - if (obj->dev == dev && - !XE_TEST_ONLY(test && test->force_different_devices)) { - /* - * Importing dmabuf exported from out own gem increases - * refcount on gem itself instead of f_count of dmabuf. - */ - drm_gem_object_get(obj); + obj = xe_dma_buf_to_gem(dev, dma_buf); + if (obj) { + if (!XE_TEST_ONLY(test && test->force_different_devices)) return obj; - } + + /* Test only: force different devices */ + drm_gem_object_put(obj); + obj = NULL; } /* diff --git a/drivers/gpu/drm/xe/xe_dma_buf.h b/drivers/gpu/drm/xe/xe_dma_buf.h index 861dd28a862c..d0c7893a5a6f 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.h +++ b/drivers/gpu/drm/xe/xe_dma_buf.h @@ -8,6 +8,8 @@ #include <drm/drm_gem.h> +struct drm_gem_object *xe_dma_buf_to_gem(struct drm_device *dev, + struct dma_buf *dma_buf); struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags); struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf); -- 2.43.0
