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