From: Simon Glass <simon.glass@canonical.com> Add a vctx parameter to vidconsole_put_char() 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/atmel/common/video_display.c | 2 +- boot/scene.c | 2 +- boot/scene_txtin.c | 4 ++-- drivers/video/vidconsole-uclass.c | 10 +++++----- include/video_console.h | 3 ++- test/dm/video.c | 14 +++++++------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/board/atmel/common/video_display.c b/board/atmel/common/video_display.c index 55a49b45f16..5d87d456399 100644 --- a/board/atmel/common/video_display.c +++ b/board/atmel/common/video_display.c @@ -71,7 +71,7 @@ int at91_video_show_board_info(void) priv->ctx->y_charsize - 1) / priv->ctx->y_charsize); for (s = buf, i = 0; i < len; s++, i++) - vidconsole_put_char(con, *s); + vidconsole_put_char(con, NULL, *s); return 0; } diff --git a/boot/scene.c b/boot/scene.c index 2627335c0e8..ed25ffdffa3 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -623,7 +623,7 @@ static void draw_string(struct udevice *cons, const char *str, int len, int i; for (i = 0; i < len; i++) - vidconsole_put_char(cons, '*'); + vidconsole_put_char(cons, NULL, '*'); } else { vidconsole_put_stringn(cons, str, len); } diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c index 007f827f776..da42f364f39 100644 --- a/boot/scene_txtin.c +++ b/boot/scene_txtin.c @@ -79,7 +79,7 @@ int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, /* move cursor back to the correct position */ for (i = cls->num; i < cls->eol_num; i++) - vidconsole_put_char(cons, '\b'); + vidconsole_put_char(cons, NULL, '\b'); ret = vidconsole_entry_save(cons, &scn->entry_save); if (ret) return log_msg_ret("sav", ret); @@ -103,7 +103,7 @@ static void scene_txtin_putch(struct cli_line_state *cls, int ch) { struct scene *scn = cls->priv; - vidconsole_put_char(scn->expo->cons, ch); + vidconsole_put_char(scn->expo->cons, NULL, ch); } void scene_txtin_close(struct scene *scn) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 7b23a0a68ac..45f39db99b0 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -486,10 +486,10 @@ static int vidconsole_output_glyph(struct udevice *dev, return 0; } -int vidconsole_put_char(struct udevice *dev, char ch) +int vidconsole_put_char(struct udevice *dev, void *vctx, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); - struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); + struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx_from_priv(priv); struct vidconsole_ansi *ansi = &ctx->ansi; int cp, ret; @@ -514,7 +514,7 @@ int vidconsole_put_char(struct udevice *dev, char ch) break; case '\n': vidconsole_newline(dev, ctx); - vidconsole_entry_start(dev, NULL); + vidconsole_entry_start(dev, ctx); break; case '\t': /* Tab (8 chars alignment) */ ctx->xcur_frac = ((ctx->xcur_frac / ctx->tab_width_frac) @@ -552,7 +552,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, *s); + ret = vidconsole_put_char(dev, NULL, *s); if (ret) return ret; } @@ -573,7 +573,7 @@ static void vidconsole_putc(struct stdio_dev *sdev, const char ch) if (priv->quiet) return; - ret = vidconsole_put_char(dev, ch); + ret = vidconsole_put_char(dev, NULL, ch); if (ret) { #ifdef DEBUG console_puts_select_stderr(true, "[vc err: putc]"); diff --git a/include/video_console.h b/include/video_console.h index 6b8278123da..16c01718bd9 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -748,10 +748,11 @@ int vidconsole_entry_start(struct udevice *dev, void *ctx); * can be adjusted manually using vidconsole_position_cursor(). * * @dev: Device to adjust + * @vctx: Vidconsole context to use, or NULL to use default * @ch: Character to write * Return: 0 if OK, -ve on error */ -int vidconsole_put_char(struct udevice *dev, char ch); +int vidconsole_put_char(struct udevice *dev, void *vctx, char ch); /** * vidconsole_put_stringn() - Output part of a string to the current console pos diff --git a/test/dm/video.c b/test/dm/video.c index ef0c0c5265b..ede09a432a2 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -420,21 +420,21 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot, /* Check display wrap */ for (i = 0; i < 120; i++) - vidconsole_put_char(con, 'A' + i % 50); + vidconsole_put_char(con, NULL, 'A' + i % 50); ut_asserteq(wrap_size, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); /* Check display scrolling */ for (i = 0; i < SCROLL_LINES; i++) { - vidconsole_put_char(con, 'A' + i % 50); - vidconsole_put_char(con, '\n'); + vidconsole_put_char(con, NULL, 'A' + i % 50); + vidconsole_put_char(con, NULL, '\n'); } ut_asserteq(scroll_size, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); /* If we scroll enough, the screen becomes blank again */ for (i = 0; i < SCROLL_LINES; i++) - vidconsole_put_char(con, '\n'); + vidconsole_put_char(con, NULL, '\n'); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -1193,8 +1193,8 @@ static int check_cursor_backspace(struct unit_test_state *uts, ut_assert(!curs->enabled); ut_assert(!curs->saved); ut_assert(!curs->height); - ut_assertok(vidconsole_put_char(con, ' ')); - ut_assertok(vidconsole_put_char(con, 'a')); + ut_assertok(vidconsole_put_char(con, NULL, ' ')); + ut_assertok(vidconsole_put_char(con, NULL, 'a')); with_a = video_compress_fb(uts, dev, false); /* Show cursor at current position (after 'a') */ @@ -1208,7 +1208,7 @@ static int check_cursor_backspace(struct unit_test_state *uts, curs->enabled = true; /* Do backspace - the cursor will be hidden */ - ut_assertok(vidconsole_put_char(con, '\b')); + ut_assertok(vidconsole_put_char(con, NULL, '\b')); ut_assert(!curs->visible); ut_assert(!curs->saved); after_backspace = video_compress_fb(uts, dev, false); -- 2.43.0