Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7137306rwp; Tue, 18 Jul 2023 10:32:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlF4Dg9TRlwcmWvVhTAh6EeN0uCcDKipfw+AHIj6mjZVNWWdvSQxWDddOFksjlx2450qt3m/ X-Received: by 2002:a17:906:1084:b0:98d:cacb:888f with SMTP id u4-20020a170906108400b0098dcacb888fmr399982eju.49.1689701564867; Tue, 18 Jul 2023 10:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689701564; cv=none; d=google.com; s=arc-20160816; b=x3XE8a6DjfY/4axLUsbR3zvHkH7VXHNC6Qa50Wvi7FZ4QepzUymub/i0XZnGDQzauO 4PG8dXj2TNo0hb2nb3sz745+Sa4poksGTxpOzlD24QQkfMpVEF76R5FCVdKAmNFRj0kD k6Nm7uZ8yHStNl7eLNOt3nYIn4bu1b3FP7/u/K1t1Sd69Frp5kswjM5AcUWdwmk7ViVX iKDjY4TQiWcdZtJALmfHlSzHCFMqA9HRtUUAzpyIXGV/i3XfKuUwf165ollyQWBEL2ql Tvb6fVJ+X4+LXpoKW13dMdu5NH0logxvutQu8FcmxuXf7GI+99aQlY03RpdpAOmhWN6z YayQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jNlS1AkXh5yEx7IayLaOVW18qs8qRML+OlK5MZwkua4=; fh=Ople2ijcDVdvBJwvAg2RvyZp0qNZK7It46SN0LxlrVk=; b=XXQM1t2NnIUev0eQ679AST66925a/gYAx508cA4+QPvFC54z/O6RlZnlW5SKrRiODt t/HZ2pDc1XcxwrOTJaXnHanHThBzeFBCWhUea8ZqXtZOK6MP3hffKl0CBK63PaIBAZ6J 1YOzwwZBJTo6/aq2rb0QSv3reM2SWThjPITlm9G0Jjj01zOLpdaJ47J1SYcuPb6d9oC4 ohKUojII3xdJj7heHSxD/nlTtvkmEUhdDh7KrfsJ/qZ7Ogccc+3+6E6prHmf4orXljPb ztcz5EhltNGvpt6z+VNbvfGvdFufERxKVf/ualMIUUHfF1WdDI53EO+C8dXy9OAdSPvO Ybng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jr14-20020a170906a98e00b00992b17e93f1si1451975ejb.47.2023.07.18.10.32.20; Tue, 18 Jul 2023 10:32:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232985AbjGRQ4q (ORCPT + 99 others); Tue, 18 Jul 2023 12:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbjGRQzF (ORCPT ); Tue, 18 Jul 2023 12:55:05 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0F919B2 for ; Tue, 18 Jul 2023 09:54:54 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:5803:2d6d:5bbc:e252]) by michel.telenet-ops.be with bizsmtp id Ngur2A00L0ucMBo06gurXQ; Tue, 18 Jul 2023 18:54:53 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qLnyD-001nZU-L7; Tue, 18 Jul 2023 18:54:51 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qLnyN-000gdf-MI; Tue, 18 Jul 2023 18:54:51 +0200 From: Geert Uytterhoeven To: Laurent Pinchart , Kieran Bingham , David Airlie , Daniel Vetter , Thomas Zimmermann , Magnus Damm Cc: linux-renesas-soc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Laurent Pinchart Subject: [PATCH v2 32/41] drm: renesas: shmobile: Wait for page flip when turning CRTC off Date: Tue, 18 Jul 2023 18:54:37 +0200 Message-Id: <99cf08e52537069380e20be72e5bdf62214dd8dd.1689698048.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turning a CRTC off will prevent a queued page flip from ever completing, potentially confusing userspace. Wait for queued page flips to complete before turning the CRTC off to avoid this. Signed-off-by: Geert Uytterhoeven Reviewed-by: Laurent Pinchart --- v2: - Add Reviewed-by. --- .../gpu/drm/renesas/shmobile/shmob_drm_crtc.c | 37 +++++++++++++++++++ .../gpu/drm/renesas/shmobile/shmob_drm_crtc.h | 3 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c index 0adf5d33ba31695e..20adb9d2fa178250 100644 --- a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c +++ b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.c @@ -50,11 +50,40 @@ void shmob_drm_crtc_finish_page_flip(struct shmob_drm_crtc *scrtc) scrtc->event = NULL; if (event) { drm_crtc_send_vblank_event(&scrtc->base, event); + wake_up(&scrtc->flip_wait); drm_crtc_vblank_put(&scrtc->base); } spin_unlock_irqrestore(&dev->event_lock, flags); } +static bool shmob_drm_crtc_page_flip_pending(struct shmob_drm_crtc *scrtc) +{ + struct drm_device *dev = scrtc->base.dev; + unsigned long flags; + bool pending; + + spin_lock_irqsave(&dev->event_lock, flags); + pending = scrtc->event != NULL; + spin_unlock_irqrestore(&dev->event_lock, flags); + + return pending; +} + +static void shmob_drm_crtc_wait_page_flip(struct shmob_drm_crtc *scrtc) +{ + struct drm_crtc *crtc = &scrtc->base; + struct shmob_drm_device *sdev = to_shmob_device(crtc->dev); + + if (wait_event_timeout(scrtc->flip_wait, + !shmob_drm_crtc_page_flip_pending(scrtc), + msecs_to_jiffies(50))) + return; + + dev_warn(sdev->dev, "page flip timeout\n"); + + shmob_drm_crtc_finish_page_flip(scrtc); +} + /* ----------------------------------------------------------------------------- * CRTC */ @@ -253,6 +282,12 @@ static void shmob_drm_crtc_stop(struct shmob_drm_crtc *scrtc) if (!scrtc->started) return; + /* + * Wait for page flip completion before stopping the CRTC as userspace + * expects page flips to eventually complete. + */ + shmob_drm_crtc_wait_page_flip(scrtc); + /* Stop the LCDC. */ shmob_drm_crtc_start_stop(scrtc, false); @@ -463,6 +498,8 @@ int shmob_drm_crtc_create(struct shmob_drm_device *sdev) unsigned int i; int ret; + init_waitqueue_head(&sdev->crtc.flip_wait); + sdev->crtc.dpms = DRM_MODE_DPMS_OFF; primary = shmob_drm_plane_create(sdev, DRM_PLANE_TYPE_PRIMARY, 0); diff --git a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h index 2c6d7541427581a6..b9863e026e8a9b83 100644 --- a/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h +++ b/drivers/gpu/drm/renesas/shmobile/shmob_drm_crtc.h @@ -14,6 +14,8 @@ #include #include +#include + #include