]>
Commit | Line | Data |
---|---|---|
7520a277 DV |
1 | /* |
2 | * Copyright (c) 2016 Intel Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, distribute, and sell this software and its | |
5 | * documentation for any purpose is hereby granted without fee, provided that | |
6 | * the above copyright notice appear in all copies and that both that copyright | |
7 | * notice and this permission notice appear in supporting documentation, and | |
8 | * that the name of the copyright holders not be used in advertising or | |
9 | * publicity pertaining to distribution of the software without specific, | |
10 | * written prior permission. The copyright holders make no representations | |
11 | * about the suitability of this software for any purpose. It is provided "as | |
12 | * is" without express or implied warranty. | |
13 | * | |
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
20 | * OF THIS SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef __DRM_FRAMEBUFFER_H__ | |
24 | #define __DRM_FRAMEBUFFER_H__ | |
25 | ||
7520a277 | 26 | #include <linux/ctype.h> |
2513147d SR |
27 | #include <linux/list.h> |
28 | #include <linux/sched.h> | |
29 | ||
949619f3 | 30 | #include <drm/drm_mode_object.h> |
7520a277 | 31 | |
2513147d | 32 | struct drm_clip_rect; |
7520a277 | 33 | struct drm_device; |
2513147d SR |
34 | struct drm_file; |
35 | struct drm_framebuffer; | |
36 | struct drm_gem_object; | |
7520a277 DV |
37 | |
38 | /** | |
39 | * struct drm_framebuffer_funcs - framebuffer hooks | |
40 | */ | |
41 | struct drm_framebuffer_funcs { | |
42 | /** | |
43 | * @destroy: | |
44 | * | |
45 | * Clean up framebuffer resources, specifically also unreference the | |
46 | * backing storage. The core guarantees to call this function for every | |
d574528a DV |
47 | * framebuffer successfully created by calling |
48 | * &drm_mode_config_funcs.fb_create. Drivers must also call | |
7520a277 DV |
49 | * drm_framebuffer_cleanup() to release DRM core resources for this |
50 | * framebuffer. | |
51 | */ | |
52 | void (*destroy)(struct drm_framebuffer *framebuffer); | |
53 | ||
54 | /** | |
55 | * @create_handle: | |
56 | * | |
57 | * Create a buffer handle in the driver-specific buffer manager (either | |
ea0dd85a | 58 | * GEM or TTM) valid for the passed-in &struct drm_file. This is used by |
7520a277 DV |
59 | * the core to implement the GETFB IOCTL, which returns (for |
60 | * sufficiently priviledged user) also a native buffer handle. This can | |
61 | * be used for seamless transitions between modesetting clients by | |
62 | * copying the current screen contents to a private buffer and blending | |
63 | * between that and the new contents. | |
64 | * | |
65 | * GEM based drivers should call drm_gem_handle_create() to create the | |
66 | * handle. | |
67 | * | |
68 | * RETURNS: | |
69 | * | |
70 | * 0 on success or a negative error code on failure. | |
71 | */ | |
72 | int (*create_handle)(struct drm_framebuffer *fb, | |
73 | struct drm_file *file_priv, | |
74 | unsigned int *handle); | |
75 | /** | |
76 | * @dirty: | |
77 | * | |
78 | * Optional callback for the dirty fb IOCTL. | |
79 | * | |
80 | * Userspace can notify the driver via this callback that an area of the | |
81 | * framebuffer has changed and should be flushed to the display | |
82 | * hardware. This can also be used internally, e.g. by the fbdev | |
83 | * emulation, though that's not the case currently. | |
84 | * | |
85 | * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd | |
86 | * for more information as all the semantics and arguments have a one to | |
87 | * one mapping on this function. | |
88 | * | |
89 | * RETURNS: | |
90 | * | |
91 | * 0 on success or a negative error code on failure. | |
92 | */ | |
93 | int (*dirty)(struct drm_framebuffer *framebuffer, | |
94 | struct drm_file *file_priv, unsigned flags, | |
95 | unsigned color, struct drm_clip_rect *clips, | |
96 | unsigned num_clips); | |
97 | }; | |
98 | ||
750fb8c4 DV |
99 | /** |
100 | * struct drm_framebuffer - frame buffer object | |
101 | * | |
102 | * Note that the fb is refcounted for the benefit of driver internals, | |
103 | * for example some hw, disabling a CRTC/plane is asynchronous, and | |
104 | * scanout does not actually complete until the next vblank. So some | |
105 | * cleanup (like releasing the reference(s) on the backing GEM bo(s)) | |
106 | * should be deferred. In cases like this, the driver would like to | |
107 | * hold a ref to the fb even though it has already been removed from | |
a4a69da0 TR |
108 | * userspace perspective. See drm_framebuffer_get() and |
109 | * drm_framebuffer_put(). | |
750fb8c4 DV |
110 | * |
111 | * The refcount is stored inside the mode object @base. | |
112 | */ | |
7520a277 | 113 | struct drm_framebuffer { |
750fb8c4 DV |
114 | /** |
115 | * @dev: DRM device this framebuffer belongs to | |
116 | */ | |
7520a277 | 117 | struct drm_device *dev; |
750fb8c4 | 118 | /** |
d574528a DV |
119 | * @head: Place on the &drm_mode_config.fb_list, access protected by |
120 | * &drm_mode_config.fb_lock. | |
7520a277 DV |
121 | */ |
122 | struct list_head head; | |
750fb8c4 DV |
123 | |
124 | /** | |
125 | * @base: base modeset object structure, contains the reference count. | |
126 | */ | |
7520a277 | 127 | struct drm_mode_object base; |
8d44e9e6 ML |
128 | |
129 | /** | |
130 | * @comm: Name of the process allocating the fb, used for fb dumping. | |
131 | */ | |
132 | char comm[TASK_COMM_LEN]; | |
133 | ||
e14c23c6 VS |
134 | /** |
135 | * @format: framebuffer format information | |
136 | */ | |
137 | const struct drm_format_info *format; | |
750fb8c4 DV |
138 | /** |
139 | * @funcs: framebuffer vfunc table | |
140 | */ | |
7520a277 | 141 | const struct drm_framebuffer_funcs *funcs; |
750fb8c4 DV |
142 | /** |
143 | * @pitches: Line stride per buffer. For userspace created object this | |
144 | * is copied from drm_mode_fb_cmd2. | |
145 | */ | |
7520a277 | 146 | unsigned int pitches[4]; |
750fb8c4 DV |
147 | /** |
148 | * @offsets: Offset from buffer start to the actual pixel data in bytes, | |
149 | * per buffer. For userspace created object this is copied from | |
150 | * drm_mode_fb_cmd2. | |
151 | * | |
152 | * Note that this is a linear offset and does not take into account | |
153 | * tiling or buffer laytou per @modifier. It meant to be used when the | |
154 | * actual pixel data for this framebuffer plane starts at an offset, | |
155 | * e.g. when multiple planes are allocated within the same backing | |
156 | * storage buffer object. For tiled layouts this generally means it | |
157 | * @offsets must at least be tile-size aligned, but hardware often has | |
158 | * stricter requirements. | |
159 | * | |
160 | * This should not be used to specifiy x/y pixel offsets into the buffer | |
161 | * data (even for linear buffers). Specifying an x/y pixel offset is | |
ea0dd85a | 162 | * instead done through the source rectangle in &struct drm_plane_state. |
750fb8c4 | 163 | */ |
7520a277 | 164 | unsigned int offsets[4]; |
750fb8c4 | 165 | /** |
bae781b2 | 166 | * @modifier: Data layout modifier. This is used to describe |
750fb8c4 DV |
167 | * tiling, or also special layouts (like compression) of auxiliary |
168 | * buffers. For userspace created object this is copied from | |
169 | * drm_mode_fb_cmd2. | |
170 | */ | |
bae781b2 | 171 | uint64_t modifier; |
750fb8c4 DV |
172 | /** |
173 | * @width: Logical width of the visible area of the framebuffer, in | |
174 | * pixels. | |
175 | */ | |
7520a277 | 176 | unsigned int width; |
750fb8c4 DV |
177 | /** |
178 | * @height: Logical height of the visible area of the framebuffer, in | |
179 | * pixels. | |
180 | */ | |
7520a277 | 181 | unsigned int height; |
750fb8c4 DV |
182 | /** |
183 | * @flags: Framebuffer flags like DRM_MODE_FB_INTERLACED or | |
184 | * DRM_MODE_FB_MODIFIERS. | |
185 | */ | |
7520a277 | 186 | int flags; |
750fb8c4 DV |
187 | /** |
188 | * @hot_x: X coordinate of the cursor hotspot. Used by the legacy cursor | |
189 | * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR | |
190 | * universal plane. | |
191 | */ | |
7520a277 | 192 | int hot_x; |
750fb8c4 DV |
193 | /** |
194 | * @hot_y: Y coordinate of the cursor hotspot. Used by the legacy cursor | |
195 | * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR | |
196 | * universal plane. | |
197 | */ | |
7520a277 | 198 | int hot_y; |
750fb8c4 | 199 | /** |
d574528a | 200 | * @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock. |
750fb8c4 | 201 | */ |
7520a277 | 202 | struct list_head filp_head; |
4c3dbb2c NT |
203 | /** |
204 | * @obj: GEM objects backing the framebuffer, one per plane (optional). | |
205 | * | |
206 | * This is used by the GEM framebuffer helpers, see e.g. | |
207 | * drm_gem_fb_create(). | |
208 | */ | |
209 | struct drm_gem_object *obj[4]; | |
7520a277 DV |
210 | }; |
211 | ||
afb21ea6 DV |
212 | #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) |
213 | ||
7520a277 DV |
214 | int drm_framebuffer_init(struct drm_device *dev, |
215 | struct drm_framebuffer *fb, | |
216 | const struct drm_framebuffer_funcs *funcs); | |
217 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, | |
418da172 | 218 | struct drm_file *file_priv, |
7520a277 DV |
219 | uint32_t id); |
220 | void drm_framebuffer_remove(struct drm_framebuffer *fb); | |
221 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb); | |
222 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); | |
223 | ||
224 | /** | |
a4a69da0 TR |
225 | * drm_framebuffer_get - acquire a framebuffer reference |
226 | * @fb: DRM framebuffer | |
227 | * | |
228 | * This function increments the framebuffer's reference count. | |
229 | */ | |
230 | static inline void drm_framebuffer_get(struct drm_framebuffer *fb) | |
231 | { | |
232 | drm_mode_object_get(&fb->base); | |
233 | } | |
234 | ||
235 | /** | |
236 | * drm_framebuffer_put - release a framebuffer reference | |
237 | * @fb: DRM framebuffer | |
238 | * | |
239 | * This function decrements the framebuffer's reference count and frees the | |
240 | * framebuffer if the reference count drops to zero. | |
241 | */ | |
242 | static inline void drm_framebuffer_put(struct drm_framebuffer *fb) | |
243 | { | |
244 | drm_mode_object_put(&fb->base); | |
245 | } | |
246 | ||
7520a277 DV |
247 | /** |
248 | * drm_framebuffer_read_refcount - read the framebuffer reference count. | |
249 | * @fb: framebuffer | |
250 | * | |
251 | * This functions returns the framebuffer's reference count. | |
252 | */ | |
6ff1086e | 253 | static inline uint32_t drm_framebuffer_read_refcount(const struct drm_framebuffer *fb) |
7520a277 | 254 | { |
2c935bc5 | 255 | return kref_read(&fb->base.refcount); |
7520a277 | 256 | } |
afb21ea6 DV |
257 | |
258 | /** | |
389f78b3 CW |
259 | * drm_framebuffer_assign - store a reference to the fb |
260 | * @p: location to store framebuffer | |
261 | * @fb: new framebuffer (maybe NULL) | |
262 | * | |
263 | * This functions sets the location to store a reference to the framebuffer, | |
264 | * unreferencing the framebuffer that was previously stored in that location. | |
265 | */ | |
266 | static inline void drm_framebuffer_assign(struct drm_framebuffer **p, | |
267 | struct drm_framebuffer *fb) | |
268 | { | |
269 | if (fb) | |
a4a69da0 | 270 | drm_framebuffer_get(fb); |
389f78b3 | 271 | if (*p) |
a4a69da0 | 272 | drm_framebuffer_put(*p); |
389f78b3 CW |
273 | *p = fb; |
274 | } | |
275 | ||
276 | /* | |
afb21ea6 DV |
277 | * drm_for_each_fb - iterate over all framebuffers |
278 | * @fb: the loop cursor | |
279 | * @dev: the DRM device | |
280 | * | |
d574528a DV |
281 | * Iterate over all framebuffers of @dev. User must hold |
282 | * &drm_mode_config.fb_lock. | |
afb21ea6 DV |
283 | */ |
284 | #define drm_for_each_fb(fb, dev) \ | |
285 | for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \ | |
286 | fb = list_first_entry(&(dev)->mode_config.fb_list, \ | |
287 | struct drm_framebuffer, head); \ | |
288 | &fb->head != (&(dev)->mode_config.fb_list); \ | |
289 | fb = list_next_entry(fb, head)) | |
8f8f6a6c VS |
290 | |
291 | int drm_framebuffer_plane_width(int width, | |
292 | const struct drm_framebuffer *fb, int plane); | |
293 | int drm_framebuffer_plane_height(int height, | |
294 | const struct drm_framebuffer *fb, int plane); | |
295 | ||
7520a277 | 296 | #endif |