|
1 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | 2 |
|
| 3 | +#include <linux/dma-resv.h> |
| 4 | + |
3 | 5 | #include <drm/drm_atomic_state_helper.h> |
| 6 | +#include <drm/drm_atomic_uapi.h> |
| 7 | +#include <drm/drm_gem.h> |
4 | 8 | #include <drm/drm_gem_atomic_helper.h> |
5 | 9 | #include <drm/drm_gem_framebuffer_helper.h> |
6 | 10 | #include <drm/drm_simple_kms_helper.h> |
|
12 | 16 | * |
13 | 17 | * The GEM atomic helpers library implements generic atomic-commit |
14 | 18 | * functions for drivers that use GEM objects. Currently, it provides |
15 | | - * plane state and framebuffer BO mappings for planes with shadow |
16 | | - * buffers. |
| 19 | + * synchronization helpers, and plane state and framebuffer BO mappings |
| 20 | + * for planes with shadow buffers. |
| 21 | + * |
| 22 | + * Before scanout, a plane's framebuffer needs to be synchronized with |
| 23 | + * possible writers that draw into the framebuffer. All drivers should |
| 24 | + * call drm_gem_plane_helper_prepare_fb() from their implementation of |
| 25 | + * struct &drm_plane_helper.prepare_fb . It sets the plane's fence from |
| 26 | + * the framebuffer so that the DRM core can synchronize access automatically. |
| 27 | + * |
| 28 | + * drm_gem_plane_helper_prepare_fb() can also be used directly as |
| 29 | + * implementation of prepare_fb. For drivers based on |
| 30 | + * struct drm_simple_display_pipe, drm_gem_simple_display_pipe_prepare_fb() |
| 31 | + * provides equivalent functionality. |
| 32 | + * |
| 33 | + * .. code-block:: c |
| 34 | + * |
| 35 | + * #include <drm/drm_gem_atomic_helper.h> |
| 36 | + * |
| 37 | + * struct drm_plane_helper_funcs driver_plane_helper_funcs = { |
| 38 | + * ..., |
| 39 | + * . prepare_fb = drm_gem_plane_helper_prepare_fb, |
| 40 | + * }; |
| 41 | + * |
| 42 | + * struct drm_simple_display_pipe_funcs driver_pipe_funcs = { |
| 43 | + * ..., |
| 44 | + * . prepare_fb = drm_gem_simple_display_pipe_prepare_fb, |
| 45 | + * }; |
17 | 46 | * |
18 | 47 | * A driver using a shadow buffer copies the content of the shadow buffers |
19 | 48 | * into the HW's framebuffer memory during an atomic update. This requires |
|
32 | 61 | * |
33 | 62 | * .. code-block:: c |
34 | 63 | * |
35 | | - * #include <drm/drm/gem_atomic_helper.h> |
| 64 | + * #include <drm/drm_gem_atomic_helper.h> |
36 | 65 | * |
37 | 66 | * struct drm_plane_funcs driver_plane_funcs = { |
38 | 67 | * ..., |
|
87 | 116 | * } |
88 | 117 | */ |
89 | 118 |
|
| 119 | +/* |
| 120 | + * Plane Helpers |
| 121 | + */ |
| 122 | + |
| 123 | +/** |
| 124 | + * drm_gem_plane_helper_prepare_fb() - Prepare a GEM backed framebuffer |
| 125 | + * @plane: Plane |
| 126 | + * @state: Plane state the fence will be attached to |
| 127 | + * |
| 128 | + * This function extracts the exclusive fence from &drm_gem_object.resv and |
| 129 | + * attaches it to plane state for the atomic helper to wait on. This is |
| 130 | + * necessary to correctly implement implicit synchronization for any buffers |
| 131 | + * shared as a struct &dma_buf. This function can be used as the |
| 132 | + * &drm_plane_helper_funcs.prepare_fb callback. |
| 133 | + * |
| 134 | + * There is no need for &drm_plane_helper_funcs.cleanup_fb hook for simple |
| 135 | + * GEM based framebuffer drivers which have their buffers always pinned in |
| 136 | + * memory. |
| 137 | + * |
| 138 | + * See drm_atomic_set_fence_for_plane() for a discussion of implicit and |
| 139 | + * explicit fencing in atomic modeset updates. |
| 140 | + */ |
| 141 | +int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) |
| 142 | +{ |
| 143 | + struct drm_gem_object *obj; |
| 144 | + struct dma_fence *fence; |
| 145 | + |
| 146 | + if (!state->fb) |
| 147 | + return 0; |
| 148 | + |
| 149 | + obj = drm_gem_fb_get_obj(state->fb, 0); |
| 150 | + fence = dma_resv_get_excl_rcu(obj->resv); |
| 151 | + drm_atomic_set_fence_for_plane(state, fence); |
| 152 | + |
| 153 | + return 0; |
| 154 | +} |
| 155 | +EXPORT_SYMBOL_GPL(drm_gem_plane_helper_prepare_fb); |
| 156 | + |
| 157 | +/** |
| 158 | + * drm_gem_simple_display_pipe_prepare_fb - prepare_fb helper for &drm_simple_display_pipe |
| 159 | + * @pipe: Simple display pipe |
| 160 | + * @plane_state: Plane state |
| 161 | + * |
| 162 | + * This function uses drm_gem_plane_helper_prepare_fb() to extract the exclusive fence |
| 163 | + * from &drm_gem_object.resv and attaches it to plane state for the atomic |
| 164 | + * helper to wait on. This is necessary to correctly implement implicit |
| 165 | + * synchronization for any buffers shared as a struct &dma_buf. Drivers can use |
| 166 | + * this as their &drm_simple_display_pipe_funcs.prepare_fb callback. |
| 167 | + * |
| 168 | + * See drm_atomic_set_fence_for_plane() for a discussion of implicit and |
| 169 | + * explicit fencing in atomic modeset updates. |
| 170 | + */ |
| 171 | +int drm_gem_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe, |
| 172 | + struct drm_plane_state *plane_state) |
| 173 | +{ |
| 174 | + return drm_gem_plane_helper_prepare_fb(&pipe->plane, plane_state); |
| 175 | +} |
| 176 | +EXPORT_SYMBOL(drm_gem_simple_display_pipe_prepare_fb); |
| 177 | + |
90 | 178 | /* |
91 | 179 | * Shadow-buffered Planes |
92 | 180 | */ |
@@ -198,7 +286,7 @@ int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *p |
198 | 286 | if (!fb) |
199 | 287 | return 0; |
200 | 288 |
|
201 | | - ret = drm_gem_fb_prepare_fb(plane, plane_state); |
| 289 | + ret = drm_gem_plane_helper_prepare_fb(plane, plane_state); |
202 | 290 | if (ret) |
203 | 291 | return ret; |
204 | 292 |
|
|
0 commit comments