Skip to content

Commit 820c170

Browse files
committed
drm/gem: Move drm_gem_fb_prepare_fb() to GEM atomic helpers
The function drm_gem_fb_prepare_fb() is a helper for atomic modesetting, but currently located next to framebuffer helpers. Move it to GEM atomic helpers, rename it slightly and adopt the drivers. Same for the rsp simple-pipe helper. Compile-tested with x86-64, aarch64 and arm. The patch is fairly large, but there are no functional changes. v3: * remove out-comented line in drm_gem_framebuffer_helper.h (Maxime) v2: * rename to drm_gem_plane_helper_prepare_fb() (Daniel) * add tutorial-style documentation Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Acked-by: Maxime Ripard <mripard@kernel.org> Link: https://patchwork.freedesktop.org/patch/msgid/20210222141756.7864-1-tzimmermann@suse.de
1 parent dc73982 commit 820c170

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+176
-145
lines changed

drivers/gpu/drm/aspeed/aspeed_gfx_crtc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <drm/drm_device.h>
1010
#include <drm/drm_fb_cma_helper.h>
1111
#include <drm/drm_fourcc.h>
12+
#include <drm/drm_gem_atomic_helper.h>
1213
#include <drm/drm_gem_cma_helper.h>
13-
#include <drm/drm_gem_framebuffer_helper.h>
1414
#include <drm/drm_panel.h>
1515
#include <drm/drm_simple_kms_helper.h>
1616
#include <drm/drm_vblank.h>
@@ -220,7 +220,7 @@ static const struct drm_simple_display_pipe_funcs aspeed_gfx_funcs = {
220220
.enable = aspeed_gfx_pipe_enable,
221221
.disable = aspeed_gfx_pipe_disable,
222222
.update = aspeed_gfx_pipe_update,
223-
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
223+
.prepare_fb = drm_gem_simple_display_pipe_prepare_fb,
224224
.enable_vblank = aspeed_gfx_enable_vblank,
225225
.disable_vblank = aspeed_gfx_disable_vblank,
226226
};

drivers/gpu/drm/drm_gem_atomic_helper.c

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3+
#include <linux/dma-resv.h>
4+
35
#include <drm/drm_atomic_state_helper.h>
6+
#include <drm/drm_atomic_uapi.h>
7+
#include <drm/drm_gem.h>
48
#include <drm/drm_gem_atomic_helper.h>
59
#include <drm/drm_gem_framebuffer_helper.h>
610
#include <drm/drm_simple_kms_helper.h>
@@ -12,8 +16,33 @@
1216
*
1317
* The GEM atomic helpers library implements generic atomic-commit
1418
* 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+
* };
1746
*
1847
* A driver using a shadow buffer copies the content of the shadow buffers
1948
* into the HW's framebuffer memory during an atomic update. This requires
@@ -32,7 +61,7 @@
3261
*
3362
* .. code-block:: c
3463
*
35-
* #include <drm/drm/gem_atomic_helper.h>
64+
* #include <drm/drm_gem_atomic_helper.h>
3665
*
3766
* struct drm_plane_funcs driver_plane_funcs = {
3867
* ...,
@@ -87,6 +116,65 @@
87116
* }
88117
*/
89118

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+
90178
/*
91179
* Shadow-buffered Planes
92180
*/
@@ -198,7 +286,7 @@ int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *p
198286
if (!fb)
199287
return 0;
200288

201-
ret = drm_gem_fb_prepare_fb(plane, plane_state);
289+
ret = drm_gem_plane_helper_prepare_fb(plane, plane_state);
202290
if (ret)
203291
return ret;
204292

drivers/gpu/drm/drm_gem_framebuffer_helper.c

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@
55
* Copyright (C) 2017 Noralf Trønnes
66
*/
77

8-
#include <linux/dma-buf.h>
9-
#include <linux/dma-fence.h>
10-
#include <linux/dma-resv.h>
118
#include <linux/slab.h>
129

13-
#include <drm/drm_atomic.h>
14-
#include <drm/drm_atomic_uapi.h>
1510
#include <drm/drm_damage_helper.h>
1611
#include <drm/drm_fb_helper.h>
1712
#include <drm/drm_fourcc.h>
1813
#include <drm/drm_framebuffer.h>
1914
#include <drm/drm_gem.h>
2015
#include <drm/drm_gem_framebuffer_helper.h>
2116
#include <drm/drm_modeset_helper.h>
22-
#include <drm/drm_simple_kms_helper.h>
2317

2418
#define AFBC_HEADER_SIZE 16
2519
#define AFBC_TH_LAYOUT_ALIGNMENT 8
@@ -432,60 +426,3 @@ int drm_gem_fb_afbc_init(struct drm_device *dev,
432426
return 0;
433427
}
434428
EXPORT_SYMBOL_GPL(drm_gem_fb_afbc_init);
435-
436-
/**
437-
* drm_gem_fb_prepare_fb() - Prepare a GEM backed framebuffer
438-
* @plane: Plane
439-
* @state: Plane state the fence will be attached to
440-
*
441-
* This function extracts the exclusive fence from &drm_gem_object.resv and
442-
* attaches it to plane state for the atomic helper to wait on. This is
443-
* necessary to correctly implement implicit synchronization for any buffers
444-
* shared as a struct &dma_buf. This function can be used as the
445-
* &drm_plane_helper_funcs.prepare_fb callback.
446-
*
447-
* There is no need for &drm_plane_helper_funcs.cleanup_fb hook for simple
448-
* gem based framebuffer drivers which have their buffers always pinned in
449-
* memory.
450-
*
451-
* See drm_atomic_set_fence_for_plane() for a discussion of implicit and
452-
* explicit fencing in atomic modeset updates.
453-
*/
454-
int drm_gem_fb_prepare_fb(struct drm_plane *plane,
455-
struct drm_plane_state *state)
456-
{
457-
struct drm_gem_object *obj;
458-
struct dma_fence *fence;
459-
460-
if (!state->fb)
461-
return 0;
462-
463-
obj = drm_gem_fb_get_obj(state->fb, 0);
464-
fence = dma_resv_get_excl_rcu(obj->resv);
465-
drm_atomic_set_fence_for_plane(state, fence);
466-
467-
return 0;
468-
}
469-
EXPORT_SYMBOL_GPL(drm_gem_fb_prepare_fb);
470-
471-
/**
472-
* drm_gem_fb_simple_display_pipe_prepare_fb - prepare_fb helper for
473-
* &drm_simple_display_pipe
474-
* @pipe: Simple display pipe
475-
* @plane_state: Plane state
476-
*
477-
* This function uses drm_gem_fb_prepare_fb() to extract the exclusive fence
478-
* from &drm_gem_object.resv and attaches it to plane state for the atomic
479-
* helper to wait on. This is necessary to correctly implement implicit
480-
* synchronization for any buffers shared as a struct &dma_buf. Drivers can use
481-
* this as their &drm_simple_display_pipe_funcs.prepare_fb callback.
482-
*
483-
* See drm_atomic_set_fence_for_plane() for a discussion of implicit and
484-
* explicit fencing in atomic modeset updates.
485-
*/
486-
int drm_gem_fb_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
487-
struct drm_plane_state *plane_state)
488-
{
489-
return drm_gem_fb_prepare_fb(&pipe->plane, plane_state);
490-
}
491-
EXPORT_SYMBOL(drm_gem_fb_simple_display_pipe_prepare_fb);

drivers/gpu/drm/drm_gem_vram_helper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <drm/drm_drv.h>
99
#include <drm/drm_file.h>
1010
#include <drm/drm_framebuffer.h>
11-
#include <drm/drm_gem_framebuffer_helper.h>
11+
#include <drm/drm_gem_atomic_helper.h>
1212
#include <drm/drm_gem_ttm_helper.h>
1313
#include <drm/drm_gem_vram_helper.h>
1414
#include <drm/drm_managed.h>
@@ -700,7 +700,7 @@ drm_gem_vram_plane_helper_prepare_fb(struct drm_plane *plane,
700700
goto err_drm_gem_vram_unpin;
701701
}
702702

703-
ret = drm_gem_fb_prepare_fb(plane, new_state);
703+
ret = drm_gem_plane_helper_prepare_fb(plane, new_state);
704704
if (ret)
705705
goto err_drm_gem_vram_unpin;
706706

drivers/gpu/drm/imx/dcss/dcss-plane.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <drm/drm_atomic.h>
77
#include <drm/drm_atomic_helper.h>
88
#include <drm/drm_fb_cma_helper.h>
9-
#include <drm/drm_gem_framebuffer_helper.h>
9+
#include <drm/drm_gem_atomic_helper.h>
1010
#include <drm/drm_gem_cma_helper.h>
1111

1212
#include "dcss-dev.h"
@@ -355,7 +355,7 @@ static void dcss_plane_atomic_disable(struct drm_plane *plane,
355355
}
356356

357357
static const struct drm_plane_helper_funcs dcss_plane_helper_funcs = {
358-
.prepare_fb = drm_gem_fb_prepare_fb,
358+
.prepare_fb = drm_gem_plane_helper_prepare_fb,
359359
.atomic_check = dcss_plane_atomic_check,
360360
.atomic_update = dcss_plane_atomic_update,
361361
.atomic_disable = dcss_plane_atomic_disable,

drivers/gpu/drm/imx/ipuv3-plane.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <drm/drm_atomic_helper.h>
1010
#include <drm/drm_fb_cma_helper.h>
1111
#include <drm/drm_fourcc.h>
12+
#include <drm/drm_gem_atomic_helper.h>
1213
#include <drm/drm_gem_cma_helper.h>
13-
#include <drm/drm_gem_framebuffer_helper.h>
1414
#include <drm/drm_managed.h>
1515
#include <drm/drm_plane_helper.h>
1616

@@ -704,7 +704,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
704704
}
705705

706706
static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
707-
.prepare_fb = drm_gem_fb_prepare_fb,
707+
.prepare_fb = drm_gem_plane_helper_prepare_fb,
708708
.atomic_check = ipu_plane_atomic_check,
709709
.atomic_disable = ipu_plane_atomic_disable,
710710
.atomic_update = ipu_plane_atomic_update,

drivers/gpu/drm/ingenic/ingenic-drm-drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <drm/drm_fb_cma_helper.h>
2929
#include <drm/drm_fb_helper.h>
3030
#include <drm/drm_fourcc.h>
31+
#include <drm/drm_gem_atomic_helper.h>
3132
#include <drm/drm_gem_framebuffer_helper.h>
3233
#include <drm/drm_irq.h>
3334
#include <drm/drm_managed.h>
@@ -780,7 +781,7 @@ static const struct drm_plane_helper_funcs ingenic_drm_plane_helper_funcs = {
780781
.atomic_update = ingenic_drm_plane_atomic_update,
781782
.atomic_check = ingenic_drm_plane_atomic_check,
782783
.atomic_disable = ingenic_drm_plane_atomic_disable,
783-
.prepare_fb = drm_gem_fb_prepare_fb,
784+
.prepare_fb = drm_gem_plane_helper_prepare_fb,
784785
};
785786

786787
static const struct drm_crtc_helper_funcs ingenic_drm_crtc_helper_funcs = {

drivers/gpu/drm/ingenic/ingenic-ipu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <drm/drm_drv.h>
2424
#include <drm/drm_fb_cma_helper.h>
2525
#include <drm/drm_fourcc.h>
26-
#include <drm/drm_gem_framebuffer_helper.h>
26+
#include <drm/drm_gem_atomic_helper.h>
2727
#include <drm/drm_plane.h>
2828
#include <drm/drm_plane_helper.h>
2929
#include <drm/drm_property.h>
@@ -608,7 +608,7 @@ static const struct drm_plane_helper_funcs ingenic_ipu_plane_helper_funcs = {
608608
.atomic_update = ingenic_ipu_plane_atomic_update,
609609
.atomic_check = ingenic_ipu_plane_atomic_check,
610610
.atomic_disable = ingenic_ipu_plane_atomic_disable,
611-
.prepare_fb = drm_gem_fb_prepare_fb,
611+
.prepare_fb = drm_gem_plane_helper_prepare_fb,
612612
};
613613

614614
static int

drivers/gpu/drm/mcde/mcde_display.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <drm/drm_device.h>
1414
#include <drm/drm_fb_cma_helper.h>
1515
#include <drm/drm_fourcc.h>
16+
#include <drm/drm_gem_atomic_helper.h>
1617
#include <drm/drm_gem_cma_helper.h>
17-
#include <drm/drm_gem_framebuffer_helper.h>
1818
#include <drm/drm_mipi_dsi.h>
1919
#include <drm/drm_simple_kms_helper.h>
2020
#include <drm/drm_bridge.h>
@@ -1479,7 +1479,7 @@ static struct drm_simple_display_pipe_funcs mcde_display_funcs = {
14791479
.update = mcde_display_update,
14801480
.enable_vblank = mcde_display_enable_vblank,
14811481
.disable_vblank = mcde_display_disable_vblank,
1482-
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
1482+
.prepare_fb = drm_gem_simple_display_pipe_prepare_fb,
14831483
};
14841484

14851485
int mcde_display_init(struct drm_device *drm)

drivers/gpu/drm/mediatek/mtk_drm_plane.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
#include <drm/drm_atomic.h>
88
#include <drm/drm_atomic_helper.h>
9-
#include <drm/drm_fourcc.h>
109
#include <drm/drm_atomic_uapi.h>
10+
#include <drm/drm_fourcc.h>
11+
#include <drm/drm_gem_atomic_helper.h>
1112
#include <drm/drm_plane_helper.h>
12-
#include <drm/drm_gem_framebuffer_helper.h>
1313

1414
#include "mtk_drm_crtc.h"
1515
#include "mtk_drm_ddp_comp.h"
@@ -216,7 +216,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
216216
}
217217

218218
static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
219-
.prepare_fb = drm_gem_fb_prepare_fb,
219+
.prepare_fb = drm_gem_plane_helper_prepare_fb,
220220
.atomic_check = mtk_plane_atomic_check,
221221
.atomic_update = mtk_plane_atomic_update,
222222
.atomic_disable = mtk_plane_atomic_disable,

0 commit comments

Comments
 (0)