Skip to content

Commit b57aa47

Browse files
author
Thomas Zimmermann
committed
drm/gem: Test for imported GEM buffers with helper
Add drm_gem_is_imported() that tests if a GEM object's buffer has been imported. Update the GEM code accordingly. GEM code usually tests for imports if import_attach has been set in struct drm_gem_object. But attaching a dma-buf on import requires a DMA-capable importer device, which is not the case for many serial busses like USB or I2C. The new helper tests if a GEM object's dma-buf has been created from the GEM object. Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Anusha Srivatsa <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ced7486 commit b57aa47

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/gpu/drm/drm_gem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
348348
return -ENOENT;
349349

350350
/* Don't allow imported objects to be mapped */
351-
if (obj->import_attach) {
351+
if (drm_gem_is_imported(obj)) {
352352
ret = -EINVAL;
353353
goto out;
354354
}
@@ -1178,7 +1178,7 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
11781178
drm_vma_node_start(&obj->vma_node));
11791179
drm_printf_indent(p, indent, "size=%zu\n", obj->size);
11801180
drm_printf_indent(p, indent, "imported=%s\n",
1181-
str_yes_no(obj->import_attach));
1181+
str_yes_no(drm_gem_is_imported(obj)));
11821182

11831183
if (obj->funcs->print_info)
11841184
obj->funcs->print_info(p, indent, obj);

include/drm/drm_gem.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636

3737
#include <linux/kref.h>
38+
#include <linux/dma-buf.h>
3839
#include <linux/dma-resv.h>
3940
#include <linux/list.h>
4041
#include <linux/mutex.h>
@@ -575,6 +576,19 @@ static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_obje
575576
return (obj->handle_count > 1) || obj->dma_buf;
576577
}
577578

579+
/**
580+
* drm_gem_is_imported() - Tests if GEM object's buffer has been imported
581+
* @obj: the GEM object
582+
*
583+
* Returns:
584+
* True if the GEM object's buffer has been imported, false otherwise
585+
*/
586+
static inline bool drm_gem_is_imported(const struct drm_gem_object *obj)
587+
{
588+
/* The dma-buf's priv field points to the original GEM object. */
589+
return obj->dma_buf && (obj->dma_buf->priv != obj);
590+
}
591+
578592
#ifdef CONFIG_LOCKDEP
579593
/**
580594
* drm_gem_gpuva_set_lock() - Set the lock protecting accesses to the gpuva list.

0 commit comments

Comments
 (0)