drm_gem_is_prime_exported_dma_buf() checks the dma_buf->ops against drm_gem_prime_dmabuf_ops, which makes it impossible to use if the driver implements custom dma_buf_ops. Instead of duplicating a bunch of helpers to work around it, let's provide a way for drivers to expose their custom dma_buf_ops so the core prime helpers can rely on that instead of hardcoding &drm_gem_prime_dmabuf_ops.
v5: - New patch v6: - Pass custom dma_buf_ops directly instead of through a getter Signed-off-by: Boris Brezillon <[email protected]> --- drivers/gpu/drm/drm_prime.c | 10 ++++++++-- include/drm/drm_drv.h | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 21809a82187b..86fd95f0c105 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -904,6 +904,12 @@ unsigned long drm_prime_get_contiguous_size(struct sg_table *sgt) } EXPORT_SYMBOL(drm_prime_get_contiguous_size); +static const struct dma_buf_ops * +drm_gem_prime_get_dma_buf_ops(struct drm_device *dev) +{ + return dev->driver->dma_buf_ops ?: &drm_gem_prime_dmabuf_ops; +} + /** * drm_gem_prime_export - helper library implementation of the export callback * @obj: GEM object to export @@ -920,7 +926,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj, struct dma_buf_export_info exp_info = { .exp_name = KBUILD_MODNAME, /* white lie for debug */ .owner = dev->driver->fops->owner, - .ops = &drm_gem_prime_dmabuf_ops, + .ops = drm_gem_prime_get_dma_buf_ops(dev), .size = obj->size, .flags = flags, .priv = obj, @@ -947,7 +953,7 @@ bool drm_gem_is_prime_exported_dma_buf(struct drm_device *dev, { struct drm_gem_object *obj = dma_buf->priv; - return (dma_buf->ops == &drm_gem_prime_dmabuf_ops) && (obj->dev == dev); + return dma_buf->ops == drm_gem_prime_get_dma_buf_ops(dev) && obj->dev == dev; } EXPORT_SYMBOL(drm_gem_is_prime_exported_dma_buf); diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 42fc085f986d..1c6dae60d523 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -431,6 +431,14 @@ struct drm_driver { * some examples. */ const struct file_operations *fops; + + /** + * @dma_buf_ops: + * + * dma_buf_ops to use for buffers exported by this driver. When NULL, + * the drm_prime logic defaults to &drm_gem_prime_dmabuf_ops. + */ + const struct dma_buf_ops *dma_buf_ops; }; void *__devm_drm_dev_alloc(struct device *parent, -- 2.51.1
