From patchwork Tue Jan 20 23:17:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1686 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951175; bh=Ep9cGuQt8qrDQhpZpmBkueC64bBi8tRSow7OmnsyuwA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=RhZUhS68OqovsDMNKtrDPPFtkBNCa/TGFA9pR9WG6YHuwpa23UKWt3UlDAeLYHzTY AHUrnMNiU8CahkR4aw3ZBcvbu+J2l36FTCPRC7AxUREs328BeUcV0tX5WGPwK2/Cot bGocJNFHTEWkCBWDjUl1DE+6VSMKW/bYQW7VNyIzA6EJc4+4oBXvT1v2RVwzg6SBmP mvYWVsgtKHSCdQx/WXY1K0+SbDw6L3cinQh9R87psplQum+FyZ/dOE/x27XLE2j1+x csB/THjhviKrR2X7B6u34D1/JGs5qR4+BpSUcz7LCaixEtAx1iX/NGksBvDncKACSN hmIRRfrFS5eNw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A1F2769572 for ; Tue, 20 Jan 2026 16:19:35 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id f41_yklRPq1i for ; Tue, 20 Jan 2026 16:19:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951175; bh=Ep9cGuQt8qrDQhpZpmBkueC64bBi8tRSow7OmnsyuwA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=RhZUhS68OqovsDMNKtrDPPFtkBNCa/TGFA9pR9WG6YHuwpa23UKWt3UlDAeLYHzTY AHUrnMNiU8CahkR4aw3ZBcvbu+J2l36FTCPRC7AxUREs328BeUcV0tX5WGPwK2/Cot bGocJNFHTEWkCBWDjUl1DE+6VSMKW/bYQW7VNyIzA6EJc4+4oBXvT1v2RVwzg6SBmP mvYWVsgtKHSCdQx/WXY1K0+SbDw6L3cinQh9R87psplQum+FyZ/dOE/x27XLE2j1+x csB/THjhviKrR2X7B6u34D1/JGs5qR4+BpSUcz7LCaixEtAx1iX/NGksBvDncKACSN hmIRRfrFS5eNw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 907506957E for ; Tue, 20 Jan 2026 16:19:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951173; bh=//UbhMJQW9UrH2ipPrwlpP+8T/W67MOzvyv4HeQQPk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r+dsLEUiUyLE6ZoHcvTbR8de1D5VRVBHyFVV+kIaLSJD5JVHRlU26x9bgIhspsMOP nffz7jlJZdRo6TIshTy6Rr2z0YWgRoAD/FT8i9cH4rUoRlxF6FvQqmfahGzrJmlBER D0za8CZGLbDPTT6Tjo1j4Gvzs3sLwlT07o8kutVyebWr84tHswdwcnze4Or0vuKPtj vFt750YNiLSaOBuMCYkfcd8qgD7TENwb1X+AgFnsokDydBeVPpjO9l91tzihqiyh+O WZrMAlKLZeGFqEzFxVVFb8cDV8zCStE/+OSXjq0BTie7x3PgHZHKi1t9RyR1zF5Srh z693fUu+D48OQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3F07169572; Tue, 20 Jan 2026 16:19:33 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id vv1ls-B6_FIJ; Tue, 20 Jan 2026 16:19:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951169; bh=i+3fYrLptDYWkkoqq7xGVUjl709KlmoNk1fJJXeWdZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ym2BVxoOO3cO49XrxvXtLBgopuda32MeIImjARIbNU0F84VD+Q5D7ClJvQB75xRro XtmrLWzHMY5bVaa1tQZ8gSxQ+2tKifsdcOXZ5AQu31RRAFy1maWGg3O1rZFAPJwCJg XGTxNCnVVAOGG4TxlbgpY2nS9TDx6ceDSP/ciOMmp1RdyxJBlzwyFAdUixjMUm576j 2eJjsSFGy9rk44FL6kuMIn4loTOi6umdxPxOn2MF0hr85SlfaC9eTFQybSqUHpc1Uz 8o5k5YH15WCTsW0bnsC23h8UfpYSkXp6bJzXDf9BBOziuFrjBlrpOz0LxG7FvtHnIT MBUIzJCoB2//A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C670D6913F; Tue, 20 Jan 2026 16:19:28 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 20 Jan 2026 16:17:40 -0700 Message-ID: <20260120231814.2033069-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120231814.2033069-1-sjg@u-boot.org> References: <20260120231814.2033069-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NDIB753HATRR5H25XKGFOQNLUVPD7CCG X-Message-ID-Hash: NDIB753HATRR5H25XKGFOQNLUVPD7CCG X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/36] video: Pass context to vidconsole_putc_xy() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a vctx parameter to vidconsole_putc_xy() and its driver method to allow passing in a specific vidconsole context. If NULL, the default context from priv is used. Update all driver implementations and callers accordingly. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- drivers/video/console_normal.c | 12 ++++++------ drivers/video/console_rotate.c | 18 +++++++++--------- drivers/video/console_truetype.c | 6 +++--- drivers/video/vidconsole-uclass.c | 10 ++++++---- drivers/video/vidconsole_internal.h | 4 +++- include/video_console.h | 7 +++++-- test/dm/video.c | 18 +++++++++--------- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index 5b6f0f0ce86..5f84896699d 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -79,13 +79,12 @@ static int console_move_rows(struct udevice *dev, uint rowdst, return 0; } -int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +int console_normal_putc_xy(struct udevice *dev, void *vctx, uint x_frac, + uint y, int cp) { - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct console_simple_priv *priv = dev_get_priv(dev); - return console_fixed_putc_xy(dev, vidconsole_ctx_from_priv(vc_priv), - x_frac, y, cp, priv->fontdata); + return console_fixed_putc_xy(dev, vctx, x_frac, y, cp, priv->fontdata); } static __maybe_unused int console_get_cursor_info(struct udevice *dev) @@ -172,9 +171,10 @@ static __maybe_unused int normal_entry_restore(struct udevice *dev, return 0; } -static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +static int console_putc_xy(struct udevice *dev, void *vctx, uint x_frac, + uint y, int cp) { - return console_normal_putc_xy(dev, x_frac, y, cp); + return console_normal_putc_xy(dev, vctx, x_frac, y, cp); } static int console_simple_ctx_new(struct udevice *dev, void **ctxp) diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c index 378c7ec6fc7..42c9de888d8 100644 --- a/drivers/video/console_rotate.c +++ b/drivers/video/console_rotate.c @@ -72,10 +72,10 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc, return 0; } -static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp) +static int console_putc_xy_1(struct udevice *dev, void *vctx, 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 vidconsole_ctx *ctx = vctx; struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); @@ -161,10 +161,10 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc, return 0; } -static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp) +static int console_putc_xy_2(struct udevice *dev, void *vctx, 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 vidconsole_ctx *ctx = vctx; struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); @@ -252,10 +252,10 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc, return 0; } -static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp) +static int console_putc_xy_3(struct udevice *dev, void *vctx, 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 vidconsole_ctx *ctx = vctx; struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index b4b491039ae..a72e2342010 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -395,11 +395,11 @@ static void clear_from(struct udevice *dev, int index) } } -static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, - int cp) +static int console_truetype_putc_xy(struct udevice *dev, void *vctx, uint x, + uint y, int cp) { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - struct console_tt_ctx *ctx = vidconsole_ctx(dev); + struct console_tt_ctx *ctx = vctx; struct vidconsole_ctx *com = &ctx->com; struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_metrics *met = ctx->cur_met; diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 29a1accb64c..ec78068f734 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -22,13 +22,15 @@ #include /* Bitmap font for code page 437 */ #include -int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, int ch) +int vidconsole_putc_xy(struct udevice *dev, void *vctx, uint x, uint y, int ch) { + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); struct vidconsole_ops *ops = vidconsole_get_ops(dev); if (!ops->putc_xy) return -ENOSYS; - return ops->putc_xy(dev, x, y, ch); + return ops->putc_xy(dev, vctx ?: vidconsole_ctx_from_priv(priv), x, y, + ch); } int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, @@ -468,10 +470,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, ctx->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx, ctx->xcur_frac, ctx->ycur, ch); if (ret == -EAGAIN) { vidconsole_newline(dev, ctx); - ret = vidconsole_putc_xy(dev, ctx->xcur_frac, ctx->ycur, ch); + ret = vidconsole_putc_xy(dev, ctx, ctx->xcur_frac, ctx->ycur, ch); } if (ret < 0) return ret; diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h index ef864a7c858..8b598b26b13 100644 --- a/drivers/video/vidconsole_internal.h +++ b/drivers/video/vidconsole_internal.h @@ -187,12 +187,14 @@ int console_simple_select_font(struct udevice *dev, const char *name, uint size) * Normal console putc_xy function that can be called by other console drivers * * @param dev console device + * @param ctx vidconsole context to use, or NULL for default * @param x_frac fractional X position * @param y Y position in pixels * @param cp Unicode code point * @returns width in fractional pixels, or -ve on error */ -int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp); +int console_normal_putc_xy(struct udevice *dev, void *ctx, uint x_frac, + uint y, int cp); /** * Fixed font putc_xy function that can be called with explicit font data diff --git a/include/video_console.h b/include/video_console.h index 3390d4fe1a7..9627d645189 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -240,6 +240,7 @@ struct vidconsole_ops { * putc_xy() - write a single character to a position * * @dev: Device to write to + * @ctx: Vidconsole context to use (cannot be NULL) * @x_frac: Fractional pixel X position (0=left-most pixel) which * is the X position multipled by VID_FRAC_DIV. * @y: Pixel Y position (0=top-most pixel) @@ -248,7 +249,8 @@ struct vidconsole_ops { * if all is OK, -EAGAIN if we ran out of space on this line, other -ve * on error */ - int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, int cp); + int (*putc_xy)(struct udevice *dev, void *ctx, uint x_frac, uint y, + int cp); /** * move_rows() - Move text rows from one place to another @@ -687,6 +689,7 @@ void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old); * vidconsole_putc_xy() - write a single character to a position * * @dev: Device to write to + * @ctx: Vidconsole context to use, or NULL to use default * @x_frac: Fractional pixel X position (0=left-most pixel) which * is the X position multipled by VID_FRAC_DIV. * @y: Pixel Y position (0=top-most pixel) @@ -695,7 +698,7 @@ void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old); * if all is OK, -EAGAIN if we ran out of space on this line, other -ve * on error */ -int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, int cp); +int vidconsole_putc_xy(struct udevice *dev, void *ctx, uint x, uint y, int cp); /** * vidconsole_move_rows() - Move text rows from one place to another diff --git a/test/dm/video.c b/test/dm/video.c index 97778a70559..e4599be30a8 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -264,16 +264,16 @@ static int dm_test_video_text(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_putc_xy(con, 0, 0, 'a'); + vidconsole_putc_xy(con, NULL, 0, 0, 'a'); ut_asserteq(79, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); - vidconsole_putc_xy(con, 0, 0, ' '); + vidconsole_putc_xy(con, NULL, 0, 0, ' '); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); for (i = 0; i < 20; i++) - vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); + vidconsole_putc_xy(con, NULL, VID_TO_POS(i * 8), 0, ' ' + i); ut_asserteq(273, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -282,7 +282,7 @@ static int dm_test_video_text(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); for (i = 0; i < 20; i++) - vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); + vidconsole_putc_xy(con, NULL, VID_TO_POS(i * 8), 0, ' ' + i); ut_asserteq(273, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -306,16 +306,16 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - vidconsole_putc_xy(con, 0, 0, 'a'); + vidconsole_putc_xy(con, NULL, 0, 0, 'a'); ut_asserteq(89, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); - vidconsole_putc_xy(con, 0, 0, ' '); + vidconsole_putc_xy(con, NULL, 0, 0, ' '); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); for (i = 0; i < 20; i++) - vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); + vidconsole_putc_xy(con, NULL, VID_TO_POS(i * 8), 0, ' ' + i); ut_asserteq(363, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -324,7 +324,7 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts) ut_assertok(video_check_copy_fb(uts, dev)); for (i = 0; i < 20; i++) - vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); + vidconsole_putc_xy(con, NULL, VID_TO_POS(i * 8), 0, ' ' + i); ut_asserteq(363, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -1442,7 +1442,7 @@ static int dm_test_video_sync_damage(struct unit_test_state *uts) ut_assert(!vid_bbox_valid(&priv->damage)); /* Write a small piece of text at a specific position */ - vidconsole_putc_xy(con, VID_TO_POS(400), 67, 'T'); + vidconsole_putc_xy(con, NULL, VID_TO_POS(400), 67, 'T'); /* Check priv->damage before sync - should have text damage */ ut_assert(vid_bbox_valid(&priv->damage));