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