[Concept,20/36] video: Pass context to mark_start() method

Message ID 20260120231814.2033069-21-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>

The mark_start() driver method currently uses the default context.
Update it to accept a context parameter so callers can specify which
context to use for marking the start position. This is needed for
text-input objects which have their own vidconsole context.

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

 drivers/video/console_truetype.c  | 4 ++--
 drivers/video/vidconsole-uclass.c | 8 ++++----
 include/video_console.h           | 3 ++-
 3 files changed, 8 insertions(+), 7 deletions(-)
  

Patch

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 5453e5d9776..b3884bddd72 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -1251,9 +1251,9 @@  const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 	}
 }
 
-static int truetype_mark_start(struct udevice *dev)
+static int truetype_mark_start(struct udevice *dev, void *vctx)
 {
-	struct console_tt_ctx *ctx = vidconsole_ctx(dev);
+	struct console_tt_ctx *ctx = vctx;
 
 	ctx->pos_start = ctx->pos_ptr;
 
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 9b29b742740..6ef86abc4ce 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -839,10 +839,10 @@  int vidconsole_hide_cursor(struct udevice *dev, void *vctx)
 }
 #endif /* CONFIG_CURSOR */
 
-int vidconsole_mark_start(struct udevice *dev)
+int vidconsole_mark_start(struct udevice *dev, void *vctx)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx_from_priv(priv);
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 
 	ctx->xmark_frac = ctx->xcur_frac;
@@ -851,7 +851,7 @@  int vidconsole_mark_start(struct udevice *dev)
 	if (ops->mark_start) {
 		int ret;
 
-		ret = ops->mark_start(dev);
+		ret = ops->mark_start(dev, ctx);
 		if (ret != -ENOSYS)
 			return ret;
 	}
@@ -1027,7 +1027,7 @@  void vidconsole_readline_start(struct udevice *dev, void *vctx, bool indent)
 
 	ctx->curs.indent = indent;
 	ctx->curs.enabled = true;
-	vidconsole_mark_start(dev);
+	vidconsole_mark_start(dev, ctx);
 }
 
 void vidconsole_readline_end(struct udevice *dev, void *vctx)
diff --git a/include/video_console.h b/include/video_console.h
index 4bb6974edcc..297049cb851 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -444,8 +444,9 @@  struct vidconsole_ops {
 	 * the beginning point for the cursor.
 	 *
 	 * @dev: Console device to use
+	 * @ctx: Vidconsole context to use (cannot be NULL)
 	 */
-	int (*mark_start)(struct udevice *dev);
+	int (*mark_start)(struct udevice *dev, void *ctx);
 };
 
 /* Get a pointer to the driver operations for a video console device */