From patchwork Tue May 24 07:27:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 9132917 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 9D084607D5 for ; Tue, 24 May 2016 07:29:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 926DC281CB for ; Tue, 24 May 2016 07:29:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 875FF2824F; Tue, 24 May 2016 07:29:28 +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 1258C281CB for ; Tue, 24 May 2016 07:29:28 +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 1b56lF-00075D-UT; Tue, 24 May 2016 07:28:17 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b56lE-0006xo-0t; Tue, 24 May 2016 07:28:16 +0000 Received: by mail-wm0-x242.google.com with SMTP id f75so3333186wmf.2; Tue, 24 May 2016 00:27:54 -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:in-reply-to:references; bh=4EGy70udvFgKOM+ORK7dqU7C9BFnHZL+v6CXzsFXCLo=; b=qcsvnYXD+4jN/k7OsOCpPjmnQXwylFnFIpw4qiTQBwrcfDAuSCB8RRlDI7f/Mp8Pv5 Fogt9JbZ/M0Vo9RcE+VuoHf4aT3kYenQfrDVqer6TlBj7dtTZ9cKxs+kT4DJMTeu/7ry 4m5Q0tfYPO56o9g+WlSf8tGrazlxGn2G86SMBpR5MT/h5CEf+OsNjglcuDvqYPrQ39Fd t2llvHcAH0VVkvamqq6izL+5ffte+T3+uAGWVg4B0EY2wP/C8j2LB3nkw491u0tU3IFq jIJwgwwlyjf3+EB6sxxOVYBCfMZp3rhVkbGP1QbBIYGMKLgR34UaskIcySWKN7iJ2kaI jdEQ== 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 :in-reply-to:references; bh=4EGy70udvFgKOM+ORK7dqU7C9BFnHZL+v6CXzsFXCLo=; b=WaZ+gXrNm+tHwC+qV/J2i+7PoxGoLVQrTUQZ76MUHrCfGrg9c6aWuWVL6Mhd5fx7+H pxiMIFefasye6HrYZAhsKv/aA8KMr3UXKIZze3j7LFPgj0OlwQU65ekOAE6g8UUFYwbR bK+NSac4sVwz3l6Q7RsIFO7+aU5OgqS4+I0wtBfaNmYhQjGCb4l/LL5hmoIaHhp2xvfz Hr925Q4t9h6PD3CawWZArlnUO3be1yTTFCKLEwqW+WCdQdK92+SCnmKH+CcF5gbY37NK waNmVyeyTHHj0I5ileWwlDixDc3aaB2sgbvZOZpfAIC/W9nadLtyXNfDSsy+rGblqm7y F7fA== X-Gm-Message-State: AOPr4FVZrgG+qzTUe5BXKlWde4ys82j7XB9XEY7IFQlJJoH5CK29mAUpwvPlfabDH2JxmA== X-Received: by 10.28.46.19 with SMTP id u19mr21368345wmu.98.1464074873536; Tue, 24 May 2016 00:27:53 -0700 (PDT) Received: from cizrna.lan ([109.72.12.176]) by smtp.gmail.com with ESMTPSA id a81sm2036591wma.16.2016.05.24.00.27.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2016 00:27:51 -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 v5 Date: Tue, 24 May 2016 09:27:37 +0200 Message-Id: <1464074857-5515-1-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464074761-5194-1-git-send-email-tomeu.vizoso@collabora.com> References: <1464074761-5194-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160524_002816_223812_7BA714FE X-CRM114-Status: GOOD ( 14.46 ) 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 Reviewed-by: Daniel Stone --- 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);