blob: 1294610e84f47e6f8d3def64b1c1345b3115c2eb [file] [log] [blame]
Daniel Vetter43968d72016-09-21 10:59:24 +02001/*
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_PLANE_H__
24#define __DRM_PLANE_H__
25
26#include <linux/list.h>
27#include <linux/ctype.h>
28#include <drm/drm_mode_object.h>
Jyri Sarha80f690e2018-02-19 22:28:23 +020029#include <drm/drm_color_mgmt.h>
Daniel Vetterb88ac002018-09-05 15:57:07 +020030#include <drm/drm_rect.h>
31#include <drm/drm_modeset_lock.h>
Daniel Vetterd78aa652018-09-05 15:57:05 +020032#include <drm/drm_util.h>
Daniel Vetter43968d72016-09-21 10:59:24 +020033
34struct drm_crtc;
Rob Clarkfceffb322016-11-05 11:08:09 -040035struct drm_printer;
Daniel Vetter34a2ab52017-03-22 22:50:41 +010036struct drm_modeset_acquire_ctx;
Daniel Vetter43968d72016-09-21 10:59:24 +020037
Pankaj Bharadiya5c759ed2020-10-20 21:44:23 +053038enum drm_scaling_filter {
39 DRM_SCALING_FILTER_DEFAULT,
40 DRM_SCALING_FILTER_NEAREST_NEIGHBOR,
41};
42
Daniel Vetter43968d72016-09-21 10:59:24 +020043/**
44 * struct drm_plane_state - mutable plane state
Daniel Vetter2e784a92018-07-09 10:40:09 +020045 *
46 * Please not that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
47 * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
48 * raw coordinates provided by userspace. Drivers should use
49 * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
50 * @src and @dst to program the hardware.
Daniel Vetter43968d72016-09-21 10:59:24 +020051 */
52struct drm_plane_state {
Daniel Vetter2e784a92018-07-09 10:40:09 +020053 /** @plane: backpointer to the plane */
Daniel Vetter43968d72016-09-21 10:59:24 +020054 struct drm_plane *plane;
55
Gustavo Padovan3835b462016-11-07 19:03:33 +090056 /**
57 * @crtc:
58 *
59 * Currently bound CRTC, NULL if disabled. Do not this write directly,
60 * use drm_atomic_set_crtc_for_plane()
61 */
62 struct drm_crtc *crtc;
Daniel Vetter43968d72016-09-21 10:59:24 +020063
Gustavo Padovan3835b462016-11-07 19:03:33 +090064 /**
65 * @fb:
66 *
67 * Currently bound framebuffer. Do not write this directly, use
68 * drm_atomic_set_fb_for_plane()
69 */
70 struct drm_framebuffer *fb;
71
72 /**
73 * @fence:
74 *
Daniel Vetter30d23f22018-04-05 17:44:46 +020075 * Optional fence to wait for before scanning out @fb. The core atomic
76 * code will set this when userspace is using explicit fencing. Do not
Daniel Vetter1b94f472019-06-03 16:28:48 +020077 * write this field directly for a driver's implicit fence, use
Daniel Vetter30d23f22018-04-05 17:44:46 +020078 * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is
79 * preserved.
80 *
81 * Drivers should store any implicit fence in this from their
Thomas Zimmermann820c1702021-02-22 15:17:56 +010082 * &drm_plane_helper_funcs.prepare_fb callback. See drm_gem_plane_helper_prepare_fb()
83 * and drm_gem_simple_display_pipe_prepare_fb() for suitable helpers.
Gustavo Padovan3835b462016-11-07 19:03:33 +090084 */
Daniel Vetter43968d72016-09-21 10:59:24 +020085 struct dma_fence *fence;
86
Gustavo Padovan3835b462016-11-07 19:03:33 +090087 /**
88 * @crtc_x:
89 *
90 * Left position of visible portion of plane on crtc, signed dest
91 * location allows it to be partially off screen.
92 */
93
94 int32_t crtc_x;
95 /**
96 * @crtc_y:
97 *
98 * Upper position of visible portion of plane on crtc, signed dest
99 * location allows it to be partially off screen.
100 */
101 int32_t crtc_y;
102
Daniel Vetter2e784a92018-07-09 10:40:09 +0200103 /** @crtc_w: width of visible portion of plane on crtc */
104 /** @crtc_h: height of visible portion of plane on crtc */
Daniel Vetter43968d72016-09-21 10:59:24 +0200105 uint32_t crtc_w, crtc_h;
106
Daniel Vetter2e784a92018-07-09 10:40:09 +0200107 /**
108 * @src_x: left position of visible portion of plane within plane (in
109 * 16.16 fixed point).
110 */
111 uint32_t src_x;
112 /**
113 * @src_y: upper position of visible portion of plane within plane (in
114 * 16.16 fixed point).
115 */
116 uint32_t src_y;
117 /** @src_w: width of visible portion of plane (in 16.16) */
118 /** @src_h: height of visible portion of plane (in 16.16) */
Daniel Vetter43968d72016-09-21 10:59:24 +0200119 uint32_t src_h, src_w;
120
Daniel Vetter2e784a92018-07-09 10:40:09 +0200121 /**
122 * @alpha:
123 * Opacity of the plane with 0 as completely transparent and 0xffff as
124 * completely opaque. See drm_plane_create_alpha_property() for more
125 * details.
126 */
Maxime Ripardae0e2822018-04-11 09:39:25 +0200127 u16 alpha;
Sean Paulb972cec2018-08-31 11:09:25 -0400128
129 /**
130 * @pixel_blend_mode:
131 * The alpha blending equation selection, describing how the pixels from
132 * the current plane are composited with the background. Value can be
133 * one of DRM_MODE_BLEND_*
134 */
Lowry Lia5ec8332018-08-23 16:30:19 +0800135 uint16_t pixel_blend_mode;
Maxime Ripardae0e2822018-04-11 09:39:25 +0200136
Daniel Vetter2e784a92018-07-09 10:40:09 +0200137 /**
138 * @rotation:
139 * Rotation of the plane. See drm_plane_create_rotation_property() for
140 * more details.
141 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200142 unsigned int rotation;
143
Daniel Vetter2e784a92018-07-09 10:40:09 +0200144 /**
145 * @zpos:
146 * Priority of the given plane on crtc (optional).
147 *
Simon Ser8f6ea272019-10-09 15:10:49 +0000148 * User-space may set mutable zpos properties so that multiple active
149 * planes on the same CRTC have identical zpos values. This is a
150 * user-space bug, but drivers can solve the conflict by comparing the
151 * plane object IDs; the plane with a higher ID is stacked on top of a
152 * plane with a lower ID.
Daniel Vetter2e784a92018-07-09 10:40:09 +0200153 *
154 * See drm_plane_create_zpos_property() and
155 * drm_plane_create_zpos_immutable_property() for more details.
156 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200157 unsigned int zpos;
Daniel Vetter2e784a92018-07-09 10:40:09 +0200158
159 /**
160 * @normalized_zpos:
161 * Normalized value of zpos: unique, range from 0 to N-1 where N is the
162 * number of active planes for given crtc. Note that the driver must set
163 * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
164 * update this before it can be trusted.
165 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200166 unsigned int normalized_zpos;
167
Jyri Sarha80f690e2018-02-19 22:28:23 +0200168 /**
169 * @color_encoding:
170 *
171 * Color encoding for non RGB formats
172 */
173 enum drm_color_encoding color_encoding;
174
175 /**
176 * @color_range:
177 *
178 * Color range for non RGB formats
179 */
180 enum drm_color_range color_range;
181
Lukasz Spintzykd3b21762018-05-23 19:04:08 -0700182 /**
183 * @fb_damage_clips:
184 *
185 * Blob representing damage (area in plane framebuffer that changed
186 * since last plane update) as an array of &drm_mode_rect in framebuffer
187 * coodinates of the attached framebuffer. Note that unlike plane src,
188 * damage clips are not in 16.16 fixed point.
189 */
190 struct drm_property_blob *fb_damage_clips;
191
Maarten Lankhorstfec74872019-10-10 13:19:13 +0200192 /**
193 * @src:
194 *
195 * source coordinates of the plane (in 16.16).
196 *
197 * When using drm_atomic_helper_check_plane_state(),
198 * the coordinates are clipped, but the driver may choose
199 * to use unclipped coordinates instead when the hardware
200 * performs the clipping automatically.
201 */
202 /**
203 * @dst:
204 *
205 * clipped destination coordinates of the plane.
206 *
207 * When using drm_atomic_helper_check_plane_state(),
208 * the coordinates are clipped, but the driver may choose
209 * to use unclipped coordinates instead when the hardware
210 * performs the clipping automatically.
211 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200212 struct drm_rect src, dst;
213
Gustavo Padovan3835b462016-11-07 19:03:33 +0900214 /**
215 * @visible:
216 *
217 * Visibility of the plane. This can be false even if fb!=NULL and
218 * crtc!=NULL, due to clipping.
Daniel Vetter43968d72016-09-21 10:59:24 +0200219 */
220 bool visible;
221
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200222 /**
Pankaj Bharadiya5c759ed2020-10-20 21:44:23 +0530223 * @scaling_filter:
224 *
225 * Scaling filter to be applied
226 */
227 enum drm_scaling_filter scaling_filter;
228
229 /**
Maarten Lankhorst669c9212017-09-04 12:48:38 +0200230 * @commit: Tracks the pending commit to prevent use-after-free conditions,
231 * and for async plane updates.
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200232 *
Maarten Lankhorst669c9212017-09-04 12:48:38 +0200233 * May be NULL.
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200234 */
235 struct drm_crtc_commit *commit;
236
Daniel Vetter2e784a92018-07-09 10:40:09 +0200237 /** @state: backpointer to global drm_atomic_state */
Daniel Vetter43968d72016-09-21 10:59:24 +0200238 struct drm_atomic_state *state;
239};
240
Rob Clark1638d302016-11-05 11:08:08 -0400241static inline struct drm_rect
242drm_plane_state_src(const struct drm_plane_state *state)
243{
244 struct drm_rect src = {
245 .x1 = state->src_x,
246 .y1 = state->src_y,
247 .x2 = state->src_x + state->src_w,
248 .y2 = state->src_y + state->src_h,
249 };
250 return src;
251}
252
253static inline struct drm_rect
254drm_plane_state_dest(const struct drm_plane_state *state)
255{
256 struct drm_rect dest = {
257 .x1 = state->crtc_x,
258 .y1 = state->crtc_y,
259 .x2 = state->crtc_x + state->crtc_w,
260 .y2 = state->crtc_y + state->crtc_h,
261 };
262 return dest;
263}
264
Daniel Vetter43968d72016-09-21 10:59:24 +0200265/**
266 * struct drm_plane_funcs - driver plane control functions
267 */
268struct drm_plane_funcs {
269 /**
270 * @update_plane:
271 *
272 * This is the legacy entry point to enable and configure the plane for
273 * the given CRTC and framebuffer. It is never called to disable the
274 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
275 *
276 * The source rectangle in frame buffer memory coordinates is given by
277 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
278 * values). Devices that don't support subpixel plane coordinates can
279 * ignore the fractional part.
280 *
281 * The destination rectangle in CRTC coordinates is given by the
282 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
283 * Devices scale the source rectangle to the destination rectangle. If
284 * scaling is not supported, and the source rectangle size doesn't match
285 * the destination rectangle size, the driver must return a
286 * -<errorname>EINVAL</errorname> error.
287 *
288 * Drivers implementing atomic modeset should use
289 * drm_atomic_helper_update_plane() to implement this hook.
290 *
291 * RETURNS:
292 *
293 * 0 on success or a negative error code on failure.
294 */
295 int (*update_plane)(struct drm_plane *plane,
296 struct drm_crtc *crtc, struct drm_framebuffer *fb,
297 int crtc_x, int crtc_y,
298 unsigned int crtc_w, unsigned int crtc_h,
299 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100300 uint32_t src_w, uint32_t src_h,
301 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200302
303 /**
304 * @disable_plane:
305 *
306 * This is the legacy entry point to disable the plane. The DRM core
307 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
308 * with the frame buffer ID set to 0. Disabled planes must not be
309 * processed by the CRTC.
310 *
311 * Drivers implementing atomic modeset should use
312 * drm_atomic_helper_disable_plane() to implement this hook.
313 *
314 * RETURNS:
315 *
316 * 0 on success or a negative error code on failure.
317 */
Daniel Vetter19315292017-03-22 22:50:43 +0100318 int (*disable_plane)(struct drm_plane *plane,
319 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200320
321 /**
322 * @destroy:
323 *
324 * Clean up plane resources. This is only called at driver unload time
325 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
326 * in DRM.
327 */
328 void (*destroy)(struct drm_plane *plane);
329
330 /**
331 * @reset:
332 *
333 * Reset plane hardware and software state to off. This function isn't
334 * called by the core directly, only through drm_mode_config_reset().
335 * It's not a helper hook only for historical reasons.
336 *
337 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
338 * atomic state using this hook.
339 */
340 void (*reset)(struct drm_plane *plane);
341
342 /**
343 * @set_property:
344 *
345 * This is the legacy entry point to update a property attached to the
346 * plane.
347 *
Daniel Vetter43968d72016-09-21 10:59:24 +0200348 * This callback is optional if the driver does not support any legacy
Daniel Vetter144a7992017-07-25 14:02:04 +0200349 * driver-private properties. For atomic drivers it is not used because
350 * property handling is done entirely in the DRM core.
Daniel Vetter43968d72016-09-21 10:59:24 +0200351 *
352 * RETURNS:
353 *
354 * 0 on success or a negative error code on failure.
355 */
356 int (*set_property)(struct drm_plane *plane,
357 struct drm_property *property, uint64_t val);
358
359 /**
360 * @atomic_duplicate_state:
361 *
362 * Duplicate the current atomic state for this plane and return it.
Daniel Vetterd5745282017-01-25 07:26:45 +0100363 * The core and helpers guarantee that any atomic state duplicated with
Daniel Vetter43968d72016-09-21 10:59:24 +0200364 * this hook and still owned by the caller (i.e. not transferred to the
Daniel Vetterd5745282017-01-25 07:26:45 +0100365 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
366 * cleaned up by calling the @atomic_destroy_state hook in this
367 * structure.
Daniel Vetter43968d72016-09-21 10:59:24 +0200368 *
Haneen Mohammedba1f6652018-05-25 04:25:55 +0300369 * This callback is mandatory for atomic drivers.
370 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100371 * Atomic drivers which don't subclass &struct drm_plane_state should use
Daniel Vetter43968d72016-09-21 10:59:24 +0200372 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
373 * state structure to extend it with driver-private state should use
374 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
375 * duplicated in a consistent fashion across drivers.
376 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100377 * It is an error to call this hook before &drm_plane.state has been
Daniel Vetter43968d72016-09-21 10:59:24 +0200378 * initialized correctly.
379 *
380 * NOTE:
381 *
382 * If the duplicate state references refcounted resources this hook must
383 * acquire a reference for each of them. The driver must release these
384 * references again in @atomic_destroy_state.
385 *
386 * RETURNS:
387 *
388 * Duplicated atomic state or NULL when the allocation failed.
389 */
390 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
391
392 /**
393 * @atomic_destroy_state:
394 *
395 * Destroy a state duplicated with @atomic_duplicate_state and release
396 * or unreference all resources it references
Haneen Mohammedba1f6652018-05-25 04:25:55 +0300397 *
398 * This callback is mandatory for atomic drivers.
Daniel Vetter43968d72016-09-21 10:59:24 +0200399 */
400 void (*atomic_destroy_state)(struct drm_plane *plane,
401 struct drm_plane_state *state);
402
403 /**
404 * @atomic_set_property:
405 *
406 * Decode a driver-private property value and store the decoded value
407 * into the passed-in state structure. Since the atomic core decodes all
408 * standardized properties (even for extensions beyond the core set of
409 * properties which might not be implemented by all drivers) this
410 * requires drivers to subclass the state structure.
411 *
412 * Such driver-private properties should really only be implemented for
413 * truly hardware/vendor specific state. Instead it is preferred to
414 * standardize atomic extension and decode the properties used to expose
415 * such an extension in the core.
416 *
417 * Do not call this function directly, use
418 * drm_atomic_plane_set_property() instead.
419 *
420 * This callback is optional if the driver does not support any
421 * driver-private atomic properties.
422 *
423 * NOTE:
424 *
425 * This function is called in the state assembly phase of atomic
426 * modesets, which can be aborted for any reason (including on
427 * userspace's request to just check whether a configuration would be
428 * possible). Drivers MUST NOT touch any persistent state (hardware or
429 * software) or data structures except the passed in @state parameter.
430 *
431 * Also since userspace controls in which order properties are set this
432 * function must not do any input validation (since the state update is
433 * incomplete and hence likely inconsistent). Instead any such input
434 * validation must be done in the various atomic_check callbacks.
435 *
436 * RETURNS:
437 *
438 * 0 if the property has been found, -EINVAL if the property isn't
439 * implemented by the driver (which shouldn't ever happen, the core only
440 * asks for properties attached to this plane). No other validation is
441 * allowed by the driver. The core already checks that the property
442 * value is within the range (integer, valid enum value, ...) the driver
443 * set when registering the property.
444 */
445 int (*atomic_set_property)(struct drm_plane *plane,
446 struct drm_plane_state *state,
447 struct drm_property *property,
448 uint64_t val);
449
450 /**
451 * @atomic_get_property:
452 *
453 * Reads out the decoded driver-private property. This is used to
454 * implement the GETPLANE IOCTL.
455 *
456 * Do not call this function directly, use
457 * drm_atomic_plane_get_property() instead.
458 *
459 * This callback is optional if the driver does not support any
460 * driver-private atomic properties.
461 *
462 * RETURNS:
463 *
464 * 0 on success, -EINVAL if the property isn't implemented by the
465 * driver (which should never happen, the core only asks for
466 * properties attached to this plane).
467 */
468 int (*atomic_get_property)(struct drm_plane *plane,
469 const struct drm_plane_state *state,
470 struct drm_property *property,
471 uint64_t *val);
472 /**
473 * @late_register:
474 *
475 * This optional hook can be used to register additional userspace
476 * interfaces attached to the plane like debugfs interfaces.
477 * It is called late in the driver load sequence from drm_dev_register().
478 * Everything added from this callback should be unregistered in
479 * the early_unregister callback.
480 *
481 * Returns:
482 *
483 * 0 on success, or a negative error code on failure.
484 */
485 int (*late_register)(struct drm_plane *plane);
486
487 /**
488 * @early_unregister:
489 *
490 * This optional hook should be used to unregister the additional
491 * userspace interfaces attached to the plane from
Daniel Vetter559bdaf2017-01-25 07:26:55 +0100492 * @late_register. It is called from drm_dev_unregister(),
Daniel Vetter43968d72016-09-21 10:59:24 +0200493 * early in the driver unload sequence to disable userspace access
494 * before data structures are torndown.
495 */
496 void (*early_unregister)(struct drm_plane *plane);
Rob Clarkfceffb322016-11-05 11:08:09 -0400497
498 /**
499 * @atomic_print_state:
500 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100501 * If driver subclasses &struct drm_plane_state, it should implement
Rob Clarkfceffb322016-11-05 11:08:09 -0400502 * this optional hook for printing additional driver specific state.
503 *
504 * Do not call this directly, use drm_atomic_plane_print_state()
505 * instead.
506 */
507 void (*atomic_print_state)(struct drm_printer *p,
508 const struct drm_plane_state *state);
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700509
510 /**
511 * @format_mod_supported:
512 *
513 * This optional hook is used for the DRM to determine if the given
514 * format/modifier combination is valid for the plane. This allows the
515 * DRM to generate the correct format bitmask (which formats apply to
Eric Anholt8fb756d2018-03-16 15:04:33 -0700516 * which modifier), and to valdiate modifiers at atomic_check time.
517 *
518 * If not present, then any modifier in the plane's modifier
519 * list is allowed with any of the plane's formats.
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700520 *
521 * Returns:
522 *
523 * True if the given modifier is valid for that format on the plane.
524 * False otherwise.
525 */
526 bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
527 uint64_t modifier);
Daniel Vetter43968d72016-09-21 10:59:24 +0200528};
529
Daniel Vetter532b3672016-09-21 10:59:25 +0200530/**
531 * enum drm_plane_type - uapi plane type enumeration
532 *
533 * For historical reasons not all planes are made the same. This enumeration is
534 * used to tell the different types of planes apart to implement the different
535 * uapi semantics for them. For userspace which is universal plane aware and
536 * which is using that atomic IOCTL there's no difference between these planes
537 * (beyong what the driver and hardware can support of course).
538 *
539 * For compatibility with legacy userspace, only overlay planes are made
540 * available to userspace by default. Userspace clients may set the
Simon Ser7e5d1e12021-01-15 12:06:25 +0100541 * &DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
Daniel Vetter532b3672016-09-21 10:59:25 +0200542 * wish to receive a universal plane list containing all plane types. See also
543 * drm_for_each_legacy_plane().
Daniel Vetter226714d2016-09-23 08:35:25 +0200544 *
Simon Ser7e5d1e12021-01-15 12:06:25 +0100545 * In addition to setting each plane's type, drivers need to setup the
546 * &drm_crtc.primary and optionally &drm_crtc.cursor pointers for legacy
547 * IOCTLs. See drm_crtc_init_with_planes().
548 *
Daniel Vetter226714d2016-09-23 08:35:25 +0200549 * WARNING: The values of this enum is UABI since they're exposed in the "type"
550 * property.
Daniel Vetter532b3672016-09-21 10:59:25 +0200551 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200552enum drm_plane_type {
Daniel Vetter532b3672016-09-21 10:59:25 +0200553 /**
Daniel Vetter226714d2016-09-23 08:35:25 +0200554 * @DRM_PLANE_TYPE_OVERLAY:
555 *
556 * Overlay planes represent all non-primary, non-cursor planes. Some
557 * drivers refer to these types of planes as "sprites" internally.
558 */
559 DRM_PLANE_TYPE_OVERLAY,
560
561 /**
Daniel Vetter532b3672016-09-21 10:59:25 +0200562 * @DRM_PLANE_TYPE_PRIMARY:
563 *
Simon Ser7e5d1e12021-01-15 12:06:25 +0100564 * A primary plane attached to a CRTC is the most likely to be able to
565 * light up the CRTC when no scaling/cropping is used and the plane
566 * covers the whole CRTC.
Daniel Vetter532b3672016-09-21 10:59:25 +0200567 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200568 DRM_PLANE_TYPE_PRIMARY,
Daniel Vetter532b3672016-09-21 10:59:25 +0200569
570 /**
571 * @DRM_PLANE_TYPE_CURSOR:
572 *
Simon Ser7e5d1e12021-01-15 12:06:25 +0100573 * A cursor plane attached to a CRTC is more likely to be able to be
574 * enabled when no scaling/cropping is used and the framebuffer has the
575 * size indicated by &drm_mode_config.cursor_width and
576 * &drm_mode_config.cursor_height. Additionally, if the driver doesn't
577 * support modifiers, the framebuffer should have a linear layout.
Daniel Vetter532b3672016-09-21 10:59:25 +0200578 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200579 DRM_PLANE_TYPE_CURSOR,
580};
581
582
583/**
584 * struct drm_plane - central DRM plane control structure
Daniel Vetter268bc242018-07-09 10:40:10 +0200585 *
586 * Planes represent the scanout hardware of a display block. They receive their
587 * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
588 * the color conversion, see `Plane Composition Properties`_ for more details,
589 * and are also involved in the color conversion of input pixels, see `Color
590 * Management Properties`_ for details on that.
Daniel Vetter43968d72016-09-21 10:59:24 +0200591 */
592struct drm_plane {
Daniel Vetter268bc242018-07-09 10:40:10 +0200593 /** @dev: DRM device this plane belongs to */
Daniel Vetter43968d72016-09-21 10:59:24 +0200594 struct drm_device *dev;
Daniel Vetter268bc242018-07-09 10:40:10 +0200595
596 /**
597 * @head:
598 *
599 * List of all planes on @dev, linked from &drm_mode_config.plane_list.
600 * Invariant over the lifetime of @dev and therefore does not need
601 * locking.
602 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200603 struct list_head head;
604
Daniel Vetter268bc242018-07-09 10:40:10 +0200605 /** @name: human readable name, can be overwritten by the driver */
Daniel Vetter43968d72016-09-21 10:59:24 +0200606 char *name;
607
608 /**
609 * @mutex:
610 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100611 * Protects modeset plane state, together with the &drm_crtc.mutex of
612 * CRTC this plane is linked to (when active, getting activated or
613 * getting disabled).
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200614 *
615 * For atomic drivers specifically this protects @state.
Daniel Vetter43968d72016-09-21 10:59:24 +0200616 */
617 struct drm_modeset_lock mutex;
618
Daniel Vetter268bc242018-07-09 10:40:10 +0200619 /** @base: base mode object */
Daniel Vetter43968d72016-09-21 10:59:24 +0200620 struct drm_mode_object base;
621
Daniel Vetter268bc242018-07-09 10:40:10 +0200622 /**
623 * @possible_crtcs: pipes this plane can be bound to constructed from
624 * drm_crtc_mask()
625 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200626 uint32_t possible_crtcs;
Daniel Vetter268bc242018-07-09 10:40:10 +0200627 /** @format_types: array of formats supported by this plane */
Daniel Vetter43968d72016-09-21 10:59:24 +0200628 uint32_t *format_types;
Daniel Vetter268bc242018-07-09 10:40:10 +0200629 /** @format_count: Size of the array pointed at by @format_types. */
Daniel Vetter43968d72016-09-21 10:59:24 +0200630 unsigned int format_count;
Daniel Vetter268bc242018-07-09 10:40:10 +0200631 /**
632 * @format_default: driver hasn't supplied supported formats for the
633 * plane. Used by the drm_plane_init compatibility wrapper only.
634 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200635 bool format_default;
636
Daniel Vetter268bc242018-07-09 10:40:10 +0200637 /** @modifiers: array of modifiers supported by this plane */
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700638 uint64_t *modifiers;
Daniel Vetter268bc242018-07-09 10:40:10 +0200639 /** @modifier_count: Size of the array pointed at by @modifier_count. */
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700640 unsigned int modifier_count;
641
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100642 /**
Daniel Vetter268bc242018-07-09 10:40:10 +0200643 * @crtc:
644 *
645 * Currently bound CRTC, only meaningful for non-atomic drivers. For
646 * atomic drivers this is forced to be NULL, atomic drivers should
647 * instead check &drm_plane_state.crtc.
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100648 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200649 struct drm_crtc *crtc;
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100650
651 /**
Daniel Vetter268bc242018-07-09 10:40:10 +0200652 * @fb:
653 *
654 * Currently bound framebuffer, only meaningful for non-atomic drivers.
655 * For atomic drivers this is forced to be NULL, atomic drivers should
656 * instead check &drm_plane_state.fb.
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100657 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200658 struct drm_framebuffer *fb;
659
Daniel Vetter268bc242018-07-09 10:40:10 +0200660 /**
661 * @old_fb:
662 *
663 * Temporary tracking of the old fb while a modeset is ongoing. Only
664 * used by non-atomic drivers, forced to be NULL for atomic drivers.
665 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200666 struct drm_framebuffer *old_fb;
667
Daniel Vetter268bc242018-07-09 10:40:10 +0200668 /** @funcs: plane control functions */
Daniel Vetter43968d72016-09-21 10:59:24 +0200669 const struct drm_plane_funcs *funcs;
670
Daniel Vetter268bc242018-07-09 10:40:10 +0200671 /** @properties: property tracking for this plane */
Daniel Vetter43968d72016-09-21 10:59:24 +0200672 struct drm_object_properties properties;
673
Daniel Vetter268bc242018-07-09 10:40:10 +0200674 /** @type: Type of plane, see &enum drm_plane_type for details. */
Daniel Vetter43968d72016-09-21 10:59:24 +0200675 enum drm_plane_type type;
676
677 /**
678 * @index: Position inside the mode_config.list, can be used as an array
679 * index. It is invariant over the lifetime of the plane.
680 */
681 unsigned index;
682
Daniel Vetter268bc242018-07-09 10:40:10 +0200683 /** @helper_private: mid-layer private data */
Daniel Vetter43968d72016-09-21 10:59:24 +0200684 const struct drm_plane_helper_funcs *helper_private;
685
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200686 /**
687 * @state:
688 *
689 * Current atomic state for this plane.
690 *
691 * This is protected by @mutex. Note that nonblocking atomic commits
692 * access the current plane state without taking locks. Either by going
693 * through the &struct drm_atomic_state pointers, see
Maarten Lankhorst77ac3b02017-07-19 16:39:20 +0200694 * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
695 * for_each_new_plane_in_state(). Or through careful ordering of atomic
696 * commit operations as implemented in the atomic helpers, see
697 * &struct drm_crtc_commit.
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200698 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200699 struct drm_plane_state *state;
700
Daniel Vetter268bc242018-07-09 10:40:10 +0200701 /**
702 * @alpha_property:
703 * Optional alpha property for this plane. See
704 * drm_plane_create_alpha_property().
705 */
Maxime Ripardae0e2822018-04-11 09:39:25 +0200706 struct drm_property *alpha_property;
Daniel Vetter268bc242018-07-09 10:40:10 +0200707 /**
708 * @zpos_property:
709 * Optional zpos property for this plane. See
710 * drm_plane_create_zpos_property().
711 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200712 struct drm_property *zpos_property;
Daniel Vetter268bc242018-07-09 10:40:10 +0200713 /**
714 * @rotation_property:
715 * Optional rotation property for this plane. See
716 * drm_plane_create_rotation_property().
717 */
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300718 struct drm_property *rotation_property;
Lowry Lia5ec8332018-08-23 16:30:19 +0800719 /**
720 * @blend_mode_property:
721 * Optional "pixel blend mode" enum property for this plane.
722 * Blend mode property represents the alpha blending equation selection,
723 * describing how the pixels from the current plane are composited with
724 * the background.
725 */
726 struct drm_property *blend_mode_property;
Jyri Sarha80f690e2018-02-19 22:28:23 +0200727
728 /**
729 * @color_encoding_property:
730 *
731 * Optional "COLOR_ENCODING" enum property for specifying
732 * color encoding for non RGB formats.
733 * See drm_plane_create_color_properties().
734 */
735 struct drm_property *color_encoding_property;
736 /**
737 * @color_range_property:
738 *
739 * Optional "COLOR_RANGE" enum property for specifying
740 * color range for non RGB formats.
741 * See drm_plane_create_color_properties().
742 */
743 struct drm_property *color_range_property;
Pankaj Bharadiya5c759ed2020-10-20 21:44:23 +0530744
745 /**
746 * @scaling_filter_property: property to apply a particular filter while
747 * scaling.
748 */
749 struct drm_property *scaling_filter_property;
Daniel Vetter43968d72016-09-21 10:59:24 +0200750};
751
752#define obj_to_plane(x) container_of(x, struct drm_plane, base)
753
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700754__printf(9, 10)
Daniel Vetter43968d72016-09-21 10:59:24 +0200755int drm_universal_plane_init(struct drm_device *dev,
756 struct drm_plane *plane,
Tomi Valkeinen5cd57a42016-12-02 15:45:35 +0200757 uint32_t possible_crtcs,
Daniel Vetter43968d72016-09-21 10:59:24 +0200758 const struct drm_plane_funcs *funcs,
759 const uint32_t *formats,
760 unsigned int format_count,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700761 const uint64_t *format_modifiers,
Daniel Vetter43968d72016-09-21 10:59:24 +0200762 enum drm_plane_type type,
763 const char *name, ...);
Daniel Vetter91faa042017-03-22 09:36:02 +0100764int drm_plane_init(struct drm_device *dev,
765 struct drm_plane *plane,
766 uint32_t possible_crtcs,
767 const struct drm_plane_funcs *funcs,
768 const uint32_t *formats, unsigned int format_count,
769 bool is_primary);
770void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200771
Philipp Zabel0a1b8132020-12-10 16:38:30 +0100772__printf(10, 11)
773void *__drmm_universal_plane_alloc(struct drm_device *dev,
774 size_t size, size_t offset,
775 uint32_t possible_crtcs,
776 const struct drm_plane_funcs *funcs,
777 const uint32_t *formats,
778 unsigned int format_count,
779 const uint64_t *format_modifiers,
780 enum drm_plane_type plane_type,
781 const char *name, ...);
782
783/**
784 * drmm_universal_plane_alloc - Allocate and initialize an universal plane object
785 * @dev: DRM device
786 * @type: the type of the struct which contains struct &drm_plane
787 * @member: the name of the &drm_plane within @type
788 * @possible_crtcs: bitmask of possible CRTCs
789 * @funcs: callbacks for the new plane
790 * @formats: array of supported formats (DRM_FORMAT\_\*)
791 * @format_count: number of elements in @formats
792 * @format_modifiers: array of struct drm_format modifiers terminated by
793 * DRM_FORMAT_MOD_INVALID
794 * @plane_type: type of plane (overlay, primary, cursor)
795 * @name: printf style format string for the plane name, or NULL for default name
796 *
797 * Allocates and initializes a plane object of type @type. Cleanup is
798 * automatically handled through registering drm_plane_cleanup() with
799 * drmm_add_action().
800 *
801 * The @drm_plane_funcs.destroy hook must be NULL.
802 *
803 * Returns:
804 * Pointer to new plane, or ERR_PTR on failure.
805 */
806#define drmm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
807 format_count, format_modifiers, plane_type, name, ...) \
808 ((type *)__drmm_universal_plane_alloc(dev, sizeof(type), \
809 offsetof(type, member), \
810 possible_crtcs, funcs, formats, \
811 format_count, format_modifiers, \
812 plane_type, name, ##__VA_ARGS__))
813
Daniel Vetter43968d72016-09-21 10:59:24 +0200814/**
815 * drm_plane_index - find the index of a registered plane
816 * @plane: plane to find index for
817 *
818 * Given a registered plane, return the index of that plane within a DRM
819 * device's list of planes.
820 */
Ville Syrjälä62f77ad2018-06-26 22:47:07 +0300821static inline unsigned int drm_plane_index(const struct drm_plane *plane)
Daniel Vetter43968d72016-09-21 10:59:24 +0200822{
823 return plane->index;
824}
Ville Syrjälä62f77ad2018-06-26 22:47:07 +0300825
826/**
827 * drm_plane_mask - find the mask of a registered plane
828 * @plane: plane to find mask for
829 */
830static inline u32 drm_plane_mask(const struct drm_plane *plane)
831{
832 return 1 << drm_plane_index(plane);
833}
834
Daniel Vetter91faa042017-03-22 09:36:02 +0100835struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
836void drm_plane_force_disable(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200837
838int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
839 struct drm_property *property,
840 uint64_t value);
841
842/**
843 * drm_plane_find - find a &drm_plane
844 * @dev: DRM device
Dave Airliee7e62c72017-11-09 09:35:04 +1000845 * @file_priv: drm file to check for lease against.
Daniel Vetter43968d72016-09-21 10:59:24 +0200846 * @id: plane id
847 *
848 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
849 * drm_mode_object_find().
850 */
851static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
Keith Packard418da172017-03-14 23:25:07 -0700852 struct drm_file *file_priv,
Daniel Vetter43968d72016-09-21 10:59:24 +0200853 uint32_t id)
854{
855 struct drm_mode_object *mo;
Keith Packard418da172017-03-14 23:25:07 -0700856 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
Daniel Vetter43968d72016-09-21 10:59:24 +0200857 return mo ? obj_to_plane(mo) : NULL;
858}
859
860/**
861 * drm_for_each_plane_mask - iterate over planes specified by bitmask
862 * @plane: the loop cursor
863 * @dev: the DRM device
864 * @plane_mask: bitmask of plane indices
865 *
866 * Iterate over all planes specified by bitmask.
867 */
868#define drm_for_each_plane_mask(plane, dev, plane_mask) \
869 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Ville Syrjälä62f77ad2018-06-26 22:47:07 +0300870 for_each_if ((plane_mask) & drm_plane_mask(plane))
Daniel Vetter43968d72016-09-21 10:59:24 +0200871
Daniel Vetter532b3672016-09-21 10:59:25 +0200872/**
873 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
874 * @plane: the loop cursor
875 * @dev: the DRM device
876 *
877 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
878 * This is useful for implementing userspace apis when userspace is not
Daniel Vetterd5745282017-01-25 07:26:45 +0100879 * universal plane aware. See also &enum drm_plane_type.
Daniel Vetter532b3672016-09-21 10:59:25 +0200880 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200881#define drm_for_each_legacy_plane(plane, dev) \
882 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
883 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
884
Daniel Vetter532b3672016-09-21 10:59:25 +0200885/**
886 * drm_for_each_plane - iterate over all planes
887 * @plane: the loop cursor
888 * @dev: the DRM device
889 *
890 * Iterate over all planes of @dev, include primary and cursor planes.
891 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200892#define drm_for_each_plane(plane, dev) \
893 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
894
Ville Syrjäläe7afb622018-10-29 20:34:52 +0200895bool drm_any_plane_has_format(struct drm_device *dev,
896 u32 format, u64 modifier);
Lukasz Spintzykd3b21762018-05-23 19:04:08 -0700897/**
898 * drm_plane_get_damage_clips_count - Returns damage clips count.
899 * @state: Plane state.
900 *
901 * Simple helper to get the number of &drm_mode_rect clips set by user-space
902 * during plane update.
903 *
904 * Return: Number of clips in plane fb_damage_clips blob property.
905 */
906static inline unsigned int
907drm_plane_get_damage_clips_count(const struct drm_plane_state *state)
908{
909 return (state && state->fb_damage_clips) ?
910 state->fb_damage_clips->length/sizeof(struct drm_mode_rect) : 0;
911}
912
913/**
914 * drm_plane_get_damage_clips - Returns damage clips.
915 * @state: Plane state.
916 *
Deepak Rawatd2780b12018-05-30 14:42:52 -0700917 * Note that this function returns uapi type &drm_mode_rect. Drivers might
918 * instead be interested in internal &drm_rect which can be obtained by calling
919 * drm_helper_get_plane_damage_clips().
Lukasz Spintzykd3b21762018-05-23 19:04:08 -0700920 *
921 * Return: Damage clips in plane fb_damage_clips blob property.
922 */
923static inline struct drm_mode_rect *
924drm_plane_get_damage_clips(const struct drm_plane_state *state)
925{
926 return (struct drm_mode_rect *)((state && state->fb_damage_clips) ?
927 state->fb_damage_clips->data : NULL);
928}
Daniel Vetter43968d72016-09-21 10:59:24 +0200929
Pankaj Bharadiya5c759ed2020-10-20 21:44:23 +0530930int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
931 unsigned int supported_filters);
932
Daniel Vetter43968d72016-09-21 10:59:24 +0200933#endif