From patchwork Fri Mar 10 04:32:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9614687 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 D286560415 for ; Fri, 10 Mar 2017 04:40:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C379D2864A for ; Fri, 10 Mar 2017 04:40:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8295286EF; Fri, 10 Mar 2017 04:40:28 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B8712864A for ; Fri, 10 Mar 2017 04:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HHuguALih2WhnJ9EKQ3NbikrsosMFE/sEBr6SQciOq0=; b=W1XjdOlJ9DiaOVmEZzW3lVxwWg pCQY36CytzNAhaCdKqcNBkEtLRMvuoUWyNnctAPAq1R/eBjPZIcGiesfc1biHRm0iDfIuHqadZaHY qYN5EVTuSZYgIdH7FOF8IswQlp0/F/vA1WLKq7sOjsydiqu97dPRliibKTmUE2oKkOp5B7vaEZV1n hvEQlv4yKXBeLAijjqU7pFFCqSWrTwVpE3QnnqFWdJQ38w06JX6NmAvkg4gyJQXC//GTFHu2X0Zcz zoW23EzoJuIo1BIE7tPHyuj9mrS8XYlMScEWQgf7lYYI/UrfoQV0NEibbZKqYo6PSBowA864cC7k2 W+8Ak5Fg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cmCLq-00042w-2n; Fri, 10 Mar 2017 04:40:26 +0000 Received: from mail-qk0-x230.google.com ([2607:f8b0:400d:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cmCI0-0000kJ-4f for linux-arm-kernel@lists.infradead.org; Fri, 10 Mar 2017 04:36:32 +0000 Received: by mail-qk0-x230.google.com with SMTP id v125so148896718qkh.2 for ; Thu, 09 Mar 2017 20:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AGjwbn1hawi9HheT8V5I6qNWAWVF7lGiUXR/bku3fZs=; b=cEfWl2hpDYJuv6jeKRqOXLgd2LLaIrRWxeOTJdwEXGnkjuXafxipx0aKA6nLkurk7W O9VSs9th85agCOwVjDZnb8JQ5Zlo51h9E5auzrcdcsiw3AZbnm7gxfqSqTZDz/cH+fjv 1E6mNY4ufUtcVllqEs6u5SIhEmrKwXQaLFLcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AGjwbn1hawi9HheT8V5I6qNWAWVF7lGiUXR/bku3fZs=; b=blH98UhhTNw0W9W7JYWQwEUBz4A923NknWAdS9nNWK6QeupoM+iJ7daX2GNjCSyLgr 0zKplmA1joV9+owJMeOB/afvaUIreRltFvlc0sFCW1qtJScOaRbqR+RrDiu3SkB1Pq6k KgETv/4YzSgRLVsn+vRVEd7qprwwXTvsQV/RPp0HOTUhvjWUHqt8oofeCawF2gYGh0CW N9SQEYZmLJkl3e0NACAjILLyZcV+wsSKhQ/QDrmsAEO1TqsN8z/jItr2t/C5E5Bp6NlZ RD83owyqdKPSAOmGgpuK6bMlHFB4f+Ooxv9RxjAd0abEvY15+aVAB9+pwL9oEalqHXPZ 47dg== X-Gm-Message-State: AFeK/H2Mj8htU5AxlSEvSpXlXevzBZMKkdqbIFJ8X07UJHftsGEEd/m/lAy614l1rWIgR5re X-Received: by 10.55.9.214 with SMTP id 205mr18431088qkj.63.1489120566770; Thu, 09 Mar 2017 20:36:06 -0800 (PST) Received: from boxwood.roam.corp.google.com (cpe-75-189-128-87.nc.res.rr.com. [75.189.128.87]) by smtp.gmail.com with ESMTPSA id n19sm5697731qtn.35.2017.03.09.20.36.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Mar 2017 20:36:05 -0800 (PST) From: Sean Paul To: linux-rockchip@lists.infradead.org, dri-devel@lists.freedesktop.org Subject: [PATCH 11/41] drm/rockchip: add mutex vop lock Date: Thu, 9 Mar 2017 23:32:26 -0500 Message-Id: <20170310043305.17216-12-seanpaul@chromium.org> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170310043305.17216-1-seanpaul@chromium.org> References: <20170310043305.17216-1-seanpaul@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170309_203628_422910_5FD6C207 X-CRM114-Status: GOOD ( 15.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zain wang , Heiko Stuebner , David Airlie , Sean Paul , linux-arm-kernel@lists.infradead.org, Mark Yao MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: zain wang Add a lock to vop to avoid disabling the crtc while waiting for a line flag while enabling psr. If we disable in the middle of waiting for the line flag, we'll end up timing out or worse. Signed-off-by: zain wang Signed-off-by: Sean Paul --- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 1c1e8535ad28..aa5c528c59fc 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -130,6 +130,7 @@ struct vop { spinlock_t reg_lock; /* lock vop irq reg */ spinlock_t irq_lock; + struct mutex vop_lock; unsigned int irq; @@ -568,6 +569,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc) WARN_ON(vop->event); + mutex_lock(&vop->vop_lock); /* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed @@ -619,6 +621,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc) clk_disable(vop->aclk); clk_disable(vop->hclk); pm_runtime_put(vop->dev); + mutex_unlock(&vop->vop_lock); if (crtc->state->event && !crtc->state->active) { spin_lock_irq(&crtc->dev->event_lock); @@ -885,10 +888,13 @@ static void vop_crtc_enable(struct drm_crtc *crtc) uint32_t pin_pol, val; int ret; + mutex_lock(&vop->vop_lock); + WARN_ON(vop->event); ret = vop_enable(crtc); if (ret) { + mutex_unlock(&vop->vop_lock); DRM_DEV_ERROR(vop->dev, "Failed to enable vop (%d)\n", ret); return; } @@ -979,6 +985,7 @@ static void vop_crtc_enable(struct drm_crtc *crtc) clk_set_rate(vop->dclk, adjusted_mode->clock * 1000); VOP_CTRL_SET(vop, standby, 0); + mutex_unlock(&vop->vop_lock); } static bool vop_fs_irq_is_pending(struct vop *vop) @@ -1506,15 +1513,22 @@ int rockchip_drm_wait_line_flag(struct drm_crtc *crtc, unsigned int line_num, { struct vop *vop = to_vop(crtc); unsigned long jiffies_left; + int ret = 0; if (!crtc || !vop->is_enabled) return -ENODEV; - if (line_num > crtc->mode.vtotal || mstimeout <= 0) - return -EINVAL; + mutex_lock(&vop->vop_lock); + + if (line_num > crtc->mode.vtotal || mstimeout <= 0) { + ret = -EINVAL; + goto out; + } - if (vop_line_flag_irq_is_enabled(vop)) - return -EBUSY; + if (vop_line_flag_irq_is_enabled(vop)) { + ret = -EBUSY; + goto out; + } reinit_completion(&vop->line_flag_completion); vop_line_flag_irq_enable(vop, line_num); @@ -1525,10 +1539,13 @@ int rockchip_drm_wait_line_flag(struct drm_crtc *crtc, unsigned int line_num, if (jiffies_left == 0) { dev_err(vop->dev, "Timeout waiting for IRQ\n"); - return -ETIMEDOUT; + ret = -ETIMEDOUT; + goto out; } - return 0; +out: + mutex_unlock(&vop->vop_lock); + return ret; } EXPORT_SYMBOL(rockchip_drm_wait_line_flag); @@ -1584,6 +1601,7 @@ static int vop_bind(struct device *dev, struct device *master, void *data) spin_lock_init(&vop->reg_lock); spin_lock_init(&vop->irq_lock); + mutex_init(&vop->vop_lock); ret = devm_request_irq(dev, vop->irq, vop_isr, IRQF_SHARED, dev_name(dev), vop);