Linux Audio

Check our new training course

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