xref: /linux/include/drm/drm_gem_atomic_helper.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
16dd7b6ceSThomas Zimmermann /* SPDX-License-Identifier: GPL-2.0-or-later */
26dd7b6ceSThomas Zimmermann 
36dd7b6ceSThomas Zimmermann #ifndef __DRM_GEM_ATOMIC_HELPER_H__
46dd7b6ceSThomas Zimmermann #define __DRM_GEM_ATOMIC_HELPER_H__
56dd7b6ceSThomas Zimmermann 
67938f421SLucas De Marchi #include <linux/iosys-map.h>
76dd7b6ceSThomas Zimmermann 
8*90367458SThomas Zimmermann #include <drm/drm_format_helper.h>
9279cc2e9SThomas Zimmermann #include <drm/drm_fourcc.h>
106dd7b6ceSThomas Zimmermann #include <drm/drm_plane.h>
116dd7b6ceSThomas Zimmermann 
126dd7b6ceSThomas Zimmermann struct drm_simple_display_pipe;
136dd7b6ceSThomas Zimmermann 
146dd7b6ceSThomas Zimmermann /*
15820c1707SThomas Zimmermann  * Plane Helpers
16820c1707SThomas Zimmermann  */
17820c1707SThomas Zimmermann 
18820c1707SThomas Zimmermann int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
19820c1707SThomas Zimmermann 
20820c1707SThomas Zimmermann /*
216dd7b6ceSThomas Zimmermann  * Helpers for planes with shadow buffers
226dd7b6ceSThomas Zimmermann  */
236dd7b6ceSThomas Zimmermann 
246dd7b6ceSThomas Zimmermann /**
259239f3e1SThomas Zimmermann  * DRM_SHADOW_PLANE_MAX_WIDTH - Maximum width of a plane's shadow buffer in pixels
269239f3e1SThomas Zimmermann  *
279239f3e1SThomas Zimmermann  * For drivers with shadow planes, the maximum width of the framebuffer is
289239f3e1SThomas Zimmermann  * usually independent from hardware limitations. Drivers can initialize struct
299239f3e1SThomas Zimmermann  * drm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.
309239f3e1SThomas Zimmermann  */
319239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_WIDTH	(4096u)
329239f3e1SThomas Zimmermann 
339239f3e1SThomas Zimmermann /**
349239f3e1SThomas Zimmermann  * DRM_SHADOW_PLANE_MAX_HEIGHT - Maximum height of a plane's shadow buffer in scanlines
359239f3e1SThomas Zimmermann  *
369239f3e1SThomas Zimmermann  * For drivers with shadow planes, the maximum height of the framebuffer is
379239f3e1SThomas Zimmermann  * usually independent from hardware limitations. Drivers can initialize struct
389239f3e1SThomas Zimmermann  * drm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.
399239f3e1SThomas Zimmermann  */
409239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_HEIGHT	(4096u)
419239f3e1SThomas Zimmermann 
429239f3e1SThomas Zimmermann /**
436dd7b6ceSThomas Zimmermann  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
446dd7b6ceSThomas Zimmermann  *
456dd7b6ceSThomas Zimmermann  * For planes that use a shadow buffer, struct drm_shadow_plane_state
466dd7b6ceSThomas Zimmermann  * provides the regular plane state plus mappings of the shadow buffer
476dd7b6ceSThomas Zimmermann  * into kernel address space.
486dd7b6ceSThomas Zimmermann  */
496dd7b6ceSThomas Zimmermann struct drm_shadow_plane_state {
506dd7b6ceSThomas Zimmermann 	/** @base: plane state */
516dd7b6ceSThomas Zimmermann 	struct drm_plane_state base;
526dd7b6ceSThomas Zimmermann 
53*90367458SThomas Zimmermann 	/**
54*90367458SThomas Zimmermann 	 * @fmtcnv_state: Format-conversion state
55*90367458SThomas Zimmermann 	 *
56*90367458SThomas Zimmermann 	 * Per-plane state for format conversion.
57*90367458SThomas Zimmermann 	 * Flags for copying shadow buffers into backend storage. Also holds
58*90367458SThomas Zimmermann 	 * temporary storage for format conversion.
59*90367458SThomas Zimmermann 	 */
60*90367458SThomas Zimmermann 	struct drm_format_conv_state fmtcnv_state;
61*90367458SThomas Zimmermann 
626dd7b6ceSThomas Zimmermann 	/* Transitional state - do not export or duplicate */
636dd7b6ceSThomas Zimmermann 
646dd7b6ceSThomas Zimmermann 	/**
656dd7b6ceSThomas Zimmermann 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
666dd7b6ceSThomas Zimmermann 	 *
676dd7b6ceSThomas Zimmermann 	 * The memory mappings stored in map should be established in the plane's
686dd7b6ceSThomas Zimmermann 	 * prepare_fb callback and removed in the cleanup_fb callback.
696dd7b6ceSThomas Zimmermann 	 */
707938f421SLucas De Marchi 	struct iosys_map map[DRM_FORMAT_MAX_PLANES];
7143b36232SThomas Zimmermann 
7243b36232SThomas Zimmermann 	/**
7343b36232SThomas Zimmermann 	 * @data: Address of each framebuffer BO's data
7443b36232SThomas Zimmermann 	 *
7543b36232SThomas Zimmermann 	 * The address of the data stored in each mapping. This is different
7643b36232SThomas Zimmermann 	 * for framebuffers with non-zero offset fields.
7743b36232SThomas Zimmermann 	 */
787938f421SLucas De Marchi 	struct iosys_map data[DRM_FORMAT_MAX_PLANES];
796dd7b6ceSThomas Zimmermann };
806dd7b6ceSThomas Zimmermann 
816dd7b6ceSThomas Zimmermann /**
826dd7b6ceSThomas Zimmermann  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
836dd7b6ceSThomas Zimmermann  * @state: the plane state
846dd7b6ceSThomas Zimmermann  */
856dd7b6ceSThomas Zimmermann static inline struct drm_shadow_plane_state *
to_drm_shadow_plane_state(struct drm_plane_state * state)866dd7b6ceSThomas Zimmermann to_drm_shadow_plane_state(struct drm_plane_state *state)
876dd7b6ceSThomas Zimmermann {
886dd7b6ceSThomas Zimmermann 	return container_of(state, struct drm_shadow_plane_state, base);
896dd7b6ceSThomas Zimmermann }
906dd7b6ceSThomas Zimmermann 
91b7156502SThomas Zimmermann void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
92b7156502SThomas Zimmermann 					    struct drm_shadow_plane_state *new_shadow_plane_state);
93b7156502SThomas Zimmermann void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
94b7156502SThomas Zimmermann void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
95b7156502SThomas Zimmermann 				  struct drm_shadow_plane_state *shadow_plane_state);
96b7156502SThomas Zimmermann 
979dc9067dSThomas Zimmermann void drm_gem_reset_shadow_plane(struct drm_plane *plane);
989dc9067dSThomas Zimmermann struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
999dc9067dSThomas Zimmermann void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
1009dc9067dSThomas Zimmermann 					struct drm_plane_state *plane_state);
1019dc9067dSThomas Zimmermann 
1029dc9067dSThomas Zimmermann /**
1039dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_FUNCS -
1049dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_funcs for shadow-buffered planes
1059dc9067dSThomas Zimmermann  *
1069dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1079dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_funcs to use the rsp helper functions.
1089dc9067dSThomas Zimmermann  */
1099dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_FUNCS \
1109dc9067dSThomas Zimmermann 	.reset = drm_gem_reset_shadow_plane, \
1119dc9067dSThomas Zimmermann 	.atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
1129dc9067dSThomas Zimmermann 	.atomic_destroy_state = drm_gem_destroy_shadow_plane_state
1139dc9067dSThomas Zimmermann 
114359c6649SThomas Zimmermann int drm_gem_begin_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
115359c6649SThomas Zimmermann void drm_gem_end_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
1169dc9067dSThomas Zimmermann 
1179dc9067dSThomas Zimmermann /**
1189dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
1199dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_helper_funcs for shadow-buffered planes
1209dc9067dSThomas Zimmermann  *
1219dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1229dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_helper_funcs to use the rsp helper
1239dc9067dSThomas Zimmermann  * functions.
1249dc9067dSThomas Zimmermann  */
1259dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
126359c6649SThomas Zimmermann 	.begin_fb_access = drm_gem_begin_shadow_fb_access, \
127359c6649SThomas Zimmermann 	.end_fb_access = drm_gem_end_shadow_fb_access
1289dc9067dSThomas Zimmermann 
129359c6649SThomas Zimmermann int drm_gem_simple_kms_begin_shadow_fb_access(struct drm_simple_display_pipe *pipe,
1306dd7b6ceSThomas Zimmermann 					      struct drm_plane_state *plane_state);
131359c6649SThomas Zimmermann void drm_gem_simple_kms_end_shadow_fb_access(struct drm_simple_display_pipe *pipe,
1326dd7b6ceSThomas Zimmermann 					     struct drm_plane_state *plane_state);
1336dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
1346dd7b6ceSThomas Zimmermann struct drm_plane_state *
1356dd7b6ceSThomas Zimmermann drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
1366dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
1376dd7b6ceSThomas Zimmermann 						   struct drm_plane_state *plane_state);
1386dd7b6ceSThomas Zimmermann 
1396dd7b6ceSThomas Zimmermann /**
1406dd7b6ceSThomas Zimmermann  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
1416dd7b6ceSThomas Zimmermann  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
1426dd7b6ceSThomas Zimmermann  *
1436dd7b6ceSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1446dd7b6ceSThomas Zimmermann  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
1456dd7b6ceSThomas Zimmermann  * functions.
1466dd7b6ceSThomas Zimmermann  */
1476dd7b6ceSThomas Zimmermann #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
148359c6649SThomas Zimmermann 	.begin_fb_access = drm_gem_simple_kms_begin_shadow_fb_access, \
149359c6649SThomas Zimmermann 	.end_fb_access = drm_gem_simple_kms_end_shadow_fb_access, \
1506dd7b6ceSThomas Zimmermann 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
1516dd7b6ceSThomas Zimmermann 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
1526dd7b6ceSThomas Zimmermann 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
1536dd7b6ceSThomas Zimmermann 
1546dd7b6ceSThomas Zimmermann #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
155