blob: 7d96116fd4c4ebcb006820d0e16d73150ff4d244 [file] [log] [blame]
Daniel Vetter43968d72016-09-21 10:59:24 +02001/*
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>
29
30struct drm_crtc;
Rob Clarkfceffb322016-11-05 11:08:09 -040031struct drm_printer;
Daniel Vetter34a2ab52017-03-22 22:50:41 +010032struct drm_modeset_acquire_ctx;
Daniel Vetter43968d72016-09-21 10:59:24 +020033
34/**
35 * struct drm_plane_state - mutable plane state
36 * @plane: backpointer to the plane
Daniel Vetter43968d72016-09-21 10:59:24 +020037 * @crtc_w: width of visible portion of plane on crtc
38 * @crtc_h: height of visible portion of plane on crtc
39 * @src_x: left position of visible portion of plane within
40 * plane (in 16.16)
41 * @src_y: upper position of visible portion of plane within
42 * plane (in 16.16)
43 * @src_w: width of visible portion of plane (in 16.16)
44 * @src_h: height of visible portion of plane (in 16.16)
45 * @rotation: rotation of the plane
46 * @zpos: priority of the given plane on crtc (optional)
Ville Syrjälä38d868e2016-10-10 17:50:56 +030047 * Note that multiple active planes on the same crtc can have an identical
48 * zpos value. The rule to solving the conflict is to compare the plane
49 * object IDs; the plane with a higher ID must be stacked on top of a
50 * plane with a lower ID.
Daniel Vetter43968d72016-09-21 10:59:24 +020051 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
Ville Syrjälä38d868e2016-10-10 17:50:56 +030052 * where N is the number of active planes for given crtc. Note that
53 * the driver must call drm_atomic_normalize_zpos() to update this before
54 * it can be trusted.
Daniel Vetter43968d72016-09-21 10:59:24 +020055 * @src: clipped source coordinates of the plane (in 16.16)
56 * @dst: clipped destination coordinates of the plane
Daniel Vetter43968d72016-09-21 10:59:24 +020057 * @state: backpointer to global drm_atomic_state
58 */
59struct drm_plane_state {
60 struct drm_plane *plane;
61
Gustavo Padovan3835b462016-11-07 19:03:33 +090062 /**
63 * @crtc:
64 *
65 * Currently bound CRTC, NULL if disabled. Do not this write directly,
66 * use drm_atomic_set_crtc_for_plane()
67 */
68 struct drm_crtc *crtc;
Daniel Vetter43968d72016-09-21 10:59:24 +020069
Gustavo Padovan3835b462016-11-07 19:03:33 +090070 /**
71 * @fb:
72 *
73 * Currently bound framebuffer. Do not write this directly, use
74 * drm_atomic_set_fb_for_plane()
75 */
76 struct drm_framebuffer *fb;
77
78 /**
79 * @fence:
80 *
81 * Optional fence to wait for before scanning out @fb. Do not write this
82 * directly, use drm_atomic_set_fence_for_plane()
83 */
Daniel Vetter43968d72016-09-21 10:59:24 +020084 struct dma_fence *fence;
85
Gustavo Padovan3835b462016-11-07 19:03:33 +090086 /**
87 * @crtc_x:
88 *
89 * Left position of visible portion of plane on crtc, signed dest
90 * location allows it to be partially off screen.
91 */
92
93 int32_t crtc_x;
94 /**
95 * @crtc_y:
96 *
97 * Upper position of visible portion of plane on crtc, signed dest
98 * location allows it to be partially off screen.
99 */
100 int32_t crtc_y;
101
Daniel Vetter43968d72016-09-21 10:59:24 +0200102 uint32_t crtc_w, crtc_h;
103
104 /* Source values are 16.16 fixed point */
105 uint32_t src_x, src_y;
106 uint32_t src_h, src_w;
107
108 /* Plane rotation */
109 unsigned int rotation;
110
111 /* Plane zpos */
112 unsigned int zpos;
113 unsigned int normalized_zpos;
114
115 /* Clipped coordinates */
116 struct drm_rect src, dst;
117
Gustavo Padovan3835b462016-11-07 19:03:33 +0900118 /**
119 * @visible:
120 *
121 * Visibility of the plane. This can be false even if fb!=NULL and
122 * crtc!=NULL, due to clipping.
Daniel Vetter43968d72016-09-21 10:59:24 +0200123 */
124 bool visible;
125
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200126 /**
127 * @commit: Tracks the pending commit to prevent use-after-free conditions.
128 *
129 * Is only set when @crtc is NULL.
130 */
131 struct drm_crtc_commit *commit;
132
Daniel Vetter43968d72016-09-21 10:59:24 +0200133 struct drm_atomic_state *state;
134};
135
Rob Clark1638d302016-11-05 11:08:08 -0400136static inline struct drm_rect
137drm_plane_state_src(const struct drm_plane_state *state)
138{
139 struct drm_rect src = {
140 .x1 = state->src_x,
141 .y1 = state->src_y,
142 .x2 = state->src_x + state->src_w,
143 .y2 = state->src_y + state->src_h,
144 };
145 return src;
146}
147
148static inline struct drm_rect
149drm_plane_state_dest(const struct drm_plane_state *state)
150{
151 struct drm_rect dest = {
152 .x1 = state->crtc_x,
153 .y1 = state->crtc_y,
154 .x2 = state->crtc_x + state->crtc_w,
155 .y2 = state->crtc_y + state->crtc_h,
156 };
157 return dest;
158}
159
Daniel Vetter43968d72016-09-21 10:59:24 +0200160/**
161 * struct drm_plane_funcs - driver plane control functions
162 */
163struct drm_plane_funcs {
164 /**
165 * @update_plane:
166 *
167 * This is the legacy entry point to enable and configure the plane for
168 * the given CRTC and framebuffer. It is never called to disable the
169 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
170 *
171 * The source rectangle in frame buffer memory coordinates is given by
172 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
173 * values). Devices that don't support subpixel plane coordinates can
174 * ignore the fractional part.
175 *
176 * The destination rectangle in CRTC coordinates is given by the
177 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
178 * Devices scale the source rectangle to the destination rectangle. If
179 * scaling is not supported, and the source rectangle size doesn't match
180 * the destination rectangle size, the driver must return a
181 * -<errorname>EINVAL</errorname> error.
182 *
183 * Drivers implementing atomic modeset should use
184 * drm_atomic_helper_update_plane() to implement this hook.
185 *
186 * RETURNS:
187 *
188 * 0 on success or a negative error code on failure.
189 */
190 int (*update_plane)(struct drm_plane *plane,
191 struct drm_crtc *crtc, struct drm_framebuffer *fb,
192 int crtc_x, int crtc_y,
193 unsigned int crtc_w, unsigned int crtc_h,
194 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100195 uint32_t src_w, uint32_t src_h,
196 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200197
198 /**
199 * @disable_plane:
200 *
201 * This is the legacy entry point to disable the plane. The DRM core
202 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
203 * with the frame buffer ID set to 0. Disabled planes must not be
204 * processed by the CRTC.
205 *
206 * Drivers implementing atomic modeset should use
207 * drm_atomic_helper_disable_plane() to implement this hook.
208 *
209 * RETURNS:
210 *
211 * 0 on success or a negative error code on failure.
212 */
Daniel Vetter19315292017-03-22 22:50:43 +0100213 int (*disable_plane)(struct drm_plane *plane,
214 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200215
216 /**
217 * @destroy:
218 *
219 * Clean up plane resources. This is only called at driver unload time
220 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
221 * in DRM.
222 */
223 void (*destroy)(struct drm_plane *plane);
224
225 /**
226 * @reset:
227 *
228 * Reset plane hardware and software state to off. This function isn't
229 * called by the core directly, only through drm_mode_config_reset().
230 * It's not a helper hook only for historical reasons.
231 *
232 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
233 * atomic state using this hook.
234 */
235 void (*reset)(struct drm_plane *plane);
236
237 /**
238 * @set_property:
239 *
240 * This is the legacy entry point to update a property attached to the
241 * plane.
242 *
Daniel Vetter43968d72016-09-21 10:59:24 +0200243 * This callback is optional if the driver does not support any legacy
Daniel Vetter144a7992017-07-25 14:02:04 +0200244 * driver-private properties. For atomic drivers it is not used because
245 * property handling is done entirely in the DRM core.
Daniel Vetter43968d72016-09-21 10:59:24 +0200246 *
247 * RETURNS:
248 *
249 * 0 on success or a negative error code on failure.
250 */
251 int (*set_property)(struct drm_plane *plane,
252 struct drm_property *property, uint64_t val);
253
254 /**
255 * @atomic_duplicate_state:
256 *
257 * Duplicate the current atomic state for this plane and return it.
Daniel Vetterd5745282017-01-25 07:26:45 +0100258 * The core and helpers guarantee that any atomic state duplicated with
Daniel Vetter43968d72016-09-21 10:59:24 +0200259 * this hook and still owned by the caller (i.e. not transferred to the
Daniel Vetterd5745282017-01-25 07:26:45 +0100260 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
261 * cleaned up by calling the @atomic_destroy_state hook in this
262 * structure.
Daniel Vetter43968d72016-09-21 10:59:24 +0200263 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100264 * Atomic drivers which don't subclass &struct drm_plane_state should use
Daniel Vetter43968d72016-09-21 10:59:24 +0200265 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
266 * state structure to extend it with driver-private state should use
267 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
268 * duplicated in a consistent fashion across drivers.
269 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100270 * It is an error to call this hook before &drm_plane.state has been
Daniel Vetter43968d72016-09-21 10:59:24 +0200271 * initialized correctly.
272 *
273 * NOTE:
274 *
275 * If the duplicate state references refcounted resources this hook must
276 * acquire a reference for each of them. The driver must release these
277 * references again in @atomic_destroy_state.
278 *
279 * RETURNS:
280 *
281 * Duplicated atomic state or NULL when the allocation failed.
282 */
283 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
284
285 /**
286 * @atomic_destroy_state:
287 *
288 * Destroy a state duplicated with @atomic_duplicate_state and release
289 * or unreference all resources it references
290 */
291 void (*atomic_destroy_state)(struct drm_plane *plane,
292 struct drm_plane_state *state);
293
294 /**
295 * @atomic_set_property:
296 *
297 * Decode a driver-private property value and store the decoded value
298 * into the passed-in state structure. Since the atomic core decodes all
299 * standardized properties (even for extensions beyond the core set of
300 * properties which might not be implemented by all drivers) this
301 * requires drivers to subclass the state structure.
302 *
303 * Such driver-private properties should really only be implemented for
304 * truly hardware/vendor specific state. Instead it is preferred to
305 * standardize atomic extension and decode the properties used to expose
306 * such an extension in the core.
307 *
308 * Do not call this function directly, use
309 * drm_atomic_plane_set_property() instead.
310 *
311 * This callback is optional if the driver does not support any
312 * driver-private atomic properties.
313 *
314 * NOTE:
315 *
316 * This function is called in the state assembly phase of atomic
317 * modesets, which can be aborted for any reason (including on
318 * userspace's request to just check whether a configuration would be
319 * possible). Drivers MUST NOT touch any persistent state (hardware or
320 * software) or data structures except the passed in @state parameter.
321 *
322 * Also since userspace controls in which order properties are set this
323 * function must not do any input validation (since the state update is
324 * incomplete and hence likely inconsistent). Instead any such input
325 * validation must be done in the various atomic_check callbacks.
326 *
327 * RETURNS:
328 *
329 * 0 if the property has been found, -EINVAL if the property isn't
330 * implemented by the driver (which shouldn't ever happen, the core only
331 * asks for properties attached to this plane). No other validation is
332 * allowed by the driver. The core already checks that the property
333 * value is within the range (integer, valid enum value, ...) the driver
334 * set when registering the property.
335 */
336 int (*atomic_set_property)(struct drm_plane *plane,
337 struct drm_plane_state *state,
338 struct drm_property *property,
339 uint64_t val);
340
341 /**
342 * @atomic_get_property:
343 *
344 * Reads out the decoded driver-private property. This is used to
345 * implement the GETPLANE IOCTL.
346 *
347 * Do not call this function directly, use
348 * drm_atomic_plane_get_property() instead.
349 *
350 * This callback is optional if the driver does not support any
351 * driver-private atomic properties.
352 *
353 * RETURNS:
354 *
355 * 0 on success, -EINVAL if the property isn't implemented by the
356 * driver (which should never happen, the core only asks for
357 * properties attached to this plane).
358 */
359 int (*atomic_get_property)(struct drm_plane *plane,
360 const struct drm_plane_state *state,
361 struct drm_property *property,
362 uint64_t *val);
363 /**
364 * @late_register:
365 *
366 * This optional hook can be used to register additional userspace
367 * interfaces attached to the plane like debugfs interfaces.
368 * It is called late in the driver load sequence from drm_dev_register().
369 * Everything added from this callback should be unregistered in
370 * the early_unregister callback.
371 *
372 * Returns:
373 *
374 * 0 on success, or a negative error code on failure.
375 */
376 int (*late_register)(struct drm_plane *plane);
377
378 /**
379 * @early_unregister:
380 *
381 * This optional hook should be used to unregister the additional
382 * userspace interfaces attached to the plane from
Daniel Vetter559bdaf2017-01-25 07:26:55 +0100383 * @late_register. It is called from drm_dev_unregister(),
Daniel Vetter43968d72016-09-21 10:59:24 +0200384 * early in the driver unload sequence to disable userspace access
385 * before data structures are torndown.
386 */
387 void (*early_unregister)(struct drm_plane *plane);
Rob Clarkfceffb322016-11-05 11:08:09 -0400388
389 /**
390 * @atomic_print_state:
391 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100392 * If driver subclasses &struct drm_plane_state, it should implement
Rob Clarkfceffb322016-11-05 11:08:09 -0400393 * this optional hook for printing additional driver specific state.
394 *
395 * Do not call this directly, use drm_atomic_plane_print_state()
396 * instead.
397 */
398 void (*atomic_print_state)(struct drm_printer *p,
399 const struct drm_plane_state *state);
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700400
401 /**
402 * @format_mod_supported:
403 *
404 * This optional hook is used for the DRM to determine if the given
405 * format/modifier combination is valid for the plane. This allows the
406 * DRM to generate the correct format bitmask (which formats apply to
407 * which modifier).
408 *
409 * Returns:
410 *
411 * True if the given modifier is valid for that format on the plane.
412 * False otherwise.
413 */
414 bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
415 uint64_t modifier);
Daniel Vetter43968d72016-09-21 10:59:24 +0200416};
417
Daniel Vetter532b3672016-09-21 10:59:25 +0200418/**
419 * enum drm_plane_type - uapi plane type enumeration
420 *
421 * For historical reasons not all planes are made the same. This enumeration is
422 * used to tell the different types of planes apart to implement the different
423 * uapi semantics for them. For userspace which is universal plane aware and
424 * which is using that atomic IOCTL there's no difference between these planes
425 * (beyong what the driver and hardware can support of course).
426 *
427 * For compatibility with legacy userspace, only overlay planes are made
428 * available to userspace by default. Userspace clients may set the
429 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
430 * wish to receive a universal plane list containing all plane types. See also
431 * drm_for_each_legacy_plane().
Daniel Vetter226714d2016-09-23 08:35:25 +0200432 *
433 * WARNING: The values of this enum is UABI since they're exposed in the "type"
434 * property.
Daniel Vetter532b3672016-09-21 10:59:25 +0200435 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200436enum drm_plane_type {
Daniel Vetter532b3672016-09-21 10:59:25 +0200437 /**
Daniel Vetter226714d2016-09-23 08:35:25 +0200438 * @DRM_PLANE_TYPE_OVERLAY:
439 *
440 * Overlay planes represent all non-primary, non-cursor planes. Some
441 * drivers refer to these types of planes as "sprites" internally.
442 */
443 DRM_PLANE_TYPE_OVERLAY,
444
445 /**
Daniel Vetter532b3672016-09-21 10:59:25 +0200446 * @DRM_PLANE_TYPE_PRIMARY:
447 *
448 * Primary planes represent a "main" plane for a CRTC. Primary planes
449 * are the planes operated upon by CRTC modesetting and flipping
Daniel Vetterd5745282017-01-25 07:26:45 +0100450 * operations described in the &drm_crtc_funcs.page_flip and
451 * &drm_crtc_funcs.set_config hooks.
Daniel Vetter532b3672016-09-21 10:59:25 +0200452 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200453 DRM_PLANE_TYPE_PRIMARY,
Daniel Vetter532b3672016-09-21 10:59:25 +0200454
455 /**
456 * @DRM_PLANE_TYPE_CURSOR:
457 *
458 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
459 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
460 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
461 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200462 DRM_PLANE_TYPE_CURSOR,
463};
464
465
466/**
467 * struct drm_plane - central DRM plane control structure
468 * @dev: DRM device this plane belongs to
469 * @head: for list management
470 * @name: human readable name, can be overwritten by the driver
471 * @base: base mode object
472 * @possible_crtcs: pipes this plane can be bound to
473 * @format_types: array of formats supported by this plane
474 * @format_count: number of formats supported
475 * @format_default: driver hasn't supplied supported formats for the plane
476 * @crtc: currently bound CRTC
477 * @fb: currently bound fb
478 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
479 * drm_mode_set_config_internal() to implement correct refcounting.
480 * @funcs: helper functions
481 * @properties: property tracking for this plane
482 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter43968d72016-09-21 10:59:24 +0200483 * @zpos_property: zpos property for this plane
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300484 * @rotation_property: rotation property for this plane
Daniel Vetter43968d72016-09-21 10:59:24 +0200485 * @helper_private: mid-layer private data
486 */
487struct drm_plane {
488 struct drm_device *dev;
489 struct list_head head;
490
491 char *name;
492
493 /**
494 * @mutex:
495 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100496 * Protects modeset plane state, together with the &drm_crtc.mutex of
497 * CRTC this plane is linked to (when active, getting activated or
498 * getting disabled).
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200499 *
500 * For atomic drivers specifically this protects @state.
Daniel Vetter43968d72016-09-21 10:59:24 +0200501 */
502 struct drm_modeset_lock mutex;
503
504 struct drm_mode_object base;
505
506 uint32_t possible_crtcs;
507 uint32_t *format_types;
508 unsigned int format_count;
509 bool format_default;
510
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700511 uint64_t *modifiers;
512 unsigned int modifier_count;
513
Daniel Vetter43968d72016-09-21 10:59:24 +0200514 struct drm_crtc *crtc;
515 struct drm_framebuffer *fb;
516
517 struct drm_framebuffer *old_fb;
518
519 const struct drm_plane_funcs *funcs;
520
521 struct drm_object_properties properties;
522
523 enum drm_plane_type type;
524
525 /**
526 * @index: Position inside the mode_config.list, can be used as an array
527 * index. It is invariant over the lifetime of the plane.
528 */
529 unsigned index;
530
531 const struct drm_plane_helper_funcs *helper_private;
532
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200533 /**
534 * @state:
535 *
536 * Current atomic state for this plane.
537 *
538 * This is protected by @mutex. Note that nonblocking atomic commits
539 * access the current plane state without taking locks. Either by going
540 * through the &struct drm_atomic_state pointers, see
541 * for_each_plane_in_state(), for_each_oldnew_plane_in_state(),
542 * for_each_old_plane_in_state() and for_each_new_plane_in_state(). Or
543 * through careful ordering of atomic commit operations as implemented
544 * in the atomic helpers, see &struct drm_crtc_commit.
545 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200546 struct drm_plane_state *state;
547
548 struct drm_property *zpos_property;
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300549 struct drm_property *rotation_property;
Daniel Vetter43968d72016-09-21 10:59:24 +0200550};
551
552#define obj_to_plane(x) container_of(x, struct drm_plane, base)
553
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700554__printf(9, 10)
Daniel Vetter43968d72016-09-21 10:59:24 +0200555int drm_universal_plane_init(struct drm_device *dev,
556 struct drm_plane *plane,
Tomi Valkeinen5cd57a42016-12-02 15:45:35 +0200557 uint32_t possible_crtcs,
Daniel Vetter43968d72016-09-21 10:59:24 +0200558 const struct drm_plane_funcs *funcs,
559 const uint32_t *formats,
560 unsigned int format_count,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700561 const uint64_t *format_modifiers,
Daniel Vetter43968d72016-09-21 10:59:24 +0200562 enum drm_plane_type type,
563 const char *name, ...);
Daniel Vetter91faa042017-03-22 09:36:02 +0100564int drm_plane_init(struct drm_device *dev,
565 struct drm_plane *plane,
566 uint32_t possible_crtcs,
567 const struct drm_plane_funcs *funcs,
568 const uint32_t *formats, unsigned int format_count,
569 bool is_primary);
570void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200571
572/**
573 * drm_plane_index - find the index of a registered plane
574 * @plane: plane to find index for
575 *
576 * Given a registered plane, return the index of that plane within a DRM
577 * device's list of planes.
578 */
579static inline unsigned int drm_plane_index(struct drm_plane *plane)
580{
581 return plane->index;
582}
Daniel Vetter91faa042017-03-22 09:36:02 +0100583struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
584void drm_plane_force_disable(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200585
586int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
587 struct drm_property *property,
588 uint64_t value);
589
590/**
591 * drm_plane_find - find a &drm_plane
592 * @dev: DRM device
593 * @id: plane id
594 *
595 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
596 * drm_mode_object_find().
597 */
598static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
599 uint32_t id)
600{
601 struct drm_mode_object *mo;
602 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
603 return mo ? obj_to_plane(mo) : NULL;
604}
605
606/**
607 * drm_for_each_plane_mask - iterate over planes specified by bitmask
608 * @plane: the loop cursor
609 * @dev: the DRM device
610 * @plane_mask: bitmask of plane indices
611 *
612 * Iterate over all planes specified by bitmask.
613 */
614#define drm_for_each_plane_mask(plane, dev, plane_mask) \
615 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
616 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
617
Daniel Vetter532b3672016-09-21 10:59:25 +0200618/**
619 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
620 * @plane: the loop cursor
621 * @dev: the DRM device
622 *
623 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
624 * This is useful for implementing userspace apis when userspace is not
Daniel Vetterd5745282017-01-25 07:26:45 +0100625 * universal plane aware. See also &enum drm_plane_type.
Daniel Vetter532b3672016-09-21 10:59:25 +0200626 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200627#define drm_for_each_legacy_plane(plane, dev) \
628 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
629 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
630
Daniel Vetter532b3672016-09-21 10:59:25 +0200631/**
632 * drm_for_each_plane - iterate over all planes
633 * @plane: the loop cursor
634 * @dev: the DRM device
635 *
636 * Iterate over all planes of @dev, include primary and cursor planes.
637 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200638#define drm_for_each_plane(plane, dev) \
639 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
640
641
642#endif