From patchwork Fri Oct 3 16:55:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 500 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510619; bh=wz6T8D6AnZRehsCCE6/02hpEU9zIqHRlyjlMiysmnLI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=FEZQs7STmEBWqwDJNcOvZNNb7zpYLvz/AZsbnkaq/RLpaAeUpXDepu85TDl5zSz2b Ahai6UzipEOkPDt4tEbZ71lGYzYQm7lN8amNgbpDUmM77ZtTNYzvpXBJv++nMtAyTd TwCsgbKA62uAmEr3DTRtXVJtOH4BAMkxxEXaGr7cjzx9yyrAmEn8mdueR3kDzEeiy8 qRU9o98PDSMvvEftrjEuHEQcIJSPbWs/sskf8Nr8/rlPKtzXTtac3u2jGVVXDepIxi wYd+g+7B15/eqIVKD7xh8P9lZ9hrym/hgKfBRcCqxZwjqE5pzVRYVOD3Dq1eldu56m ZpbN0ijEY0COg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C885F67F46 for ; Fri, 3 Oct 2025 10:56:59 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id LrgozLCdZxpu for ; Fri, 3 Oct 2025 10:56:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510618; bh=wz6T8D6AnZRehsCCE6/02hpEU9zIqHRlyjlMiysmnLI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kPrFAz5QH4DZQjGYGsMhSfkO/3tMdl0lg3sdYMxjA0Qh4PmkO74RR88q2+KoJypO5 /KJjg+Bx075HeS2WT5pkK5o0nnRQlJg+XnLOMrTTvyHBskj0UnfjgH+tAYcDPiQLAS icdq28Q4keLnaUl+jpDDXpmCRYE5ieKpTKvJupz2kKaw5poKW0J7n915G8NvrEMgmL gR7nPnerPVLC/tyPKfrnHLOJWUq4l3W/g7kYCfE0SWVhIEqiLZ+5ksnSfQvlhSL+km BOp+SwCZzm/plilREkl0fOanKI6BSuDmJioVkTvvD10fVs5PUMt40XjsBBhOlgKVzp BQ3RqjtsLkVmA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D60C567E86 for ; Fri, 3 Oct 2025 10:56:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510617; bh=GatLQG762X8iw4Yyajl7TzQmFgPGNm8JTH5HO8bn+bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFK6ShiQYM1KOue4bEtQeZUAQD8sMdHEqqq4QwU1tJxcX2JqxobGu2gdr80noldcC gHUqwUFQiPE9fyfgUygK3hPqBYZQ2Nre7RC7NEYBEUV8J9LtnwHqlt457HfxoaCf42 TOpIR8hxYbQgdNxfm30A7mBsxkizBbE31EudRuSEAJlsXxrvrbnMt/JG3qhGS8ueui ftE3DYFSsPuxv7BV56aW8KEF1GWsHqNAzEQZolfitmnILPcXI9lvzw0GujjhlyZlU2 O16iD6WHizuHqNIroxS8C71uB+7ZjUCMBXzxb8fRUY+0CtFDOQI590SIWAbhbhs/gr ApwI0oHo3jZAg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 67FC467E85; Fri, 3 Oct 2025 10:56:57 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id itEzQYATfgmN; Fri, 3 Oct 2025 10:56:57 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510615; bh=GcQHb5GbL/YvLtvJvt0nvHgYDDV8nuY8fTOu+e5+R28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RwOKBiWZ1UfI2OHeZkClOCwEfhUTrQ++hG0Ij59WgyRVM3q5V3i2ybCNZZbytyDYU oqB7vIZ9OGJNzcNmlGgxW/FWSI/i34zONZEz7VOhww6TRylD8smr+7iKApUOOP2K6r mISNeOoaT52R9RnIc8UEVh8pYJjr/gpsQFIe3+FxrY9afTBLAGVh1fsRLe6unBskZN tCwiWku1yrxFVs7w9SKqOW8JwjLXQRN2O0KUqhrvpfjH7X3a4U9MaJbgWksLbmTMva l1ZQUB+twURUbwOyC+XpN2WzS/GCUfuDqGXG4TG3xJiTvBJ5eSBBEQebOS1wxw6oKM YuxCGImAXe3YA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9846C67DC0; Fri, 3 Oct 2025 10:56:55 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Oct 2025 10:55:12 -0600 Message-ID: <20251003165525.440173-20-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251003165525.440173-1-sjg@u-boot.org> References: <20251003165525.440173-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TGVTCMVSWFMPLSRH7DLBM3QBCQ77LPXB X-Message-ID-Hash: TGVTCMVSWFMPLSRH7DLBM3QBCQ77LPXB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 19/22] video: Refactor video_sync() to use video_manual_sync() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Extract the core sync logic from video_sync() into a new video_manual_sync() function that accepts flags directly. This allows callers to perform sync operations with explicit control over the sync behavior. The video_sync() function now: - Determines the appropriate flags (VIDSYNC_FORCE, VIDSYNC_FLUSH, VIDSYNC_COPY) based on the force parameter and timing - Calls video_manual_sync() with those flags The video_manual_sync() function: - Takes explicit flags as a parameter - Handles VIDSYNC_COPY flag to control copy framebuffer flush - Performs the actual sync operations This separation allows manual-sync mode users (and tests) to call video_manual_sync() directly with custom flags while video_sync() continues to work as before for normal scenarios. Add tests for video_manual_sync() to check the behaviour with different flag combinations. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/video/video-uclass.c | 46 ++++++++++++++++++++++-------------- include/video.h | 16 +++++++++++++ test/dm/video.c | 27 +++++++++++++++++++++ 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 8f5689a8a51..a8849cf6289 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -499,28 +499,13 @@ static void video_flush_copy(struct udevice *vid) } } -/* Flush video activity to the caches */ -int video_sync(struct udevice *vid, bool force) +int video_manual_sync(struct udevice *vid, uint flags) { struct video_priv *priv = dev_get_uclass_priv(vid); - struct video_uc_priv *uc_priv = uclass_get_priv(vid->uclass); struct video_ops *ops = video_get_ops(vid); - uint flags = 0; int ret; - /* Skip sync if manual-sync mode is active */ - if (uc_priv->manual_sync) - return 0; - - if (force) - flags |= VIDSYNC_FORCE; - - /* Check if sync should do full flush */ - if (!CONFIG_IS_ENABLED(CYCLIC) || force || - get_timer(priv->last_sync) >= CONFIG_VIDEO_SYNC_MS) - flags |= VIDSYNC_FLUSH; - - if (IS_ENABLED(CONFIG_VIDEO_COPY)) + if (IS_ENABLED(CONFIG_VIDEO_COPY) && (flags & VIDSYNC_COPY)) video_flush_copy(vid); if (ops && ops->sync) { @@ -534,7 +519,7 @@ int video_sync(struct udevice *vid, bool force) video_flush_dcache(vid, false); - if (IS_ENABLED(CONFIG_VIDEO_COPY)) + if (IS_ENABLED(CONFIG_VIDEO_COPY) && (flags & VIDSYNC_COPY)) video_flush_dcache(vid, true); #if defined(CONFIG_VIDEO_SANDBOX_SDL) @@ -555,6 +540,31 @@ int video_sync(struct udevice *vid, bool force) return 0; } +/* 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_uc_priv *uc_priv = uclass_get_priv(vid->uclass); + uint flags = 0; + + /* Skip sync if manual-sync mode is active */ + if (uc_priv->manual_sync) + return 0; + + if (force) + flags |= VIDSYNC_FORCE; + + /* Check if sync should do full flush */ + if (!CONFIG_IS_ENABLED(CYCLIC) || force || + get_timer(priv->last_sync) >= CONFIG_VIDEO_SYNC_MS) + flags |= VIDSYNC_FLUSH; + + if (IS_ENABLED(CONFIG_VIDEO_COPY)) + flags |= VIDSYNC_COPY; + + return video_manual_sync(vid, flags); +} + void video_sync_all(void) { struct udevice *dev; diff --git a/include/video.h b/include/video.h index d08781d3a78..d8ba27ab8a7 100644 --- a/include/video.h +++ b/include/video.h @@ -80,10 +80,12 @@ enum video_format { * * @VIDSYNC_FORCE: Force sync even if recently synced or in manual-sync mode * @VIDSYNC_FLUSH: Flush dcache and perform full sync operations + * @VIDSYNC_COPY: Flush framebuffer to copy buffer */ enum video_sync_flags { VIDSYNC_FORCE = BIT(0), VIDSYNC_FLUSH = BIT(1), + VIDSYNC_COPY = BIT(2), }; /** @@ -341,6 +343,20 @@ int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend, int video_draw_box(struct udevice *dev, int x0, int y0, int x1, int y1, int width, u32 colour, bool fill); +/** + * video_manual_sync() - Manually sync a device's frame buffer with its hardware + * + * @vid: Device to sync + * @flags: Flags for the sync (enum video_sync_flags) + * + * @return: 0 on success, error code otherwise + * + * Performs the actual sync operation with the provided flags. This is called + * by video_sync() after determining the appropriate flags, but can also be + * called directly when manual-sync mode is enabled. + */ +int video_manual_sync(struct udevice *vid, uint flags); + /** * video_sync() - Sync a device's frame buffer with its hardware * diff --git a/test/dm/video.c b/test/dm/video.c index cee9e528689..080297d8350 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -1342,6 +1342,33 @@ static int dm_test_video_manual_sync(struct unit_test_state *uts) ut_asserteq(183, video_compress_fb(uts, dev, true)); } + /* Now test video_manual_sync() directly with VIDSYNC_FORCE and COPY */ + ut_assertok(video_manual_sync(dev, VIDSYNC_FORCE | VIDSYNC_FLUSH | + VIDSYNC_COPY)); + ut_asserteq(183, video_compress_fb(uts, dev, false)); + + /* The copy framebuffer should now match since we forced the sync */ + ut_assertok(video_check_copy_fb(uts, dev)); + + /* Write new text again */ + vidconsole_put_string(con, "Test2"); + + /* without VIDSYNC_FLUSH or COPY - should do nothing */ + ut_assertok(video_manual_sync(dev, 0)); + + /* Copy fb should not match since neither flush nor copy occurred */ + if (IS_ENABLED(CONFIG_VIDEO_COPY)) { + ut_assertf(memcmp(priv->fb, priv->copy_fb, priv->fb_size), + "Copy fb shouldn't match fb w/o VIDSYNC_FLUSH/COPY"); + } + + /* video_manual_sync() with full flags - should perform full sync */ + ut_assertok(video_manual_sync(dev, VIDSYNC_FLUSH | VIDSYNC_COPY)); + ut_assertok(video_check_copy_fb(uts, dev)); + + /* Disable manual-sync mode */ + video_set_manual_sync(false); + return 0; } DM_TEST(dm_test_video_manual_sync, UTF_SCAN_PDATA | UTF_SCAN_FDT);