xref: /linux/include/drm/drm_gem_atomic_helper.h (revision 9239f3e1807c282e3c6bced510640910e9b25c60)
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 
66dd7b6ceSThomas Zimmermann #include <linux/dma-buf-map.h>
76dd7b6ceSThomas Zimmermann 
8279cc2e9SThomas Zimmermann #include <drm/drm_fourcc.h>
96dd7b6ceSThomas Zimmermann #include <drm/drm_plane.h>
106dd7b6ceSThomas Zimmermann 
116dd7b6ceSThomas Zimmermann struct drm_simple_display_pipe;
126dd7b6ceSThomas Zimmermann 
136dd7b6ceSThomas Zimmermann /*
14820c1707SThomas Zimmermann  * Plane Helpers
15820c1707SThomas Zimmermann  */
16820c1707SThomas Zimmermann 
17820c1707SThomas Zimmermann int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
18820c1707SThomas Zimmermann int drm_gem_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
19820c1707SThomas Zimmermann 					   struct drm_plane_state *plane_state);
20820c1707SThomas Zimmermann 
21820c1707SThomas Zimmermann /*
226dd7b6ceSThomas Zimmermann  * Helpers for planes with shadow buffers
236dd7b6ceSThomas Zimmermann  */
246dd7b6ceSThomas Zimmermann 
256dd7b6ceSThomas Zimmermann /**
26*9239f3e1SThomas Zimmermann  * DRM_SHADOW_PLANE_MAX_WIDTH - Maximum width of a plane's shadow buffer in pixels
27*9239f3e1SThomas Zimmermann  *
28*9239f3e1SThomas Zimmermann  * For drivers with shadow planes, the maximum width of the framebuffer is
29*9239f3e1SThomas Zimmermann  * usually independent from hardware limitations. Drivers can initialize struct
30*9239f3e1SThomas Zimmermann  * drm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.
31*9239f3e1SThomas Zimmermann  */
32*9239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_WIDTH	(4096u)
33*9239f3e1SThomas Zimmermann 
34*9239f3e1SThomas Zimmermann /**
35*9239f3e1SThomas Zimmermann  * DRM_SHADOW_PLANE_MAX_HEIGHT - Maximum height of a plane's shadow buffer in scanlines
36*9239f3e1SThomas Zimmermann  *
37*9239f3e1SThomas Zimmermann  * For drivers with shadow planes, the maximum height of the framebuffer is
38*9239f3e1SThomas Zimmermann  * usually independent from hardware limitations. Drivers can initialize struct
39*9239f3e1SThomas Zimmermann  * drm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.
40*9239f3e1SThomas Zimmermann  */
41*9239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_HEIGHT	(4096u)
42*9239f3e1SThomas Zimmermann 
43*9239f3e1SThomas Zimmermann /**
446dd7b6ceSThomas Zimmermann  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
456dd7b6ceSThomas Zimmermann  *
466dd7b6ceSThomas Zimmermann  * For planes that use a shadow buffer, struct drm_shadow_plane_state
476dd7b6ceSThomas Zimmermann  * provides the regular plane state plus mappings of the shadow buffer
486dd7b6ceSThomas Zimmermann  * into kernel address space.
496dd7b6ceSThomas Zimmermann  */
506dd7b6ceSThomas Zimmermann struct drm_shadow_plane_state {
516dd7b6ceSThomas Zimmermann 	/** @base: plane state */
526dd7b6ceSThomas Zimmermann 	struct drm_plane_state base;
536dd7b6ceSThomas Zimmermann 
546dd7b6ceSThomas Zimmermann 	/* Transitional state - do not export or duplicate */
556dd7b6ceSThomas Zimmermann 
566dd7b6ceSThomas Zimmermann 	/**
576dd7b6ceSThomas Zimmermann 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
586dd7b6ceSThomas Zimmermann 	 *
596dd7b6ceSThomas Zimmermann 	 * The memory mappings stored in map should be established in the plane's
606dd7b6ceSThomas Zimmermann 	 * prepare_fb callback and removed in the cleanup_fb callback.
616dd7b6ceSThomas Zimmermann 	 */
62279cc2e9SThomas Zimmermann 	struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
6343b36232SThomas Zimmermann 
6443b36232SThomas Zimmermann 	/**
6543b36232SThomas Zimmermann 	 * @data: Address of each framebuffer BO's data
6643b36232SThomas Zimmermann 	 *
6743b36232SThomas Zimmermann 	 * The address of the data stored in each mapping. This is different
6843b36232SThomas Zimmermann 	 * for framebuffers with non-zero offset fields.
6943b36232SThomas Zimmermann 	 */
7043b36232SThomas Zimmermann 	struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
716dd7b6ceSThomas Zimmermann };
726dd7b6ceSThomas Zimmermann 
736dd7b6ceSThomas Zimmermann /**
746dd7b6ceSThomas Zimmermann  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
756dd7b6ceSThomas Zimmermann  * @state: the plane state
766dd7b6ceSThomas Zimmermann  */
776dd7b6ceSThomas Zimmermann static inline struct drm_shadow_plane_state *
786dd7b6ceSThomas Zimmermann to_drm_shadow_plane_state(struct drm_plane_state *state)
796dd7b6ceSThomas Zimmermann {
806dd7b6ceSThomas Zimmermann 	return container_of(state, struct drm_shadow_plane_state, base);
816dd7b6ceSThomas Zimmermann }
826dd7b6ceSThomas Zimmermann 
83b7156502SThomas Zimmermann void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
84b7156502SThomas Zimmermann 					    struct drm_shadow_plane_state *new_shadow_plane_state);
85b7156502SThomas Zimmermann void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
86b7156502SThomas Zimmermann void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
87b7156502SThomas Zimmermann 				  struct drm_shadow_plane_state *shadow_plane_state);
88b7156502SThomas Zimmermann 
899dc9067dSThomas Zimmermann void drm_gem_reset_shadow_plane(struct drm_plane *plane);
909dc9067dSThomas Zimmermann struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
919dc9067dSThomas Zimmermann void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
929dc9067dSThomas Zimmermann 					struct drm_plane_state *plane_state);
939dc9067dSThomas Zimmermann 
949dc9067dSThomas Zimmermann /**
959dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_FUNCS -
969dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_funcs for shadow-buffered planes
979dc9067dSThomas Zimmermann  *
989dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
999dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_funcs to use the rsp helper functions.
1009dc9067dSThomas Zimmermann  */
1019dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_FUNCS \
1029dc9067dSThomas Zimmermann 	.reset = drm_gem_reset_shadow_plane, \
1039dc9067dSThomas Zimmermann 	.atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
1049dc9067dSThomas Zimmermann 	.atomic_destroy_state = drm_gem_destroy_shadow_plane_state
1059dc9067dSThomas Zimmermann 
1069dc9067dSThomas Zimmermann int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
1079dc9067dSThomas Zimmermann void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
1089dc9067dSThomas Zimmermann 
1099dc9067dSThomas Zimmermann /**
1109dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
1119dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_helper_funcs for shadow-buffered planes
1129dc9067dSThomas Zimmermann  *
1139dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1149dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_helper_funcs to use the rsp helper
1159dc9067dSThomas Zimmermann  * functions.
1169dc9067dSThomas Zimmermann  */
1179dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
1189dc9067dSThomas Zimmermann 	.prepare_fb = drm_gem_prepare_shadow_fb, \
1199dc9067dSThomas Zimmermann 	.cleanup_fb = drm_gem_cleanup_shadow_fb
1209dc9067dSThomas Zimmermann 
1216dd7b6ceSThomas Zimmermann int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
1226dd7b6ceSThomas Zimmermann 					 struct drm_plane_state *plane_state);
1236dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
1246dd7b6ceSThomas Zimmermann 					  struct drm_plane_state *plane_state);
1256dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
1266dd7b6ceSThomas Zimmermann struct drm_plane_state *
1276dd7b6ceSThomas Zimmermann drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
1286dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
1296dd7b6ceSThomas Zimmermann 						   struct drm_plane_state *plane_state);
1306dd7b6ceSThomas Zimmermann 
1316dd7b6ceSThomas Zimmermann /**
1326dd7b6ceSThomas Zimmermann  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
1336dd7b6ceSThomas Zimmermann  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
1346dd7b6ceSThomas Zimmermann  *
1356dd7b6ceSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1366dd7b6ceSThomas Zimmermann  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
1376dd7b6ceSThomas Zimmermann  * functions.
1386dd7b6ceSThomas Zimmermann  */
1396dd7b6ceSThomas Zimmermann #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
1406dd7b6ceSThomas Zimmermann 	.prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
1416dd7b6ceSThomas Zimmermann 	.cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
1426dd7b6ceSThomas Zimmermann 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
1436dd7b6ceSThomas Zimmermann 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
1446dd7b6ceSThomas Zimmermann 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
1456dd7b6ceSThomas Zimmermann 
1466dd7b6ceSThomas Zimmermann #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
147