From patchwork Fri Jan 16 17:14:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1529 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=1768583699; bh=OXizIclYu1GHzNAWv0afHCqkoVc2G2rb55ESnpmRdBE=; 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=UvValsnDMM66AbTJnicTr9TwJ/JQtewb5HYTRnx0bGJOfhQYSIuyoiBXhad+eByQp 7/H6W3n/h+gl9MDLcXta7i97ldfOQpVj6NEAsW7h+u4wxNjWhzgVRM97lUUS7502xF dHi3xedb9DrHRoXgrTrDC0QgRI8d6vn/IQmeO5Cj2Ggq2Xt4kcF+42GwjNp6dPButb I4IBD/GWRVDrGKWmcL2ZAia7XQokvitdV4UNtIVEDnijebJ5iHiFa3d/KWIDUtYsFY mSnp3TfGHlyBN5BlzNVuqSoxTxFG0s/HIqv2QdARhur3zdulOJHO1QNsoZrPKWbTy1 3yqwgcLGnn5cw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0DE406913F for ; Fri, 16 Jan 2026 10:14:59 -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 AGji_xlRfb1L for ; Fri, 16 Jan 2026 10:14:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583697; bh=OXizIclYu1GHzNAWv0afHCqkoVc2G2rb55ESnpmRdBE=; 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=GljAbvPlsPT4k4ginjgaU+5k+Va9WEP98wLpYw5yS92aYtvkmqxw83xhfgKVdWf1j 9lFJ5AyimzIxNkRuqHBkQYTquS9K1VTt/FLh8aucQLa8VpwyjVjJY9/vOBMmAnPDxe 2DiqpT0voWm4iRc6t1gDR+ikUzo1BdiP7wW/Ru/nQlyVX0viGZsrq1t/qRN1tkdTz/ WBDu94giwMGUAlpS+LzpLwZw6apCggcgfTztmLpq5pT3dQP9YaLzJ8O5WjHLb8JVWg qxXJeEt1b7uHi4hF1ujEmGvfRf2NCNBBM/5RaSRuxO8kFLeeWZxozmIdKBLg7nCm7L +SSIOOuMDWAOw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B8A5B693C0 for ; Fri, 16 Jan 2026 10:14:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583686; bh=2859VhInrNKtrmxCsIbWaodiHrbjL/zc/xltNcmdHjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WX9+u4K12R+EIGgcuvQ1CsgMxrdgFBLV/lsoIimmPYfM3Tc8Y/Gg5wbQKEEDHsDPS VLtpp9EUzQpahIODV124VCl5FpsKNctTkTklKF9bou9aI37wC9wEmGnGgCId8jmOpm Icz210MGfwE9ymVsclha+Ksc7nVqFFl+WG1jd1nFzpc6u5YVqltQLmRQEhotrdmlMs oFSV8YjijT9+NDHehGm94KZqolqk/oMbrJyQjeDl8Uuv7C9CxOgLEAioS08E0bWN2/ x8nYxoKWix7ot0DF1IGmyMXl/DF5iaY0KRE/SgDwdbSnekm0BO4KBprTH424FELVmW 2LPLmHL+M4NFw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B2E516932F; Fri, 16 Jan 2026 10:14:46 -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 MIAxlR3m5SEN; Fri, 16 Jan 2026 10:14:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583681; bh=ajjtPnkYkxqlApBvTVvgSV9ayXjifsbLAWDCSKtpG2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UHwxHKprQCmeWVtL0bCFuquBFV8nIHXXIr7pzI5dpcQtuaIUHJY4+IZHb1hu/BuiL lHjigp/NV36+MkaCjPJ57qs9mkiX9RI+PontEceURrZfHt0fl1LFAHdKYV2aSklwNF GGK2Q9CECAc0D6TMEel40MqYn2BF745UWOcYfTxEOIkvAGszaKYgwL6Lqcw+gRtJ2q 7TSgHZxJJt+wROxDhxxG1KyYrup2FK/PoarLGx6zBBon6IWudHoXR29emEP7cTiDHQ Ps6Q7jZ4fSoh89CaXQiTFv+p7j4oYEYStUXp2XB5k/CKUF10qJ1es826yF5V1s9QlS 18wvoAeuPSv8A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1D70E6913F; Fri, 16 Jan 2026 10:14:41 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:03 -0700 Message-ID: <20260116171424.398597-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QD4SD7KTRR3A5NBSYF2YS34PRI4SMCYX X-Message-ID-Hash: QD4SD7KTRR3A5NBSYF2YS34PRI4SMCYX 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 01/14] video: Add empty vidconsole_ctx struct 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 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 Signed-off-by: Simon Glass --- 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 /* 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 * From patchwork Fri Jan 16 17:14:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1530 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=1768583699; bh=8yPxxCmyX2jRR7pDKcu/kTE/kTMhUm7lCMHbOsYVIys=; 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=XAL4hGALcHEIM18jUW1M8kjoa4oXz8AFbDRqnSYddqZBDgWtlejKXP6j2W+rVh2yo cxurgy2dXYM656c4q8YuyHnZmsXHxAmGOK0M+JSRQW9pkBO7QjxDe9N2ZGd3wyqfaP qV3s/WL5eXWJaA8EGgYTGgtSWkXt/KENwaEN4zU9Dqn13IMbFsBOBZ6155HwnqkYTA lttCP8YZgfzuXt3YOYSnFJbtVtV/XQ2GaenEOohIACTgqoh3C5zIemef1F7fQsA18c 5A7Gl/FDC2uYxrkzdik3xoQiiJ0MjFfrUmuJwD2lhw7uJi5C1+t/oyXvI5H/3TtjRD o+djgyzK3raVg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5041C693C0 for ; Fri, 16 Jan 2026 10:14:59 -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 Umc1n4etXDmN for ; Fri, 16 Jan 2026 10:14:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583698; bh=8yPxxCmyX2jRR7pDKcu/kTE/kTMhUm7lCMHbOsYVIys=; 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=TF4qRSysIyfl1zA4A61XYIF8+ptRxfdCIe/IxRYdbgF5uFyBCOJmI1CIGXr32VcrN rmSInne46tse5ulc9Zb06AwrCUNJFtMsUD8BL66VQplve8Cp0vKzWYFAxBmNSb1wIJ xdAdPhVjC9zYY94bC3xZ8qeJm5LPjRkm+gjEeJ/LzabNez35/E+4nFoVQAZ+NvCDqb XFDcGtlA5iPaSoEKoKQaW2sogmJ6vlD/uk2FBhr4bY08tEnAhAodxCPl10s9SojLrM Z3RoTQsBn8IJDH6mpTIGaj3JXsBAckQjMs7VSHWSFRvfHSxX8XoUpDClNZ6gDnCtI0 JlJdBUoKWvcsw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4AFAF693CB for ; Fri, 16 Jan 2026 10:14:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583692; bh=O0qMXt5sWmZP6L0DgMeGNEITy3Ia7bWjtbPNM63OSA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=snI3o5XdBQcJ9DHHiR38IDPWAgJOSkfel4g8w6fbyWkLHXwiTq0+OV6MJuHAO1rTt jZwHOoMA5+z5Lnj0fcFvnA4KfM43x24hm79aj+A/ratFRGvU6MrhNZPh+nkJ1Vsizv 2anvrq4Ws4Uz0+MpegwzhglahpDkN37CqT9hsualKMJ0X5zLwD/+0VSXH24cbQrJTW Xooh55ATLrQOFuqCJhoTgQRgOuCJZYzHZtt2JbnT/1t8za1lwwxI3hKDy5gUM/26og jNXK532oVEUz2QlHIXX+yi73se7OrrJX8i+YhIzipMcUm/KeJHsiE4yiXSaQIBOrr6 JUJQJvRTTNZFw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 868536932F; Fri, 16 Jan 2026 10:14:52 -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 UDIK04y0GFlz; Fri, 16 Jan 2026 10:14:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583687; bh=B5n0yEU6I9XcbZk231r70qfYr2bx1X2S+WBJuKj0tpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXFV75OmagOna7AQExw5qnLYI62tRAjkRp9XgvcbEdvn/jNEkmrjg4gcPCnZXGyAZ bQgVq3vat0p2mZ7+Hac+lwFpIClyPZ5e1S3NSjiwXwnytGmOLO1EqgWoSLpmpAEINT wkRmP2EZxrnoXPF4mfJtb8Kutz95ABZrN8D7BCcOKvwed9uxvwmjQXWWLBt9cOXDRn HDFzyrk1PDynah30MPq78bBngh6rn8UKmJDScwS94j25YrbVwMuUcLxuKyRwn9bBD9 i2B6oDAq3CJYAMUH2/JO7C7gHdF7xXlWRztOIgb88R/90v4Kwi69Da5NGnw7uZBwwT bsqKec+1dQJDQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E4C4A6913F; Fri, 16 Jan 2026 10:14:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:04 -0700 Message-ID: <20260116171424.398597-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: I3QHL2V4UBXO6TW4PBVHEK2GIF4JLWYW X-Message-ID-Hash: I3QHL2V4UBXO6TW4PBVHEK2GIF4JLWYW 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 02/14] video: Add vidconsole context creation and disposal 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 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 Signed-off-by: Simon Glass --- 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 #include +#include #include #include #include @@ -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); From patchwork Fri Jan 16 17:14:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1531 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=1768583701; bh=s3oPst/QeTO0VwDgF83M93bjat1rbmAoDNO5QpDvPtM=; 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=jSvbNOJnFk13mrK+QY5dQuhFZt3cQMEoAhNwSKD7QPKSq0NQx8fsAV8xN7rzE1BIe ikjVX+5sSeePuXJhztAvX+EaMnXTR4Mqr+aSSwkE1NpVqtSJmOdRWA8wmdJY9T2Cl3 T/NsBW7WudOeN98//QMyG2moHlIzGv1tKH+GMHhGvQFgYwFVT7KC2wjDD6QFgK2sfE e9UBAV+rsy6d2AzlMVK0iyRHcDQkdVRSce1+2jPyT5k8mPyble8Uay1snUuXgoO4+f 6y6YZ/UFTLgSfhxhby/PurPIS72+KO4i8gbqrFbqvcmhkuRJmJjv9as8pQTy3utSvr yuD7SrbDmDkzA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A67BE693B0 for ; Fri, 16 Jan 2026 10:15:01 -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 y8GYivHlew8d for ; Fri, 16 Jan 2026 10:15:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583699; bh=s3oPst/QeTO0VwDgF83M93bjat1rbmAoDNO5QpDvPtM=; 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=OpRvDejX3PLjl24I5duQWVe/xgRIpTGhzQUx1huKD4t9um5iVHlfD9djyYkcBm8H7 qqsHKe8brEXee2P5EOYMak/p/61O71Ft6oOzfe06INxBJ9SnAVbNeX09BtxVshTPeV mtAc8kbg7zFXN9RkFMb2rjVtvgSSGDjz48K/4FQDzL8Eh94nVzobBKF0ZIk19IRMYq uxp/cyDGxsNCTNoNvm0P1QK9Y2/aZ1AU1DmrIg65MStewlCku53WzJjvQ34c2LVPks L4EQt68TJvlTxVgcFWcSXDgnURuz+mIqOFeAmv0PqDCoNCku59cdbnr9CMNnWTPhfT j99GTq8meQGUw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C08096913F for ; Fri, 16 Jan 2026 10:14:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583698; bh=XntqdCrHxs6g5Wd0jaYYQRIJibF1QfoVzVc7d/q/jws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PZvpP/+8mnqBVyBsnBlhEXAv9CRQbcZUD+7eMIXjT5HvnoGzCOdOfeORagJ/CUY6i Zjgnu+xw8fPGUq7EcN2Seluh2BJ9Kib8f48naKzrKNntIwbGUt5pO0IkiXGH0jO8Lb Lb/baxRITOIs/aRZ5AbYV1GuwQ4NVy3AxyGHl5h5rNZCLbnSQagbpdRCPij/PnkcZi ElXzHlbpAPow25EOQLZthjpND8/CbVD8tRz4IrRkaW73wWiAf3Vex2pxDdUM1pAuhc BcnK9ged/8zZvwNiOWYtKSRPF987x6H0iC2xT3+FhsNnT+WafyxR27M2KtmFhmo2pB n7EPxr69X833A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DB021693D1; Fri, 16 Jan 2026 10:14:58 -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 d9RkQiGw5V6g; Fri, 16 Jan 2026 10:14:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583693; bh=pTds3CqeGglGtndPW/4tNuTLYpQRXJaOLSVAH1I7hEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YfGxzbQZI8/e93Rfbzzn7uQa/zupneshDR7s5NpVxXEXXoY2U0A8OKD93HbuWrSwM D0elJAfls6vd09z9SMcuWATG2iXYKH2lqgDnRkCmJLEIaAbJy8RZF/acHfb3dJsKoR E1khR2xXQOwq+WwbIoLY2SJtYEW53/RfjA+b9aRULZnWRcIT64hGDDHa3auf3nhnku aCAxhry7ZjKeARmY/2rjGSxJqSJ7Dg3zVNkQSGgDpCFj03iFPC+MVEpa6zIj7v1cAe NTqWFjAsP+8s7XkJVH3sQkdwPvYg65xZWdYsbLP1kjSedVKBJ39kG+RqAYdJdx5+/E uHp7N4BCmsRJg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CC9026913F; Fri, 16 Jan 2026 10:14:52 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:05 -0700 Message-ID: <20260116171424.398597-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IVOIM62TS352IJQJGDPS2DTXPEE6KG6M X-Message-ID-Hash: IVOIM62TS352IJQJGDPS2DTXPEE6KG6M 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 03/14] video: truetype: Restore pos_start in entry_restore() 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 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 Signed-off-by: Simon Glass --- 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)); From patchwork Fri Jan 16 17:14:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1532 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=1768583705; bh=NuIWGl4GAG9ZcplWnetkMK0zJEXhZ8vkLeOIfKVFZ08=; 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=w4dIHHtQUKxDi3CgFGcNisey2Lh8/0054OixsgrsnOLOwjvt1Jp6V3V6s0oGCdNnv 7mvTB4jh5A59RHHzOjT5CO5WownCbmzSQCPzIFeMvktp57d2JnIoq0k/tNZIv0eQ5t XjNPxutyfW4X1nwtRrPmvVmzY9ZYq5kgHY9dW/htaIYDRWiWwyPGnAGFUB8pi+SlLI FUGZFoyFVtLx5sLCDhKrppUC74+p0Ty3r0oW97G3bbD32wXK8/oY4hJX3w6DFGQEfP WA5dfAvoNFExJ0L8GCVfmUTxOqsI3HnPCznFR6IOJxfKXY+YhinSVwvzEhCe7sn/yO mpZ3mcPnvno9Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AD0A4693B1 for ; Fri, 16 Jan 2026 10:15:05 -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 BlfWTMY0tsFT for ; Fri, 16 Jan 2026 10:15:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583705; bh=NuIWGl4GAG9ZcplWnetkMK0zJEXhZ8vkLeOIfKVFZ08=; 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=w4dIHHtQUKxDi3CgFGcNisey2Lh8/0054OixsgrsnOLOwjvt1Jp6V3V6s0oGCdNnv 7mvTB4jh5A59RHHzOjT5CO5WownCbmzSQCPzIFeMvktp57d2JnIoq0k/tNZIv0eQ5t XjNPxutyfW4X1nwtRrPmvVmzY9ZYq5kgHY9dW/htaIYDRWiWwyPGnAGFUB8pi+SlLI FUGZFoyFVtLx5sLCDhKrppUC74+p0Ty3r0oW97G3bbD32wXK8/oY4hJX3w6DFGQEfP WA5dfAvoNFExJ0L8GCVfmUTxOqsI3HnPCznFR6IOJxfKXY+YhinSVwvzEhCe7sn/yO mpZ3mcPnvno9Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 983046913F for ; Fri, 16 Jan 2026 10:15:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583703; bh=Mxg8q4fW777Xqrto4LjB6qYWoGeGZaqwJ4njsFyQf3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=trZVmf1C7rVwEZ1aWDGyn+/tFLtOALHpBpLZRsT3P8STGv7YhtGXKEpxTcabcPWp4 q7O7/vlUsIWUZLXC6WErafwTh5YjFa9vRj/J4vvthbSx2rLy7/SBicZszPqyJdSdwD dhnXpWrPJHBJFkFrJI5FpLWdt6n4a0wcf4/Yiki0/K0PAzQnVeOnK2TXw/ifA+/Koi dVoof0fiAqwZiqg8k372CEZcjr2erC9WBh+KFdj17CbIOa2a6LtsmNwv8NSj8D0e2q YYMS90yb4+XyIi3G9d/mdcIxKePb5sV0QGLVn8cYHjp/U4K3a9duKtGyIKjSMiW3qB Gs6HUBoxWD/KA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 15E486913F; Fri, 16 Jan 2026 10:15:03 -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 EZckwwIRgrM0; Fri, 16 Jan 2026 10:15:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583697; bh=iXW57lFLgx892Bm9vL3QEwHxgk4HNdmlOcjsmnzIg54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EeqFXkzsX2RXkxlNHaK90lm2tCjlTtwxqT8ag3UHfZEAH6OA6NF18CVauMWC3O514 4UTXb84xso/hXAw49Ndd1XtZFytrYgnfzfpDPLsv2JTvbJdTGPaVMze/wrqO5S/2sx r6i1w4+Yy/OE7T9S9dCG1JYcejye/F72uUoRepkWYmpHn5F+KzqpPmFZplT9rN8AH4 Z7cyNcL2I0bZhJRgHqsrsdluRnAK2m3s1akJdIIRGb+BlZLeh/DcgbFGwe1TSZ/gSk byp8zPv/n2VPiIgsdpkoaaHf7TaZueXKsybfh+BymRgI99PQAKnSz+dkicHATpCye9 7lAs5wH9omWXA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 82768693B2; Fri, 16 Jan 2026 10:14:57 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:06 -0700 Message-ID: <20260116171424.398597-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MC4E4EEE2F3C6Q3BF7K2PR525267SGOZ X-Message-ID-Hash: MC4E4EEE2F3C6Q3BF7K2PR525267SGOZ 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 04/14] video: truetype: Move per-client context into ctx struct 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 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 Signed-off-by: Simon Glass --- 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; } From patchwork Fri Jan 16 17:14:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1533 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=1768583708; bh=qMYnX5ZVdH1pVRxG01ZqnvtAdqztLvxdiLSTAQy/YXM=; 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=FvQbW3GGQ2rxNOnrXyc/ExeGHfz/C9xS76BeVE6Ml5yJKFQisAb4/OjVE6tpSvqKm +1bg3IjqsUygNWHoCoch8n6AJnNwR4AlMVYeXvtnQjNwnJRrc+hKIWjZC5117KpZVC Q0D2E7NbLFdEClTHX5KAp8Ncv26UiXULJDwJPQCeTKYwt1aHz8exb080tGP2LvIA4Q 3FkBBQKPwTe9IzDxW6PESBRlY6crVAgsN8tc3eYcLV3MVG2U0ncevqdf5Tv80ha2p+ IZ5UIC464TLO5//r4agRBcaD4FEjGHO09HtU7fxygMDL64Q+4wcBkyobuG1/5gXGJT xWu96QvPkSBnA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 169C4693BE for ; Fri, 16 Jan 2026 10:15:08 -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 wA2_AYWJKJbl for ; Fri, 16 Jan 2026 10:15:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583706; bh=qMYnX5ZVdH1pVRxG01ZqnvtAdqztLvxdiLSTAQy/YXM=; 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=XCFYB7NslF+z6CQQ3mAD2W5dOhtgVPaAjk+WWfstgh7X9jOJE0rFkvHb4NlOAkJqs 1yqNz7LsTmdOesz7PCgaDvzUJlWRHr0zPykeI1QjDSaI2A4adSv90CFfyPS7QJeFZZ YxzfsMi6K1FaEwD9EmG3cQlsfcX7xnqfb1ZnY7boL/6zg8w/nsybGaGeIYM1uMZdkO 9yB+yWwN/2VEt04IM1TofmG61v67huwyYAUcOcaYovfxJQTB9+skGpDxkZWrQhf6XW OICQodwySoXVB0JWEYM8lA9LSDwdBKsUC+wg8KqtJ1lK57nykCoeUhWSXaaJ4iIteA EaksJepz2jqUQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2544F693C2 for ; Fri, 16 Jan 2026 10:15:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583703; bh=HzOFlZn46KMv2KBmOEfD1jO0HuqX4X4hlS+fS3hRCx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNf5BT1ME06r2rAWWpISjxtn2LgWgjaj6CLNI2+DCU3/rkSdd7XcxTtA4RjVUUK5v tYrX4wJAlij4sS/bn3vs3zsRtfYhdj354HuYEewYmKC4s84BwqqKKP8Z149YuQ6Os2 06Pu27sEZ1WbOIZsc6L6IqJlfYI6UdgyF2zZjJewth91OSRX+b+cgkSo9X9TsciUbn 2SMFzv4l0iMarp+1zXwzROJqRG/T843XI5zOmZ1SKLM8X0nJdZ6YoVcjWZ9nRGXBlW o5Hp9h8FTI+C/AhS5hO/I0Gj1VBjTBVeZUk7lzmXpaitAlIwa3jadxScqAp/Xxw7gJ r8aV7/JsPM67A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3DEE2693BE; Fri, 16 Jan 2026 10:15:03 -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 9aJC5_MEcjSh; Fri, 16 Jan 2026 10:15:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583702; bh=v1k1dgQQ1i67ekfi6DoeLt/FhFnRNQ/xBUx8+jN29eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pIbpCVRr3qUYFfJYrvGdNsSZ7wMj3GUCo06RiAaxucAhmfg6QvZWMrn8WTGFSyWS1 81G+cSYOBmGFhDoR923GWNF0odZx8YIj0BBGhmWE31hZdtktB17jJ29xDdsKKJkoxG zLmqu5Q09kWPG7NUS0EuvNHnqo3Ttak0BWwU8VQHyhAWYUBIsWT21GFnsbDCI2xkHu GpRbALZVgHkqTmOmRN7Ahz8PfgCDa+oJh5Qd/cBy6gLQkUdByPxqnoCycutH7I7Y5f 2ePh3cPNBrN/hN/ye4oSVMbIu8AolgB1wxGZ5JI4XqLQVYOwRoPL7zvde+kFM9Q7D/ q9HZUsCOEqVEw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4581E693B3; Fri, 16 Jan 2026 10:15:02 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:07 -0700 Message-ID: <20260116171424.398597-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EEFMJMMHT35SP3XUN6XKKK3OVCC6SJDC X-Message-ID-Hash: EEFMJMMHT35SP3XUN6XKKK3OVCC6SJDC 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/14] video: Add a helper to obtain the vidconsole context 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 function which returns the default context for a vidconsole. Signed-off-by: Simon Glass --- 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 * From patchwork Fri Jan 16 17:14:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1534 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=1768583712; bh=GyTCBA5k28jYDDRG1+zBpobvdf2r7lQhCweBM04mdHo=; 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=ZQOAqwvTkH+HUCNFQCzY86e+/BzU2wKYC6u//wX8AhQAnxqQgX0uYYnhN/2H9dwr7 sAPHdOP+OZcf6AwvVmwCJnEqSbEsylQm31sR4NbOyKMJQ4ysDYccVVZQmfIEprWOGS R07SDxbXw3oLdBbh1Ls1Ij7EYYVbKg6qVmDhI3WpHZzN4S2oQ48gMeToH8WLjHHc1z IOCdikLdLf67davDVjlZZWN4tWgoFpvvrjPSe9r4yM55KkMu8MhI0Tkg6xU0SeyPSs DwGO+oZ1zzA4mqlcRYTJIgI7NCMZ+RBUYBDIsxR1zWTz8Q31HHvkVWpR9NgeukyB2I ThLrTfXKyVoKg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A52CD693B1 for ; Fri, 16 Jan 2026 10:15:12 -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 TLQSKWG2db5g for ; Fri, 16 Jan 2026 10:15:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583712; bh=GyTCBA5k28jYDDRG1+zBpobvdf2r7lQhCweBM04mdHo=; 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=ZQOAqwvTkH+HUCNFQCzY86e+/BzU2wKYC6u//wX8AhQAnxqQgX0uYYnhN/2H9dwr7 sAPHdOP+OZcf6AwvVmwCJnEqSbEsylQm31sR4NbOyKMJQ4ysDYccVVZQmfIEprWOGS R07SDxbXw3oLdBbh1Ls1Ij7EYYVbKg6qVmDhI3WpHZzN4S2oQ48gMeToH8WLjHHc1z IOCdikLdLf67davDVjlZZWN4tWgoFpvvrjPSe9r4yM55KkMu8MhI0Tkg6xU0SeyPSs DwGO+oZ1zzA4mqlcRYTJIgI7NCMZ+RBUYBDIsxR1zWTz8Q31HHvkVWpR9NgeukyB2I ThLrTfXKyVoKg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 94139693B2 for ; Fri, 16 Jan 2026 10:15:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583710; bh=vufqm0gcr3eFc3WBNT3fs91SgbIAaUu4HfLPQUPAJds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWeZIiZyf19oCt3mFpzl/YKKcHbbar4GM9vrHLp09z01A5dH/z7SxWi0o1tv4gSR4 ouO//jQoqtNHTP9lxlxd9P20LP7ENqlIclqVsfSoNzOyOT30YKV6TD6kE4mrregGah NSRlT9hQ53YDWVRVi6LD/Ins9+5z0aAxCMRRloZwSysPriR+/1hqtqdI2KmEO5Sex7 BE0DIOTD4HAVjZ3hWTp27i5z1qa6V+eCTGLlt4cUK5ueIFVDbbQttP3youboLyMb/J 1/qdrZWCh9e2A6A9tQlk2DCe0/n3LaFksSZ9eHGa01vePxOWbBCxveDFuccArwtQCe Gt6YSI1dtBeVw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 65CAF6913F; Fri, 16 Jan 2026 10:15:10 -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 9Iy7KDOikiLv; Fri, 16 Jan 2026 10:15:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583703; bh=wN7uE8BIXwlT22hW/alIFXeVvAQ13DK9l7rgrw0GpbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bYO4lkbbng1cyCdoQJuGroK3Ee5wvFCYPfA2ZRwBiLX0sTR1z0oX8iVDdaLA2WC3A cfpxNt4GaCUkIppOfy7Kn9Iprqex8R/ne1QLpYmlMUgp67RG9z/EGYg3HQzvj9wdvV pXUERrVsiNbGM68n6dVHhBPHQKN37Cqo8WE+P1dv38qmPiDULXbb99WUNuDmYKC1mg 1Ni5fESNJpxJ+ayri+Xo1YeXeENd5IuUzoVLW5i2bRPKoOQxR21WXjS4b/e3xQAaUL jR/hbjz2WqyhB8b6ujQoEC+i0cmS8QxWLZqRo56LoVSCrWvBcasHkK9Ai4+I1NNKm6 oUbA/zjSY4QmA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 218A1693B2; Fri, 16 Jan 2026 10:15:03 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:08 -0700 Message-ID: <20260116171424.398597-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EKXS7OXZ7AXIIKZPOIMEW7ACHKN27VII X-Message-ID-Hash: EKXS7OXZ7AXIIKZPOIMEW7ACHKN27VII 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 06/14] video: Move rows and cols into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; } From patchwork Fri Jan 16 17:14:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1535 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=1768583714; bh=gqUGHf+2uVnsl2izeTpp7CtvA6QKK4y6etHOdIefgDo=; 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=knUjAbSYYE1R6qP2W0XOwR4aA6W/tyq/XuH/rSFPk0qwePaDRumIGqelg7mFDn4R8 ayRJNjQEOC4TvXHIdFvsaXMctvHErQf81WKaZwnDXrcq8y89g7CjjDg7gznOauFYaD SMqcTHpuNi/eV9EhUoiymJHwFxJzoowNnYoG2U+W4SCF86cimjTXl9tr6LVwb7jfkD mG+Z9FHwJI9nkVfPNlML0aWcnx6PhJOZLQ9n3zg7nwyfxyd+lih9eRwla/xJZxJmHi Gcp/GI6CtLKOSALdjb7vC4/C5iHtYSPdsdzu4iOk4toC3a9QMy5uaccMj9C1SVWa/c Us7V/+Bxk0jrQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8512D693B3 for ; Fri, 16 Jan 2026 10:15:14 -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 8n9K6SlYBj27 for ; Fri, 16 Jan 2026 10:15:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583714; bh=gqUGHf+2uVnsl2izeTpp7CtvA6QKK4y6etHOdIefgDo=; 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=knUjAbSYYE1R6qP2W0XOwR4aA6W/tyq/XuH/rSFPk0qwePaDRumIGqelg7mFDn4R8 ayRJNjQEOC4TvXHIdFvsaXMctvHErQf81WKaZwnDXrcq8y89g7CjjDg7gznOauFYaD SMqcTHpuNi/eV9EhUoiymJHwFxJzoowNnYoG2U+W4SCF86cimjTXl9tr6LVwb7jfkD mG+Z9FHwJI9nkVfPNlML0aWcnx6PhJOZLQ9n3zg7nwyfxyd+lih9eRwla/xJZxJmHi Gcp/GI6CtLKOSALdjb7vC4/C5iHtYSPdsdzu4iOk4toC3a9QMy5uaccMj9C1SVWa/c Us7V/+Bxk0jrQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7401D693B1 for ; Fri, 16 Jan 2026 10:15:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583712; bh=B73ta/XRnyLRFlJj5UK7Y83c08PnGoxJ/SG1YKnvkdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PcAmv4PfsgzDO2qaRjqHamHpwfaHY7PNg8wTxTsQZxrgmFdj6mm2phWLz+wZSnmc9 rrfjymAmwKkjrruUIcdbQ0obu9FNdDXvf1MYBS/3kTh+2ISrNG/WMPeoNAGL4Wd1XC AKULzFa7IWSsZ8zZOyTkX3fMRl+msh+yHHohOmjwb0bqaBnLZxfIwPmFsaxBbl02o8 kyFhs0x9EdIVoZDjaYY8vbAyDOjNq08s0jAhiOeIPaae5UAurINU37gSLD1f1u37qR BKhxcJKRKTJKC5idOKDh1sWfHPgqbghFh9g6zaB+qp48NjhT7IUTxdX/R+N30v4R3X f6HZvhZDTHifg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3334F6913F; Fri, 16 Jan 2026 10:15:12 -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 b8itjUnq0BZb; Fri, 16 Jan 2026 10:15:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583708; bh=W2QTRi3zMlkskdpTscdWSzwEXrICUP3zdBbHSpAC3VQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UQHBOFx8uGtMBU2scG2HTjzsEl0ExxswmCsTjyNL6JAkFr0FI49mn1irX1uLup8gE M3f4VCCyTzAgRhSw6w0czPOmgcC+zFPLsSAEfAI01uJcYxDf5bQP1QrDVpXIu8CR4Z 43/3pktZlLfmeJvCCq8n22kUHx0SdtErP/OEqVUd0eVUgpyBnQaMbe8s7KIt4vSvSX n4a5WNsBpspFNO838dWkkyNRWNqO9C+zAZxnHkdetog5YlUmUCrWvEED12jAUn8O41 svg9Ebxw+tHIGwVXFadNFnK6IJM7ZD9CavmsSkVuKSSpJ0kjPsrYPXqqTx2kYIpQG1 oe7BIu7qPTRdw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BAB6E693B1; Fri, 16 Jan 2026 10:15:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:09 -0700 Message-ID: <20260116171424.398597-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4EYTW5Y53KG77BZULGMNF6SYW6ZKRAFG X-Message-ID-Hash: 4EYTW5Y53KG77BZULGMNF6SYW6ZKRAFG 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 07/14] video: Move x_charsize and y_charsize into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1536 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=1768583719; bh=VgAN+17KpI1Y1lE40F57Gr/pUD1y5rSe0rv4S3TkEsE=; 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=iGrK+osRuvxM+O0PtMpLoN45zZc5zhy1Jb1SWQubMRozSWbBWXbEkZ41IDH4/qlOn Yq5BsXKeI7euekhjkNh6hC0D0OnhRn7NcYHe5GC9tHUePLWcyuxDte8DNMlMOhoTu5 m4h2/ChHhQtmTfIQbwrNUXHHeqZij2jJmtAAssT4NY/kRT2iL8ntixHW42wKIIWvQq R590spsPsQTLZd7bt2e7Pd05mOcQHokPfD7DOtB0MlhxEbBgR82y/cjrLgMeHUU5dc Igxam/ZB6jAjhqbjZaOc+8DX1S4vtPJio36Bgm/aaSwXJevak1WS8wwl/sryyWt9zI vob/TLzI8bcLA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2040A693B2 for ; Fri, 16 Jan 2026 10:15:19 -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 YYApdEnNVvKk for ; Fri, 16 Jan 2026 10:15:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583718; bh=VgAN+17KpI1Y1lE40F57Gr/pUD1y5rSe0rv4S3TkEsE=; 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=F0YEEzJCDxkTQkyKfM/qwOqMsDDqRiG2zxmFEJXyFoM4BEHAHoqaEHPl/6G5S8Ldu BQXwEOIJMmItxnibgrjK9lcmr5i0kAkHjzHxEHQ01YxQjNbvkrxX1DPV2Adgy1jWQx 9MEXbfn2nUNFCaMjBFYoP53f2q/MphhVEUuw8Wr+TgWpnEch8N1B6LvJos8bgZo/he fFeyOrfuGMR3dr56fxanEP4jXuvhibipXd8i0hjHFQaWCh6k69o42fK+pbj/axbPyN of7FVU/eCS9xxemOINbadFISE6ddccPsJqp6oYELa3o4JkN5YdLbLyHROsSwc8SOb7 9nPEF9VYlRQOw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E7CA2693B0 for ; Fri, 16 Jan 2026 10:15:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583716; bh=KYfIrm2sC8N3kyPqbB2tjSpw15gQBhJgQC9iTWGd5gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ua1MJC+g/mSMifI0qHmlP9ttoiTGx7LV4m6hauCNIpbWGBBxvXInEbyhGmYg94PCK t6xu5wjo+sSDtMYiF3Mhuq6epASnAD5VMDSsKCa+dH5mcK08t6m01ki4QBC1GEPiBA D/nAw4cgD8f0BdMLJn14CcBOlDOz2wSelLOllVsAfdoFRgD962shqz6/4I6w+CXXUO BxTXTkNIjUR6Oz0bJsPUSbGFG/EAUlZdMId6KF9M8Pv93JZJ6BrEOwcKoPHzMZuh6Y IDOVlzlbb8Yl5WAuaGMe6DgOVNdMqhEYITMHfCA2DZIjB95OKWgZQcGmEEy2/BNmmj rglIpNYUDvIZA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F0DF66913F; Fri, 16 Jan 2026 10:15:16 -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 le3S6NqjGjKn; Fri, 16 Jan 2026 10:15:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583712; bh=3xrz1i4u1DZqRJTRFF+0HHxtn2p20DkO7Vg6yZVsnuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WT4EmC0GLx5bogaY7OXctV4gOM4st7963+HcRgY1mwBQRXFX5whg6a0AgjJuB6BZ9 3UcfvLmxNFxdMRft59o8hu4jyYuxLchq3tLANtvaDUHe3I3cBb9IBCvm0pMqL1LGCg ONUDpaxdBHdm4GFZe6XVFrCs5Z9quOtC8gue/MmSuYQWSJ+Jy+yNzxVmLLv14mmDBy vbo4+hrnYXciqUz6O2DopkXgHK6M/3aiDInLVxxwPcRLJEwKmK8U78hqqCsNLBVY5N 68Cs+EsY7scd5PrjwItVnezC4vEt/ZzUr9nXenFvtv8BoByEScfLWRkoDA/1mLVzSG 0I1y86b1QdtsA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 78EA26932E; Fri, 16 Jan 2026 10:15:12 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:10 -0700 Message-ID: <20260116171424.398597-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WJWJYDJR2TNLZRYHQ73FW45OFHVXIRHS X-Message-ID-Hash: WJWJYDJR2TNLZRYHQ73FW45OFHVXIRHS 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 08/14] video: Create struct vidconsole_ansi for ANSI state 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1537 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=1768583723; bh=zvBCoVqihFDdgvC8bjzsR4vQzroc7Yk9drpzm6wyNQE=; 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=cwsb/7FDXNtC7srTmM6Ib+rNHqyWymMv2PieMSLbKCJkyqn12Smni3FWcO2emSGx5 ggDjp5XaKzRX5dHrQ81MvxnMCmA62RJGJSgv37kgD0EzOXehI3QT9PDYyNkA+QbxZ/ xSGtdKMruzjg0ED4dtSzIV2mFZLoJz7lBIDTtTlvUVxFFaPhvQT1fv5TdHt0O314Jg 1biO3BYuwOac9cTmQgrKm/6UaWaAgABh+fwQc2/e0UUdKcY5SaLswic1ZmvBay9MBN wd1ZRMh40GV/fKtR1SYXwtlxN0+irCMogQkKKGyp/aS+R6FfOMM0qmyPWaBUMzFlw6 BCrQBvqAPilRQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C6F8C693B3 for ; Fri, 16 Jan 2026 10:15:23 -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 sCkPC1Bh5hmb for ; Fri, 16 Jan 2026 10:15:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583723; bh=zvBCoVqihFDdgvC8bjzsR4vQzroc7Yk9drpzm6wyNQE=; 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=cwsb/7FDXNtC7srTmM6Ib+rNHqyWymMv2PieMSLbKCJkyqn12Smni3FWcO2emSGx5 ggDjp5XaKzRX5dHrQ81MvxnMCmA62RJGJSgv37kgD0EzOXehI3QT9PDYyNkA+QbxZ/ xSGtdKMruzjg0ED4dtSzIV2mFZLoJz7lBIDTtTlvUVxFFaPhvQT1fv5TdHt0O314Jg 1biO3BYuwOac9cTmQgrKm/6UaWaAgABh+fwQc2/e0UUdKcY5SaLswic1ZmvBay9MBN wd1ZRMh40GV/fKtR1SYXwtlxN0+irCMogQkKKGyp/aS+R6FfOMM0qmyPWaBUMzFlw6 BCrQBvqAPilRQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9D4B46932E for ; Fri, 16 Jan 2026 10:15:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583721; bh=SUSkBI8j+EpwdUcXOtqE8F7qM8uOBMjpeyT8mtq0WEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QmOjzYEWMHFSwfdKIUgFX5ZI8Mzkri9Mp/BYwfHLH6/v233FnVLuJmVhJM5dKam/+ SxbsXOCNxe3NeLNV5K2T5El51o5A3NCEpZfHSKzAeorjCWor47w6CXbBPH5U4oFLty 0EF1ZzGSJqGa1swG+/zXoP1lD2LH0OgL70uEfGUgtcf7bod+VddXHgulyxtXmdmAv/ GIabKwVLH5jwUsUKygL9DQTnXfkKZqTvlf+7vxrNTsHuUjHnv6MQ9TltVzx9t7UrMN lcBSPngrAaRZfAPL8ArIzvZWau7/pmNu29H51C0pD9ir5dGfGhjro0nxxpRf7if2li tbQPptgGxpadw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 865EB6913F; Fri, 16 Jan 2026 10:15:21 -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 Emk-5gwdx4QD; Fri, 16 Jan 2026 10:15:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583717; bh=il9gqbP/KH6e4AvXZvJsQqw5ezzLkS0w+S2kRodLc6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dkd1iAKzmEptKHzNxZnsXSImcisHHxV/Dg1Z2LPCzt8Qldf1yTNMVgWF/VmEVIIJW 7QnwR5i2b4zD3SDaMNzATUx9G6QP05rFqMtF6vpVmBQLoJjXdzFYB419oaH+bBEtfw KA2x1hHPK2Lf73Jm2Fp2/Ip8NecXYKZ+JGl0RkEN7qkjxE0u0ESEzCGMZG8USlj2nw K/EvbXNxTBvcr2MnSc0PNMTfA/w4yg2u1dOSEKWB7G8UH8606RlwzBvXNPmFFXkQNc EjJwztI7HA+gMtQycimk61p3HzCcBKMji2pPdsJ0LkKTfU8LYBtoA1EbjR4FvU6xVW k68e84Vp86EUA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1A6676932E; Fri, 16 Jan 2026 10:15:17 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:11 -0700 Message-ID: <20260116171424.398597-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YWF4QQPQ6BSIR4TR2L35342CBADUYIXF X-Message-ID-Hash: YWF4QQPQ6BSIR4TR2L35342CBADUYIXF 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 09/14] video: Move xcur_frac into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1538 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=1768583728; bh=AhJLhx/g5GMlC2jAH8KcdysaT717pRrFAfigEXWCFAw=; 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=pfeHAD3X6cZY9YdJ2/V4AS4KUds47eKvlFRTLrVhGqFCqoLr7M9MnzdpvwPEUzGg1 2igNf1G09Lifq6P4+RH4ktblghXMWfKbDsNDeWbzamSAWxgXSoYlCRIfbZ8phsZT8b 85Ci3+i8YqZjLb7F/y7cDH4voGcs+SHjC8RDv+YtyvEypJlKMpJaytBfATQ0/1n1l7 qvZ6eDrLJR4YCpMsWsDKjBC2kvOTi/LENXbqEE+ckuBAZVJ04p6tAU1xu7QOui33Mc SZw6qDCKUnq5erM/AB6oEv2ce4qtsD3Hgrjv93LHcy+v6sVw2Z8+WYVNNjnqMqD43j BCB9RzSQNWMQA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3EFA7693B2 for ; Fri, 16 Jan 2026 10:15:28 -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 qrBUVXAb7R9m for ; Fri, 16 Jan 2026 10:15:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583728; bh=AhJLhx/g5GMlC2jAH8KcdysaT717pRrFAfigEXWCFAw=; 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=pfeHAD3X6cZY9YdJ2/V4AS4KUds47eKvlFRTLrVhGqFCqoLr7M9MnzdpvwPEUzGg1 2igNf1G09Lifq6P4+RH4ktblghXMWfKbDsNDeWbzamSAWxgXSoYlCRIfbZ8phsZT8b 85Ci3+i8YqZjLb7F/y7cDH4voGcs+SHjC8RDv+YtyvEypJlKMpJaytBfATQ0/1n1l7 qvZ6eDrLJR4YCpMsWsDKjBC2kvOTi/LENXbqEE+ckuBAZVJ04p6tAU1xu7QOui33Mc SZw6qDCKUnq5erM/AB6oEv2ce4qtsD3Hgrjv93LHcy+v6sVw2Z8+WYVNNjnqMqD43j BCB9RzSQNWMQA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2282B693B0 for ; Fri, 16 Jan 2026 10:15:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583726; bh=m+DV1eqJanbr3/IHLUOGblyRrtsrMN+F1AJdJQD2XFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QPxtbcrHLIKSR/in8GhvGcppO0ZezW+kxOXliCOdlB0FPv0pkx6vFsYDj+Mg4xsS5 webiyLk3uE3or4ZqddNypqhWKL3QKsZLerU/sJnQfM0ZQrRFOk7u4FokNZAkK0dBIM kmhjsXhJEObXX/AFyeRJk24HaWAR3swhdRbuTOP50pdA6H9QtgTrf7w5rKEVe/XTzH zhga45WYKzaB3DPTmF2GGaxQVefUozPxJtUPJRnlkSkR2pGFLw+2m9+OIZh+Zi6xwN P0sOBlBOa7inkt47cbKdi+Atp/etxrSxMqXVt2nLQ7La/zA7iXBJI1OnlQ81NG64NG kh1R7kxhYCRwA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 30D266932E; Fri, 16 Jan 2026 10:15:26 -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 ET69hy6wmJ5P; Fri, 16 Jan 2026 10:15:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583722; bh=htDl+EOjWpncI+bd/fQxxOCuHv0Ks4fkASGonmh1KQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X9olHd6r098I3baUtuQvcHFId15Ykh9LfMmk1u8vGQBgmOQvjtLkA76p9Qer8KB0k 3qHvfTMitdE32xgcFNAfC9THtpZ5U4gu8+9/rJWsbyWsOVcY/qeDNxkOyYaAkOQF7F lwtzvMjZYkCeB6101iWAMYk3G4sBCx4gma6ICf6HkCSBXbiG6+RO3to3uoyfqsgpL4 A4C8ksks40lZD/QmIOfwDwGHxcFoPH7pPsh8eQYTtbo7bwylMD76fYCHqkApkUhoAn GnZ+KTWUFz41/SvKWIXvOgnjaVv3wDrBQYvZPSmf3NO8mj6g0K/7OUS5uCthDT1PuY Zf9oevmk4qEqg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B300C693B0; Fri, 16 Jan 2026 10:15:21 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:12 -0700 Message-ID: <20260116171424.398597-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FWLWAWPUWMF47AD7I4VUTI2RGDATXF6E X-Message-ID-Hash: FWLWAWPUWMF47AD7I4VUTI2RGDATXF6E 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 10/14] video: Move ycur into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1539 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=1768583732; bh=LSIYfEavN4RLFyuV4j6j3FYJGxE/BEuUiv+QW9/oDDQ=; 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=b7pRn1sJ/u0QAoFUGZ8h7fOFCX61BHc+vwicNd4UHmtPpeKdAdX4k1BmNXmZGhq+x 5++kN1XV7fHgHjQ3cC72cUzihxAC4cOO8WjNHNuA7gSgfK86vsaEbTS+jcn/EFIkyZ oQpe1Z41bWJLaIGK4nUbqKw4CP9fDWBA92UyQNTkg3rNKobwZarRUCpkQY2+jS9vB3 yjlGEWaTdPvWS25SXJ6TuFzKl23wR4z/LzF3tg7bTcVhkKym2TMH/q9n5uLgBONN9G +FQ7si6XfAaZfYktQrTtQgTO8wTkJIPYZG5Otxh6bEPbwJfROGAwLte24a0EIHESq9 6BvICY2CtGecQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9D0B2693B2 for ; Fri, 16 Jan 2026 10:15:32 -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 C6VoZwAhz1nD for ; Fri, 16 Jan 2026 10:15:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583732; bh=LSIYfEavN4RLFyuV4j6j3FYJGxE/BEuUiv+QW9/oDDQ=; 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=b7pRn1sJ/u0QAoFUGZ8h7fOFCX61BHc+vwicNd4UHmtPpeKdAdX4k1BmNXmZGhq+x 5++kN1XV7fHgHjQ3cC72cUzihxAC4cOO8WjNHNuA7gSgfK86vsaEbTS+jcn/EFIkyZ oQpe1Z41bWJLaIGK4nUbqKw4CP9fDWBA92UyQNTkg3rNKobwZarRUCpkQY2+jS9vB3 yjlGEWaTdPvWS25SXJ6TuFzKl23wR4z/LzF3tg7bTcVhkKym2TMH/q9n5uLgBONN9G +FQ7si6XfAaZfYktQrTtQgTO8wTkJIPYZG5Otxh6bEPbwJfROGAwLte24a0EIHESq9 6BvICY2CtGecQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8CB16693B0 for ; Fri, 16 Jan 2026 10:15:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583730; bh=dvGlgPsWnPqYtnMlGPH4zxoav8A6tVfU3RAZC7GIq6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uF5/Fv6bl9/ZMty7rUrt4dFDaLq0xFLyqZ1KZxRscoOYDyry5k/HLBfTH1VSj0IDB UGMQg7xWs4Yk8RggIOeFz0s5igP34ocM6TjOUj+1feTqU8Qk9N3p+UYH2a86gLqEMX rqDvjZqivPE0Ajbp8+aOP5ynmegMVdhMJTggMe7Wd6ip8IdljYkoXjLH7Otji9qnLc B+NkUf+XgF8FSL/dMN01ROOYAQKF6+c/iwXVsYgIZhu5Wklpq+FzZdP2KlGOONOFft qiM/bCVtyKL8TzwPc0uGP3BHW+RAN+xnFq289i8cQY5q+pK41xTwTzZmfaMWP8jlG9 x4xFukwF/sYyw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9A90A6932E; Fri, 16 Jan 2026 10:15:30 -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 6POJS-Kp81Db; Fri, 16 Jan 2026 10:15:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583726; bh=f4TtYDj8DlgekYE/WJXZZnFfN8mf+38+z8+w9kZ8wQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GTcXghILCcbXkU1vO9sp3B9W30Lyda9o2z1peIqw8/VnaqfpYxImYNhG8qogbYdu7 8yxbIghM3uLa9JdFCaANdjO/61eh12eQdmqlj14I7N/ai4+c2P04ZGgWcbHeeDMjHc b7uGc73v38vmwuQM49ICc7Xi7dT7ZjeljslyB/OGUU5HUB/Gc6QuknxdeUhx/ejUJ5 SwKGC6kX1ZpkPgw364h34e7s9SQWuVW1LV69WStxw2H7g7vd5KfThEAsh5H9/kWKce eKGTbDvl4VoambROBKKWR9KxIdBoC7PoEw0btqOyGKamXD4jcESLWjMJYCGjG1H5Vr pALM4y9ZZUHWg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 510926913F; Fri, 16 Jan 2026 10:15:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:13 -0700 Message-ID: <20260116171424.398597-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GY7EDAPXXVPH32Y6DCWNV7OXYL4LBNUW X-Message-ID-Hash: GY7EDAPXXVPH32Y6DCWNV7OXYL4LBNUW 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 11/14] video: Move last_ch into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1540 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=1768583737; bh=NuygM4CRMa0EAzrILgxivuiiRj+JOKk4ftJVqf4JNCE=; 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=Q5W7w+3ygMj/MAcoHoQudX4NHoE+OUk1ekfLfmDCn5+qJzWbpLWSf6buvgT6Sh+An OITynYITLR6iqmaXEywfpOAlglbrlNIv1VUwtThGq/KmawG2QlmCmU8xmG4r4iufje KOQkpFF/xOhAwtoyhiQM5905ZBE75zl3JgLEI7bNd3aQe/YAsiuUBUsUqGcSi6FCB2 xpxxtVMCMgzGyjTgtfFkdyzLgPxnaO41EicZpHiV15cCTBvWNbsWlAvOi1NEWweBIF o0agyMEVeSb+/fg7uXlvxULfCUc2j9WA4EjOkaXd7nusOFXNqm09XQeIfLmuvztBld RorK4aJod12Gw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0EB546932E for ; Fri, 16 Jan 2026 10:15:37 -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 KxH51PudlKAQ for ; Fri, 16 Jan 2026 10:15:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583736; bh=NuygM4CRMa0EAzrILgxivuiiRj+JOKk4ftJVqf4JNCE=; 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=jgwk4THkSagTub0tqd73kM4+L/Jr7JXnrBZ04GYXITQOYwfL2Y6AV02ehrOmkH9AS IiTvnWdpK8kfz27qT931M4vy+juRUaKKd/pLjt9ImVrrzMaa0wahHffbWIwyXTUamJ 8SH0E+Db/EjmJIarOAhzT/82JmTTfEOU6gHOhOZRlkrF99VX9QUM04VPravljEzIlq xjYi7tzT58jQil8lpXRnZVLWfZRVTkxB1FzsMCbrK/4/kVSwNPFeyiTtS8sj2ElDE0 AjxgdkIfSCVutTlhyYslroUYHiOJr7dp2ssz0exgsOj1G7p/K5HHqSyFJKvpVIFPwr cggMUrjWK+h/A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F1C3E693B0 for ; Fri, 16 Jan 2026 10:15:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583735; bh=rlrKHJWaxgDZs5tktaz/ax6SRHpmz4bbs+SCbEOHCYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u0mLmO0PVtRpH0b2YVOyigSD8LIfSu+cdKjHstomp3DQEpJyAGW55U8rYyL1faPYw 1YynPyWrWKqNRRJGNVT337yAIkLDLNKLN762atEY+uubMlBwt+sFqTJ3/cKVKXBar7 QsS3fdFDxB+TANlJ5A5/DANrmaJ5q4ABd5BUMEh6I5cf2ZQtorzBVMg9d+sCxPA6ss ufz0Wvh9SP0AoypyxnjkDIwAkq5QqFKqnz/f+O++bmATc4xBlYsAeMOUwd5xclle51 e0uEm4LJBefWQF0V97iRG+VKsw0EZZnzkcHaIKbS1Aqzrj9Ru1Xx8cMvanQHNyB/eg fJi8d2dw4h5KA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3E34D6932E; Fri, 16 Jan 2026 10:15: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 10026) with ESMTP id pH-HiukDajpn; Fri, 16 Jan 2026 10:15:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583731; bh=+cWjD3uJLvJ9YXj3y9WnwMwRYoWiCEvXyd9G9YFV/bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wKzpqEW8GxBr06Pe4NKiSwhDw0b8fftIAdc/g1JtkqdqGsBCKMc7R2eOSo81hrgQj TGWjlizXWgvADsFuN8FpTyTc6suVkS7/eGKoA5aRe2wsp+ZVGuUC2M4vSN1IDH1I63 5bZ0Am+z18ZQdfuSqTSQ5aGW0FUuAcvQk4h0s7kEsCBmaJN7fiWuIga+WXbBABDU9x 8L77Z+M8uLYwr2CgbcIcHSvr4IHPK9xtbUInL4hL/cLV3p3GRpML5QRoVtH3X8GTgO nNYNU52sdWuuKz26OYwO7ve4nNqEd00UJchvU/BwopC4RU1cs8bIq6c2kYqjcXT46z eJFjrc/8BzSkA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id DDD806913F; Fri, 16 Jan 2026 10:15:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:14 -0700 Message-ID: <20260116171424.398597-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VKK7IVSAYT6VQQALEUZIE6TBM3RN2BGI X-Message-ID-Hash: VKK7IVSAYT6VQQALEUZIE6TBM3RN2BGI 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 12/14] video: Move cli_index into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; } /** From patchwork Fri Jan 16 17:14:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1541 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=1768583739; bh=0G3P3szNtK4pufNNXBZn1+S/+jqLfVGcUtEZa5jfHNU=; 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=pwVgPeqrslOsE7YVCfPH/wS3/Dj912ZwhMZNTB1ZvR8JrYCj/tAYUL/6eWHN65gIV TeAOA13V66KCkvqf2Ha3kcw4u63JgsdARzmKoaWOCllgZqgX51Q6eBtQw0A359cAne U533H4PMlEKSWfSWFJ7ygiX88hPrfmtf3V0LyxvwuANITxISMz+O4iMveULcDq953k ynR/5Zq49CTpYB5ltDHy+rrQsFeeVIpYSI81YPLeRowWXxLwFUrXSyhiuQ+rTFaWDl tGTRRgE2j+OZSbs6jDYT7eZQ/U2XusWuJpZOD0QoDDFuAW/G6DJ/hOiunnHUuqmoLe tJxDAAZ2KrZJw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 74BF56932E for ; Fri, 16 Jan 2026 10:15:39 -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 MXSAodJqzI_L for ; Fri, 16 Jan 2026 10:15:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583739; bh=0G3P3szNtK4pufNNXBZn1+S/+jqLfVGcUtEZa5jfHNU=; 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=pwVgPeqrslOsE7YVCfPH/wS3/Dj912ZwhMZNTB1ZvR8JrYCj/tAYUL/6eWHN65gIV TeAOA13V66KCkvqf2Ha3kcw4u63JgsdARzmKoaWOCllgZqgX51Q6eBtQw0A359cAne U533H4PMlEKSWfSWFJ7ygiX88hPrfmtf3V0LyxvwuANITxISMz+O4iMveULcDq953k ynR/5Zq49CTpYB5ltDHy+rrQsFeeVIpYSI81YPLeRowWXxLwFUrXSyhiuQ+rTFaWDl tGTRRgE2j+OZSbs6jDYT7eZQ/U2XusWuJpZOD0QoDDFuAW/G6DJ/hOiunnHUuqmoLe tJxDAAZ2KrZJw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0F545693B1 for ; Fri, 16 Jan 2026 10:15:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583736; bh=PO8NrOX+qQGJgZFLBtJkoA4pdAh9Xq9d7cvx2vnVcDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sv4N0nQsLYDHorzm3Q1KNTonYi3OKa7jKXTZErqVVooZbVEolomEWH3Xo2k0hZY/T 4K6ZCLGPVLbZ2gWzknqz1+bWOFa2Zi0Pv6WdmSW4m+aolvFwU+gY0lon6psb4THgJc 6ipBZRfSl3WdfwI2f96dyp4z65na8LjxjUE0d4a9TE4UbWoZyO0MsMDjQyGdsaAdGv 4COb/iIe62D0NvJmZvF0KB1W9coJaNA+YUTyNIsdlTxqGqrSwpaYzs36Re5ZJE0Lir 4brWDMpYTh1Cs8jld3P95ZVFYrHiUFEzKIGqN9ZSjxK8euC4y13HfTJPSmM/2f8Wep 3/zcngNfFw05g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 14F196932E; Fri, 16 Jan 2026 10:15:36 -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 5RgR0aHcV1eN; Fri, 16 Jan 2026 10:15:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583735; bh=aYI/9gc96jSq4dg9pCkyCnSrlmRObMhoiq6l9SsCaA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W7UfZN6u9qfy1kneJQAPqMo3HboO49D319aqxN+VzHfnuviXGzh437zwI9eTUBNQ8 7oKFAXHQEHhG/hYD2gj9AJ6/7K5+uKa75E2sC/ZB9HoIqYMHIYnZ9I0u23b3nzKjcJ YZnkyFLX1WQgRwe8EfTLtnZNLBh8tDq46WIPpfQBg7bny9gtHt8auEVSinyia8Oarg EIcPOeDH+MVOV6uofEoWW8T96VPNrX/7U8vIPlMZqNjKYwhQW/X1PnDEilGNXRve2/ cTs/yJ6gwXDdYCYMgAtlUPwCysdSWlBEdwgfF9wdm8ezCa1JvUncqDyv0U9PWPSzMn odGQcrEMOsWnQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 84E1A6913F; Fri, 16 Jan 2026 10:15:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:15 -0700 Message-ID: <20260116171424.398597-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JDXCCJEV65JV3RGM3AY6DHE4SCH7474W X-Message-ID-Hash: JDXCCJEV65JV3RGM3AY6DHE4SCH7474W 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/14] video: Move xmark_frac and ymark into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; From patchwork Fri Jan 16 17:14:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1542 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=1768583743; bh=wvW7J0jMSjI4cngoEFyxdaJbcAYVYTzBYDVAw3mAfxY=; 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=nDjKVCvsmt0Wiz4M/IMUBu9XZmvTW7jqJzcHts7/+vDDKZYPwGjnKTx7DGuSPW6ls YayJoTrr4EggR/xy0DRfJ8Z+gocnyWbNTeNLZcZpY3h53kHYetKUnwytycoo5FicOF wua2gOq6J+Cpv5Z1J7GcINNn8y3ylusgdD6QeS5WkBHY3op8x6vLqKxGfas2scxXAM 1gBrp8E9kOxYeHToJaLcxxTPLIMpRercjXE2LOfRbIlaOtTgLB/EeQaMkiqB7XksAL EWJ0LF099Ja7tlIXyFZUsNtskRQSMbELSkPuy+DZ3f+JZ6gWUQTa2RZy9Ayg2K9jAo uYjpvvDImIjjw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 96692693B1 for ; Fri, 16 Jan 2026 10:15:43 -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 lnDZDIgvAE3d for ; Fri, 16 Jan 2026 10:15:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583743; bh=wvW7J0jMSjI4cngoEFyxdaJbcAYVYTzBYDVAw3mAfxY=; 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=nDjKVCvsmt0Wiz4M/IMUBu9XZmvTW7jqJzcHts7/+vDDKZYPwGjnKTx7DGuSPW6ls YayJoTrr4EggR/xy0DRfJ8Z+gocnyWbNTeNLZcZpY3h53kHYetKUnwytycoo5FicOF wua2gOq6J+Cpv5Z1J7GcINNn8y3ylusgdD6QeS5WkBHY3op8x6vLqKxGfas2scxXAM 1gBrp8E9kOxYeHToJaLcxxTPLIMpRercjXE2LOfRbIlaOtTgLB/EeQaMkiqB7XksAL EWJ0LF099Ja7tlIXyFZUsNtskRQSMbELSkPuy+DZ3f+JZ6gWUQTa2RZy9Ayg2K9jAo uYjpvvDImIjjw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 852FF6932E for ; Fri, 16 Jan 2026 10:15:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583741; bh=7O26K89EkLEisPAFk2GJTufUOhsnCLPfkMyvSMyyp2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gE4CXeyWAqUzbhtTV1E7b1vC+pTcFIujt1uvg4E0r5E8Ipg41nMaeSodYm67dGdmW VBvY+mQfX9619+beL5PIffxyKs9btIBWNzaz5osWjZr7pJSbp54PkV50N9TxWqe3m6 3iHBYyfQU8v3Rhfs8Y2EOmCNigCQ/C+Atp+SABiL5n89V4BjX0ZY/aMiN2Cl85ssKH TO1KrJgu0vi7u9y2ZHoD5GXjwyuXfEqhADnRuFbNT8ym+ndZynLJTlUNi5cyWla1bZ SxqzvsovoUucMF1gmqIG1VQUqdau12ISo67bsBg1hCQ7fH2K09g5BbPYTZA5T95ssC nHBePuvwnXTdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AF0726932E; Fri, 16 Jan 2026 10:15:41 -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 GfP_Rbrt6NXN; Fri, 16 Jan 2026 10:15:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583736; bh=0W1sCuVqkqzbrZY6ZKLC85fDc2uOsAvKGnKq2dWB2mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERU1vbRfqQkYhDnISo0POCMko0i2XyekemmchhUyHbShSJmDHmt14w16aGYkOWoAh 44WoefMkUnW/T7J0GKyLHojOi4XeCkPM4K+1hzWgth0BonACjDtYgUDlVIquXWSGe4 VaOb603jmk5lLZaoYWBVAAqNqihL0kOrId3D1KTCWpRreE5fINQyhGojWIUjkr9WSA NkLpwoClBAMjbPma/g1SqSsNTkn4i7Pp0sdPNxk4o+rwY4BNtF6LqYS6qpr6w5yoHX QwG7NTcsvLXzyiCKUtB2dffossYjL8hsFFgfxTQIaINDutRAX80XIEZn257SGeVqhN ba74L64Yh0MAw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 59EE56913F; Fri, 16 Jan 2026 10:15:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:16 -0700 Message-ID: <20260116101415.14.I33b9868999de00f88d957f23cf1d62a5fe0e9cff@changeid> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NTL4G3CBFERUODOXC6CD4ZRMDUTA7S6M X-Message-ID-Hash: NTL4G3CBFERUODOXC6CD4ZRMDUTA7S6M 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 14/14] video: Move ansi and utf8_buf into vidconsole_ctx 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 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 Signed-off-by: Simon Glass --- 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; };