drm/plane: Pass old state to ->atomic_update()
Subsystems (5)
PATCH 1/5 drm/plane: Pass old state to ->atomic_update()
From: Thierry Reding <[email protected]>
In most situations it will be useful to have the old state passed to the ->atomic_update() callback. For example if a plane is being disabled the new state's .crtc field will be NULL, but some drivers may rely on this field to program the CRTCs registers.
---
Note that I based this patch on a local tree which has Daniel's Exynos prototype conversion, so the Exynos specific parts may not apply to anything else. I can respin if that's a problem.
drivers/gpu/drm/drm_atomic_helper.c | 4 +++- drivers/gpu/drm/drm_plane_helper.c | 2 +- drivers/gpu/drm/exynos/exynos_drm_plane.c | 3 ++- drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c | 3 ++- include/drm/drm_plane_helper.h | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +3 -1
@@ -1011,6 +1011,7 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,for (i =0 ; i < nplanes; i++) {struct drm_plane_helper_funcs *funcs;struct drm_plane *plane = old_state->planes[i]; +struct drm_plane_state *state = old_state->plane_states[i];if (!plane)continue ;
@@ -1020,7 +1021,8 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,if (!funcs || !funcs->atomic_update)continue ; - funcs->atomic_update (plane); +/* NOTE: state is the old state here. */ + funcs->atomic_update (plane, state); }for (i =0 ; i < ncrtcs; i++) {
drivers/gpu/drm/drm_plane_helper.c +1 -1
@@ -443,7 +443,7 @@ int drm_plane_helper_commit(struct drm_plane *plane, crtc_funcs[i]->atomic_begin (crtc[i]); } - plane_funcs->atomic_update (plane); + plane_funcs->atomic_update (plane, plane_state);for (i =0 ; i <2 ; i++) {if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
drivers/gpu/drm/exynos/exynos_drm_plane.c +2 -1
@@ -311,7 +311,8 @@ static int exynos_plane_atomic_check(struct drm_plane *plane,return 0 ; } -static void exynos_plane_atomic_update (struct drm_plane *plane) +static void exynos_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) {struct exynos_plane *exynos_plane =to_exynos_plane (plane);int ret;
drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c +2 -1
@@ -107,7 +107,8 @@ static int mdp4_plane_atomic_check(struct drm_plane *plane,return 0 ; } -static void mdp4_plane_atomic_update (struct drm_plane *plane) +static void mdp4_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) {struct drm_plane_state *state = plane->state;int ret;
include/drm/drm_plane_helper.h +2 -1
@@ -59,7 +59,8 @@ struct drm_plane_helper_funcs {int (*atomic_check)(struct drm_plane *plane,struct drm_plane_state *state); -void (*atomic_update)(struct drm_plane *plane); +void (*atomic_update)(struct drm_plane *plane, +struct drm_plane_state *old_state); }; static inline void drm_plane_helper_add(struct drm_plane *plane,
Signature · 6 lines
2.1.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/5 drm/plane: Add missing kerneldoc
From: Thierry Reding <[email protected]>
The plane helpers aren't pulled into the DocBook yet, so these weren't noticed.
--- include/drm/drm_plane_helper.h | 4 ++++ 1 file changed, 4 insertions(+)
include/drm/drm_plane_helper.h +4 -0
@@ -48,6 +48,10 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,/** * drm_plane_helper_funcs - helper operations for CRTCs +* @prepare_fb: prepare a framebuffer for use by the plane +* @cleanup_fb: cleanup a framebuffer when it's no longer used by the plane +* @atomic_check: check that a given atomic state is valid and can be applied +* @atomic_update: apply an atomic state to the plane * * The helper operations are called by the mid-layer CRTC helper. */
Signature · 6 lines
2.1.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/5 drm/plane: Add optional ->atomic_disable() callback
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
In order to prevent drivers from having to perform the same checks over and over again, add an optional ->atomic_disable callback which the core calls under the right circumstances.
--- drivers/gpu/drm/drm_atomic_helper.c | 13 ++++++++++++- drivers/gpu/drm/drm_plane_helper.c | 9 ++++++++- include/drm/drm_crtc.h | 24 ++++++++++++++++++++++++ include/drm/drm_plane_helper.h | 3 +++ 4 files changed, 47 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +12 -1
@@ -1017,8 +1017,19 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,continue ; funcs = plane->helper_private; +if (!funcs) +continue ; + +/* +* Special-case disabling the plane if drivers support it. +*/ +if (drm_plane_disabled (plane) && funcs->atomic_disable) { +/* NOTE: state is the old state here. */ + funcs->atomic_disable (plane, state); +continue ; + } -if (!funcs || !funcs->atomic_update) +if (!funcs->atomic_update)continue ;/* NOTE: state is the old state here. */
drivers/gpu/drm/drm_plane_helper.c +8 -1
@@ -443,7 +443,14 @@ int drm_plane_helper_commit(struct drm_plane *plane, crtc_funcs[i]->atomic_begin (crtc[i]); } - plane_funcs->atomic_update (plane, plane_state); +/* +* Drivers may optionally implement the ->atomic_disable callback, so +* special-case that here. +*/ +if (drm_plane_disabled (plane) && plane_funcs->atomic_disable) + plane_funcs->atomic_disable (plane, plane_state); +else + plane_funcs->atomic_update (plane, plane_state);for (i =0 ; i <2 ; i++) {if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
include/drm/drm_crtc.h +24 -0
@@ -795,6 +795,30 @@ struct drm_plane {struct drm_plane_state *state; }; +/* +* drm_plane_disabled - check whether a plane is being disabled +* @plane: plane object +* +* Checks the atomic state of a plane to determine whether it's being disabled +* or not. This also WARNs if it detects an invalid state (both CRTC and FB +* need to either both be NULL or both be non-NULL). +* +* RETURNS: +* True if the plane is being disabled, false otherwise. +*/ +static inline bool drm_plane_disabled (struct drm_plane *plane) +{ +/* +* When disabling a plane, CRTC and FB should always be NULL together. +* Anything else should be considered a bug in the atomic core, so we +* gently warn about it. +*/ +WARN_ON ((plane->state->crtc ==NULL && plane->state->fb !=NULL ) || + (plane->state->crtc !=NULL && plane->state->fb ==NULL )); + +return plane->state->crtc ==NULL || plane->state->fb ==NULL ; +} +/** * struct drm_bridge_funcs - drm_bridge control functions * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
include/drm/drm_plane_helper.h +3 -0
@@ -52,6 +52,7 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* @cleanup_fb: cleanup a framebuffer when it's no longer used by the plane * @atomic_check: check that a given atomic state is valid and can be applied * @atomic_update: apply an atomic state to the plane +* @atomic_disable: disable the plane * * The helper operations are called by the mid-layer CRTC helper. */
@@ -65,6 +66,8 @@ struct drm_plane_helper_funcs { struct drm_plane_state *state);void (*atomic_update)(struct drm_plane *plane,struct drm_plane_state *old_state); +void (*atomic_disable)(struct drm_plane *plane, +struct drm_plane_state *old_state); }; static inline void drm_plane_helper_add(struct drm_plane *plane,
Signature · 6 lines
2.1.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/5 drm: Make drm_atomic_helper.h standalone includible
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This header uses a bunch of declarations from the drm/drm_crtc.h header, so make sure to include that as well so that drm_atomic_helper.h can be included standalone.
--- include/drm/drm_atomic_helper.h | 2 ++ 1 file changed, 2 insertions(+)
include/drm/drm_atomic_helper.h +2 -0
@@ -28,6 +28,8 @@#ifndef DRM_ATOMIC_HELPER_H_ #define DRM_ATOMIC_HELPER_H_ +#include <drm/drm_crtc.h> +int drm_atomic_helper_check (struct drm_device *dev,struct drm_atomic_state *state); int drm_atomic_helper_commit(struct drm_device *dev,
Signature · 6 lines
2.1.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/5 drm: Free atomic state during cleanup
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The current state of CRTCs, planes and connectors currently leaks during DRM driver ->unload() unless drivers explicitly clean it up. Since there is nothing driver-specific about it, that cleanup can be done within the DRM core.
--- drivers/gpu/drm/drm_crtc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/drm_crtc.c +13 -0
@@ -721,6 +721,10 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)drm_mode_object_put (dev, &crtc->base);list_del (&crtc->head); dev->mode_config.num_crtc--; + +WARN_ON (crtc->state && !crtc->funcs->atomic_destroy_state); +if (crtc->state && crtc->funcs->atomic_destroy_state) + crtc->funcs->atomic_destroy_state (crtc, crtc->state); }EXPORT_SYMBOL (drm_crtc_cleanup);
@@ -918,6 +922,11 @@ void drm_connector_cleanup(struct drm_connector *connector) connector->name =NULL ;list_del (&connector->head); dev->mode_config.num_connector--; + +WARN_ON (connector->state && !connector->funcs->atomic_destroy_state); +if (connector->state && connector->funcs->atomic_destroy_state) + connector->funcs->atomic_destroy_state (connector, + connector->state); }EXPORT_SYMBOL (drm_connector_cleanup);
@@ -1244,6 +1253,10 @@ void drm_plane_cleanup(struct drm_plane *plane)if (plane->type ==DRM_PLANE_TYPE_OVERLAY ) dev->mode_config.num_overlay_plane--;drm_modeset_unlock_all (dev); + +WARN_ON (plane->state && !plane->funcs->atomic_destroy_state); +if (plane->state && plane->funcs->atomic_destroy_state) + plane->funcs->atomic_destroy_state (plane, plane->state); }EXPORT_SYMBOL (drm_plane_cleanup);
Signature · 6 lines
2.1.3 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 5/5] drm: Free atomic state during cleanup
Quoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
The current state of CRTCs, planes and connectors currently leaks during DRM driver ->unload() unless drivers explicitly clean it up. Since there is nothing driver-specific about it, that cleanup can be done within the DRM core.
Signed-off-by Thierry Reding <[email protected]>
Patches 2, 4 & this one here are
Cheers, Daniel
Quoted 45 lines
--- drivers/gpu/drm/drm_crtc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/gpu/drm/drm_crtc.c +13
-0@@ -721,6 +721,10 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)drm_mode_object_put (dev, &crtc->base);list_del (&crtc->head); dev->mode_config.num_crtc--; + +WARN_ON (crtc->state && !crtc->funcs->atomic_destroy_state); +if (crtc->state && crtc->funcs->atomic_destroy_state) + crtc->funcs->atomic_destroy_state (crtc, crtc->state); }EXPORT_SYMBOL (drm_crtc_cleanup);@@ -918,6 +922,11 @@ void drm_connector_cleanup(struct drm_connector *connector) connector->name =NULL ;list_del (&connector->head); dev->mode_config.num_connector--; + +WARN_ON (connector->state && !connector->funcs->atomic_destroy_state); +if (connector->state && connector->funcs->atomic_destroy_state) + connector->funcs->atomic_destroy_state (connector, + connector->state); }EXPORT_SYMBOL (drm_connector_cleanup);@@ -1244,6 +1253,10 @@ void drm_plane_cleanup(struct drm_plane *plane)if (plane->type ==DRM_PLANE_TYPE_OVERLAY ) dev->mode_config.num_overlay_plane--;drm_modeset_unlock_all (dev); + +WARN_ON (plane->state && !plane->funcs->atomic_destroy_state); +if (plane->state && plane->funcs->atomic_destroy_state) + plane->funcs->atomic_destroy_state (plane, plane->state); }EXPORT_SYMBOL (drm_plane_cleanup);Signature · 1 line
2.1.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
Quoted 33 lines · Thierry Reding
From: Thierry Reding <[email protected]>
In most situations it will be useful to have the old state passed to the ->atomic_update() callback. For example if a plane is being disabled the new state's .crtc field will be NULL, but some drivers may rely on this field to program the CRTCs registers.
Signed-off-by Thierry Reding <[email protected]>---
Note that I based this patch on a local tree which has Daniel's Exynos prototype conversion, so the Exynos specific parts may not apply to anything else. I can respin if that's a problem.drivers/gpu/drm/drm_atomic_helper.c | 4 +++- drivers/gpu/drm/drm_plane_helper.c | 2 +- drivers/gpu/drm/exynos/exynos_drm_plane.c | 3 ++- drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c | 3 ++- include/drm/drm_plane_helper.h | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +1
-0@@ -1011,6 +1011,7 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,for (i =0 ; i < nplanes; i++) {struct drm_plane_helper_funcs *funcs;struct drm_plane *plane = old_state->planes[i]; +struct drm_plane_state *state = old_state->plane_states[i];if (!plane)continue ;
drivers/gpu/drm/drm_atomic_helper.c void drm_atomic_helper_commit_planes(struct drm_device *dev, · line 1024
Quoted 5 lines
drivers/gpu/drm/drm_atomic_helper.c +1
-1@@ -1020,7 +1021,8 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,if (!funcs || !funcs->atomic_update)continue ; - funcs->atomic_update (plane); +/* NOTE: state is the old state here. */
Call the variable old_plane_state and remove the comment imo. Otherwise
Quoted 62 lines
drivers/gpu/drm/drm_atomic_helper.c +1
-0+ funcs->atomic_update (plane, state); }for (i =0 ; i < ncrtcs; i++) {drivers/gpu/drm/drm_plane_helper.c +1
-1@@ -443,7 +443,7 @@ int drm_plane_helper_commit(struct drm_plane *plane, crtc_funcs[i]->atomic_begin (crtc[i]); } - plane_funcs->atomic_update (plane); + plane_funcs->atomic_update (plane, plane_state);for (i =0 ; i <2 ; i++) {if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)drivers/gpu/drm/exynos/exynos_drm_plane.c +2
-1@@ -311,7 +311,8 @@ static int exynos_plane_atomic_check(struct drm_plane *plane,return 0 ; } -static void exynos_plane_atomic_update (struct drm_plane *plane) +static void exynos_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) {struct exynos_plane *exynos_plane =to_exynos_plane (plane);int ret;drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c +2
-1@@ -107,7 +107,8 @@ static int mdp4_plane_atomic_check(struct drm_plane *plane,return 0 ; } -static void mdp4_plane_atomic_update (struct drm_plane *plane) +static void mdp4_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) {struct drm_plane_state *state = plane->state;int ret;include/drm/drm_plane_helper.h +2
-1@@ -59,7 +59,8 @@ struct drm_plane_helper_funcs {int (*atomic_check)(struct drm_plane *plane,struct drm_plane_state *state); -void (*atomic_update)(struct drm_plane *plane); +void (*atomic_update)(struct drm_plane *plane, +struct drm_plane_state *old_state); }; static inline void drm_plane_helper_add(struct drm_plane *plane,Signature · 1 line
2.1.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 3/5] drm/plane: Add optional ->atomic_disable() callback
In reply to Thierry RedingQuoted 7 lines · Thierry Reding
From: Thierry Reding <[email protected]>
In order to prevent drivers from having to perform the same checks over and over again, add an optional ->atomic_disable callback which the core calls under the right circumstances.
Signed-off-by Thierry Reding <[email protected]>
One comment below, looks good otherwise.
Quoted 72 lines
--- drivers/gpu/drm/drm_atomic_helper.c | 13 ++++++++++++- drivers/gpu/drm/drm_plane_helper.c | 9 ++++++++- include/drm/drm_crtc.h | 24 ++++++++++++++++++++++++ include/drm/drm_plane_helper.h | 3 +++ 4 files changed, 47 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +12
-1@@ -1017,8 +1017,19 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,continue ; funcs = plane->helper_private; +if (!funcs) +continue ; + +/* +* Special-case disabling the plane if drivers support it. +*/ +if (drm_plane_disabled (plane) && funcs->atomic_disable) { +/* NOTE: state is the old state here. */ + funcs->atomic_disable (plane, state); +continue ; + } -if (!funcs || !funcs->atomic_update) +if (!funcs->atomic_update)continue ;/* NOTE: state is the old state here. */ drivers/gpu/drm/drm_plane_helper.c +8
-1@@ -443,7 +443,14 @@ int drm_plane_helper_commit(struct drm_plane *plane, crtc_funcs[i]->atomic_begin (crtc[i]); } - plane_funcs->atomic_update (plane, plane_state); +/* +* Drivers may optionally implement the ->atomic_disable callback, so +* special-case that here. +*/ +if (drm_plane_disabled (plane) && plane_funcs->atomic_disable) + plane_funcs->atomic_disable (plane, plane_state); +else + plane_funcs->atomic_update (plane, plane_state);for (i =0 ; i <2 ; i++) {if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)include/drm/drm_crtc.h +12
-0@@ -795,6 +795,30 @@ struct drm_plane {struct drm_plane_state *state; }; +/* +* drm_plane_disabled - check whether a plane is being disabled +* @plane: plane object +* +* Checks the atomic state of a plane to determine whether it's being disabled +* or not. This also WARNs if it detects an invalid state (both CRTC and FB +* need to either both be NULL or both be non-NULL). +* +* RETURNS: +* True if the plane is being disabled, false otherwise. +*/ +static inline bool drm_plane_disabled (struct drm_plane *plane)
include/drm/drm_crtc.h struct drm_plane { · line 819
Quoted 10 lines
include/drm/drm_crtc.h +10
-0+{ +/* +* When disabling a plane, CRTC and FB should always be NULL together. +* Anything else should be considered a bug in the atomic core, so we +* gently warn about it. +*/ +WARN_ON ((plane->state->crtc ==NULL && plane->state->fb !=NULL ) || + (plane->state->crtc !=NULL && plane->state->fb ==NULL )); + +return plane->state->crtc ==NULL || plane->state->fb ==NULL ;
I think we should only detect disabling edges here so that multiple disables (userspace or drm core might do stupid things) don't result in multiple disable calls. So would amount to passing the old state and changing the check to
return old_state->crtc && !plane->state->crtc;
Imo keeping the || here is redudant, the WARN_ON is good enough. -Daniel
Quoted 29 lines
include/drm/drm_crtc.h +2
-0+} +/** * struct drm_bridge_funcs - drm_bridge control functions * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge include/drm/drm_plane_helper.h +3
-0@@ -52,6 +52,7 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* @cleanup_fb: cleanup a framebuffer when it's no longer used by the plane * @atomic_check: check that a given atomic state is valid and can be applied * @atomic_update: apply an atomic state to the plane +* @atomic_disable: disable the plane * * The helper operations are called by the mid-layer CRTC helper. */ @@ -65,6 +66,8 @@ struct drm_plane_helper_funcs { struct drm_plane_state *state);void (*atomic_update)(struct drm_plane *plane,struct drm_plane_state *old_state); +void (*atomic_disable)(struct drm_plane *plane, +struct drm_plane_state *old_state); }; static inline void drm_plane_helper_add(struct drm_plane *plane,Signature · 1 line
2.1.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