Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/workqueue_types.h>
30
31struct drm_device;
32struct drm_gem_object;
33struct intel_display;
34
35enum fb_op_origin {
36 ORIGIN_CPU = 0,
37 ORIGIN_CS,
38 ORIGIN_FLIP,
39 ORIGIN_DIRTYFB,
40 ORIGIN_CURSOR_UPDATE,
41};
42
43struct intel_frontbuffer {
44 struct intel_display *display;
45 atomic_t bits;
46 struct work_struct flush_work;
47};
48
49/*
50 * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
51 * considered to be the frontbuffer for the given plane interface-wise. This
52 * doesn't mean that the hw necessarily already scans it out, but that any
53 * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
54 *
55 * We have one bit per pipe and per scanout plane type.
56 */
57#define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
58#define INTEL_FRONTBUFFER(pipe, plane_id) \
59 BIT((plane_id) + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe));
60#define INTEL_FRONTBUFFER_OVERLAY(pipe) \
61 BIT(INTEL_FRONTBUFFER_BITS_PER_PIPE - 1 + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
62#define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
63 GENMASK(INTEL_FRONTBUFFER_BITS_PER_PIPE * ((pipe) + 1) - 1, \
64 INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
65
66void intel_frontbuffer_flip(struct intel_display *display,
67 unsigned frontbuffer_bits);
68
69void intel_frontbuffer_put(struct intel_frontbuffer *front);
70
71struct intel_frontbuffer *
72intel_frontbuffer_get(struct drm_gem_object *obj);
73
74void __intel_fb_invalidate(struct intel_frontbuffer *front,
75 enum fb_op_origin origin,
76 unsigned int frontbuffer_bits);
77
78/**
79 * intel_frontbuffer_invalidate - invalidate frontbuffer object
80 * @front: GEM object to invalidate
81 * @origin: which operation caused the invalidation
82 *
83 * This function gets called every time rendering on the given object starts and
84 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
85 * be invalidated. For ORIGIN_CS any subsequent invalidation will be delayed
86 * until the rendering completes or a flip on this frontbuffer plane is
87 * scheduled.
88 */
89static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
90 enum fb_op_origin origin)
91{
92 unsigned int frontbuffer_bits;
93
94 if (!front)
95 return false;
96
97 frontbuffer_bits = atomic_read(&front->bits);
98 if (!frontbuffer_bits)
99 return false;
100
101 __intel_fb_invalidate(front, origin, frontbuffer_bits);
102 return true;
103}
104
105void __intel_fb_flush(struct intel_frontbuffer *front,
106 enum fb_op_origin origin,
107 unsigned int frontbuffer_bits);
108
109/**
110 * intel_frontbuffer_flush - flush frontbuffer object
111 * @front: GEM object to flush
112 * @origin: which operation caused the flush
113 *
114 * This function gets called every time rendering on the given object has
115 * completed and frontbuffer caching can be started again.
116 */
117static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
118 enum fb_op_origin origin)
119{
120 unsigned int frontbuffer_bits;
121
122 if (!front)
123 return;
124
125 frontbuffer_bits = atomic_read(&front->bits);
126 if (!frontbuffer_bits)
127 return;
128
129 __intel_fb_flush(front, origin, frontbuffer_bits);
130}
131
132void intel_frontbuffer_queue_flush(struct intel_frontbuffer *front);
133
134void intel_frontbuffer_track(struct intel_frontbuffer *old,
135 struct intel_frontbuffer *new,
136 unsigned int frontbuffer_bits);
137
138void intel_frontbuffer_init(struct intel_frontbuffer *front, struct drm_device *drm);
139void intel_frontbuffer_fini(struct intel_frontbuffer *front);
140
141#endif /* __INTEL_FRONTBUFFER_H__ */