[Concept,03/36] video: Pass context to vidconsole_entry_start()

Message ID 20260120231814.2033069-4-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:17 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a ctx parameter to vidconsole_entry_start() to allow callers to
specify which vidconsole context to use. If NULL is passed, the function
falls back to using the default context from vidconsole_priv.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/scene_txtin.c                |  2 +-
 drivers/video/console_truetype.c  |  4 ++--
 drivers/video/vidconsole-uclass.c | 14 ++++++++------
 include/video_console.h           |  6 ++++--
 4 files changed, 15 insertions(+), 11 deletions(-)
  

Patch

diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index fd7cefa1d5b..4f9230f931d 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -127,7 +127,7 @@  int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
 		return log_msg_ret("cur", -ENOENT);
 
 	vidconsole_set_cursor_pos(cons, NULL, txt->obj.bbox.x0, txt->obj.bbox.y0);
-	vidconsole_entry_start(cons);
+	vidconsole_entry_start(cons, NULL);
 	cli_cread_init(&scn->cls, abuf_data(&tin->buf), tin->line_chars);
 	scn->cls.insert = true;
 	scn->cls.putch = scene_txtin_putch;
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 98356de2fd2..106da0e086d 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -697,9 +697,9 @@  static int console_truetype_backspace(struct udevice *dev)
 	return 0;
 }
 
-static int console_truetype_entry_start(struct udevice *dev)
+static int console_truetype_entry_start(struct udevice *dev, void *vctx)
 {
-	struct console_tt_ctx *ctx = vidconsole_ctx(dev);
+	struct console_tt_ctx *ctx = vctx;
 	struct vidconsole_ctx *com = &ctx->com;
 
 	/* A new input line has start, so clear our history */
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 17366d2de40..679d5d46f81 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -50,13 +50,15 @@  int vidconsole_set_row(struct udevice *dev, uint row, int clr)
 	return ops->set_row(dev, row, clr);
 }
 
-int vidconsole_entry_start(struct udevice *dev)
+int vidconsole_entry_start(struct udevice *dev, void *ctx)
 {
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 
+	if (!ctx)
+		ctx = vidconsole_ctx_from_priv(dev_get_uclass_priv(dev));
 	if (!ops->entry_start)
 		return -ENOSYS;
-	return ops->entry_start(dev);
+	return ops->entry_start(dev, ctx);
 }
 
 /* Move backwards one space */
@@ -130,10 +132,10 @@  static char *parsenum(char *s, int *num)
 	return end;
 }
 
-void vidconsole_set_cursor_pos(struct udevice *dev, void *ctxp, int x, int y)
+void vidconsole_set_cursor_pos(struct udevice *dev, void *vctx, int x, int y)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = ctxp ? ctxp : vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = vctx ? vctx : vidconsole_ctx_from_priv(priv);
 
 	/* Hide cursor at old position if it's visible */
 	vidconsole_hide_cursor(dev);
@@ -144,7 +146,7 @@  void vidconsole_set_cursor_pos(struct udevice *dev, void *ctxp, int x, int y)
 
 	/* make sure not to kern against the previous character */
 	ctx->last_ch = 0;
-	vidconsole_entry_start(dev);
+	vidconsole_entry_start(dev, NULL);
 }
 
 /**
@@ -511,7 +513,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 		break;
 	case '\n':
 		vidconsole_newline(dev);
-		vidconsole_entry_start(dev);
+		vidconsole_entry_start(dev, NULL);
 		break;
 	case '\t':	/* Tab (8 chars alignment) */
 		ctx->xcur_frac = ((ctx->xcur_frac / ctx->tab_width_frac)
diff --git a/include/video_console.h b/include/video_console.h
index a91b2a510b4..bb0445dc7c9 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -278,6 +278,7 @@  struct vidconsole_ops {
 	 * entry_start() - Indicate that text entry is starting afresh
 	 *
 	 * @dev:	Device to adjust
+	 * @ctx:	Vidconsole context to use
 	 * Returns: 0 on success, -ve on error
 	 *
 	 * Consoles which use proportional fonts need to track the position of
@@ -287,7 +288,7 @@  struct vidconsole_ops {
 	 * command). The driver can use this signal to empty its list of
 	 * positions.
 	 */
-	int (*entry_start)(struct udevice *dev);
+	int (*entry_start)(struct udevice *dev, void *ctx);
 
 	/**
 	 * backspace() - Handle erasing the last character
@@ -695,8 +696,9 @@  int vidconsole_set_row(struct udevice *dev, uint row, int clr);
  * Marks the current cursor position as the start of a line
  *
  * @dev:	Device to adjust
+ * @ctx:	vidconsole context to use, or NULL to use the default
  */
-int vidconsole_entry_start(struct udevice *dev);
+int vidconsole_entry_start(struct udevice *dev, void *ctx);
 
 /**
  * vidconsole_put_char() - Output a character to the current console position