]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/i915: Add getter/setter for i915_gem_object->frontbuffer
authorJouni Högander <jouni.hogander@intel.com>
Thu, 27 Jul 2023 06:41:40 +0000 (09:41 +0300)
committerJouni Högander <jouni.hogander@intel.com>
Tue, 1 Aug 2023 05:47:08 +0000 (08:47 +0300)
Add getter/setter for i915_gem_object->frontbuffer and use it instead of
directly touching i915_gem_object->frontbuffer frontbuffer pointer.

v3:
 - Fix intel_frontbuffer_get return value
 - s/front_ret/cur/
v2: Move getter/setter into i915_gem_object.h

Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230727064142.751976-3-jouni.hogander@intel.com
drivers/gpu/drm/i915/display/intel_frontbuffer.c
drivers/gpu/drm/i915/display/intel_frontbuffer.h
drivers/gpu/drm/i915/gem/i915_gem_object.c
drivers/gpu/drm/i915/gem/i915_gem_object.h
drivers/gpu/drm/i915/i915_vma.c

index 3ce0436a0c7dfbd9f108953763b60f3aaaf1cf97..56f45370fee0d6e06c047f8b72ed9dd0b0237773 100644 (file)
@@ -237,7 +237,7 @@ static void frontbuffer_release(struct kref *ref)
        }
        spin_unlock(&obj->vma.lock);
 
-       RCU_INIT_POINTER(obj->frontbuffer, NULL);
+       i915_gem_object_set_frontbuffer(obj, NULL);
        spin_unlock(&intel_bo_to_i915(obj)->display.fb_tracking.lock);
 
        i915_active_fini(&front->write);
@@ -250,9 +250,9 @@ struct intel_frontbuffer *
 intel_frontbuffer_get(struct drm_i915_gem_object *obj)
 {
        struct drm_i915_private *i915 = intel_bo_to_i915(obj);
-       struct intel_frontbuffer *front;
+       struct intel_frontbuffer *front, *cur;
 
-       front = __intel_frontbuffer_get(obj);
+       front = i915_gem_object_get_frontbuffer(obj);
        if (front)
                return front;
 
@@ -269,17 +269,11 @@ intel_frontbuffer_get(struct drm_i915_gem_object *obj)
                         I915_ACTIVE_RETIRE_SLEEPS);
 
        spin_lock(&i915->display.fb_tracking.lock);
-       if (rcu_access_pointer(obj->frontbuffer)) {
-               kfree(front);
-               front = rcu_dereference_protected(obj->frontbuffer, true);
-               kref_get(&front->ref);
-       } else {
-               i915_gem_object_get(obj);
-               rcu_assign_pointer(obj->frontbuffer, front);
-       }
+       cur = i915_gem_object_set_frontbuffer(obj, front);
        spin_unlock(&i915->display.fb_tracking.lock);
-
-       return front;
+       if (cur != front)
+               kfree(front);
+       return cur;
 }
 
 void intel_frontbuffer_put(struct intel_frontbuffer *front)
index 3c474ed937fb2c4352639b65a443e31647ec5401..eeccc847331daae40f0b58edd1bf70e46b5aade3 100644 (file)
@@ -75,33 +75,6 @@ void intel_frontbuffer_flip(struct drm_i915_private *i915,
 
 void intel_frontbuffer_put(struct intel_frontbuffer *front);
 
-static inline struct intel_frontbuffer *
-__intel_frontbuffer_get(const struct drm_i915_gem_object *obj)
-{
-       struct intel_frontbuffer *front;
-
-       if (likely(!rcu_access_pointer(obj->frontbuffer)))
-               return NULL;
-
-       rcu_read_lock();
-       do {
-               front = rcu_dereference(obj->frontbuffer);
-               if (!front)
-                       break;
-
-               if (unlikely(!kref_get_unless_zero(&front->ref)))
-                       continue;
-
-               if (likely(front == rcu_access_pointer(obj->frontbuffer)))
-                       break;
-
-               intel_frontbuffer_put(front);
-       } while (1);
-       rcu_read_unlock();
-
-       return front;
-}
-
 struct intel_frontbuffer *
 intel_frontbuffer_get(struct drm_i915_gem_object *obj);
 
index 97ac6fb37958f4a44e8ee8b5c826219be908eda8..1484680980824c16f3773c906b54bda6f6e7d56b 100644 (file)
@@ -469,7 +469,7 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,
 {
        struct intel_frontbuffer *front;
 
-       front = __intel_frontbuffer_get(obj);
+       front = i915_gem_object_get_frontbuffer(obj);
        if (front) {
                intel_frontbuffer_flush(front, origin);
                intel_frontbuffer_put(front);
@@ -481,7 +481,7 @@ void __i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj,
 {
        struct intel_frontbuffer *front;
 
-       front = __intel_frontbuffer_get(obj);
+       front = i915_gem_object_get_frontbuffer(obj);
        if (front) {
                intel_frontbuffer_invalidate(front, origin);
                intel_frontbuffer_put(front);
index 884a17275b3a4ab42caa50173b54fb4040596660..112c130cfaaa868f6ca60f94938dc134e27e56fc 100644 (file)
@@ -891,4 +891,71 @@ static inline int i915_gem_object_userptr_validate(struct drm_i915_gem_object *o
 
 #endif
 
+/**
+ * i915_gem_object_get_frontbuffer - Get the object's frontbuffer
+ * @obj: The object whose frontbuffer to get.
+ *
+ * Get pointer to object's frontbuffer if such exists. Please note that RCU
+ * mechanism is used to handle e.g. ongoing removal of frontbuffer pointer.
+ *
+ * Return: pointer to object's frontbuffer is such exists or NULL
+ */
+static inline struct intel_frontbuffer *
+i915_gem_object_get_frontbuffer(const struct drm_i915_gem_object *obj)
+{
+       struct intel_frontbuffer *front;
+
+       if (likely(!rcu_access_pointer(obj->frontbuffer)))
+               return NULL;
+
+       rcu_read_lock();
+       do {
+               front = rcu_dereference(obj->frontbuffer);
+               if (!front)
+                       break;
+
+               if (unlikely(!kref_get_unless_zero(&front->ref)))
+                       continue;
+
+               if (likely(front == rcu_access_pointer(obj->frontbuffer)))
+                       break;
+
+               intel_frontbuffer_put(front);
+       } while (1);
+       rcu_read_unlock();
+
+       return front;
+}
+
+/**
+ * i915_gem_object_set_frontbuffer - Set the object's frontbuffer
+ * @obj: The object whose frontbuffer to set.
+ * @front: The frontbuffer to set
+ *
+ * Set object's frontbuffer pointer. If frontbuffer is already set for the
+ * object keep it and return it's pointer to the caller. Please note that RCU
+ * mechanism is used to handle e.g. ongoing removal of frontbuffer pointer. This
+ * function is protected by i915->display.fb_tracking.lock
+ *
+ * Return: pointer to frontbuffer which was set.
+ */
+static inline struct intel_frontbuffer *
+i915_gem_object_set_frontbuffer(struct drm_i915_gem_object *obj,
+                               struct intel_frontbuffer *front)
+{
+       struct intel_frontbuffer *cur = front;
+
+       if (!front) {
+               RCU_INIT_POINTER(obj->frontbuffer, NULL);
+       } else if (rcu_access_pointer(obj->frontbuffer)) {
+               cur = rcu_dereference_protected(obj->frontbuffer, true);
+               kref_get(&cur->ref);
+       } else {
+               drm_gem_object_get(intel_bo_to_drm_bo(obj));
+               rcu_assign_pointer(obj->frontbuffer, front);
+       }
+
+       return cur;
+}
+
 #endif
index af2e49f90f2f855a2b7e21f74e9f7b4ecaaa9598..e90b9c812180f81a522e8f1f3f2c7c64b186b43e 100644 (file)
@@ -1908,7 +1908,7 @@ int _i915_vma_move_to_active(struct i915_vma *vma,
        if (flags & EXEC_OBJECT_WRITE) {
                struct intel_frontbuffer *front;
 
-               front = __intel_frontbuffer_get(obj);
+               front = i915_gem_object_get_frontbuffer(obj);
                if (unlikely(front)) {
                        if (intel_frontbuffer_invalidate(front, ORIGIN_CS))
                                i915_active_add_request(&front->write, rq);