xref: /openbmc/linux/include/drm/drm_plane.h (revision 7d7ae873b5e0f46d19e5dc818d1a7809e4b7cc81)
143968d7bSDaniel Vetter /*
243968d7bSDaniel Vetter  * Copyright (c) 2016 Intel Corporation
343968d7bSDaniel Vetter  *
443968d7bSDaniel Vetter  * Permission to use, copy, modify, distribute, and sell this software and its
543968d7bSDaniel Vetter  * documentation for any purpose is hereby granted without fee, provided that
643968d7bSDaniel Vetter  * the above copyright notice appear in all copies and that both that copyright
743968d7bSDaniel Vetter  * notice and this permission notice appear in supporting documentation, and
843968d7bSDaniel Vetter  * that the name of the copyright holders not be used in advertising or
943968d7bSDaniel Vetter  * publicity pertaining to distribution of the software without specific,
1043968d7bSDaniel Vetter  * written prior permission.  The copyright holders make no representations
1143968d7bSDaniel Vetter  * about the suitability of this software for any purpose.  It is provided "as
1243968d7bSDaniel Vetter  * is" without express or implied warranty.
1343968d7bSDaniel Vetter  *
1443968d7bSDaniel Vetter  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1543968d7bSDaniel Vetter  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1643968d7bSDaniel Vetter  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1743968d7bSDaniel Vetter  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1843968d7bSDaniel Vetter  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1943968d7bSDaniel Vetter  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2043968d7bSDaniel Vetter  * OF THIS SOFTWARE.
2143968d7bSDaniel Vetter  */
2243968d7bSDaniel Vetter 
2343968d7bSDaniel Vetter #ifndef __DRM_PLANE_H__
2443968d7bSDaniel Vetter #define __DRM_PLANE_H__
2543968d7bSDaniel Vetter 
2643968d7bSDaniel Vetter #include <linux/list.h>
2743968d7bSDaniel Vetter #include <linux/ctype.h>
2843968d7bSDaniel Vetter #include <drm/drm_mode_object.h>
2980f690e9SJyri Sarha #include <drm/drm_color_mgmt.h>
30b88ac005SDaniel Vetter #include <drm/drm_rect.h>
31b88ac005SDaniel Vetter #include <drm/drm_modeset_lock.h>
32d78aa650SDaniel Vetter #include <drm/drm_util.h>
3343968d7bSDaniel Vetter 
3443968d7bSDaniel Vetter struct drm_crtc;
35fceffb32SRob Clark struct drm_printer;
3634a2ab5eSDaniel Vetter struct drm_modeset_acquire_ctx;
3743968d7bSDaniel Vetter 
385c759edaSPankaj Bharadiya enum drm_scaling_filter {
395c759edaSPankaj Bharadiya 	DRM_SCALING_FILTER_DEFAULT,
405c759edaSPankaj Bharadiya 	DRM_SCALING_FILTER_NEAREST_NEIGHBOR,
415c759edaSPankaj Bharadiya };
425c759edaSPankaj Bharadiya 
4343968d7bSDaniel Vetter /**
4443968d7bSDaniel Vetter  * struct drm_plane_state - mutable plane state
452e784a91SDaniel Vetter  *
464087d2fbSAlyssa Rosenzweig  * Please note that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
472e784a91SDaniel Vetter  * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
482e784a91SDaniel Vetter  * raw coordinates provided by userspace. Drivers should use
492e784a91SDaniel Vetter  * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
502e784a91SDaniel Vetter  * @src and @dst to program the hardware.
5143968d7bSDaniel Vetter  */
5243968d7bSDaniel Vetter struct drm_plane_state {
532e784a91SDaniel Vetter 	/** @plane: backpointer to the plane */
5443968d7bSDaniel Vetter 	struct drm_plane *plane;
5543968d7bSDaniel Vetter 
563835b46eSGustavo Padovan 	/**
573835b46eSGustavo Padovan 	 * @crtc:
583835b46eSGustavo Padovan 	 *
59dd9d7c18SSui Jingfeng 	 * Currently bound CRTC, NULL if disabled. Do not write this directly,
603835b46eSGustavo Padovan 	 * use drm_atomic_set_crtc_for_plane()
613835b46eSGustavo Padovan 	 */
623835b46eSGustavo Padovan 	struct drm_crtc *crtc;
6343968d7bSDaniel Vetter 
643835b46eSGustavo Padovan 	/**
653835b46eSGustavo Padovan 	 * @fb:
663835b46eSGustavo Padovan 	 *
673835b46eSGustavo Padovan 	 * Currently bound framebuffer. Do not write this directly, use
683835b46eSGustavo Padovan 	 * drm_atomic_set_fb_for_plane()
693835b46eSGustavo Padovan 	 */
703835b46eSGustavo Padovan 	struct drm_framebuffer *fb;
713835b46eSGustavo Padovan 
723835b46eSGustavo Padovan 	/**
733835b46eSGustavo Padovan 	 * @fence:
743835b46eSGustavo Padovan 	 *
7530d23f22SDaniel Vetter 	 * Optional fence to wait for before scanning out @fb. The core atomic
7630d23f22SDaniel Vetter 	 * code will set this when userspace is using explicit fencing. Do not
771ea28bc5SChristian König 	 * write this field directly for a driver's implicit fence.
7830d23f22SDaniel Vetter 	 *
7930d23f22SDaniel Vetter 	 * Drivers should store any implicit fence in this from their
8000b5497dSThomas Zimmermann 	 * &drm_plane_helper_funcs.prepare_fb callback. See
8100b5497dSThomas Zimmermann 	 * drm_gem_plane_helper_prepare_fb() for a suitable helper.
823835b46eSGustavo Padovan 	 */
8343968d7bSDaniel Vetter 	struct dma_fence *fence;
8443968d7bSDaniel Vetter 
853835b46eSGustavo Padovan 	/**
863835b46eSGustavo Padovan 	 * @crtc_x:
873835b46eSGustavo Padovan 	 *
883835b46eSGustavo Padovan 	 * Left position of visible portion of plane on crtc, signed dest
893835b46eSGustavo Padovan 	 * location allows it to be partially off screen.
903835b46eSGustavo Padovan 	 */
913835b46eSGustavo Padovan 
923835b46eSGustavo Padovan 	int32_t crtc_x;
933835b46eSGustavo Padovan 	/**
943835b46eSGustavo Padovan 	 * @crtc_y:
953835b46eSGustavo Padovan 	 *
963835b46eSGustavo Padovan 	 * Upper position of visible portion of plane on crtc, signed dest
973835b46eSGustavo Padovan 	 * location allows it to be partially off screen.
983835b46eSGustavo Padovan 	 */
993835b46eSGustavo Padovan 	int32_t crtc_y;
1003835b46eSGustavo Padovan 
1012e784a91SDaniel Vetter 	/** @crtc_w: width of visible portion of plane on crtc */
1022e784a91SDaniel Vetter 	/** @crtc_h: height of visible portion of plane on crtc */
10343968d7bSDaniel Vetter 	uint32_t crtc_w, crtc_h;
10443968d7bSDaniel Vetter 
1052e784a91SDaniel Vetter 	/**
1062e784a91SDaniel Vetter 	 * @src_x: left position of visible portion of plane within plane (in
1072e784a91SDaniel Vetter 	 * 16.16 fixed point).
1082e784a91SDaniel Vetter 	 */
1092e784a91SDaniel Vetter 	uint32_t src_x;
1102e784a91SDaniel Vetter 	/**
1112e784a91SDaniel Vetter 	 * @src_y: upper position of visible portion of plane within plane (in
1122e784a91SDaniel Vetter 	 * 16.16 fixed point).
1132e784a91SDaniel Vetter 	 */
1142e784a91SDaniel Vetter 	uint32_t src_y;
1152e784a91SDaniel Vetter 	/** @src_w: width of visible portion of plane (in 16.16) */
1162e784a91SDaniel Vetter 	/** @src_h: height of visible portion of plane (in 16.16) */
11743968d7bSDaniel Vetter 	uint32_t src_h, src_w;
11843968d7bSDaniel Vetter 
1192e784a91SDaniel Vetter 	/**
1202e784a91SDaniel Vetter 	 * @alpha:
1212e784a91SDaniel Vetter 	 * Opacity of the plane with 0 as completely transparent and 0xffff as
1222e784a91SDaniel Vetter 	 * completely opaque. See drm_plane_create_alpha_property() for more
1232e784a91SDaniel Vetter 	 * details.
1242e784a91SDaniel Vetter 	 */
125ae0e2826SMaxime Ripard 	u16 alpha;
126b972ceceSSean Paul 
127b972ceceSSean Paul 	/**
128b972ceceSSean Paul 	 * @pixel_blend_mode:
129b972ceceSSean Paul 	 * The alpha blending equation selection, describing how the pixels from
130b972ceceSSean Paul 	 * the current plane are composited with the background. Value can be
131b972ceceSSean Paul 	 * one of DRM_MODE_BLEND_*
132b972ceceSSean Paul 	 */
133a5ec8332SLowry Li 	uint16_t pixel_blend_mode;
134ae0e2826SMaxime Ripard 
1352e784a91SDaniel Vetter 	/**
1362e784a91SDaniel Vetter 	 * @rotation:
1372e784a91SDaniel Vetter 	 * Rotation of the plane. See drm_plane_create_rotation_property() for
1382e784a91SDaniel Vetter 	 * more details.
1392e784a91SDaniel Vetter 	 */
14043968d7bSDaniel Vetter 	unsigned int rotation;
14143968d7bSDaniel Vetter 
1422e784a91SDaniel Vetter 	/**
1432e784a91SDaniel Vetter 	 * @zpos:
1442e784a91SDaniel Vetter 	 * Priority of the given plane on crtc (optional).
1452e784a91SDaniel Vetter 	 *
1468f6ea27bSSimon Ser 	 * User-space may set mutable zpos properties so that multiple active
1478f6ea27bSSimon Ser 	 * planes on the same CRTC have identical zpos values. This is a
1488f6ea27bSSimon Ser 	 * user-space bug, but drivers can solve the conflict by comparing the
1498f6ea27bSSimon Ser 	 * plane object IDs; the plane with a higher ID is stacked on top of a
1508f6ea27bSSimon Ser 	 * plane with a lower ID.
1512e784a91SDaniel Vetter 	 *
1522e784a91SDaniel Vetter 	 * See drm_plane_create_zpos_property() and
1532e784a91SDaniel Vetter 	 * drm_plane_create_zpos_immutable_property() for more details.
1542e784a91SDaniel Vetter 	 */
15543968d7bSDaniel Vetter 	unsigned int zpos;
1562e784a91SDaniel Vetter 
1572e784a91SDaniel Vetter 	/**
1582e784a91SDaniel Vetter 	 * @normalized_zpos:
1592e784a91SDaniel Vetter 	 * Normalized value of zpos: unique, range from 0 to N-1 where N is the
1602e784a91SDaniel Vetter 	 * number of active planes for given crtc. Note that the driver must set
1612e784a91SDaniel Vetter 	 * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
1622e784a91SDaniel Vetter 	 * update this before it can be trusted.
1632e784a91SDaniel Vetter 	 */
16443968d7bSDaniel Vetter 	unsigned int normalized_zpos;
16543968d7bSDaniel Vetter 
16680f690e9SJyri Sarha 	/**
16780f690e9SJyri Sarha 	 * @color_encoding:
16880f690e9SJyri Sarha 	 *
16980f690e9SJyri Sarha 	 * Color encoding for non RGB formats
17080f690e9SJyri Sarha 	 */
17180f690e9SJyri Sarha 	enum drm_color_encoding color_encoding;
17280f690e9SJyri Sarha 
17380f690e9SJyri Sarha 	/**
17480f690e9SJyri Sarha 	 * @color_range:
17580f690e9SJyri Sarha 	 *
17680f690e9SJyri Sarha 	 * Color range for non RGB formats
17780f690e9SJyri Sarha 	 */
17880f690e9SJyri Sarha 	enum drm_color_range color_range;
17980f690e9SJyri Sarha 
180d3b21767SLukasz Spintzyk 	/**
181d3b21767SLukasz Spintzyk 	 * @fb_damage_clips:
182d3b21767SLukasz Spintzyk 	 *
183d3b21767SLukasz Spintzyk 	 * Blob representing damage (area in plane framebuffer that changed
184d3b21767SLukasz Spintzyk 	 * since last plane update) as an array of &drm_mode_rect in framebuffer
185d3b21767SLukasz Spintzyk 	 * coodinates of the attached framebuffer. Note that unlike plane src,
186d3b21767SLukasz Spintzyk 	 * damage clips are not in 16.16 fixed point.
1876f11f374SDaniel Vetter 	 *
1886f11f374SDaniel Vetter 	 * See drm_plane_get_damage_clips() and
1896f11f374SDaniel Vetter 	 * drm_plane_get_damage_clips_count() for accessing these.
190d3b21767SLukasz Spintzyk 	 */
191d3b21767SLukasz Spintzyk 	struct drm_property_blob *fb_damage_clips;
192d3b21767SLukasz Spintzyk 
193fec74874SMaarten Lankhorst 	/**
194*45aafb50SJavier Martinez Canillas 	 * @ignore_damage_clips:
195*45aafb50SJavier Martinez Canillas 	 *
196*45aafb50SJavier Martinez Canillas 	 * Set by drivers to indicate the drm_atomic_helper_damage_iter_init()
197*45aafb50SJavier Martinez Canillas 	 * helper that the @fb_damage_clips blob property should be ignored.
198*45aafb50SJavier Martinez Canillas 	 *
199*45aafb50SJavier Martinez Canillas 	 * See :ref:`damage_tracking_properties` for more information.
200*45aafb50SJavier Martinez Canillas 	 */
201*45aafb50SJavier Martinez Canillas 	bool ignore_damage_clips;
202*45aafb50SJavier Martinez Canillas 
203*45aafb50SJavier Martinez Canillas 	/**
204fec74874SMaarten Lankhorst 	 * @src:
205fec74874SMaarten Lankhorst 	 *
206fec74874SMaarten Lankhorst 	 * source coordinates of the plane (in 16.16).
207fec74874SMaarten Lankhorst 	 *
208fec74874SMaarten Lankhorst 	 * When using drm_atomic_helper_check_plane_state(),
209fec74874SMaarten Lankhorst 	 * the coordinates are clipped, but the driver may choose
210fec74874SMaarten Lankhorst 	 * to use unclipped coordinates instead when the hardware
211fec74874SMaarten Lankhorst 	 * performs the clipping automatically.
212fec74874SMaarten Lankhorst 	 */
213fec74874SMaarten Lankhorst 	/**
214fec74874SMaarten Lankhorst 	 * @dst:
215fec74874SMaarten Lankhorst 	 *
216fec74874SMaarten Lankhorst 	 * clipped destination coordinates of the plane.
217fec74874SMaarten Lankhorst 	 *
218fec74874SMaarten Lankhorst 	 * When using drm_atomic_helper_check_plane_state(),
219fec74874SMaarten Lankhorst 	 * the coordinates are clipped, but the driver may choose
220fec74874SMaarten Lankhorst 	 * to use unclipped coordinates instead when the hardware
221fec74874SMaarten Lankhorst 	 * performs the clipping automatically.
222fec74874SMaarten Lankhorst 	 */
22343968d7bSDaniel Vetter 	struct drm_rect src, dst;
22443968d7bSDaniel Vetter 
2253835b46eSGustavo Padovan 	/**
2263835b46eSGustavo Padovan 	 * @visible:
2273835b46eSGustavo Padovan 	 *
2283835b46eSGustavo Padovan 	 * Visibility of the plane. This can be false even if fb!=NULL and
2293835b46eSGustavo Padovan 	 * crtc!=NULL, due to clipping.
23043968d7bSDaniel Vetter 	 */
23143968d7bSDaniel Vetter 	bool visible;
23243968d7bSDaniel Vetter 
23321a01abbSMaarten Lankhorst 	/**
2345c759edaSPankaj Bharadiya 	 * @scaling_filter:
2355c759edaSPankaj Bharadiya 	 *
2365c759edaSPankaj Bharadiya 	 * Scaling filter to be applied
2375c759edaSPankaj Bharadiya 	 */
2385c759edaSPankaj Bharadiya 	enum drm_scaling_filter scaling_filter;
2395c759edaSPankaj Bharadiya 
2405c759edaSPankaj Bharadiya 	/**
241669c9215SMaarten Lankhorst 	 * @commit: Tracks the pending commit to prevent use-after-free conditions,
242669c9215SMaarten Lankhorst 	 * and for async plane updates.
24321a01abbSMaarten Lankhorst 	 *
244669c9215SMaarten Lankhorst 	 * May be NULL.
24521a01abbSMaarten Lankhorst 	 */
24621a01abbSMaarten Lankhorst 	struct drm_crtc_commit *commit;
24721a01abbSMaarten Lankhorst 
2482e784a91SDaniel Vetter 	/** @state: backpointer to global drm_atomic_state */
24943968d7bSDaniel Vetter 	struct drm_atomic_state *state;
25043968d7bSDaniel Vetter };
25143968d7bSDaniel Vetter 
2521638d30cSRob Clark static inline struct drm_rect
drm_plane_state_src(const struct drm_plane_state * state)2531638d30cSRob Clark drm_plane_state_src(const struct drm_plane_state *state)
2541638d30cSRob Clark {
2551638d30cSRob Clark 	struct drm_rect src = {
2561638d30cSRob Clark 		.x1 = state->src_x,
2571638d30cSRob Clark 		.y1 = state->src_y,
2581638d30cSRob Clark 		.x2 = state->src_x + state->src_w,
2591638d30cSRob Clark 		.y2 = state->src_y + state->src_h,
2601638d30cSRob Clark 	};
2611638d30cSRob Clark 	return src;
2621638d30cSRob Clark }
2631638d30cSRob Clark 
2641638d30cSRob Clark static inline struct drm_rect
drm_plane_state_dest(const struct drm_plane_state * state)2651638d30cSRob Clark drm_plane_state_dest(const struct drm_plane_state *state)
2661638d30cSRob Clark {
2671638d30cSRob Clark 	struct drm_rect dest = {
2681638d30cSRob Clark 		.x1 = state->crtc_x,
2691638d30cSRob Clark 		.y1 = state->crtc_y,
2701638d30cSRob Clark 		.x2 = state->crtc_x + state->crtc_w,
2711638d30cSRob Clark 		.y2 = state->crtc_y + state->crtc_h,
2721638d30cSRob Clark 	};
2731638d30cSRob Clark 	return dest;
2741638d30cSRob Clark }
2751638d30cSRob Clark 
27643968d7bSDaniel Vetter /**
27743968d7bSDaniel Vetter  * struct drm_plane_funcs - driver plane control functions
27843968d7bSDaniel Vetter  */
27943968d7bSDaniel Vetter struct drm_plane_funcs {
28043968d7bSDaniel Vetter 	/**
28143968d7bSDaniel Vetter 	 * @update_plane:
28243968d7bSDaniel Vetter 	 *
28343968d7bSDaniel Vetter 	 * This is the legacy entry point to enable and configure the plane for
28443968d7bSDaniel Vetter 	 * the given CRTC and framebuffer. It is never called to disable the
28543968d7bSDaniel Vetter 	 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
28643968d7bSDaniel Vetter 	 *
28743968d7bSDaniel Vetter 	 * The source rectangle in frame buffer memory coordinates is given by
28843968d7bSDaniel Vetter 	 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
28943968d7bSDaniel Vetter 	 * values). Devices that don't support subpixel plane coordinates can
29043968d7bSDaniel Vetter 	 * ignore the fractional part.
29143968d7bSDaniel Vetter 	 *
29243968d7bSDaniel Vetter 	 * The destination rectangle in CRTC coordinates is given by the
29343968d7bSDaniel Vetter 	 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
29443968d7bSDaniel Vetter 	 * Devices scale the source rectangle to the destination rectangle. If
29543968d7bSDaniel Vetter 	 * scaling is not supported, and the source rectangle size doesn't match
29643968d7bSDaniel Vetter 	 * the destination rectangle size, the driver must return a
29743968d7bSDaniel Vetter 	 * -<errorname>EINVAL</errorname> error.
29843968d7bSDaniel Vetter 	 *
29943968d7bSDaniel Vetter 	 * Drivers implementing atomic modeset should use
30043968d7bSDaniel Vetter 	 * drm_atomic_helper_update_plane() to implement this hook.
30143968d7bSDaniel Vetter 	 *
30243968d7bSDaniel Vetter 	 * RETURNS:
30343968d7bSDaniel Vetter 	 *
30443968d7bSDaniel Vetter 	 * 0 on success or a negative error code on failure.
30543968d7bSDaniel Vetter 	 */
30643968d7bSDaniel Vetter 	int (*update_plane)(struct drm_plane *plane,
30743968d7bSDaniel Vetter 			    struct drm_crtc *crtc, struct drm_framebuffer *fb,
30843968d7bSDaniel Vetter 			    int crtc_x, int crtc_y,
30943968d7bSDaniel Vetter 			    unsigned int crtc_w, unsigned int crtc_h,
31043968d7bSDaniel Vetter 			    uint32_t src_x, uint32_t src_y,
31134a2ab5eSDaniel Vetter 			    uint32_t src_w, uint32_t src_h,
31234a2ab5eSDaniel Vetter 			    struct drm_modeset_acquire_ctx *ctx);
31343968d7bSDaniel Vetter 
31443968d7bSDaniel Vetter 	/**
31543968d7bSDaniel Vetter 	 * @disable_plane:
31643968d7bSDaniel Vetter 	 *
31743968d7bSDaniel Vetter 	 * This is the legacy entry point to disable the plane. The DRM core
31843968d7bSDaniel Vetter 	 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
31943968d7bSDaniel Vetter 	 * with the frame buffer ID set to 0.  Disabled planes must not be
32043968d7bSDaniel Vetter 	 * processed by the CRTC.
32143968d7bSDaniel Vetter 	 *
32243968d7bSDaniel Vetter 	 * Drivers implementing atomic modeset should use
32343968d7bSDaniel Vetter 	 * drm_atomic_helper_disable_plane() to implement this hook.
32443968d7bSDaniel Vetter 	 *
32543968d7bSDaniel Vetter 	 * RETURNS:
32643968d7bSDaniel Vetter 	 *
32743968d7bSDaniel Vetter 	 * 0 on success or a negative error code on failure.
32843968d7bSDaniel Vetter 	 */
32919315294SDaniel Vetter 	int (*disable_plane)(struct drm_plane *plane,
33019315294SDaniel Vetter 			     struct drm_modeset_acquire_ctx *ctx);
33143968d7bSDaniel Vetter 
33243968d7bSDaniel Vetter 	/**
33343968d7bSDaniel Vetter 	 * @destroy:
33443968d7bSDaniel Vetter 	 *
33543968d7bSDaniel Vetter 	 * Clean up plane resources. This is only called at driver unload time
33643968d7bSDaniel Vetter 	 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
33743968d7bSDaniel Vetter 	 * in DRM.
33843968d7bSDaniel Vetter 	 */
33943968d7bSDaniel Vetter 	void (*destroy)(struct drm_plane *plane);
34043968d7bSDaniel Vetter 
34143968d7bSDaniel Vetter 	/**
34243968d7bSDaniel Vetter 	 * @reset:
34343968d7bSDaniel Vetter 	 *
34443968d7bSDaniel Vetter 	 * Reset plane hardware and software state to off. This function isn't
34543968d7bSDaniel Vetter 	 * called by the core directly, only through drm_mode_config_reset().
34643968d7bSDaniel Vetter 	 * It's not a helper hook only for historical reasons.
34743968d7bSDaniel Vetter 	 *
34843968d7bSDaniel Vetter 	 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
34943968d7bSDaniel Vetter 	 * atomic state using this hook.
35043968d7bSDaniel Vetter 	 */
35143968d7bSDaniel Vetter 	void (*reset)(struct drm_plane *plane);
35243968d7bSDaniel Vetter 
35343968d7bSDaniel Vetter 	/**
35443968d7bSDaniel Vetter 	 * @set_property:
35543968d7bSDaniel Vetter 	 *
35643968d7bSDaniel Vetter 	 * This is the legacy entry point to update a property attached to the
35743968d7bSDaniel Vetter 	 * plane.
35843968d7bSDaniel Vetter 	 *
35943968d7bSDaniel Vetter 	 * This callback is optional if the driver does not support any legacy
360144a7999SDaniel Vetter 	 * driver-private properties. For atomic drivers it is not used because
361144a7999SDaniel Vetter 	 * property handling is done entirely in the DRM core.
36243968d7bSDaniel Vetter 	 *
36343968d7bSDaniel Vetter 	 * RETURNS:
36443968d7bSDaniel Vetter 	 *
36543968d7bSDaniel Vetter 	 * 0 on success or a negative error code on failure.
36643968d7bSDaniel Vetter 	 */
36743968d7bSDaniel Vetter 	int (*set_property)(struct drm_plane *plane,
36843968d7bSDaniel Vetter 			    struct drm_property *property, uint64_t val);
36943968d7bSDaniel Vetter 
37043968d7bSDaniel Vetter 	/**
37143968d7bSDaniel Vetter 	 * @atomic_duplicate_state:
37243968d7bSDaniel Vetter 	 *
37343968d7bSDaniel Vetter 	 * Duplicate the current atomic state for this plane and return it.
374d574528aSDaniel Vetter 	 * The core and helpers guarantee that any atomic state duplicated with
37543968d7bSDaniel Vetter 	 * this hook and still owned by the caller (i.e. not transferred to the
376d574528aSDaniel Vetter 	 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
377d574528aSDaniel Vetter 	 * cleaned up by calling the @atomic_destroy_state hook in this
378d574528aSDaniel Vetter 	 * structure.
37943968d7bSDaniel Vetter 	 *
380ba1f665fSHaneen Mohammed 	 * This callback is mandatory for atomic drivers.
381ba1f665fSHaneen Mohammed 	 *
382ea0dd85aSDaniel Vetter 	 * Atomic drivers which don't subclass &struct drm_plane_state should use
38343968d7bSDaniel Vetter 	 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
38443968d7bSDaniel Vetter 	 * state structure to extend it with driver-private state should use
38543968d7bSDaniel Vetter 	 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
38643968d7bSDaniel Vetter 	 * duplicated in a consistent fashion across drivers.
38743968d7bSDaniel Vetter 	 *
388d574528aSDaniel Vetter 	 * It is an error to call this hook before &drm_plane.state has been
38943968d7bSDaniel Vetter 	 * initialized correctly.
39043968d7bSDaniel Vetter 	 *
39143968d7bSDaniel Vetter 	 * NOTE:
39243968d7bSDaniel Vetter 	 *
39343968d7bSDaniel Vetter 	 * If the duplicate state references refcounted resources this hook must
39443968d7bSDaniel Vetter 	 * acquire a reference for each of them. The driver must release these
39543968d7bSDaniel Vetter 	 * references again in @atomic_destroy_state.
39643968d7bSDaniel Vetter 	 *
39743968d7bSDaniel Vetter 	 * RETURNS:
39843968d7bSDaniel Vetter 	 *
39943968d7bSDaniel Vetter 	 * Duplicated atomic state or NULL when the allocation failed.
40043968d7bSDaniel Vetter 	 */
40143968d7bSDaniel Vetter 	struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
40243968d7bSDaniel Vetter 
40343968d7bSDaniel Vetter 	/**
40443968d7bSDaniel Vetter 	 * @atomic_destroy_state:
40543968d7bSDaniel Vetter 	 *
40643968d7bSDaniel Vetter 	 * Destroy a state duplicated with @atomic_duplicate_state and release
40743968d7bSDaniel Vetter 	 * or unreference all resources it references
408ba1f665fSHaneen Mohammed 	 *
409ba1f665fSHaneen Mohammed 	 * This callback is mandatory for atomic drivers.
41043968d7bSDaniel Vetter 	 */
41143968d7bSDaniel Vetter 	void (*atomic_destroy_state)(struct drm_plane *plane,
41243968d7bSDaniel Vetter 				     struct drm_plane_state *state);
41343968d7bSDaniel Vetter 
41443968d7bSDaniel Vetter 	/**
41543968d7bSDaniel Vetter 	 * @atomic_set_property:
41643968d7bSDaniel Vetter 	 *
41743968d7bSDaniel Vetter 	 * Decode a driver-private property value and store the decoded value
41843968d7bSDaniel Vetter 	 * into the passed-in state structure. Since the atomic core decodes all
41943968d7bSDaniel Vetter 	 * standardized properties (even for extensions beyond the core set of
42043968d7bSDaniel Vetter 	 * properties which might not be implemented by all drivers) this
42143968d7bSDaniel Vetter 	 * requires drivers to subclass the state structure.
42243968d7bSDaniel Vetter 	 *
42343968d7bSDaniel Vetter 	 * Such driver-private properties should really only be implemented for
42443968d7bSDaniel Vetter 	 * truly hardware/vendor specific state. Instead it is preferred to
42543968d7bSDaniel Vetter 	 * standardize atomic extension and decode the properties used to expose
42643968d7bSDaniel Vetter 	 * such an extension in the core.
42743968d7bSDaniel Vetter 	 *
42843968d7bSDaniel Vetter 	 * Do not call this function directly, use
42943968d7bSDaniel Vetter 	 * drm_atomic_plane_set_property() instead.
43043968d7bSDaniel Vetter 	 *
43143968d7bSDaniel Vetter 	 * This callback is optional if the driver does not support any
43243968d7bSDaniel Vetter 	 * driver-private atomic properties.
43343968d7bSDaniel Vetter 	 *
43443968d7bSDaniel Vetter 	 * NOTE:
43543968d7bSDaniel Vetter 	 *
43643968d7bSDaniel Vetter 	 * This function is called in the state assembly phase of atomic
43743968d7bSDaniel Vetter 	 * modesets, which can be aborted for any reason (including on
43843968d7bSDaniel Vetter 	 * userspace's request to just check whether a configuration would be
43943968d7bSDaniel Vetter 	 * possible). Drivers MUST NOT touch any persistent state (hardware or
44043968d7bSDaniel Vetter 	 * software) or data structures except the passed in @state parameter.
44143968d7bSDaniel Vetter 	 *
44243968d7bSDaniel Vetter 	 * Also since userspace controls in which order properties are set this
44343968d7bSDaniel Vetter 	 * function must not do any input validation (since the state update is
44443968d7bSDaniel Vetter 	 * incomplete and hence likely inconsistent). Instead any such input
44543968d7bSDaniel Vetter 	 * validation must be done in the various atomic_check callbacks.
44643968d7bSDaniel Vetter 	 *
44743968d7bSDaniel Vetter 	 * RETURNS:
44843968d7bSDaniel Vetter 	 *
44943968d7bSDaniel Vetter 	 * 0 if the property has been found, -EINVAL if the property isn't
45043968d7bSDaniel Vetter 	 * implemented by the driver (which shouldn't ever happen, the core only
45143968d7bSDaniel Vetter 	 * asks for properties attached to this plane). No other validation is
45243968d7bSDaniel Vetter 	 * allowed by the driver. The core already checks that the property
45343968d7bSDaniel Vetter 	 * value is within the range (integer, valid enum value, ...) the driver
45443968d7bSDaniel Vetter 	 * set when registering the property.
45543968d7bSDaniel Vetter 	 */
45643968d7bSDaniel Vetter 	int (*atomic_set_property)(struct drm_plane *plane,
45743968d7bSDaniel Vetter 				   struct drm_plane_state *state,
45843968d7bSDaniel Vetter 				   struct drm_property *property,
45943968d7bSDaniel Vetter 				   uint64_t val);
46043968d7bSDaniel Vetter 
46143968d7bSDaniel Vetter 	/**
46243968d7bSDaniel Vetter 	 * @atomic_get_property:
46343968d7bSDaniel Vetter 	 *
46443968d7bSDaniel Vetter 	 * Reads out the decoded driver-private property. This is used to
46543968d7bSDaniel Vetter 	 * implement the GETPLANE IOCTL.
46643968d7bSDaniel Vetter 	 *
46743968d7bSDaniel Vetter 	 * Do not call this function directly, use
46843968d7bSDaniel Vetter 	 * drm_atomic_plane_get_property() instead.
46943968d7bSDaniel Vetter 	 *
47043968d7bSDaniel Vetter 	 * This callback is optional if the driver does not support any
47143968d7bSDaniel Vetter 	 * driver-private atomic properties.
47243968d7bSDaniel Vetter 	 *
47343968d7bSDaniel Vetter 	 * RETURNS:
47443968d7bSDaniel Vetter 	 *
47543968d7bSDaniel Vetter 	 * 0 on success, -EINVAL if the property isn't implemented by the
47643968d7bSDaniel Vetter 	 * driver (which should never happen, the core only asks for
47743968d7bSDaniel Vetter 	 * properties attached to this plane).
47843968d7bSDaniel Vetter 	 */
47943968d7bSDaniel Vetter 	int (*atomic_get_property)(struct drm_plane *plane,
48043968d7bSDaniel Vetter 				   const struct drm_plane_state *state,
48143968d7bSDaniel Vetter 				   struct drm_property *property,
48243968d7bSDaniel Vetter 				   uint64_t *val);
48343968d7bSDaniel Vetter 	/**
48443968d7bSDaniel Vetter 	 * @late_register:
48543968d7bSDaniel Vetter 	 *
48643968d7bSDaniel Vetter 	 * This optional hook can be used to register additional userspace
48743968d7bSDaniel Vetter 	 * interfaces attached to the plane like debugfs interfaces.
48843968d7bSDaniel Vetter 	 * It is called late in the driver load sequence from drm_dev_register().
48943968d7bSDaniel Vetter 	 * Everything added from this callback should be unregistered in
49043968d7bSDaniel Vetter 	 * the early_unregister callback.
49143968d7bSDaniel Vetter 	 *
49243968d7bSDaniel Vetter 	 * Returns:
49343968d7bSDaniel Vetter 	 *
49443968d7bSDaniel Vetter 	 * 0 on success, or a negative error code on failure.
49543968d7bSDaniel Vetter 	 */
49643968d7bSDaniel Vetter 	int (*late_register)(struct drm_plane *plane);
49743968d7bSDaniel Vetter 
49843968d7bSDaniel Vetter 	/**
49943968d7bSDaniel Vetter 	 * @early_unregister:
50043968d7bSDaniel Vetter 	 *
50143968d7bSDaniel Vetter 	 * This optional hook should be used to unregister the additional
50243968d7bSDaniel Vetter 	 * userspace interfaces attached to the plane from
503559bdaf7SDaniel Vetter 	 * @late_register. It is called from drm_dev_unregister(),
50443968d7bSDaniel Vetter 	 * early in the driver unload sequence to disable userspace access
50543968d7bSDaniel Vetter 	 * before data structures are torndown.
50643968d7bSDaniel Vetter 	 */
50743968d7bSDaniel Vetter 	void (*early_unregister)(struct drm_plane *plane);
508fceffb32SRob Clark 
509fceffb32SRob Clark 	/**
510fceffb32SRob Clark 	 * @atomic_print_state:
511fceffb32SRob Clark 	 *
512ea0dd85aSDaniel Vetter 	 * If driver subclasses &struct drm_plane_state, it should implement
513fceffb32SRob Clark 	 * this optional hook for printing additional driver specific state.
514fceffb32SRob Clark 	 *
515fceffb32SRob Clark 	 * Do not call this directly, use drm_atomic_plane_print_state()
516fceffb32SRob Clark 	 * instead.
517fceffb32SRob Clark 	 */
518fceffb32SRob Clark 	void (*atomic_print_state)(struct drm_printer *p,
519fceffb32SRob Clark 				   const struct drm_plane_state *state);
520e6fc3b68SBen Widawsky 
521e6fc3b68SBen Widawsky 	/**
522e6fc3b68SBen Widawsky 	 * @format_mod_supported:
523e6fc3b68SBen Widawsky 	 *
524e6fc3b68SBen Widawsky 	 * This optional hook is used for the DRM to determine if the given
525e6fc3b68SBen Widawsky 	 * format/modifier combination is valid for the plane. This allows the
526e6fc3b68SBen Widawsky 	 * DRM to generate the correct format bitmask (which formats apply to
52791d85313SJosé Expósito 	 * which modifier), and to validate modifiers at atomic_check time.
5288fb756dfSEric Anholt 	 *
5298fb756dfSEric Anholt 	 * If not present, then any modifier in the plane's modifier
5308fb756dfSEric Anholt 	 * list is allowed with any of the plane's formats.
531e6fc3b68SBen Widawsky 	 *
532e6fc3b68SBen Widawsky 	 * Returns:
533e6fc3b68SBen Widawsky 	 *
534e6fc3b68SBen Widawsky 	 * True if the given modifier is valid for that format on the plane.
535e6fc3b68SBen Widawsky 	 * False otherwise.
536e6fc3b68SBen Widawsky 	 */
537e6fc3b68SBen Widawsky 	bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
538e6fc3b68SBen Widawsky 				     uint64_t modifier);
53943968d7bSDaniel Vetter };
54043968d7bSDaniel Vetter 
541532b3671SDaniel Vetter /**
542532b3671SDaniel Vetter  * enum drm_plane_type - uapi plane type enumeration
543532b3671SDaniel Vetter  *
544532b3671SDaniel Vetter  * For historical reasons not all planes are made the same. This enumeration is
545532b3671SDaniel Vetter  * used to tell the different types of planes apart to implement the different
546532b3671SDaniel Vetter  * uapi semantics for them. For userspace which is universal plane aware and
547532b3671SDaniel Vetter  * which is using that atomic IOCTL there's no difference between these planes
548532b3671SDaniel Vetter  * (beyong what the driver and hardware can support of course).
549532b3671SDaniel Vetter  *
550532b3671SDaniel Vetter  * For compatibility with legacy userspace, only overlay planes are made
551532b3671SDaniel Vetter  * available to userspace by default. Userspace clients may set the
5527e5d1e12SSimon Ser  * &DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
553532b3671SDaniel Vetter  * wish to receive a universal plane list containing all plane types. See also
554532b3671SDaniel Vetter  * drm_for_each_legacy_plane().
555226714dcSDaniel Vetter  *
5567e5d1e12SSimon Ser  * In addition to setting each plane's type, drivers need to setup the
5577e5d1e12SSimon Ser  * &drm_crtc.primary and optionally &drm_crtc.cursor pointers for legacy
5587e5d1e12SSimon Ser  * IOCTLs. See drm_crtc_init_with_planes().
5597e5d1e12SSimon Ser  *
560226714dcSDaniel Vetter  * WARNING: The values of this enum is UABI since they're exposed in the "type"
561226714dcSDaniel Vetter  * property.
562532b3671SDaniel Vetter  */
56343968d7bSDaniel Vetter enum drm_plane_type {
564532b3671SDaniel Vetter 	/**
565226714dcSDaniel Vetter 	 * @DRM_PLANE_TYPE_OVERLAY:
566226714dcSDaniel Vetter 	 *
567226714dcSDaniel Vetter 	 * Overlay planes represent all non-primary, non-cursor planes. Some
568226714dcSDaniel Vetter 	 * drivers refer to these types of planes as "sprites" internally.
569226714dcSDaniel Vetter 	 */
570226714dcSDaniel Vetter 	DRM_PLANE_TYPE_OVERLAY,
571226714dcSDaniel Vetter 
572226714dcSDaniel Vetter 	/**
573532b3671SDaniel Vetter 	 * @DRM_PLANE_TYPE_PRIMARY:
574532b3671SDaniel Vetter 	 *
5757e5d1e12SSimon Ser 	 * A primary plane attached to a CRTC is the most likely to be able to
5767e5d1e12SSimon Ser 	 * light up the CRTC when no scaling/cropping is used and the plane
5777e5d1e12SSimon Ser 	 * covers the whole CRTC.
578532b3671SDaniel Vetter 	 */
57943968d7bSDaniel Vetter 	DRM_PLANE_TYPE_PRIMARY,
580532b3671SDaniel Vetter 
581532b3671SDaniel Vetter 	/**
582532b3671SDaniel Vetter 	 * @DRM_PLANE_TYPE_CURSOR:
583532b3671SDaniel Vetter 	 *
5847e5d1e12SSimon Ser 	 * A cursor plane attached to a CRTC is more likely to be able to be
5857e5d1e12SSimon Ser 	 * enabled when no scaling/cropping is used and the framebuffer has the
5867e5d1e12SSimon Ser 	 * size indicated by &drm_mode_config.cursor_width and
5877e5d1e12SSimon Ser 	 * &drm_mode_config.cursor_height. Additionally, if the driver doesn't
5887e5d1e12SSimon Ser 	 * support modifiers, the framebuffer should have a linear layout.
589532b3671SDaniel Vetter 	 */
59043968d7bSDaniel Vetter 	DRM_PLANE_TYPE_CURSOR,
59143968d7bSDaniel Vetter };
59243968d7bSDaniel Vetter 
59343968d7bSDaniel Vetter 
59443968d7bSDaniel Vetter /**
59543968d7bSDaniel Vetter  * struct drm_plane - central DRM plane control structure
596268bc24eSDaniel Vetter  *
597268bc24eSDaniel Vetter  * Planes represent the scanout hardware of a display block. They receive their
598268bc24eSDaniel Vetter  * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
599268bc24eSDaniel Vetter  * the color conversion, see `Plane Composition Properties`_ for more details,
600268bc24eSDaniel Vetter  * and are also involved in the color conversion of input pixels, see `Color
601268bc24eSDaniel Vetter  * Management Properties`_ for details on that.
60243968d7bSDaniel Vetter  */
60343968d7bSDaniel Vetter struct drm_plane {
604268bc24eSDaniel Vetter 	/** @dev: DRM device this plane belongs to */
60543968d7bSDaniel Vetter 	struct drm_device *dev;
606268bc24eSDaniel Vetter 
607268bc24eSDaniel Vetter 	/**
608268bc24eSDaniel Vetter 	 * @head:
609268bc24eSDaniel Vetter 	 *
610268bc24eSDaniel Vetter 	 * List of all planes on @dev, linked from &drm_mode_config.plane_list.
611268bc24eSDaniel Vetter 	 * Invariant over the lifetime of @dev and therefore does not need
612268bc24eSDaniel Vetter 	 * locking.
613268bc24eSDaniel Vetter 	 */
61443968d7bSDaniel Vetter 	struct list_head head;
61543968d7bSDaniel Vetter 
616268bc24eSDaniel Vetter 	/** @name: human readable name, can be overwritten by the driver */
61743968d7bSDaniel Vetter 	char *name;
61843968d7bSDaniel Vetter 
61943968d7bSDaniel Vetter 	/**
62043968d7bSDaniel Vetter 	 * @mutex:
62143968d7bSDaniel Vetter 	 *
622d574528aSDaniel Vetter 	 * Protects modeset plane state, together with the &drm_crtc.mutex of
623d574528aSDaniel Vetter 	 * CRTC this plane is linked to (when active, getting activated or
624d574528aSDaniel Vetter 	 * getting disabled).
625c9e42b72SDaniel Vetter 	 *
626c9e42b72SDaniel Vetter 	 * For atomic drivers specifically this protects @state.
62743968d7bSDaniel Vetter 	 */
62843968d7bSDaniel Vetter 	struct drm_modeset_lock mutex;
62943968d7bSDaniel Vetter 
630268bc24eSDaniel Vetter 	/** @base: base mode object */
63143968d7bSDaniel Vetter 	struct drm_mode_object base;
63243968d7bSDaniel Vetter 
633268bc24eSDaniel Vetter 	/**
634268bc24eSDaniel Vetter 	 * @possible_crtcs: pipes this plane can be bound to constructed from
635268bc24eSDaniel Vetter 	 * drm_crtc_mask()
636268bc24eSDaniel Vetter 	 */
63743968d7bSDaniel Vetter 	uint32_t possible_crtcs;
638268bc24eSDaniel Vetter 	/** @format_types: array of formats supported by this plane */
63943968d7bSDaniel Vetter 	uint32_t *format_types;
640268bc24eSDaniel Vetter 	/** @format_count: Size of the array pointed at by @format_types. */
64143968d7bSDaniel Vetter 	unsigned int format_count;
642268bc24eSDaniel Vetter 	/**
643268bc24eSDaniel Vetter 	 * @format_default: driver hasn't supplied supported formats for the
6447221941cSThomas Zimmermann 	 * plane. Used by the non-atomic driver compatibility wrapper only.
645268bc24eSDaniel Vetter 	 */
64643968d7bSDaniel Vetter 	bool format_default;
64743968d7bSDaniel Vetter 
648268bc24eSDaniel Vetter 	/** @modifiers: array of modifiers supported by this plane */
649e6fc3b68SBen Widawsky 	uint64_t *modifiers;
650268bc24eSDaniel Vetter 	/** @modifier_count: Size of the array pointed at by @modifier_count. */
651e6fc3b68SBen Widawsky 	unsigned int modifier_count;
652e6fc3b68SBen Widawsky 
6532e2b96efSDaniel Vetter 	/**
654268bc24eSDaniel Vetter 	 * @crtc:
655268bc24eSDaniel Vetter 	 *
656268bc24eSDaniel Vetter 	 * Currently bound CRTC, only meaningful for non-atomic drivers. For
657268bc24eSDaniel Vetter 	 * atomic drivers this is forced to be NULL, atomic drivers should
658268bc24eSDaniel Vetter 	 * instead check &drm_plane_state.crtc.
6592e2b96efSDaniel Vetter 	 */
66043968d7bSDaniel Vetter 	struct drm_crtc *crtc;
6612e2b96efSDaniel Vetter 
6622e2b96efSDaniel Vetter 	/**
663268bc24eSDaniel Vetter 	 * @fb:
664268bc24eSDaniel Vetter 	 *
665268bc24eSDaniel Vetter 	 * Currently bound framebuffer, only meaningful for non-atomic drivers.
666268bc24eSDaniel Vetter 	 * For atomic drivers this is forced to be NULL, atomic drivers should
667268bc24eSDaniel Vetter 	 * instead check &drm_plane_state.fb.
6682e2b96efSDaniel Vetter 	 */
66943968d7bSDaniel Vetter 	struct drm_framebuffer *fb;
67043968d7bSDaniel Vetter 
671268bc24eSDaniel Vetter 	/**
672268bc24eSDaniel Vetter 	 * @old_fb:
673268bc24eSDaniel Vetter 	 *
674268bc24eSDaniel Vetter 	 * Temporary tracking of the old fb while a modeset is ongoing. Only
675268bc24eSDaniel Vetter 	 * used by non-atomic drivers, forced to be NULL for atomic drivers.
676268bc24eSDaniel Vetter 	 */
67743968d7bSDaniel Vetter 	struct drm_framebuffer *old_fb;
67843968d7bSDaniel Vetter 
679268bc24eSDaniel Vetter 	/** @funcs: plane control functions */
68043968d7bSDaniel Vetter 	const struct drm_plane_funcs *funcs;
68143968d7bSDaniel Vetter 
682268bc24eSDaniel Vetter 	/** @properties: property tracking for this plane */
68343968d7bSDaniel Vetter 	struct drm_object_properties properties;
68443968d7bSDaniel Vetter 
685268bc24eSDaniel Vetter 	/** @type: Type of plane, see &enum drm_plane_type for details. */
68643968d7bSDaniel Vetter 	enum drm_plane_type type;
68743968d7bSDaniel Vetter 
68843968d7bSDaniel Vetter 	/**
68943968d7bSDaniel Vetter 	 * @index: Position inside the mode_config.list, can be used as an array
69043968d7bSDaniel Vetter 	 * index. It is invariant over the lifetime of the plane.
69143968d7bSDaniel Vetter 	 */
69243968d7bSDaniel Vetter 	unsigned index;
69343968d7bSDaniel Vetter 
694268bc24eSDaniel Vetter 	/** @helper_private: mid-layer private data */
69543968d7bSDaniel Vetter 	const struct drm_plane_helper_funcs *helper_private;
69643968d7bSDaniel Vetter 
697c9e42b72SDaniel Vetter 	/**
698c9e42b72SDaniel Vetter 	 * @state:
699c9e42b72SDaniel Vetter 	 *
700c9e42b72SDaniel Vetter 	 * Current atomic state for this plane.
701c9e42b72SDaniel Vetter 	 *
702c9e42b72SDaniel Vetter 	 * This is protected by @mutex. Note that nonblocking atomic commits
703c9e42b72SDaniel Vetter 	 * access the current plane state without taking locks. Either by going
704c9e42b72SDaniel Vetter 	 * through the &struct drm_atomic_state pointers, see
70577ac3b00SMaarten Lankhorst 	 * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
70677ac3b00SMaarten Lankhorst 	 * for_each_new_plane_in_state(). Or through careful ordering of atomic
70777ac3b00SMaarten Lankhorst 	 * commit operations as implemented in the atomic helpers, see
70877ac3b00SMaarten Lankhorst 	 * &struct drm_crtc_commit.
709c9e42b72SDaniel Vetter 	 */
71043968d7bSDaniel Vetter 	struct drm_plane_state *state;
71143968d7bSDaniel Vetter 
712268bc24eSDaniel Vetter 	/**
713268bc24eSDaniel Vetter 	 * @alpha_property:
714268bc24eSDaniel Vetter 	 * Optional alpha property for this plane. See
715268bc24eSDaniel Vetter 	 * drm_plane_create_alpha_property().
716268bc24eSDaniel Vetter 	 */
717ae0e2826SMaxime Ripard 	struct drm_property *alpha_property;
718268bc24eSDaniel Vetter 	/**
719268bc24eSDaniel Vetter 	 * @zpos_property:
720268bc24eSDaniel Vetter 	 * Optional zpos property for this plane. See
721268bc24eSDaniel Vetter 	 * drm_plane_create_zpos_property().
722268bc24eSDaniel Vetter 	 */
72343968d7bSDaniel Vetter 	struct drm_property *zpos_property;
724268bc24eSDaniel Vetter 	/**
725268bc24eSDaniel Vetter 	 * @rotation_property:
726268bc24eSDaniel Vetter 	 * Optional rotation property for this plane. See
727268bc24eSDaniel Vetter 	 * drm_plane_create_rotation_property().
728268bc24eSDaniel Vetter 	 */
729d138dd3cSVille Syrjälä 	struct drm_property *rotation_property;
730a5ec8332SLowry Li 	/**
731a5ec8332SLowry Li 	 * @blend_mode_property:
732a5ec8332SLowry Li 	 * Optional "pixel blend mode" enum property for this plane.
733a5ec8332SLowry Li 	 * Blend mode property represents the alpha blending equation selection,
734a5ec8332SLowry Li 	 * describing how the pixels from the current plane are composited with
735a5ec8332SLowry Li 	 * the background.
736a5ec8332SLowry Li 	 */
737a5ec8332SLowry Li 	struct drm_property *blend_mode_property;
73880f690e9SJyri Sarha 
73980f690e9SJyri Sarha 	/**
74080f690e9SJyri Sarha 	 * @color_encoding_property:
74180f690e9SJyri Sarha 	 *
74280f690e9SJyri Sarha 	 * Optional "COLOR_ENCODING" enum property for specifying
74380f690e9SJyri Sarha 	 * color encoding for non RGB formats.
74480f690e9SJyri Sarha 	 * See drm_plane_create_color_properties().
74580f690e9SJyri Sarha 	 */
74680f690e9SJyri Sarha 	struct drm_property *color_encoding_property;
74780f690e9SJyri Sarha 	/**
74880f690e9SJyri Sarha 	 * @color_range_property:
74980f690e9SJyri Sarha 	 *
75080f690e9SJyri Sarha 	 * Optional "COLOR_RANGE" enum property for specifying
75180f690e9SJyri Sarha 	 * color range for non RGB formats.
75280f690e9SJyri Sarha 	 * See drm_plane_create_color_properties().
75380f690e9SJyri Sarha 	 */
75480f690e9SJyri Sarha 	struct drm_property *color_range_property;
7555c759edaSPankaj Bharadiya 
7565c759edaSPankaj Bharadiya 	/**
7575c759edaSPankaj Bharadiya 	 * @scaling_filter_property: property to apply a particular filter while
7585c759edaSPankaj Bharadiya 	 * scaling.
7595c759edaSPankaj Bharadiya 	 */
7605c759edaSPankaj Bharadiya 	struct drm_property *scaling_filter_property;
76143968d7bSDaniel Vetter };
76243968d7bSDaniel Vetter 
76343968d7bSDaniel Vetter #define obj_to_plane(x) container_of(x, struct drm_plane, base)
76443968d7bSDaniel Vetter 
765e6fc3b68SBen Widawsky __printf(9, 10)
76643968d7bSDaniel Vetter int drm_universal_plane_init(struct drm_device *dev,
76743968d7bSDaniel Vetter 			     struct drm_plane *plane,
7685cd57a46STomi Valkeinen 			     uint32_t possible_crtcs,
76943968d7bSDaniel Vetter 			     const struct drm_plane_funcs *funcs,
77043968d7bSDaniel Vetter 			     const uint32_t *formats,
77143968d7bSDaniel Vetter 			     unsigned int format_count,
772e6fc3b68SBen Widawsky 			     const uint64_t *format_modifiers,
77343968d7bSDaniel Vetter 			     enum drm_plane_type type,
77443968d7bSDaniel Vetter 			     const char *name, ...);
77591faa047SDaniel Vetter void drm_plane_cleanup(struct drm_plane *plane);
77643968d7bSDaniel Vetter 
7770a1b813fSPhilipp Zabel __printf(10, 11)
7780a1b813fSPhilipp Zabel void *__drmm_universal_plane_alloc(struct drm_device *dev,
7790a1b813fSPhilipp Zabel 				   size_t size, size_t offset,
7800a1b813fSPhilipp Zabel 				   uint32_t possible_crtcs,
7810a1b813fSPhilipp Zabel 				   const struct drm_plane_funcs *funcs,
7820a1b813fSPhilipp Zabel 				   const uint32_t *formats,
7830a1b813fSPhilipp Zabel 				   unsigned int format_count,
7840a1b813fSPhilipp Zabel 				   const uint64_t *format_modifiers,
7850a1b813fSPhilipp Zabel 				   enum drm_plane_type plane_type,
7860a1b813fSPhilipp Zabel 				   const char *name, ...);
7870a1b813fSPhilipp Zabel 
7880a1b813fSPhilipp Zabel /**
7890a1b813fSPhilipp Zabel  * drmm_universal_plane_alloc - Allocate and initialize an universal plane object
7900a1b813fSPhilipp Zabel  * @dev: DRM device
7910a1b813fSPhilipp Zabel  * @type: the type of the struct which contains struct &drm_plane
7920a1b813fSPhilipp Zabel  * @member: the name of the &drm_plane within @type
7930a1b813fSPhilipp Zabel  * @possible_crtcs: bitmask of possible CRTCs
7940a1b813fSPhilipp Zabel  * @funcs: callbacks for the new plane
7950a1b813fSPhilipp Zabel  * @formats: array of supported formats (DRM_FORMAT\_\*)
7960a1b813fSPhilipp Zabel  * @format_count: number of elements in @formats
7970a1b813fSPhilipp Zabel  * @format_modifiers: array of struct drm_format modifiers terminated by
7980a1b813fSPhilipp Zabel  *                    DRM_FORMAT_MOD_INVALID
7990a1b813fSPhilipp Zabel  * @plane_type: type of plane (overlay, primary, cursor)
8000a1b813fSPhilipp Zabel  * @name: printf style format string for the plane name, or NULL for default name
8010a1b813fSPhilipp Zabel  *
8020a1b813fSPhilipp Zabel  * Allocates and initializes a plane object of type @type. Cleanup is
8030a1b813fSPhilipp Zabel  * automatically handled through registering drm_plane_cleanup() with
8040a1b813fSPhilipp Zabel  * drmm_add_action().
8050a1b813fSPhilipp Zabel  *
8060a1b813fSPhilipp Zabel  * The @drm_plane_funcs.destroy hook must be NULL.
8070a1b813fSPhilipp Zabel  *
8088be57683STomohito Esaki  * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
8098be57683STomohito Esaki  * @format_modifiers to NULL. The plane will advertise the linear modifier.
8108be57683STomohito Esaki  *
8110a1b813fSPhilipp Zabel  * Returns:
8120a1b813fSPhilipp Zabel  * Pointer to new plane, or ERR_PTR on failure.
8130a1b813fSPhilipp Zabel  */
8140a1b813fSPhilipp Zabel #define drmm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
8150a1b813fSPhilipp Zabel 				   format_count, format_modifiers, plane_type, name, ...) \
8160a1b813fSPhilipp Zabel 	((type *)__drmm_universal_plane_alloc(dev, sizeof(type), \
8170a1b813fSPhilipp Zabel 					      offsetof(type, member), \
8180a1b813fSPhilipp Zabel 					      possible_crtcs, funcs, formats, \
8190a1b813fSPhilipp Zabel 					      format_count, format_modifiers, \
8200a1b813fSPhilipp Zabel 					      plane_type, name, ##__VA_ARGS__))
8210a1b813fSPhilipp Zabel 
822e71def05SThomas Zimmermann __printf(10, 11)
823e71def05SThomas Zimmermann void *__drm_universal_plane_alloc(struct drm_device *dev,
824e71def05SThomas Zimmermann 				  size_t size, size_t offset,
825e71def05SThomas Zimmermann 				  uint32_t possible_crtcs,
826e71def05SThomas Zimmermann 				  const struct drm_plane_funcs *funcs,
827e71def05SThomas Zimmermann 				  const uint32_t *formats,
828e71def05SThomas Zimmermann 				  unsigned int format_count,
829e71def05SThomas Zimmermann 				  const uint64_t *format_modifiers,
830e71def05SThomas Zimmermann 				  enum drm_plane_type plane_type,
831e71def05SThomas Zimmermann 				  const char *name, ...);
832e71def05SThomas Zimmermann 
833e71def05SThomas Zimmermann /**
834e71def05SThomas Zimmermann  * drm_universal_plane_alloc() - Allocate and initialize an universal plane object
835e71def05SThomas Zimmermann  * @dev: DRM device
836e71def05SThomas Zimmermann  * @type: the type of the struct which contains struct &drm_plane
837e71def05SThomas Zimmermann  * @member: the name of the &drm_plane within @type
838e71def05SThomas Zimmermann  * @possible_crtcs: bitmask of possible CRTCs
839e71def05SThomas Zimmermann  * @funcs: callbacks for the new plane
840e71def05SThomas Zimmermann  * @formats: array of supported formats (DRM_FORMAT\_\*)
841e71def05SThomas Zimmermann  * @format_count: number of elements in @formats
842e71def05SThomas Zimmermann  * @format_modifiers: array of struct drm_format modifiers terminated by
843e71def05SThomas Zimmermann  *                    DRM_FORMAT_MOD_INVALID
844e71def05SThomas Zimmermann  * @plane_type: type of plane (overlay, primary, cursor)
845e71def05SThomas Zimmermann  * @name: printf style format string for the plane name, or NULL for default name
846e71def05SThomas Zimmermann  *
847e71def05SThomas Zimmermann  * Allocates and initializes a plane object of type @type. The caller
848e71def05SThomas Zimmermann  * is responsible for releasing the allocated memory with kfree().
849e71def05SThomas Zimmermann  *
850e71def05SThomas Zimmermann  * Drivers are encouraged to use drmm_universal_plane_alloc() instead.
851e71def05SThomas Zimmermann  *
852e71def05SThomas Zimmermann  * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
853e71def05SThomas Zimmermann  * @format_modifiers to NULL. The plane will advertise the linear modifier.
854e71def05SThomas Zimmermann  *
855e71def05SThomas Zimmermann  * Returns:
856e71def05SThomas Zimmermann  * Pointer to new plane, or ERR_PTR on failure.
857e71def05SThomas Zimmermann  */
858e71def05SThomas Zimmermann #define drm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
859e71def05SThomas Zimmermann 				   format_count, format_modifiers, plane_type, name, ...) \
860e71def05SThomas Zimmermann 	((type *)__drm_universal_plane_alloc(dev, sizeof(type), \
861e71def05SThomas Zimmermann 					     offsetof(type, member), \
862e71def05SThomas Zimmermann 					     possible_crtcs, funcs, formats, \
863e71def05SThomas Zimmermann 					     format_count, format_modifiers, \
864e71def05SThomas Zimmermann 					     plane_type, name, ##__VA_ARGS__))
865e71def05SThomas Zimmermann 
86643968d7bSDaniel Vetter /**
86743968d7bSDaniel Vetter  * drm_plane_index - find the index of a registered plane
86843968d7bSDaniel Vetter  * @plane: plane to find index for
86943968d7bSDaniel Vetter  *
87043968d7bSDaniel Vetter  * Given a registered plane, return the index of that plane within a DRM
87143968d7bSDaniel Vetter  * device's list of planes.
87243968d7bSDaniel Vetter  */
drm_plane_index(const struct drm_plane * plane)87362f77ad0SVille Syrjälä static inline unsigned int drm_plane_index(const struct drm_plane *plane)
87443968d7bSDaniel Vetter {
87543968d7bSDaniel Vetter 	return plane->index;
87643968d7bSDaniel Vetter }
87762f77ad0SVille Syrjälä 
87862f77ad0SVille Syrjälä /**
87962f77ad0SVille Syrjälä  * drm_plane_mask - find the mask of a registered plane
88062f77ad0SVille Syrjälä  * @plane: plane to find mask for
88162f77ad0SVille Syrjälä  */
drm_plane_mask(const struct drm_plane * plane)88262f77ad0SVille Syrjälä static inline u32 drm_plane_mask(const struct drm_plane *plane)
88362f77ad0SVille Syrjälä {
88462f77ad0SVille Syrjälä 	return 1 << drm_plane_index(plane);
88562f77ad0SVille Syrjälä }
88662f77ad0SVille Syrjälä 
88791faa047SDaniel Vetter struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
88891faa047SDaniel Vetter void drm_plane_force_disable(struct drm_plane *plane);
88943968d7bSDaniel Vetter 
89043968d7bSDaniel Vetter int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
89143968d7bSDaniel Vetter 				       struct drm_property *property,
89243968d7bSDaniel Vetter 				       uint64_t value);
89343968d7bSDaniel Vetter 
89443968d7bSDaniel Vetter /**
89543968d7bSDaniel Vetter  * drm_plane_find - find a &drm_plane
89643968d7bSDaniel Vetter  * @dev: DRM device
897e7e62c7eSDave Airlie  * @file_priv: drm file to check for lease against.
89843968d7bSDaniel Vetter  * @id: plane id
89943968d7bSDaniel Vetter  *
90043968d7bSDaniel Vetter  * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
90143968d7bSDaniel Vetter  * drm_mode_object_find().
90243968d7bSDaniel Vetter  */
drm_plane_find(struct drm_device * dev,struct drm_file * file_priv,uint32_t id)90343968d7bSDaniel Vetter static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
904418da172SKeith Packard 		struct drm_file *file_priv,
90543968d7bSDaniel Vetter 		uint32_t id)
90643968d7bSDaniel Vetter {
90743968d7bSDaniel Vetter 	struct drm_mode_object *mo;
908418da172SKeith Packard 	mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
90943968d7bSDaniel Vetter 	return mo ? obj_to_plane(mo) : NULL;
91043968d7bSDaniel Vetter }
91143968d7bSDaniel Vetter 
91243968d7bSDaniel Vetter /**
91343968d7bSDaniel Vetter  * drm_for_each_plane_mask - iterate over planes specified by bitmask
91443968d7bSDaniel Vetter  * @plane: the loop cursor
91543968d7bSDaniel Vetter  * @dev: the DRM device
91643968d7bSDaniel Vetter  * @plane_mask: bitmask of plane indices
91743968d7bSDaniel Vetter  *
91843968d7bSDaniel Vetter  * Iterate over all planes specified by bitmask.
91943968d7bSDaniel Vetter  */
92043968d7bSDaniel Vetter #define drm_for_each_plane_mask(plane, dev, plane_mask) \
92143968d7bSDaniel Vetter 	list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
92262f77ad0SVille Syrjälä 		for_each_if ((plane_mask) & drm_plane_mask(plane))
92343968d7bSDaniel Vetter 
924532b3671SDaniel Vetter /**
925532b3671SDaniel Vetter  * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
926532b3671SDaniel Vetter  * @plane: the loop cursor
927532b3671SDaniel Vetter  * @dev: the DRM device
928532b3671SDaniel Vetter  *
929532b3671SDaniel Vetter  * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
930532b3671SDaniel Vetter  * This is useful for implementing userspace apis when userspace is not
931d574528aSDaniel Vetter  * universal plane aware. See also &enum drm_plane_type.
932532b3671SDaniel Vetter  */
93343968d7bSDaniel Vetter #define drm_for_each_legacy_plane(plane, dev) \
93443968d7bSDaniel Vetter 	list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
93543968d7bSDaniel Vetter 		for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
93643968d7bSDaniel Vetter 
937532b3671SDaniel Vetter /**
938532b3671SDaniel Vetter  * drm_for_each_plane - iterate over all planes
939532b3671SDaniel Vetter  * @plane: the loop cursor
940532b3671SDaniel Vetter  * @dev: the DRM device
941532b3671SDaniel Vetter  *
942532b3671SDaniel Vetter  * Iterate over all planes of @dev, include primary and cursor planes.
943532b3671SDaniel Vetter  */
94443968d7bSDaniel Vetter #define drm_for_each_plane(plane, dev) \
94543968d7bSDaniel Vetter 	list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
94643968d7bSDaniel Vetter 
947e7afb623SVille Syrjälä bool drm_any_plane_has_format(struct drm_device *dev,
948e7afb623SVille Syrjälä 			      u32 format, u64 modifier);
949ba6cd766SDaniel Vetter 
950ba6cd766SDaniel Vetter void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
951c7fcbf25SDaniel Vetter unsigned int
952c7fcbf25SDaniel Vetter drm_plane_get_damage_clips_count(const struct drm_plane_state *state);
953c7fcbf25SDaniel Vetter struct drm_mode_rect *
954c7fcbf25SDaniel Vetter drm_plane_get_damage_clips(const struct drm_plane_state *state);
95543968d7bSDaniel Vetter 
9565c759edaSPankaj Bharadiya int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
9575c759edaSPankaj Bharadiya 					     unsigned int supported_filters);
9585c759edaSPankaj Bharadiya 
95943968d7bSDaniel Vetter #endif
960