From: Simon Glass <simon.glass@canonical.com> Add a ctx parameter to vidconsole_put_stringn() and vidconsole_put_string() to allow passing in a specific vidconsole context. If NULL, the default context from priv is used. Update all callers accordingly. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- board/kosagi/novena/novena.c | 2 +- boot/expo_test.c | 10 +++--- boot/scene.c | 2 +- cmd/video.c | 4 +-- common/splash.c | 2 +- drivers/video/vidconsole-uclass.c | 11 ++++--- include/video_console.h | 7 +++-- test/dm/video.c | 52 +++++++++++++++---------------- 8 files changed, 47 insertions(+), 43 deletions(-) diff --git a/board/kosagi/novena/novena.c b/board/kosagi/novena/novena.c index f65551ece5e..a1f177265cb 100644 --- a/board/kosagi/novena/novena.c +++ b/board/kosagi/novena/novena.c @@ -79,7 +79,7 @@ int board_late_init(void) display_options_get_banner(false, buf, sizeof(buf)); vidconsole_position_cursor(con, 0, 0); - vidconsole_put_string(con, buf); + vidconsole_put_string(con, NULL, buf); #endif return 0; } diff --git a/boot/expo_test.c b/boot/expo_test.c index ae4e70ceede..2d5ba7c0f4c 100644 --- a/boot/expo_test.c +++ b/boot/expo_test.c @@ -181,14 +181,14 @@ int expo_test_render(struct expo *exp) x = vid_priv->xsize - 18 * ctx->x_charsize; y = 10; vidconsole_set_cursor_pos(exp->cons, NULL, x, y); - vidconsole_put_string(exp->cons, buf); + vidconsole_put_string(exp->cons, NULL, buf); /* Display FPS on next line (only if non-zero) */ if (test->fps_last > 0) { snprintf(buf, sizeof(buf), "fps %6d", test->fps_last); y += ctx->y_charsize; vidconsole_set_cursor_pos(exp->cons, NULL, x, y); - vidconsole_put_string(exp->cons, buf); + vidconsole_put_string(exp->cons, NULL, buf); } /* Display average render time in milliseconds on next line */ @@ -197,7 +197,7 @@ int expo_test_render(struct expo *exp) (test->render_avg_us % 1000) / 100); y += ctx->y_charsize; vidconsole_set_cursor_pos(exp->cons, NULL, x, y); - vidconsole_put_string(exp->cons, buf); + vidconsole_put_string(exp->cons, NULL, buf); /* Display average sync time in milliseconds on next line */ snprintf(buf, sizeof(buf), "sync %6lu.%01lums", @@ -205,7 +205,7 @@ int expo_test_render(struct expo *exp) (test->sync_avg_us % 1000) / 100); y += ctx->y_charsize; vidconsole_set_cursor_pos(exp->cons, NULL, x, y); - vidconsole_put_string(exp->cons, buf); + vidconsole_put_string(exp->cons, NULL, buf); /* Display average poll time in milliseconds on next line */ snprintf(buf, sizeof(buf), "poll %6lu.%01lums", @@ -213,7 +213,7 @@ int expo_test_render(struct expo *exp) (test->poll_avg_us % 1000) / 100); y += ctx->y_charsize; vidconsole_set_cursor_pos(exp->cons, NULL, x, y); - vidconsole_put_string(exp->cons, buf); + vidconsole_put_string(exp->cons, NULL, buf); return 0; } diff --git a/boot/scene.c b/boot/scene.c index ed25ffdffa3..e504cb29d51 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -625,7 +625,7 @@ static void draw_string(struct udevice *cons, const char *str, int len, for (i = 0; i < len; i++) vidconsole_put_char(cons, NULL, '*'); } else { - vidconsole_put_stringn(cons, str, len); + vidconsole_put_stringn(cons, NULL, str, len); } } diff --git a/cmd/video.c b/cmd/video.c index 5c228b48058..cdd5804a172 100644 --- a/cmd/video.c +++ b/cmd/video.c @@ -41,7 +41,7 @@ static int do_video_puts(struct cmd_tbl *cmdtp, int flag, int argc, if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) return CMD_RET_FAILURE; - ret = vidconsole_put_string(dev, argv[1]); + ret = vidconsole_put_string(dev, NULL, argv[1]); if (!ret) ret = video_sync(dev->parent, false); @@ -89,7 +89,7 @@ static int do_video_write(struct cmd_tbl *cmdtp, int flag, int argc, else vidconsole_position_cursor(dev, col, row); - ret = vidconsole_put_string(dev, argv[i + 1]); + ret = vidconsole_put_string(dev, NULL, argv[i + 1]); if (ret) return CMD_RET_FAILURE; } diff --git a/common/splash.c b/common/splash.c index c5591293634..7bdf2927d1e 100644 --- a/common/splash.c +++ b/common/splash.c @@ -149,7 +149,7 @@ void splash_display_banner(void) display_options_get_banner(false, buf, sizeof(buf)); vidconsole_position_cursor(dev, col, 1); - vidconsole_put_string(dev, buf); + vidconsole_put_string(dev, NULL, buf); vidconsole_position_cursor(dev, 0, row); } #endif /* CONFIG_VIDEO && !CONFIG_HIDE_LOGO_VERSION */ diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 45f39db99b0..9b29b742740 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -544,7 +544,8 @@ int vidconsole_put_char(struct udevice *dev, void *vctx, char ch) return 0; } -int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen) +int vidconsole_put_stringn(struct udevice *dev, void *ctx, const char *str, + int maxlen) { const char *s, *end = NULL; int ret; @@ -552,7 +553,7 @@ int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen) if (maxlen != -1) end = str + maxlen; for (s = str; *s && (maxlen == -1 || s < end); s++) { - ret = vidconsole_put_char(dev, NULL, *s); + ret = vidconsole_put_char(dev, ctx, *s); if (ret) return ret; } @@ -560,9 +561,9 @@ int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen) return 0; } -int vidconsole_put_string(struct udevice *dev, const char *str) +int vidconsole_put_string(struct udevice *dev, void *ctx, const char *str) { - return vidconsole_put_stringn(dev, str, -1); + return vidconsole_put_stringn(dev, ctx, str, -1); } static void vidconsole_putc(struct stdio_dev *sdev, const char ch) @@ -595,7 +596,7 @@ static void vidconsole_puts(struct stdio_dev *sdev, const char *s) if (priv->quiet) return; - ret = vidconsole_put_string(dev, s); + ret = vidconsole_put_string(dev, NULL, s); if (ret) { #ifdef DEBUG char str[30]; diff --git a/include/video_console.h b/include/video_console.h index 16c01718bd9..4bb6974edcc 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -765,11 +765,13 @@ int vidconsole_put_char(struct udevice *dev, void *vctx, char ch); * can be adjusted manually using vidconsole_position_cursor(). * * @dev: Device to adjust + * @ctx: Vidconsole context, or NULL to use default * @str: String to write * @maxlen: Maximum chars to output, or -1 for all * Return: 0 if OK, -ve on error */ -int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen); +int vidconsole_put_stringn(struct udevice *dev, void *ctx, const char *str, + int maxlen); /** * vidconsole_put_string() - Output a string to the current console position @@ -782,10 +784,11 @@ int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen); * can be adjusted manually using vidconsole_position_cursor(). * * @dev: Device to adjust + * @ctx: Vidconsole context, or NULL to use default * @str: String to write * Return: 0 if OK, -ve on error */ -int vidconsole_put_string(struct udevice *dev, const char *str); +int vidconsole_put_string(struct udevice *dev, void *ctx, const char *str); /** * vidconsole_position_cursor() - Move the text cursor diff --git a/test/dm/video.c b/test/dm/video.c index ede09a432a2..7a58a64c0f9 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -343,7 +343,7 @@ static int dm_test_video_chars(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); ut_assertok(vidconsole_select_font(con, "8x16", 0)); - vidconsole_put_string(con, test_string); + vidconsole_put_string(con, NULL, test_string); ut_asserteq(466, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -370,18 +370,18 @@ static int dm_test_video_ansi(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); /* test clear escape sequence: [2J */ - vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J"); + vidconsole_put_string(con, NULL, "A\tB\tC" ANSI_ESC "[2J"); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); /* test set-cursor: [%d;%df */ - vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd"); + vidconsole_put_string(con, NULL, "abc" ANSI_ESC "[2;2fab" ANSI_ESC "[4;4fcd"); ut_asserteq(143, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); /* test colors (30-37 fg color, 40-47 bg color) */ - vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */ - vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */ + vidconsole_put_string(con, NULL, ANSI_ESC "[30;41mfoo"); /* black on red */ + vidconsole_put_string(con, NULL, ANSI_ESC "[33;44mbar"); /* yellow on blue */ ut_asserteq(272, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -770,8 +770,8 @@ static int dm_test_video_truetype(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_put_string(con, test_string); - vidconsole_put_stringn(con, test_string, 30); + vidconsole_put_string(con, NULL, test_string); + vidconsole_put_stringn(con, NULL, test_string, 30); ut_asserteq(13073, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -799,7 +799,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_put_string(con, test_string); + vidconsole_put_string(con, NULL, test_string); ut_asserteq(34248, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -825,7 +825,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_put_string(con, test_string); + vidconsole_put_string(con, NULL, test_string); ut_asserteq(29310, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -862,9 +862,9 @@ static int dm_test_video_copy(struct unit_test_state *uts) ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_put_string(con, "\n\n\n\n\n"); - vidconsole_put_string(con, test_string); - vidconsole_put_string(con, test_string); + vidconsole_put_string(con, NULL, "\n\n\n\n\n"); + vidconsole_put_string(con, NULL, test_string); + vidconsole_put_string(con, NULL, test_string); ut_asserteq(6884, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -888,8 +888,8 @@ static int dm_test_video_copy(struct unit_test_state *uts) * ./u-boot -Tl * ut dm dm_test_video_copy */ - vidconsole_put_string(con, test_string); - vidconsole_put_string(con, test_string); + vidconsole_put_string(con, NULL, test_string); + vidconsole_put_string(con, NULL, test_string); video_sync(dev, true); ut_asserteq(7621, video_compress_fb(uts, dev, false)); ut_asserteq(7741, video_compress_fb(uts, dev, true)); @@ -925,21 +925,21 @@ static int dm_test_video_damage(struct unit_test_state *uts) damage = &priv->damage; vidconsole_position_cursor(con, 14, 10); - vidconsole_put_string(con, test_string_2); + vidconsole_put_string(con, NULL, test_string_2); ut_asserteq(449, damage->x0); ut_asserteq(325, damage->y0); ut_asserteq(661, damage->x1); ut_asserteq(350, damage->y1); vidconsole_position_cursor(con, 7, 5); - vidconsole_put_string(con, test_string_1); + vidconsole_put_string(con, NULL, test_string_1); ut_asserteq(225, damage->x0); ut_asserteq(164, damage->y0); ut_asserteq(661, damage->x1); ut_asserteq(350, damage->y1); vidconsole_position_cursor(con, 21, 15); - vidconsole_put_string(con, test_string_3); + vidconsole_put_string(con, NULL, test_string_3); ut_asserteq(225, damage->x0); ut_asserteq(164, damage->y0); ut_asserteq(1280, damage->x1); @@ -1091,15 +1091,15 @@ static int dm_test_video_silence(struct unit_test_state *uts) ut_unsilence_console(uts); printf("message 1: console\n"); - vidconsole_put_string(con, "message 1: video\n"); + vidconsole_put_string(con, NULL, "message 1: video\n"); vidconsole_set_quiet(con, true); printf("second message: console\n"); - vidconsole_put_string(con, "second message: video\n"); + vidconsole_put_string(con, NULL, "second message: video\n"); vidconsole_set_quiet(con, false); printf("final message: console\n"); - vidconsole_put_string(con, "final message: video\n"); + vidconsole_put_string(con, NULL, "final message: video\n"); ut_asserteq(3944, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -1162,15 +1162,15 @@ static int dm_test_video_font_switch(struct unit_test_state *uts) ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); /* Start with TrueType font and write multi-line text */ - vidconsole_put_string(con, truetype_text); + vidconsole_put_string(con, NULL, truetype_text); /* Switch to bitmap font */ ut_assertok(vidconsole_select_font(con, "8x16", 0)); - vidconsole_put_string(con, bitmap_text); + vidconsole_put_string(con, NULL, bitmap_text); /* Switch back to TrueType font */ ut_assertok(vidconsole_select_font(con, NULL, 0)); - vidconsole_put_string(con, final_truetype_text); + vidconsole_put_string(con, NULL, final_truetype_text); ut_asserteq(14892, video_compress_fb(uts, dev, false)); @@ -1332,7 +1332,7 @@ static int dm_test_video_manual_sync(struct unit_test_state *uts) priv = dev_get_uclass_priv(dev); /* Write some text and verify it appears in the framebuffer */ - vidconsole_put_string(con, "Test"); + vidconsole_put_string(con, NULL, "Test"); ut_asserteq(118, video_compress_fb(uts, dev, false)); /* Sync to copy buffer before enabling manual-sync mode */ @@ -1343,7 +1343,7 @@ static int dm_test_video_manual_sync(struct unit_test_state *uts) /* Clear and write new text - auto-sync should not happen */ video_clear(dev); - vidconsole_put_string(con, "Manual Sync"); + vidconsole_put_string(con, NULL, "Manual Sync"); /* should do nothing in manual-sync mode */ ut_assertok(video_sync(dev, false)); @@ -1377,7 +1377,7 @@ static int dm_test_video_manual_sync(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); /* Write new text again */ - vidconsole_put_string(con, "Test2"); + vidconsole_put_string(con, NULL, "Test2"); /* without VIDSYNC_FLUSH or COPY - should do nothing */ ut_assertok(video_manual_sync(dev, 0)); -- 2.43.0