diff mbox

[47/58] drm/i915: extract adjusted mode computation

Message ID 1345403595-9678-48-git-send-email-daniel.vetter@ffwll.ch (mailing list archive)
State Accepted
Headers show

Commit Message

Daniel Vetter Aug. 19, 2012, 7:13 p.m. UTC
While at it, adjust a few things:
- Only assigng the new mode to crtc->mode right before calling the
  mode_set callbacks - none of the previous callbacks depend upon
  this, they all use the mode argument (as they should).
- Check encoder->new_crtc instead of the current crtc to check whether
  the encoder will be used. This prepares for moving the staged output
  committing further down in the sequence. Follow-on patches will fix
  up individual ->mode_fixup callbacks (only tv and lvds are affected
  though).

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/intel_display.c | 75 ++++++++++++++++++++++--------------
 1 file changed, 47 insertions(+), 28 deletions(-)

Comments

Jesse Barnes Sept. 5, 2012, 6 p.m. UTC | #1
On Sun, 19 Aug 2012 21:13:04 +0200
Daniel Vetter <daniel.vetter@ffwll.ch> wrote:

> While at it, adjust a few things:
> - Only assigng the new mode to crtc->mode right before calling the
>   mode_set callbacks - none of the previous callbacks depend upon
>   this, they all use the mode argument (as they should).
> - Check encoder->new_crtc instead of the current crtc to check whether
>   the encoder will be used. This prepares for moving the staged output
>   committing further down in the sequence. Follow-on patches will fix
>   up individual ->mode_fixup callbacks (only tv and lvds are affected
>   though).
> 
> Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/intel_display.c | 75 ++++++++++++++++++++++--------------
>  1 file changed, 47 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 348727d..c7bd573 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -6642,6 +6642,48 @@ static void intel_modeset_commit_output_state(struct drm_device *dev)
>  	}
>  }
>  
> +static struct drm_display_mode *
> +intel_modeset_adjusted_mode(struct drm_crtc *crtc,
> +			    struct drm_display_mode *mode)
> +{
> +	struct drm_device *dev = crtc->dev;
> +	struct drm_display_mode *adjusted_mode;
> +	struct drm_encoder_helper_funcs *encoder_funcs;
> +	struct intel_encoder *encoder;
> +
> +	adjusted_mode = drm_mode_duplicate(dev, mode);
> +	if (!adjusted_mode)
> +		return ERR_PTR(-ENOMEM);
> +
> +	/* Pass our mode to the connectors and the CRTC to give them a chance to
> +	 * adjust it according to limitations or connector properties, and also
> +	 * a chance to reject the mode entirely.
> +	 */
> +	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
> +			    base.head) {
> +
> +		if (&encoder->new_crtc->base != crtc)
> +			continue;
> +		encoder_funcs = encoder->base.helper_private;
> +		if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
> +						adjusted_mode))) {
> +			DRM_DEBUG_KMS("Encoder fixup failed\n");
> +			goto fail;
> +		}
> +	}
> +
> +	if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
> +		DRM_DEBUG_KMS("CRTC fixup failed\n");
> +		goto fail;
> +	}
> +	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
> +
> +	return adjusted_mode;
> +fail:
> +	drm_mode_destroy(dev, adjusted_mode);
> +	return ERR_PTR(-EINVAL);
> +}
> +
>  bool intel_set_mode(struct drm_crtc *crtc,
>  		    struct drm_display_mode *mode,
>  		    int x, int y, struct drm_framebuffer *fb)
> @@ -6661,44 +6703,21 @@ bool intel_set_mode(struct drm_crtc *crtc,
>  		return true;
>  	}
>  
> -	adjusted_mode = drm_mode_duplicate(dev, mode);
> -	if (!adjusted_mode)
> -		return false;
>  
>  	saved_hwmode = crtc->hwmode;
>  	saved_mode = crtc->mode;
>  
> -	/* Update crtc values up front so the driver can rely on them for mode
> -	 * setting.
> -	 */
> -	crtc->mode = *mode;
> -
> -	/* Pass our mode to the connectors and the CRTC to give them a chance to
> -	 * adjust it according to limitations or connector properties, and also
> -	 * a chance to reject the mode entirely.
> -	 */
> -	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
> -
> -		if (encoder->crtc != crtc)
> -			continue;
> -		encoder_funcs = encoder->helper_private;
> -		if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
> -						      adjusted_mode))) {
> -			DRM_DEBUG_KMS("Encoder fixup failed\n");
> -			goto done;
> -		}
> -	}
> -
> -	if (!(ret = intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
> -		DRM_DEBUG_KMS("CRTC fixup failed\n");
> -		goto done;
> +	adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
> +	if (IS_ERR(adjusted_mode)) {
> +		return false;
>  	}
> -	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
>  
>  	intel_crtc_prepare_encoders(dev);
>  
>  	dev_priv->display.crtc_disable(crtc);
>  
> +	crtc->mode = *mode;
> +
>  	/* Set up the DPLL and any encoders state that needs to adjust or depend
>  	 * on the DPLL.
>  	 */

Fancy, using ERR_PTR even. :)

Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Daniel Vetter Sept. 5, 2012, 7:30 p.m. UTC | #2
On Wed, Sep 5, 2012 at 8:00 PM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> Fancy, using ERR_PTR even. :)

Consider this a tell-tale of the shape of things to come ;-) I.e. I
plan to extend this adjusted_mode computation to a full up-front
resource allocation step to decide about pipe bpp, dithering,
bandwidth allocation, pll allocation and all these fancy things. And
Chris wanted better error codes, so I've just started somewhere - in
the middle of the callchain, so doesn't really do anything yet, but
...
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 348727d..c7bd573 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -6642,6 +6642,48 @@  static void intel_modeset_commit_output_state(struct drm_device *dev)
 	}
 }
 
+static struct drm_display_mode *
+intel_modeset_adjusted_mode(struct drm_crtc *crtc,
+			    struct drm_display_mode *mode)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_display_mode *adjusted_mode;
+	struct drm_encoder_helper_funcs *encoder_funcs;
+	struct intel_encoder *encoder;
+
+	adjusted_mode = drm_mode_duplicate(dev, mode);
+	if (!adjusted_mode)
+		return ERR_PTR(-ENOMEM);
+
+	/* Pass our mode to the connectors and the CRTC to give them a chance to
+	 * adjust it according to limitations or connector properties, and also
+	 * a chance to reject the mode entirely.
+	 */
+	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
+			    base.head) {
+
+		if (&encoder->new_crtc->base != crtc)
+			continue;
+		encoder_funcs = encoder->base.helper_private;
+		if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
+						adjusted_mode))) {
+			DRM_DEBUG_KMS("Encoder fixup failed\n");
+			goto fail;
+		}
+	}
+
+	if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
+		DRM_DEBUG_KMS("CRTC fixup failed\n");
+		goto fail;
+	}
+	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
+
+	return adjusted_mode;
+fail:
+	drm_mode_destroy(dev, adjusted_mode);
+	return ERR_PTR(-EINVAL);
+}
+
 bool intel_set_mode(struct drm_crtc *crtc,
 		    struct drm_display_mode *mode,
 		    int x, int y, struct drm_framebuffer *fb)
@@ -6661,44 +6703,21 @@  bool intel_set_mode(struct drm_crtc *crtc,
 		return true;
 	}
 
-	adjusted_mode = drm_mode_duplicate(dev, mode);
-	if (!adjusted_mode)
-		return false;
 
 	saved_hwmode = crtc->hwmode;
 	saved_mode = crtc->mode;
 
-	/* Update crtc values up front so the driver can rely on them for mode
-	 * setting.
-	 */
-	crtc->mode = *mode;
-
-	/* Pass our mode to the connectors and the CRTC to give them a chance to
-	 * adjust it according to limitations or connector properties, and also
-	 * a chance to reject the mode entirely.
-	 */
-	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
-
-		if (encoder->crtc != crtc)
-			continue;
-		encoder_funcs = encoder->helper_private;
-		if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
-						      adjusted_mode))) {
-			DRM_DEBUG_KMS("Encoder fixup failed\n");
-			goto done;
-		}
-	}
-
-	if (!(ret = intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
-		DRM_DEBUG_KMS("CRTC fixup failed\n");
-		goto done;
+	adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
+	if (IS_ERR(adjusted_mode)) {
+		return false;
 	}
-	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
 
 	intel_crtc_prepare_encoders(dev);
 
 	dev_priv->display.crtc_disable(crtc);
 
+	crtc->mode = *mode;
+
 	/* Set up the DPLL and any encoders state that needs to adjust or depend
 	 * on the DPLL.
 	 */