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