Skip to content

Commit 5ddb0bd

Browse files
committed
drm/atomic: Pass the full state to planes async atomic check and update
The current atomic helpers have either their object state being passed as an argument or the full atomic state. The former is the pattern that was done at first, before switching to the latter for new hooks or when it was needed. Let's start convert all the remaining helpers to provide a consistent interface, starting with the planes atomic_async_check and atomic_async_update. The conversion was done using the coccinelle script below, built tested on all the drivers. @@ identifier plane, plane_state; symbol state; @@ struct drm_plane_helper_funcs { ... int (*atomic_async_check)(struct drm_plane *plane, - struct drm_plane_state *plane_state); + struct drm_atomic_state *state); ... } @@ identifier plane, plane_state; symbol state; @@ struct drm_plane_helper_funcs { ... void (*atomic_async_update)(struct drm_plane *plane, - struct drm_plane_state *plane_state); + struct drm_atomic_state *state); ... } @ plane_atomic_func @ identifier helpers; identifier func; @@ ( static const struct drm_plane_helper_funcs helpers = { ..., .atomic_async_check = func, ..., }; | static const struct drm_plane_helper_funcs helpers = { ..., .atomic_async_update = func, ..., }; ) @@ struct drm_plane_helper_funcs *FUNCS; identifier f; identifier dev; identifier plane, plane_state, state; @@ f(struct drm_device *dev, struct drm_atomic_state *state) { <+... - FUNCS->atomic_async_check(plane, plane_state) + FUNCS->atomic_async_check(plane, state) ...+> } @@ struct drm_plane_helper_funcs *FUNCS; identifier f; identifier dev; identifier plane, plane_state, state; @@ f(struct drm_device *dev, struct drm_atomic_state *state) { <+... - FUNCS->atomic_async_update(plane, plane_state) + FUNCS->atomic_async_update(plane, state) ...+> } @@ identifier mtk_plane_atomic_async_update; identifier plane; symbol new_state, state; expression e; @@ void mtk_plane_atomic_async_update(struct drm_plane *plane, struct drm_plane_state *new_state) { ... - struct mtk_plane_state *state = e; + struct mtk_plane_state *new_plane_state = e; <+... - state + new_plane_state ...+> } @@ identifier plane_atomic_func.func; identifier plane; symbol state; @@ func(struct drm_plane *plane, - struct drm_plane_state *state) + struct drm_plane_state *new_plane_state) { <... - state + new_plane_state ...> } @ ignores_new_state @ identifier plane_atomic_func.func; identifier plane, new_plane_state; @@ func(struct drm_plane *plane, struct drm_plane_state *new_plane_state) { ... when != new_plane_state } @ adds_new_state depends on plane_atomic_func && !ignores_new_state @ identifier plane_atomic_func.func; identifier plane, new_plane_state; @@ func(struct drm_plane *plane, struct drm_plane_state *new_plane_state) { + struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane); ... } @ depends on plane_atomic_func @ identifier plane_atomic_func.func; identifier plane, plane_state; @@ func(struct drm_plane *plane, - struct drm_plane_state *plane_state + struct drm_atomic_state *state ) { ... } @ include depends on adds_new_state @ @@ #include <drm/drm_atomic.h> @ no_include depends on !include && adds_new_state @ @@ + #include <drm/drm_atomic.h> #include <drm/...> @@ identifier plane_atomic_func.func; identifier plane, state; identifier plane_state; @@ func(struct drm_plane *plane, struct drm_atomic_state *state) { ... struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane); <+... - plane_state->state + state ...+> } Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-1-maxime@cerno.tech
1 parent d919d3d commit 5ddb0bd

File tree

7 files changed

+90
-73
lines changed

7 files changed

+90
-73
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6468,7 +6468,7 @@ static int dm_plane_atomic_check(struct drm_plane *plane,
64686468
}
64696469

64706470
static int dm_plane_atomic_async_check(struct drm_plane *plane,
6471-
struct drm_plane_state *new_plane_state)
6471+
struct drm_atomic_state *state)
64726472
{
64736473
/* Only support async updates on cursor planes. */
64746474
if (plane->type != DRM_PLANE_TYPE_CURSOR)
@@ -6478,10 +6478,12 @@ static int dm_plane_atomic_async_check(struct drm_plane *plane,
64786478
}
64796479

64806480
static void dm_plane_atomic_async_update(struct drm_plane *plane,
6481-
struct drm_plane_state *new_state)
6481+
struct drm_atomic_state *state)
64826482
{
6483+
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
6484+
plane);
64836485
struct drm_plane_state *old_state =
6484-
drm_atomic_get_old_plane_state(new_state->state, plane);
6486+
drm_atomic_get_old_plane_state(state, plane);
64856487

64866488
trace_amdgpu_dm_atomic_update_cursor(new_state);
64876489

drivers/gpu/drm/drm_atomic_helper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ int drm_atomic_helper_async_check(struct drm_device *dev,
17421742
return -EBUSY;
17431743
}
17441744

1745-
return funcs->atomic_async_check(plane, new_plane_state);
1745+
return funcs->atomic_async_check(plane, state);
17461746
}
17471747
EXPORT_SYMBOL(drm_atomic_helper_async_check);
17481748

@@ -1772,7 +1772,7 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,
17721772
struct drm_framebuffer *old_fb = plane->state->fb;
17731773

17741774
funcs = plane->helper_private;
1775-
funcs->atomic_async_update(plane, plane_state);
1775+
funcs->atomic_async_update(plane, state);
17761776

17771777
/*
17781778
* ->atomic_async_update() is supposed to update the

drivers/gpu/drm/mediatek/mtk_drm_plane.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ static void mtk_drm_plane_destroy_state(struct drm_plane *plane,
7777
}
7878

7979
static int mtk_plane_atomic_async_check(struct drm_plane *plane,
80-
struct drm_plane_state *state)
80+
struct drm_atomic_state *state)
8181
{
82+
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
83+
plane);
8284
struct drm_crtc_state *crtc_state;
8385
int ret;
8486

85-
if (plane != state->crtc->cursor)
87+
if (plane != new_plane_state->crtc->cursor)
8688
return -EINVAL;
8789

8890
if (!plane->state)
@@ -91,16 +93,16 @@ static int mtk_plane_atomic_async_check(struct drm_plane *plane,
9193
if (!plane->state->fb)
9294
return -EINVAL;
9395

94-
ret = mtk_drm_crtc_plane_check(state->crtc, plane,
95-
to_mtk_plane_state(state));
96+
ret = mtk_drm_crtc_plane_check(new_plane_state->crtc, plane,
97+
to_mtk_plane_state(new_plane_state));
9698
if (ret)
9799
return ret;
98100

99-
if (state->state)
100-
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
101-
state->crtc);
101+
if (state)
102+
crtc_state = drm_atomic_get_existing_crtc_state(state,
103+
new_plane_state->crtc);
102104
else /* Special case for asynchronous cursor updates. */
103-
crtc_state = state->crtc->state;
105+
crtc_state = new_plane_state->crtc->state;
104106

105107
return drm_atomic_helper_check_plane_state(plane->state, crtc_state,
106108
DRM_PLANE_HELPER_NO_SCALING,
@@ -109,9 +111,11 @@ static int mtk_plane_atomic_async_check(struct drm_plane *plane,
109111
}
110112

111113
static void mtk_plane_atomic_async_update(struct drm_plane *plane,
112-
struct drm_plane_state *new_state)
114+
struct drm_atomic_state *state)
113115
{
114-
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
116+
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
117+
plane);
118+
struct mtk_plane_state *new_plane_state = to_mtk_plane_state(plane->state);
115119

116120
plane->state->crtc_x = new_state->crtc_x;
117121
plane->state->crtc_y = new_state->crtc_y;
@@ -122,7 +126,7 @@ static void mtk_plane_atomic_async_update(struct drm_plane *plane,
122126
plane->state->src_h = new_state->src_h;
123127
plane->state->src_w = new_state->src_w;
124128
swap(plane->state->fb, new_state->fb);
125-
state->pending.async_dirty = true;
129+
new_plane_state->pending.async_dirty = true;
126130

127131
mtk_drm_crtc_async_update(new_state->crtc, plane, new_state);
128132
}

drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Author: Rob Clark <robdclark@gmail.com>
66
*/
77

8+
#include <drm/drm_atomic.h>
89
#include <drm/drm_damage_helper.h>
910
#include <drm/drm_fourcc.h>
1011
#include <drm/drm_print.h>
@@ -438,41 +439,43 @@ static void mdp5_plane_atomic_update(struct drm_plane *plane,
438439
}
439440

440441
static int mdp5_plane_atomic_async_check(struct drm_plane *plane,
441-
struct drm_plane_state *state)
442+
struct drm_atomic_state *state)
442443
{
443-
struct mdp5_plane_state *mdp5_state = to_mdp5_plane_state(state);
444+
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
445+
plane);
446+
struct mdp5_plane_state *mdp5_state = to_mdp5_plane_state(new_plane_state);
444447
struct drm_crtc_state *crtc_state;
445448
int min_scale, max_scale;
446449
int ret;
447450

448-
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
449-
state->crtc);
451+
crtc_state = drm_atomic_get_existing_crtc_state(state,
452+
new_plane_state->crtc);
450453
if (WARN_ON(!crtc_state))
451454
return -EINVAL;
452455

453456
if (!crtc_state->active)
454457
return -EINVAL;
455458

456-
mdp5_state = to_mdp5_plane_state(state);
459+
mdp5_state = to_mdp5_plane_state(new_plane_state);
457460

458461
/* don't use fast path if we don't have a hwpipe allocated yet */
459462
if (!mdp5_state->hwpipe)
460463
return -EINVAL;
461464

462465
/* only allow changing of position(crtc x/y or src x/y) in fast path */
463-
if (plane->state->crtc != state->crtc ||
464-
plane->state->src_w != state->src_w ||
465-
plane->state->src_h != state->src_h ||
466-
plane->state->crtc_w != state->crtc_w ||
467-
plane->state->crtc_h != state->crtc_h ||
466+
if (plane->state->crtc != new_plane_state->crtc ||
467+
plane->state->src_w != new_plane_state->src_w ||
468+
plane->state->src_h != new_plane_state->src_h ||
469+
plane->state->crtc_w != new_plane_state->crtc_w ||
470+
plane->state->crtc_h != new_plane_state->crtc_h ||
468471
!plane->state->fb ||
469-
plane->state->fb != state->fb)
472+
plane->state->fb != new_plane_state->fb)
470473
return -EINVAL;
471474

472475
min_scale = FRAC_16_16(1, 8);
473476
max_scale = FRAC_16_16(8, 1);
474477

475-
ret = drm_atomic_helper_check_plane_state(state, crtc_state,
478+
ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
476479
min_scale, max_scale,
477480
true, true);
478481
if (ret)
@@ -485,15 +488,17 @@ static int mdp5_plane_atomic_async_check(struct drm_plane *plane,
485488
* also assign/unassign the hwpipe(s) tied to the plane. We avoid
486489
* taking the fast path for both these reasons.
487490
*/
488-
if (state->visible != plane->state->visible)
491+
if (new_plane_state->visible != plane->state->visible)
489492
return -EINVAL;
490493

491494
return 0;
492495
}
493496

494497
static void mdp5_plane_atomic_async_update(struct drm_plane *plane,
495-
struct drm_plane_state *new_state)
498+
struct drm_atomic_state *state)
496499
{
500+
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
501+
plane);
497502
struct drm_framebuffer *old_fb = plane->state->fb;
498503

499504
plane->state->src_x = new_state->src_x;

drivers/gpu/drm/rockchip/rockchip_drm_vop.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,10 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
10221022
}
10231023

10241024
static int vop_plane_atomic_async_check(struct drm_plane *plane,
1025-
struct drm_plane_state *state)
1025+
struct drm_atomic_state *state)
10261026
{
1027+
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
1028+
plane);
10271029
struct vop_win *vop_win = to_vop_win(plane);
10281030
const struct vop_win_data *win = vop_win->data;
10291031
int min_scale = win->phy->scl ? FRAC_16_16(1, 8) :
@@ -1032,7 +1034,7 @@ static int vop_plane_atomic_async_check(struct drm_plane *plane,
10321034
DRM_PLANE_HELPER_NO_SCALING;
10331035
struct drm_crtc_state *crtc_state;
10341036

1035-
if (plane != state->crtc->cursor)
1037+
if (plane != new_plane_state->crtc->cursor)
10361038
return -EINVAL;
10371039

10381040
if (!plane->state)
@@ -1041,9 +1043,9 @@ static int vop_plane_atomic_async_check(struct drm_plane *plane,
10411043
if (!plane->state->fb)
10421044
return -EINVAL;
10431045

1044-
if (state->state)
1045-
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
1046-
state->crtc);
1046+
if (state)
1047+
crtc_state = drm_atomic_get_existing_crtc_state(state,
1048+
new_plane_state->crtc);
10471049
else /* Special case for asynchronous cursor updates. */
10481050
crtc_state = plane->crtc->state;
10491051

@@ -1053,8 +1055,10 @@ static int vop_plane_atomic_async_check(struct drm_plane *plane,
10531055
}
10541056

10551057
static void vop_plane_atomic_async_update(struct drm_plane *plane,
1056-
struct drm_plane_state *new_state)
1058+
struct drm_atomic_state *state)
10571059
{
1060+
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
1061+
plane);
10581062
struct vop *vop = to_vop(plane->state->crtc);
10591063
struct drm_framebuffer *old_fb = plane->state->fb;
10601064

drivers/gpu/drm/vc4/vc4_plane.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,32 +1118,34 @@ void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb)
11181118
}
11191119

11201120
static void vc4_plane_atomic_async_update(struct drm_plane *plane,
1121-
struct drm_plane_state *state)
1121+
struct drm_atomic_state *state)
11221122
{
1123+
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
1124+
plane);
11231125
struct vc4_plane_state *vc4_state, *new_vc4_state;
11241126

1125-
swap(plane->state->fb, state->fb);
1126-
plane->state->crtc_x = state->crtc_x;
1127-
plane->state->crtc_y = state->crtc_y;
1128-
plane->state->crtc_w = state->crtc_w;
1129-
plane->state->crtc_h = state->crtc_h;
1130-
plane->state->src_x = state->src_x;
1131-
plane->state->src_y = state->src_y;
1132-
plane->state->src_w = state->src_w;
1133-
plane->state->src_h = state->src_h;
1134-
plane->state->src_h = state->src_h;
1135-
plane->state->alpha = state->alpha;
1136-
plane->state->pixel_blend_mode = state->pixel_blend_mode;
1137-
plane->state->rotation = state->rotation;
1138-
plane->state->zpos = state->zpos;
1139-
plane->state->normalized_zpos = state->normalized_zpos;
1140-
plane->state->color_encoding = state->color_encoding;
1141-
plane->state->color_range = state->color_range;
1142-
plane->state->src = state->src;
1143-
plane->state->dst = state->dst;
1144-
plane->state->visible = state->visible;
1145-
1146-
new_vc4_state = to_vc4_plane_state(state);
1127+
swap(plane->state->fb, new_plane_state->fb);
1128+
plane->state->crtc_x = new_plane_state->crtc_x;
1129+
plane->state->crtc_y = new_plane_state->crtc_y;
1130+
plane->state->crtc_w = new_plane_state->crtc_w;
1131+
plane->state->crtc_h = new_plane_state->crtc_h;
1132+
plane->state->src_x = new_plane_state->src_x;
1133+
plane->state->src_y = new_plane_state->src_y;
1134+
plane->state->src_w = new_plane_state->src_w;
1135+
plane->state->src_h = new_plane_state->src_h;
1136+
plane->state->src_h = new_plane_state->src_h;
1137+
plane->state->alpha = new_plane_state->alpha;
1138+
plane->state->pixel_blend_mode = new_plane_state->pixel_blend_mode;
1139+
plane->state->rotation = new_plane_state->rotation;
1140+
plane->state->zpos = new_plane_state->zpos;
1141+
plane->state->normalized_zpos = new_plane_state->normalized_zpos;
1142+
plane->state->color_encoding = new_plane_state->color_encoding;
1143+
plane->state->color_range = new_plane_state->color_range;
1144+
plane->state->src = new_plane_state->src;
1145+
plane->state->dst = new_plane_state->dst;
1146+
plane->state->visible = new_plane_state->visible;
1147+
1148+
new_vc4_state = to_vc4_plane_state(new_plane_state);
11471149
vc4_state = to_vc4_plane_state(plane->state);
11481150

11491151
vc4_state->crtc_x = new_vc4_state->crtc_x;
@@ -1187,23 +1189,25 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane,
11871189
}
11881190

11891191
static int vc4_plane_atomic_async_check(struct drm_plane *plane,
1190-
struct drm_plane_state *state)
1192+
struct drm_atomic_state *state)
11911193
{
1194+
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
1195+
plane);
11921196
struct vc4_plane_state *old_vc4_state, *new_vc4_state;
11931197
int ret;
11941198
u32 i;
11951199

1196-
ret = vc4_plane_mode_set(plane, state);
1200+
ret = vc4_plane_mode_set(plane, new_plane_state);
11971201
if (ret)
11981202
return ret;
11991203

12001204
old_vc4_state = to_vc4_plane_state(plane->state);
1201-
new_vc4_state = to_vc4_plane_state(state);
1205+
new_vc4_state = to_vc4_plane_state(new_plane_state);
12021206
if (old_vc4_state->dlist_count != new_vc4_state->dlist_count ||
12031207
old_vc4_state->pos0_offset != new_vc4_state->pos0_offset ||
12041208
old_vc4_state->pos2_offset != new_vc4_state->pos2_offset ||
12051209
old_vc4_state->ptr0_offset != new_vc4_state->ptr0_offset ||
1206-
vc4_lbm_size(plane->state) != vc4_lbm_size(state))
1210+
vc4_lbm_size(plane->state) != vc4_lbm_size(new_plane_state))
12071211
return -EINVAL;
12081212

12091213
/* Only pos0, pos2 and ptr0 DWORDS can be updated in an async update

include/drm/drm_modeset_helper_vtables.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,9 @@ struct drm_plane_helper_funcs {
12921292
/**
12931293
* @atomic_async_check:
12941294
*
1295-
* Drivers should set this function pointer to check if the plane state
1296-
* can be updated in a async fashion. Here async means "not vblank
1297-
* synchronized".
1295+
* Drivers should set this function pointer to check if the plane's
1296+
* atomic state can be updated in a async fashion. Here async means
1297+
* "not vblank synchronized".
12981298
*
12991299
* This hook is called by drm_atomic_async_check() to establish if a
13001300
* given update can be committed asynchronously, that is, if it can
@@ -1306,7 +1306,7 @@ struct drm_plane_helper_funcs {
13061306
* can not be applied in asynchronous manner.
13071307
*/
13081308
int (*atomic_async_check)(struct drm_plane *plane,
1309-
struct drm_plane_state *state);
1309+
struct drm_atomic_state *state);
13101310

13111311
/**
13121312
* @atomic_async_update:
@@ -1322,11 +1322,9 @@ struct drm_plane_helper_funcs {
13221322
* update won't happen if there is an outstanding commit modifying
13231323
* the same plane.
13241324
*
1325-
* Note that unlike &drm_plane_helper_funcs.atomic_update this hook
1326-
* takes the new &drm_plane_state as parameter. When doing async_update
1327-
* drivers shouldn't replace the &drm_plane_state but update the
1328-
* current one with the new plane configurations in the new
1329-
* plane_state.
1325+
* When doing async_update drivers shouldn't replace the
1326+
* &drm_plane_state but update the current one with the new plane
1327+
* configurations in the new plane_state.
13301328
*
13311329
* Drivers should also swap the framebuffers between current plane
13321330
* state (&drm_plane.state) and new_state.
@@ -1345,7 +1343,7 @@ struct drm_plane_helper_funcs {
13451343
* for deferring if needed, until a common solution is created.
13461344
*/
13471345
void (*atomic_async_update)(struct drm_plane *plane,
1348-
struct drm_plane_state *new_state);
1346+
struct drm_atomic_state *state);
13491347
};
13501348

13511349
/**

0 commit comments

Comments
 (0)