blob: f7bf4a48b1c3dfd56f6db5f445317883ccfd813c [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>
Jyri Sarha80f690e2018-02-19 22:28:23 +020029#include <drm/drm_color_mgmt.h>
Daniel Vetter43968d72016-09-21 10:59:24 +020030
31struct drm_crtc;
Rob Clarkfceffb322016-11-05 11:08:09 -040032struct drm_printer;
Daniel Vetter34a2ab52017-03-22 22:50:41 +010033struct drm_modeset_acquire_ctx;
Daniel Vetter43968d72016-09-21 10:59:24 +020034
35/**
36 * struct drm_plane_state - mutable plane state
37 * @plane: backpointer to the plane
Daniel Vetter43968d72016-09-21 10:59:24 +020038 * @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)
46 * @rotation: rotation of the plane
47 * @zpos: priority of the given plane on crtc (optional)
Ville Syrjälä38d868e2016-10-10 17:50:56 +030048 * Note that multiple active planes on the same crtc can have an identical
49 * zpos value. The rule to solving the conflict is to compare the plane
50 * object IDs; the plane with a higher ID must be stacked on top of a
51 * plane with a lower ID.
Daniel Vetter43968d72016-09-21 10:59:24 +020052 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
Ville Syrjälä38d868e2016-10-10 17:50:56 +030053 * where N is the number of active planes for given crtc. Note that
54 * the driver must call drm_atomic_normalize_zpos() to update this before
55 * it can be trusted.
Daniel Vetter43968d72016-09-21 10:59:24 +020056 * @src: clipped source coordinates of the plane (in 16.16)
57 * @dst: clipped destination coordinates of the plane
Daniel Vetter43968d72016-09-21 10:59:24 +020058 * @state: backpointer to global drm_atomic_state
59 */
60struct drm_plane_state {
61 struct drm_plane *plane;
62
Gustavo Padovan3835b462016-11-07 19:03:33 +090063 /**
64 * @crtc:
65 *
66 * Currently bound CRTC, NULL if disabled. Do not this write directly,
67 * use drm_atomic_set_crtc_for_plane()
68 */
69 struct drm_crtc *crtc;
Daniel Vetter43968d72016-09-21 10:59:24 +020070
Gustavo Padovan3835b462016-11-07 19:03:33 +090071 /**
72 * @fb:
73 *
74 * Currently bound framebuffer. Do not write this directly, use
75 * drm_atomic_set_fb_for_plane()
76 */
77 struct drm_framebuffer *fb;
78
79 /**
80 * @fence:
81 *
82 * Optional fence to wait for before scanning out @fb. Do not write this
83 * directly, use drm_atomic_set_fence_for_plane()
84 */
Daniel Vetter43968d72016-09-21 10:59:24 +020085 struct dma_fence *fence;
86
Gustavo Padovan3835b462016-11-07 19:03:33 +090087 /**
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
Daniel Vetter43968d72016-09-21 10:59:24 +0200103 uint32_t crtc_w, crtc_h;
104
105 /* Source values are 16.16 fixed point */
106 uint32_t src_x, src_y;
107 uint32_t src_h, src_w;
108
109 /* Plane rotation */
110 unsigned int rotation;
111
112 /* Plane zpos */
113 unsigned int zpos;
114 unsigned int normalized_zpos;
115
Jyri Sarha80f690e2018-02-19 22:28:23 +0200116 /**
117 * @color_encoding:
118 *
119 * Color encoding for non RGB formats
120 */
121 enum drm_color_encoding color_encoding;
122
123 /**
124 * @color_range:
125 *
126 * Color range for non RGB formats
127 */
128 enum drm_color_range color_range;
129
Daniel Vetter43968d72016-09-21 10:59:24 +0200130 /* Clipped coordinates */
131 struct drm_rect src, dst;
132
Gustavo Padovan3835b462016-11-07 19:03:33 +0900133 /**
134 * @visible:
135 *
136 * Visibility of the plane. This can be false even if fb!=NULL and
137 * crtc!=NULL, due to clipping.
Daniel Vetter43968d72016-09-21 10:59:24 +0200138 */
139 bool visible;
140
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200141 /**
Maarten Lankhorst669c9212017-09-04 12:48:38 +0200142 * @commit: Tracks the pending commit to prevent use-after-free conditions,
143 * and for async plane updates.
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200144 *
Maarten Lankhorst669c9212017-09-04 12:48:38 +0200145 * May be NULL.
Maarten Lankhorst21a01ab2017-09-04 12:48:37 +0200146 */
147 struct drm_crtc_commit *commit;
148
Daniel Vetter43968d72016-09-21 10:59:24 +0200149 struct drm_atomic_state *state;
150};
151
Rob Clark1638d302016-11-05 11:08:08 -0400152static inline struct drm_rect
153drm_plane_state_src(const struct drm_plane_state *state)
154{
155 struct drm_rect src = {
156 .x1 = state->src_x,
157 .y1 = state->src_y,
158 .x2 = state->src_x + state->src_w,
159 .y2 = state->src_y + state->src_h,
160 };
161 return src;
162}
163
164static inline struct drm_rect
165drm_plane_state_dest(const struct drm_plane_state *state)
166{
167 struct drm_rect dest = {
168 .x1 = state->crtc_x,
169 .y1 = state->crtc_y,
170 .x2 = state->crtc_x + state->crtc_w,
171 .y2 = state->crtc_y + state->crtc_h,
172 };
173 return dest;
174}
175
Daniel Vetter43968d72016-09-21 10:59:24 +0200176/**
177 * struct drm_plane_funcs - driver plane control functions
178 */
179struct drm_plane_funcs {
180 /**
181 * @update_plane:
182 *
183 * This is the legacy entry point to enable and configure the plane for
184 * the given CRTC and framebuffer. It is never called to disable the
185 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
186 *
187 * The source rectangle in frame buffer memory coordinates is given by
188 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
189 * values). Devices that don't support subpixel plane coordinates can
190 * ignore the fractional part.
191 *
192 * The destination rectangle in CRTC coordinates is given by the
193 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
194 * Devices scale the source rectangle to the destination rectangle. If
195 * scaling is not supported, and the source rectangle size doesn't match
196 * the destination rectangle size, the driver must return a
197 * -<errorname>EINVAL</errorname> error.
198 *
199 * Drivers implementing atomic modeset should use
200 * drm_atomic_helper_update_plane() to implement this hook.
201 *
202 * RETURNS:
203 *
204 * 0 on success or a negative error code on failure.
205 */
206 int (*update_plane)(struct drm_plane *plane,
207 struct drm_crtc *crtc, struct drm_framebuffer *fb,
208 int crtc_x, int crtc_y,
209 unsigned int crtc_w, unsigned int crtc_h,
210 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100211 uint32_t src_w, uint32_t src_h,
212 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200213
214 /**
215 * @disable_plane:
216 *
217 * This is the legacy entry point to disable the plane. The DRM core
218 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
219 * with the frame buffer ID set to 0. Disabled planes must not be
220 * processed by the CRTC.
221 *
222 * Drivers implementing atomic modeset should use
223 * drm_atomic_helper_disable_plane() to implement this hook.
224 *
225 * RETURNS:
226 *
227 * 0 on success or a negative error code on failure.
228 */
Daniel Vetter19315292017-03-22 22:50:43 +0100229 int (*disable_plane)(struct drm_plane *plane,
230 struct drm_modeset_acquire_ctx *ctx);
Daniel Vetter43968d72016-09-21 10:59:24 +0200231
232 /**
233 * @destroy:
234 *
235 * Clean up plane resources. This is only called at driver unload time
236 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
237 * in DRM.
238 */
239 void (*destroy)(struct drm_plane *plane);
240
241 /**
242 * @reset:
243 *
244 * Reset plane hardware and software state to off. This function isn't
245 * called by the core directly, only through drm_mode_config_reset().
246 * It's not a helper hook only for historical reasons.
247 *
248 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
249 * atomic state using this hook.
250 */
251 void (*reset)(struct drm_plane *plane);
252
253 /**
254 * @set_property:
255 *
256 * This is the legacy entry point to update a property attached to the
257 * plane.
258 *
Daniel Vetter43968d72016-09-21 10:59:24 +0200259 * This callback is optional if the driver does not support any legacy
Daniel Vetter144a7992017-07-25 14:02:04 +0200260 * driver-private properties. For atomic drivers it is not used because
261 * property handling is done entirely in the DRM core.
Daniel Vetter43968d72016-09-21 10:59:24 +0200262 *
263 * RETURNS:
264 *
265 * 0 on success or a negative error code on failure.
266 */
267 int (*set_property)(struct drm_plane *plane,
268 struct drm_property *property, uint64_t val);
269
270 /**
271 * @atomic_duplicate_state:
272 *
273 * Duplicate the current atomic state for this plane and return it.
Daniel Vetterd5745282017-01-25 07:26:45 +0100274 * The core and helpers guarantee that any atomic state duplicated with
Daniel Vetter43968d72016-09-21 10:59:24 +0200275 * this hook and still owned by the caller (i.e. not transferred to the
Daniel Vetterd5745282017-01-25 07:26:45 +0100276 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
277 * cleaned up by calling the @atomic_destroy_state hook in this
278 * structure.
Daniel Vetter43968d72016-09-21 10:59:24 +0200279 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100280 * Atomic drivers which don't subclass &struct drm_plane_state should use
Daniel Vetter43968d72016-09-21 10:59:24 +0200281 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
282 * state structure to extend it with driver-private state should use
283 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
284 * duplicated in a consistent fashion across drivers.
285 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100286 * It is an error to call this hook before &drm_plane.state has been
Daniel Vetter43968d72016-09-21 10:59:24 +0200287 * initialized correctly.
288 *
289 * NOTE:
290 *
291 * If the duplicate state references refcounted resources this hook must
292 * acquire a reference for each of them. The driver must release these
293 * references again in @atomic_destroy_state.
294 *
295 * RETURNS:
296 *
297 * Duplicated atomic state or NULL when the allocation failed.
298 */
299 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
300
301 /**
302 * @atomic_destroy_state:
303 *
304 * Destroy a state duplicated with @atomic_duplicate_state and release
305 * or unreference all resources it references
306 */
307 void (*atomic_destroy_state)(struct drm_plane *plane,
308 struct drm_plane_state *state);
309
310 /**
311 * @atomic_set_property:
312 *
313 * Decode a driver-private property value and store the decoded value
314 * into the passed-in state structure. Since the atomic core decodes all
315 * standardized properties (even for extensions beyond the core set of
316 * properties which might not be implemented by all drivers) this
317 * requires drivers to subclass the state structure.
318 *
319 * Such driver-private properties should really only be implemented for
320 * truly hardware/vendor specific state. Instead it is preferred to
321 * standardize atomic extension and decode the properties used to expose
322 * such an extension in the core.
323 *
324 * Do not call this function directly, use
325 * drm_atomic_plane_set_property() instead.
326 *
327 * This callback is optional if the driver does not support any
328 * driver-private atomic properties.
329 *
330 * NOTE:
331 *
332 * This function is called in the state assembly phase of atomic
333 * modesets, which can be aborted for any reason (including on
334 * userspace's request to just check whether a configuration would be
335 * possible). Drivers MUST NOT touch any persistent state (hardware or
336 * software) or data structures except the passed in @state parameter.
337 *
338 * Also since userspace controls in which order properties are set this
339 * function must not do any input validation (since the state update is
340 * incomplete and hence likely inconsistent). Instead any such input
341 * validation must be done in the various atomic_check callbacks.
342 *
343 * RETURNS:
344 *
345 * 0 if the property has been found, -EINVAL if the property isn't
346 * implemented by the driver (which shouldn't ever happen, the core only
347 * asks for properties attached to this plane). No other validation is
348 * allowed by the driver. The core already checks that the property
349 * value is within the range (integer, valid enum value, ...) the driver
350 * set when registering the property.
351 */
352 int (*atomic_set_property)(struct drm_plane *plane,
353 struct drm_plane_state *state,
354 struct drm_property *property,
355 uint64_t val);
356
357 /**
358 * @atomic_get_property:
359 *
360 * Reads out the decoded driver-private property. This is used to
361 * implement the GETPLANE IOCTL.
362 *
363 * Do not call this function directly, use
364 * drm_atomic_plane_get_property() instead.
365 *
366 * This callback is optional if the driver does not support any
367 * driver-private atomic properties.
368 *
369 * RETURNS:
370 *
371 * 0 on success, -EINVAL if the property isn't implemented by the
372 * driver (which should never happen, the core only asks for
373 * properties attached to this plane).
374 */
375 int (*atomic_get_property)(struct drm_plane *plane,
376 const struct drm_plane_state *state,
377 struct drm_property *property,
378 uint64_t *val);
379 /**
380 * @late_register:
381 *
382 * This optional hook can be used to register additional userspace
383 * interfaces attached to the plane like debugfs interfaces.
384 * It is called late in the driver load sequence from drm_dev_register().
385 * Everything added from this callback should be unregistered in
386 * the early_unregister callback.
387 *
388 * Returns:
389 *
390 * 0 on success, or a negative error code on failure.
391 */
392 int (*late_register)(struct drm_plane *plane);
393
394 /**
395 * @early_unregister:
396 *
397 * This optional hook should be used to unregister the additional
398 * userspace interfaces attached to the plane from
Daniel Vetter559bdaf2017-01-25 07:26:55 +0100399 * @late_register. It is called from drm_dev_unregister(),
Daniel Vetter43968d72016-09-21 10:59:24 +0200400 * early in the driver unload sequence to disable userspace access
401 * before data structures are torndown.
402 */
403 void (*early_unregister)(struct drm_plane *plane);
Rob Clarkfceffb322016-11-05 11:08:09 -0400404
405 /**
406 * @atomic_print_state:
407 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100408 * If driver subclasses &struct drm_plane_state, it should implement
Rob Clarkfceffb322016-11-05 11:08:09 -0400409 * this optional hook for printing additional driver specific state.
410 *
411 * Do not call this directly, use drm_atomic_plane_print_state()
412 * instead.
413 */
414 void (*atomic_print_state)(struct drm_printer *p,
415 const struct drm_plane_state *state);
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700416
417 /**
418 * @format_mod_supported:
419 *
420 * This optional hook is used for the DRM to determine if the given
421 * format/modifier combination is valid for the plane. This allows the
422 * DRM to generate the correct format bitmask (which formats apply to
423 * which modifier).
424 *
425 * Returns:
426 *
427 * True if the given modifier is valid for that format on the plane.
428 * False otherwise.
429 */
430 bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
431 uint64_t modifier);
Daniel Vetter43968d72016-09-21 10:59:24 +0200432};
433
Daniel Vetter532b3672016-09-21 10:59:25 +0200434/**
435 * enum drm_plane_type - uapi plane type enumeration
436 *
437 * For historical reasons not all planes are made the same. This enumeration is
438 * used to tell the different types of planes apart to implement the different
439 * uapi semantics for them. For userspace which is universal plane aware and
440 * which is using that atomic IOCTL there's no difference between these planes
441 * (beyong what the driver and hardware can support of course).
442 *
443 * For compatibility with legacy userspace, only overlay planes are made
444 * available to userspace by default. Userspace clients may set the
445 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
446 * wish to receive a universal plane list containing all plane types. See also
447 * drm_for_each_legacy_plane().
Daniel Vetter226714d2016-09-23 08:35:25 +0200448 *
449 * WARNING: The values of this enum is UABI since they're exposed in the "type"
450 * property.
Daniel Vetter532b3672016-09-21 10:59:25 +0200451 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200452enum drm_plane_type {
Daniel Vetter532b3672016-09-21 10:59:25 +0200453 /**
Daniel Vetter226714d2016-09-23 08:35:25 +0200454 * @DRM_PLANE_TYPE_OVERLAY:
455 *
456 * Overlay planes represent all non-primary, non-cursor planes. Some
457 * drivers refer to these types of planes as "sprites" internally.
458 */
459 DRM_PLANE_TYPE_OVERLAY,
460
461 /**
Daniel Vetter532b3672016-09-21 10:59:25 +0200462 * @DRM_PLANE_TYPE_PRIMARY:
463 *
464 * Primary planes represent a "main" plane for a CRTC. Primary planes
465 * are the planes operated upon by CRTC modesetting and flipping
Daniel Vetterd5745282017-01-25 07:26:45 +0100466 * operations described in the &drm_crtc_funcs.page_flip and
467 * &drm_crtc_funcs.set_config hooks.
Daniel Vetter532b3672016-09-21 10:59:25 +0200468 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200469 DRM_PLANE_TYPE_PRIMARY,
Daniel Vetter532b3672016-09-21 10:59:25 +0200470
471 /**
472 * @DRM_PLANE_TYPE_CURSOR:
473 *
474 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
475 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
476 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
477 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200478 DRM_PLANE_TYPE_CURSOR,
479};
480
481
482/**
483 * struct drm_plane - central DRM plane control structure
484 * @dev: DRM device this plane belongs to
485 * @head: for list management
486 * @name: human readable name, can be overwritten by the driver
487 * @base: base mode object
488 * @possible_crtcs: pipes this plane can be bound to
489 * @format_types: array of formats supported by this plane
490 * @format_count: number of formats supported
491 * @format_default: driver hasn't supplied supported formats for the plane
Ville Syrjälä3df67452017-11-14 21:10:21 +0200492 * @modifiers: array of modifiers supported by this plane
493 * @modifier_count: number of modifiers supported
Daniel Vetter43968d72016-09-21 10:59:24 +0200494 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
495 * drm_mode_set_config_internal() to implement correct refcounting.
496 * @funcs: helper functions
497 * @properties: property tracking for this plane
498 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter43968d72016-09-21 10:59:24 +0200499 * @zpos_property: zpos property for this plane
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300500 * @rotation_property: rotation property for this plane
Daniel Vetter43968d72016-09-21 10:59:24 +0200501 * @helper_private: mid-layer private data
502 */
503struct drm_plane {
504 struct drm_device *dev;
505 struct list_head head;
506
507 char *name;
508
509 /**
510 * @mutex:
511 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100512 * Protects modeset plane state, together with the &drm_crtc.mutex of
513 * CRTC this plane is linked to (when active, getting activated or
514 * getting disabled).
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200515 *
516 * For atomic drivers specifically this protects @state.
Daniel Vetter43968d72016-09-21 10:59:24 +0200517 */
518 struct drm_modeset_lock mutex;
519
520 struct drm_mode_object base;
521
522 uint32_t possible_crtcs;
523 uint32_t *format_types;
524 unsigned int format_count;
525 bool format_default;
526
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700527 uint64_t *modifiers;
528 unsigned int modifier_count;
529
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100530 /**
531 * @crtc: Currently bound CRTC, only really meaningful for non-atomic
532 * drivers. Atomic drivers should instead check &drm_plane_state.crtc.
533 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200534 struct drm_crtc *crtc;
Daniel Vetter2e2b96e2017-11-08 21:30:07 +0100535
536 /**
537 * @fb: Currently bound framebuffer, only really meaningful for
538 * non-atomic drivers. Atomic drivers should instead check
539 * &drm_plane_state.fb.
540 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200541 struct drm_framebuffer *fb;
542
543 struct drm_framebuffer *old_fb;
544
545 const struct drm_plane_funcs *funcs;
546
547 struct drm_object_properties properties;
548
549 enum drm_plane_type type;
550
551 /**
552 * @index: Position inside the mode_config.list, can be used as an array
553 * index. It is invariant over the lifetime of the plane.
554 */
555 unsigned index;
556
557 const struct drm_plane_helper_funcs *helper_private;
558
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200559 /**
560 * @state:
561 *
562 * Current atomic state for this plane.
563 *
564 * This is protected by @mutex. Note that nonblocking atomic commits
565 * access the current plane state without taking locks. Either by going
566 * through the &struct drm_atomic_state pointers, see
Maarten Lankhorst77ac3b02017-07-19 16:39:20 +0200567 * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
568 * for_each_new_plane_in_state(). Or through careful ordering of atomic
569 * commit operations as implemented in the atomic helpers, see
570 * &struct drm_crtc_commit.
Daniel Vetterc9e42b72017-03-28 17:53:48 +0200571 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200572 struct drm_plane_state *state;
573
574 struct drm_property *zpos_property;
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300575 struct drm_property *rotation_property;
Jyri Sarha80f690e2018-02-19 22:28:23 +0200576
577 /**
578 * @color_encoding_property:
579 *
580 * Optional "COLOR_ENCODING" enum property for specifying
581 * color encoding for non RGB formats.
582 * See drm_plane_create_color_properties().
583 */
584 struct drm_property *color_encoding_property;
585 /**
586 * @color_range_property:
587 *
588 * Optional "COLOR_RANGE" enum property for specifying
589 * color range for non RGB formats.
590 * See drm_plane_create_color_properties().
591 */
592 struct drm_property *color_range_property;
Daniel Vetter43968d72016-09-21 10:59:24 +0200593};
594
595#define obj_to_plane(x) container_of(x, struct drm_plane, base)
596
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700597__printf(9, 10)
Daniel Vetter43968d72016-09-21 10:59:24 +0200598int drm_universal_plane_init(struct drm_device *dev,
599 struct drm_plane *plane,
Tomi Valkeinen5cd57a42016-12-02 15:45:35 +0200600 uint32_t possible_crtcs,
Daniel Vetter43968d72016-09-21 10:59:24 +0200601 const struct drm_plane_funcs *funcs,
602 const uint32_t *formats,
603 unsigned int format_count,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700604 const uint64_t *format_modifiers,
Daniel Vetter43968d72016-09-21 10:59:24 +0200605 enum drm_plane_type type,
606 const char *name, ...);
Daniel Vetter91faa0472017-03-22 09:36:02 +0100607int drm_plane_init(struct drm_device *dev,
608 struct drm_plane *plane,
609 uint32_t possible_crtcs,
610 const struct drm_plane_funcs *funcs,
611 const uint32_t *formats, unsigned int format_count,
612 bool is_primary);
613void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200614
615/**
616 * drm_plane_index - find the index of a registered plane
617 * @plane: plane to find index for
618 *
619 * Given a registered plane, return the index of that plane within a DRM
620 * device's list of planes.
621 */
622static inline unsigned int drm_plane_index(struct drm_plane *plane)
623{
624 return plane->index;
625}
Daniel Vetter91faa0472017-03-22 09:36:02 +0100626struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
627void drm_plane_force_disable(struct drm_plane *plane);
Daniel Vetter43968d72016-09-21 10:59:24 +0200628
629int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
630 struct drm_property *property,
631 uint64_t value);
632
633/**
634 * drm_plane_find - find a &drm_plane
635 * @dev: DRM device
Dave Airliee7e62c72017-11-09 09:35:04 +1000636 * @file_priv: drm file to check for lease against.
Daniel Vetter43968d72016-09-21 10:59:24 +0200637 * @id: plane id
638 *
639 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
640 * drm_mode_object_find().
641 */
642static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
Keith Packard418da172017-03-14 23:25:07 -0700643 struct drm_file *file_priv,
Daniel Vetter43968d72016-09-21 10:59:24 +0200644 uint32_t id)
645{
646 struct drm_mode_object *mo;
Keith Packard418da172017-03-14 23:25:07 -0700647 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
Daniel Vetter43968d72016-09-21 10:59:24 +0200648 return mo ? obj_to_plane(mo) : NULL;
649}
650
651/**
652 * drm_for_each_plane_mask - iterate over planes specified by bitmask
653 * @plane: the loop cursor
654 * @dev: the DRM device
655 * @plane_mask: bitmask of plane indices
656 *
657 * Iterate over all planes specified by bitmask.
658 */
659#define drm_for_each_plane_mask(plane, dev, plane_mask) \
660 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
661 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
662
Daniel Vetter532b3672016-09-21 10:59:25 +0200663/**
664 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
665 * @plane: the loop cursor
666 * @dev: the DRM device
667 *
668 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
669 * This is useful for implementing userspace apis when userspace is not
Daniel Vetterd5745282017-01-25 07:26:45 +0100670 * universal plane aware. See also &enum drm_plane_type.
Daniel Vetter532b3672016-09-21 10:59:25 +0200671 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200672#define drm_for_each_legacy_plane(plane, dev) \
673 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
674 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
675
Daniel Vetter532b3672016-09-21 10:59:25 +0200676/**
677 * drm_for_each_plane - iterate over all planes
678 * @plane: the loop cursor
679 * @dev: the DRM device
680 *
681 * Iterate over all planes of @dev, include primary and cursor planes.
682 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200683#define drm_for_each_plane(plane, dev) \
684 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
685
686
687#endif