From: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx> We've replicated the fb pin/unpin code in a few places. Pull it into convenint helpers. This results in a slight change in behaviour on account of the cursor path now dropping struct_mutex and reacquiring it later. Signed-off-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx> --- drivers/gpu/drm/i915/intel_display.c | 105 +++++++++++++++++------------------ 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 25050bfce5d1..8e1e1dd7f4af 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -12705,6 +12705,51 @@ static void add_rps_boost_after_vblank(struct drm_crtc *crtc, add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); } +static int intel_plane_pin_fb(struct intel_plane_state *plane_state) +{ + struct intel_plane *plane = to_intel_plane(plane_state->base.plane); + struct drm_i915_private *dev_priv = to_i915(plane->base.dev); + const struct drm_framebuffer *fb = plane_state->base.fb; + struct i915_vma *vma; + bool needs_fence; + + if (plane->id == PLANE_CURSOR && + INTEL_INFO(dev_priv)->cursor_needs_physical) { + struct drm_i915_gem_object *obj = intel_fb_obj(fb); + int align = intel_cursor_alignment(dev_priv); + + return i915_gem_object_attach_phys(obj, align); + } + + needs_fence = intel_plane_needs_fence(plane_state); + vma = intel_pin_and_fence_fb_obj(fb, plane_state->base.rotation, + needs_fence); + if (IS_ERR(vma)) + return PTR_ERR(vma); + + plane_state->vma = vma; + + return 0; +} + +static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) +{ + struct intel_plane *plane = to_intel_plane(old_plane_state->base.plane); + struct drm_i915_private *dev_priv = to_i915(plane->base.dev); + struct i915_vma *vma; + bool needs_fence; + + vma = fetch_and_zero(&old_plane_state->vma); + if (!vma) + return; + + needs_fence = intel_plane_needs_fence(old_plane_state); + + mutex_lock(&dev_priv->drm.struct_mutex); + intel_unpin_fb_vma(vma, needs_fence); + mutex_unlock(&dev_priv->drm.struct_mutex); +} + /** * intel_prepare_plane_fb - Prepare fb for usage on plane * @plane: drm plane to prepare for @@ -12779,23 +12824,7 @@ intel_prepare_plane_fb(struct drm_plane *plane, return ret; } - if (plane->type == DRM_PLANE_TYPE_CURSOR && - INTEL_INFO(dev_priv)->cursor_needs_physical) { - const int align = intel_cursor_alignment(dev_priv); - - ret = i915_gem_object_attach_phys(obj, align); - } else { - bool needs_fence = - intel_plane_needs_fence(to_intel_plane_state(new_state)); - struct i915_vma *vma; - - vma = intel_pin_and_fence_fb_obj(fb, new_state->rotation, - needs_fence); - if (!IS_ERR(vma)) - to_intel_plane_state(new_state)->vma = vma; - else - ret = PTR_ERR(vma); - } + ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY); @@ -12839,18 +12868,8 @@ void intel_cleanup_plane_fb(struct drm_plane *plane, struct drm_plane_state *old_state) { - struct i915_vma *vma; - /* Should only be called after a successful intel_prepare_plane_fb()! */ - vma = fetch_and_zero(&to_intel_plane_state(old_state)->vma); - if (vma) { - bool needs_fence = - intel_plane_needs_fence(to_intel_plane_state(old_state)); - - mutex_lock(&plane->dev->struct_mutex); - intel_unpin_fb_vma(vma, needs_fence); - mutex_unlock(&plane->dev->struct_mutex); - } + intel_plane_unpin_fb(to_intel_plane_state(old_state)); } int @@ -13122,7 +13141,6 @@ intel_legacy_cursor_update(struct drm_plane *plane, struct intel_plane *intel_plane = to_intel_plane(plane); struct drm_framebuffer *old_fb; struct drm_crtc_state *crtc_state = crtc->state; - struct i915_vma *old_vma, *vma; /* * When crtc is inactive or there is a modeset pending, @@ -13181,26 +13199,11 @@ intel_legacy_cursor_update(struct drm_plane *plane, if (ret) goto out_free; - if (INTEL_INFO(dev_priv)->cursor_needs_physical) { - int align = intel_cursor_alignment(dev_priv); - - ret = i915_gem_object_attach_phys(intel_fb_obj(fb), align); - if (ret) { - DRM_DEBUG_KMS("failed to attach phys object\n"); - goto out_unlock; - } - } else { - vma = intel_pin_and_fence_fb_obj(fb, new_plane_state->rotation, - false); - if (IS_ERR(vma)) { - DRM_DEBUG_KMS("failed to pin object\n"); - - ret = PTR_ERR(vma); - goto out_unlock; - } + ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); - to_intel_plane_state(new_plane_state)->vma = vma; - } + mutex_unlock(&dev_priv->drm.struct_mutex); + if (ret) + goto out_free; old_fb = old_plane_state->fb; @@ -13220,12 +13223,8 @@ intel_legacy_cursor_update(struct drm_plane *plane, intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc)); } - old_vma = fetch_and_zero(&to_intel_plane_state(old_plane_state)->vma); - if (old_vma) - intel_unpin_fb_vma(old_vma, false); + intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); -out_unlock: - mutex_unlock(&dev_priv->drm.struct_mutex); out_free: if (ret) intel_plane_destroy_state(plane, new_plane_state); -- 2.13.6 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx