]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/drm/drm_plane.h
drm/i915: Promote .format_mod_supported() to the lead role
[mirror_ubuntu-jammy-kernel.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>
28#include <drm/drm_mode_object.h>
80f690e9 29#include <drm/drm_color_mgmt.h>
43968d7b
DV
30
31struct drm_crtc;
fceffb32 32struct drm_printer;
34a2ab5e 33struct drm_modeset_acquire_ctx;
43968d7b
DV
34
35/**
36 * struct drm_plane_state - mutable plane state
37 * @plane: backpointer to the plane
43968d7b
DV
38 * @crtc_w: width of visible portion of plane on crtc
39 * @crtc_h: height of visible portion of plane on crtc
40 * @src_x: left position of visible portion of plane within
41 * plane (in 16.16)
42 * @src_y: upper position of visible portion of plane within
43 * plane (in 16.16)
44 * @src_w: width of visible portion of plane (in 16.16)
45 * @src_h: height of visible portion of plane (in 16.16)
ae0e2826 46 * @alpha: opacity of the plane
43968d7b
DV
47 * @rotation: rotation of the plane
48 * @zpos: priority of the given plane on crtc (optional)
38d868e4
VS
49 * Note that multiple active planes on the same crtc can have an identical
50 * zpos value. The rule to solving the conflict is to compare the plane
51 * object IDs; the plane with a higher ID must be stacked on top of a
52 * plane with a lower ID.
43968d7b 53 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
38d868e4 54 * where N is the number of active planes for given crtc. Note that
49efffc7
PU
55 * the driver must set drm_mode_config.normalize_zpos or call
56 * drm_atomic_normalize_zpos() to update this before it can be trusted.
43968d7b
DV
57 * @src: clipped source coordinates of the plane (in 16.16)
58 * @dst: clipped destination coordinates of the plane
43968d7b
DV
59 * @state: backpointer to global drm_atomic_state
60 */
61struct drm_plane_state {
62 struct drm_plane *plane;
63
3835b46e
GP
64 /**
65 * @crtc:
66 *
67 * Currently bound CRTC, NULL if disabled. Do not this write directly,
68 * use drm_atomic_set_crtc_for_plane()
69 */
70 struct drm_crtc *crtc;
71
72 /**
73 * @fb:
74 *
75 * Currently bound framebuffer. Do not write this directly, use
76 * drm_atomic_set_fb_for_plane()
77 */
78 struct drm_framebuffer *fb;
79
80 /**
81 * @fence:
82 *
30d23f22
DV
83 * Optional fence to wait for before scanning out @fb. The core atomic
84 * code will set this when userspace is using explicit fencing. Do not
85 * write this directly for a driver's implicit fence, use
86 * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is
87 * preserved.
88 *
89 * Drivers should store any implicit fence in this from their
90 * &drm_plane_helper.prepare_fb callback. See drm_gem_fb_prepare_fb()
91 * and drm_gem_fb_simple_display_pipe_prepare_fb() for suitable helpers.
3835b46e 92 */
f54d1867 93 struct dma_fence *fence;
43968d7b 94
3835b46e
GP
95 /**
96 * @crtc_x:
97 *
98 * Left position of visible portion of plane on crtc, signed dest
99 * location allows it to be partially off screen.
100 */
101
102 int32_t crtc_x;
103 /**
104 * @crtc_y:
105 *
106 * Upper position of visible portion of plane on crtc, signed dest
107 * location allows it to be partially off screen.
108 */
109 int32_t crtc_y;
43968d7b 110
43968d7b
DV
111 uint32_t crtc_w, crtc_h;
112
113 /* Source values are 16.16 fixed point */
114 uint32_t src_x, src_y;
115 uint32_t src_h, src_w;
116
ae0e2826
MR
117 /* Plane opacity */
118 u16 alpha;
119
43968d7b
DV
120 /* Plane rotation */
121 unsigned int rotation;
122
123 /* Plane zpos */
124 unsigned int zpos;
125 unsigned int normalized_zpos;
126
80f690e9
JS
127 /**
128 * @color_encoding:
129 *
130 * Color encoding for non RGB formats
131 */
132 enum drm_color_encoding color_encoding;
133
134 /**
135 * @color_range:
136 *
137 * Color range for non RGB formats
138 */
139 enum drm_color_range color_range;
140
43968d7b
DV
141 /* Clipped coordinates */
142 struct drm_rect src, dst;
143
3835b46e
GP
144 /**
145 * @visible:
146 *
147 * Visibility of the plane. This can be false even if fb!=NULL and
148 * crtc!=NULL, due to clipping.
43968d7b
DV
149 */
150 bool visible;
151
21a01abb 152 /**
669c9215
ML
153 * @commit: Tracks the pending commit to prevent use-after-free conditions,
154 * and for async plane updates.
21a01abb 155 *
669c9215 156 * May be NULL.
21a01abb
ML
157 */
158 struct drm_crtc_commit *commit;
159
43968d7b
DV
160 struct drm_atomic_state *state;
161};
162
1638d30c
RC
163static inline struct drm_rect
164drm_plane_state_src(const struct drm_plane_state *state)
165{
166 struct drm_rect src = {
167 .x1 = state->src_x,
168 .y1 = state->src_y,
169 .x2 = state->src_x + state->src_w,
170 .y2 = state->src_y + state->src_h,
171 };
172 return src;
173}
174
175static inline struct drm_rect
176drm_plane_state_dest(const struct drm_plane_state *state)
177{
178 struct drm_rect dest = {
179 .x1 = state->crtc_x,
180 .y1 = state->crtc_y,
181 .x2 = state->crtc_x + state->crtc_w,
182 .y2 = state->crtc_y + state->crtc_h,
183 };
184 return dest;
185}
186
43968d7b
DV
187/**
188 * struct drm_plane_funcs - driver plane control functions
189 */
190struct drm_plane_funcs {
191 /**
192 * @update_plane:
193 *
194 * This is the legacy entry point to enable and configure the plane for
195 * the given CRTC and framebuffer. It is never called to disable the
196 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
197 *
198 * The source rectangle in frame buffer memory coordinates is given by
199 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
200 * values). Devices that don't support subpixel plane coordinates can
201 * ignore the fractional part.
202 *
203 * The destination rectangle in CRTC coordinates is given by the
204 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
205 * Devices scale the source rectangle to the destination rectangle. If
206 * scaling is not supported, and the source rectangle size doesn't match
207 * the destination rectangle size, the driver must return a
208 * -<errorname>EINVAL</errorname> error.
209 *
210 * Drivers implementing atomic modeset should use
211 * drm_atomic_helper_update_plane() to implement this hook.
212 *
213 * RETURNS:
214 *
215 * 0 on success or a negative error code on failure.
216 */
217 int (*update_plane)(struct drm_plane *plane,
218 struct drm_crtc *crtc, struct drm_framebuffer *fb,
219 int crtc_x, int crtc_y,
220 unsigned int crtc_w, unsigned int crtc_h,
221 uint32_t src_x, uint32_t src_y,
34a2ab5e
DV
222 uint32_t src_w, uint32_t src_h,
223 struct drm_modeset_acquire_ctx *ctx);
43968d7b
DV
224
225 /**
226 * @disable_plane:
227 *
228 * This is the legacy entry point to disable the plane. The DRM core
229 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
230 * with the frame buffer ID set to 0. Disabled planes must not be
231 * processed by the CRTC.
232 *
233 * Drivers implementing atomic modeset should use
234 * drm_atomic_helper_disable_plane() to implement this hook.
235 *
236 * RETURNS:
237 *
238 * 0 on success or a negative error code on failure.
239 */
19315294
DV
240 int (*disable_plane)(struct drm_plane *plane,
241 struct drm_modeset_acquire_ctx *ctx);
43968d7b
DV
242
243 /**
244 * @destroy:
245 *
246 * Clean up plane resources. This is only called at driver unload time
247 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
248 * in DRM.
249 */
250 void (*destroy)(struct drm_plane *plane);
251
252 /**
253 * @reset:
254 *
255 * Reset plane hardware and software state to off. This function isn't
256 * called by the core directly, only through drm_mode_config_reset().
257 * It's not a helper hook only for historical reasons.
258 *
259 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
260 * atomic state using this hook.
261 */
262 void (*reset)(struct drm_plane *plane);
263
264 /**
265 * @set_property:
266 *
267 * This is the legacy entry point to update a property attached to the
268 * plane.
269 *
43968d7b 270 * This callback is optional if the driver does not support any legacy
144a7999
DV
271 * driver-private properties. For atomic drivers it is not used because
272 * property handling is done entirely in the DRM core.
43968d7b
DV
273 *
274 * RETURNS:
275 *
276 * 0 on success or a negative error code on failure.
277 */
278 int (*set_property)(struct drm_plane *plane,
279 struct drm_property *property, uint64_t val);
280
281 /**
282 * @atomic_duplicate_state:
283 *
284 * Duplicate the current atomic state for this plane and return it.
d574528a 285 * The core and helpers guarantee that any atomic state duplicated with
43968d7b 286 * this hook and still owned by the caller (i.e. not transferred to the
d574528a
DV
287 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
288 * cleaned up by calling the @atomic_destroy_state hook in this
289 * structure.
43968d7b 290 *
ea0dd85a 291 * Atomic drivers which don't subclass &struct drm_plane_state should use
43968d7b
DV
292 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
293 * state structure to extend it with driver-private state should use
294 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
295 * duplicated in a consistent fashion across drivers.
296 *
d574528a 297 * It is an error to call this hook before &drm_plane.state has been
43968d7b
DV
298 * initialized correctly.
299 *
300 * NOTE:
301 *
302 * If the duplicate state references refcounted resources this hook must
303 * acquire a reference for each of them. The driver must release these
304 * references again in @atomic_destroy_state.
305 *
306 * RETURNS:
307 *
308 * Duplicated atomic state or NULL when the allocation failed.
309 */
310 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
311
312 /**
313 * @atomic_destroy_state:
314 *
315 * Destroy a state duplicated with @atomic_duplicate_state and release
316 * or unreference all resources it references
317 */
318 void (*atomic_destroy_state)(struct drm_plane *plane,
319 struct drm_plane_state *state);
320
321 /**
322 * @atomic_set_property:
323 *
324 * Decode a driver-private property value and store the decoded value
325 * into the passed-in state structure. Since the atomic core decodes all
326 * standardized properties (even for extensions beyond the core set of
327 * properties which might not be implemented by all drivers) this
328 * requires drivers to subclass the state structure.
329 *
330 * Such driver-private properties should really only be implemented for
331 * truly hardware/vendor specific state. Instead it is preferred to
332 * standardize atomic extension and decode the properties used to expose
333 * such an extension in the core.
334 *
335 * Do not call this function directly, use
336 * drm_atomic_plane_set_property() instead.
337 *
338 * This callback is optional if the driver does not support any
339 * driver-private atomic properties.
340 *
341 * NOTE:
342 *
343 * This function is called in the state assembly phase of atomic
344 * modesets, which can be aborted for any reason (including on
345 * userspace's request to just check whether a configuration would be
346 * possible). Drivers MUST NOT touch any persistent state (hardware or
347 * software) or data structures except the passed in @state parameter.
348 *
349 * Also since userspace controls in which order properties are set this
350 * function must not do any input validation (since the state update is
351 * incomplete and hence likely inconsistent). Instead any such input
352 * validation must be done in the various atomic_check callbacks.
353 *
354 * RETURNS:
355 *
356 * 0 if the property has been found, -EINVAL if the property isn't
357 * implemented by the driver (which shouldn't ever happen, the core only
358 * asks for properties attached to this plane). No other validation is
359 * allowed by the driver. The core already checks that the property
360 * value is within the range (integer, valid enum value, ...) the driver
361 * set when registering the property.
362 */
363 int (*atomic_set_property)(struct drm_plane *plane,
364 struct drm_plane_state *state,
365 struct drm_property *property,
366 uint64_t val);
367
368 /**
369 * @atomic_get_property:
370 *
371 * Reads out the decoded driver-private property. This is used to
372 * implement the GETPLANE IOCTL.
373 *
374 * Do not call this function directly, use
375 * drm_atomic_plane_get_property() instead.
376 *
377 * This callback is optional if the driver does not support any
378 * driver-private atomic properties.
379 *
380 * RETURNS:
381 *
382 * 0 on success, -EINVAL if the property isn't implemented by the
383 * driver (which should never happen, the core only asks for
384 * properties attached to this plane).
385 */
386 int (*atomic_get_property)(struct drm_plane *plane,
387 const struct drm_plane_state *state,
388 struct drm_property *property,
389 uint64_t *val);
390 /**
391 * @late_register:
392 *
393 * This optional hook can be used to register additional userspace
394 * interfaces attached to the plane like debugfs interfaces.
395 * It is called late in the driver load sequence from drm_dev_register().
396 * Everything added from this callback should be unregistered in
397 * the early_unregister callback.
398 *
399 * Returns:
400 *
401 * 0 on success, or a negative error code on failure.
402 */
403 int (*late_register)(struct drm_plane *plane);
404
405 /**
406 * @early_unregister:
407 *
408 * This optional hook should be used to unregister the additional
409 * userspace interfaces attached to the plane from
559bdaf7 410 * @late_register. It is called from drm_dev_unregister(),
43968d7b
DV
411 * early in the driver unload sequence to disable userspace access
412 * before data structures are torndown.
413 */
414 void (*early_unregister)(struct drm_plane *plane);
fceffb32
RC
415
416 /**
417 * @atomic_print_state:
418 *
ea0dd85a 419 * If driver subclasses &struct drm_plane_state, it should implement
fceffb32
RC
420 * this optional hook for printing additional driver specific state.
421 *
422 * Do not call this directly, use drm_atomic_plane_print_state()
423 * instead.
424 */
425 void (*atomic_print_state)(struct drm_printer *p,
426 const struct drm_plane_state *state);
e6fc3b68
BW
427
428 /**
429 * @format_mod_supported:
430 *
431 * This optional hook is used for the DRM to determine if the given
432 * format/modifier combination is valid for the plane. This allows the
433 * DRM to generate the correct format bitmask (which formats apply to
434 * which modifier).
435 *
436 * Returns:
437 *
438 * True if the given modifier is valid for that format on the plane.
439 * False otherwise.
440 */
441 bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
442 uint64_t modifier);
43968d7b
DV
443};
444
532b3671
DV
445/**
446 * enum drm_plane_type - uapi plane type enumeration
447 *
448 * For historical reasons not all planes are made the same. This enumeration is
449 * used to tell the different types of planes apart to implement the different
450 * uapi semantics for them. For userspace which is universal plane aware and
451 * which is using that atomic IOCTL there's no difference between these planes
452 * (beyong what the driver and hardware can support of course).
453 *
454 * For compatibility with legacy userspace, only overlay planes are made
455 * available to userspace by default. Userspace clients may set the
456 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
457 * wish to receive a universal plane list containing all plane types. See also
458 * drm_for_each_legacy_plane().
226714dc
DV
459 *
460 * WARNING: The values of this enum is UABI since they're exposed in the "type"
461 * property.
532b3671 462 */
43968d7b 463enum drm_plane_type {
226714dc
DV
464 /**
465 * @DRM_PLANE_TYPE_OVERLAY:
466 *
467 * Overlay planes represent all non-primary, non-cursor planes. Some
468 * drivers refer to these types of planes as "sprites" internally.
469 */
470 DRM_PLANE_TYPE_OVERLAY,
471
532b3671
DV
472 /**
473 * @DRM_PLANE_TYPE_PRIMARY:
474 *
475 * Primary planes represent a "main" plane for a CRTC. Primary planes
476 * are the planes operated upon by CRTC modesetting and flipping
d574528a
DV
477 * operations described in the &drm_crtc_funcs.page_flip and
478 * &drm_crtc_funcs.set_config hooks.
532b3671 479 */
43968d7b 480 DRM_PLANE_TYPE_PRIMARY,
532b3671
DV
481
482 /**
483 * @DRM_PLANE_TYPE_CURSOR:
484 *
485 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
486 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
487 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
488 */
43968d7b
DV
489 DRM_PLANE_TYPE_CURSOR,
490};
491
492
493/**
494 * struct drm_plane - central DRM plane control structure
495 * @dev: DRM device this plane belongs to
496 * @head: for list management
497 * @name: human readable name, can be overwritten by the driver
498 * @base: base mode object
499 * @possible_crtcs: pipes this plane can be bound to
500 * @format_types: array of formats supported by this plane
501 * @format_count: number of formats supported
502 * @format_default: driver hasn't supplied supported formats for the plane
3df67458
VS
503 * @modifiers: array of modifiers supported by this plane
504 * @modifier_count: number of modifiers supported
43968d7b
DV
505 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
506 * drm_mode_set_config_internal() to implement correct refcounting.
507 * @funcs: helper functions
508 * @properties: property tracking for this plane
509 * @type: type of plane (overlay, primary, cursor)
ae0e2826 510 * @alpha_property: alpha property for this plane
43968d7b 511 * @zpos_property: zpos property for this plane
d138dd3c 512 * @rotation_property: rotation property for this plane
43968d7b
DV
513 * @helper_private: mid-layer private data
514 */
515struct drm_plane {
516 struct drm_device *dev;
517 struct list_head head;
518
519 char *name;
520
521 /**
522 * @mutex:
523 *
d574528a
DV
524 * Protects modeset plane state, together with the &drm_crtc.mutex of
525 * CRTC this plane is linked to (when active, getting activated or
526 * getting disabled).
c9e42b72
DV
527 *
528 * For atomic drivers specifically this protects @state.
43968d7b
DV
529 */
530 struct drm_modeset_lock mutex;
531
532 struct drm_mode_object base;
533
534 uint32_t possible_crtcs;
535 uint32_t *format_types;
536 unsigned int format_count;
537 bool format_default;
538
e6fc3b68
BW
539 uint64_t *modifiers;
540 unsigned int modifier_count;
541
2e2b96ef
DV
542 /**
543 * @crtc: Currently bound CRTC, only really meaningful for non-atomic
544 * drivers. Atomic drivers should instead check &drm_plane_state.crtc.
545 */
43968d7b 546 struct drm_crtc *crtc;
2e2b96ef
DV
547
548 /**
549 * @fb: Currently bound framebuffer, only really meaningful for
550 * non-atomic drivers. Atomic drivers should instead check
551 * &drm_plane_state.fb.
552 */
43968d7b
DV
553 struct drm_framebuffer *fb;
554
555 struct drm_framebuffer *old_fb;
556
557 const struct drm_plane_funcs *funcs;
558
559 struct drm_object_properties properties;
560
561 enum drm_plane_type type;
562
563 /**
564 * @index: Position inside the mode_config.list, can be used as an array
565 * index. It is invariant over the lifetime of the plane.
566 */
567 unsigned index;
568
569 const struct drm_plane_helper_funcs *helper_private;
570
c9e42b72
DV
571 /**
572 * @state:
573 *
574 * Current atomic state for this plane.
575 *
576 * This is protected by @mutex. Note that nonblocking atomic commits
577 * access the current plane state without taking locks. Either by going
578 * through the &struct drm_atomic_state pointers, see
77ac3b00
ML
579 * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
580 * for_each_new_plane_in_state(). Or through careful ordering of atomic
581 * commit operations as implemented in the atomic helpers, see
582 * &struct drm_crtc_commit.
c9e42b72 583 */
43968d7b
DV
584 struct drm_plane_state *state;
585
ae0e2826 586 struct drm_property *alpha_property;
43968d7b 587 struct drm_property *zpos_property;
d138dd3c 588 struct drm_property *rotation_property;
80f690e9
JS
589
590 /**
591 * @color_encoding_property:
592 *
593 * Optional "COLOR_ENCODING" enum property for specifying
594 * color encoding for non RGB formats.
595 * See drm_plane_create_color_properties().
596 */
597 struct drm_property *color_encoding_property;
598 /**
599 * @color_range_property:
600 *
601 * Optional "COLOR_RANGE" enum property for specifying
602 * color range for non RGB formats.
603 * See drm_plane_create_color_properties().
604 */
605 struct drm_property *color_range_property;
43968d7b
DV
606};
607
608#define obj_to_plane(x) container_of(x, struct drm_plane, base)
609
e6fc3b68 610__printf(9, 10)
43968d7b
DV
611int drm_universal_plane_init(struct drm_device *dev,
612 struct drm_plane *plane,
5cd57a46 613 uint32_t possible_crtcs,
43968d7b
DV
614 const struct drm_plane_funcs *funcs,
615 const uint32_t *formats,
616 unsigned int format_count,
e6fc3b68 617 const uint64_t *format_modifiers,
43968d7b
DV
618 enum drm_plane_type type,
619 const char *name, ...);
91faa047
DV
620int drm_plane_init(struct drm_device *dev,
621 struct drm_plane *plane,
622 uint32_t possible_crtcs,
623 const struct drm_plane_funcs *funcs,
624 const uint32_t *formats, unsigned int format_count,
625 bool is_primary);
626void drm_plane_cleanup(struct drm_plane *plane);
43968d7b
DV
627
628/**
629 * drm_plane_index - find the index of a registered plane
630 * @plane: plane to find index for
631 *
632 * Given a registered plane, return the index of that plane within a DRM
633 * device's list of planes.
634 */
635static inline unsigned int drm_plane_index(struct drm_plane *plane)
636{
637 return plane->index;
638}
91faa047
DV
639struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
640void drm_plane_force_disable(struct drm_plane *plane);
43968d7b
DV
641
642int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
643 struct drm_property *property,
644 uint64_t value);
645
646/**
647 * drm_plane_find - find a &drm_plane
648 * @dev: DRM device
e7e62c7e 649 * @file_priv: drm file to check for lease against.
43968d7b
DV
650 * @id: plane id
651 *
652 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
653 * drm_mode_object_find().
654 */
655static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
418da172 656 struct drm_file *file_priv,
43968d7b
DV
657 uint32_t id)
658{
659 struct drm_mode_object *mo;
418da172 660 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
43968d7b
DV
661 return mo ? obj_to_plane(mo) : NULL;
662}
663
664/**
665 * drm_for_each_plane_mask - iterate over planes specified by bitmask
666 * @plane: the loop cursor
667 * @dev: the DRM device
668 * @plane_mask: bitmask of plane indices
669 *
670 * Iterate over all planes specified by bitmask.
671 */
672#define drm_for_each_plane_mask(plane, dev, plane_mask) \
673 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
674 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
675
532b3671
DV
676/**
677 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
678 * @plane: the loop cursor
679 * @dev: the DRM device
680 *
681 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
682 * This is useful for implementing userspace apis when userspace is not
d574528a 683 * universal plane aware. See also &enum drm_plane_type.
532b3671 684 */
43968d7b
DV
685#define drm_for_each_legacy_plane(plane, dev) \
686 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
687 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
688
532b3671
DV
689/**
690 * drm_for_each_plane - iterate over all planes
691 * @plane: the loop cursor
692 * @dev: the DRM device
693 *
694 * Iterate over all planes of @dev, include primary and cursor planes.
695 */
43968d7b
DV
696#define drm_for_each_plane(plane, dev) \
697 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
698
699
700#endif