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