File Index
Files and directories
Sign in
FILE

drm_plane.h

File preview with syntax highlighting.

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