[RFC 3/3] drm/i915: Merge of visible and !visible paths for primary planes

Ville Syrjälä ville.syrjala at linux.intel.com
Tue Sep 9 10:26:09 PDT 2014


On Tue, Sep 09, 2014 at 11:43:21AM -0300, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan at collabora.co.uk>
> 
> Fold intel_pipe_set_base() in the update primary plane path merging
> pieces of code that are common to both paths.
> 
> Basically the the pin/unpin procedures are the same for both paths
> and some checks can also be shared (some of the were moved to the
> check() stage)
> 
> Signed-off-by: Gustavo Padovan <gustavo.padovan at collabora.co.uk>
> ---
>  drivers/gpu/drm/i915/intel_display.c | 100 ++++++++++++++++++++++++-----------
>  1 file changed, 69 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index e7e7184..175a284 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -11821,16 +11821,36 @@ intel_check_primary_plane(struct drm_plane *plane,
>  			  struct intel_plane_state *state)
>  {
>  	struct drm_crtc *crtc = state->crtc;
> +	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
> +	struct drm_device *dev = crtc->dev;
>  	struct drm_framebuffer *fb = state->fb;
>  	struct drm_rect *dest = &state->dst;
>  	struct drm_rect *src = &state->src;
>  	const struct drm_rect *clip = &state->clip;
> +	int ret;
>  
> -	return drm_plane_helper_check_update(plane, crtc, fb,
> +	ret = drm_plane_helper_check_update(plane, crtc, fb,
>  					    src, dest, clip,
>  					    DRM_PLANE_HELPER_NO_SCALING,
>  					    DRM_PLANE_HELPER_NO_SCALING,
>  					    false, true, &state->visible);
> +	if (ret)
> +		return ret;
> +
> +	if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
> +		DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
> +			  plane_name(intel_crtc->plane),
> +			  INTEL_INFO(dev)->num_pipes);
> +		return -EINVAL;
> +	}

I think we can just kill this plane check. It serves no purpose IMO.

> +
> +	/* no fb bound */
> +	if (state->visible && !fb) {
> +		DRM_ERROR("No FB bound\n");
> +		return -EINVAL;
> +	}

Hmm. This one may be needed still in cases where the BIOS fb takeover
fails. Otherwise it shouldn't happen.

> +
> +	return 0;
>  }
>  
>  static int
> @@ -11842,14 +11862,34 @@ intel_commit_primary_plane(struct drm_plane *plane,
>  	struct drm_device *dev = crtc->dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
> +	enum pipe pipe = intel_crtc->pipe;
> +	struct drm_framebuffer *old_fb = plane->fb;
>  	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
>  	struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
>  	struct intel_plane *intel_plane = to_intel_plane(plane);
>  	struct drm_rect *src = &state->src;
> -	int ret;
> +	int ret = 0;
>  
>  	intel_crtc_wait_for_pending_flips(crtc);
>  
> +	if (intel_crtc_has_pending_flip(crtc)) {
> +		DRM_ERROR("pipe is still busy with an old pageflip\n");
> +		return -EBUSY;
> +	}

Yeah I guess we can keep this sanity check here.

> +
> +	mutex_lock(&dev->struct_mutex);
> +	if (plane->fb != fb) {
> +		ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
> +		if (ret == 0)
> +			i915_gem_track_fb(old_obj, obj,
> +					  INTEL_FRONTBUFFER_PRIMARY(pipe));
> +	}
> +	mutex_unlock(&dev->struct_mutex);

Could move the locking within the 'if (plane->fb != fb)' block since the
lock just protects the lower level stuff and not the plane->fb pointer.

Hmm. I started to wonder if we can do the pin/unpin conditionally, but
it must be fine, otherwise we already have some kind of problem with 
the pin count going astray.

I guess we could apply this small optimization to the sprite code as
well. There we currently do the pin/unpin unconditionally.

> +	if (ret != 0) {
> +		DRM_ERROR("pin & fence failed\n");
> +		return ret;
> +	}

Hmm. I wonder if this error is user triggerable on some platforms.
Should probably kill it or make it DRM_DEBUG_KMS or something. 

> +
>  	/*
>  	 * If clipping results in a non-visible primary plane, we'll disable
>  	 * the primary plane.  Note that this is a bit different than what
> @@ -11857,33 +11897,9 @@ intel_commit_primary_plane(struct drm_plane *plane,
>  	 * because plane->fb still gets set and pinned.
>  	 */
>  	if (!state->visible) {
> -		mutex_lock(&dev->struct_mutex);
> -
> -		/*
> -		 * Try to pin the new fb first so that we can bail out if we
> -		 * fail.
> -		 */
> -		if (plane->fb != fb) {
> -			ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
> -			if (ret) {
> -				mutex_unlock(&dev->struct_mutex);
> -				return ret;
> -			}
> -		}
> -
> -		i915_gem_track_fb(old_obj, obj,
> -				  INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
> -
>  		if (intel_crtc->primary_enabled)
>  			intel_disable_primary_hw_plane(plane, crtc);
>  
> -
> -		if (plane->fb != fb)
> -			if (plane->fb)
> -				intel_unpin_fb_obj(old_obj);
> -
> -		mutex_unlock(&dev->struct_mutex);
> -
>  	} else {
>  		if (intel_crtc && intel_crtc->active &&
>  		    intel_crtc->primary_enabled) {
> @@ -11903,12 +11919,34 @@ intel_commit_primary_plane(struct drm_plane *plane,
>  				intel_disable_fbc(dev);
>  			}
>  		}
> -		ret = intel_pipe_set_base(crtc, src->x1, src->y1, fb);
> -		if (ret)
> -			return ret;
>  
> -		if (!intel_crtc->primary_enabled)
> -			intel_enable_primary_hw_plane(plane, crtc);
> +		intel_update_pipe_size(crtc);

I was going to say we probably don't want to call this here, but we do
in fact call it already so this doesn't change the behaviour. Which is
good since I don't want to think about this fastboot hack at all ;)

Maybe slap a comment on top of it. Eg.:
/* FIXME kill this fastboot hack */

> +
> +		intel_crtc->primary_enabled = true;
> +
> +		dev_priv->display.update_primary_plane(crtc, fb, src->x1, src->y1);
> +
> +		mutex_lock(&dev->struct_mutex);
> +		intel_update_fbc(dev);
> +		mutex_unlock(&dev->struct_mutex);

intel_update_fbc() must be called only after primary->fb has been
updated. Just after the intel_frontbuffer_flip() call is probably
the best place for it.

Otherwise this patch is looking good I think.

> +	}
> +
> +	crtc->primary->fb = fb;
> +	crtc->x = src->x1;
> +	crtc->y = src->y1;
> +
> +	if (intel_crtc->active)
> +		intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
> +
> +	if (old_fb) {
> +		if (intel_crtc->active && old_fb != fb)
> +			intel_wait_for_vblank(dev, intel_crtc->pipe);
> +
> +		if (old_fb != fb) {
> +			mutex_lock(&dev->struct_mutex);
> +			intel_unpin_fb_obj(old_obj);
> +			mutex_unlock(&dev->struct_mutex);
> +		}
>  	}
>  	intel_plane->crtc_x = state->orig_dst.x1;
> -- 
> 1.9.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel OTC


More information about the dri-devel mailing list