Skip to content

Commit 1ea0c02

Browse files
committed
drm/atomic: Unconfuse the old_state mess in commmit_tail
I totally butcherd the job on typing the kernel-doc for these, and no one realized. Noticed by Russell. Maarten has a more complete approach to this confusion, by making it more explicit what the new/old state is, instead of this magic switching behaviour. v2: - Liviu pointed out that wait_for_fences is even more magic. Leave that as @State, and document @pre_swap better. - While at it, patch in header for the reference section. - Fix spelling issues Russell noticed. v3: Fix up the @pre_swap note (Liviu): Also s/synchronous/blocking/, since async flip is something else than non-blocking. Cc: Liviu Dudau <liviu.dudau@arm.com> Reported-by: Russell King - ARM Linux <linux@armlinux.org.uk> Cc: Russell King - ARM Linux <linux@armlinux.org.uk> Fixes: 9f2a795 ("drm/atomic-helper: nonblocking commit support") Cc: Gustavo Padovan <gustavo.padovan@collabora.co.uk> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Tomeu Vizoso <tomeu.vizoso@gmail.com> Cc: Daniel Stone <daniels@collabora.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/20161121171802.24147-1-daniel.vetter@ffwll.ch
1 parent 9a83a71 commit 1ea0c02

3 files changed

Lines changed: 54 additions & 39 deletions

File tree

‎Documentation/gpu/drm-kms-helpers.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ Atomic State Reset and Initialization
6363
.. kernel-doc:: drivers/gpu/drm/drm_atomic_helper.c
6464
:doc: atomic state reset and initialization
6565

66+
Helper Functions Reference
67+
--------------------------
68+
6669
.. kernel-doc:: include/drm/drm_atomic_helper.h
6770
:internal:
6871

‎drivers/gpu/drm/drm_atomic_helper.c‎

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,21 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables);
10061006
* drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state
10071007
* @dev: DRM device
10081008
* @state: atomic state object with old state structures
1009-
* @pre_swap: if true, do an interruptible wait
1009+
* @pre_swap: If true, do an interruptible wait, and @state is the new state.
1010+
* Otherwise @state is the old state.
10101011
*
10111012
* For implicit sync, driver should fish the exclusive fence out from the
10121013
* incoming fb's and stash it in the drm_plane_state. This is called after
10131014
* drm_atomic_helper_swap_state() so it uses the current plane state (and
10141015
* just uses the atomic state to find the changed planes)
10151016
*
1017+
* Note that @pre_swap is needed since the point where we block for fences moves
1018+
* around depending upon whether an atomic commit is blocking or
1019+
* non-blocking. For async commit all waiting needs to happen after
1020+
* drm_atomic_helper_swap_state() is called, but for synchronous commits we want
1021+
* to wait **before** we do anything that can't be easily rolled back. That is
1022+
* before we call drm_atomic_helper_swap_state().
1023+
*
10161024
* Returns zero if success or < 0 if dma_fence_wait() fails.
10171025
*/
10181026
int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
@@ -1147,7 +1155,7 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
11471155

11481156
/**
11491157
* drm_atomic_helper_commit_tail - commit atomic update to hardware
1150-
* @state: new modeset state to be committed
1158+
* @old_state: atomic state object with old state structures
11511159
*
11521160
* This is the default implemenation for the ->atomic_commit_tail() hook of the
11531161
* &drm_mode_config_helper_funcs vtable.
@@ -1158,53 +1166,53 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
11581166
*
11591167
* For drivers supporting runtime PM the recommended sequence is instead ::
11601168
*
1161-
* drm_atomic_helper_commit_modeset_disables(dev, state);
1169+
* drm_atomic_helper_commit_modeset_disables(dev, old_state);
11621170
*
1163-
* drm_atomic_helper_commit_modeset_enables(dev, state);
1171+
* drm_atomic_helper_commit_modeset_enables(dev, old_state);
11641172
*
1165-
* drm_atomic_helper_commit_planes(dev, state,
1173+
* drm_atomic_helper_commit_planes(dev, old_state,
11661174
* DRM_PLANE_COMMIT_ACTIVE_ONLY);
11671175
*
11681176
* for committing the atomic update to hardware. See the kerneldoc entries for
11691177
* these three functions for more details.
11701178
*/
1171-
void drm_atomic_helper_commit_tail(struct drm_atomic_state *state)
1179+
void drm_atomic_helper_commit_tail(struct drm_atomic_state *old_state)
11721180
{
1173-
struct drm_device *dev = state->dev;
1181+
struct drm_device *dev = old_state->dev;
11741182

1175-
drm_atomic_helper_commit_modeset_disables(dev, state);
1183+
drm_atomic_helper_commit_modeset_disables(dev, old_state);
11761184

1177-
drm_atomic_helper_commit_planes(dev, state, 0);
1185+
drm_atomic_helper_commit_planes(dev, old_state, 0);
11781186

1179-
drm_atomic_helper_commit_modeset_enables(dev, state);
1187+
drm_atomic_helper_commit_modeset_enables(dev, old_state);
11801188

1181-
drm_atomic_helper_commit_hw_done(state);
1189+
drm_atomic_helper_commit_hw_done(old_state);
11821190

1183-
drm_atomic_helper_wait_for_vblanks(dev, state);
1191+
drm_atomic_helper_wait_for_vblanks(dev, old_state);
11841192

1185-
drm_atomic_helper_cleanup_planes(dev, state);
1193+
drm_atomic_helper_cleanup_planes(dev, old_state);
11861194
}
11871195
EXPORT_SYMBOL(drm_atomic_helper_commit_tail);
11881196

1189-
static void commit_tail(struct drm_atomic_state *state)
1197+
static void commit_tail(struct drm_atomic_state *old_state)
11901198
{
1191-
struct drm_device *dev = state->dev;
1199+
struct drm_device *dev = old_state->dev;
11921200
struct drm_mode_config_helper_funcs *funcs;
11931201

11941202
funcs = dev->mode_config.helper_private;
11951203

1196-
drm_atomic_helper_wait_for_fences(dev, state, false);
1204+
drm_atomic_helper_wait_for_fences(dev, old_state, false);
11971205

1198-
drm_atomic_helper_wait_for_dependencies(state);
1206+
drm_atomic_helper_wait_for_dependencies(old_state);
11991207

12001208
if (funcs && funcs->atomic_commit_tail)
1201-
funcs->atomic_commit_tail(state);
1209+
funcs->atomic_commit_tail(old_state);
12021210
else
1203-
drm_atomic_helper_commit_tail(state);
1211+
drm_atomic_helper_commit_tail(old_state);
12041212

1205-
drm_atomic_helper_commit_cleanup_done(state);
1213+
drm_atomic_helper_commit_cleanup_done(old_state);
12061214

1207-
drm_atomic_state_put(state);
1215+
drm_atomic_state_put(old_state);
12081216
}
12091217

12101218
static void commit_work(struct work_struct *work)
@@ -1498,26 +1506,26 @@ static struct drm_crtc_commit *preceeding_commit(struct drm_crtc *crtc)
14981506

14991507
/**
15001508
* drm_atomic_helper_wait_for_dependencies - wait for required preceeding commits
1501-
* @state: new modeset state to be committed
1509+
* @old_state: atomic state object with old state structures
15021510
*
15031511
* This function waits for all preceeding commits that touch the same CRTC as
1504-
* @state to both be committed to the hardware (as signalled by
1512+
* @old_state to both be committed to the hardware (as signalled by
15051513
* drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled
15061514
* by calling drm_crtc_vblank_send_event on the event member of
15071515
* &drm_crtc_state).
15081516
*
15091517
* This is part of the atomic helper support for nonblocking commits, see
15101518
* drm_atomic_helper_setup_commit() for an overview.
15111519
*/
1512-
void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state)
1520+
void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *old_state)
15131521
{
15141522
struct drm_crtc *crtc;
15151523
struct drm_crtc_state *crtc_state;
15161524
struct drm_crtc_commit *commit;
15171525
int i;
15181526
long ret;
15191527

1520-
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1528+
for_each_crtc_in_state(old_state, crtc, crtc_state, i) {
15211529
spin_lock(&crtc->commit_lock);
15221530
commit = preceeding_commit(crtc);
15231531
if (commit)
@@ -1548,7 +1556,7 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_dependencies);
15481556

15491557
/**
15501558
* drm_atomic_helper_commit_hw_done - setup possible nonblocking commit
1551-
* @state: new modeset state to be committed
1559+
* @old_state: atomic state object with old state structures
15521560
*
15531561
* This function is used to signal completion of the hardware commit step. After
15541562
* this step the driver is not allowed to read or change any permanent software
@@ -1561,15 +1569,15 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_dependencies);
15611569
* This is part of the atomic helper support for nonblocking commits, see
15621570
* drm_atomic_helper_setup_commit() for an overview.
15631571
*/
1564-
void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state)
1572+
void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *old_state)
15651573
{
15661574
struct drm_crtc *crtc;
15671575
struct drm_crtc_state *crtc_state;
15681576
struct drm_crtc_commit *commit;
15691577
int i;
15701578

1571-
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1572-
commit = state->crtcs[i].commit;
1579+
for_each_crtc_in_state(old_state, crtc, crtc_state, i) {
1580+
commit = old_state->crtcs[i].commit;
15731581
if (!commit)
15741582
continue;
15751583

@@ -1584,25 +1592,25 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done);
15841592

15851593
/**
15861594
* drm_atomic_helper_commit_cleanup_done - signal completion of commit
1587-
* @state: new modeset state to be committed
1595+
* @old_state: atomic state object with old state structures
15881596
*
1589-
* This signals completion of the atomic update @state, including any cleanup
1590-
* work. If used, it must be called right before calling
1597+
* This signals completion of the atomic update @old_state, including any
1598+
* cleanup work. If used, it must be called right before calling
15911599
* drm_atomic_state_put().
15921600
*
15931601
* This is part of the atomic helper support for nonblocking commits, see
15941602
* drm_atomic_helper_setup_commit() for an overview.
15951603
*/
1596-
void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state)
1604+
void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *old_state)
15971605
{
15981606
struct drm_crtc *crtc;
15991607
struct drm_crtc_state *crtc_state;
16001608
struct drm_crtc_commit *commit;
16011609
int i;
16021610
long ret;
16031611

1604-
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1605-
commit = state->crtcs[i].commit;
1612+
for_each_crtc_in_state(old_state, crtc, crtc_state, i) {
1613+
commit = old_state->crtcs[i].commit;
16061614
if (WARN_ON(!commit))
16071615
continue;
16081616

‎include/drm/drm_modeset_helper_vtables.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,10 +999,14 @@ struct drm_mode_config_helper_funcs {
999999
* to implement blocking and nonblocking commits easily. It is not used
10001000
* by the atomic helpers
10011001
*
1002-
* This hook should first commit the given atomic state to the hardware.
1003-
* But drivers can add more waiting calls at the start of their
1004-
* implementation, e.g. to wait for driver-internal request for implicit
1005-
* syncing, before starting to commit the update to the hardware.
1002+
* This function is called when the new atomic state has already been
1003+
* swapped into the various state pointers. The passed in state
1004+
* therefore contains copies of the old/previous state. This hook should
1005+
* commit the new state into hardware. Note that the helpers have
1006+
* already waited for preceeding atomic commits and fences, but drivers
1007+
* can add more waiting calls at the start of their implementation, e.g.
1008+
* to wait for driver-internal request for implicit syncing, before
1009+
* starting to commit the update to the hardware.
10061010
*
10071011
* After the atomic update is committed to the hardware this hook needs
10081012
* to call drm_atomic_helper_commit_hw_done(). Then wait for the upate

0 commit comments

Comments
 (0)