From patchwork Wed Aug 17 01:11:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9285057 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 0606E600CB for ; Wed, 17 Aug 2016 01:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB8B6287C7 for ; Wed, 17 Aug 2016 01:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E054E287CC; Wed, 17 Aug 2016 01:11:29 +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 9BD36287C7 for ; Wed, 17 Aug 2016 01:11:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3789B6E77E; Wed, 17 Aug 2016 01:11:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-x231.google.com (mail-pa0-x231.google.com [IPv6:2607:f8b0:400e:c03::231]) by gabe.freedesktop.org (Postfix) with ESMTPS id D0FBD6E77E for ; Wed, 17 Aug 2016 01:11:27 +0000 (UTC) Received: by mail-pa0-x231.google.com with SMTP id pp5so31233030pac.3 for ; Tue, 16 Aug 2016 18:11:27 -0700 (PDT) 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=NDfwdGpDwyvljNjeL5cHERcAgTSFKWibrIg+GhFpg5o=; b=ePJgr0ArqP5ipKqkHBA1s+WNeNpmy+grhEZv0WDkriWmZaTpchFK3yWPeEBeIq/MyO PN3SPOeF5nIbmev3SOH4BOteaTXXvcy77uLjZzvl2PKN/9pzvSgjb6PSUN4aWkrLBwBN Vd2vCZn5MpouSJZBN8V86sJ8MkV7i5dwESHfM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NDfwdGpDwyvljNjeL5cHERcAgTSFKWibrIg+GhFpg5o=; b=RbFywulr6T4jsb+et95iho9QnwufDwHn0sFuQGIYHlDmBSJlG8/58e31urxbbdK2NU OofzV2gquNDVl1mHk7XGYhDAZpKp9DfVrfVLTN2h+DZ9kJ3RO17b9KHSLkDIy9I3f+pZ eGhjw9WgSMvn5c+lSF/NgTQ6nxMgSaGiPxhVYRD9kSe7tI8zc5USjDcOpDUfRfZIl5cv fimAm4ylYHs7p2+mrAmBW5r8TMTjycYNa1YfSNF6zTxakqszgdhJm4yczcl1M13pc8jR VfqJfA/TdoGjOT1zxPcUN638noDUeXZMuyYv08xLT5JDWI7YC3lgznTT0wLbg93a15Bs UigA== X-Gm-Message-State: AEkoouuDsCM+hQKjti7oE1bSiap9jA6GYlrGd5H4YwERkHmu0SYOfJ+hzQG8TTUpcRpXHWCD X-Received: by 10.66.236.201 with SMTP id uw9mr64387510pac.111.1471396287450; Tue, 16 Aug 2016 18:11:27 -0700 (PDT) Received: from seanpaul0.corp.google.com ([172.22.162.59]) by smtp.gmail.com with ESMTPSA id f6sm42170827pfa.17.2016.08.16.18.11.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 18:11:26 -0700 (PDT) From: Sean Paul To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org, ykk@rock-chips.com Subject: [PATCH v2 3/6] drm/rockchip: Use a spinlock to protect psr state Date: Tue, 16 Aug 2016 18:11:13 -0700 Message-Id: <1471396276-8222-4-git-send-email-seanpaul@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> References: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> Cc: marcheu@chromium.org, dianders@chromium.org, linux-rockchip@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 The handling of psr state is racey, shore that up with a per-psr driver lock. Signed-off-by: Sean Paul Reviewed-by: Yakir Yang --- Changes in v2: - Rebased on https://cgit.freedesktop.org/~seanpaul/dogwood/log/?h=for-next drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c index 4c645d7..5bd54f2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c @@ -30,6 +30,7 @@ struct psr_drv { struct list_head list; struct drm_encoder *encoder; + spinlock_t lock; enum psr_state state; struct timer_list flush_timer; @@ -55,7 +56,7 @@ out: return psr; } -static void psr_set_state(struct psr_drv *psr, enum psr_state state) +static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state) { /* * Allowed finite state machine: @@ -75,7 +76,6 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) if (state == PSR_FLUSH && psr->state == PSR_DISABLE) return; - /* Only wrote in this work, no need lock protection */ psr->state = state; /* Allow but no need hardware change, just need assign the state */ @@ -95,18 +95,28 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) } } +static void psr_set_state(struct psr_drv *psr, enum psr_state state) +{ + unsigned long flags; + + spin_lock_irqsave(&psr->lock, flags); + psr_set_state_locked(psr, state); + spin_unlock_irqrestore(&psr->lock, flags); +} + static void psr_flush_handler(unsigned long data) { struct psr_drv *psr = (struct psr_drv *)data; + unsigned long flags; if (!psr) return; /* State changed between flush time, then keep it */ - if (psr->state != PSR_FLUSH) - return; - - psr_set_state(psr, PSR_ENABLE); + spin_lock_irqsave(&psr->lock, flags); + if (psr->state == PSR_FLUSH) + psr_set_state_locked(psr, PSR_ENABLE); + spin_unlock_irqrestore(&psr->lock, flags); } /** @@ -167,9 +177,6 @@ void rockchip_drm_psr_flush(struct drm_device *dev) spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_for_each_entry(psr, &drm_drv->psr_list, list) { - if (psr->state == PSR_DISABLE) - continue; - mod_timer(&psr->flush_timer, round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT)); @@ -202,6 +209,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, return -ENOMEM; setup_timer(&psr->flush_timer, psr_flush_handler, (unsigned long)psr); + spin_lock_init(&psr->lock); psr->state = PSR_DISABLE; psr->encoder = encoder;