drm/i915: Introduce GEM object functions
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 23 Sep 2020 10:21:43 +0000 (12:21 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Fri, 25 Sep 2020 07:20:34 +0000 (09:20 +0200)
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in i915.

v2:
* move object-function instance to i915_gem_object.c (Jani)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Acked-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200923102159.24084-7-tzimmermann@suse.de
drivers/gpu/drm/i915/gem/i915_gem_object.c
drivers/gpu/drm/i915/gem/i915_gem_object.h
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/selftests/mock_gem_device.c

index c8421fd..3389ac9 100644 (file)
@@ -39,9 +39,18 @@ static struct i915_global_object {
        struct kmem_cache *slab_objects;
 } global;
 
+static const struct drm_gem_object_funcs i915_gem_object_funcs;
+
 struct drm_i915_gem_object *i915_gem_object_alloc(void)
 {
-       return kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+       struct drm_i915_gem_object *obj;
+
+       obj = kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+       if (!obj)
+               return NULL;
+       obj->base.funcs = &i915_gem_object_funcs;
+
+       return obj;
 }
 
 void i915_gem_object_free(struct drm_i915_gem_object *obj)
@@ -101,7 +110,7 @@ void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
                !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE);
 }
 
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)
+static void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)
 {
        struct drm_i915_gem_object *obj = to_intel_bo(gem);
        struct drm_i915_file_private *fpriv = file->driver_priv;
@@ -264,7 +273,7 @@ static void __i915_gem_free_work(struct work_struct *work)
        i915_gem_flush_free_objects(i915);
 }
 
-void i915_gem_free_object(struct drm_gem_object *gem_obj)
+static void i915_gem_free_object(struct drm_gem_object *gem_obj)
 {
        struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
        struct drm_i915_private *i915 = to_i915(obj->base.dev);
@@ -403,6 +412,12 @@ int __init i915_global_objects_init(void)
        return 0;
 }
 
+static const struct drm_gem_object_funcs i915_gem_object_funcs = {
+       .free = i915_gem_free_object,
+       .close = i915_gem_close_object,
+       .export = i915_gem_prime_export,
+};
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/huge_gem_object.c"
 #include "selftests/huge_pages.c"
index d46db8d..eaf3d41 100644 (file)
@@ -38,9 +38,6 @@ void __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
 
 int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align);
 
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);
-void i915_gem_free_object(struct drm_gem_object *obj);
-
 void i915_gem_flush_free_objects(struct drm_i915_private *i915);
 
 struct sg_table *
index 00292a8..d580d86 100644 (file)
@@ -1853,12 +1853,8 @@ static struct drm_driver driver = {
        .lastclose = i915_driver_lastclose,
        .postclose = i915_driver_postclose,
 
-       .gem_close_object = i915_gem_close_object,
-       .gem_free_object_unlocked = i915_gem_free_object,
-
        .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
        .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-       .gem_prime_export = i915_gem_prime_export,
        .gem_prime_import = i915_gem_prime_import,
 
        .dumb_create = i915_gem_dumb_create,
index c207d22..cf81ba8 100644 (file)
@@ -85,9 +85,6 @@ static struct drm_driver mock_driver = {
        .name = "mock",
        .driver_features = DRIVER_GEM,
        .release = mock_device_release,
-
-       .gem_close_object = i915_gem_close_object,
-       .gem_free_object_unlocked = i915_gem_free_object,
 };
 
 static void release_dev(struct device *dev)