From patchwork Thu Nov 16 19:14:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 10061983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A96786023A for ; Thu, 16 Nov 2017 19:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99E092ABCB for ; Thu, 16 Nov 2017 19:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E1692A9A5; Thu, 16 Nov 2017 19:15:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 30E182901E for ; Thu, 16 Nov 2017 19:15:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 729B86E939; Thu, 16 Nov 2017 19:15:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4D8BE6E939 for ; Thu, 16 Nov 2017 19:15:06 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 11:15:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,405,1505804400"; d="scan'208";a="2635598" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by FMSMGA003.fm.intel.com with SMTP; 16 Nov 2017 11:15:04 -0800 Received: by stinkbox (sSMTP sendmail emulation); Thu, 16 Nov 2017 21:15:03 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Date: Thu, 16 Nov 2017 21:14:51 +0200 Message-Id: <20171116191451.28823-5-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171116191451.28823-1-ville.syrjala@linux.intel.com> References: <20171116191451.28823-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 5/5] drm/i915: Extract intel_plane_{pin, unpin}_fb() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä 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ä --- 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);