14
14
* functions for drivers that use GEM objects. Currently, it provides
15
15
* plane state and framebuffer BO mappings for planes with shadow
16
16
* buffers.
17
+ *
18
+ * A driver using a shadow buffer copies the content of the shadow buffers
19
+ * into the HW's framebuffer memory during an atomic update. This requires
20
+ * a mapping of the shadow buffer into kernel address space. The mappings
21
+ * cannot be established by commit-tail functions, such as atomic_update,
22
+ * as this would violate locking rules around dma_buf_vmap().
23
+ *
24
+ * The helpers for shadow-buffered planes establish and release mappings,
25
+ * and provide struct drm_shadow_plane_state, which stores the plane's mapping
26
+ * for commit-tail functons.
27
+ *
28
+ * Shadow-buffered planes can easily be enabled by using the provided macros
29
+ * %DRM_GEM_SHADOW_PLANE_FUNCS and %DRM_GEM_SHADOW_PLANE_HELPER_FUNCS.
30
+ * These macros set up the plane and plane-helper callbacks to point to the
31
+ * shadow-buffer helpers.
32
+ *
33
+ * .. code-block:: c
34
+ *
35
+ * #include <drm/drm/gem_atomic_helper.h>
36
+ *
37
+ * struct drm_plane_funcs driver_plane_funcs = {
38
+ * ...,
39
+ * DRM_GEM_SHADOW_PLANE_FUNCS,
40
+ * };
41
+ *
42
+ * struct drm_plane_helper_funcs driver_plane_helper_funcs = {
43
+ * ...,
44
+ * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
45
+ * };
46
+ *
47
+ * In the driver's atomic-update function, shadow-buffer mappings are available
48
+ * from the plane state. Use to_drm_shadow_plane_state() to upcast from
49
+ * struct drm_plane_state.
50
+ *
51
+ * .. code-block:: c
52
+ *
53
+ * void driver_plane_atomic_update(struct drm_plane *plane,
54
+ * struct drm_plane_state *old_plane_state)
55
+ * {
56
+ * struct drm_plane_state *plane_state = plane->state;
57
+ * struct drm_shadow_plane_state *shadow_plane_state =
58
+ * to_drm_shadow_plane_state(plane_state);
59
+ *
60
+ * // access shadow buffer via shadow_plane_state->map
61
+ * }
62
+ *
63
+ * A mapping address for each of the framebuffer's buffer object is stored in
64
+ * struct &drm_shadow_plane_state.map. The mappings are valid while the state
65
+ * is being used.
66
+ *
67
+ * Drivers that use struct drm_simple_display_pipe can use
68
+ * %DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS to initialize the rsp
69
+ * callbacks. Access to shadow-buffer mappings is similar to regular
70
+ * atomic_update.
71
+ *
72
+ * .. code-block:: c
73
+ *
74
+ * struct drm_simple_display_pipe_funcs driver_pipe_funcs = {
75
+ * ...,
76
+ * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS,
77
+ * };
78
+ *
79
+ * void driver_pipe_enable(struct drm_simple_display_pipe *pipe,
80
+ * struct drm_crtc_state *crtc_state,
81
+ * struct drm_plane_state *plane_state)
82
+ * {
83
+ * struct drm_shadow_plane_state *shadow_plane_state =
84
+ * to_drm_shadow_plane_state(plane_state);
85
+ *
86
+ * // access shadow buffer via shadow_plane_state->map
87
+ * }
17
88
*/
18
89
19
90
/*
20
91
* Shadow-buffered Planes
21
92
*/
22
93
23
- static struct drm_plane_state *
94
+ /**
95
+ * drm_gem_duplicate_shadow_plane_state - duplicates shadow-buffered plane state
96
+ * @plane: the plane
97
+ *
98
+ * This function implements struct &drm_plane_funcs.atomic_duplicate_state for
99
+ * shadow-buffered planes. It assumes the existing state to be of type
100
+ * struct drm_shadow_plane_state and it allocates the new state to be of this
101
+ * type.
102
+ *
103
+ * The function does not duplicate existing mappings of the shadow buffers.
104
+ * Mappings are maintained during the atomic commit by the plane's prepare_fb
105
+ * and cleanup_fb helpers. See drm_gem_prepare_shadow_fb() and drm_gem_cleanup_shadow_fb()
106
+ * for corresponding helpers.
107
+ *
108
+ * Returns:
109
+ * A pointer to a new plane state on success, or NULL otherwise.
110
+ */
111
+ struct drm_plane_state *
24
112
drm_gem_duplicate_shadow_plane_state (struct drm_plane * plane )
25
113
{
26
114
struct drm_plane_state * plane_state = plane -> state ;
@@ -36,18 +124,38 @@ drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane)
36
124
37
125
return & new_shadow_plane_state -> base ;
38
126
}
127
+ EXPORT_SYMBOL (drm_gem_duplicate_shadow_plane_state );
39
128
40
- static void drm_gem_destroy_shadow_plane_state (struct drm_plane * plane ,
41
- struct drm_plane_state * plane_state )
129
+ /**
130
+ * drm_gem_destroy_shadow_plane_state - deletes shadow-buffered plane state
131
+ * @plane: the plane
132
+ * @plane_state: the plane state of type struct drm_shadow_plane_state
133
+ *
134
+ * This function implements struct &drm_plane_funcs.atomic_destroy_state
135
+ * for shadow-buffered planes. It expects that mappings of shadow buffers
136
+ * have been released already.
137
+ */
138
+ void drm_gem_destroy_shadow_plane_state (struct drm_plane * plane ,
139
+ struct drm_plane_state * plane_state )
42
140
{
43
141
struct drm_shadow_plane_state * shadow_plane_state =
44
142
to_drm_shadow_plane_state (plane_state );
45
143
46
144
__drm_atomic_helper_plane_destroy_state (& shadow_plane_state -> base );
47
145
kfree (shadow_plane_state );
48
146
}
147
+ EXPORT_SYMBOL (drm_gem_destroy_shadow_plane_state );
49
148
50
- static void drm_gem_reset_shadow_plane (struct drm_plane * plane )
149
+ /**
150
+ * drm_gem_reset_shadow_plane - resets a shadow-buffered plane
151
+ * @plane: the plane
152
+ *
153
+ * This function implements struct &drm_plane_funcs.reset_plane for
154
+ * shadow-buffered planes. It assumes the current plane state to be
155
+ * of type struct drm_shadow_plane and it allocates the new state of
156
+ * this type.
157
+ */
158
+ void drm_gem_reset_shadow_plane (struct drm_plane * plane )
51
159
{
52
160
struct drm_shadow_plane_state * shadow_plane_state ;
53
161
@@ -61,8 +169,24 @@ static void drm_gem_reset_shadow_plane(struct drm_plane *plane)
61
169
return ;
62
170
__drm_atomic_helper_plane_reset (plane , & shadow_plane_state -> base );
63
171
}
172
+ EXPORT_SYMBOL (drm_gem_reset_shadow_plane );
64
173
65
- static int drm_gem_prepare_shadow_fb (struct drm_plane * plane , struct drm_plane_state * plane_state )
174
+ /**
175
+ * drm_gem_prepare_shadow_fb - prepares shadow framebuffers
176
+ * @plane: the plane
177
+ * @plane_state: the plane state of type struct drm_shadow_plane_state
178
+ *
179
+ * This function implements struct &drm_plane_helper_funcs.prepare_fb. It
180
+ * maps all buffer objects of the plane's framebuffer into kernel address
181
+ * space and stores them in &struct drm_shadow_plane_state.map. The
182
+ * framebuffer will be synchronized as part of the atomic commit.
183
+ *
184
+ * See drm_gem_cleanup_shadow_fb() for cleanup.
185
+ *
186
+ * Returns:
187
+ * 0 on success, or a negative errno code otherwise.
188
+ */
189
+ int drm_gem_prepare_shadow_fb (struct drm_plane * plane , struct drm_plane_state * plane_state )
66
190
{
67
191
struct drm_shadow_plane_state * shadow_plane_state = to_drm_shadow_plane_state (plane_state );
68
192
struct drm_framebuffer * fb = plane_state -> fb ;
@@ -100,8 +224,19 @@ static int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_s
100
224
}
101
225
return ret ;
102
226
}
227
+ EXPORT_SYMBOL (drm_gem_prepare_shadow_fb );
103
228
104
- static void drm_gem_cleanup_shadow_fb (struct drm_plane * plane , struct drm_plane_state * plane_state )
229
+ /**
230
+ * drm_gem_cleanup_shadow_fb - releases shadow framebuffers
231
+ * @plane: the plane
232
+ * @plane_state: the plane state of type struct drm_shadow_plane_state
233
+ *
234
+ * This function implements struct &drm_plane_helper_funcs.cleanup_fb.
235
+ * This function unmaps all buffer objects of the plane's framebuffer.
236
+ *
237
+ * See drm_gem_prepare_shadow_fb() for more inforamtion.
238
+ */
239
+ void drm_gem_cleanup_shadow_fb (struct drm_plane * plane , struct drm_plane_state * plane_state )
105
240
{
106
241
struct drm_shadow_plane_state * shadow_plane_state = to_drm_shadow_plane_state (plane_state );
107
242
struct drm_framebuffer * fb = plane_state -> fb ;
@@ -119,6 +254,7 @@ static void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_
119
254
drm_gem_vunmap (obj , & shadow_plane_state -> map [i ]);
120
255
}
121
256
}
257
+ EXPORT_SYMBOL (drm_gem_cleanup_shadow_fb );
122
258
123
259
/**
124
260
* drm_gem_simple_kms_prepare_shadow_fb - prepares shadow framebuffers
0 commit comments