Received: by 10.192.165.156 with SMTP id m28csp405504imm; Mon, 16 Apr 2018 02:09:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48usjjQhkNHXG8G1C80mRPd+/VV08TyeuLDNdIYJkhudGkFn+U5H21dtFTw+ajCVVzERdSd X-Received: by 10.101.65.130 with SMTP id a2mr4979460pgq.72.1523869785613; Mon, 16 Apr 2018 02:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523869785; cv=none; d=google.com; s=arc-20160816; b=zvqwOt7ojE82/5a6KwoZ5TsTeg7iFnxGd0raesnKqoj1lwGrc7eL6CDCJjPz0gb5SN e5s8YbyOQvm8xPOoBXuz2sFdncy+M6OVvAbbdlRsF6xfDPkOVVStpqm0mu8rQZGSHzmz rgLVLAVdVGZ/UPrUxGdO+Jb2oyJbMlRU0bxVnzFBTKbnPbpKXl2s/Tc+s8d+K9kVnIwH KL9zGhKrO8iYykFRtNWrA5W2K1CrC2+yb5V+37n4VKwR4j9Pxjtjn5hAuW+HT0qRD7VJ yfvLNShxAtGygMn7Wdvk4NVCZVl5ALMask1pVSAGqvY21n8v9DccZzXI/zY8EVIigg60 C1mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:subject:dkim-signature:dkim-filter :arc-authentication-results; bh=8hU08RMQR0glkrqhWuDJKvecAU8V3ooEhlbzS1sF5Jw=; b=djPtI+uSK7L45zZYZNcCwikga3traCazckW3lCP9BNRUNYW9dOM0z6hrMk1X2yUOfE SQ6kufVub5J4bOG1EnRHo1EVM9Inmkizf8ajmFHfT3EX81K28tjoH8N78AAnpUGRaus8 zFHkCOcfLNrZs9aCRfBTNBCi3/rKPpK9dUHods9EM1pmn13h0LaPo3ZeKsjbfk8iCnRK x9Wg+gvvKapM6PX/AGNLcUEJFqi6Y+hXy6loIWloga+xPE3e1f6yRJuFpppjUfePxuEp JOcai1BCOkeqVIK3go26He203ip+sBVYROEGydPkzdour+1uLF5x5TymmJvOqV6ysaW9 obMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JSVHWsdd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si9823888pfi.310.2018.04.16.02.09.31; Mon, 16 Apr 2018 02:09:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JSVHWsdd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754454AbeDPJG6 (ORCPT + 99 others); Mon, 16 Apr 2018 05:06:58 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:33471 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754116AbeDPJG4 (ORCPT ); Mon, 16 Apr 2018 05:06:56 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180416090653euoutp0150a2e4c7bda971a330d993be44dffa64~l31cC2x4k0138701387euoutp01v; Mon, 16 Apr 2018 09:06:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180416090653euoutp0150a2e4c7bda971a330d993be44dffa64~l31cC2x4k0138701387euoutp01v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523869613; bh=8hU08RMQR0glkrqhWuDJKvecAU8V3ooEhlbzS1sF5Jw=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=JSVHWsdd2RRAy/g5lgu/mmC/l2PT9U/QyKGn+Y5ek61OtUYcsvXDWK5Yz8ay8nLg2 5/C1r6I5ogjnHJI7y8lqUgX/Czykp0EMQnKuYhcQ1ws/+W122JX0DlBlLRcmcY/AJe hkbMb/EDDdn+WCppHUXsB9AxFbeOVy+ROr5YAXxc= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180416090652eucas1p27ec1e2eef58b5e95f48a0a4a25e4efb1~l31bR5Lt51665516655eucas1p2c; Mon, 16 Apr 2018 09:06:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 4A.18.17380.CA764DA5; Mon, 16 Apr 2018 10:06:52 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20180416090652eucas1p1de9f6fa001d37a109e5587395653ae11~l31aeVFCE1821318213eucas1p1J; Mon, 16 Apr 2018 09:06:52 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20180416090651eusmtrp29f81dfb559361e668198295e262c2d66~l31aOoMBy1959519595eusmtrp2O; Mon, 16 Apr 2018 09:06:51 +0000 (GMT) X-AuditID: cbfec7f4-b4fc79c0000043e4-58-5ad467ac3df3 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F6.A5.04183.BA764DA5; Mon, 16 Apr 2018 10:06:51 +0100 (BST) Received: from [106.120.43.17] (unknown [106.120.43.17]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180416090650eusmtip22cbba422b156ae1a347052c0346fff27~l31Y9ZCdm2866928669eusmtip2e; Mon, 16 Apr 2018 09:06:50 +0000 (GMT) Subject: Re: [PATCH v6 26/30] drm/rockchip: psr: Avoid redundant calls to .set() callback To: Enric Balletbo i Serra , architt@codeaurora.org, inki.dae@samsung.com, thierry.reding@gmail.com, hjc@rock-chips.com, seanpaul@chromium.org, airlied@linux.ie, tfiga@chromium.org, heiko@sntech.de Cc: dri-devel@lists.freedesktop.org, dianders@chromium.org, ykk@rock-chips.com, kernel@collabora.com, m.szyprowski@samsung.com, linux-samsung-soc@vger.kernel.org, jy0922.shim@samsung.com, rydberg@bitmath.org, krzk@kernel.org, linux-rockchip@lists.infradead.org, kgene@kernel.org, linux-input@vger.kernel.org, orjan.eide@arm.com, wxt@rock-chips.com, jeffy.chen@rock-chips.com, linux-arm-kernel@lists.infradead.org, mark.yao@rock-chips.com, wzz@rock-chips.com, hl@rock-chips.com, jingoohan1@gmail.com, sw0312.kim@samsung.com, linux-kernel@vger.kernel.org, kyungmin.park@samsung.com, Laurent.pinchart@ideasonboard.com, kuankuan.y@gmail.com, hshi@chromium.org From: Andrzej Hajda Message-ID: Date: Mon, 16 Apr 2018 11:06:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180405095000.9756-27-enric.balletbo@collabora.com> Content-Transfer-Encoding: 7bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUxbZRjde7/brPOlTHnCjGadJGIUEGbyGnFRN7Mbf+2Pipi4XceVLUKH vWOKC7OpAh0wYGzqKBPJxiojmJUW+WgisOJWcZaOdE7QVCYj4xvNCow6AWkvi/w7z3nOyXNO 8gi0/g4XLxw0HpZNRinHwGmZtqth/zPN2TcyU4JdT5AT/X0UsVhnWOKzX+bIjfm/ONL8uweR lZEplnxVXUgWHT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wDAAA= X-CMS-MailID: 20180416090652eucas1p1de9f6fa001d37a109e5587395653ae11 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-MTR: 20180416090652eucas1p1de9f6fa001d37a109e5587395653ae11 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180405095305epcas1p11a5082d2f0df9d35b953a4932827be0e X-RootMTR: 20180405095305epcas1p11a5082d2f0df9d35b953a4932827be0e References: <20180405095000.9756-1-enric.balletbo@collabora.com> <20180405095000.9756-27-enric.balletbo@collabora.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05.04.2018 11:49, Enric Balletbo i Serra wrote: > From: Tomasz Figa > > The first time after we call rockchip_drm_do_flush() after > rockchip_drm_psr_register(), we go from PSR_DISABLE to PSR_FLUSH. The > difference between PSR_DISABLE and PSR_FLUSH is whether or not we have a > delayed work pending - PSR is off in either state. However > psr_set_state() only catches the transition from PSR_FLUSH to > PSR_DISABLE (which never happens), while going from PSR_DISABLE to > PSR_FLUSH triggers a call to psr->set() to disable PSR while it's > already disabled. This triggers the eDP PHY power-on sequence without > being shut down first and this seems to occasionally leave the encoder > unable to later enable PSR. Let's just simplify the state machine and > simply consider PSR_DISABLE and PSR_FLUSH the same state. This lets us > represent the hardware state by a simple boolean called "enabled" and, > while at it, rename the misleading "active" boolean to "inhibit", which > represents the purpose much better. This phrase has no corresponding part in the patch. > > Also, userspace can (and does) trigger the rockchip_drm_do_flush() path > from drmModeDirtyFB() at any time, whether or the encoder is active. If > no mode is set, we call into analogix_dp_psr_set() which returns -EINVAL > because encoder->crtc is NULL. Avoid this by starting out with > psr->allowed set to false. ditto > > Signed-off-by: Kristian H. Kristensen > Signed-off-by: Tomasz Figa Original author should be first, 1st line of the patch "From:...." suggests it should be Tomasz. Regards Andrzej > Signed-off-by: Thierry Escande > Signed-off-by: Enric Balletbo i Serra > Tested-by: Marek Szyprowski > --- > > drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 79 +++++++++-------------------- > 1 file changed, 23 insertions(+), 56 deletions(-) > > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c > index c8655e625ba2..448c5fde241c 100644 > --- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c > @@ -22,19 +22,13 @@ > > #define PSR_FLUSH_TIMEOUT_MS 100 > > -enum psr_state { > - PSR_FLUSH, > - PSR_ENABLE, > - PSR_DISABLE, > -}; > - > struct psr_drv { > struct list_head list; > struct drm_encoder *encoder; > > struct mutex lock; > bool active; > - enum psr_state state; > + bool enabled; > > struct delayed_work flush_work; > struct work_struct disable_work; > @@ -78,52 +72,22 @@ static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder) > return psr; > } > > -static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state) > +static int psr_set_state_locked(struct psr_drv *psr, bool enable) > { > - /* > - * Allowed finite state machine: > - * > - * PSR_ENABLE < = = = = = > PSR_FLUSH > - * | ^ | > - * | | | > - * v | | > - * PSR_DISABLE < - - - - - - - - - > - */ > - if (state == psr->state || !psr->active) > - return; > - > - /* Already disabled in flush, change the state, but not the hardware */ > - if (state == PSR_DISABLE && psr->state == PSR_FLUSH) { > - psr->state = state; > - return; > - } > + int ret; > > - /* Actually commit the state change to hardware */ > - switch (state) { > - case PSR_ENABLE: > - if (psr->set(psr->encoder, true)) > - return; > - break; > - > - case PSR_DISABLE: > - case PSR_FLUSH: > - if (psr->set(psr->encoder, false)) > - return; > - break; > - > - default: > - pr_err("%s: Unknown state %d\n", __func__, state); > - return; > - } > + if (!psr->active) > + return -EINVAL; > > - psr->state = state; > -} > + if (enable == psr->enabled) > + return 0; > > -static void psr_set_state(struct psr_drv *psr, enum psr_state state) > -{ > - mutex_lock(&psr->lock); > - psr_set_state_locked(psr, state); > - mutex_unlock(&psr->lock); > + ret = psr->set(psr->encoder, enable); > + if (ret) > + return ret; > + > + psr->enabled = enable; > + return 0; > } > > static void psr_flush_handler(struct work_struct *work) > @@ -131,10 +95,8 @@ static void psr_flush_handler(struct work_struct *work) > struct psr_drv *psr = container_of(to_delayed_work(work), > struct psr_drv, flush_work); > > - /* If the state has changed since we initiated the flush, do nothing */ > mutex_lock(&psr->lock); > - if (psr->state == PSR_FLUSH) > - psr_set_state_locked(psr, PSR_ENABLE); > + psr_set_state_locked(psr, true); > mutex_unlock(&psr->lock); > } > > @@ -176,6 +138,7 @@ int rockchip_drm_psr_deactivate(struct drm_encoder *encoder) > > mutex_lock(&psr->lock); > psr->active = false; > + psr->enabled = false; > mutex_unlock(&psr->lock); > cancel_delayed_work_sync(&psr->flush_work); > cancel_work_sync(&psr->disable_work); > @@ -187,8 +150,12 @@ EXPORT_SYMBOL(rockchip_drm_psr_deactivate); > static void rockchip_drm_do_flush(struct psr_drv *psr) > { > cancel_delayed_work_sync(&psr->flush_work); > - psr_set_state(psr, PSR_FLUSH); > - mod_delayed_work(system_wq, &psr->flush_work, PSR_FLUSH_TIMEOUT_MS); > + > + mutex_lock(&psr->lock); > + if (!psr_set_state_locked(psr, false)) > + mod_delayed_work(system_wq, &psr->flush_work, > + PSR_FLUSH_TIMEOUT_MS); > + mutex_unlock(&psr->lock); > } > > /** > @@ -355,8 +322,8 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, > INIT_WORK(&psr->disable_work, psr_disable_handler); > mutex_init(&psr->lock); > > - psr->active = true; > - psr->state = PSR_DISABLE; > + psr->active = false; > + psr->enabled = false; > psr->encoder = encoder; > psr->set = psr_set; >