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