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  * Plane Helpers
14  */
15 
16 int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
17 int drm_gem_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
18 					   struct drm_plane_state *plane_state);
19 
20 /*
21  * Helpers for planes with shadow buffers
22  */
23 
24 /**
25  * struct drm_shadow_plane_state - plane state for planes with shadow buffers
26  *
27  * For planes that use a shadow buffer, struct drm_shadow_plane_state
28  * provides the regular plane state plus mappings of the shadow buffer
29  * into kernel address space.
30  */
31 struct drm_shadow_plane_state {
32 	/** @base: plane state */
33 	struct drm_plane_state base;
34 
35 	/* Transitional state - do not export or duplicate */
36 
37 	/**
38 	 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
39 	 *
40 	 * The memory mappings stored in map should be established in the plane's
41 	 * prepare_fb callback and removed in the cleanup_fb callback.
42 	 */
43 	struct dma_buf_map map[4];
44 };
45 
46 /**
47  * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
48  * @state: the plane state
49  */
50 static inline struct drm_shadow_plane_state *
51 to_drm_shadow_plane_state(struct drm_plane_state *state)
52 {
53 	return container_of(state, struct drm_shadow_plane_state, base);
54 }
55 
56 void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
57 					    struct drm_shadow_plane_state *new_shadow_plane_state);
58 void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
59 void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
60 				  struct drm_shadow_plane_state *shadow_plane_state);
61 
62 void drm_gem_reset_shadow_plane(struct drm_plane *plane);
63 struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
64 void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
65 					struct drm_plane_state *plane_state);
66 
67 /**
68  * DRM_GEM_SHADOW_PLANE_FUNCS -
69  *	Initializes struct drm_plane_funcs for shadow-buffered planes
70  *
71  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
72  * macro initializes struct drm_plane_funcs to use the rsp helper functions.
73  */
74 #define DRM_GEM_SHADOW_PLANE_FUNCS \
75 	.reset = drm_gem_reset_shadow_plane, \
76 	.atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
77 	.atomic_destroy_state = drm_gem_destroy_shadow_plane_state
78 
79 int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
80 void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
81 
82 /**
83  * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
84  *	Initializes struct drm_plane_helper_funcs for shadow-buffered planes
85  *
86  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
87  * macro initializes struct drm_plane_helper_funcs to use the rsp helper
88  * functions.
89  */
90 #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
91 	.prepare_fb = drm_gem_prepare_shadow_fb, \
92 	.cleanup_fb = drm_gem_cleanup_shadow_fb
93 
94 int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
95 					 struct drm_plane_state *plane_state);
96 void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
97 					  struct drm_plane_state *plane_state);
98 void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
99 struct drm_plane_state *
100 drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
101 void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
102 						   struct drm_plane_state *plane_state);
103 
104 /**
105  * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
106  *	Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
107  *
108  * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
109  * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
110  * functions.
111  */
112 #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
113 	.prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
114 	.cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
115 	.reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
116 	.duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
117 	.destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
118 
119 #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
120