From patchwork Thu Aug 28 17:40:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 4806011 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2C4BC9F2A9 for ; Thu, 28 Aug 2014 17:40:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17050200DF for ; Thu, 28 Aug 2014 17:40:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1E9A42013A for ; Thu, 28 Aug 2014 17:40:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E27E96E645; Thu, 28 Aug 2014 10:40:37 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) by gabe.freedesktop.org (Postfix) with ESMTP id BBE486E099; Thu, 28 Aug 2014 10:40:29 -0700 (PDT) Received: by mail-yk0-f170.google.com with SMTP id 142so695444ykq.29 for ; Thu, 28 Aug 2014 10:40:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l+ITMeteTOGGAWKXI8pgdpiOI8nYO/SifJu6XsZMldM=; b=mlj3mMYpNFP46bzQItElacmu8L2FDBbJhZFS3uugaGqEVvCHQHK4I8HCQnV0gpAvnL mMexBRdvDej446ElaXFFn8IyKtccW/OvEb1Cf6Lb0xMy8xWlgVbowIXaKuY272QiqjQF 4+OFiOZ6blotXlfbCnnKgCcGy7hlqjAo4Qjr3U3TNpq9wtllx/U5AuWalhur6xWiP9rp ZR9b5eXrU2NwLJDf3LXjJVAjPvBiJJWg9m3plKaU+4RBAbqnyML4Qcfea7KQTjAlVw02 1DIJK3UUvRD9DbG7LxQ49bODioAlMiX4/AOIzAZiXdqjRTlvy6hy/7SvSM7FYzdtGkht 2XPA== X-Received: by 10.236.19.196 with SMTP id n44mr6711521yhn.83.1409247629177; Thu, 28 Aug 2014 10:40:29 -0700 (PDT) Received: from localhost.localdomain ([187.10.18.246]) by mx.google.com with ESMTPSA id a14sm2020073yho.33.2014.08.28.10.40.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Aug 2014 10:40:28 -0700 (PDT) From: Gustavo Padovan To: intel-gfx@lists.freedesktop.org Subject: [PATCH 6/9] drm/i915: split intel_crtc_cursor_set_obj() into check() and commit() Date: Thu, 28 Aug 2014 14:40:10 -0300 Message-Id: <1409247613-14232-6-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409247613-14232-1-git-send-email-gustavo@padovan.org> References: <1409247613-14232-1-git-send-email-gustavo@padovan.org> Cc: Gustavo Padovan , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan Create intel_crtc_cursor_create_obj() to check any need setting before we call intel_crtc_cursor_set_obj() to apply the cursor updates. intel_crtc_cursor_check_obj() must always be called before intel_crtc_cursor_set_obj(). Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/i915/intel_display.c | 115 ++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 0173c53..86c8fa3 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -8232,30 +8232,25 @@ static bool cursor_size_ok(struct drm_device *dev, } /* - * intel_crtc_cursor_set_obj - Set cursor to specified GEM object + * intel_crtc_cursor_check_obj - Check settings for a specified GEM object * - * Note that the object's reference will be consumed if the update fails. If - * the update succeeds, the reference of the old object (if any) will be - * consumed. + * Note that the object's reference will be consumed if the check fails. If + * the check succeeds, the reference of the old object (if any) will be + * consumed in intel_crtc_cursor_set_obj(). It must be called before + * intel_crtc_cursor_set_obj() */ -static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, +static int intel_crtc_cursor_check_obj(struct drm_crtc *crtc, struct drm_i915_gem_object *obj, uint32_t width, uint32_t height) + { struct drm_device *dev = crtc->dev; - struct intel_crtc *intel_crtc = to_intel_crtc(crtc); - enum pipe pipe = intel_crtc->pipe; - unsigned old_width, stride; - uint32_t addr; + unsigned stride; int ret; /* if we want to turn off the cursor ignore width and height */ - if (!obj) { - DRM_DEBUG_KMS("cursor off\n"); - addr = 0; - mutex_lock(&dev->struct_mutex); - goto finish; - } + if (!obj) + return 0; /* Check for which cursor types we support */ if (!cursor_size_ok(dev, width, height)) { @@ -8302,7 +8297,6 @@ static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, goto fail_unpin; } - addr = i915_gem_obj_ggtt_offset(obj); } else { int align = IS_I830(dev) ? 16 * 1024 : 256; ret = i915_gem_object_attach_phys(obj, align); @@ -8310,8 +8304,50 @@ static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, DRM_DEBUG_KMS("failed to attach phys object\n"); goto fail_locked; } - addr = obj->phys_handle->busaddr; } + mutex_unlock(&dev->struct_mutex); + + return 0; + +fail_unpin: + i915_gem_object_unpin_from_display_plane(obj); +fail_locked: + mutex_unlock(&dev->struct_mutex); +fail: + drm_gem_object_unreference_unlocked(&obj->base); + return ret; +} + +/* + * intel_crtc_cursor_set_obj - Set cursor to specified GEM object + * + * intel_crtc_cursor_check_obj() must be called before this function + * so check for failures can be done before apply the update. + */ +static void intel_crtc_cursor_set_obj(struct drm_crtc *crtc, + struct drm_i915_gem_object *obj, + uint32_t width, uint32_t height) +{ + struct drm_device *dev = crtc->dev; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + enum pipe pipe = intel_crtc->pipe; + unsigned old_width; + uint32_t addr; + + /* if we want to turn off the cursor ignore width and height */ + if (!obj) { + DRM_DEBUG_KMS("cursor off\n"); + addr = 0; + mutex_lock(&dev->struct_mutex); + goto finish; + } + + /* we only need to pin inside GTT if cursor is non-phy */ + mutex_lock(&dev->struct_mutex); + if (!INTEL_INFO(dev)->cursor_needs_physical) + addr = i915_gem_obj_ggtt_offset(obj); + else + addr = obj->phys_handle->busaddr; finish: if (intel_crtc->cursor_bo) { @@ -8337,15 +8373,6 @@ static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, } intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe)); - - return 0; -fail_unpin: - i915_gem_object_unpin_from_display_plane(obj); -fail_locked: - mutex_unlock(&dev->struct_mutex); -fail: - drm_gem_object_unreference_unlocked(&obj->base); - return ret; } static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, @@ -11733,12 +11760,20 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, static int intel_cursor_plane_disable(struct drm_plane *plane) { + int ret; + if (!plane->fb) return 0; BUG_ON(!plane->crtc); - return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0); + ret = intel_crtc_cursor_check_obj(plane->crtc, NULL, 0, 0); + if (ret) + return ret; + + intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0); + + return 0; } static int @@ -11749,6 +11784,7 @@ intel_check_cursor_plane(struct drm_plane *plane, struct drm_crtc *crtc, uint32_t src_h, bool *visible) { struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); struct drm_rect dest = { /* integer pixels */ .x1 = crtc_x, @@ -11768,12 +11804,21 @@ intel_check_cursor_plane(struct drm_plane *plane, struct drm_crtc *crtc, .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, }; + int ret; - return drm_plane_helper_check_update(plane, crtc, fb, - &src, &dest, &clip, - DRM_PLANE_HELPER_NO_SCALING, - DRM_PLANE_HELPER_NO_SCALING, - true, true, visible); + ret = drm_plane_helper_check_update(plane, crtc, fb, + &src, &dest, &clip, + DRM_PLANE_HELPER_NO_SCALING, + DRM_PLANE_HELPER_NO_SCALING, + true, true, visible); + if (ret) + return ret; + + if (fb != crtc->cursor->fb) + ret = intel_crtc_cursor_check_obj(crtc, intel_fb->obj, + crtc_w, crtc_h); + + return ret; } static int @@ -11789,15 +11834,15 @@ intel_commit_cursor_plane(struct drm_plane *plane, struct drm_crtc *crtc, crtc->cursor_x = crtc_x; crtc->cursor_y = crtc_y; if (fb != crtc->cursor->fb) { - return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h); + intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h); } else { intel_crtc_update_cursor(crtc, visible); intel_frontbuffer_flip(crtc->dev, INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe)); - - return 0; } + + return 0; } static int