Linux Audio

Check our new training course

Loading...
v5.14.15
  1/*
  2 * Copyright © 2014 Intel Corporation
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 21 * DEALINGS IN THE SOFTWARE.
 22 *
 23 * Authors:
 24 *	Daniel Vetter <daniel.vetter@ffwll.ch>
 25 */
 26
 27/**
 28 * DOC: frontbuffer tracking
 29 *
 30 * Many features require us to track changes to the currently active
 31 * frontbuffer, especially rendering targeted at the frontbuffer.
 32 *
 33 * To be able to do so we track frontbuffers using a bitmask for all possible
 34 * frontbuffer slots through intel_frontbuffer_track(). The functions in this
 35 * file are then called when the contents of the frontbuffer are invalidated,
 36 * when frontbuffer rendering has stopped again to flush out all the changes
 37 * and when the frontbuffer is exchanged with a flip. Subsystems interested in
 38 * frontbuffer changes (e.g. PSR, FBC, DRRS) should directly put their callbacks
 39 * into the relevant places and filter for the frontbuffer slots that they are
 40 * interested int.
 41 *
 42 * On a high level there are two types of powersaving features. The first one
 43 * work like a special cache (FBC and PSR) and are interested when they should
 44 * stop caching and when to restart caching. This is done by placing callbacks
 45 * into the invalidate and the flush functions: At invalidate the caching must
 46 * be stopped and at flush time it can be restarted. And maybe they need to know
 47 * when the frontbuffer changes (e.g. when the hw doesn't initiate an invalidate
 48 * and flush on its own) which can be achieved with placing callbacks into the
 49 * flip functions.
 50 *
 51 * The other type of display power saving feature only cares about busyness
 52 * (e.g. DRRS). In that case all three (invalidate, flush and flip) indicate
 53 * busyness. There is no direct way to detect idleness. Instead an idle timer
 54 * work delayed work should be started from the flush and flip functions and
 55 * cancelled as soon as busyness is detected.
 56 */
 57
 58#include "display/intel_dp.h"
 59
 60#include "i915_drv.h"
 61#include "i915_trace.h"
 62#include "intel_display_types.h"
 
 
 63#include "intel_fbc.h"
 64#include "intel_frontbuffer.h"
 65#include "intel_psr.h"
 66
 67/**
 68 * frontbuffer_flush - flush frontbuffer
 69 * @i915: i915 device
 70 * @frontbuffer_bits: frontbuffer plane tracking bits
 71 * @origin: which operation caused the flush
 72 *
 73 * This function gets called every time rendering on the given planes has
 74 * completed and frontbuffer caching can be started again. Flushes will get
 75 * delayed if they're blocked by some outstanding asynchronous rendering.
 76 *
 77 * Can be called without any locks held.
 78 */
 79static void frontbuffer_flush(struct drm_i915_private *i915,
 80			      unsigned int frontbuffer_bits,
 81			      enum fb_op_origin origin)
 82{
 83	/* Delay flushing when rings are still busy.*/
 84	spin_lock(&i915->fb_tracking.lock);
 85	frontbuffer_bits &= ~i915->fb_tracking.busy_bits;
 86	spin_unlock(&i915->fb_tracking.lock);
 87
 88	if (!frontbuffer_bits)
 89		return;
 90
 91	trace_intel_frontbuffer_flush(frontbuffer_bits, origin);
 92
 93	might_sleep();
 94	intel_edp_drrs_flush(i915, frontbuffer_bits);
 95	intel_psr_flush(i915, frontbuffer_bits, origin);
 96	intel_fbc_flush(i915, frontbuffer_bits, origin);
 97}
 98
 99/**
100 * intel_frontbuffer_flip_prepare - prepare asynchronous frontbuffer flip
101 * @i915: i915 device
102 * @frontbuffer_bits: frontbuffer plane tracking bits
103 *
104 * This function gets called after scheduling a flip on @obj. The actual
105 * frontbuffer flushing will be delayed until completion is signalled with
106 * intel_frontbuffer_flip_complete. If an invalidate happens in between this
107 * flush will be cancelled.
108 *
109 * Can be called without any locks held.
110 */
111void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
112				    unsigned frontbuffer_bits)
113{
114	spin_lock(&i915->fb_tracking.lock);
115	i915->fb_tracking.flip_bits |= frontbuffer_bits;
116	/* Remove stale busy bits due to the old buffer. */
117	i915->fb_tracking.busy_bits &= ~frontbuffer_bits;
118	spin_unlock(&i915->fb_tracking.lock);
119}
120
121/**
122 * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flip
123 * @i915: i915 device
124 * @frontbuffer_bits: frontbuffer plane tracking bits
125 *
126 * This function gets called after the flip has been latched and will complete
127 * on the next vblank. It will execute the flush if it hasn't been cancelled yet.
128 *
129 * Can be called without any locks held.
130 */
131void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
132				     unsigned frontbuffer_bits)
133{
134	spin_lock(&i915->fb_tracking.lock);
135	/* Mask any cancelled flips. */
136	frontbuffer_bits &= i915->fb_tracking.flip_bits;
137	i915->fb_tracking.flip_bits &= ~frontbuffer_bits;
138	spin_unlock(&i915->fb_tracking.lock);
139
140	if (frontbuffer_bits)
141		frontbuffer_flush(i915, frontbuffer_bits, ORIGIN_FLIP);
142}
143
144/**
145 * intel_frontbuffer_flip - synchronous frontbuffer flip
146 * @i915: i915 device
147 * @frontbuffer_bits: frontbuffer plane tracking bits
148 *
149 * This function gets called after scheduling a flip on @obj. This is for
150 * synchronous plane updates which will happen on the next vblank and which will
151 * not get delayed by pending gpu rendering.
152 *
153 * Can be called without any locks held.
154 */
155void intel_frontbuffer_flip(struct drm_i915_private *i915,
156			    unsigned frontbuffer_bits)
157{
158	spin_lock(&i915->fb_tracking.lock);
159	/* Remove stale busy bits due to the old buffer. */
160	i915->fb_tracking.busy_bits &= ~frontbuffer_bits;
161	spin_unlock(&i915->fb_tracking.lock);
162
163	frontbuffer_flush(i915, frontbuffer_bits, ORIGIN_FLIP);
164}
165
166void __intel_fb_invalidate(struct intel_frontbuffer *front,
167			   enum fb_op_origin origin,
168			   unsigned int frontbuffer_bits)
169{
170	struct drm_i915_private *i915 = to_i915(front->obj->base.dev);
171
172	if (origin == ORIGIN_CS) {
173		spin_lock(&i915->fb_tracking.lock);
174		i915->fb_tracking.busy_bits |= frontbuffer_bits;
175		i915->fb_tracking.flip_bits &= ~frontbuffer_bits;
176		spin_unlock(&i915->fb_tracking.lock);
177	}
178
179	trace_intel_frontbuffer_invalidate(frontbuffer_bits, origin);
180
181	might_sleep();
182	intel_psr_invalidate(i915, frontbuffer_bits, origin);
183	intel_edp_drrs_invalidate(i915, frontbuffer_bits);
184	intel_fbc_invalidate(i915, frontbuffer_bits, origin);
185}
186
187void __intel_fb_flush(struct intel_frontbuffer *front,
188		      enum fb_op_origin origin,
189		      unsigned int frontbuffer_bits)
190{
191	struct drm_i915_private *i915 = to_i915(front->obj->base.dev);
192
193	if (origin == ORIGIN_CS) {
194		spin_lock(&i915->fb_tracking.lock);
195		/* Filter out new bits since rendering started. */
196		frontbuffer_bits &= i915->fb_tracking.busy_bits;
197		i915->fb_tracking.busy_bits &= ~frontbuffer_bits;
198		spin_unlock(&i915->fb_tracking.lock);
199	}
200
201	if (frontbuffer_bits)
202		frontbuffer_flush(i915, frontbuffer_bits, origin);
203}
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205static int frontbuffer_active(struct i915_active *ref)
206{
207	struct intel_frontbuffer *front =
208		container_of(ref, typeof(*front), write);
209
210	kref_get(&front->ref);
211	return 0;
212}
213
214static void frontbuffer_retire(struct i915_active *ref)
215{
216	struct intel_frontbuffer *front =
217		container_of(ref, typeof(*front), write);
218
219	intel_frontbuffer_flush(front, ORIGIN_CS);
220	intel_frontbuffer_put(front);
221}
222
223static void frontbuffer_release(struct kref *ref)
224	__releases(&to_i915(front->obj->base.dev)->fb_tracking.lock)
225{
226	struct intel_frontbuffer *front =
227		container_of(ref, typeof(*front), ref);
228	struct drm_i915_gem_object *obj = front->obj;
229	struct i915_vma *vma;
230
231	drm_WARN_ON(obj->base.dev, atomic_read(&front->bits));
232
233	spin_lock(&obj->vma.lock);
234	for_each_ggtt_vma(vma, obj) {
235		i915_vma_clear_scanout(vma);
236		vma->display_alignment = I915_GTT_MIN_ALIGNMENT;
237	}
238	spin_unlock(&obj->vma.lock);
239
240	RCU_INIT_POINTER(obj->frontbuffer, NULL);
241	spin_unlock(&to_i915(obj->base.dev)->fb_tracking.lock);
 
242
243	i915_active_fini(&front->write);
244
245	i915_gem_object_put(obj);
246	kfree_rcu(front, rcu);
247}
248
249struct intel_frontbuffer *
250intel_frontbuffer_get(struct drm_i915_gem_object *obj)
251{
252	struct drm_i915_private *i915 = to_i915(obj->base.dev);
253	struct intel_frontbuffer *front;
254
255	front = __intel_frontbuffer_get(obj);
256	if (front)
257		return front;
258
259	front = kmalloc(sizeof(*front), GFP_KERNEL);
260	if (!front)
261		return NULL;
262
263	front->obj = obj;
264	kref_init(&front->ref);
265	atomic_set(&front->bits, 0);
266	i915_active_init(&front->write,
267			 frontbuffer_active,
268			 frontbuffer_retire,
269			 I915_ACTIVE_RETIRE_SLEEPS);
 
270
271	spin_lock(&i915->fb_tracking.lock);
272	if (rcu_access_pointer(obj->frontbuffer)) {
 
 
273		kfree(front);
274		front = rcu_dereference_protected(obj->frontbuffer, true);
275		kref_get(&front->ref);
276	} else {
277		i915_gem_object_get(obj);
278		rcu_assign_pointer(obj->frontbuffer, front);
279	}
280	spin_unlock(&i915->fb_tracking.lock);
281
282	return front;
283}
284
285void intel_frontbuffer_put(struct intel_frontbuffer *front)
286{
287	kref_put_lock(&front->ref,
288		      frontbuffer_release,
289		      &to_i915(front->obj->base.dev)->fb_tracking.lock);
290}
291
292/**
293 * intel_frontbuffer_track - update frontbuffer tracking
294 * @old: current buffer for the frontbuffer slots
295 * @new: new buffer for the frontbuffer slots
296 * @frontbuffer_bits: bitmask of frontbuffer slots
297 *
298 * This updates the frontbuffer tracking bits @frontbuffer_bits by clearing them
299 * from @old and setting them in @new. Both @old and @new can be NULL.
300 */
301void intel_frontbuffer_track(struct intel_frontbuffer *old,
302			     struct intel_frontbuffer *new,
303			     unsigned int frontbuffer_bits)
304{
305	/*
306	 * Control of individual bits within the mask are guarded by
307	 * the owning plane->mutex, i.e. we can never see concurrent
308	 * manipulation of individual bits. But since the bitfield as a whole
309	 * is updated using RMW, we need to use atomics in order to update
310	 * the bits.
311	 */
312	BUILD_BUG_ON(INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES >
313		     BITS_PER_TYPE(atomic_t));
 
 
314
315	if (old) {
316		drm_WARN_ON(old->obj->base.dev,
317			    !(atomic_read(&old->bits) & frontbuffer_bits));
318		atomic_andnot(frontbuffer_bits, &old->bits);
319	}
320
321	if (new) {
322		drm_WARN_ON(new->obj->base.dev,
323			    atomic_read(&new->bits) & frontbuffer_bits);
324		atomic_or(frontbuffer_bits, &new->bits);
325	}
326}
v6.9.4
  1/*
  2 * Copyright © 2014 Intel Corporation
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 21 * DEALINGS IN THE SOFTWARE.
 22 *
 23 * Authors:
 24 *	Daniel Vetter <daniel.vetter@ffwll.ch>
 25 */
 26
 27/**
 28 * DOC: frontbuffer tracking
 29 *
 30 * Many features require us to track changes to the currently active
 31 * frontbuffer, especially rendering targeted at the frontbuffer.
 32 *
 33 * To be able to do so we track frontbuffers using a bitmask for all possible
 34 * frontbuffer slots through intel_frontbuffer_track(). The functions in this
 35 * file are then called when the contents of the frontbuffer are invalidated,
 36 * when frontbuffer rendering has stopped again to flush out all the changes
 37 * and when the frontbuffer is exchanged with a flip. Subsystems interested in
 38 * frontbuffer changes (e.g. PSR, FBC, DRRS) should directly put their callbacks
 39 * into the relevant places and filter for the frontbuffer slots that they are
 40 * interested int.
 41 *
 42 * On a high level there are two types of powersaving features. The first one
 43 * work like a special cache (FBC and PSR) and are interested when they should
 44 * stop caching and when to restart caching. This is done by placing callbacks
 45 * into the invalidate and the flush functions: At invalidate the caching must
 46 * be stopped and at flush time it can be restarted. And maybe they need to know
 47 * when the frontbuffer changes (e.g. when the hw doesn't initiate an invalidate
 48 * and flush on its own) which can be achieved with placing callbacks into the
 49 * flip functions.
 50 *
 51 * The other type of display power saving feature only cares about busyness
 52 * (e.g. DRRS). In that case all three (invalidate, flush and flip) indicate
 53 * busyness. There is no direct way to detect idleness. Instead an idle timer
 54 * work delayed work should be started from the flush and flip functions and
 55 * cancelled as soon as busyness is detected.
 56 */
 57
 58#include "gem/i915_gem_object_frontbuffer.h"
 59#include "i915_active.h"
 60#include "i915_drv.h"
 61#include "intel_display_trace.h"
 62#include "intel_display_types.h"
 63#include "intel_dp.h"
 64#include "intel_drrs.h"
 65#include "intel_fbc.h"
 66#include "intel_frontbuffer.h"
 67#include "intel_psr.h"
 68
 69/**
 70 * frontbuffer_flush - flush frontbuffer
 71 * @i915: i915 device
 72 * @frontbuffer_bits: frontbuffer plane tracking bits
 73 * @origin: which operation caused the flush
 74 *
 75 * This function gets called every time rendering on the given planes has
 76 * completed and frontbuffer caching can be started again. Flushes will get
 77 * delayed if they're blocked by some outstanding asynchronous rendering.
 78 *
 79 * Can be called without any locks held.
 80 */
 81static void frontbuffer_flush(struct drm_i915_private *i915,
 82			      unsigned int frontbuffer_bits,
 83			      enum fb_op_origin origin)
 84{
 85	/* Delay flushing when rings are still busy.*/
 86	spin_lock(&i915->display.fb_tracking.lock);
 87	frontbuffer_bits &= ~i915->display.fb_tracking.busy_bits;
 88	spin_unlock(&i915->display.fb_tracking.lock);
 89
 90	if (!frontbuffer_bits)
 91		return;
 92
 93	trace_intel_frontbuffer_flush(i915, frontbuffer_bits, origin);
 94
 95	might_sleep();
 96	intel_drrs_flush(i915, frontbuffer_bits);
 97	intel_psr_flush(i915, frontbuffer_bits, origin);
 98	intel_fbc_flush(i915, frontbuffer_bits, origin);
 99}
100
101/**
102 * intel_frontbuffer_flip_prepare - prepare asynchronous frontbuffer flip
103 * @i915: i915 device
104 * @frontbuffer_bits: frontbuffer plane tracking bits
105 *
106 * This function gets called after scheduling a flip on @obj. The actual
107 * frontbuffer flushing will be delayed until completion is signalled with
108 * intel_frontbuffer_flip_complete. If an invalidate happens in between this
109 * flush will be cancelled.
110 *
111 * Can be called without any locks held.
112 */
113void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
114				    unsigned frontbuffer_bits)
115{
116	spin_lock(&i915->display.fb_tracking.lock);
117	i915->display.fb_tracking.flip_bits |= frontbuffer_bits;
118	/* Remove stale busy bits due to the old buffer. */
119	i915->display.fb_tracking.busy_bits &= ~frontbuffer_bits;
120	spin_unlock(&i915->display.fb_tracking.lock);
121}
122
123/**
124 * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flip
125 * @i915: i915 device
126 * @frontbuffer_bits: frontbuffer plane tracking bits
127 *
128 * This function gets called after the flip has been latched and will complete
129 * on the next vblank. It will execute the flush if it hasn't been cancelled yet.
130 *
131 * Can be called without any locks held.
132 */
133void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
134				     unsigned frontbuffer_bits)
135{
136	spin_lock(&i915->display.fb_tracking.lock);
137	/* Mask any cancelled flips. */
138	frontbuffer_bits &= i915->display.fb_tracking.flip_bits;
139	i915->display.fb_tracking.flip_bits &= ~frontbuffer_bits;
140	spin_unlock(&i915->display.fb_tracking.lock);
141
142	if (frontbuffer_bits)
143		frontbuffer_flush(i915, frontbuffer_bits, ORIGIN_FLIP);
144}
145
146/**
147 * intel_frontbuffer_flip - synchronous frontbuffer flip
148 * @i915: i915 device
149 * @frontbuffer_bits: frontbuffer plane tracking bits
150 *
151 * This function gets called after scheduling a flip on @obj. This is for
152 * synchronous plane updates which will happen on the next vblank and which will
153 * not get delayed by pending gpu rendering.
154 *
155 * Can be called without any locks held.
156 */
157void intel_frontbuffer_flip(struct drm_i915_private *i915,
158			    unsigned frontbuffer_bits)
159{
160	spin_lock(&i915->display.fb_tracking.lock);
161	/* Remove stale busy bits due to the old buffer. */
162	i915->display.fb_tracking.busy_bits &= ~frontbuffer_bits;
163	spin_unlock(&i915->display.fb_tracking.lock);
164
165	frontbuffer_flush(i915, frontbuffer_bits, ORIGIN_FLIP);
166}
167
168void __intel_fb_invalidate(struct intel_frontbuffer *front,
169			   enum fb_op_origin origin,
170			   unsigned int frontbuffer_bits)
171{
172	struct drm_i915_private *i915 = intel_bo_to_i915(front->obj);
173
174	if (origin == ORIGIN_CS) {
175		spin_lock(&i915->display.fb_tracking.lock);
176		i915->display.fb_tracking.busy_bits |= frontbuffer_bits;
177		i915->display.fb_tracking.flip_bits &= ~frontbuffer_bits;
178		spin_unlock(&i915->display.fb_tracking.lock);
179	}
180
181	trace_intel_frontbuffer_invalidate(i915, frontbuffer_bits, origin);
182
183	might_sleep();
184	intel_psr_invalidate(i915, frontbuffer_bits, origin);
185	intel_drrs_invalidate(i915, frontbuffer_bits);
186	intel_fbc_invalidate(i915, frontbuffer_bits, origin);
187}
188
189void __intel_fb_flush(struct intel_frontbuffer *front,
190		      enum fb_op_origin origin,
191		      unsigned int frontbuffer_bits)
192{
193	struct drm_i915_private *i915 = intel_bo_to_i915(front->obj);
194
195	if (origin == ORIGIN_CS) {
196		spin_lock(&i915->display.fb_tracking.lock);
197		/* Filter out new bits since rendering started. */
198		frontbuffer_bits &= i915->display.fb_tracking.busy_bits;
199		i915->display.fb_tracking.busy_bits &= ~frontbuffer_bits;
200		spin_unlock(&i915->display.fb_tracking.lock);
201	}
202
203	if (frontbuffer_bits)
204		frontbuffer_flush(i915, frontbuffer_bits, origin);
205}
206
207static void intel_frontbuffer_flush_work(struct work_struct *work)
208{
209	struct intel_frontbuffer *front =
210		container_of(work, struct intel_frontbuffer, flush_work);
211
212	i915_gem_object_flush_if_display(front->obj);
213	intel_frontbuffer_flush(front, ORIGIN_DIRTYFB);
214	intel_frontbuffer_put(front);
215}
216
217/**
218 * intel_frontbuffer_queue_flush - queue flushing frontbuffer object
219 * @front: GEM object to flush
220 *
221 * This function is targeted for our dirty callback for queueing flush when
222 * dma fence is signales
223 */
224void intel_frontbuffer_queue_flush(struct intel_frontbuffer *front)
225{
226	if (!front)
227		return;
228
229	kref_get(&front->ref);
230	if (!schedule_work(&front->flush_work))
231		intel_frontbuffer_put(front);
232}
233
234static int frontbuffer_active(struct i915_active *ref)
235{
236	struct intel_frontbuffer *front =
237		container_of(ref, typeof(*front), write);
238
239	kref_get(&front->ref);
240	return 0;
241}
242
243static void frontbuffer_retire(struct i915_active *ref)
244{
245	struct intel_frontbuffer *front =
246		container_of(ref, typeof(*front), write);
247
248	intel_frontbuffer_flush(front, ORIGIN_CS);
249	intel_frontbuffer_put(front);
250}
251
252static void frontbuffer_release(struct kref *ref)
253	__releases(&intel_bo_to_i915(front->obj)->display.fb_tracking.lock)
254{
255	struct intel_frontbuffer *ret, *front =
256		container_of(ref, typeof(*front), ref);
257	struct drm_i915_gem_object *obj = front->obj;
 
258
259	drm_WARN_ON(&intel_bo_to_i915(obj)->drm, atomic_read(&front->bits));
260
261	i915_ggtt_clear_scanout(obj);
 
 
 
 
 
262
263	ret = i915_gem_object_set_frontbuffer(obj, NULL);
264	drm_WARN_ON(&intel_bo_to_i915(obj)->drm, ret);
265	spin_unlock(&intel_bo_to_i915(obj)->display.fb_tracking.lock);
266
267	i915_active_fini(&front->write);
 
 
268	kfree_rcu(front, rcu);
269}
270
271struct intel_frontbuffer *
272intel_frontbuffer_get(struct drm_i915_gem_object *obj)
273{
274	struct drm_i915_private *i915 = intel_bo_to_i915(obj);
275	struct intel_frontbuffer *front, *cur;
276
277	front = i915_gem_object_get_frontbuffer(obj);
278	if (front)
279		return front;
280
281	front = kmalloc(sizeof(*front), GFP_KERNEL);
282	if (!front)
283		return NULL;
284
285	front->obj = obj;
286	kref_init(&front->ref);
287	atomic_set(&front->bits, 0);
288	i915_active_init(&front->write,
289			 frontbuffer_active,
290			 frontbuffer_retire,
291			 I915_ACTIVE_RETIRE_SLEEPS);
292	INIT_WORK(&front->flush_work, intel_frontbuffer_flush_work);
293
294	spin_lock(&i915->display.fb_tracking.lock);
295	cur = i915_gem_object_set_frontbuffer(obj, front);
296	spin_unlock(&i915->display.fb_tracking.lock);
297	if (cur != front)
298		kfree(front);
299	return cur;
 
 
 
 
 
 
 
 
300}
301
302void intel_frontbuffer_put(struct intel_frontbuffer *front)
303{
304	kref_put_lock(&front->ref,
305		      frontbuffer_release,
306		      &intel_bo_to_i915(front->obj)->display.fb_tracking.lock);
307}
308
309/**
310 * intel_frontbuffer_track - update frontbuffer tracking
311 * @old: current buffer for the frontbuffer slots
312 * @new: new buffer for the frontbuffer slots
313 * @frontbuffer_bits: bitmask of frontbuffer slots
314 *
315 * This updates the frontbuffer tracking bits @frontbuffer_bits by clearing them
316 * from @old and setting them in @new. Both @old and @new can be NULL.
317 */
318void intel_frontbuffer_track(struct intel_frontbuffer *old,
319			     struct intel_frontbuffer *new,
320			     unsigned int frontbuffer_bits)
321{
322	/*
323	 * Control of individual bits within the mask are guarded by
324	 * the owning plane->mutex, i.e. we can never see concurrent
325	 * manipulation of individual bits. But since the bitfield as a whole
326	 * is updated using RMW, we need to use atomics in order to update
327	 * the bits.
328	 */
329	BUILD_BUG_ON(INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES >
330		     BITS_PER_TYPE(atomic_t));
331	BUILD_BUG_ON(INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES > 32);
332	BUILD_BUG_ON(I915_MAX_PLANES > INTEL_FRONTBUFFER_BITS_PER_PIPE);
333
334	if (old) {
335		drm_WARN_ON(&intel_bo_to_i915(old->obj)->drm,
336			    !(atomic_read(&old->bits) & frontbuffer_bits));
337		atomic_andnot(frontbuffer_bits, &old->bits);
338	}
339
340	if (new) {
341		drm_WARN_ON(&intel_bo_to_i915(new->obj)->drm,
342			    atomic_read(&new->bits) & frontbuffer_bits);
343		atomic_or(frontbuffer_bits, &new->bits);
344	}
345}