1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef __DRM_GEM_ATOMIC_HELPER_H__
4 #define __DRM_GEM_ATOMIC_HELPER_H__
5 
6 #include <linux/dma-buf-map.h>
7 
8 #include <drm/drm_plane.h>
9 
10 struct drm_simple_display_pipe;
11 
12 /*
13  * Helpers for planes with shadow buffers
14  */
15 
16 /**
17  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
18  *
19  * For planes that use a shadow buffer, struct drm_shadow_plane_state
20  * provides the regular plane state plus mappings of the shadow buffer
21  * into kernel address space.
22  */
23 struct drm_shadow_plane_state {
24 	/** @base: plane state */
25 	struct drm_plane_state base;
26 
27 	/* Transitional state - do not export or duplicate */
28 
29 	/**
30 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
31 	 *
32 	 * The memory mappings stored in map should be established in the plane's
33 	 * prepare_fb callback and removed in the cleanup_fb callback.
34 	 */
35 	struct dma_buf_map map[4];
36 };
37 
38 /**
39  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
40  * @state: the plane state
41  */
42 static inline struct drm_shadow_plane_state *
43 to_drm_shadow_plane_state(struct drm_plane_state *state)
44 {
45 	return container_of(state, struct drm_shadow_plane_state, base);
46 }
47 
48 int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
49 					 struct drm_plane_state *plane_state);
50 void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
51 					  struct drm_plane_state *plane_state);
52 void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
53 struct drm_plane_state *
54 drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
55 void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
56 						   struct drm_plane_state *plane_state);
57 
58 /**
59  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
60  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
61  *
62  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
63  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
64  * functions.
65  */
66 #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
67 	.prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
68 	.cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
69 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
70 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
71 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
72 
73 #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
74