All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/3] drm: atomic-helper: Implement drm_atomic_helper_duplicate_state()
Date: Tue, 11 Aug 2015 13:51:11 +0200	[thread overview]
Message-ID: <55C9E1AF.9030801@linux.intel.com> (raw)
In-Reply-To: <1439293065-15941-1-git-send-email-thierry.reding@gmail.com>

Hey,

This patch series would be less complicated if you assume the caller locked with drm_modeset_lock_all
and use the global acquire_ctx in each function. You're locking all state here after all..

Also you should use drm_atomic_get_*_state instead of calling those duplicate_state functions directly.

Op 11-08-15 om 13:37 schreef Thierry Reding:
> From: Thierry Reding <treding@nvidia.com>
>
> This function can be used to duplicate an atomic state object. This is
> useful for example to implement suspend/resume, where the state before
> suspend can be saved and restored upon resume.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/gpu/drm/drm_atomic_helper.c | 90 +++++++++++++++++++++++++++++++++++++
>  include/drm/drm_atomic_helper.h     |  2 +
>  2 files changed, 92 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index fd06595c2ee5..f842499ca79e 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -2358,6 +2358,96 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
>  EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
>  
>  /**
> + * drm_atomic_helper_duplicate_state - duplicate an atomic state object
> + * @dev: DRM device
> + *
> + * Makes a copy of the current atomic state by looping over all objects and
> + * duplicating their respective states.
> + *
> + * Returns: A pointer to the copy of the atomic state object on success or an
> + * ERR_PTR()-encoded error code on failure.
> + */
> +struct drm_atomic_state *
> +drm_atomic_helper_duplicate_state(struct drm_device *dev)
> +{
> +	struct drm_modeset_acquire_ctx ctx;
> +	struct drm_atomic_state *state;
> +	struct drm_connector *conn;
> +	struct drm_plane *plane;
> +	struct drm_crtc *crtc;
> +	int err;
> +
> +	state = drm_atomic_state_alloc(dev);
> +	if (!state)
> +		return ERR_PTR(-ENOMEM);
> +
> +	drm_modeset_acquire_init(&ctx, 0);
> +	state->acquire_ctx = &ctx;
> +
> +	err = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
> +	if (err < 0)
> +		goto free;
> +
> +	drm_for_each_crtc(crtc, dev) {
> +		unsigned int index = drm_crtc_index(crtc);
> +		struct drm_crtc_state *crtc_state;
> +
> +		crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
> +		if (!crtc_state) {
> +			err = -ENOMEM;
> +			goto unlock;
> +		}
> +
> +		state->crtc_states[index] = crtc_state;
> +		state->crtcs[index] = crtc;
> +		crtc_state->state = state;
> +	}
> +
> +	drm_for_each_plane(plane, dev) {
> +		unsigned int index = drm_plane_index(plane);
> +		struct drm_plane_state *plane_state;
> +
> +		plane_state = plane->funcs->atomic_duplicate_state(plane);
> +		if (!plane_state) {
> +			err = -ENOMEM;
> +			goto unlock;
> +		}
> +
> +		state->plane_states[index] = plane_state;
> +		state->planes[index] = plane;
> +		plane_state->state = state;
> +	}
> +
> +	drm_for_each_connector(conn, dev) {
> +		unsigned int index = drm_connector_index(conn);
> +		struct drm_connector_state *conn_state;
> +
> +		conn_state = conn->funcs->atomic_duplicate_state(conn);
> +		if (!conn_state) {
> +			err = -ENOMEM;
> +			goto unlock;
> +		}
> +
> +		state->connector_states[index] = conn_state;
> +		state->connectors[index] = conn;
> +		conn_state->state = state;
> +	}
> +
> +unlock:
> +	drm_modeset_drop_locks(&ctx);
> +free:
> +	drm_modeset_acquire_fini(&ctx);
> +
> +	if (err < 0) {
> +		drm_atomic_state_free(state);
> +		state = ERR_PTR(err);
> +	}
> +
> +	return state;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
> +
> +/**
>   * __drm_atomic_helper_connector_destroy_state - release connector state
>   * @connector: connector object
>   * @state: connector state object to release
> diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
> index 4ffe9dca07c4..5d27612997ce 100644
> --- a/include/drm/drm_atomic_helper.h
> +++ b/include/drm/drm_atomic_helper.h
> @@ -118,6 +118,8 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
>  					   struct drm_connector_state *state);
>  struct drm_connector_state *
>  drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
> +struct drm_atomic_state *
> +drm_atomic_helper_duplicate_state(struct drm_device *dev);
>  void
>  __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
>  					    struct drm_connector_state *state);

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-08-11 11:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11 11:37 [PATCH 1/3] drm: atomic-helper: Implement drm_atomic_helper_duplicate_state() Thierry Reding
2015-08-11 11:37 ` [PATCH 2/3] drm/atomic-helper: Implement subsystem-level suspend/resume Thierry Reding
2015-08-11 11:55   ` Maarten Lankhorst
2015-08-11 11:59   ` Daniel Vetter
2015-08-11 11:37 ` [PATCH 3/3] drm/tegra: " Thierry Reding
2015-08-11 11:49 ` [PATCH 1/3] drm: atomic-helper: Implement drm_atomic_helper_duplicate_state() Daniel Vetter
2015-08-11 11:51 ` Maarten Lankhorst [this message]
2015-08-11 11:52 ` 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=55C9E1AF.9030801@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=thierry.reding@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.