From patchwork Wed Sep 14 12:54:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 9331375 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 0850E60231 for ; Wed, 14 Sep 2016 12:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED23329D32 for ; Wed, 14 Sep 2016 12:58:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E210629DCD; Wed, 14 Sep 2016 12:58:25 +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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CF6A29D32 for ; Wed, 14 Sep 2016 12:58:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bk9lg-0008T9-QZ; Wed, 14 Sep 2016 12:58:24 +0000 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bk9ix-00071n-SQ for linux-rockchip@lists.infradead.org; Wed, 14 Sep 2016 12:55:36 +0000 Received: by mail-pa0-x22d.google.com with SMTP id wk8so5305606pab.1 for ; Wed, 14 Sep 2016 05:55:16 -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=zL4b14kJOj/J/c1FD4cvxI5AXZbnJcOibOx7kjlaEHM=; b=VGmmUgxYZ+f9Ys3CuORRnCx9/IY3A007eKFtlWBxKB1xuq2sgU15ZSz6ANVfD6WjwO lkQ/Ro6PhflmpY0JWT08sO92CxGJDOGNtMQDpT5gU2ohUuq89KtnJNsnCDLZ56x0iw35 HAG5WkyctgbZ5vP5ckwnNY7wB6yAt7eU0uJts= 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=zL4b14kJOj/J/c1FD4cvxI5AXZbnJcOibOx7kjlaEHM=; b=XFmfucMZ836tlnxBWHzxjGQVD1KE1/BjldPO9Zxg1GfBjjmlDv47tQ21KW2GymRW/Q RTwAbrbuP89gpaMT+H8K9hzQo5jCkdQH3KpAoFxALZ82m9q2vWxaYkFMMyYg8DfnC5IH JlHizZbRezDee960/0x8OtquCwedSBZ33BIOkKh5PgrRp21WLCsTw9tEd5+OtKj8X5Rl AKzNU2BXI1aNzV2z+qoH1q+7KC8pw8B4T8lcB59TLpSBgx36Jv34M5cMHBaX6y+fDp87 w5jxONK/ptzwL1e8pzTsJuxybf7lzQG7rUlRtEzeUY5Axg9dJCfxgEkUU7qiTUNH7jdU 5EPw== X-Gm-Message-State: AE9vXwPNVEL1/PGVuBpKHWMTmk/RZQuxKB5IONCYNhdul2U82rFTE+cVIde+3TO4lt9ou6A/ X-Received: by 10.66.86.105 with SMTP id o9mr4268848paz.108.1473857715770; Wed, 14 Sep 2016 05:55:15 -0700 (PDT) Received: from basement.tok.corp.google.com ([100.103.3.207]) by smtp.gmail.com with ESMTPSA id t7sm5601309paz.21.2016.09.14.05.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Sep 2016 05:55:15 -0700 (PDT) From: Tomasz Figa To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/8] drm/rockchip: Avoid race with vblank count increment Date: Wed, 14 Sep 2016 21:54:56 +0900 Message-Id: <1473857701-9250-4-git-send-email-tfiga@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1473857701-9250-1-git-send-email-tfiga@chromium.org> References: <1473857701-9250-1-git-send-email-tfiga@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160914_055535_998393_07106C4A X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , David Airlie , linux-kernel@vger.kernel.org, Daniel Kurtz , Tomasz Figa , linux-rockchip@lists.infradead.org, Sean Paul , linux-arm-kernel@lists.infradead.org, Mark Yao MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since VOP does not have a hardware vblank count register, the ongoing commit might be racing with a requested vblank interrupt, which would increment the software vblank counter before the changes being committed actually happen. To avoid this, we can extend .atomic_flush(), so after it sets cfg_done bit, it polls the vblank interrupt bit until it's inactive to make sure that any old vblank interrupt gets to the handler and then uses synchronize_irq(vop->irq) to make sure the handler finishes running. The polling case should happen very rarely, but even if, the total wait time should be relatively low and in practice almost equal to the vop hardirq handler running time. Signed-off-by: Tomasz Figa --- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 68988c6..f989440 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1063,6 +1064,32 @@ static void vop_crtc_enable(struct drm_crtc *crtc) rockchip_drm_psr_activate(&vop->crtc); } +static bool vop_fs_irq_is_pending(struct vop *vop) +{ + return VOP_INTR_GET_TYPE(vop, status, FS_INTR); +} + +static void vop_wait_for_irq_handler(struct vop *vop) +{ + bool pending; + int ret; + + /* + * Spin until frame start interrupt status bit goes low, which means + * that interrupt handler was invoked and cleared it. The timeout of + * 10 msecs is really too long, but it is just a safety measure if + * something goes really wrong. The wait will only happen in the very + * unlikely case of a vblank happening exactly at the same time and + * shouldn't exceed microseconds range. + */ + ret = readx_poll_timeout_atomic(vop_fs_irq_is_pending, vop, pending, + !pending, 0, 10 * 1000); + if (ret) + DRM_DEV_ERROR(vop->dev, "VOP vblank IRQ stuck for 10 ms\n"); + + synchronize_irq(vop->irq); +} + static void vop_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { @@ -1076,6 +1103,13 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc, vop_cfg_done(vop); spin_unlock(&vop->reg_lock); + + /* + * There is a (rather unlikely) possiblity that a vblank interrupt + * fired before we set the cfg_done bit. To avoid spuriously + * signalling flip completion we need to wait for it to finish. + */ + vop_wait_for_irq_handler(vop); } static void vop_crtc_atomic_begin(struct drm_crtc *crtc,