From: Daniel Vetter <daniel@ffwll.ch>
To: Maxime Ripard <maxime@cerno.tech>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>,
David Airlie <airlied@linux.ie>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
dri-devel@lists.freedesktop.org, Eric Anholt <eric@anholt.net>,
bcm-kernel-feedback-list@broadcom.com,
linux-rpi-kernel@lists.infradead.org,
Thomas Zimmermann <tzimmermann@suse.de>,
Daniel Vetter <daniel.vetter@intel.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 6/6] drm/vc4: kms: Add functions to create the state objects
Date: Fri, 30 Oct 2020 09:59:31 +0100 [thread overview]
Message-ID: <20201030085931.GF401619@phenom.ffwll.local> (raw)
In-Reply-To: <20201029190104.2181730-6-maxime@cerno.tech>
On Thu, Oct 29, 2020 at 08:01:04PM +0100, Maxime Ripard wrote:
> In order to make the vc4_kms_load code and error path a bit easier to
> read and extend, add functions to create state objects, and use managed
> actions to cleanup if needed.
>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Nice. With an s/drmm_add_action/drmm_add_action_or_reset/ over the entire
series:
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
btw there's a series pending from imx people (Philip Zabel iirc) to add
drmm support for modeset objects. I think that would really help clean up
vc4. Or well make it slightly less buggy, since atm you're using
devm_kzalloc, which strictly speaking, frees the memory too early.
Anyway this here looks all nice.
-Daniel
> ---
> drivers/gpu/drm/vc4/vc4_drv.c | 3 --
> drivers/gpu/drm/vc4/vc4_kms.c | 78 +++++++++++++++++++++++++----------
> 2 files changed, 57 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
> index 6e037fbaa090..08c1cc225045 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.c
> +++ b/drivers/gpu/drm/vc4/vc4_drv.c
> @@ -312,9 +312,6 @@ static void vc4_drm_unbind(struct device *dev)
> drm_dev_unregister(drm);
>
> drm_atomic_helper_shutdown(drm);
> -
> - drm_atomic_private_obj_fini(&vc4->load_tracker);
> - drm_atomic_private_obj_fini(&vc4->ctm_manager);
> }
>
> static const struct component_master_ops vc4_drm_ops = {
> diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c
> index 708099a24406..fbfb0698073e 100644
> --- a/drivers/gpu/drm/vc4/vc4_kms.c
> +++ b/drivers/gpu/drm/vc4/vc4_kms.c
> @@ -93,6 +93,29 @@ static const struct drm_private_state_funcs vc4_ctm_state_funcs = {
> .atomic_destroy_state = vc4_ctm_destroy_state,
> };
>
> +static void vc4_ctm_obj_fini(struct drm_device *dev, void *unused)
> +{
> + struct vc4_dev *vc4 = to_vc4_dev(dev);
> +
> + drm_atomic_private_obj_fini(&vc4->ctm_manager);
> +}
> +
> +static int vc4_ctm_obj_init(struct vc4_dev *vc4)
> +{
> + struct vc4_ctm_state *ctm_state;
> +
> + drm_modeset_lock_init(&vc4->ctm_state_lock);
> +
> + ctm_state = kzalloc(sizeof(*ctm_state), GFP_KERNEL);
> + if (!ctm_state)
> + return -ENOMEM;
> +
> + drm_atomic_private_obj_init(vc4->dev, &vc4->ctm_manager, &ctm_state->base,
> + &vc4_ctm_state_funcs);
> +
> + return drmm_add_action(&vc4->base, vc4_ctm_obj_fini, NULL);
> +}
> +
> /* Converts a DRM S31.32 value to the HW S0.9 format. */
> static u16 vc4_ctm_s31_32_to_s0_9(u64 in)
> {
> @@ -609,6 +632,34 @@ static const struct drm_private_state_funcs vc4_load_tracker_state_funcs = {
> .atomic_destroy_state = vc4_load_tracker_destroy_state,
> };
>
> +static void vc4_load_tracker_obj_fini(struct drm_device *dev, void *unused)
> +{
> + struct vc4_dev *vc4 = to_vc4_dev(dev);
> +
> + if (!vc4->load_tracker_available)
> + return 0;
> +
> + drm_atomic_private_obj_fini(&vc4->load_tracker);
> +}
> +
> +static int vc4_load_tracker_obj_init(struct vc4_dev *vc4)
> +{
> + struct vc4_load_tracker_state *load_state;
> +
> + if (!vc4->load_tracker_available)
> + return 0;
> +
> + load_state = kzalloc(sizeof(*load_state), GFP_KERNEL);
> + if (!load_state)
> + return -ENOMEM;
> +
> + drm_atomic_private_obj_init(vc4->dev, &vc4->load_tracker,
> + &load_state->base,
> + &vc4_load_tracker_state_funcs);
> +
> + return drmm_add_action(&vc4->base, vc4_load_tracker_obj_fini, NULL);
> +}
> +
> #define NUM_OUTPUTS 6
> #define NUM_CHANNELS 3
>
> @@ -711,8 +762,6 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = {
> int vc4_kms_load(struct drm_device *dev)
> {
> struct vc4_dev *vc4 = to_vc4_dev(dev);
> - struct vc4_ctm_state *ctm_state;
> - struct vc4_load_tracker_state *load_state;
> bool is_vc5 = of_device_is_compatible(dev->dev->of_node,
> "brcm,bcm2711-vc5");
> int ret;
> @@ -751,26 +800,13 @@ int vc4_kms_load(struct drm_device *dev)
> dev->mode_config.async_page_flip = true;
> dev->mode_config.allow_fb_modifiers = true;
>
> - drm_modeset_lock_init(&vc4->ctm_state_lock);
> + ret = vc4_ctm_obj_init(vc4);
> + if (ret)
> + return ret;
>
> - ctm_state = kzalloc(sizeof(*ctm_state), GFP_KERNEL);
> - if (!ctm_state)
> - return -ENOMEM;
> -
> - drm_atomic_private_obj_init(dev, &vc4->ctm_manager, &ctm_state->base,
> - &vc4_ctm_state_funcs);
> -
> - if (vc4->load_tracker_available) {
> - load_state = kzalloc(sizeof(*load_state), GFP_KERNEL);
> - if (!load_state) {
> - drm_atomic_private_obj_fini(&vc4->ctm_manager);
> - return -ENOMEM;
> - }
> -
> - drm_atomic_private_obj_init(dev, &vc4->load_tracker,
> - &load_state->base,
> - &vc4_load_tracker_state_funcs);
> - }
> + ret = vc4_load_tracker_obj_init(vc4);
> + if (ret)
> + return ret;
>
> drm_mode_config_reset(dev);
>
> --
> 2.26.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-10-30 9:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 19:00 [PATCH 1/6] drm/vc4: bo: Add a managed action to cleanup the cache Maxime Ripard
2020-10-29 19:01 ` [PATCH 2/6] drm/vc4: drv: Use managed drm_mode_config_init Maxime Ripard
2020-10-29 19:01 ` [PATCH 3/6] drm/vc4: gem: Add a managed action to cleanup the job queue Maxime Ripard
2020-10-29 19:01 ` [PATCH 4/6] drm/vc4: Use the helper to retrieve vc4_dev when needed Maxime Ripard
2020-10-29 19:01 ` [PATCH 5/6] drm/vc4: Use devm_drm_dev_alloc Maxime Ripard
2020-10-29 19:01 ` [PATCH 6/6] drm/vc4: kms: Add functions to create the state objects Maxime Ripard
2020-10-30 8:59 ` Daniel Vetter [this message]
2020-11-02 11:17 ` Maxime Ripard
2020-10-30 8:56 ` [PATCH 1/6] drm/vc4: bo: Add a managed action to cleanup the cache Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201030085931.GF401619@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=airlied@linux.ie \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=daniel.vetter@intel.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric@anholt.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=maxime@cerno.tech \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox