Home | History | Annotate | Line # | Download | only in display
      1 /*	$NetBSD: intel_frontbuffer.h,v 1.2 2021/12/18 23:45:30 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2014-2016 Intel Corporation
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the next
     14  * paragraph) shall be included in all copies or substantial portions of the
     15  * Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     23  * IN THE SOFTWARE.
     24  */
     25 
     26 #ifndef __INTEL_FRONTBUFFER_H__
     27 #define __INTEL_FRONTBUFFER_H__
     28 
     29 #include <linux/atomic.h>
     30 #include <linux/kref.h>
     31 
     32 #include "gem/i915_gem_object_types.h"
     33 #include "i915_active.h"
     34 
     35 struct drm_i915_private;
     36 
     37 enum fb_op_origin {
     38 	ORIGIN_GTT,
     39 	ORIGIN_CPU,
     40 	ORIGIN_CS,
     41 	ORIGIN_FLIP,
     42 	ORIGIN_DIRTYFB,
     43 };
     44 
     45 struct intel_frontbuffer {
     46 	struct kref ref;
     47 	atomic_t bits;
     48 	struct i915_active write;
     49 	struct drm_i915_gem_object *obj;
     50 	struct rcu_head rcu;
     51 };
     52 
     53 void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
     54 				    unsigned frontbuffer_bits);
     55 void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
     56 				     unsigned frontbuffer_bits);
     57 void intel_frontbuffer_flip(struct drm_i915_private *i915,
     58 			    unsigned frontbuffer_bits);
     59 
     60 void intel_frontbuffer_put(struct intel_frontbuffer *front);
     61 
     62 static inline struct intel_frontbuffer *
     63 __intel_frontbuffer_get(const struct drm_i915_gem_object *obj)
     64 {
     65 	struct intel_frontbuffer *front;
     66 
     67 	if (likely(!rcu_access_pointer(obj->frontbuffer)))
     68 		return NULL;
     69 
     70 	rcu_read_lock();
     71 	do {
     72 		front = rcu_dereference(obj->frontbuffer);
     73 		if (!front)
     74 			break;
     75 
     76 		if (unlikely(!kref_get_unless_zero(&front->ref)))
     77 			continue;
     78 
     79 		if (likely(front == rcu_access_pointer(obj->frontbuffer)))
     80 			break;
     81 
     82 		intel_frontbuffer_put(front);
     83 	} while (1);
     84 	rcu_read_unlock();
     85 
     86 	return front;
     87 }
     88 
     89 struct intel_frontbuffer *
     90 intel_frontbuffer_get(struct drm_i915_gem_object *obj);
     91 
     92 void __intel_fb_invalidate(struct intel_frontbuffer *front,
     93 			   enum fb_op_origin origin,
     94 			   unsigned int frontbuffer_bits);
     95 
     96 /**
     97  * intel_frontbuffer_invalidate - invalidate frontbuffer object
     98  * @front: GEM object to invalidate
     99  * @origin: which operation caused the invalidation
    100  *
    101  * This function gets called every time rendering on the given object starts and
    102  * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
    103  * be invalidated. For ORIGIN_CS any subsequent invalidation will be delayed
    104  * until the rendering completes or a flip on this frontbuffer plane is
    105  * scheduled.
    106  */
    107 static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
    108 						enum fb_op_origin origin)
    109 {
    110 	unsigned int frontbuffer_bits;
    111 
    112 	if (!front)
    113 		return false;
    114 
    115 	frontbuffer_bits = atomic_read(&front->bits);
    116 	if (!frontbuffer_bits)
    117 		return false;
    118 
    119 	__intel_fb_invalidate(front, origin, frontbuffer_bits);
    120 	return true;
    121 }
    122 
    123 void __intel_fb_flush(struct intel_frontbuffer *front,
    124 		      enum fb_op_origin origin,
    125 		      unsigned int frontbuffer_bits);
    126 
    127 /**
    128  * intel_frontbuffer_flush - flush frontbuffer object
    129  * @front: GEM object to flush
    130  * @origin: which operation caused the flush
    131  *
    132  * This function gets called every time rendering on the given object has
    133  * completed and frontbuffer caching can be started again.
    134  */
    135 static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
    136 					   enum fb_op_origin origin)
    137 {
    138 	unsigned int frontbuffer_bits;
    139 
    140 	if (!front)
    141 		return;
    142 
    143 	frontbuffer_bits = atomic_read(&front->bits);
    144 	if (!frontbuffer_bits)
    145 		return;
    146 
    147 	__intel_fb_flush(front, origin, frontbuffer_bits);
    148 }
    149 
    150 void intel_frontbuffer_track(struct intel_frontbuffer *old,
    151 			     struct intel_frontbuffer *new,
    152 			     unsigned int frontbuffer_bits);
    153 
    154 #endif /* __INTEL_FRONTBUFFER_H__ */
    155