2 * Copyright (c) 2014-2016 Intel Corporation
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:
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
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
24 #ifndef __INTEL_FRONTBUFFER_H__
25 #define __INTEL_FRONTBUFFER_H__
27 #include <linux/atomic.h>
28 #include <linux/bits.h>
29 #include <linux/kref.h>
31 #include "i915_active_types.h"
33 struct drm_gem_object;
34 struct drm_i915_private;
44 struct intel_frontbuffer {
47 struct i915_active write;
48 struct drm_gem_object *obj;
51 struct work_struct flush_work;
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.
60 * We have one bit per pipe and per scanout plane type.
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))
71 void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
72 unsigned frontbuffer_bits);
73 void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
74 unsigned frontbuffer_bits);
75 void intel_frontbuffer_flip(struct drm_i915_private *i915,
76 unsigned frontbuffer_bits);
78 void intel_frontbuffer_put(struct intel_frontbuffer *front);
80 struct intel_frontbuffer *
81 intel_frontbuffer_get(struct drm_gem_object *obj);
83 void __intel_fb_invalidate(struct intel_frontbuffer *front,
84 enum fb_op_origin origin,
85 unsigned int frontbuffer_bits);
88 * intel_frontbuffer_invalidate - invalidate frontbuffer object
89 * @front: GEM object to invalidate
90 * @origin: which operation caused the invalidation
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
98 static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
99 enum fb_op_origin origin)
101 unsigned int frontbuffer_bits;
106 frontbuffer_bits = atomic_read(&front->bits);
107 if (!frontbuffer_bits)
110 __intel_fb_invalidate(front, origin, frontbuffer_bits);
114 void __intel_fb_flush(struct intel_frontbuffer *front,
115 enum fb_op_origin origin,
116 unsigned int frontbuffer_bits);
119 * intel_frontbuffer_flush - flush frontbuffer object
120 * @front: GEM object to flush
121 * @origin: which operation caused the flush
123 * This function gets called every time rendering on the given object has
124 * completed and frontbuffer caching can be started again.
126 static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
127 enum fb_op_origin origin)
129 unsigned int frontbuffer_bits;
134 frontbuffer_bits = atomic_read(&front->bits);
135 if (!frontbuffer_bits)
138 __intel_fb_flush(front, origin, frontbuffer_bits);
141 void intel_frontbuffer_queue_flush(struct intel_frontbuffer *front);
143 void intel_frontbuffer_track(struct intel_frontbuffer *old,
144 struct intel_frontbuffer *new,
145 unsigned int frontbuffer_bits);
147 #endif /* __INTEL_FRONTBUFFER_H__ */