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