[Concept,02/18] video: Move curs into vidconsole_ctx

Message ID 20260117005702.1684841-3-sjg@u-boot.org
State New
Headers
Series Refactor vidconsole context for dynamic allocation |

Commit Message

Simon Glass Jan. 17, 2026, 12:56 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The cursor state should be per-context so that different clients can
maintain their own cursor information. Move the curs field from
vidconsole_priv into vidconsole_ctx.

Update all access to use the vidconsole_ctx() or
vidconsole_ctx_from_priv() helpers for consistency.

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

 drivers/video/console_core.c      |  6 +++---
 drivers/video/console_normal.c    |  2 +-
 drivers/video/console_truetype.c  |  2 +-
 drivers/video/vidconsole-uclass.c | 24 +++++++++++++-----------
 include/video_console.h           |  4 ++--
 test/dm/video.c                   |  3 ++-
 6 files changed, 22 insertions(+), 19 deletions(-)
  

Patch

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 9cf5831b562..50f67ffcf83 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -280,7 +280,7 @@  int cursor_hide(struct vidconsole_cursor *curs, struct video_priv *vid_priv,
 
 int console_alloc_cursor(struct udevice *dev)
 {
-	struct vidconsole_priv *vc_priv;
+	struct vidconsole_ctx *ctx;
 	struct vidconsole_cursor *curs;
 	struct video_priv *vid_priv;
 	struct udevice *vid;
@@ -289,10 +289,10 @@  int console_alloc_cursor(struct udevice *dev)
 	if (!CONFIG_IS_ENABLED(CURSOR) || xpl_phase() < PHASE_BOARD_R)
 		return 0;
 
-	vc_priv = dev_get_uclass_priv(dev);
+	ctx = vidconsole_ctx(dev);
 	vid = dev_get_parent(dev);
 	vid_priv = dev_get_uclass_priv(vid);
-	curs = &vc_priv->curs;
+	curs = &ctx->curs;
 
 	/* Allocate cursor save buffer for maximum possible cursor height */
 	save_count = vid_priv->ysize * VIDCONSOLE_CURSOR_WIDTH;
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 73bf3a7ebe8..4854e953e58 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -98,7 +98,7 @@  static __maybe_unused int console_get_cursor_info(struct udevice *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;
+	struct vidconsole_cursor *curs = &ctx->curs;
 	int x, y, index, xspace, xpos;
 
 	/* for now, this is not used outside expo */
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 37cc1f0fc5d..978e81a9350 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -1233,7 +1233,7 @@  static int truetype_get_cursor_info(struct udevice *dev)
 	struct vidconsole_ctx *com = 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;
+	struct vidconsole_cursor *curs = &com->curs;
 	int x, y, index;
 	uint height;
 
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 2136253b15e..71bcb0d9c91 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -767,8 +767,9 @@  int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf)
 int vidconsole_show_cursor(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);
-	struct vidconsole_cursor *curs = &priv->curs;
+	struct vidconsole_cursor *curs = &ctx->curs;
 	int ret;
 
 	/* find out where the cursor should be drawn */
@@ -807,7 +808,8 @@  int vidconsole_show_cursor(struct udevice *dev)
 int vidconsole_hide_cursor(struct udevice *dev)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_cursor *curs = &priv->curs;
+	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
+	struct vidconsole_cursor *curs = &ctx->curs;
 	int ret;
 
 	if (!curs->visible)
@@ -912,9 +914,9 @@  static int vidconsole_post_probe(struct udevice *dev)
 
 static int vidconsole_pre_remove(struct udevice *dev)
 {
-	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
 
-	free(vc_priv->curs.save_data);
+	free(ctx->curs.save_data);
 
 	return 0;
 }
@@ -987,8 +989,8 @@  void vidconsole_set_bitmap_font(struct udevice *dev,
 
 void vidconsole_idle(struct udevice *dev)
 {
-	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_cursor *curs = &priv->curs;
+	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+	struct vidconsole_cursor *curs = &ctx->curs;
 
 	/* Only handle cursor if it's enabled */
 	if (curs->enabled && !curs->visible) {
@@ -1008,10 +1010,10 @@  void vidconsole_readline_start(bool indent)
 	struct udevice *dev;
 
 	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc) {
-		struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+		struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
 
-		priv->curs.indent = indent;
-		priv->curs.enabled = true;
+		ctx->curs.indent = indent;
+		ctx->curs.enabled = true;
 		vidconsole_mark_start(dev);
 	}
 }
@@ -1022,9 +1024,9 @@  void vidconsole_readline_end(void)
 	struct udevice *dev;
 
 	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc) {
-		struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+		struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
 
-		priv->curs.enabled = false;
+		ctx->curs.enabled = false;
 	}
 }
 #endif /* CURSOR */
diff --git a/include/video_console.h b/include/video_console.h
index bc468d753d4..5b90a5cf160 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -112,6 +112,7 @@  struct vidconsole_ansi {
  * @ymark:		Y position of start of CLI text
  * @ansi:		ANSI escape-sequence state
  * @utf8_buf:		Buffer to accumulate UTF-8 byte sequence
+ * @curs:		Cursor state and management
  */
 struct vidconsole_ctx {
 	int rows;
@@ -126,6 +127,7 @@  struct vidconsole_ctx {
 	int ymark;
 	struct vidconsole_ansi ansi;
 	char utf8_buf[5];
+	struct vidconsole_cursor curs;
 };
 
 /**
@@ -148,7 +150,6 @@  struct vidconsole_ctx {
  * @xsize_frac:		Width of the display in fractional units
  * @xstart_frac:	Left margin for the text console in fractional units
  * @quiet:		Suppress all output from stdio
- * @curs:		Cursor state and management
  */
 struct vidconsole_priv {
 	struct stdio_dev sdev;
@@ -157,7 +158,6 @@  struct vidconsole_priv {
 	int xsize_frac;
 	int xstart_frac;
 	bool quiet;
-	struct vidconsole_cursor curs;
 };
 
 /**
diff --git a/test/dm/video.c b/test/dm/video.c
index d802a5cc24d..d3978f4b00c 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -1185,7 +1185,8 @@  static int check_cursor_backspace(struct unit_test_state *uts,
 {
 	int with_a, with_cursor, after_backspace, after_idle, after_hide;
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(con);
-	struct vidconsole_cursor *curs = &vc_priv->curs;
+	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(vc_priv);
+	struct vidconsole_cursor *curs = &ctx->curs;
 
 	/* Output chars without cursor */
 	ut_assert(!curs->visible);