1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2023 Intel Corporation
6 #ifndef __I915_GEM_OBJECT_FRONTBUFFER_H__
7 #define __I915_GEM_OBJECT_FRONTBUFFER_H__
9 #include <linux/kref.h>
10 #include <linux/rcupdate.h>
12 #include "display/intel_frontbuffer.h"
13 #include "i915_gem_object_types.h"
15 void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,
16 enum fb_op_origin origin);
17 void __i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj,
18 enum fb_op_origin origin);
21 i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,
22 enum fb_op_origin origin)
24 if (unlikely(rcu_access_pointer(obj->frontbuffer)))
25 __i915_gem_object_flush_frontbuffer(obj, origin);
29 i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj,
30 enum fb_op_origin origin)
32 if (unlikely(rcu_access_pointer(obj->frontbuffer)))
33 __i915_gem_object_invalidate_frontbuffer(obj, origin);
37 * i915_gem_object_get_frontbuffer - Get the object's frontbuffer
38 * @obj: The object whose frontbuffer to get.
40 * Get pointer to object's frontbuffer if such exists. Please note that RCU
41 * mechanism is used to handle e.g. ongoing removal of frontbuffer pointer.
43 * Return: pointer to object's frontbuffer is such exists or NULL
45 static inline struct intel_frontbuffer *
46 i915_gem_object_get_frontbuffer(const struct drm_i915_gem_object *obj)
48 struct intel_frontbuffer *front;
50 if (likely(!rcu_access_pointer(obj->frontbuffer)))
55 front = rcu_dereference(obj->frontbuffer);
59 if (unlikely(!kref_get_unless_zero(&front->ref)))
62 if (likely(front == rcu_access_pointer(obj->frontbuffer)))
65 intel_frontbuffer_put(front);
73 * i915_gem_object_set_frontbuffer - Set the object's frontbuffer
74 * @obj: The object whose frontbuffer to set.
75 * @front: The frontbuffer to set
77 * Set object's frontbuffer pointer. If frontbuffer is already set for the
78 * object keep it and return it's pointer to the caller. Please note that RCU
79 * mechanism is used to handle e.g. ongoing removal of frontbuffer pointer. This
80 * function is protected by i915->display.fb_tracking.lock
82 * Return: pointer to frontbuffer which was set.
84 static inline struct intel_frontbuffer *
85 i915_gem_object_set_frontbuffer(struct drm_i915_gem_object *obj,
86 struct intel_frontbuffer *front)
88 struct intel_frontbuffer *cur = front;
91 RCU_INIT_POINTER(obj->frontbuffer, NULL);
92 } else if (rcu_access_pointer(obj->frontbuffer)) {
93 cur = rcu_dereference_protected(obj->frontbuffer, true);
96 drm_gem_object_get(intel_bo_to_drm_bo(obj));
97 rcu_assign_pointer(obj->frontbuffer, front);