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 /**
266dd7b6ceSThomas Zimmermann  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
276dd7b6ceSThomas Zimmermann  *
286dd7b6ceSThomas Zimmermann  * For planes that use a shadow buffer, struct drm_shadow_plane_state
296dd7b6ceSThomas Zimmermann  * provides the regular plane state plus mappings of the shadow buffer
306dd7b6ceSThomas Zimmermann  * into kernel address space.
316dd7b6ceSThomas Zimmermann  */
326dd7b6ceSThomas Zimmermann struct drm_shadow_plane_state {
336dd7b6ceSThomas Zimmermann 	/** @base: plane state */
346dd7b6ceSThomas Zimmermann 	struct drm_plane_state base;
356dd7b6ceSThomas Zimmermann 
366dd7b6ceSThomas Zimmermann 	/* Transitional state - do not export or duplicate */
376dd7b6ceSThomas Zimmermann 
386dd7b6ceSThomas Zimmermann 	/**
396dd7b6ceSThomas Zimmermann 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
406dd7b6ceSThomas Zimmermann 	 *
416dd7b6ceSThomas Zimmermann 	 * The memory mappings stored in map should be established in the plane's
426dd7b6ceSThomas Zimmermann 	 * prepare_fb callback and removed in the cleanup_fb callback.
436dd7b6ceSThomas Zimmermann 	 */
44279cc2e9SThomas Zimmermann 	struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
45*43b36232SThomas Zimmermann 
46*43b36232SThomas Zimmermann 	/**
47*43b36232SThomas Zimmermann 	 * @data: Address of each framebuffer BO's data
48*43b36232SThomas Zimmermann 	 *
49*43b36232SThomas Zimmermann 	 * The address of the data stored in each mapping. This is different
50*43b36232SThomas Zimmermann 	 * for framebuffers with non-zero offset fields.
51*43b36232SThomas Zimmermann 	 */
52*43b36232SThomas Zimmermann 	struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
536dd7b6ceSThomas Zimmermann };
546dd7b6ceSThomas Zimmermann 
556dd7b6ceSThomas Zimmermann /**
566dd7b6ceSThomas Zimmermann  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
576dd7b6ceSThomas Zimmermann  * @state: the plane state
586dd7b6ceSThomas Zimmermann  */
596dd7b6ceSThomas Zimmermann static inline struct drm_shadow_plane_state *
606dd7b6ceSThomas Zimmermann to_drm_shadow_plane_state(struct drm_plane_state *state)
616dd7b6ceSThomas Zimmermann {
626dd7b6ceSThomas Zimmermann 	return container_of(state, struct drm_shadow_plane_state, base);
636dd7b6ceSThomas Zimmermann }
646dd7b6ceSThomas Zimmermann 
65b7156502SThomas Zimmermann void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
66b7156502SThomas Zimmermann 					    struct drm_shadow_plane_state *new_shadow_plane_state);
67b7156502SThomas Zimmermann void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
68b7156502SThomas Zimmermann void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
69b7156502SThomas Zimmermann 				  struct drm_shadow_plane_state *shadow_plane_state);
70b7156502SThomas Zimmermann 
719dc9067dSThomas Zimmermann void drm_gem_reset_shadow_plane(struct drm_plane *plane);
729dc9067dSThomas Zimmermann struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
739dc9067dSThomas Zimmermann void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
749dc9067dSThomas Zimmermann 					struct drm_plane_state *plane_state);
759dc9067dSThomas Zimmermann 
769dc9067dSThomas Zimmermann /**
779dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_FUNCS -
789dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_funcs for shadow-buffered planes
799dc9067dSThomas Zimmermann  *
809dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
819dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_funcs to use the rsp helper functions.
829dc9067dSThomas Zimmermann  */
839dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_FUNCS \
849dc9067dSThomas Zimmermann 	.reset = drm_gem_reset_shadow_plane, \
859dc9067dSThomas Zimmermann 	.atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
869dc9067dSThomas Zimmermann 	.atomic_destroy_state = drm_gem_destroy_shadow_plane_state
879dc9067dSThomas Zimmermann 
889dc9067dSThomas Zimmermann int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
899dc9067dSThomas Zimmermann void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
909dc9067dSThomas Zimmermann 
919dc9067dSThomas Zimmermann /**
929dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
939dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_helper_funcs for shadow-buffered planes
949dc9067dSThomas Zimmermann  *
959dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
969dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_helper_funcs to use the rsp helper
979dc9067dSThomas Zimmermann  * functions.
989dc9067dSThomas Zimmermann  */
999dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
1009dc9067dSThomas Zimmermann 	.prepare_fb = drm_gem_prepare_shadow_fb, \
1019dc9067dSThomas Zimmermann 	.cleanup_fb = drm_gem_cleanup_shadow_fb
1029dc9067dSThomas Zimmermann 
1036dd7b6ceSThomas Zimmermann int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
1046dd7b6ceSThomas Zimmermann 					 struct drm_plane_state *plane_state);
1056dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
1066dd7b6ceSThomas Zimmermann 					  struct drm_plane_state *plane_state);
1076dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
1086dd7b6ceSThomas Zimmermann struct drm_plane_state *
1096dd7b6ceSThomas Zimmermann drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
1106dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
1116dd7b6ceSThomas Zimmermann 						   struct drm_plane_state *plane_state);
1126dd7b6ceSThomas Zimmermann 
1136dd7b6ceSThomas Zimmermann /**
1146dd7b6ceSThomas Zimmermann  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
1156dd7b6ceSThomas Zimmermann  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
1166dd7b6ceSThomas Zimmermann  *
1176dd7b6ceSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1186dd7b6ceSThomas Zimmermann  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
1196dd7b6ceSThomas Zimmermann  * functions.
1206dd7b6ceSThomas Zimmermann  */
1216dd7b6ceSThomas Zimmermann #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
1226dd7b6ceSThomas Zimmermann 	.prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
1236dd7b6ceSThomas Zimmermann 	.cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
1246dd7b6ceSThomas Zimmermann 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
1256dd7b6ceSThomas Zimmermann 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
1266dd7b6ceSThomas Zimmermann 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
1276dd7b6ceSThomas Zimmermann 
1286dd7b6ceSThomas Zimmermann #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
129