Linux Audio

Check our new training course

Loading...
v5.14.15
  1/*
  2 * Copyright (c) 2014-2016 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 DEALINGS
 21 * IN THE SOFTWARE.
 22 */
 23
 24#ifndef __INTEL_FRONTBUFFER_H__
 25#define __INTEL_FRONTBUFFER_H__
 26
 27#include <linux/atomic.h>
 
 28#include <linux/kref.h>
 29
 30#include "gem/i915_gem_object_types.h"
 31#include "i915_active.h"
 32
 
 33struct drm_i915_private;
 34
 35enum fb_op_origin {
 36	ORIGIN_GTT,
 37	ORIGIN_CPU,
 38	ORIGIN_CS,
 39	ORIGIN_FLIP,
 40	ORIGIN_DIRTYFB,
 
 41};
 42
 43struct intel_frontbuffer {
 44	struct kref ref;
 45	atomic_t bits;
 46	struct i915_active write;
 47	struct drm_i915_gem_object *obj;
 48	struct rcu_head rcu;
 
 
 49};
 50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 51void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
 52				    unsigned frontbuffer_bits);
 53void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
 54				     unsigned frontbuffer_bits);
 55void intel_frontbuffer_flip(struct drm_i915_private *i915,
 56			    unsigned frontbuffer_bits);
 57
 58void intel_frontbuffer_put(struct intel_frontbuffer *front);
 59
 60static inline struct intel_frontbuffer *
 61__intel_frontbuffer_get(const struct drm_i915_gem_object *obj)
 62{
 63	struct intel_frontbuffer *front;
 64
 65	if (likely(!rcu_access_pointer(obj->frontbuffer)))
 66		return NULL;
 67
 68	rcu_read_lock();
 69	do {
 70		front = rcu_dereference(obj->frontbuffer);
 71		if (!front)
 72			break;
 73
 74		if (unlikely(!kref_get_unless_zero(&front->ref)))
 75			continue;
 76
 77		if (likely(front == rcu_access_pointer(obj->frontbuffer)))
 78			break;
 79
 80		intel_frontbuffer_put(front);
 81	} while (1);
 82	rcu_read_unlock();
 83
 84	return front;
 85}
 86
 87struct intel_frontbuffer *
 88intel_frontbuffer_get(struct drm_i915_gem_object *obj);
 89
 90void __intel_fb_invalidate(struct intel_frontbuffer *front,
 91			   enum fb_op_origin origin,
 92			   unsigned int frontbuffer_bits);
 93
 94/**
 95 * intel_frontbuffer_invalidate - invalidate frontbuffer object
 96 * @front: GEM object to invalidate
 97 * @origin: which operation caused the invalidation
 98 *
 99 * This function gets called every time rendering on the given object starts and
100 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
101 * be invalidated. For ORIGIN_CS any subsequent invalidation will be delayed
102 * until the rendering completes or a flip on this frontbuffer plane is
103 * scheduled.
104 */
105static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
106						enum fb_op_origin origin)
107{
108	unsigned int frontbuffer_bits;
109
110	if (!front)
111		return false;
112
113	frontbuffer_bits = atomic_read(&front->bits);
114	if (!frontbuffer_bits)
115		return false;
116
117	__intel_fb_invalidate(front, origin, frontbuffer_bits);
118	return true;
119}
120
121void __intel_fb_flush(struct intel_frontbuffer *front,
122		      enum fb_op_origin origin,
123		      unsigned int frontbuffer_bits);
124
125/**
126 * intel_frontbuffer_flush - flush frontbuffer object
127 * @front: GEM object to flush
128 * @origin: which operation caused the flush
129 *
130 * This function gets called every time rendering on the given object has
131 * completed and frontbuffer caching can be started again.
132 */
133static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
134					   enum fb_op_origin origin)
135{
136	unsigned int frontbuffer_bits;
137
138	if (!front)
139		return;
140
141	frontbuffer_bits = atomic_read(&front->bits);
142	if (!frontbuffer_bits)
143		return;
144
145	__intel_fb_flush(front, origin, frontbuffer_bits);
146}
 
 
147
148void intel_frontbuffer_track(struct intel_frontbuffer *old,
149			     struct intel_frontbuffer *new,
150			     unsigned int frontbuffer_bits);
151
152#endif /* __INTEL_FRONTBUFFER_H__ */
v6.13.7
  1/*
  2 * Copyright (c) 2014-2016 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 DEALINGS
 21 * IN THE SOFTWARE.
 22 */
 23
 24#ifndef __INTEL_FRONTBUFFER_H__
 25#define __INTEL_FRONTBUFFER_H__
 26
 27#include <linux/atomic.h>
 28#include <linux/bits.h>
 29#include <linux/kref.h>
 30
 31#include "i915_active_types.h"
 
 32
 33struct drm_gem_object;
 34struct drm_i915_private;
 35
 36enum fb_op_origin {
 37	ORIGIN_CPU = 0,
 
 38	ORIGIN_CS,
 39	ORIGIN_FLIP,
 40	ORIGIN_DIRTYFB,
 41	ORIGIN_CURSOR_UPDATE,
 42};
 43
 44struct intel_frontbuffer {
 45	struct kref ref;
 46	atomic_t bits;
 47	struct i915_active write;
 48	struct drm_gem_object *obj;
 49	struct rcu_head rcu;
 50
 51	struct work_struct flush_work;
 52};
 53
 54/*
 55 * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
 56 * considered to be the frontbuffer for the given plane interface-wise. This
 57 * doesn't mean that the hw necessarily already scans it out, but that any
 58 * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
 59 *
 60 * We have one bit per pipe and per scanout plane type.
 61 */
 62#define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
 63#define INTEL_FRONTBUFFER(pipe, plane_id) \
 64	BIT((plane_id) + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe));
 65#define INTEL_FRONTBUFFER_OVERLAY(pipe) \
 66	BIT(INTEL_FRONTBUFFER_BITS_PER_PIPE - 1 + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
 67#define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
 68	GENMASK(INTEL_FRONTBUFFER_BITS_PER_PIPE * ((pipe) + 1) - 1,	\
 69		INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
 70
 71void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
 72				    unsigned frontbuffer_bits);
 73void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
 74				     unsigned frontbuffer_bits);
 75void intel_frontbuffer_flip(struct drm_i915_private *i915,
 76			    unsigned frontbuffer_bits);
 77
 78void intel_frontbuffer_put(struct intel_frontbuffer *front);
 79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 80struct intel_frontbuffer *
 81intel_frontbuffer_get(struct drm_gem_object *obj);
 82
 83void __intel_fb_invalidate(struct intel_frontbuffer *front,
 84			   enum fb_op_origin origin,
 85			   unsigned int frontbuffer_bits);
 86
 87/**
 88 * intel_frontbuffer_invalidate - invalidate frontbuffer object
 89 * @front: GEM object to invalidate
 90 * @origin: which operation caused the invalidation
 91 *
 92 * This function gets called every time rendering on the given object starts and
 93 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
 94 * be invalidated. For ORIGIN_CS any subsequent invalidation will be delayed
 95 * until the rendering completes or a flip on this frontbuffer plane is
 96 * scheduled.
 97 */
 98static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
 99						enum fb_op_origin origin)
100{
101	unsigned int frontbuffer_bits;
102
103	if (!front)
104		return false;
105
106	frontbuffer_bits = atomic_read(&front->bits);
107	if (!frontbuffer_bits)
108		return false;
109
110	__intel_fb_invalidate(front, origin, frontbuffer_bits);
111	return true;
112}
113
114void __intel_fb_flush(struct intel_frontbuffer *front,
115		      enum fb_op_origin origin,
116		      unsigned int frontbuffer_bits);
117
118/**
119 * intel_frontbuffer_flush - flush frontbuffer object
120 * @front: GEM object to flush
121 * @origin: which operation caused the flush
122 *
123 * This function gets called every time rendering on the given object has
124 * completed and frontbuffer caching can be started again.
125 */
126static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
127					   enum fb_op_origin origin)
128{
129	unsigned int frontbuffer_bits;
130
131	if (!front)
132		return;
133
134	frontbuffer_bits = atomic_read(&front->bits);
135	if (!frontbuffer_bits)
136		return;
137
138	__intel_fb_flush(front, origin, frontbuffer_bits);
139}
140
141void intel_frontbuffer_queue_flush(struct intel_frontbuffer *front);
142
143void intel_frontbuffer_track(struct intel_frontbuffer *old,
144			     struct intel_frontbuffer *new,
145			     unsigned int frontbuffer_bits);
146
147#endif /* __INTEL_FRONTBUFFER_H__ */