From patchwork Wed Apr 20 13:00:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 8889691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 53B399F1C1 for ; Wed, 20 Apr 2016 13:03:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E0512020F for ; Wed, 20 Apr 2016 13:03:42 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 78982201FE for ; Wed, 20 Apr 2016 13:03:41 +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 1asrlH-0007J4-Cs; Wed, 20 Apr 2016 13:01:43 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asrlE-0007EK-BS; Wed, 20 Apr 2016 13:01:41 +0000 Received: by mail-wm0-x243.google.com with SMTP id n3so13608985wmn.1; Wed, 20 Apr 2016 06:01:19 -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=9oUqpZkjMQRoi9m9rPOouV3HPjN0dRTVOAA3K60l5jE=; b=Ulx7I0nmPiWJtjyEIaTT8h1yXPDu9ilZ9WfgJi8FDQxao5x6xHPtM5A8DQeDSNmhJo lAG3w5ajZZLb5fbpckyQRZRcduosGtRckBLrBRrHz2KID60ior1kGu3wErDbUBlXj+mQ ZU5/4MmCdJbov/l/V5AC25xcZHwpYue1CKWz8DREkymGntvscnwDwRUvjBhn95XLtogF TkHFqtNrOrVsKJ50EsV3b7ZReV0mQN9HT2vkh9T787MmSNEW+bfsWLoExayyyljhA87w NbwV0lrPxpxuRf6WI+Uq4rIVjSup8O0M+xnJ0Z149A/lBxytyZ4DK5RE3QEhCVMADOVz +IsQ== 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=9oUqpZkjMQRoi9m9rPOouV3HPjN0dRTVOAA3K60l5jE=; b=NRNRUNRuA2XONjmUOyIRyC/mRD47eSreGpUSPGfK/oiQE04QjiQ9HiD/x5cvbNE3Yx 0NH4kLcwlng0CrYmxYCPN+HCkT4BDXHFP3DiolLrQivpwmW5/Q7rs+Y4xjvX96iTYSb5 nyxTytsvXobq2jFevAQTjXcPCIpYJeL4rP3e4RvbSxUza5jgRYOueCI4blILZToKWug3 4iGMQh9WlpfLfVCEw6/S3ukoSr7W6yW1t3Z08fPwtFN+UUU8yYW+gTr+GEDvGMpaUXLr CWconW3MI3ixmfHluJZWiqrVCo54l8+PgVn9WfbVr6EFURzuK+0r3JOyivNXdu0l3c80 UVog== X-Gm-Message-State: AOPr4FV7LnuWGU/BfrInWex+xZf4YTr5+HIgwPXIDzO/M3BOLMsKRwlTDcBuSVLfNC5wuQ== X-Received: by 10.194.41.104 with SMTP id e8mr8282054wjl.177.1461157278311; Wed, 20 Apr 2016 06:01:18 -0700 (PDT) Received: from cizrna.lan ([109.72.12.68]) by smtp.gmail.com with ESMTPSA id ki9sm5519450wjb.37.2016.04.20.06.01.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Apr 2016 06:01:17 -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: Wed, 20 Apr 2016 15:00:56 +0200 Message-Id: <1461157257-15964-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-20160420_060140_550091_CEFB3E6A X-CRM114-Status: GOOD ( 12.36 ) X-Spam-Score: -2.4 (--) 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-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.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. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 1 + drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 19 ++++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h index 00d17d71aa4c..02ed8b78c939 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h @@ -70,6 +70,7 @@ int rockchip_register_crtc_funcs(struct drm_crtc *crtc, void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc); int rockchip_drm_crtc_mode_config(struct drm_crtc *crtc, int connector_type, int out_mode); +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 3b8f652698f8..45cdc2859364 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -280,7 +280,24 @@ 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 (async) { + 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) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index a619f120f801..82e6f145f7a2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -850,6 +850,12 @@ int rockchip_drm_crtc_mode_config(struct drm_crtc *crtc, } EXPORT_SYMBOL_GPL(rockchip_drm_crtc_mode_config); +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);