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