1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #ifndef __I915_GEM_OBJECT_FRONTBUFFER_H__ 7 #define __I915_GEM_OBJECT_FRONTBUFFER_H__ 8 9 #include <linux/kref.h> 10 #include <linux/rcupdate.h> 11 12 #include "display/intel_frontbuffer.h" 13 #include "i915_gem_object_types.h" 14 15 struct i915_frontbuffer { 16 struct intel_frontbuffer base; 17 struct drm_i915_gem_object *obj; 18 struct i915_active write; 19 struct rcu_head rcu; 20 struct kref ref; 21 }; 22 23 void __i915_gem_object_frontbuffer_flush(struct drm_i915_gem_object *obj, 24 enum fb_op_origin origin); 25 void __i915_gem_object_frontbuffer_invalidate(struct drm_i915_gem_object *obj, 26 enum fb_op_origin origin); 27 28 static inline void 29 i915_gem_object_frontbuffer_flush(struct drm_i915_gem_object *obj, 30 enum fb_op_origin origin) 31 { 32 if (unlikely(rcu_access_pointer(obj->frontbuffer))) 33 __i915_gem_object_frontbuffer_flush(obj, origin); 34 } 35 36 static inline void 37 i915_gem_object_frontbuffer_invalidate(struct drm_i915_gem_object *obj, 38 enum fb_op_origin origin) 39 { 40 if (unlikely(rcu_access_pointer(obj->frontbuffer))) 41 __i915_gem_object_frontbuffer_invalidate(obj, origin); 42 } 43 44 struct i915_frontbuffer *i915_gem_object_frontbuffer_get(struct drm_i915_gem_object *obj); 45 void i915_gem_object_frontbuffer_ref(struct i915_frontbuffer *front); 46 void i915_gem_object_frontbuffer_put(struct i915_frontbuffer *front); 47 48 static inline void i915_gem_object_frontbuffer_track(struct i915_frontbuffer *_old, 49 struct i915_frontbuffer *_new, 50 unsigned int frontbuffer_bits) 51 { 52 struct intel_frontbuffer *old = _old ? &_old->base : NULL; 53 struct intel_frontbuffer *new = _new ? &_new->base : NULL; 54 55 intel_frontbuffer_track(old, new, frontbuffer_bits); 56 } 57 58 /** 59 * i915_gem_object_frontbuffer_lookup - Look up the object's frontbuffer 60 * @obj: The object whose frontbuffer to look up. 61 * 62 * Get pointer to object's frontbuffer if such exists. Please note that RCU 63 * mechanism is used to handle e.g. ongoing removal of frontbuffer pointer. 64 * 65 * Return: pointer to object's frontbuffer is such exists or NULL 66 */ 67 static inline struct i915_frontbuffer * 68 i915_gem_object_frontbuffer_lookup(const struct drm_i915_gem_object *obj) 69 { 70 struct i915_frontbuffer *front; 71 72 if (likely(!rcu_access_pointer(obj->frontbuffer))) 73 return NULL; 74 75 rcu_read_lock(); 76 do { 77 front = rcu_dereference(obj->frontbuffer); 78 if (!front) 79 break; 80 81 if (unlikely(!kref_get_unless_zero(&front->ref))) 82 continue; 83 84 if (likely(front == rcu_access_pointer(obj->frontbuffer))) 85 break; 86 87 i915_gem_object_frontbuffer_put(front); 88 } while (1); 89 rcu_read_unlock(); 90 91 return front; 92 } 93 94 extern const struct intel_display_frontbuffer_interface i915_display_frontbuffer_interface; 95 96 #endif 97