Add a drm_crtc_helper_atomic_check() helper
Subsystems (4)
Javier Martinez Canillas
maintainerv2 cover Add a drm_crtc_helper_atomic_check() helper
Add a helper function and make drivers that have the same logic in their struct drm_crtc_helper_funcs .atomic_check handler to use this instead.
Patch #1, #2 and #3 are just cleanups for the mgag200, simpledrm and ssd130x drivers respectively. Finally patch #4 converts the last two drivers to use a helper instead of open coding it the same logic.
The changes are inspired by a patch from Thomas Zimmermann for the ast DRM driver:
https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
This is a v2 that addresses issues pointed out also by Thomas in v1:
https://lists.freedesktop.org/archives/dri-devel/2022-October/375363.html
Best regards,
Javier
Changes in v2:
- Reference drm_plane_helper_atomic_check() from drm_crtc_atomic_check() kernel doc comments and viceversa (Thomas Zimmermann).
Javier Martinez Canillas (4):
drm/mgag200: Do not call drm_atomic_add_affected_planes() drm/simpledrm: Do not call drm_atomic_add_affected_planes() drm/ssd130x: Do not call drm_atomic_add_affected_planes() drm/crtc-helper: Add a drm_crtc_helper_atomic_check() helper
drivers/gpu/drm/drm_crtc_helper.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/drm_plane_helper.c | 4 +++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/solomon/ssd130x.c | 20 ++------------------ drivers/gpu/drm/tiny/simpledrm.c | 20 ++------------------ include/drm/drm_crtc_helper.h | 2 ++ 6 files changed, 36 insertions(+), 38 deletions(-)
Signature · 1 line
2.37.3
Javier Martinez Canillas
maintainerPATCH v2 1/4 drm/mgag200: Do not call drm_atomic_add_affected_planes()
There's no need to add planes to the atomic state. Remove the call to drm_atomic_add_affected_planes() from mgag200.
On full modesets, the DRM helpers already add a CRTC's planes to the atomic state; see drm_atomic_helper_check_modeset(). There's no reason to call drm_atomic_add_affected_planes() unconditionally in the CRTC's atomic_check() in mgag200. It's also too late, as the atomic_check() of the added planes will not be called before the commit.
---
(no changes since v1)
drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -1
@@ -601,7 +601,7 @@ int mgag200_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_st } } -return drm_atomic_add_affected_planes (new_state, crtc); +return 0 ; }void mgag200_crtc_helper_atomic_flush (struct drm_crtc *crtc,struct drm_atomic_state *old_state)
Signature · 1 line
2.37.3
Re: [PATCH v2 1/4] drm/mgag200: Do not call drm_atomic_add_affected_planes()
Am 11.10.22 um 18:51 schrieb Javier Martinez Canillas:
Quoted 11 lines
There's no need to add planes to the atomic state. Remove the call to
drm_atomic_add_affected_planes()from mgag200.On full modesets, the DRM helpers already add a CRTC's planes to the atomic state; see
drm_atomic_helper_check_modeset(). There's no reason to calldrm_atomic_add_affected_planes()unconditionally in the CRTC'satomic_check()in mgag200. It's also too late, as theatomic_check()of the added planes will not be called before the commit.Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>
Quoted 20 lines
---
(no changes since v1)
drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1@@ -601,7 +601,7 @@ int mgag200_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_st } } -return drm_atomic_add_affected_planes (new_state, crtc); +return 0 ; }void mgag200_crtc_helper_atomic_flush (struct drm_crtc *crtc,struct drm_atomic_state *old_state)
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Javier Martinez Canillas
maintainerPATCH v2 2/4 drm/simpledrm: Do not call drm_atomic_add_affected_planes()
In reply to Javier Martinez CanillasThere's no need to add planes to the atomic state. Remove the call to drm_atomic_add_affected_planes() from simpledrm.
On full modesets, the DRM helpers already add a CRTC's planes to the atomic state; see drm_atomic_helper_check_modeset(). There's no reason to call drm_atomic_add_affected_planes() unconditionally in the CRTC's atomic_check() in simpledrm. It's also too late, as the atomic_check() of the added planes will not be called before the commit.
---
(no changes since v1)
drivers/gpu/drm/tiny/simpledrm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/drm/tiny/simpledrm.c +2 -8
@@ -549,17 +549,11 @@ static int simpledrm_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *new_state) {struct drm_crtc_state *new_crtc_state =drm_atomic_get_new_crtc_state (new_state, crtc); -int ret;if (!new_crtc_state->enable) - goto out; - - ret =drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); -if (ret) -return ret; +return 0 ; -out: -return drm_atomic_add_affected_planes (new_state, crtc); +return drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); }/*
Signature · 1 line
2.37.3
Javier Martinez Canillas
maintainerPATCH v2 3/4 drm/ssd130x: Do not call drm_atomic_add_affected_planes()
In reply to Javier Martinez CanillasThere's no need to add planes to the atomic state. Remove the call to drm_atomic_add_affected_planes() from ssd130x.
On full modesets, the DRM helpers already add a CRTC's planes to the atomic state; see drm_atomic_helper_check_modeset(). There's no reason to call drm_atomic_add_affected_planes() unconditionally in the CRTC's atomic_check() in ssd130x. It's also too late, as the atomic_check() of the added planes will not be called before the commit.
---
(no changes since v1)
drivers/gpu/drm/solomon/ssd130x.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/drm/solomon/ssd130x.c +2 -8
@@ -649,17 +649,11 @@ static int ssd130x_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *new_state) {struct drm_crtc_state *new_crtc_state =drm_atomic_get_new_crtc_state (new_state, crtc); -int ret;if (!new_crtc_state->enable) - goto out; - - ret =drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); -if (ret) -return ret; +return 0 ; -out: -return drm_atomic_add_affected_planes (new_state, crtc); +return drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); }/*
Signature · 1 line
2.37.3
Javier Martinez Canillas
maintainerPATCH v2 4/4 drm/crtc-helper: Add a drm_crtc_helper_atomic_check() helper
In reply to Javier Martinez CanillasProvides a default CRTC state check handler for CRTCs that only have one primary plane attached.
There are some drivers that duplicate this logic in their helpers, such as simpledrm and ssd130x. Factor out this common code into a CRTC helper and make drivers use it.
---
Changes in v2:
- Reference drm_plane_helper_atomic_check() from drm_crtc_atomic_check() kernel doc comments and viceversa (Thomas Zimmermann).
drivers/gpu/drm/drm_crtc_helper.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/drm_plane_helper.c | 4 +++- drivers/gpu/drm/solomon/ssd130x.c | 14 ++------------ drivers/gpu/drm/tiny/simpledrm.c | 14 ++------------ include/drm/drm_crtc_helper.h | 2 ++ 5 files changed, 35 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +26 -0
@@ -421,6 +421,32 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, }EXPORT_SYMBOL (drm_crtc_helper_set_mode); +/** +* drm_crtc_helper_atomic_check() - Helper to check CRTC atomic-state +* @crtc: CRTC to check +* @state: atomic state object +* +* Provides a default CRTC-state check handler for CRTCs that only have +* one primary plane attached to it. +* +* This is often the case for the CRTC of simple framebuffers. See also +* drm_plane_helper_atomic_check() for the respective plane-state check +* helper function. +* +* RETURNS: +* Zero on success, or an errno code otherwise. +*/ +int drm_crtc_helper_atomic_check (struct drm_crtc *crtc,struct drm_atomic_state *state) +{ +struct drm_crtc_state *new_crtc_state =drm_atomic_get_new_crtc_state (state, crtc); + +if (!new_crtc_state->enable) +return 0 ; + +return drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); +} +EXPORT_SYMBOL (drm_crtc_helper_atomic_check); +static void drm_crtc_helper_disable (struct drm_crtc *crtc) {
drivers/gpu/drm/drm_plane_helper.c +3 -1
@@ -298,7 +298,9 @@ EXPORT_SYMBOL(drm_plane_helper_destroy);* scale and positioning are not expected to change since the plane is always * a fullscreen scanout buffer. * -* This is often the case for the primary plane of simple framebuffers. +* This is often the case for the primary plane of simple framebuffers. See +* also drm_crtc_helper_atomic_check() for the respective CRTC-state check +* helper function. * * RETURNS: * Zero on success, or an errno code otherwise.
drivers/gpu/drm/solomon/ssd130x.c +2 -12
@@ -20,6 +20,7 @@#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_crtc_helper.h> #include <drm/drm_damage_helper.h> #include <drm/drm_edid.h> #include <drm/drm_fb_helper.h>
@@ -645,17 +646,6 @@ static enum drm_mode_status ssd130x_crtc_helper_mode_valid(struct drm_crtc *crtcreturn MODE_OK ; } -static int ssd130x_crtc_helper_atomic_check (struct drm_crtc *crtc, -struct drm_atomic_state *new_state) -{ -struct drm_crtc_state *new_crtc_state =drm_atomic_get_new_crtc_state (new_state, crtc); - -if (!new_crtc_state->enable) -return 0 ; - -return drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); -} -/* * The CRTC is always enabled. Screen updates are performed by * the primary plane's atomic_update function. Disabling clears
@@ -663,7 +653,7 @@ static int ssd130x_crtc_helper_atomic_check(struct drm_crtc *crtc,*/ static const struct drm_crtc_helper_funcs ssd130x_crtc_helper_funcs = { .mode_valid = ssd130x_crtc_helper_mode_valid, - .atomic_check = ssd130x_crtc_helper_atomic_check, + .atomic_check = drm_crtc_helper_atomic_check, };static void ssd130x_crtc_reset (struct drm_crtc *crtc)
drivers/gpu/drm/tiny/simpledrm.c +2 -12
@@ -11,6 +11,7 @@#include <drm/drm_atomic.h> #include <drm/drm_atomic_state_helper.h> #include <drm/drm_connector.h> +#include <drm/drm_crtc_helper.h> #include <drm/drm_damage_helper.h> #include <drm/drm_device.h> #include <drm/drm_drv.h>
@@ -545,17 +546,6 @@ static enum drm_mode_status simpledrm_crtc_helper_mode_valid(struct drm_crtc *crreturn drm_crtc_helper_mode_valid_fixed (crtc, mode, &sdev->mode); } -static int simpledrm_crtc_helper_atomic_check (struct drm_crtc *crtc, -struct drm_atomic_state *new_state) -{ -struct drm_crtc_state *new_crtc_state =drm_atomic_get_new_crtc_state (new_state, crtc); - -if (!new_crtc_state->enable) -return 0 ; - -return drm_atomic_helper_check_crtc_primary_plane (new_crtc_state); -} -/* * The CRTC is always enabled. Screen updates are performed by * the primary plane's atomic_update function. Disabling clears
@@ -563,7 +553,7 @@ static int simpledrm_crtc_helper_atomic_check(struct drm_crtc *crtc,*/ static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = { .mode_valid = simpledrm_crtc_helper_mode_valid, - .atomic_check = simpledrm_crtc_helper_atomic_check, + .atomic_check = drm_crtc_helper_atomic_check, };static const struct drm_crtc_funcs simpledrm_crtc_funcs = {
include/drm/drm_crtc_helper.h +2 -0
@@ -50,6 +50,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,struct drm_display_mode *mode, int x, int y, struct drm_framebuffer *old_fb); +int drm_crtc_helper_atomic_check (struct drm_crtc *crtc, +struct drm_atomic_state *state);bool drm_helper_crtc_in_use (struct drm_crtc *crtc);bool drm_helper_encoder_in_use (struct drm_encoder *encoder);
Signature · 1 line
2.37.3
Javier Martinez Canillas
maintainerQuoted 7 lines · Javier Martinez Canillas
Add a helper function and make drivers that have the same logic in their struct
drm_crtc_helper_funcs.atomic_check handler to use this instead.Patch #1, #2 and #3 are just cleanups for the mgag200, simpledrm and ssd130x drivers respectively. Finally patch #4 converts the last two drivers to use a helper instead of open coding it the same logic.
Quoted 7 lines
The changes are inspired by a patch from Thomas Zimmermann for the ast DRM driver:
https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
This is a v2 that addresses issues pointed out also by Thomas in v1:
Pushed this to drm-misc (drm-misc-next). Thanks!
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat