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