drm/atomic: track bitmask of planes attached to crtc
Subsystems (3)
PATCH 1/2 drm/atomic: track bitmask of planes attached to crtc
Chasing plane->state->crtc of planes that are *not* part of the same atomic update is racy, making it incredibly awkward (or impossible) to do something simple like iterate over all planes and figure out which ones are attached to a crtc.
Solve this by adding a bitmask of currently attached planes in the crtc-state.
Note that the transitional helpers do not maintain the plane_mask. But they only support the legacy ioctls, which have sufficient brute-force locking around plane updates that they can continue to loop over all planes to see what is attached to a crtc the old way.
--- drivers/gpu/drm/drm_atomic.c | 25 ++++++++++++++++++++----- drivers/gpu/drm/drm_atomic_helper.c | 8 ++++---- include/drm/drm_atomic.h | 4 ++-- include/drm/drm_crtc.h | 14 +++++++++++--- 4 files changed, 37 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_atomic.c +20 -5
@@ -350,7 +350,8 @@ EXPORT_SYMBOL(drm_atomic_get_connector_state);/** * drm_atomic_set_crtc_for_plane - set crtc for plane -* @plane_state: atomic state object for the plane +* @state: the incoming atomic state +* @plane: the plane whose incoming state to update * @crtc: crtc to use for the plane * * Changing the assigned crtc for a plane requires us to grab the lock and state
@@ -363,20 +364,34 @@ EXPORT_SYMBOL(drm_atomic_get_connector_state);* sequence must be restarted. All other errors are fatal. */ int -drm_atomic_set_crtc_for_plane (struct drm_plane_state *plane_state, -struct drm_crtc *crtc) +drm_atomic_set_crtc_for_plane (struct drm_atomic_state *state, +struct drm_plane *plane,struct drm_crtc *crtc) { +struct drm_plane_state *plane_state = +drm_atomic_get_plane_state (state, plane);struct drm_crtc_state *crtc_state; -if (crtc) { +/* acquire outgoing crtc lock, and clear bit in outgoing crtc mask: */ +if (plane_state->crtc) { crtc_state =drm_atomic_get_crtc_state (plane_state->state, - crtc); + plane_state->crtc);if (IS_ERR (crtc_state))return PTR_ERR (crtc_state); + + crtc_state->plane_mask &= ~(1 <<drm_plane_index (plane)); } plane_state->crtc = crtc; +/* acquire incoming crtc lock, and set bit in incoming crtc mask: */ +if (crtc) { + crtc_state =drm_atomic_get_crtc_state (plane_state->state, + crtc); +if (IS_ERR (crtc_state)) +return PTR_ERR (crtc_state); + crtc_state->plane_mask |= (1 <<drm_plane_index (plane)); + } +if (crtc)DRM_DEBUG_KMS ("Link plane state %p to [CRTC:%d]\n" , plane_state, crtc->base.id);
drivers/gpu/drm/drm_atomic_helper.c +4 -4
@@ -1187,7 +1187,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, plane, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state, fb);
@@ -1255,7 +1255,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state,NULL ); + ret =drm_atomic_set_crtc_for_plane (state, plane,NULL );if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state,NULL );
@@ -1426,7 +1426,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (primary_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, crtc->primary, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (primary_state, set->fb);
@@ -1698,7 +1698,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, plane, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state, fb);
include/drm/drm_atomic.h +2 -2
@@ -44,8 +44,8 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state, struct drm_connector *connector);int __must_check -drm_atomic_set_crtc_for_plane (struct drm_plane_state *plane_state, -struct drm_crtc *crtc); +drm_atomic_set_crtc_for_plane (struct drm_atomic_state *state, +struct drm_plane *plane,struct drm_crtc *crtc);void drm_atomic_set_fb_for_plane (struct drm_plane_state *plane_state,struct drm_framebuffer *fb);int __must_check
include/drm/drm_crtc.h +11 -3
@@ -231,6 +231,7 @@ struct drm_atomic_state;* struct drm_crtc_state - mutable CRTC state * @enable: whether the CRTC should be enabled, gates all other state * @mode_changed: for use by helpers and drivers when computing state updates +* @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes * @last_vblank_count: for helpers and drivers to capture the vblank of the * update to ensure framebuffer cleanup isn't done too early * @planes_changed: for use by helpers and drivers when computing state updates
@@ -247,6 +248,13 @@ struct drm_crtc_state { bool planes_changed : 1; bool mode_changed : 1; +/* attached planes bitmask: +* WARNING: transitional helpers do not maintain plane_mask so +* drivers not converted over to atomic helpers should not rely +* on plane_mask being accurate! +*/ +u32 plane_mask; +/* last_vblank_count: for vblank waits before cleanup */ u32 last_vblank_count;
@@ -438,7 +446,7 @@ struct drm_crtc {* @state: backpointer to global drm_atomic_state */ struct drm_connector_state { -struct drm_crtc *crtc; +struct drm_crtc *crtc;/* do not write directly, use drm_atomic_set_crtc_for_connector() */ struct drm_encoder *best_encoder;
@@ -673,8 +681,8 @@ struct drm_connector {* @state: backpointer to global drm_atomic_state */ struct drm_plane_state { -struct drm_crtc *crtc; -struct drm_framebuffer *fb; +struct drm_crtc *crtc;/* do not write directly, use drm_atomic_set_crtc_for_plane() */ +struct drm_framebuffer *fb;/* do not write directly, use drm_atomic_set_fb_for_plane() */ struct fence *fence;/* Signed dest location allows it to be partially off screen */
Signature · 6 lines
1.9.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm/atomic: add plane iterator macros
Add helper macros to iterate the current, or incoming set of planes attached to a crtc. These helpers are only available for drivers converted to use atomic-helpers.
--- Documentation/DocBook/drm.tmpl | 1 + include/drm/drm_atomic_helper.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
Documentation/DocBook/drm.tmpl +1 -0
@@ -2343,6 +2343,7 @@ void intel_crt_init(struct drm_device *dev) <title>Atomic State Reset and Initialization</title> !Pdrivers/gpu/drm/drm_atomic_helper.c atomic state reset and initialization </sect3> +!Iinclude/drm/drm_atomic_helper.h !Edrivers/gpu/drm/drm_atomic_helper.c </sect2> <sect2>
include/drm/drm_atomic_helper.h +26 -0
@@ -96,5 +96,31 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);void drm_atomic_helper_connector_destroy_state (struct drm_connector *connector,struct drm_connector_state *state); +/** +* drm_crtc_for_each_plane - iterate over planes currently attached to crtc +* @plane: the loop cursor +* @crtc: the crtc whose planes are iterated +* +* This iterates over the current state, useful (for example) when applying +* atomic state after it has been checked and swapped. To iterate over the +* planes which *will* be attached (for ->atomic_check()) see +* drm_crtc_for_each_pending_plane() +*/ +#define drm_crtc_for_each_plane (plane, crtc) \ + list_for_each_entry((plane), &(crtc)->dev->mode_config.plane_list, head) \ + if ((crtc)->state->plane_mask & (1 << drm_plane_index(plane))) + +/** +* drm_crtc_for_each_pending_plane - iterate over attached planes in new state +* @plane: the loop cursor +* @crtc_state: the incoming crtc-state +* +* Similar to drm_crtc_for_each_plane(), but iterates the planes that will be +* attached if the specified state is applied. Useful during (for example) +* ->atomic_check() operations, to validate the incoming state +*/ +#define drm_crtc_for_each_pending_plane (plane, crtc_state) \ + list_for_each_entry((plane), &(crtc_state)->state->dev->mode_config.plane_list, head) \ + if ((crtc_state)->plane_mask & (1 << drm_plane_index(plane)))#endif /* DRM_ATOMIC_HELPER_H_ */
Signature · 6 lines
1.9.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/atomic: add plane iterator macros
Quoted 33 lines · Rob Clark
Add helper macros to iterate the current, or incoming set of planes attached to a crtc. These helpers are only available for drivers converted to use atomic-helpers.
Signed-off-by Rob Clark <[email protected]>--- Documentation/DocBook/drm.tmpl | 1 + include/drm/drm_atomic_helper.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)Documentation/DocBook/drm.tmpl +1
-0@@ -2343,6 +2343,7 @@ void intel_crt_init(struct drm_device *dev) <title>Atomic State Reset and Initialization</title> !Pdrivers/gpu/drm/drm_atomic_helper.c atomic state reset and initialization </sect3> +!Iinclude/drm/drm_atomic_helper.h !Edrivers/gpu/drm/drm_atomic_helper.c </sect2> <sect2>include/drm/drm_atomic_helper.h +3
-0@@ -96,5 +96,31 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);void drm_atomic_helper_connector_destroy_state (struct drm_connector *connector,struct drm_connector_state *state); +/** +* drm_crtc_for_each_plane - iterate over planes currently attached to crtc +* @plane: the loop cursor
include/drm/drm_atomic_helper.h drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector); · line 111
Quoted 10 lines
include/drm/drm_atomic_helper.h +10
-0+* @crtc: the crtc whose planes are iterated +* +* This iterates over the current state, useful (for example) when applying +* atomic state after it has been checked and swapped. To iterate over the +* planes which *will* be attached (for ->atomic_check()) see +* drm_crtc_for_each_pending_plane() +*/ +#define drm_crtc_for_each_plane (plane, crtc) \ + list_for_each_entry((plane), &(crtc)->dev->mode_config.plane_list, head) \ + if ((crtc)->state->plane_mask & (1 << drm_plane_index(plane)))
Implement this as drm_crtc_for_each_pending_plane(plane, (crtc)->state)? Which means _pending is a strange name ...
-Daniel
Quoted 18 lines
include/drm/drm_atomic_helper.h +13
-0+ +/** +* drm_crtc_for_each_pending_plane - iterate over attached planes in new state +* @plane: the loop cursor +* @crtc_state: the incoming crtc-state +* +* Similar to drm_crtc_for_each_plane(), but iterates the planes that will be +* attached if the specified state is applied. Useful during (for example) +* ->atomic_check() operations, to validate the incoming state +*/ +#define drm_crtc_for_each_pending_plane (plane, crtc_state) \ + list_for_each_entry((plane), &(crtc_state)->state->dev->mode_config.plane_list, head) \ + if ((crtc_state)->plane_mask & (1 << drm_plane_index(plane)))#endif /* DRM_ATOMIC_HELPER_H_ */ Signature · 1 line
1.9.3
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/atomic: add plane iterator macros
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Rob Clark
Add helper macros to iterate the current, or incoming set of planes attached to a crtc. These helpers are only available for drivers converted to use atomic-helpers.
Signed-off-by Rob Clark <[email protected]>--- Documentation/DocBook/drm.tmpl | 1 + include/drm/drm_atomic_helper.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)Documentation/DocBook/drm.tmpl +1
-0@@ -2343,6 +2343,7 @@ void intel_crt_init(struct drm_device *dev) <title>Atomic State Reset and Initialization</title> !Pdrivers/gpu/drm/drm_atomic_helper.c atomic state reset and initialization </sect3> +!Iinclude/drm/drm_atomic_helper.h !Edrivers/gpu/drm/drm_atomic_helper.c </sect2> <sect2>include/drm/drm_atomic_helper.h +0
-0@@ -96,5 +96,31 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);void drm_atomic_helper_connector_destroy_state (struct drm_connector *connector,struct drm_connector_state *state);
Quoted 16 lines
include/drm/drm_atomic_helper.h drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector); · line 111
Quoted 13 lines
include/drm/drm_atomic_helper.h +13
-0+/** +* drm_crtc_for_each_plane - iterate over planes currently attached to crtc +* @plane: the loop cursor +* @crtc: the crtc whose planes are iterated +* +* This iterates over the current state, useful (for example) when applying +* atomic state after it has been checked and swapped. To iterate over the +* planes which *will* be attached (for ->atomic_check()) see +* drm_crtc_for_each_pending_plane() +*/ +#define drm_crtc_for_each_plane (plane, crtc) \ + list_for_each_entry((plane), &(crtc)->dev->mode_config.plane_list, head) \ + if ((crtc)->state->plane_mask & (1 << drm_plane_index(plane)))Implement this as
drm_crtc_for_each_pending_plane(plane, (crtc)->state)? Which means_pendingis a strange name ...
Yeah, I think the drm_crtc_for_each_pending_plane() could be drm_crtc_state_for_each_plane(), then your suggestion makes perfect sense.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/atomic: add plane iterator macros
Quoted 9 lines · Thierry Reding
Quoted 7 lines · Daniel Vetter
include/drm/drm_atomic_helper.h drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector); · line 111
Quoted 3 lines · Rob Clark
include/drm/drm_atomic_helper.h +3
-0+#define drm_crtc_for_each_plane (plane, crtc) \ + list_for_each_entry((plane), &(crtc)->dev->mode_config.plane_list, head) \ + if ((crtc)->state->plane_mask & (1 << drm_plane_index(plane)))Implement this as
drm_crtc_for_each_pending_plane(plane, (crtc)->state)? Which means_pendingis a strange name ...
Quoted 3 lines
Yeah, I think the
drm_crtc_for_each_pending_plane()could bedrm_crtc_state_for_each_plane(), then your suggestion makes perfect sense.
I like Thierry's naming here. Rob can you apply that please?
Thanks, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/atomic: add plane iterator macros
In reply to Rob ClarkQuoted 9 lines · Rob Clark
Add helper macros to iterate the current, or incoming set of planes attached to a crtc. These helpers are only available for drivers converted to use atomic-helpers.
Signed-off-by Rob Clark <[email protected]>--- Documentation/DocBook/drm.tmpl | 1 + include/drm/drm_atomic_helper.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
I'd personally do s/crtc/CRTC/ in the commit message and kerneldoc descriptions, but perhaps not everyone shares that same pedantry.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 40 lines · Rob Clark
Chasing
plane->state->crtcof planes that are *not* part of the same atomic update is racy, making it incredibly awkward (or impossible) to do something simple like iterate over all planes and figure out which ones are attached to a crtc.Solve this by adding a bitmask of currently attached planes in the crtc-state.
Note that the transitional helpers do not maintain the
plane_mask. But they only support the legacy ioctls, which have sufficient brute-force locking around plane updates that they can continue to loop over all planes to see what is attached to a crtc the old way.Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/drm_atomic.c | 25 ++++++++++++++++++++----- drivers/gpu/drm/drm_atomic_helper.c | 8 ++++---- include/drm/drm_atomic.h | 4 ++-- include/drm/drm_crtc.h | 14 +++++++++++--- 4 files changed, 37 insertions(+), 14 deletions(-)drivers/gpu/drm/drm_atomic.c +2
-2@@ -350,7 +350,8 @@ EXPORT_SYMBOL(drm_atomic_get_connector_state);/** * drm_atomic_set_crtc_for_plane - set crtc for plane -* @plane_state: atomic state object for the plane +* @state: the incoming atomic state +* @plane: the plane whose incoming state to update * @crtc: crtc to use for the plane * * Changing the assigned crtc for a plane requires us to grab the lock and state @@ -363,20 +364,34 @@ EXPORT_SYMBOL(drm_atomic_get_connector_state);* sequence must be restarted. All other errors are fatal. */ int -drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
drivers/gpu/drm/drm_atomic.c EXPORT_SYMBOL(drm_atomic_get_connector_state); · line 374
Quoted 10 lines
drivers/gpu/drm/drm_atomic.c +5
-2- struct drm_crtc *crtc) +drm_atomic_set_crtc_for_plane(struct drm_atomic_state *state, + struct drm_plane *plane, struct drm_crtc *crtc) { + struct drm_plane_state *plane_state = +drm_atomic_get_plane_state (state, plane);struct drm_crtc_state *crtc_state; -if (crtc) { +/* acquire outgoing crtc lock, and clear bit in outgoing crtc mask: */
Ok still don't like these comments since at least for the old crtc it's
wrong: We already must both hold the lock and copied the state. So I've dropped them (kerneldoc already mentions this too).
drivers/gpu/drm/drm_atomic.c EXPORT_SYMBOL(drm_atomic_get_connector_state); · line 378
Quoted 5 lines
drivers/gpu/drm/drm_atomic.c +2
-1+if (plane_state->crtc) { crtc_state =drm_atomic_get_crtc_state (plane_state->state, - crtc); + plane_state->crtc);if (IS_ERR (crtc_state))
And changed this to WARN_ON too to make sure this never fails. The pulled it into my atomic-fixes branch.
-Daniel
Quoted 123 lines
drivers/gpu/drm/drm_atomic.c +11
-0return PTR_ERR (crtc_state); + + crtc_state->plane_mask &= ~(1 <<drm_plane_index (plane)); } plane_state->crtc = crtc; +/* acquire incoming crtc lock, and set bit in incoming crtc mask: */ +if (crtc) { + crtc_state =drm_atomic_get_crtc_state (plane_state->state, + crtc); +if (IS_ERR (crtc_state)) +return PTR_ERR (crtc_state); + crtc_state->plane_mask |= (1 <<drm_plane_index (plane)); + } +if (crtc)DRM_DEBUG_KMS ("Link plane state %p to [CRTC:%d]\n" , plane_state, crtc->base.id);drivers/gpu/drm/drm_atomic_helper.c +4
-4@@ -1187,7 +1187,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, plane, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state, fb);@@ -1255,7 +1255,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state,NULL ); + ret =drm_atomic_set_crtc_for_plane (state, plane,NULL );if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state,NULL );@@ -1426,7 +1426,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (primary_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, crtc->primary, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (primary_state, set->fb);@@ -1698,7 +1698,7 @@ retry: goto fail; } - ret =drm_atomic_set_crtc_for_plane (plane_state, crtc); + ret =drm_atomic_set_crtc_for_plane (state, plane, crtc);if (ret !=0 ) goto fail;drm_atomic_set_fb_for_plane (plane_state, fb);include/drm/drm_atomic.h +2
-2@@ -44,8 +44,8 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state, struct drm_connector *connector);int __must_check -drm_atomic_set_crtc_for_plane (struct drm_plane_state *plane_state, -struct drm_crtc *crtc); +drm_atomic_set_crtc_for_plane (struct drm_atomic_state *state, +struct drm_plane *plane,struct drm_crtc *crtc);void drm_atomic_set_fb_for_plane (struct drm_plane_state *plane_state,struct drm_framebuffer *fb);int __must_check include/drm/drm_crtc.h +11
-3@@ -231,6 +231,7 @@ struct drm_atomic_state;* struct drm_crtc_state - mutable CRTC state * @enable: whether the CRTC should be enabled, gates all other state * @mode_changed: for use by helpers and drivers when computing state updates +* @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes * @last_vblank_count: for helpers and drivers to capture the vblank of the * update to ensure framebuffer cleanup isn't done too early * @planes_changed: for use by helpers and drivers when computing state updates @@ -247,6 +248,13 @@ struct drm_crtc_state { bool planes_changed : 1; bool mode_changed : 1; +/* attached planes bitmask: +* WARNING: transitional helpers do not maintain plane_mask so +* drivers not converted over to atomic helpers should not rely +* on plane_mask being accurate! +*/ +u32 plane_mask; +/* last_vblank_count: for vblank waits before cleanup */ u32 last_vblank_count;@@ -438,7 +446,7 @@ struct drm_crtc {* @state: backpointer to global drm_atomic_state */ struct drm_connector_state { -struct drm_crtc *crtc; +struct drm_crtc *crtc;/* do not write directly, use drm_atomic_set_crtc_for_connector() */ struct drm_encoder *best_encoder;@@ -673,8 +681,8 @@ struct drm_connector {* @state: backpointer to global drm_atomic_state */ struct drm_plane_state { -struct drm_crtc *crtc; -struct drm_framebuffer *fb; +struct drm_crtc *crtc;/* do not write directly, use drm_atomic_set_crtc_for_plane() */ +struct drm_framebuffer *fb;/* do not write directly, use drm_atomic_set_fb_for_plane() */ struct fence *fence;/* Signed dest location allows it to be partially off screen */ Signature · 1 line
1.9.3
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel