xref: /linux/include/drm/drm_gem_atomic_helper.h (revision 9dc9067dce20b2ac7e1ba376485190e4a8b2675f)
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 
86dd7b6ceSThomas Zimmermann #include <drm/drm_plane.h>
96dd7b6ceSThomas Zimmermann 
106dd7b6ceSThomas Zimmermann struct drm_simple_display_pipe;
116dd7b6ceSThomas Zimmermann 
126dd7b6ceSThomas Zimmermann /*
136dd7b6ceSThomas Zimmermann  * Helpers for planes with shadow buffers
146dd7b6ceSThomas Zimmermann  */
156dd7b6ceSThomas Zimmermann 
166dd7b6ceSThomas Zimmermann /**
176dd7b6ceSThomas Zimmermann  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
186dd7b6ceSThomas Zimmermann  *
196dd7b6ceSThomas Zimmermann  * For planes that use a shadow buffer, struct drm_shadow_plane_state
206dd7b6ceSThomas Zimmermann  * provides the regular plane state plus mappings of the shadow buffer
216dd7b6ceSThomas Zimmermann  * into kernel address space.
226dd7b6ceSThomas Zimmermann  */
236dd7b6ceSThomas Zimmermann struct drm_shadow_plane_state {
246dd7b6ceSThomas Zimmermann 	/** @base: plane state */
256dd7b6ceSThomas Zimmermann 	struct drm_plane_state base;
266dd7b6ceSThomas Zimmermann 
276dd7b6ceSThomas Zimmermann 	/* Transitional state - do not export or duplicate */
286dd7b6ceSThomas Zimmermann 
296dd7b6ceSThomas Zimmermann 	/**
306dd7b6ceSThomas Zimmermann 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
316dd7b6ceSThomas Zimmermann 	 *
326dd7b6ceSThomas Zimmermann 	 * The memory mappings stored in map should be established in the plane's
336dd7b6ceSThomas Zimmermann 	 * prepare_fb callback and removed in the cleanup_fb callback.
346dd7b6ceSThomas Zimmermann 	 */
356dd7b6ceSThomas Zimmermann 	struct dma_buf_map map[4];
366dd7b6ceSThomas Zimmermann };
376dd7b6ceSThomas Zimmermann 
386dd7b6ceSThomas Zimmermann /**
396dd7b6ceSThomas Zimmermann  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
406dd7b6ceSThomas Zimmermann  * @state: the plane state
416dd7b6ceSThomas Zimmermann  */
426dd7b6ceSThomas Zimmermann static inline struct drm_shadow_plane_state *
436dd7b6ceSThomas Zimmermann to_drm_shadow_plane_state(struct drm_plane_state *state)
446dd7b6ceSThomas Zimmermann {
456dd7b6ceSThomas Zimmermann 	return container_of(state, struct drm_shadow_plane_state, base);
466dd7b6ceSThomas Zimmermann }
476dd7b6ceSThomas Zimmermann 
48*9dc9067dSThomas Zimmermann void drm_gem_reset_shadow_plane(struct drm_plane *plane);
49*9dc9067dSThomas Zimmermann struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
50*9dc9067dSThomas Zimmermann void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
51*9dc9067dSThomas Zimmermann 					struct drm_plane_state *plane_state);
52*9dc9067dSThomas Zimmermann 
53*9dc9067dSThomas Zimmermann /**
54*9dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_FUNCS -
55*9dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_funcs for shadow-buffered planes
56*9dc9067dSThomas Zimmermann  *
57*9dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
58*9dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_funcs to use the rsp helper functions.
59*9dc9067dSThomas Zimmermann  */
60*9dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_FUNCS \
61*9dc9067dSThomas Zimmermann 	.reset = drm_gem_reset_shadow_plane, \
62*9dc9067dSThomas Zimmermann 	.atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
63*9dc9067dSThomas Zimmermann 	.atomic_destroy_state = drm_gem_destroy_shadow_plane_state
64*9dc9067dSThomas Zimmermann 
65*9dc9067dSThomas Zimmermann int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
66*9dc9067dSThomas Zimmermann void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
67*9dc9067dSThomas Zimmermann 
68*9dc9067dSThomas Zimmermann /**
69*9dc9067dSThomas Zimmermann  * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
70*9dc9067dSThomas Zimmermann  *	Initializes struct drm_plane_helper_funcs for shadow-buffered planes
71*9dc9067dSThomas Zimmermann  *
72*9dc9067dSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
73*9dc9067dSThomas Zimmermann  * macro initializes struct drm_plane_helper_funcs to use the rsp helper
74*9dc9067dSThomas Zimmermann  * functions.
75*9dc9067dSThomas Zimmermann  */
76*9dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
77*9dc9067dSThomas Zimmermann 	.prepare_fb = drm_gem_prepare_shadow_fb, \
78*9dc9067dSThomas Zimmermann 	.cleanup_fb = drm_gem_cleanup_shadow_fb
79*9dc9067dSThomas Zimmermann 
806dd7b6ceSThomas Zimmermann int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
816dd7b6ceSThomas Zimmermann 					 struct drm_plane_state *plane_state);
826dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
836dd7b6ceSThomas Zimmermann 					  struct drm_plane_state *plane_state);
846dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
856dd7b6ceSThomas Zimmermann struct drm_plane_state *
866dd7b6ceSThomas Zimmermann drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
876dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
886dd7b6ceSThomas Zimmermann 						   struct drm_plane_state *plane_state);
896dd7b6ceSThomas Zimmermann 
906dd7b6ceSThomas Zimmermann /**
916dd7b6ceSThomas Zimmermann  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
926dd7b6ceSThomas Zimmermann  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
936dd7b6ceSThomas Zimmermann  *
946dd7b6ceSThomas Zimmermann  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
956dd7b6ceSThomas Zimmermann  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
966dd7b6ceSThomas Zimmermann  * functions.
976dd7b6ceSThomas Zimmermann  */
986dd7b6ceSThomas Zimmermann #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
996dd7b6ceSThomas Zimmermann 	.prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
1006dd7b6ceSThomas Zimmermann 	.cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
1016dd7b6ceSThomas Zimmermann 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
1026dd7b6ceSThomas Zimmermann 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
1036dd7b6ceSThomas Zimmermann 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
1046dd7b6ceSThomas Zimmermann 
1056dd7b6ceSThomas Zimmermann #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
106