[PATCH 1/3] drm: add mmap() to drm_gem_object_funcs

Gerd Hoffmann kraxel at redhat.com
Thu Jun 20 06:15:45 UTC 2019


drm_gem_object_funcs->vm_ops alone can't handle
everything mmap() needs.  Add a new callback for it.

Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
---
 include/drm/drm_gem.h     | 9 +++++++++
 drivers/gpu/drm/drm_gem.c | 4 ++++
 2 files changed, 13 insertions(+)

diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index a9121fe66ea2..2e680a065470 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -144,6 +144,15 @@ struct drm_gem_object_funcs {
 	 */
 	void (*vunmap)(struct drm_gem_object *obj, void *vaddr);
 
+	/**
+	 * @mmap:
+	 *
+	 * Called by drm_gem_mmap() for additional checks/setup.
+	 *
+	 * This callback is optional.
+	 */
+	int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);
+
 	/**
 	 * @vm_ops:
 	 *
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index a8c4468f03d9..1deae1b70f39 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1192,6 +1192,10 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
 	ret = drm_gem_mmap_obj(obj, drm_vma_node_size(node) << PAGE_SHIFT,
 			       vma);
 
+	if (ret == 0)
+		if (obj->funcs->mmap)
+			ret = obj->funcs->mmap(obj, vma);
+
 	drm_gem_object_put_unlocked(obj);
 
 	return ret;
-- 
2.18.1



More information about the dri-devel mailing list