From patchwork Tue May 24 07:26:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 9132913 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 C80AB607D5 for ; Tue, 24 May 2016 07:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B97C52823C for ; Tue, 24 May 2016 07:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB9D02828D; Tue, 24 May 2016 07:28:14 +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 4E6822823C for ; Tue, 24 May 2016 07:28:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b56jv-0006cv-66; Tue, 24 May 2016 07:26:55 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b56jr-0006Y0-S2; Tue, 24 May 2016 07:26:53 +0000 Received: by mail-wm0-x241.google.com with SMTP id 67so3312439wmg.0; Tue, 24 May 2016 00:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=4EGy70udvFgKOM+ORK7dqU7C9BFnHZL+v6CXzsFXCLo=; b=MGYOw3FnBfx2LEw9DtocJlqmRUk0yO8Hrf08fIiZ77U42SFghVPUxD7S04j89Roll2 U3wupRNNq3KXKUPphYe5bpa3vGBqLh+vXU6A234LEvhqCFvR2RRHGacyVO32dyQv37EC il5W1VIQWR7IfJfNHMRfJHiO2RIg61ghlykUVB/7rwKSXvmSurMChmGUyhFUnxkiundA g0NaYAQC+EH2/36jxpHBr0rE4J8fBMunAcZZ7JRHa405dOTu83p3ZTAnpJqZk069j40Z 007Qufop49XavvDHt+h0qldwCRWzDyibxVfAqjYDq4A9f0Zoyub85R4WH2X8W1yS2Wel aOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=4EGy70udvFgKOM+ORK7dqU7C9BFnHZL+v6CXzsFXCLo=; b=d6vaitpfGoOCZjii9c5gsMrYwyTzb13NRt4O1UqEkzPOUzkR9Nhukuo1bq8XLr0qdq p1Juf+2O1ZeBEtUKdl+Q20KC5FsDvtMaaoy+U+OW382KtNJV+T53AuyecjWdNxLeIWe9 kz4EwVfsVv581hWsJCKO4dRBYYFfMcBL5L+9gpHuputc2wNPMdZyoyKoMXY23hX13YI4 pgvxS5KfbDZ0Ba4I8wgOjcA9ohilT9PSxatGkuMFJlNk0TkhUPK6h+2G2bX6vEdCgZCT LScvIcUxwmDOVL917rCewzuJyttAF+aBb5r3dQVLL0iqYd0gISe1LN0m6BeXvPaXevLD CsdA== X-Gm-Message-State: ALyK8tLNiNtCdUAKkD3X2DhYNP3BZE+F8EZIf/4vl0e2Yd3uCdsIJAi/Sfc9WhyD8xRdzw== X-Received: by 10.194.22.167 with SMTP id e7mr2613245wjf.9.1464074789628; Tue, 24 May 2016 00:26:29 -0700 (PDT) Received: from cizrna.lan ([109.72.12.176]) by smtp.gmail.com with ESMTPSA id jq1sm1560999wjc.28.2016.05.24.00.26.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2016 00:26:28 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH] drm/rockchip: Return -EBUSY if there's already a pending flip event v4 Date: Tue, 24 May 2016 09:26:01 +0200 Message-Id: <1464074761-5194-1-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160524_002652_062911_71E1F6B0 X-CRM114-Status: GOOD ( 14.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Tomeu Vizoso , David Airlie , dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, 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 As per the docs, atomic_commit should return -EBUSY "if an asycnhronous updated is requested and there is an earlier updated pending". v2: Use the status of the workqueue instead of vop->event, and don't add a superfluous wait on the workqueue. v3: Drop work_busy, as there's a sizeable delay when the worker finishes, which introduces a race in which the client has already received the last flip event but the next page flip ioctl will still return -EBUSY because work_busy returns outdated information. v4: Hold dev->event_lock while checking the VOP's event field as suggested by Daniel Stone. v5: Only block if there's outstanding work if it's a blocking call. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 1 + drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 6 ++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h index 56f43a364c7f..0b46617decd9 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h @@ -76,6 +76,7 @@ void rockchip_drm_atomic_work(struct work_struct *work); int rockchip_register_crtc_funcs(struct drm_crtc *crtc, const struct rockchip_crtc_funcs *crtc_funcs); void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc); +bool rockchip_drm_crtc_has_pending_event(struct drm_crtc *crtc); int rockchip_drm_dma_attach_device(struct drm_device *drm_dev, struct device *dev); void rockchip_drm_dma_detach_device(struct drm_device *drm_dev, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 755cfdba61cd..e9531353b8d2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -279,15 +279,34 @@ int rockchip_drm_atomic_commit(struct drm_device *dev, { struct rockchip_drm_private *private = dev->dev_private; struct rockchip_atomic_commit *commit = &private->commit; - int ret; + struct drm_crtc_state *crtc_state; + struct drm_crtc *crtc; + unsigned long flags; + int i, ret; + + if (nonblock) { + for_each_crtc_in_state(state, crtc, crtc_state, i) { + spin_lock_irqsave(&dev->event_lock, flags); + + if (crtc->state->event || + rockchip_drm_crtc_has_pending_event(crtc)) { + spin_unlock_irqrestore(&dev->event_lock, flags); + return -EBUSY; + } + + spin_unlock_irqrestore(&dev->event_lock, flags); + } + } ret = drm_atomic_helper_prepare_planes(dev, state); if (ret) return ret; - /* serialize outstanding nonblocking commits */ mutex_lock(&commit->lock); - flush_work(&commit->work); + + /* serialize outstanding nonblocking commits */ + if (!nonblock) + flush_work(&commit->work); drm_atomic_helper_swap_state(dev, state); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 1c4d5b5a70a2..3f980f52c640 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -836,6 +836,12 @@ static const struct drm_plane_funcs vop_plane_funcs = { .atomic_destroy_state = vop_atomic_plane_destroy_state, }; +bool rockchip_drm_crtc_has_pending_event(struct drm_crtc *crtc) +{ + assert_spin_locked(&crtc->dev->event_lock); + return to_vop(crtc)->event; +} + static int vop_crtc_enable_vblank(struct drm_crtc *crtc) { struct vop *vop = to_vop(crtc);