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; }