drm: Add |struct drm_gem_vram_object| callbacks for |struct drm_driver|
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 8 May 2019 08:26:13 +0000 (10:26 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 15 May 2019 14:17:05 +0000 (16:17 +0200)
The provided helpers can be used for the respective callback functions
in |struct drm_driver|.

v4:
* cleanups from checkpatch.pl
v2:
* documentation fixes

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: http://patchwork.freedesktop.org/patch/msgid/20190508082630.15116-4-tzimmermann@suse.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
drivers/gpu/drm/drm_gem_vram_helper.c
include/drm/drm_gem_vram_helper.h

index d6c4e0d0a1c5c5bf5271409ac1a9fb4eb2ec11ad..2640283743360963b365e83149f2bbd682fe7267 100644 (file)
@@ -460,3 +460,52 @@ int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
                                          filp->private_data);
 }
 EXPORT_SYMBOL(drm_gem_vram_bo_driver_verify_access);
+
+/*
+ * Helpers for struct drm_driver
+ */
+
+/**
+ * drm_gem_vram_driver_gem_free_object_unlocked() - \
+       Implements &struct drm_driver.gem_free_object_unlocked
+ * @gem:       GEM object. Refers to &struct drm_gem_vram_object.gem
+ */
+void drm_gem_vram_driver_gem_free_object_unlocked(struct drm_gem_object *gem)
+{
+       struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+
+       drm_gem_vram_put(gbo);
+}
+EXPORT_SYMBOL(drm_gem_vram_driver_gem_free_object_unlocked);
+
+/**
+ * drm_gem_vram_driver_dumb_mmap_offset() - \
+       Implements &struct drm_driver.dumb_mmap_offset
+ * @file:      DRM file pointer.
+ * @dev:       DRM device.
+ * @handle:    GEM handle
+ * @offset:    Returns the mapping's memory offset on success
+ *
+ * Returns:
+ * 0 on success, or
+ * a negative errno code otherwise.
+ */
+int drm_gem_vram_driver_dumb_mmap_offset(struct drm_file *file,
+                                        struct drm_device *dev,
+                                        uint32_t handle, uint64_t *offset)
+{
+       struct drm_gem_object *gem;
+       struct drm_gem_vram_object *gbo;
+
+       gem = drm_gem_object_lookup(file, handle);
+       if (!gem)
+               return -ENOENT;
+
+       gbo = drm_gem_vram_of_gem(gem);
+       *offset = drm_gem_vram_mmap_offset(gbo);
+
+       drm_gem_object_put_unlocked(gem);
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_gem_vram_driver_dumb_mmap_offset);
index 1915d395830451dc29df47cd869569075e08cc75..b87cb2e9d9dace5b800bed3a1de28000e5e3e6da 100644 (file)
@@ -99,4 +99,14 @@ void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
 int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
                                         struct file *filp);
 
+/*
+ * Helpers for struct drm_driver
+ */
+
+void drm_gem_vram_driver_gem_free_object_unlocked(struct drm_gem_object *gem);
+
+int drm_gem_vram_driver_dumb_mmap_offset(struct drm_file *file,
+                                        struct drm_device *dev,
+                                        uint32_t handle, uint64_t *offset);
+
 #endif