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