]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/drm/drm_plane.h
Merge tag 'imx-drm-next-2018-12-03' of git://git.pengutronix.de/git/pza/linux into...
[mirror_ubuntu-jammy-kernel.git] / include / drm / drm_plane.h
CommitLineData
43968d7b
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_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>
80f690e9 29#include <drm/drm_color_mgmt.h>
b88ac005
DV
30#include <drm/drm_rect.h>
31#include <drm/drm_modeset_lock.h>
d78aa650 32#include <drm/drm_util.h>
43968d7b
DV
33
34struct drm_crtc;
fceffb32 35struct drm_printer;
34a2ab5e 36struct drm_modeset_acquire_ctx;
43968d7b
DV
37
38/**
39 * struct drm_plane_state - mutable plane state
2e784a91
DV
40 *
41 * Please not that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
42 * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
43 * raw coordinates provided by userspace. Drivers should use
44 * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
45 * @src and @dst to program the hardware.
43968d7b
DV
46 */
47struct drm_plane_state {
2e784a91 48 /** @plane: backpointer to the plane */
43968d7b
DV
49 struct drm_plane *plane;
50
3835b46e
GP
51 /**
52 * @crtc:
53 *
54 * Currently bound CRTC, NULL if disabled. Do not this write directly,
55 * use drm_atomic_set_crtc_for_plane()
56 */
57 struct drm_crtc *crtc;
58
59 /**
60 * @fb:
61 *
62 * Currently bound framebuffer. Do not write this directly, use
63 * drm_atomic_set_fb_for_plane()
64 */
65 struct drm_framebuffer *fb;
66
67 /**
68 * @fence:
69 *
30d23f22
DV
70 * Optional fence to wait for before scanning out @fb. The core atomic
71 * code will set this when userspace is using explicit fencing. Do not
72 * write this directly for a driver's implicit fence, use
73 * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is
74 * preserved.
75 *
76 * Drivers should store any implicit fence in this from their
2e784a91 77 * &drm_plane_helper_funcs.prepare_fb callback. See drm_gem_fb_prepare_fb()
30d23f22 78 * and drm_gem_fb_simple_display_pipe_prepare_fb() for suitable helpers.
3835b46e 79 */
f54d1867 80 struct dma_fence *fence;
43968d7b 81
3835b46e
GP
82 /**
83 * @crtc_x:
84 *
85 * Left position of visible portion of plane on crtc, signed dest
86 * location allows it to be partially off screen.
87 */
88
89 int32_t crtc_x;
90 /**
91 * @crtc_y:
92 *
93 * Upper position of visible portion of plane on crtc, signed dest
94 * location allows it to be partially off screen.
95 */
96 int32_t crtc_y;
43968d7b 97
2e784a91
DV
98 /** @crtc_w: width of visible portion of plane on crtc */
99 /** @crtc_h: height of visible portion of plane on crtc */
43968d7b
DV
100 uint32_t crtc_w, crtc_h;
101
2e784a91
DV
102 /**
103 * @src_x: left position of visible portion of plane within plane (in
104 * 16.16 fixed point).
105 */
106 uint32_t src_x;
107 /**
108 * @src_y: upper position of visible portion of plane within plane (in
109 * 16.16 fixed point).
110 */
111 uint32_t src_y;
112 /** @src_w: width of visible portion of plane (in 16.16) */
113 /** @src_h: height of visible portion of plane (in 16.16) */
43968d7b
DV
114 uint32_t src_h, src_w;
115
2e784a91
DV
116 /**
117 * @alpha:
118 * Opacity of the plane with 0 as completely transparent and 0xffff as
119 * completely opaque. See drm_plane_create_alpha_property() for more
120 * details.
121 */
ae0e2826 122 u16 alpha;
b972cece
SP
123
124 /**
125 * @pixel_blend_mode:
126 * The alpha blending equation selection, describing how the pixels from
127 * the current plane are composited with the background. Value can be
128 * one of DRM_MODE_BLEND_*
129 */
a5ec8332 130 uint16_t pixel_blend_mode;
ae0e2826 131
2e784a91
DV
132 /**
133 * @rotation:
134 * Rotation of the plane. See drm_plane_create_rotation_property() for
135 * more details.
136 */
43968d7b
DV
137 unsigned int rotation;
138
2e784a91
DV
139 /**
140 * @zpos:
141 * Priority of the given plane on crtc (optional).
142 *
143 * Note that multiple active planes on the same crtc can have an
144 * identical zpos value. The rule to solving the conflict is to compare
145 * the plane object IDs; the plane with a higher ID must be stacked on
146 * top of a plane with a lower ID.
147 *
148 * See drm_plane_create_zpos_property() and
149 * drm_plane_create_zpos_immutable_property() for more details.
150 */
43968d7b 151 unsigned int zpos;
2e784a91
DV
152
153 /**
154 * @normalized_zpos:
155 * Normalized value of zpos: unique, range from 0 to N-1 where N is the
156 * number of active planes for given crtc. Note that the driver must set
157 * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
158 * update this before it can be trusted.
159 */
43968d7b
DV
160 unsigned int normalized_zpos;
161
80f690e9
JS
162 /**
163 * @color_encoding:
164 *
165 * Color encoding for non RGB formats
166 */
167 enum drm_color_encoding color_encoding;
168
169 /**
170 * @color_range:
171 *
172 * Color range for non RGB formats
173 */
174 enum drm_color_range color_range;
175
2e784a91
DV
176 /** @src: clipped source coordinates of the plane (in 16.16) */
177 /** @dst: clipped destination coordinates of the plane */
43968d7b
DV
178 struct drm_rect src, dst;
179
3835b46e
GP
180 /**
181 * @visible:
182 *
183 * Visibility of the plane. This can be false even if fb!=NULL and
184 * crtc!=NULL, due to clipping.
43968d7b
DV
185 */
186 bool visible;
187
21a01abb 188 /**
669c9215
ML
189 * @commit: Tracks the pending commit to prevent use-after-free conditions,
190 * and for async plane updates.
21a01abb 191 *
669c9215 192 * May be NULL.
21a01abb
ML
193 */
194 struct drm_crtc_commit *commit;
195
2e784a91 196 /** @state: backpointer to global drm_atomic_state */
43968d7b
DV
197 struct drm_atomic_state *state;
198};
199
1638d30c
RC
200static inline struct drm_rect
201drm_plane_state_src(const struct drm_plane_state *state)
202{
203 struct drm_rect src = {
204 .x1 = state->src_x,
205 .y1 = state->src_y,
206 .x2 = state->src_x + state->src_w,
207 .y2 = state->src_y + state->src_h,
208 };
209 return src;
210}
211
212static inline struct drm_rect
213drm_plane_state_dest(const struct drm_plane_state *state)
214{
215 struct drm_rect dest = {
216 .x1 = state->crtc_x,
217 .y1 = state->crtc_y,
218 .x2 = state->crtc_x + state->crtc_w,
219 .y2 = state->crtc_y + state->crtc_h,
220 };
221 return dest;
222}
223
43968d7b
DV
224/**
225 * struct drm_plane_funcs - driver plane control functions
226 */
227struct drm_plane_funcs {
228 /**
229 * @update_plane:
230 *
231 * This is the legacy entry point to enable and configure the plane for
232 * the given CRTC and framebuffer. It is never called to disable the
233 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
234 *
235 * The source rectangle in frame buffer memory coordinates is given by
236 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
237 * values). Devices that don't support subpixel plane coordinates can
238 * ignore the fractional part.
239 *
240 * The destination rectangle in CRTC coordinates is given by the
241 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
242 * Devices scale the source rectangle to the destination rectangle. If
243 * scaling is not supported, and the source rectangle size doesn't match
244 * the destination rectangle size, the driver must return a
245 * -<errorname>EINVAL</errorname> error.
246 *
247 * Drivers implementing atomic modeset should use
248 * drm_atomic_helper_update_plane() to implement this hook.
249 *
250 * RETURNS:
251 *
252 * 0 on success or a negative error code on failure.
253 */
254 int (*update_plane)(struct drm_plane *plane,
255 struct drm_crtc *crtc, struct drm_framebuffer *fb,
256 int crtc_x, int crtc_y,
257 unsigned int crtc_w, unsigned int crtc_h,
258 uint32_t src_x, uint32_t src_y,
34a2ab5e
DV
259 uint32_t src_w, uint32_t src_h,
260 struct drm_modeset_acquire_ctx *ctx);
43968d7b
DV
261
262 /**
263 * @disable_plane:
264 *
265 * This is the legacy entry point to disable the plane. The DRM core
266 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
267 * with the frame buffer ID set to 0. Disabled planes must not be
268 * processed by the CRTC.
269 *
270 * Drivers implementing atomic modeset should use
271 * drm_atomic_helper_disable_plane() to implement this hook.
272 *
273 * RETURNS:
274 *
275 * 0 on success or a negative error code on failure.
276 */
19315294
DV
277 int (*disable_plane)(struct drm_plane *plane,
278 struct drm_modeset_acquire_ctx *ctx);
43968d7b
DV
279
280 /**
281 * @destroy:
282 *
283 * Clean up plane resources. This is only called at driver unload time
284 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
285 * in DRM.
286 */
287 void (*destroy)(struct drm_plane *plane);
288
289 /**
290 * @reset:
291 *
292 * Reset plane hardware and software state to off. This function isn't
293 * called by the core directly, only through drm_mode_config_reset().
294 * It's not a helper hook only for historical reasons.
295 *
296 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
297 * atomic state using this hook.
298 */
299 void (*reset)(struct drm_plane *plane);
300
301 /**
302 * @set_property:
303 *
304 * This is the legacy entry point to update a property attached to the
305 * plane.
306 *
43968d7b 307 * This callback is optional if the driver does not support any legacy
144a7999
DV
308 * driver-private properties. For atomic drivers it is not used because
309 * property handling is done entirely in the DRM core.
43968d7b
DV
310 *
311 * RETURNS:
312 *
313 * 0 on success or a negative error code on failure.
314 */
315 int (*set_property)(struct drm_plane *plane,
316 struct drm_property *property, uint64_t val);
317
318 /**
319 * @atomic_duplicate_state:
320 *
321 * Duplicate the current atomic state for this plane and return it.
d574528a 322 * The core and helpers guarantee that any atomic state duplicated with
43968d7b 323 * this hook and still owned by the caller (i.e. not transferred to the
d574528a
DV
324 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
325 * cleaned up by calling the @atomic_destroy_state hook in this
326 * structure.
43968d7b 327 *
ba1f665f
HM
328 * This callback is mandatory for atomic drivers.
329 *
ea0dd85a 330 * Atomic drivers which don't subclass &struct drm_plane_state should use
43968d7b
DV
331 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
332 * state structure to extend it with driver-private state should use
333 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
334 * duplicated in a consistent fashion across drivers.
335 *
d574528a 336 * It is an error to call this hook before &drm_plane.state has been
43968d7b
DV
337 * initialized correctly.
338 *
339 * NOTE:
340 *
341 * If the duplicate state references refcounted resources this hook must
342 * acquire a reference for each of them. The driver must release these
343 * references again in @atomic_destroy_state.
344 *
345 * RETURNS:
346 *
347 * Duplicated atomic state or NULL when the allocation failed.
348 */
349 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
350
351 /**
352 * @atomic_destroy_state:
353 *
354 * Destroy a state duplicated with @atomic_duplicate_state and release
355 * or unreference all resources it references
ba1f665f
HM
356 *
357 * This callback is mandatory for atomic drivers.
43968d7b
DV
358 */
359 void (*atomic_destroy_state)(struct drm_plane *plane,
360 struct drm_plane_state *state);
361
362 /**
363 * @atomic_set_property:
364 *
365 * Decode a driver-private property value and store the decoded value
366 * into the passed-in state structure. Since the atomic core decodes all
367 * standardized properties (even for extensions beyond the core set of
368 * properties which might not be implemented by all drivers) this
369 * requires drivers to subclass the state structure.
370 *
371 * Such driver-private properties should really only be implemented for
372 * truly hardware/vendor specific state. Instead it is preferred to
373 * standardize atomic extension and decode the properties used to expose
374 * such an extension in the core.
375 *
376 * Do not call this function directly, use
377 * drm_atomic_plane_set_property() instead.
378 *
379 * This callback is optional if the driver does not support any
380 * driver-private atomic properties.
381 *
382 * NOTE:
383 *
384 * This function is called in the state assembly phase of atomic
385 * modesets, which can be aborted for any reason (including on
386 * userspace's request to just check whether a configuration would be
387 * possible). Drivers MUST NOT touch any persistent state (hardware or
388 * software) or data structures except the passed in @state parameter.
389 *
390 * Also since userspace controls in which order properties are set this
391 * function must not do any input validation (since the state update is
392 * incomplete and hence likely inconsistent). Instead any such input
393 * validation must be done in the various atomic_check callbacks.
394 *
395 * RETURNS:
396 *
397 * 0 if the property has been found, -EINVAL if the property isn't
398 * implemented by the driver (which shouldn't ever happen, the core only
399 * asks for properties attached to this plane). No other validation is
400 * allowed by the driver. The core already checks that the property
401 * value is within the range (integer, valid enum value, ...) the driver
402 * set when registering the property.
403 */
404 int (*atomic_set_property)(struct drm_plane *plane,
405 struct drm_plane_state *state,
406 struct drm_property *property,
407 uint64_t val);
408
409 /**
410 * @atomic_get_property:
411 *
412 * Reads out the decoded driver-private property. This is used to
413 * implement the GETPLANE IOCTL.
414 *
415 * Do not call this function directly, use
416 * drm_atomic_plane_get_property() instead.
417 *
418 * This callback is optional if the driver does not support any
419 * driver-private atomic properties.
420 *
421 * RETURNS:
422 *
423 * 0 on success, -EINVAL if the property isn't implemented by the
424 * driver (which should never happen, the core only asks for
425 * properties attached to this plane).
426 */
427 int (*atomic_get_property)(struct drm_plane *plane,
428 const struct drm_plane_state *state,
429 struct drm_property *property,
430 uint64_t *val);
431 /**
432 * @late_register:
433 *
434 * This optional hook can be used to register additional userspace
435 * interfaces attached to the plane like debugfs interfaces.
436 * It is called late in the driver load sequence from drm_dev_register().
437 * Everything added from this callback should be unregistered in
438 * the early_unregister callback.
439 *
440 * Returns:
441 *
442 * 0 on success, or a negative error code on failure.
443 */
444 int (*late_register)(struct drm_plane *plane);
445
446 /**
447 * @early_unregister:
448 *
449 * This optional hook should be used to unregister the additional
450 * userspace interfaces attached to the plane from
559bdaf7 451 * @late_register. It is called from drm_dev_unregister(),
43968d7b
DV
452 * early in the driver unload sequence to disable userspace access
453 * before data structures are torndown.
454 */
455 void (*early_unregister)(struct drm_plane *plane);
fceffb32
RC
456
457 /**
458 * @atomic_print_state:
459 *
ea0dd85a 460 * If driver subclasses &struct drm_plane_state, it should implement
fceffb32
RC
461 * this optional hook for printing additional driver specific state.
462 *
463 * Do not call this directly, use drm_atomic_plane_print_state()
464 * instead.
465 */
466 void (*atomic_print_state)(struct drm_printer *p,
467 const struct drm_plane_state *state);
e6fc3b68
BW
468
469 /**
470 * @format_mod_supported:
471 *
472 * This optional hook is used for the DRM to determine if the given
473 * format/modifier combination is valid for the plane. This allows the
474 * DRM to generate the correct format bitmask (which formats apply to
8fb756df
EA
475 * which modifier), and to valdiate modifiers at atomic_check time.
476 *
477 * If not present, then any modifier in the plane's modifier
478 * list is allowed with any of the plane's formats.
e6fc3b68
BW
479 *
480 * Returns:
481 *
482 * True if the given modifier is valid for that format on the plane.
483 * False otherwise.
484 */
485 bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
486 uint64_t modifier);
43968d7b
DV
487};
488
532b3671
DV
489/**
490 * enum drm_plane_type - uapi plane type enumeration
491 *
492 * For historical reasons not all planes are made the same. This enumeration is
493 * used to tell the different types of planes apart to implement the different
494 * uapi semantics for them. For userspace which is universal plane aware and
495 * which is using that atomic IOCTL there's no difference between these planes
496 * (beyong what the driver and hardware can support of course).
497 *
498 * For compatibility with legacy userspace, only overlay planes are made
499 * available to userspace by default. Userspace clients may set the
500 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
501 * wish to receive a universal plane list containing all plane types. See also
502 * drm_for_each_legacy_plane().
226714dc
DV
503 *
504 * WARNING: The values of this enum is UABI since they're exposed in the "type"
505 * property.
532b3671 506 */
43968d7b 507enum drm_plane_type {
226714dc
DV
508 /**
509 * @DRM_PLANE_TYPE_OVERLAY:
510 *
511 * Overlay planes represent all non-primary, non-cursor planes. Some
512 * drivers refer to these types of planes as "sprites" internally.
513 */
514 DRM_PLANE_TYPE_OVERLAY,
515
532b3671
DV
516 /**
517 * @DRM_PLANE_TYPE_PRIMARY:
518 *
519 * Primary planes represent a "main" plane for a CRTC. Primary planes
520 * are the planes operated upon by CRTC modesetting and flipping
d574528a
DV
521 * operations described in the &drm_crtc_funcs.page_flip and
522 * &drm_crtc_funcs.set_config hooks.
532b3671 523 */
43968d7b 524 DRM_PLANE_TYPE_PRIMARY,
532b3671
DV
525
526 /**
527 * @DRM_PLANE_TYPE_CURSOR:
528 *
529 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
530 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
531 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
532 */
43968d7b
DV
533 DRM_PLANE_TYPE_CURSOR,
534};
535
536
537/**
538 * struct drm_plane - central DRM plane control structure
268bc24e
DV
539 *
540 * Planes represent the scanout hardware of a display block. They receive their
541 * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
542 * the color conversion, see `Plane Composition Properties`_ for more details,
543 * and are also involved in the color conversion of input pixels, see `Color
544 * Management Properties`_ for details on that.
43968d7b
DV
545 */
546struct drm_plane {
268bc24e 547 /** @dev: DRM device this plane belongs to */
43968d7b 548 struct drm_device *dev;
268bc24e
DV
549
550 /**
551 * @head:
552 *
553 * List of all planes on @dev, linked from &drm_mode_config.plane_list.
554 * Invariant over the lifetime of @dev and therefore does not need
555 * locking.
556 */
43968d7b
DV
557 struct list_head head;
558
268bc24e 559 /** @name: human readable name, can be overwritten by the driver */
43968d7b
DV
560 char *name;
561
562 /**
563 * @mutex:
564 *
d574528a
DV
565 * Protects modeset plane state, together with the &drm_crtc.mutex of
566 * CRTC this plane is linked to (when active, getting activated or
567 * getting disabled).
c9e42b72
DV
568 *
569 * For atomic drivers specifically this protects @state.
43968d7b
DV
570 */
571 struct drm_modeset_lock mutex;
572
268bc24e 573 /** @base: base mode object */
43968d7b
DV
574 struct drm_mode_object base;
575
268bc24e
DV
576 /**
577 * @possible_crtcs: pipes this plane can be bound to constructed from
578 * drm_crtc_mask()
579 */
43968d7b 580 uint32_t possible_crtcs;
268bc24e 581 /** @format_types: array of formats supported by this plane */
43968d7b 582 uint32_t *format_types;
268bc24e 583 /** @format_count: Size of the array pointed at by @format_types. */
43968d7b 584 unsigned int format_count;
268bc24e
DV
585 /**
586 * @format_default: driver hasn't supplied supported formats for the
587 * plane. Used by the drm_plane_init compatibility wrapper only.
588 */
43968d7b
DV
589 bool format_default;
590
268bc24e 591 /** @modifiers: array of modifiers supported by this plane */
e6fc3b68 592 uint64_t *modifiers;
268bc24e 593 /** @modifier_count: Size of the array pointed at by @modifier_count. */
e6fc3b68
BW
594 unsigned int modifier_count;
595
2e2b96ef 596 /**
268bc24e
DV
597 * @crtc:
598 *
599 * Currently bound CRTC, only meaningful for non-atomic drivers. For
600 * atomic drivers this is forced to be NULL, atomic drivers should
601 * instead check &drm_plane_state.crtc.
2e2b96ef 602 */
43968d7b 603 struct drm_crtc *crtc;
2e2b96ef
DV
604
605 /**
268bc24e
DV
606 * @fb:
607 *
608 * Currently bound framebuffer, only meaningful for non-atomic drivers.
609 * For atomic drivers this is forced to be NULL, atomic drivers should
610 * instead check &drm_plane_state.fb.
2e2b96ef 611 */
43968d7b
DV
612 struct drm_framebuffer *fb;
613
268bc24e
DV
614 /**
615 * @old_fb:
616 *
617 * Temporary tracking of the old fb while a modeset is ongoing. Only
618 * used by non-atomic drivers, forced to be NULL for atomic drivers.
619 */
43968d7b
DV
620 struct drm_framebuffer *old_fb;
621
268bc24e 622 /** @funcs: plane control functions */
43968d7b
DV
623 const struct drm_plane_funcs *funcs;
624
268bc24e 625 /** @properties: property tracking for this plane */
43968d7b
DV
626 struct drm_object_properties properties;
627
268bc24e 628 /** @type: Type of plane, see &enum drm_plane_type for details. */
43968d7b
DV
629 enum drm_plane_type type;
630
631 /**
632 * @index: Position inside the mode_config.list, can be used as an array
633 * index. It is invariant over the lifetime of the plane.
634 */
635 unsigned index;
636
268bc24e 637 /** @helper_private: mid-layer private data */
43968d7b
DV
638 const struct drm_plane_helper_funcs *helper_private;
639
c9e42b72
DV
640 /**
641 * @state:
642 *
643 * Current atomic state for this plane.
644 *
645 * This is protected by @mutex. Note that nonblocking atomic commits
646 * access the current plane state without taking locks. Either by going
647 * through the &struct drm_atomic_state pointers, see
77ac3b00
ML
648 * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
649 * for_each_new_plane_in_state(). Or through careful ordering of atomic
650 * commit operations as implemented in the atomic helpers, see
651 * &struct drm_crtc_commit.
c9e42b72 652 */
43968d7b
DV
653 struct drm_plane_state *state;
654
268bc24e
DV
655 /**
656 * @alpha_property:
657 * Optional alpha property for this plane. See
658 * drm_plane_create_alpha_property().
659 */
ae0e2826 660 struct drm_property *alpha_property;
268bc24e
DV
661 /**
662 * @zpos_property:
663 * Optional zpos property for this plane. See
664 * drm_plane_create_zpos_property().
665 */
43968d7b 666 struct drm_property *zpos_property;
268bc24e
DV
667 /**
668 * @rotation_property:
669 * Optional rotation property for this plane. See
670 * drm_plane_create_rotation_property().
671 */
d138dd3c 672 struct drm_property *rotation_property;
a5ec8332
LL
673 /**
674 * @blend_mode_property:
675 * Optional "pixel blend mode" enum property for this plane.
676 * Blend mode property represents the alpha blending equation selection,
677 * describing how the pixels from the current plane are composited with
678 * the background.
679 */
680 struct drm_property *blend_mode_property;
80f690e9
JS
681
682 /**
683 * @color_encoding_property:
684 *
685 * Optional "COLOR_ENCODING" enum property for specifying
686 * color encoding for non RGB formats.
687 * See drm_plane_create_color_properties().
688 */
689 struct drm_property *color_encoding_property;
690 /**
691 * @color_range_property:
692 *
693 * Optional "COLOR_RANGE" enum property for specifying
694 * color range for non RGB formats.
695 * See drm_plane_create_color_properties().
696 */
697 struct drm_property *color_range_property;
43968d7b
DV
698};
699
700#define obj_to_plane(x) container_of(x, struct drm_plane, base)
701
e6fc3b68 702__printf(9, 10)
43968d7b
DV
703int drm_universal_plane_init(struct drm_device *dev,
704 struct drm_plane *plane,
5cd57a46 705 uint32_t possible_crtcs,
43968d7b
DV
706 const struct drm_plane_funcs *funcs,
707 const uint32_t *formats,
708 unsigned int format_count,
e6fc3b68 709 const uint64_t *format_modifiers,
43968d7b
DV
710 enum drm_plane_type type,
711 const char *name, ...);
91faa047
DV
712int drm_plane_init(struct drm_device *dev,
713 struct drm_plane *plane,
714 uint32_t possible_crtcs,
715 const struct drm_plane_funcs *funcs,
716 const uint32_t *formats, unsigned int format_count,
717 bool is_primary);
718void drm_plane_cleanup(struct drm_plane *plane);
43968d7b
DV
719
720/**
721 * drm_plane_index - find the index of a registered plane
722 * @plane: plane to find index for
723 *
724 * Given a registered plane, return the index of that plane within a DRM
725 * device's list of planes.
726 */
62f77ad0 727static inline unsigned int drm_plane_index(const struct drm_plane *plane)
43968d7b
DV
728{
729 return plane->index;
730}
62f77ad0
VS
731
732/**
733 * drm_plane_mask - find the mask of a registered plane
734 * @plane: plane to find mask for
735 */
736static inline u32 drm_plane_mask(const struct drm_plane *plane)
737{
738 return 1 << drm_plane_index(plane);
739}
740
91faa047
DV
741struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
742void drm_plane_force_disable(struct drm_plane *plane);
43968d7b
DV
743
744int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
745 struct drm_property *property,
746 uint64_t value);
747
748/**
749 * drm_plane_find - find a &drm_plane
750 * @dev: DRM device
e7e62c7e 751 * @file_priv: drm file to check for lease against.
43968d7b
DV
752 * @id: plane id
753 *
754 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
755 * drm_mode_object_find().
756 */
757static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
418da172 758 struct drm_file *file_priv,
43968d7b
DV
759 uint32_t id)
760{
761 struct drm_mode_object *mo;
418da172 762 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
43968d7b
DV
763 return mo ? obj_to_plane(mo) : NULL;
764}
765
766/**
767 * drm_for_each_plane_mask - iterate over planes specified by bitmask
768 * @plane: the loop cursor
769 * @dev: the DRM device
770 * @plane_mask: bitmask of plane indices
771 *
772 * Iterate over all planes specified by bitmask.
773 */
774#define drm_for_each_plane_mask(plane, dev, plane_mask) \
775 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
62f77ad0 776 for_each_if ((plane_mask) & drm_plane_mask(plane))
43968d7b 777
532b3671
DV
778/**
779 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
780 * @plane: the loop cursor
781 * @dev: the DRM device
782 *
783 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
784 * This is useful for implementing userspace apis when userspace is not
d574528a 785 * universal plane aware. See also &enum drm_plane_type.
532b3671 786 */
43968d7b
DV
787#define drm_for_each_legacy_plane(plane, dev) \
788 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
789 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
790
532b3671
DV
791/**
792 * drm_for_each_plane - iterate over all planes
793 * @plane: the loop cursor
794 * @dev: the DRM device
795 *
796 * Iterate over all planes of @dev, include primary and cursor planes.
797 */
43968d7b
DV
798#define drm_for_each_plane(plane, dev) \
799 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
800
e7afb623
VS
801bool drm_any_plane_has_format(struct drm_device *dev,
802 u32 format, u64 modifier);
43968d7b
DV
803
804#endif