drm: Add |struct drm_gem_vram_object| callbacks for |struct ttm_bo_driver|
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 8 May 2019 08:26:12 +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 ttm_bo_driver|.

v2:
* drm_is_gem_vram() is now a private function
* documentation fixes

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: http://patchwork.freedesktop.org/patch/msgid/20190508082630.15116-3-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 761a546412f85872787f504cf95c0a1f0c5bebed..d6c4e0d0a1c5c5bf5271409ac1a9fb4eb2ec11ad 100644 (file)
@@ -410,3 +410,53 @@ void drm_gem_vram_kunmap(struct drm_gem_vram_object *gbo)
        drm_gem_vram_kunmap_at(gbo, &gbo->kmap);
 }
 EXPORT_SYMBOL(drm_gem_vram_kunmap);
+
+/*
+ * Helpers for struct ttm_bo_driver
+ */
+
+static bool drm_is_gem_vram(struct ttm_buffer_object *bo)
+{
+       return (bo->destroy == ttm_buffer_object_destroy);
+}
+
+/**
+ * drm_gem_vram_bo_driver_evict_flags() - \
+       Implements &struct ttm_bo_driver.evict_flags
+ * @bo:        TTM buffer object. Refers to &struct drm_gem_vram_object.bo
+ * @pl:        TTM placement information.
+ */
+void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
+                                       struct ttm_placement *pl)
+{
+       struct drm_gem_vram_object *gbo;
+
+       /* TTM may pass BOs that are not GEM VRAM BOs. */
+       if (!drm_is_gem_vram(bo))
+               return;
+
+       gbo = drm_gem_vram_of_bo(bo);
+       drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM);
+       *pl = gbo->placement;
+}
+EXPORT_SYMBOL(drm_gem_vram_bo_driver_evict_flags);
+
+/**
+ * drm_gem_vram_bo_driver_verify_access() - \
+       Implements &struct ttm_bo_driver.verify_access
+ * @bo:                TTM buffer object. Refers to &struct drm_gem_vram_object.bo
+ * @filp:      File pointer.
+ *
+ * Returns:
+ * 0 on success, or
+ * a negative errno code otherwise.
+ */
+int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
+                                        struct file *filp)
+{
+       struct drm_gem_vram_object *gbo = drm_gem_vram_of_bo(bo);
+
+       return drm_vma_node_verify_access(&gbo->gem.vma_node,
+                                         filp->private_data);
+}
+EXPORT_SYMBOL(drm_gem_vram_bo_driver_verify_access);
index 5802dd6949397ccdf957c9591943f9bfa352d254..1915d395830451dc29df47cd869569075e08cc75 100644 (file)
@@ -89,4 +89,14 @@ void drm_gem_vram_kunmap_at(struct drm_gem_vram_object *gbo,
                            struct ttm_bo_kmap_obj *kmap);
 void drm_gem_vram_kunmap(struct drm_gem_vram_object *gbo);
 
+/*
+ * Helpers for struct ttm_bo_driver
+ */
+
+void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
+                                       struct ttm_placement *pl);
+
+int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
+                                        struct file *filp);
+
 #endif