dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Daniel Stone <daniels@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH 17/37] DRM: Atomic: Use pointer for mode in CRTC state
Date: Fri, 20 Mar 2015 17:16:22 +0100	[thread overview]
Message-ID: <20150320161622.GZ1349@phenom.ffwll.local> (raw)
In-Reply-To: <1426739616-10635-17-git-send-email-daniels@collabora.com>

On Thu, Mar 19, 2015 at 04:33:16AM +0000, Daniel Stone wrote:
> Holding a pointer to the mode, rather than an embed, allows us to get
> towards sharing refcounted modes.
> 
> XXX: atomic_destroy_state does _not_ seem to be optional - so we should
>      remove any fallback paths which compensate for its lack!
>      the crtc_state->mode handling is particularly ugly here :\

duplicate/destroy callbacks are optional in the transitional helpers. And
that's fairly intentional to avoid the need for switching to the full
state scaffolding at once.

For these couldn't we instead just store a pointer to crtc->mode instead?
Lifetimes should be fully in sync.

> @@ -2058,11 +2058,22 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_dpms);
>   */
>  void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
>  {
> +	if (crtc->state)
> +		kfree(crtc->state->mode);
> +
>  	kfree(crtc->state);
>  	crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
>  
> -	if (crtc->state)
> +	if (crtc->state) {
>  		crtc->state->crtc = crtc;
> +		crtc->state->mode =
> +			kzalloc(sizeof(*crtc->state->mode), GFP_KERNEL);

Allocating an empty mode object seems superflous. Why do we need this?

> +	}
> +
> +	if (crtc->state && !crtc->state->mode) {
> +		kfree(crtc->state);
> +		crtc->state = NULL;
> +	}
>  }
>  EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
>  
> @@ -2088,6 +2099,11 @@ drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
>  		state->active_changed = false;
>  		state->planes_changed = false;
>  		state->event = NULL;
> +		state->mode = drm_mode_duplicate(crtc->dev, crtc->state->mode);
> +		if (!state->mode) {
> +			kfree(state);
> +			state = NULL;
> +		}
>  	}
>  
>  	return state;
> @@ -2105,6 +2121,7 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
>  void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
>  					  struct drm_crtc_state *state)
>  {
> +	kfree(state->mode);
>  	kfree(state);
>  }
>  EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 5785336..6023851 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -2008,7 +2008,7 @@ int drm_mode_getcrtc(struct drm_device *dev,
>  		crtc_resp->x = crtc->primary->state->src_x >> 16;
>  		crtc_resp->y = crtc->primary->state->src_y >> 16;
>  		if (crtc->state->enable) {
> -			drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
> +			drm_crtc_convert_to_umode(&crtc_resp->mode, crtc->state->mode);
>  			crtc_resp->mode_valid = 1;
>  
>  		} else {
> diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
> index c6063ff..8a9a045 100644
> --- a/drivers/gpu/drm/drm_crtc_helper.c
> +++ b/drivers/gpu/drm/drm_crtc_helper.c
> @@ -943,11 +943,32 @@ int drm_helper_crtc_mode_set(struct drm_crtc *crtc,
>  
>  	if (crtc->funcs->atomic_duplicate_state)
>  		crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
> -	else if (crtc->state)
> +	else if (crtc->state) {
>  		crtc_state = kmemdup(crtc->state, sizeof(*crtc_state),
>  				     GFP_KERNEL);
> -	else
> +		/* XXX: this is unpleasant: we should mandate dup instead */
> +		if (crtc_state) {
> +			crtc_state->mode =
> +				drm_mode_duplicate(crtc->dev,
> +				                   crtc->state->mode);
> +			if (!crtc_state->mode) {
> +				kfree(crtc_state);
> +				crtc_state = NULL;
> +			}
> +		}
> +	}
> +	else {
>  		crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
> +		if (crtc_state) {
> +			crtc_state->mode = kzalloc(sizeof(*crtc_state->mode),
> +			                           GFP_KERNEL);
> +			/* XXX: as above, but mandate a new_state */
> +			if (!crtc_state->mode) {
> +				kfree(crtc_state);
> +				crtc_state = NULL;
> +			}
> +		}
> +	}

I think for transitional helpers if we just do a crtc_state->mode =
crtc->mode that should be all that's needed.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2015-03-20 16:15 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  4:32 [RFC PATCH 00/37] Modesetting for atomic modesetting Daniel Stone
2015-03-19  4:33 ` [RFC PATCH 01/37] drm: mode: Fix typo in kerneldoc Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 02/37] drm: fb_helper: Simplify exit condition Daniel Stone
2015-03-20 15:57     ` Daniel Vetter
2015-03-19  4:33   ` [RFC PATCH 03/37] drm: mode: Allow NULL modes for equality check Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 04/37] drm: crtc_helper: Update hwmode before mode_set call Daniel Stone
2015-03-20 16:05     ` Daniel Vetter
2015-03-19  4:33   ` [RFC PATCH 05/37] drm: Exynos: Remove mode validation inside mode_fixup Daniel Stone
2015-03-20 15:59     ` Daniel Vetter
2015-03-19  4:33   ` [RFC PATCH 06/37] drm: Exynos: Use hwmode for adjusted_mode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 07/37] drm: sti: Use crtc->hwmode for adjusted mode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 08/37] drm: ast: Split register set from get_vbios_mode_info Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 09/37] drm: ast: Split mode adjustment " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 10/37] drm: armada: Use crtc->hwmode for adjusted mode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 11/37] drm: bridge: Constify mode parameters Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 12/37] drm: encoder-slave: " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 13/37] drm: connector-helper: Constify mode_valid parameter Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 14/37] drm: connector-helper: Constify mode_set parameters Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 15/37] drm: crtc-helper: " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 16/37] drm: fb_helper: Constify modeset mode member Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 17/37] DRM: Atomic: Use pointer for mode in CRTC state Daniel Stone
2015-03-20 16:16     ` Daniel Vetter [this message]
2015-03-19  4:33   ` [RFC PATCH 18/37] DRM: CRTC: Use pointer for display mode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 19/37] DRM: Constify crtc->mode pointer Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 20/37] DRM: mode: Rename and combine drm_crtc_convert_umode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 21/37] DRM: mode: Un-staticise drm_mode_new_from_umode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 22/37] DRM: mode: Un-staticise drm_crtc_convert_to_umode Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 23/37] drm: mode: Cache userspace mode representation Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 24/37] drm: mode: Use cached usermode representation Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 25/37] drm: mode: Allow userspace to fetch mode as blob Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 26/37] drm: atomic: Expose CRTC active property Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 27/37] drm: atomic: Allow setting " Daniel Stone
2015-03-20 16:21     ` Daniel Vetter
2015-03-19  4:33   ` [RFC PATCH 28/37] drm: mode: Add kref to modes Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 29/37] drm: mode: Add drm_mode_reference Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 30/37] drm: fb_helper: Reference, not duplicate, modes Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 31/37] drm: crtc_helper: " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 32/37] drm: atomic_helper: " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 33/37] drm: i915/tegra: atomic: " Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 34/37] drm: atomic: Add MODE_ID property Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 35/37] drm: property: Allow non-global blob properties Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 36/37] drm: mode: Add user object-creation ioctl Daniel Stone
2015-03-19  4:33   ` [RFC PATCH 37/37] Tegra: SOR: Don't always assume a valid mode Daniel Stone
2015-03-23  8:20 ` [RFC PATCH 00/37] Modesetting for atomic modesetting Daniel Vetter
2015-03-23 16:58   ` Daniel Stone
2015-03-24  8:55     ` Daniel Vetter
2015-03-24 22:49       ` Daniel Stone
2015-03-25  8:37         ` 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=20150320161622.GZ1349@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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