[PATCH 00/14] video: Add per-client context to vidconsole
From: Simon Glass <simon.glass@canonical.com> This series refactors the vidconsole interface to support multiple clients with their own context. This will enables features like expo to maintain separate text-entry state without interfering with each other. The approach is to create a new struct vidconsole_ctx that holds per-client state, initially embedded in vidconsole_priv for the default context. Helper functions vidconsole_ctx() and vidconsole_ctx_from_priv() provide access to the context. Fields moved into vidconsole_ctx: - rows, cols, x_charsize, y_charsize (display metrics) - xcur_frac, ycur (cursor position) - last_ch (for kerning) - cli_index, xmark_frac, ymark (CLI entry state) - ansi, utf8_buf (parsing state) The series also adds ctx_new() and ctx_dispose() operations for drivers to allocate and free per-client context, with implementations for both the normal and truetype console drivers. Simon Glass (14): video: Add empty vidconsole_ctx struct video: Add vidconsole context creation and disposal video: truetype: Restore pos_start in entry_restore() video: truetype: Move per-client context into ctx struct video: Add a helper to obtain the vidconsole context video: Move rows and cols into vidconsole_ctx video: Move x_charsize and y_charsize into vidconsole_ctx video: Create struct vidconsole_ansi for ANSI state video: Move xcur_frac into vidconsole_ctx video: Move ycur into vidconsole_ctx video: Move last_ch into vidconsole_ctx video: Move cli_index into vidconsole_ctx video: Move xmark_frac and ymark into vidconsole_ctx video: Move ansi and utf8_buf into vidconsole_ctx board/atmel/common/video_display.c | 3 +- boot/expo_test.c | 10 +- common/console.c | 6 +- drivers/video/console_core.c | 3 +- drivers/video/console_normal.c | 66 +++++++-- drivers/video/console_rotate.c | 9 +- drivers/video/console_truetype.c | 186 +++++++++++++++---------- drivers/video/vidconsole-uclass.c | 214 ++++++++++++++++++----------- drivers/video/video-uclass.c | 4 +- include/video_console.h | 167 ++++++++++++++++------ lib/efi_loader/efi_console.c | 10 +- test/dm/video.c | 22 +++ 12 files changed, 473 insertions(+), 227 deletions(-) -- 2.43.0 base-commit: 26606c3849cb974cba6037c79edd0329f7b27a32 branch: expb
From: Simon Glass <simon.glass@canonical.com> Add a new struct vidconsole_ctx to hold per-client state for video consoles. Add some driver-specific structs as well, so that each driver can build on the common context fields. This is preparation for supporting multiple clients with their own context. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 9 +++++++++ drivers/video/console_truetype.c | 9 +++++++++ include/video_console.h | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 8f936191dd8..cfe6196fced 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -14,6 +14,15 @@ #include <video_font.h> /* Get font data, width and height */ #include "vidconsole_internal.h" +/** + * struct console_ctx - context for the normal console + * + * @com: Common fields from the vidconsole uclass + */ +struct console_ctx { + struct vidconsole_ctx com; +}; + struct console_store { int xpos_frac; int ypos; diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index cbc4473207c..c2d165a8b8e 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -203,6 +203,15 @@ struct console_tt_metrics { double scale; }; +/** + * struct console_tt_ctx - Per-client context for this driver + * + * @com: Common fields from the vidconsole uclass + */ +struct console_tt_ctx { + struct vidconsole_ctx com; +}; + /** * struct console_tt_priv - Private data for this driver * diff --git a/include/video_console.h b/include/video_console.h index ac04aeb3aef..0acc7ab2737 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -73,6 +73,15 @@ struct vidconsole_cursor { uint index; }; +/** + * struct vidconsole_ctx - per-client context for a video console + * + * This holds per-client state for video consoles. It can be used by clients + * to maintain separate contexts for different text-entry operations. + */ +struct vidconsole_ctx { +}; + /** * struct vidconsole_priv - uclass-private data about a console device * -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Add ctx_new and ctx_dispose operations to the vidconsole interface. These allow clients to create and dispose of their own context, with the driver determining what state is stored in the context buffer. The wrapper functions provide default implementations that just initialise or free the abuf if the driver does not implement the ops. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 24 +++++++++++++++++ drivers/video/console_truetype.c | 23 ++++++++++++++++ drivers/video/vidconsole-uclass.c | 32 ++++++++++++++++++++++ include/video_console.h | 44 +++++++++++++++++++++++++++++++ test/dm/video.c | 22 ++++++++++++++++ 5 files changed, 145 insertions(+) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index cfe6196fced..f6dc37bc6be 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -8,6 +8,7 @@ #include <charset.h> #include <dm.h> +#include <malloc.h> #include <spl.h> #include <video.h> #include <video_console.h> @@ -188,6 +189,27 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) return console_normal_putc_xy(dev, x_frac, y, cp); } +static int console_simple_ctx_new(struct udevice *dev, void **ctxp) +{ + struct console_ctx *ctx; + + ctx = malloc(sizeof(*ctx)); + if (!ctx) + return -ENOMEM; + + memset(ctx, '\0', sizeof(*ctx)); + *ctxp = ctx; + + return 0; +} + +static int console_simple_ctx_dispose(struct udevice *dev, void *ctx) +{ + free(ctx); + + return 0; +} + struct vidconsole_ops console_ops = { .putc_xy = console_putc_xy, .move_rows = console_move_rows, @@ -195,6 +217,8 @@ struct vidconsole_ops console_ops = { .get_font_size = console_simple_get_font_size, .get_font = console_simple_get_font, .select_font = console_simple_select_font, + .ctx_new = console_simple_ctx_new, + .ctx_dispose = console_simple_ctx_dispose, #ifdef CONFIG_CURSOR .get_cursor_info = console_get_cursor_info, .entry_save = normal_entry_save, diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index c2d165a8b8e..d707ac3c864 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -1149,6 +1149,27 @@ static int truetype_nominal(struct udevice *dev, const char *name, uint size, return 0; } +static int truetype_ctx_new(struct udevice *dev, void **ctxp) +{ + struct console_tt_ctx *ctx; + + ctx = malloc(sizeof(*ctx)); + if (!ctx) + return -ENOMEM; + + memset(ctx, '\0', sizeof(*ctx)); + *ctxp = ctx; + + return 0; +} + +static int truetype_ctx_dispose(struct udevice *dev, void *ctx) +{ + free(ctx); + + return 0; +} + static int truetype_entry_save(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); @@ -1331,6 +1352,8 @@ struct vidconsole_ops console_truetype_ops = { .select_font = truetype_select_font, .measure = truetype_measure, .nominal = truetype_nominal, + .ctx_new = truetype_ctx_new, + .ctx_dispose = truetype_ctx_dispose, .entry_save = truetype_entry_save, .entry_restore = truetype_entry_restore, .get_cursor_info = truetype_get_cursor_info, diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 8efe458287a..8ef9f4c90d6 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -690,6 +690,38 @@ int vidconsole_nominal(struct udevice *dev, const char *name, uint size, return 0; } +int vidconsole_ctx_new(struct udevice *dev, void **ctxp) +{ + struct vidconsole_ops *ops = vidconsole_get_ops(dev); + void *ctx; + int ret; + + if (!ops->ctx_new) + return -ENOSYS; + + ret = ops->ctx_new(dev, &ctx); + if (ret) + return ret; + *ctxp = ctx; + + return 0; +} + +int vidconsole_ctx_dispose(struct udevice *dev, void *ctx) +{ + struct vidconsole_ops *ops = vidconsole_get_ops(dev); + int ret; + + if (!ops->ctx_dispose) + return -ENOSYS; + + ret = ops->ctx_dispose(dev, ctx); + if (ret) + return ret; + + return 0; +} + int vidconsole_entry_save(struct udevice *dev, struct abuf *buf) { struct vidconsole_ops *ops = vidconsole_get_ops(dev); diff --git a/include/video_console.h b/include/video_console.h index 0acc7ab2737..adc4537ceb7 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -348,6 +348,28 @@ struct vidconsole_ops { int (*nominal)(struct udevice *dev, const char *name, uint size, uint num_chars, struct vidconsole_bbox *bbox); + /** + * ctx_new() - Create a new context for a client + * + * Allocates and initialises a context for a client of the vidconsole. + * The driver determines what information is stored in the context. + * + * @dev: Console device to use + * @ctxp: Returns new context, on success + * Return: 0 on success, -ENOMEM if out of memory + */ + int (*ctx_new)(struct udevice *dev, void **ctxp); + + /** + * ctx_dispose() - Dispose of a context + * + * Frees any memory allocated for the context. + * + * @dev: Console device to use + * @ctx: Context to dispose of + */ + int (*ctx_dispose)(struct udevice *dev, void *ctx); + /** * entry_save() - Save any text-entry information for later use * @@ -456,6 +478,28 @@ int vidconsole_measure(struct udevice *dev, const char *name, uint size, int vidconsole_nominal(struct udevice *dev, const char *name, uint size, uint num_chars, struct vidconsole_bbox *bbox); +/** + * vidconsole_ctx_new() - Create a new context for a client + * + * Allocates and initialises a context for a client of the vidconsole. + * The driver determines what information is stored in the context. + * + * @dev: Console device to use + * @ctxp: Returns new context, on success + * Return: 0 on success, -ENOMEM if out of memory + */ +int vidconsole_ctx_new(struct udevice *dev, void **ctxp); + +/** + * vidconsole_ctx_dispose() - Dispose of a context + * + * Frees any memory allocated for the context. + * + * @dev: Console device to use + * @ctx: Context to dispose of + */ +int vidconsole_ctx_dispose(struct udevice *dev, void *ctx); + /** * vidconsole_entry_save() - Save any text-entry information for later use * diff --git a/test/dm/video.c b/test/dm/video.c index 6029fa3d5cc..d802a5cc24d 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -1493,3 +1493,25 @@ static int dm_test_video_sync_damage(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_video_sync_damage, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +/* Test vidconsole context allocation */ +static int dm_test_video_context_alloc(struct unit_test_state *uts) +{ + struct udevice *dev, *con; + void *ctx; + + ut_assertok(select_vidconsole(uts, "vidconsole0")); + ut_assertok(video_get_nologo(uts, &dev)); + ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); + + ut_assertok(vidconsole_ctx_new(con, &ctx)); + ut_assertnonnull(ctx); + + ut_assertok(vidconsole_ctx_dispose(con, ctx)); + + /* Dispose should handle NULL gracefully */ + ut_assertok(vidconsole_ctx_dispose(con, NULL)); + + return 0; +} +DM_TEST(dm_test_video_context_alloc, UTF_SCAN_PDATA | UTF_SCAN_FDT); -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> The pos_start member is saved by truetype_entry_save() but is not restored by truetype_entry_restore(). Add the missing restoration. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_truetype.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index d707ac3c864..74255ac98ac 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -1209,6 +1209,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) vc_priv->xcur_frac = store.cur.xpos_frac; vc_priv->ycur = store.cur.ypos; priv->pos_ptr = store.priv.pos_ptr; + priv->pos_start = store.priv.pos_start; priv->pos_count = store.priv.pos_count; memcpy(priv->pos, store.priv.pos, store.priv.pos_ptr * sizeof(struct pos_info)); -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Add some of the per-client state for the truetype console driver into the context struct. This includes the position history pos[], pos_ptr, pos_start and pos_count fields. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_truetype.c | 87 +++++++++++++++++--------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 74255ac98ac..f55c56671e2 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -207,9 +207,22 @@ struct console_tt_metrics { * struct console_tt_ctx - Per-client context for this driver * * @com: Common fields from the vidconsole uclass + * @pos_ptr: Current position in the position history + * @pos_start: Value of pos_ptr when the cursor is at the start of the text + * being entered by the user + * @pos_count: Maximum value reached by pos_ptr (initially zero) + * @pos: List of cursor positions for each character written. This is + * used to handle backspace. We clear the frame buffer between + * the last position and the current position, thus erasing the + * last character. We record enough characters to go back to the + * start of the current command line. */ struct console_tt_ctx { struct vidconsole_ctx com; + int pos_ptr; + int pos_start; + int pos_count; + struct pos_info pos[POS_HISTORY_SIZE]; }; /** @@ -218,16 +231,8 @@ struct console_tt_ctx { * @cur_met: Current metrics being used * @metrics: List metrics that can be used * @num_metrics: Number of available metrics - * @pos: List of cursor positions for each character written. This is - * used to handle backspace. We clear the frame buffer between - * the last position and the current position, thus erasing the - * last character. We record enough characters to go back to the - * start of the current command line. - * @pos_ptr: Current position in the position history * @cur_fontdata: Current fixed font data (NULL if using TrueType) - * @pos_start: Value of pos_ptr when the cursor is at the start of the text - * being entered by the user - * @pos_count: Maximum value reached by pos_ptr (initially zero) + * @ctx: Per-client context * @glyph_buf: Pre-allocated buffer for rendering glyphs. If a glyph fits, * this avoids malloc/free per character. Allocated lazily after * relocation to avoid using early malloc space. @@ -239,11 +244,8 @@ struct console_tt_priv { struct console_tt_metrics *cur_met; struct console_tt_metrics metrics[CONFIG_CONSOLE_TRUETYPE_MAX_METRICS]; int num_metrics; - struct pos_info pos[POS_HISTORY_SIZE]; - int pos_ptr; struct video_fontdata *cur_fontdata; - int pos_start; - int pos_count; + struct console_tt_ctx ctx; u8 *glyph_buf; int glyph_buf_size; struct stbtt_scratch scratch; @@ -325,6 +327,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst, struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; void *dst; void *src; int i, diff, font_height; @@ -341,8 +344,8 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst, /* Scroll up our position history */ diff = (rowsrc - rowdst) * font_height; - for (i = 0; i < priv->pos_ptr; i++) - priv->pos[i].ypos -= diff; + for (i = 0; i < ctx->pos_ptr; i++) + ctx->pos[i].ypos -= diff; video_damage(dev->parent, 0, @@ -367,20 +370,21 @@ static void clear_from(struct udevice *dev, int index) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; struct udevice *vid_dev = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); struct pos_info *start_pos, *end_pos; int xstart, xend; int ystart, yend; - assert(priv->pos_count && index && index < priv->pos_count); + assert(ctx->pos_count && index && index < ctx->pos_count); - start_pos = &priv->pos[index]; + start_pos = &ctx->pos[index]; xstart = VID_TO_PIXEL(start_pos->xpos_frac); ystart = start_pos->ypos; /* End position is the last character in the position array */ - end_pos = &priv->pos[priv->pos_count - 1]; + end_pos = &ctx->pos[ctx->pos_count - 1]; xend = VID_TO_PIXEL(end_pos->xpos_frac) + end_pos->width; yend = end_pos->ypos; @@ -412,6 +416,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; struct console_tt_metrics *met = priv->cur_met; stbtt_fontinfo *font; int width, height, xoff, yoff; @@ -440,8 +445,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, * First out our current X position in fractional pixels. If we wrote * a character previously, use kerning to fine-tune the position of * this character */ - pos = priv->pos_ptr < priv->pos_count ? &priv->pos[priv->pos_ptr] : - NULL; + pos = ctx->pos_ptr < ctx->pos_count ? &ctx->pos[ctx->pos_ptr] : NULL; xpos = frac(VID_TO_PIXEL((double)x)); kern = 0; if (vc_priv->last_ch) { @@ -474,27 +478,27 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, return -EAGAIN; /* Write the current cursor position into history */ - if (priv->pos_ptr < POS_HISTORY_SIZE) { + if (ctx->pos_ptr < POS_HISTORY_SIZE) { bool erase = false; /* Check if we're overwriting a different character */ if (pos && pos->cp != cp) { erase = true; /* Erase using the old character's position before updating */ - clear_from(dev, priv->pos_ptr); + clear_from(dev, ctx->pos_ptr); /* After erasing, we don't care about erased characters */ - priv->pos_count = priv->pos_ptr; + ctx->pos_count = ctx->pos_ptr; } - pos = &priv->pos[priv->pos_ptr]; + pos = &ctx->pos[ctx->pos_ptr]; pos->xpos_frac = vc_priv->xcur_frac; pos->ypos = vc_priv->ycur; pos->width = (width_frac + VID_FRAC_DIV - 1) / VID_FRAC_DIV; pos->cp = cp; - priv->pos_ptr++; - if (priv->pos_ptr > priv->pos_count) - priv->pos_count = priv->pos_ptr; + ctx->pos_ptr++; + if (ctx->pos_ptr > ctx->pos_count) + ctx->pos_count = ctx->pos_ptr; } /* @@ -677,6 +681,7 @@ static int console_truetype_backspace(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; struct udevice *vid_dev = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); struct pos_info *pos; @@ -686,11 +691,11 @@ static int console_truetype_backspace(struct udevice *dev) * This indicates a very strange error higher in the stack. The caller * has sent out n character and n + 1 backspaces. */ - if (!priv->pos_ptr) + if (!ctx->pos_ptr) return -ENOSYS; /* Pop the last cursor position off the stack */ - pos = &priv->pos[--priv->pos_ptr]; + pos = &ctx->pos[--ctx->pos_ptr]; /* * Figure out the end position for clearing. Normally it is the current @@ -713,10 +718,11 @@ static int console_truetype_entry_start(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; /* A new input line has start, so clear our history */ - priv->pos_ptr = 0; - priv->pos_count = 0; + ctx->pos_ptr = 0; + ctx->pos_count = 0; vc_priv->last_ch = 0; return 0; @@ -1199,6 +1205,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; struct console_tt_store store; if (xpl_phase() <= PHASE_SPL) @@ -1208,11 +1215,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) vc_priv->xcur_frac = store.cur.xpos_frac; vc_priv->ycur = store.cur.ypos; - priv->pos_ptr = store.priv.pos_ptr; - priv->pos_start = store.priv.pos_start; - priv->pos_count = store.priv.pos_count; - memcpy(priv->pos, store.priv.pos, - store.priv.pos_ptr * sizeof(struct pos_info)); + *ctx = store.priv.ctx; return 0; } @@ -1221,6 +1224,7 @@ static int truetype_get_cursor_info(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; struct vidconsole_cursor *curs = &vc_priv->curs; int x, y, index; uint height; @@ -1235,11 +1239,11 @@ static int truetype_get_cursor_info(struct udevice *dev) * * A current quirk is that the cursor is always at xcur_frac, since we * output characters directly to the console as they are typed by the - * user. So we never bother with priv->pos[index] for now. + * user. So we never bother with ctx->pos[index] for now. */ - index = priv->pos_ptr; - if (0 && index < priv->pos_count) - x = VID_TO_PIXEL(priv->pos[index].xpos_frac); + index = ctx->pos_ptr; + if (0 && index < ctx->pos_count) + x = VID_TO_PIXEL(ctx->pos[index].xpos_frac); else x = VID_TO_PIXEL(vc_priv->xcur_frac); y = vc_priv->ycur; @@ -1279,8 +1283,9 @@ const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep) static int truetype_mark_start(struct udevice *dev) { struct console_tt_priv *priv = dev_get_priv(dev); + struct console_tt_ctx *ctx = &priv->ctx; - priv->pos_start = priv->pos_ptr; + ctx->pos_start = ctx->pos_ptr; return 0; } -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Add a function which returns the default context for a vidconsole. Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/vidconsole-uclass.c | 7 +++++++ include/video_console.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 8ef9f4c90d6..e282c3de557 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -1015,3 +1015,10 @@ void vidconsole_readline_end(void) } } #endif /* CURSOR */ + +void *vidconsole_ctx(struct udevice *dev) +{ + struct vidconsole_priv *uc_priv = dev_get_uclass_priv(dev); + + return &uc_priv->ctx; +} diff --git a/include/video_console.h b/include/video_console.h index adc4537ceb7..d7e74f71171 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -121,6 +121,7 @@ struct vidconsole_ctx { */ struct vidconsole_priv { struct stdio_dev sdev; + struct vidconsole_ctx ctx; int xcur_frac; int ycur; int rows; @@ -421,6 +422,25 @@ struct vidconsole_ops { /* Get a pointer to the driver operations for a video console device */ #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) +/** + * vidconsole_ctx() - Get the default context for a vidconsole device + * + * @dev: vidconsole device to check + * Return: pointer to context + */ +void *vidconsole_ctx(struct udevice *dev); + +/** + * vidconsole_ctx_from_priv() - Get the default context for a vidconsole device + * + * @priv: vidconsole uclass-private data + * Return: pointer to context + */ +static inline void *vidconsole_ctx_from_priv(struct vidconsole_priv *uc_priv) +{ + return &uc_priv->ctx; +} + /** * vidconsole_get_font() - Obtain information about a font * -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the rows and cols fields from vidconsole_priv into the new vidconsole_ctx struct. This is preparation for supporting multiple clients with their own context. Use a local ctx pointer in each function that accesses these fields. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- common/console.c | 6 +++--- drivers/video/console_normal.c | 5 +++-- drivers/video/console_truetype.c | 5 +++-- drivers/video/vidconsole-uclass.c | 27 +++++++++++++++------------ include/video_console.h | 14 ++++++++------ lib/efi_loader/efi_console.c | 10 +++++----- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/common/console.c b/common/console.c index da1125cfa98..9273ed7d8e2 100644 --- a/common/console.c +++ b/common/console.c @@ -494,10 +494,10 @@ int calc_check_console_lines(void) dev = sdev_file_has_uclass(stdout, UCLASS_VIDEO_CONSOLE); if (dev) { - struct vidconsole_priv *priv; + struct vidconsole_ctx *ctx; - priv = dev_get_uclass_priv(dev); - dev_lines = priv->rows; + ctx = vidconsole_ctx(dev); + dev_lines = ctx->rows; } } /* get number of lines from the serial console, if available */ diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index f6dc37bc6be..5417612f9de 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -95,6 +95,7 @@ int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) static __maybe_unused int console_get_cursor_info(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct console_simple_priv *priv = dev_get_priv(dev); struct video_fontdata *fontdata = priv->fontdata; struct vidconsole_cursor *curs = &vc_priv->curs; @@ -112,7 +113,7 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) xpos = (x + vc_priv->x_charsize - 1) / vc_priv->x_charsize; /* number of characters which can fit on this (first) line */ - xspace = vc_priv->cols - xpos; + xspace = ctx->cols - xpos; if (!curs->indent && index > xspace) { /* move to the next line */ @@ -121,7 +122,7 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) /* figure out the available space in subsequent lines */ if (!curs->indent) { - xspace = vc_priv->cols; + xspace = ctx->cols; x = 0; } diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index f55c56671e2..f241761bbbc 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -932,6 +932,7 @@ static void set_bitmap_font(struct udevice *dev, static void select_metrics(struct udevice *dev, struct console_tt_metrics *met) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct udevice *vid_dev = dev_get_parent(dev); struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); @@ -940,8 +941,8 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met) vc_priv->x_charsize = met->font_size; vc_priv->y_charsize = met->font_size; vc_priv->xstart_frac = VID_TO_POS(2); - vc_priv->cols = vid_priv->xsize / met->font_size; - vc_priv->rows = vid_priv->ysize / met->font_size; + ctx->cols = vid_priv->xsize / met->font_size; + ctx->rows = vid_priv->ysize / met->font_size; vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2; } diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index e282c3de557..28c9e88cbb6 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -63,6 +63,7 @@ int vidconsole_entry_start(struct udevice *dev) static int vidconsole_back(struct udevice *dev) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct vidconsole_ops *ops = vidconsole_get_ops(dev); int ret; @@ -77,7 +78,7 @@ static int vidconsole_back(struct udevice *dev) priv->xcur_frac -= VID_TO_POS(priv->x_charsize); if (priv->xcur_frac < priv->xstart_frac) { - priv->xcur_frac = (priv->cols - 1) * + priv->xcur_frac = (ctx->cols - 1) * VID_TO_POS(priv->x_charsize); priv->ycur -= priv->y_charsize; if (priv->ycur < 0) @@ -93,6 +94,7 @@ static int vidconsole_back(struct udevice *dev) static void vidconsole_newline(struct udevice *dev) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct udevice *vid_dev = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES); @@ -105,9 +107,9 @@ static void vidconsole_newline(struct udevice *dev) if (vid_priv->rot % 2 ? priv->ycur + priv->x_charsize > vid_priv->xsize : priv->ycur + priv->y_charsize > vid_priv->ysize) { - vidconsole_move_rows(dev, 0, rows, priv->rows - rows); + vidconsole_move_rows(dev, 0, rows, ctx->rows - rows); for (i = 0; i < rows; i++) - vidconsole_set_row(dev, priv->rows - i - 1, + vidconsole_set_row(dev, ctx->rows - i - 1, vid_priv->colour_bg); priv->ycur -= rows * priv->y_charsize; } @@ -153,15 +155,15 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y) */ static void set_cursor_position(struct udevice *dev, int row, int col) { - struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx(dev); /* * Ensure we stay in the bounds of the screen. */ - if (row >= priv->rows) - row = priv->rows - 1; - if (col >= priv->cols) - col = priv->cols - 1; + if (row >= ctx->rows) + row = ctx->rows - 1; + if (col >= ctx->cols) + col = ctx->cols - 1; vidconsole_position_cursor(dev, col, row); } @@ -951,6 +953,7 @@ void vidconsole_set_bitmap_font(struct udevice *dev, struct video_fontdata *fontdata) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); log_debug("console_simple: setting %s font\n", fontdata->name); @@ -961,12 +964,12 @@ void vidconsole_set_bitmap_font(struct udevice *dev, vc_priv->x_charsize = fontdata->width; vc_priv->y_charsize = fontdata->height; if (vid_priv->rot % 2) { - vc_priv->cols = vid_priv->ysize / fontdata->width; - vc_priv->rows = vid_priv->xsize / fontdata->height; + ctx->cols = vid_priv->ysize / fontdata->width; + ctx->rows = vid_priv->xsize / fontdata->height; vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize); } else { - vc_priv->cols = vid_priv->xsize / fontdata->width; - vc_priv->rows = vid_priv->ysize / fontdata->height; + ctx->cols = vid_priv->xsize / fontdata->width; + ctx->rows = vid_priv->ysize / fontdata->height; /* xsize_frac is set in vidconsole_pre_probe() */ } vc_priv->xstart_frac = 0; diff --git a/include/video_console.h b/include/video_console.h index d7e74f71171..ec07c4e2286 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -78,15 +78,20 @@ struct vidconsole_cursor { * * This holds per-client state for video consoles. It can be used by clients * to maintain separate contexts for different text-entry operations. + * + * @rows: Number of text rows + * @cols: Number of text columns */ struct vidconsole_ctx { + int rows; + int cols; }; /** * struct vidconsole_priv - uclass-private data about a console device * - * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() - * method. Drivers may set up @xstart_frac if desired. + * Drivers must set up @ctx.rows, @ctx.cols, @x_charsize, @y_charsize in their + * probe() method. Drivers may set up @xstart_frac if desired. * * Note that these values relate to the rotated console, so that an 80x25 * console which is rotated 90 degrees will have rows=80 and cols=25 @@ -99,8 +104,7 @@ struct vidconsole_ctx { * @sdev: stdio device, acting as an output sink * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) * @ycur: Current Y position in pixels (0=top) - * @rows: Number of text rows - * @cols: Number of text columns + * @ctx: Per-client context * @x_charsize: Character width in pixels * @y_charsize: Character height in pixels * @tab_width_frac: Tab width in fractional units @@ -124,8 +128,6 @@ struct vidconsole_priv { struct vidconsole_ctx ctx; int xcur_frac; int ycur; - int rows; - int cols; int x_charsize; int y_charsize; int tab_width_frac; diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index d2eabfdb07e..7deaef81ecb 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -213,7 +213,7 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols) const char *stdout_name = env_get("stdout"); struct stdio_dev *stdout_dev; struct udevice *dev; - struct vidconsole_priv *priv; + struct vidconsole_ctx *ctx; if (!stdout_name || strncmp(stdout_name, "vidconsole", 10)) return -ENODEV; @@ -223,11 +223,11 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols) dev = stdout_dev->priv; if (!dev) return -ENODEV; - priv = dev_get_uclass_priv(dev); - if (!priv) + ctx = vidconsole_ctx(dev); + if (!ctx) return -ENODEV; - *rows = priv->rows; - *cols = priv->cols; + *rows = ctx->rows; + *cols = ctx->cols; return 0; } -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the x_charsize and y_charsize fields from vidconsole_priv into vidconsole_ctx. This continues the refactoring to support multiple clients with their own context. Use a local ctx pointer (or vc_ctx where ctx is already used for the driver's context) in each function that accesses these fields. 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 | 3 +- boot/expo_test.c | 10 +++---- drivers/video/console_core.c | 3 +- drivers/video/console_normal.c | 6 ++-- drivers/video/console_rotate.c | 9 ++++-- drivers/video/console_truetype.c | 29 ++++++++++--------- drivers/video/vidconsole-uclass.c | 45 ++++++++++++++++-------------- drivers/video/video-uclass.c | 4 +-- include/video_console.h | 16 +++++------ 9 files changed, 68 insertions(+), 57 deletions(-) diff --git a/board/atmel/common/video_display.c b/board/atmel/common/video_display.c index 77188820581..4d6ac3a740e 100644 --- a/board/atmel/common/video_display.c +++ b/board/atmel/common/video_display.c @@ -68,7 +68,8 @@ int at91_video_show_board_info(void) priv = dev_get_uclass_priv(con); vidconsole_position_cursor(con, 0, (logo_info.logo_height + - priv->y_charsize - 1) / priv->y_charsize); + priv->ctx.y_charsize - 1) / + priv->ctx.y_charsize); for (s = buf, i = 0; i < len; s++, i++) vidconsole_put_char(con, *s); diff --git a/boot/expo_test.c b/boot/expo_test.c index 3ddeb86fb2c..a905b144745 100644 --- a/boot/expo_test.c +++ b/boot/expo_test.c @@ -176,7 +176,7 @@ int expo_test_render(struct expo *exp) /* Display frame count */ snprintf(buf, sizeof(buf), "frame %6d", test->render_count); - x = vid_priv->xsize - 18 * cons_priv->x_charsize; + x = vid_priv->xsize - 18 * cons_priv->ctx.x_charsize; y = 10; vidconsole_set_cursor_pos(exp->cons, x, y); vidconsole_put_string(exp->cons, buf); @@ -184,7 +184,7 @@ int expo_test_render(struct expo *exp) /* Display FPS on next line (only if non-zero) */ if (test->fps_last > 0) { snprintf(buf, sizeof(buf), "fps %6d", test->fps_last); - y += cons_priv->y_charsize; + y += cons_priv->ctx.y_charsize; vidconsole_set_cursor_pos(exp->cons, x, y); vidconsole_put_string(exp->cons, buf); } @@ -193,7 +193,7 @@ int expo_test_render(struct expo *exp) snprintf(buf, sizeof(buf), "render %6lu.%01lums", test->render_avg_us / 1000, (test->render_avg_us % 1000) / 100); - y += cons_priv->y_charsize; + y += cons_priv->ctx.y_charsize; vidconsole_set_cursor_pos(exp->cons, x, y); vidconsole_put_string(exp->cons, buf); @@ -201,7 +201,7 @@ int expo_test_render(struct expo *exp) snprintf(buf, sizeof(buf), "sync %6lu.%01lums", test->sync_avg_us / 1000, (test->sync_avg_us % 1000) / 100); - y += cons_priv->y_charsize; + y += cons_priv->ctx.y_charsize; vidconsole_set_cursor_pos(exp->cons, x, y); vidconsole_put_string(exp->cons, buf); @@ -209,7 +209,7 @@ int expo_test_render(struct expo *exp) snprintf(buf, sizeof(buf), "poll %6lu.%01lums", test->poll_avg_us / 1000, (test->poll_avg_us % 1000) / 100); - y += cons_priv->y_charsize; + y += cons_priv->ctx.y_charsize; vidconsole_set_cursor_pos(exp->cons, x, y); vidconsole_put_string(exp->cons, buf); diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c index 3f3efb94ab1..9cf5831b562 100644 --- a/drivers/video/console_core.c +++ b/drivers/video/console_core.c @@ -340,6 +340,7 @@ int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, struct video_fontdata *fontdata) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); int pbytes = VNBYTES(vid_priv->bpix); @@ -349,7 +350,7 @@ int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, uchar *pfont = fontdata->video_fontdata + ch * fontdata->char_pixel_bytes; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + if (x_frac + VID_TO_POS(ctx->x_charsize) > vc_priv->xsize_frac) return -EAGAIN; linenum = y; x = VID_TO_PIXEL(x_frac); diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 5417612f9de..cc0ac79a924 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -110,14 +110,14 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) index = vc_priv->cli_index; /* rounded up character position in this line */ - xpos = (x + vc_priv->x_charsize - 1) / vc_priv->x_charsize; + xpos = (x + ctx->x_charsize - 1) / ctx->x_charsize; /* number of characters which can fit on this (first) line */ xspace = ctx->cols - xpos; if (!curs->indent && index > xspace) { /* move to the next line */ - y += vc_priv->y_charsize; + y += ctx->y_charsize; index -= xspace; /* figure out the available space in subsequent lines */ @@ -140,7 +140,7 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) /* Store line pointer and height in cursor struct */ curs->x = x; curs->y = y; - curs->height = vc_priv->y_charsize; + curs->height = ctx->y_charsize; curs->index = vc_priv->cli_index; return 0; diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c index 886b25dcfaf..85c571accd4 100644 --- a/drivers/video/console_rotate.c +++ b/drivers/video/console_rotate.c @@ -75,6 +75,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc, static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); @@ -86,7 +87,7 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp) uchar *pfont = fontdata->video_fontdata + ch * fontdata->char_pixel_bytes; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + if (x_frac + VID_TO_POS(ctx->x_charsize) > vc_priv->xsize_frac) return -EAGAIN; linenum = VID_TO_PIXEL(x_frac) + 1; x = y + 1; @@ -163,6 +164,7 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc, static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); @@ -174,7 +176,7 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp) uchar *pfont = fontdata->video_fontdata + ch * fontdata->char_pixel_bytes; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + if (x_frac + VID_TO_POS(ctx->x_charsize) > vc_priv->xsize_frac) return -EAGAIN; linenum = vid_priv->ysize - y - 1; x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - 1; @@ -253,6 +255,7 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc, static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); @@ -264,7 +267,7 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp) uchar *pfont = fontdata->video_fontdata + ch * fontdata->char_pixel_bytes; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + if (x_frac + VID_TO_POS(ctx->x_charsize) > vc_priv->xsize_frac) return -EAGAIN; x = y; linenum = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1; diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index f241761bbbc..62a3f501958 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -266,7 +266,7 @@ struct console_tt_store { static int console_truetype_set_row(struct udevice *dev, uint row, int clr) { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx(dev); struct console_tt_priv *priv = dev_get_priv(dev); void *end, *line; int font_height; @@ -314,9 +314,9 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr) video_damage(dev->parent, 0, - vc_priv->y_charsize * row, + vc_ctx->y_charsize * row, vid_priv->xsize, - vc_priv->y_charsize); + vc_ctx->y_charsize); return 0; } @@ -325,7 +325,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, uint count) { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx(dev); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; void *dst; @@ -349,9 +349,9 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst, video_damage(dev->parent, 0, - vc_priv->y_charsize * rowdst, + vc_ctx->y_charsize * rowdst, vid_priv->xsize, - vc_priv->y_charsize * count); + vc_ctx->y_charsize * count); return 0; } @@ -369,6 +369,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst, static void clear_from(struct udevice *dev, int index) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; struct udevice *vid_dev = dev->parent; @@ -390,21 +391,23 @@ static void clear_from(struct udevice *dev, int index) /* If on the same line, just erase from start to end position */ if (ystart == yend) { - video_fill_part(vid_dev, xstart, ystart, xend, ystart + vc_priv->y_charsize, + video_fill_part(vid_dev, xstart, ystart, xend, + ystart + vc_ctx->y_charsize, vid_priv->colour_bg); } else { /* Different lines - erase to end of first line */ video_fill_part(vid_dev, xstart, ystart, vid_priv->xsize, - ystart + vc_priv->y_charsize, vid_priv->colour_bg); + ystart + vc_ctx->y_charsize, vid_priv->colour_bg); /* Erase any complete lines in between */ - if (yend > ystart + vc_priv->y_charsize) { - video_fill_part(vid_dev, 0, ystart + vc_priv->y_charsize, + if (yend > ystart + vc_ctx->y_charsize) { + video_fill_part(vid_dev, 0, ystart + vc_ctx->y_charsize, vid_priv->xsize, yend, vid_priv->colour_bg); } /* Erase from start of final line to end of last character */ - video_fill_part(vid_dev, 0, yend, xend, yend + vc_priv->y_charsize, + video_fill_part(vid_dev, 0, yend, xend, + yend + vc_ctx->y_charsize, vid_priv->colour_bg); } } @@ -938,8 +941,8 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met) struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); priv->cur_met = met; - vc_priv->x_charsize = met->font_size; - vc_priv->y_charsize = met->font_size; + ctx->x_charsize = met->font_size; + ctx->y_charsize = met->font_size; vc_priv->xstart_frac = VID_TO_POS(2); ctx->cols = vid_priv->xsize / met->font_size; ctx->rows = vid_priv->ysize / met->font_size; diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 28c9e88cbb6..71bcac4288e 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -76,11 +76,11 @@ static int vidconsole_back(struct udevice *dev) /* Hide cursor at old position if it's visible */ vidconsole_hide_cursor(dev); - priv->xcur_frac -= VID_TO_POS(priv->x_charsize); + priv->xcur_frac -= VID_TO_POS(ctx->x_charsize); if (priv->xcur_frac < priv->xstart_frac) { priv->xcur_frac = (ctx->cols - 1) * - VID_TO_POS(priv->x_charsize); - priv->ycur -= priv->y_charsize; + VID_TO_POS(ctx->x_charsize); + priv->ycur -= ctx->y_charsize; if (priv->ycur < 0) priv->ycur = 0; } @@ -101,17 +101,17 @@ static void vidconsole_newline(struct udevice *dev) int i, ret; priv->xcur_frac = priv->xstart_frac; - priv->ycur += priv->y_charsize; + priv->ycur += ctx->y_charsize; /* Check if we need to scroll the terminal */ if (vid_priv->rot % 2 ? - priv->ycur + priv->x_charsize > vid_priv->xsize : - priv->ycur + priv->y_charsize > vid_priv->ysize) { + priv->ycur + ctx->x_charsize > vid_priv->xsize : + priv->ycur + ctx->y_charsize > vid_priv->ysize) { vidconsole_move_rows(dev, 0, rows, ctx->rows - rows); for (i = 0; i < rows; i++) vidconsole_set_row(dev, ctx->rows - i - 1, vid_priv->colour_bg); - priv->ycur -= rows * priv->y_charsize; + priv->ycur -= rows * ctx->y_charsize; } priv->last_ch = 0; @@ -178,9 +178,11 @@ static void set_cursor_position(struct udevice *dev, int row, int col) static void get_cursor_position(struct vidconsole_priv *priv, int *row, int *col) { - *row = priv->ycur / priv->y_charsize; + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); + + *row = priv->ycur / ctx->y_charsize; *col = VID_TO_PIXEL(priv->xcur_frac - priv->xstart_frac) / - priv->x_charsize; + ctx->x_charsize; } /* @@ -649,7 +651,7 @@ int vidconsole_measure(struct udevice *dev, const char *name, uint size, const char *text, int limit, struct vidconsole_bbox *bbox, struct alist *lines) { - struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx(dev); struct vidconsole_ops *ops = vidconsole_get_ops(dev); int ret; @@ -664,8 +666,8 @@ int vidconsole_measure(struct udevice *dev, const char *name, uint size, bbox->valid = true; bbox->x0 = 0; bbox->y0 = 0; - bbox->x1 = priv->x_charsize * strlen(text); - bbox->y1 = priv->y_charsize; + bbox->x1 = ctx->x_charsize * strlen(text); + bbox->y1 = ctx->y_charsize; return 0; } @@ -673,7 +675,7 @@ int vidconsole_measure(struct udevice *dev, const char *name, uint size, int vidconsole_nominal(struct udevice *dev, const char *name, uint size, uint num_chars, struct vidconsole_bbox *bbox) { - struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx(dev); struct vidconsole_ops *ops = vidconsole_get_ops(dev); int ret; @@ -686,8 +688,8 @@ int vidconsole_nominal(struct udevice *dev, const char *name, uint size, bbox->valid = true; bbox->x0 = 0; bbox->y0 = 0; - bbox->x1 = priv->x_charsize * num_chars; - bbox->y1 = priv->y_charsize; + bbox->x1 = ctx->x_charsize * num_chars; + bbox->y1 = ctx->y_charsize; return 0; } @@ -880,10 +882,11 @@ static int vidconsole_pre_probe(struct udevice *dev) static int vidconsole_post_probe(struct udevice *dev) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct stdio_dev *sdev = &priv->sdev; if (!priv->tab_width_frac) - priv->tab_width_frac = VID_TO_POS(priv->x_charsize) * 8; + priv->tab_width_frac = VID_TO_POS(ctx->x_charsize) * 8; if (dev_seq(dev)) { snprintf(sdev->name, sizeof(sdev->name), "vidconsole%d", @@ -932,13 +935,13 @@ int vidconsole_clear_and_reset(struct udevice *dev) void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row) { - struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx(dev); struct udevice *vid_dev = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); short x, y; - x = min_t(short, col * priv->x_charsize, vid_priv->xsize - 1); - y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1); + x = min_t(short, col * ctx->x_charsize, vid_priv->xsize - 1); + y = min_t(short, row * ctx->y_charsize, vid_priv->ysize - 1); vidconsole_set_cursor_pos(dev, x, y); } @@ -961,8 +964,8 @@ void vidconsole_set_bitmap_font(struct udevice *dev, log_debug("byte width: %d\n", fontdata->byte_width); log_debug("height: %d\n", fontdata->height); - vc_priv->x_charsize = fontdata->width; - vc_priv->y_charsize = fontdata->height; + ctx->x_charsize = fontdata->width; + ctx->y_charsize = fontdata->height; if (vid_priv->rot % 2) { ctx->cols = vid_priv->ysize / fontdata->width; ctx->rows = vid_priv->xsize / fontdata->height; diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 75b13481380..5dd6df8468e 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -665,13 +665,13 @@ static int show_splash(struct udevice *dev) int video_default_font_height(struct udevice *dev) { - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx(dev); if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE, CONFIG_CONSOLE_TRUETYPE_SIZE); - return vc_priv->y_charsize; + return ctx->y_charsize; } static void video_idle(struct cyclic_info *cyc) diff --git a/include/video_console.h b/include/video_console.h index ec07c4e2286..0d0e6edbfb7 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -79,19 +79,23 @@ struct vidconsole_cursor { * This holds per-client state for video consoles. It can be used by clients * to maintain separate contexts for different text-entry operations. * - * @rows: Number of text rows - * @cols: Number of text columns + * @rows: Number of text rows + * @cols: Number of text columns + * @x_charsize: Character width in pixels + * @y_charsize: Character height in pixels */ struct vidconsole_ctx { int rows; int cols; + int x_charsize; + int y_charsize; }; /** * struct vidconsole_priv - uclass-private data about a console device * - * Drivers must set up @ctx.rows, @ctx.cols, @x_charsize, @y_charsize in their - * probe() method. Drivers may set up @xstart_frac if desired. + * Drivers must set up @ctx.rows, @ctx.cols, @ctx.x_charsize, @ctx.y_charsize + * in their probe() method. Drivers may set up @xstart_frac if desired. * * Note that these values relate to the rotated console, so that an 80x25 * console which is rotated 90 degrees will have rows=80 and cols=25 @@ -105,8 +109,6 @@ struct vidconsole_ctx { * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) * @ycur: Current Y position in pixels (0=top) * @ctx: Per-client context - * @x_charsize: Character width in pixels - * @y_charsize: Character height in pixels * @tab_width_frac: Tab width in fractional units * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units @@ -128,8 +130,6 @@ struct vidconsole_priv { struct vidconsole_ctx ctx; int xcur_frac; int ycur; - int x_charsize; - int y_charsize; int tab_width_frac; int xsize_frac; int xstart_frac; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> The ANSI escape-sequence state in struct vidconsole_priv is related and can be grouped together. Create a new struct vidconsole_ansi to hold these fields and update vidconsole-uclass.c to use a local pointer variable for cleaner access. Move escape, escape_len, row_saved, col_saved, and escape_buf into the new struct. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/vidconsole-uclass.c | 44 ++++++++++++++++--------------- include/video_console.h | 38 +++++++++++++++----------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 71bcac4288e..ddcf2e87b6b 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -193,29 +193,30 @@ static void get_cursor_position(struct vidconsole_priv *priv, static void vidconsole_escape_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ansi *ansi = &priv->ansi; if (!IS_ENABLED(CONFIG_VIDEO_ANSI)) goto error; /* Sanity checking for bogus ESC sequences: */ - if (priv->escape_len >= sizeof(priv->escape_buf)) + if (ansi->escape_len >= sizeof(ansi->escape_buf)) goto error; - if (priv->escape_len == 0) { + if (ansi->escape_len == 0) { switch (ch) { case '7': /* Save cursor position */ - get_cursor_position(priv, &priv->row_saved, - &priv->col_saved); - priv->escape = 0; + get_cursor_position(priv, &ansi->row_saved, + &ansi->col_saved); + ansi->escape = 0; return; case '8': { /* Restore cursor position */ - int row = priv->row_saved; - int col = priv->col_saved; + int row = ansi->row_saved; + int col = ansi->col_saved; set_cursor_position(dev, row, col); - priv->escape = 0; + ansi->escape = 0; return; } case '[': @@ -225,7 +226,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } } - priv->escape_buf[priv->escape_len++] = ch; + ansi->escape_buf[ansi->escape_len++] = ch; /* * Escape sequences are terminated by a letter, so keep @@ -239,7 +240,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * surprising if you hit any debug prints that come back to * this console. */ - priv->escape = 0; + ansi->escape = 0; switch (ch) { case 'A': @@ -249,7 +250,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) case 'E': case 'F': { int row, col, num; - char *s = priv->escape_buf; + char *s = ansi->escape_buf; /* * Cursor up/down: [%dA, [%dB, [%dE, [%dF @@ -282,7 +283,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) case 'H': case 'f': { int row, col; - char *s = priv->escape_buf; + char *s = ansi->escape_buf; /* * Set cursor position: [%d;%df or [%d;%dH @@ -317,7 +318,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * probably require some additions to video-uclass (and * are not really needed yet by efi_console) */ - parsenum(priv->escape_buf + 1, &mode); + parsenum(ansi->escape_buf + 1, &mode); if (mode == 2) { int ret; @@ -345,7 +346,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * [0K - clear line to end * [2K - clear entire line */ - parsenum(priv->escape_buf + 1, &mode); + parsenum(ansi->escape_buf + 1, &mode); if (mode == 2) { int row, col; @@ -357,8 +358,8 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } case 'm': { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - char *s = priv->escape_buf; - char *end = &priv->escape_buf[priv->escape_len]; + char *s = ansi->escape_buf; + char *end = &ansi->escape_buf[ansi->escape_len]; /* * Set graphics mode: [%d;...;%dm @@ -437,14 +438,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } default: debug("unrecognized escape sequence: %*s\n", - priv->escape_len, priv->escape_buf); + ansi->escape_len, ansi->escape_buf); } return; error: /* something went wrong, just revert to normal mode: */ - priv->escape = 0; + ansi->escape = 0; } /* Put that actual character on the screen (using the UTF-32 code points). */ @@ -482,20 +483,21 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ansi *ansi = &priv->ansi; int cp, ret; /* Hide cursor to avoid artifacts */ vidconsole_hide_cursor(dev); - if (priv->escape) { + if (ansi->escape) { vidconsole_escape_char(dev, ch); return 0; } switch (ch) { case '\x1b': - priv->escape_len = 0; - priv->escape = 1; + ansi->escape_len = 0; + ansi->escape = 1; break; case '\a': /* beep */ diff --git a/include/video_console.h b/include/video_console.h index 0d0e6edbfb7..6f74f64cddf 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -91,6 +91,27 @@ struct vidconsole_ctx { int y_charsize; }; +/** + * struct vidconsole_ansi - ANSI escape-sequence state + * + * ANSI escape sequences are accumulated character by character, starting after + * the ESC char (0x1b) until the entire sequence is consumed, at which point it + * is acted upon. + * + * @escape: True if currently accumulating an ANSI escape sequence + * @escape_len: Length of accumulated escape sequence so far + * @row_saved: Saved Y position in pixels (0=top) + * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) + * @escape_buf: Buffer to accumulate escape sequence + */ +struct vidconsole_ansi { + int escape; + int escape_len; + int row_saved; + int col_saved; + char escape_buf[32]; +}; + /** * struct vidconsole_priv - uclass-private data about a console device * @@ -116,11 +137,7 @@ struct vidconsole_ctx { * @xmark_frac: X position of start of CLI text entry, in fractional units * @ymark: Y position of start of CLI text * @cli_index: Character index into the CLI text (0=start) - * @escape: TRUE if currently accumulating an ANSI escape sequence - * @escape_len: Length of accumulated escape sequence so far - * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) - * @row_saved: Saved Y position in pixels (0=top) - * @escape_buf: Buffer to accumulate escape sequence + * @ansi: ANSI escape-sequence state * @utf8_buf: Buffer to accumulate UTF-8 byte sequence * @quiet: Suppress all output from stdio * @curs: Cursor state and management @@ -137,16 +154,7 @@ struct vidconsole_priv { int xmark_frac; int ymark; int cli_index; - /* - * ANSI escape sequences are accumulated character by character, - * starting after the ESC char (0x1b) until the entire sequence - * is consumed at which point it is acted upon. - */ - int escape; - int escape_len; - int row_saved; - int col_saved; - char escape_buf[32]; + struct vidconsole_ansi ansi; char utf8_buf[5]; bool quiet; struct vidconsole_cursor curs; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the xcur_frac field from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. This allows each client to maintain its own cursor X position. Update all files that access xcur_frac to use the ctx pointer: vidconsole-uclass.c, console_normal.c, and console_truetype.c. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 6 +++-- drivers/video/console_truetype.c | 17 +++++++++----- drivers/video/vidconsole-uclass.c | 37 ++++++++++++++++++------------- include/video_console.h | 12 +++++----- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index cc0ac79a924..0aadd8bc96f 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -150,6 +150,7 @@ static __maybe_unused int normal_entry_save(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct console_store store; const uint size = sizeof(store); @@ -159,7 +160,7 @@ static __maybe_unused int normal_entry_save(struct udevice *dev, if (!abuf_realloc(buf, size)) return log_msg_ret("sav", -ENOMEM); - store.xpos_frac = vc_priv->xcur_frac; + store.xpos_frac = ctx->xcur_frac; store.ypos = vc_priv->ycur; store.cli_index = vc_priv->cli_index; memcpy(abuf_data(buf), &store, size); @@ -171,6 +172,7 @@ static __maybe_unused int normal_entry_restore(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv); struct console_store store; if (xpl_phase() <= PHASE_SPL) @@ -178,7 +180,7 @@ static __maybe_unused int normal_entry_restore(struct udevice *dev, memcpy(&store, abuf_data(buf), sizeof(store)); - vc_priv->xcur_frac = store.xpos_frac; + ctx->xcur_frac = store.xpos_frac; vc_priv->ycur = store.ypos; vc_priv->cli_index = store.cli_index; diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 62a3f501958..386e9aa8a59 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -416,6 +416,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, int cp) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_tt_priv *priv = dev_get_priv(dev); @@ -495,7 +496,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, } pos = &ctx->pos[ctx->pos_ptr]; - pos->xpos_frac = vc_priv->xcur_frac; + pos->xpos_frac = vc_ctx->xcur_frac; pos->ypos = vc_priv->ycur; pos->width = (width_frac + VID_FRAC_DIV - 1) / VID_FRAC_DIV; pos->cp = cp; @@ -683,6 +684,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, static int console_truetype_backspace(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; struct udevice *vid_dev = dev->parent; @@ -706,12 +708,12 @@ static int console_truetype_backspace(struct udevice *dev) * line, we clear from the end of the line. */ if (pos->ypos == vc_priv->ycur) - xend = VID_TO_PIXEL(vc_priv->xcur_frac); + xend = VID_TO_PIXEL(vc_ctx->xcur_frac); else xend = vid_priv->xsize; /* Move the cursor back to where it was when we pushed this record */ - vc_priv->xcur_frac = pos->xpos_frac; + vc_ctx->xcur_frac = pos->xpos_frac; vc_priv->ycur = pos->ypos; return 0; @@ -1183,6 +1185,7 @@ static int truetype_ctx_dispose(struct udevice *dev, void *ctx) static int truetype_entry_save(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_store store; const uint size = sizeof(store); @@ -1198,7 +1201,7 @@ static int truetype_entry_save(struct udevice *dev, struct abuf *buf) return log_msg_ret("sav", -ENOMEM); store.priv = *priv; - store.cur.xpos_frac = vc_priv->xcur_frac; + store.cur.xpos_frac = vc_ctx->xcur_frac; store.cur.ypos = vc_priv->ycur; memcpy(abuf_data(buf), &store, size); @@ -1208,6 +1211,7 @@ static int truetype_entry_save(struct udevice *dev, struct abuf *buf) static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; struct console_tt_store store; @@ -1217,7 +1221,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) memcpy(&store, abuf_data(buf), sizeof(store)); - vc_priv->xcur_frac = store.cur.xpos_frac; + vc_ctx->xcur_frac = store.cur.xpos_frac; vc_priv->ycur = store.cur.ypos; *ctx = store.priv.ctx; @@ -1227,6 +1231,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) static int truetype_get_cursor_info(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; struct vidconsole_cursor *curs = &vc_priv->curs; @@ -1249,7 +1254,7 @@ static int truetype_get_cursor_info(struct udevice *dev) if (0 && index < ctx->pos_count) x = VID_TO_PIXEL(ctx->pos[index].xpos_frac); else - x = VID_TO_PIXEL(vc_priv->xcur_frac); + x = VID_TO_PIXEL(vc_ctx->xcur_frac); y = vc_priv->ycur; /* Get font height from current font type */ diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index ddcf2e87b6b..8bc2384dd7a 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -76,9 +76,9 @@ static int vidconsole_back(struct udevice *dev) /* Hide cursor at old position if it's visible */ vidconsole_hide_cursor(dev); - priv->xcur_frac -= VID_TO_POS(ctx->x_charsize); - if (priv->xcur_frac < priv->xstart_frac) { - priv->xcur_frac = (ctx->cols - 1) * + ctx->xcur_frac -= VID_TO_POS(ctx->x_charsize); + if (ctx->xcur_frac < priv->xstart_frac) { + ctx->xcur_frac = (ctx->cols - 1) * VID_TO_POS(ctx->x_charsize); priv->ycur -= ctx->y_charsize; if (priv->ycur < 0) @@ -100,7 +100,7 @@ static void vidconsole_newline(struct udevice *dev) const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES); int i, ret; - priv->xcur_frac = priv->xstart_frac; + ctx->xcur_frac = priv->xstart_frac; priv->ycur += ctx->y_charsize; /* Check if we need to scroll the terminal */ @@ -133,12 +133,13 @@ static char *parsenum(char *s, int *num) void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); /* Hide cursor at old position if it's visible */ vidconsole_hide_cursor(dev); - priv->xcur_frac = VID_TO_POS(x); - priv->xstart_frac = priv->xcur_frac; + ctx->xcur_frac = VID_TO_POS(x); + priv->xstart_frac = ctx->xcur_frac; priv->ycur = y; /* make sure not to kern against the previous character */ @@ -181,7 +182,7 @@ static void get_cursor_position(struct vidconsole_priv *priv, struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); *row = priv->ycur / ctx->y_charsize; - *col = VID_TO_PIXEL(priv->xcur_frac - priv->xstart_frac) / + *col = VID_TO_PIXEL(ctx->xcur_frac - priv->xstart_frac) / ctx->x_charsize; } @@ -193,6 +194,7 @@ static void get_cursor_position(struct vidconsole_priv *priv, static void vidconsole_escape_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct vidconsole_ansi *ansi = &priv->ansi; if (!IS_ENABLED(CONFIG_VIDEO_ANSI)) @@ -331,7 +333,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) #endif } priv->ycur = 0; - priv->xcur_frac = priv->xstart_frac; + ctx->xcur_frac = priv->xstart_frac; } else { debug("unsupported clear mode: %d\n", mode); } @@ -452,6 +454,7 @@ error: static int vidconsole_output_glyph(struct udevice *dev, int ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); int ret; if (_DEBUG) { @@ -464,16 +467,16 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) * colour depth. Check this and return an error to help with * diagnosis. */ - ret = vidconsole_putc_xy(dev, priv->xcur_frac, priv->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx->xcur_frac, priv->ycur, ch); if (ret == -EAGAIN) { vidconsole_newline(dev); - ret = vidconsole_putc_xy(dev, priv->xcur_frac, priv->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx->xcur_frac, priv->ycur, ch); } if (ret < 0) return ret; - priv->xcur_frac += ret; + ctx->xcur_frac += ret; priv->last_ch = ch; - if (priv->xcur_frac >= priv->xsize_frac) + if (ctx->xcur_frac >= priv->xsize_frac) vidconsole_newline(dev); cli_index_adjust(priv, 1); @@ -483,6 +486,7 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct vidconsole_ansi *ansi = &priv->ansi; int cp, ret; @@ -503,17 +507,17 @@ int vidconsole_put_char(struct udevice *dev, char ch) /* beep */ break; case '\r': - priv->xcur_frac = priv->xstart_frac; + ctx->xcur_frac = priv->xstart_frac; break; case '\n': vidconsole_newline(dev); vidconsole_entry_start(dev); break; case '\t': /* Tab (8 chars alignment) */ - priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac) + ctx->xcur_frac = ((ctx->xcur_frac / priv->tab_width_frac) + 1) * priv->tab_width_frac; - if (priv->xcur_frac >= priv->xsize_frac) + if (ctx->xcur_frac >= priv->xsize_frac) vidconsole_newline(dev); break; case '\b': @@ -832,9 +836,10 @@ int vidconsole_hide_cursor(struct udevice *dev) int vidconsole_mark_start(struct udevice *dev) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct vidconsole_ops *ops = vidconsole_get_ops(dev); - priv->xmark_frac = priv->xcur_frac; + priv->xmark_frac = ctx->xcur_frac; priv->ymark = priv->ycur; priv->cli_index = 0; if (ops->mark_start) { diff --git a/include/video_console.h b/include/video_console.h index 6f74f64cddf..f6971a20e0d 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -83,12 +83,14 @@ struct vidconsole_cursor { * @cols: Number of text columns * @x_charsize: Character width in pixels * @y_charsize: Character height in pixels + * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) */ struct vidconsole_ctx { int rows; int cols; int x_charsize; int y_charsize; + int xcur_frac; }; /** @@ -121,13 +123,12 @@ struct vidconsole_ansi { * Note that these values relate to the rotated console, so that an 80x25 * console which is rotated 90 degrees will have rows=80 and cols=25 * - * The xcur_frac and ycur values refer to the unrotated coordinates, that is - * xcur_frac always advances with each character, even if its limit might be - * vid_priv->ysize instead of vid_priv->xsize if the console is rotated 90 or - * 270 degrees. + * The ctx.xcur_frac and ycur values refer to the unrotated coordinates, that + * is ctx.xcur_frac always advances with each character, even if its limit + * might be vid_priv->ysize instead of vid_priv->xsize if the console is + * rotated 90 or 270 degrees. * * @sdev: stdio device, acting as an output sink - * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) * @ycur: Current Y position in pixels (0=top) * @ctx: Per-client context * @tab_width_frac: Tab width in fractional units @@ -145,7 +146,6 @@ struct vidconsole_ansi { struct vidconsole_priv { struct stdio_dev sdev; struct vidconsole_ctx ctx; - int xcur_frac; int ycur; int tab_width_frac; int xsize_frac; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the ycur field from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. This allows each client to maintain its own cursor Y position. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 4 ++-- drivers/video/console_truetype.c | 12 ++++++------ drivers/video/vidconsole-uclass.c | 26 +++++++++++++------------- include/video_console.h | 8 ++++---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 0aadd8bc96f..95cde3aa709 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -161,7 +161,7 @@ static __maybe_unused int normal_entry_save(struct udevice *dev, return log_msg_ret("sav", -ENOMEM); store.xpos_frac = ctx->xcur_frac; - store.ypos = vc_priv->ycur; + store.ypos = ctx->ycur; store.cli_index = vc_priv->cli_index; memcpy(abuf_data(buf), &store, size); @@ -181,7 +181,7 @@ static __maybe_unused int normal_entry_restore(struct udevice *dev, memcpy(&store, abuf_data(buf), sizeof(store)); ctx->xcur_frac = store.xpos_frac; - vc_priv->ycur = store.ypos; + ctx->ycur = store.ypos; vc_priv->cli_index = store.cli_index; return 0; diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 386e9aa8a59..233154cfeea 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -497,7 +497,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, pos = &ctx->pos[ctx->pos_ptr]; pos->xpos_frac = vc_ctx->xcur_frac; - pos->ypos = vc_priv->ycur; + pos->ypos = vc_ctx->ycur; pos->width = (width_frac + VID_FRAC_DIV - 1) / VID_FRAC_DIV; pos->cp = cp; ctx->pos_ptr++; @@ -707,14 +707,14 @@ static int console_truetype_backspace(struct udevice *dev) * cursor position, but if we are clearing a character on the previous * line, we clear from the end of the line. */ - if (pos->ypos == vc_priv->ycur) + if (pos->ypos == vc_ctx->ycur) xend = VID_TO_PIXEL(vc_ctx->xcur_frac); else xend = vid_priv->xsize; /* Move the cursor back to where it was when we pushed this record */ vc_ctx->xcur_frac = pos->xpos_frac; - vc_priv->ycur = pos->ypos; + vc_ctx->ycur = pos->ypos; return 0; } @@ -1202,7 +1202,7 @@ static int truetype_entry_save(struct udevice *dev, struct abuf *buf) store.priv = *priv; store.cur.xpos_frac = vc_ctx->xcur_frac; - store.cur.ypos = vc_priv->ycur; + store.cur.ypos = vc_ctx->ycur; memcpy(abuf_data(buf), &store, size); return 0; @@ -1222,7 +1222,7 @@ static int truetype_entry_restore(struct udevice *dev, struct abuf *buf) memcpy(&store, abuf_data(buf), sizeof(store)); vc_ctx->xcur_frac = store.cur.xpos_frac; - vc_priv->ycur = store.cur.ypos; + vc_ctx->ycur = store.cur.ypos; *ctx = store.priv.ctx; return 0; @@ -1255,7 +1255,7 @@ static int truetype_get_cursor_info(struct udevice *dev) x = VID_TO_PIXEL(ctx->pos[index].xpos_frac); else x = VID_TO_PIXEL(vc_ctx->xcur_frac); - y = vc_priv->ycur; + y = vc_ctx->ycur; /* Get font height from current font type */ if (priv->cur_fontdata) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 8bc2384dd7a..29caaf34fc0 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -80,9 +80,9 @@ static int vidconsole_back(struct udevice *dev) if (ctx->xcur_frac < priv->xstart_frac) { ctx->xcur_frac = (ctx->cols - 1) * VID_TO_POS(ctx->x_charsize); - priv->ycur -= ctx->y_charsize; - if (priv->ycur < 0) - priv->ycur = 0; + ctx->ycur -= ctx->y_charsize; + if (ctx->ycur < 0) + ctx->ycur = 0; } assert(priv->cli_index); cli_index_adjust(priv, -1); @@ -101,17 +101,17 @@ static void vidconsole_newline(struct udevice *dev) int i, ret; ctx->xcur_frac = priv->xstart_frac; - priv->ycur += ctx->y_charsize; + ctx->ycur += ctx->y_charsize; /* Check if we need to scroll the terminal */ if (vid_priv->rot % 2 ? - priv->ycur + ctx->x_charsize > vid_priv->xsize : - priv->ycur + ctx->y_charsize > vid_priv->ysize) { + ctx->ycur + ctx->x_charsize > vid_priv->xsize : + ctx->ycur + ctx->y_charsize > vid_priv->ysize) { vidconsole_move_rows(dev, 0, rows, ctx->rows - rows); for (i = 0; i < rows; i++) vidconsole_set_row(dev, ctx->rows - i - 1, vid_priv->colour_bg); - priv->ycur -= rows * ctx->y_charsize; + ctx->ycur -= rows * ctx->y_charsize; } priv->last_ch = 0; @@ -140,7 +140,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y) ctx->xcur_frac = VID_TO_POS(x); priv->xstart_frac = ctx->xcur_frac; - priv->ycur = y; + ctx->ycur = y; /* make sure not to kern against the previous character */ priv->last_ch = 0; @@ -181,7 +181,7 @@ static void get_cursor_position(struct vidconsole_priv *priv, { struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); - *row = priv->ycur / ctx->y_charsize; + *row = ctx->ycur / ctx->y_charsize; *col = VID_TO_PIXEL(ctx->xcur_frac - priv->xstart_frac) / ctx->x_charsize; } @@ -332,7 +332,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) console_puts_select_stderr(true, "[vc err: video_sync]"); #endif } - priv->ycur = 0; + ctx->ycur = 0; ctx->xcur_frac = priv->xstart_frac; } else { debug("unsupported clear mode: %d\n", mode); @@ -467,10 +467,10 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) * colour depth. Check this and return an error to help with * diagnosis. */ - ret = vidconsole_putc_xy(dev, ctx->xcur_frac, priv->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx->xcur_frac, ctx->ycur, ch); if (ret == -EAGAIN) { vidconsole_newline(dev); - ret = vidconsole_putc_xy(dev, ctx->xcur_frac, priv->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx->xcur_frac, ctx->ycur, ch); } if (ret < 0) return ret; @@ -840,7 +840,7 @@ int vidconsole_mark_start(struct udevice *dev) struct vidconsole_ops *ops = vidconsole_get_ops(dev); priv->xmark_frac = ctx->xcur_frac; - priv->ymark = priv->ycur; + priv->ymark = ctx->ycur; priv->cli_index = 0; if (ops->mark_start) { int ret; diff --git a/include/video_console.h b/include/video_console.h index f6971a20e0d..c2656ec452d 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -84,6 +84,7 @@ struct vidconsole_cursor { * @x_charsize: Character width in pixels * @y_charsize: Character height in pixels * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) + * @ycur: Current Y position in pixels (0=top) */ struct vidconsole_ctx { int rows; @@ -91,6 +92,7 @@ struct vidconsole_ctx { int x_charsize; int y_charsize; int xcur_frac; + int ycur; }; /** @@ -123,13 +125,12 @@ struct vidconsole_ansi { * Note that these values relate to the rotated console, so that an 80x25 * console which is rotated 90 degrees will have rows=80 and cols=25 * - * The ctx.xcur_frac and ycur values refer to the unrotated coordinates, that - * is ctx.xcur_frac always advances with each character, even if its limit + * The ctx.xcur_frac and ctx.ycur values refer to the unrotated coordinates, + * that is ctx.xcur_frac always advances with each character, even if its limit * might be vid_priv->ysize instead of vid_priv->xsize if the console is * rotated 90 or 270 degrees. * * @sdev: stdio device, acting as an output sink - * @ycur: Current Y position in pixels (0=top) * @ctx: Per-client context * @tab_width_frac: Tab width in fractional units * @xsize_frac: Width of the display in fractional units @@ -146,7 +147,6 @@ struct vidconsole_ansi { struct vidconsole_priv { struct stdio_dev sdev; struct vidconsole_ctx ctx; - int ycur; int tab_width_frac; int xsize_frac; int xstart_frac; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the last_ch field from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. This field tracks the last character written, used for kerning in truetype fonts. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_truetype.c | 7 ++++--- drivers/video/vidconsole-uclass.c | 10 +++++----- include/video_console.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 233154cfeea..e607dff0aea 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -452,8 +452,8 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, pos = ctx->pos_ptr < ctx->pos_count ? &ctx->pos[ctx->pos_ptr] : NULL; xpos = frac(VID_TO_PIXEL((double)x)); kern = 0; - if (vc_priv->last_ch) { - int last_cp = vc_priv->last_ch; + if (vc_ctx->last_ch) { + int last_cp = vc_ctx->last_ch; if (pos) last_cp = pos->cp; @@ -722,13 +722,14 @@ static int console_truetype_backspace(struct udevice *dev) static int console_truetype_entry_start(struct udevice *dev) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *vc_ctx = vidconsole_ctx_from_priv(vc_priv); struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_ctx *ctx = &priv->ctx; /* A new input line has start, so clear our history */ ctx->pos_ptr = 0; ctx->pos_count = 0; - vc_priv->last_ch = 0; + vc_ctx->last_ch = 0; return 0; } diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 29caaf34fc0..1e9c0b4b730 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -113,7 +113,7 @@ static void vidconsole_newline(struct udevice *dev) vid_priv->colour_bg); ctx->ycur -= rows * ctx->y_charsize; } - priv->last_ch = 0; + ctx->last_ch = 0; ret = video_sync(dev->parent, false); if (ret) { @@ -143,7 +143,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y) ctx->ycur = y; /* make sure not to kern against the previous character */ - priv->last_ch = 0; + ctx->last_ch = 0; vidconsole_entry_start(dev); } @@ -460,7 +460,7 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) if (_DEBUG) { console_printf_select_stderr(true, "glyph last_ch '%c': ch '%c' (%02x): ", - priv->last_ch, ch >= ' ' ? ch : ' ', ch); + ctx->last_ch, ch >= ' ' ? ch : ' ', ch); } /* * Failure of this function normally indicates an unsupported @@ -475,7 +475,7 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) if (ret < 0) return ret; ctx->xcur_frac += ret; - priv->last_ch = ch; + ctx->last_ch = ch; if (ctx->xcur_frac >= priv->xsize_frac) vidconsole_newline(dev); cli_index_adjust(priv, 1); @@ -522,7 +522,7 @@ int vidconsole_put_char(struct udevice *dev, char ch) break; case '\b': vidconsole_back(dev); - priv->last_ch = 0; + ctx->last_ch = 0; break; default: if (CONFIG_IS_ENABLED(CHARSET)) { diff --git a/include/video_console.h b/include/video_console.h index c2656ec452d..6dfa2214448 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -85,6 +85,7 @@ struct vidconsole_cursor { * @y_charsize: Character height in pixels * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) * @ycur: Current Y position in pixels (0=top) + * @last_ch: Last character written to the text console on this line */ struct vidconsole_ctx { int rows; @@ -93,6 +94,7 @@ struct vidconsole_ctx { int y_charsize; int xcur_frac; int ycur; + int last_ch; }; /** @@ -135,7 +137,6 @@ struct vidconsole_ansi { * @tab_width_frac: Tab width in fractional units * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units - * @last_ch: Last character written to the text console on this line * @xmark_frac: X position of start of CLI text entry, in fractional units * @ymark: Y position of start of CLI text * @cli_index: Character index into the CLI text (0=start) @@ -150,7 +151,6 @@ struct vidconsole_priv { int tab_width_frac; int xsize_frac; int xstart_frac; - int last_ch; int xmark_frac; int ymark; int cli_index; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the cli_index field from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. This field tracks the character position within CLI text entry. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 8 ++++---- drivers/video/vidconsole-uclass.c | 4 ++-- include/video_console.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 95cde3aa709..283bbdff681 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -107,7 +107,7 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) x = VID_TO_PIXEL(vc_priv->xmark_frac); y = vc_priv->ymark; - index = vc_priv->cli_index; + index = ctx->cli_index; /* rounded up character position in this line */ xpos = (x + ctx->x_charsize - 1) / ctx->x_charsize; @@ -141,7 +141,7 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) curs->x = x; curs->y = y; curs->height = ctx->y_charsize; - curs->index = vc_priv->cli_index; + curs->index = ctx->cli_index; return 0; } @@ -162,7 +162,7 @@ static __maybe_unused int normal_entry_save(struct udevice *dev, store.xpos_frac = ctx->xcur_frac; store.ypos = ctx->ycur; - store.cli_index = vc_priv->cli_index; + store.cli_index = ctx->cli_index; memcpy(abuf_data(buf), &store, size); return 0; @@ -182,7 +182,7 @@ static __maybe_unused int normal_entry_restore(struct udevice *dev, ctx->xcur_frac = store.xpos_frac; ctx->ycur = store.ypos; - vc_priv->cli_index = store.cli_index; + ctx->cli_index = store.cli_index; return 0; } diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 1e9c0b4b730..4570c9fe60d 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -84,7 +84,7 @@ static int vidconsole_back(struct udevice *dev) if (ctx->ycur < 0) ctx->ycur = 0; } - assert(priv->cli_index); + assert(ctx->cli_index); cli_index_adjust(priv, -1); return video_sync(dev->parent, false); @@ -841,7 +841,7 @@ int vidconsole_mark_start(struct udevice *dev) priv->xmark_frac = ctx->xcur_frac; priv->ymark = ctx->ycur; - priv->cli_index = 0; + ctx->cli_index = 0; if (ops->mark_start) { int ret; diff --git a/include/video_console.h b/include/video_console.h index 6dfa2214448..559263e214b 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -86,6 +86,7 @@ struct vidconsole_cursor { * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) * @ycur: Current Y position in pixels (0=top) * @last_ch: Last character written to the text console on this line + * @cli_index: Character index into the CLI text (0=start) */ struct vidconsole_ctx { int rows; @@ -95,6 +96,7 @@ struct vidconsole_ctx { int xcur_frac; int ycur; int last_ch; + int cli_index; }; /** @@ -139,7 +141,6 @@ struct vidconsole_ansi { * @xstart_frac: Left margin for the text console in fractional units * @xmark_frac: X position of start of CLI text entry, in fractional units * @ymark: Y position of start of CLI text - * @cli_index: Character index into the CLI text (0=start) * @ansi: ANSI escape-sequence state * @utf8_buf: Buffer to accumulate UTF-8 byte sequence * @quiet: Suppress all output from stdio @@ -153,7 +154,6 @@ struct vidconsole_priv { int xstart_frac; int xmark_frac; int ymark; - int cli_index; struct vidconsole_ansi ansi; char utf8_buf[5]; bool quiet; @@ -615,7 +615,7 @@ static inline void vidconsole_readline_end(void) static inline void cli_index_adjust(struct vidconsole_priv *priv, int by) { if (CONFIG_IS_ENABLED(CURSOR)) - priv->cli_index += by; + priv->ctx.cli_index += by; } /** -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the xmark_frac and ymark fields from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. These fields track the start position of CLI text entry, allowing each client to have its own entry point. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/console_normal.c | 4 ++-- drivers/video/vidconsole-uclass.c | 4 ++-- include/video_console.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 283bbdff681..73bf3a7ebe8 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -105,8 +105,8 @@ static __maybe_unused int console_get_cursor_info(struct udevice *dev) if (!IS_ENABLED(CONFIG_EXPO)) return -ENOSYS; - x = VID_TO_PIXEL(vc_priv->xmark_frac); - y = vc_priv->ymark; + x = VID_TO_PIXEL(ctx->xmark_frac); + y = ctx->ymark; index = ctx->cli_index; /* rounded up character position in this line */ diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 4570c9fe60d..182505d1056 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -839,8 +839,8 @@ int vidconsole_mark_start(struct udevice *dev) struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); struct vidconsole_ops *ops = vidconsole_get_ops(dev); - priv->xmark_frac = ctx->xcur_frac; - priv->ymark = ctx->ycur; + ctx->xmark_frac = ctx->xcur_frac; + ctx->ymark = ctx->ycur; ctx->cli_index = 0; if (ops->mark_start) { int ret; diff --git a/include/video_console.h b/include/video_console.h index 559263e214b..73c4f54f62c 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -87,6 +87,8 @@ struct vidconsole_cursor { * @ycur: Current Y position in pixels (0=top) * @last_ch: Last character written to the text console on this line * @cli_index: Character index into the CLI text (0=start) + * @xmark_frac: X position of start of CLI text entry, in fractional units + * @ymark: Y position of start of CLI text */ struct vidconsole_ctx { int rows; @@ -97,6 +99,8 @@ struct vidconsole_ctx { int ycur; int last_ch; int cli_index; + int xmark_frac; + int ymark; }; /** @@ -139,8 +143,6 @@ struct vidconsole_ansi { * @tab_width_frac: Tab width in fractional units * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units - * @xmark_frac: X position of start of CLI text entry, in fractional units - * @ymark: Y position of start of CLI text * @ansi: ANSI escape-sequence state * @utf8_buf: Buffer to accumulate UTF-8 byte sequence * @quiet: Suppress all output from stdio @@ -152,8 +154,6 @@ struct vidconsole_priv { int tab_width_frac; int xsize_frac; int xstart_frac; - int xmark_frac; - int ymark; struct vidconsole_ansi ansi; char utf8_buf[5]; bool quiet; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the ansi struct and utf8_buf array from vidconsole_priv into vidconsole_ctx as part of the per-client context refactoring. These fields hold parsing state for ANSI escape sequences and UTF-8 byte accumulation, which need to be per-client to avoid interference when multiple clients send interleaved data. Also move struct vidconsole_ansi definition before struct vidconsole_ctx since the latter now contains the former. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/video/vidconsole-uclass.c | 6 ++-- include/video_console.h | 50 +++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 182505d1056..2136253b15e 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -195,7 +195,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); - struct vidconsole_ansi *ansi = &priv->ansi; + struct vidconsole_ansi *ansi = &ctx->ansi; if (!IS_ENABLED(CONFIG_VIDEO_ANSI)) goto error; @@ -487,7 +487,7 @@ int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv); - struct vidconsole_ansi *ansi = &priv->ansi; + struct vidconsole_ansi *ansi = &ctx->ansi; int cp, ret; /* Hide cursor to avoid artifacts */ @@ -526,7 +526,7 @@ int vidconsole_put_char(struct udevice *dev, char ch) break; default: if (CONFIG_IS_ENABLED(CHARSET)) { - cp = utf8_to_utf32_stream(ch, priv->utf8_buf); + cp = utf8_to_utf32_stream(ch, ctx->utf8_buf); if (cp == 0) return 0; } else { diff --git a/include/video_console.h b/include/video_console.h index 73c4f54f62c..bc468d753d4 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -73,6 +73,27 @@ struct vidconsole_cursor { uint index; }; +/** + * struct vidconsole_ansi - ANSI escape-sequence state + * + * ANSI escape sequences are accumulated character by character, starting after + * the ESC char (0x1b) until the entire sequence is consumed, at which point it + * is acted upon. + * + * @escape: True if currently accumulating an ANSI escape sequence + * @escape_len: Length of accumulated escape sequence so far + * @row_saved: Saved Y position in pixels (0=top) + * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) + * @escape_buf: Buffer to accumulate escape sequence + */ +struct vidconsole_ansi { + int escape; + int escape_len; + int row_saved; + int col_saved; + char escape_buf[32]; +}; + /** * struct vidconsole_ctx - per-client context for a video console * @@ -89,6 +110,8 @@ struct vidconsole_cursor { * @cli_index: Character index into the CLI text (0=start) * @xmark_frac: X position of start of CLI text entry, in fractional units * @ymark: Y position of start of CLI text + * @ansi: ANSI escape-sequence state + * @utf8_buf: Buffer to accumulate UTF-8 byte sequence */ struct vidconsole_ctx { int rows; @@ -101,27 +124,8 @@ struct vidconsole_ctx { int cli_index; int xmark_frac; int ymark; -}; - -/** - * struct vidconsole_ansi - ANSI escape-sequence state - * - * ANSI escape sequences are accumulated character by character, starting after - * the ESC char (0x1b) until the entire sequence is consumed, at which point it - * is acted upon. - * - * @escape: True if currently accumulating an ANSI escape sequence - * @escape_len: Length of accumulated escape sequence so far - * @row_saved: Saved Y position in pixels (0=top) - * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) - * @escape_buf: Buffer to accumulate escape sequence - */ -struct vidconsole_ansi { - int escape; - int escape_len; - int row_saved; - int col_saved; - char escape_buf[32]; + struct vidconsole_ansi ansi; + char utf8_buf[5]; }; /** @@ -143,8 +147,6 @@ struct vidconsole_ansi { * @tab_width_frac: Tab width in fractional units * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units - * @ansi: ANSI escape-sequence state - * @utf8_buf: Buffer to accumulate UTF-8 byte sequence * @quiet: Suppress all output from stdio * @curs: Cursor state and management */ @@ -154,8 +156,6 @@ struct vidconsole_priv { int tab_width_frac; int xsize_frac; int xstart_frac; - struct vidconsole_ansi ansi; - char utf8_buf[5]; bool quiet; struct vidconsole_cursor curs; }; -- 2.43.0
participants (1)
-
Simon Glass