From patchwork Tue Jan 3 21:50:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 1721181 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nmmdt5txSz23f3 for ; Wed, 4 Jan 2023 08:51:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D067D85559; Tue, 3 Jan 2023 22:50:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=csgraf.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7FD9C854B1; Tue, 3 Jan 2023 22:50:23 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from zulu616.server4you.de (mail.csgraf.de [85.25.223.15]) by phobos.denx.de (Postfix) with ESMTP id A887C8547A for ; Tue, 3 Jan 2023 22:50:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=csgraf.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=agraf@csgraf.de Received: from localhost.localdomain (dynamic-092-225-244-121.92.225.pool.telefonica.de [92.225.244.121]) by csgraf.de (Postfix) with ESMTPSA id 0206A6081042; Tue, 3 Jan 2023 22:50:09 +0100 (CET) From: Alexander Graf To: u-boot@lists.denx.de Cc: Matthias Brugger , Heinrich Schuchardt , Anatolij Gustschin , Simon Glass , Da Xue , Ilias Apalodimas , Jagan Teki , Andre Przywara , Neil Armstrong , Philipp Tomsich , Kever Yang , Patrick Delaunay , Patrice Chotard , uboot-stm32@st-md-mailman.stormreply.com, u-boot-amlogic@groups.io Subject: [PATCH v4 6/9] video: Only dcache flush damaged lines Date: Tue, 3 Jan 2023 22:50:01 +0100 Message-Id: <20230103215004.22646-7-agraf@csgraf.de> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230103215004.22646-1-agraf@csgraf.de> References: <20230103215004.22646-1-agraf@csgraf.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Now that we have a damage area tells us which parts of the frame buffer actually need updating, let's only dcache flush those on video_sync() calls. With this optimization in place, frame buffer updates - especially on large screen such as 4k displays - speed up significantly. Signed-off-by: Alexander Graf Reported-by: Da Xue --- v1 -> v2: - Fix dcache range; we were flushing too much before - Remove ifdefs v3 -> v4: - Simplify first damage logic --- drivers/video/video-uclass.c | 45 +++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 48fc29aeb0..37ab9f7ca4 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -289,9 +289,45 @@ int video_damage(struct udevice *vid, int x, int y, int width, int height) return 0; } +#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) +static void video_flush_dcache(struct udevice *vid) +{ + struct video_priv *priv = dev_get_uclass_priv(vid); + + if (!priv->flush_dcache) + return; + + if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE)) { + flush_dcache_range((ulong)priv->fb, + ALIGN((ulong)priv->fb + priv->fb_size, + CONFIG_SYS_CACHELINE_SIZE)); + + return; + } + + if (priv->damage.endx > priv->damage.x) { + int lstart = priv->damage.x * VNBYTES(priv->bpix); + int lend = priv->damage.endx * VNBYTES(priv->bpix); + int y; + + for (y = priv->damage.y; y < priv->damage.endy; y++) { + ulong fb = (ulong)priv->fb; + ulong start = fb + (y * priv->line_length) + lstart; + ulong end = start + lend - lstart; + + start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE); + end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE); + + flush_dcache_range(start, end); + } + } +} +#endif + /* Flush video activity to the caches */ int video_sync(struct udevice *vid, bool force) { + struct video_priv *priv = dev_get_uclass_priv(vid); struct video_ops *ops = video_get_ops(vid); int ret; @@ -307,15 +343,8 @@ int video_sync(struct udevice *vid, bool force) * out whether it exists? For now, ARM is safe. */ #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) - struct video_priv *priv = dev_get_uclass_priv(vid); - - if (priv->flush_dcache) { - flush_dcache_range((ulong)priv->fb, - ALIGN((ulong)priv->fb + priv->fb_size, - CONFIG_SYS_CACHELINE_SIZE)); - } + video_flush_dcache(vid); #elif defined(CONFIG_VIDEO_SANDBOX_SDL) - struct video_priv *priv = dev_get_uclass_priv(vid); static ulong last_sync; if (force || get_timer(last_sync) > 100) {