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: 9614749 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 8BAF160415 for ; Fri, 10 Mar 2017 04:47:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DEB7286B9 for ; Fri, 10 Mar 2017 04:47:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72CDA286EF; Fri, 10 Mar 2017 04:47:30 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 25CB9286B9 for ; Fri, 10 Mar 2017 04:47:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DE846ED90; Fri, 10 Mar 2017 04:47:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x22b.google.com (mail-qk0-x22b.google.com [IPv6:2607:f8b0:400d:c09::22b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F71E6ED8C for ; Fri, 10 Mar 2017 04:46:34 +0000 (UTC) Received: by mail-qk0-x22b.google.com with SMTP id y76so152356984qkb.0 for ; Thu, 09 Mar 2017 20:46:34 -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=A9HkZoyw079W3qWKm3d0HtR3RVkT+oxOXyABYWDRP+ZR098/Hug5ff/jG0SWqKqC+K lAuTYEs/AxDVJT/CmVdTRoL8ahM19ivhjWTqtSvZQq1E4qy4qvFPqPyW98TAXl14fiPq o4tg0TN4bRVV/XDjmI6hS8CWPXExm3zLlvjaH92nE/5aMKnmlLcV7sptkRpdvHJ2Gm+o Do8M6bd87vAQkoB0HXNwUZCkAT4d6rdAn+x6KZiX8QediC3LRO/n3+NzO4VBn3BFClo2 AyfWX7c0vSGa7Hk5lbAWTvK/X+Rc9YsxohNR18civ7ho2tgJQI+k/46FAIqhX32HbcB+ POmg== X-Gm-Message-State: AFeK/H2XvP97Il1g3cylkjwoJOWN/qsPr2kai7ruubUHUTDF90yvnvhuVyKO6RUhRYO3NBsl 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> Cc: zain wang , linux-arm-kernel@lists.infradead.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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-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);