From patchwork Sat Jan 17 00:56:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1552 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=1768611484; bh=300RAiaePuuVQp+IEiXZTCpXVE/nTrkIuD6EliiU4JU=; 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=VGpd/9ftDwwHAawL5KocAd9QmD4xBxm8VzZwe/ITvxjPvfrxwQgisBkXIM0yDflF9 jTnqyWK8Rt0fJe+ZNoPob+au3z/r4dBUWZ1ol4H/GbEYQMpWCgVClsgCYFW5oPmpYD sdXj0E0CidEVoJPZtSEpkru4cgm2HHuxtDuPfHlKV8VTbOCruz1aNwwO668t84JHL0 jQp7bDDsL1/XKs14rd+x7oR1ODhxDG83/Zveh30FjGzV1ov+ebdqoRQhmmGe0X9Ypo UP+hBHSsA7jrDASGUkZT48Iv4yozXJR5ObpXEqXMojX7q0JddZwdz0cmyDucmV7tR4 rNLI84c0c1Gqg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A9ADC693E9 for ; Fri, 16 Jan 2026 17:58:04 -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 0IPysS9rlNmZ for ; Fri, 16 Jan 2026 17:58:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768611484; bh=300RAiaePuuVQp+IEiXZTCpXVE/nTrkIuD6EliiU4JU=; 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=VGpd/9ftDwwHAawL5KocAd9QmD4xBxm8VzZwe/ITvxjPvfrxwQgisBkXIM0yDflF9 jTnqyWK8Rt0fJe+ZNoPob+au3z/r4dBUWZ1ol4H/GbEYQMpWCgVClsgCYFW5oPmpYD sdXj0E0CidEVoJPZtSEpkru4cgm2HHuxtDuPfHlKV8VTbOCruz1aNwwO668t84JHL0 jQp7bDDsL1/XKs14rd+x7oR1ODhxDG83/Zveh30FjGzV1ov+ebdqoRQhmmGe0X9Ypo UP+hBHSsA7jrDASGUkZT48Iv4yozXJR5ObpXEqXMojX7q0JddZwdz0cmyDucmV7tR4 rNLI84c0c1Gqg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 978D2693E6 for ; Fri, 16 Jan 2026 17:58:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768611482; bh=qSWY/4czXIebmVhAo+dPCu31IYlkaGnT/BySBNGfp/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M9x/wGnZtHOna3ntRU915KYZKaHlc44rTo2/vvYnSymyWhcRTfAn+Yenp3anTI0fk 26NJkvkBaJ8BzeEcJNv1QqL++k8MANpUers23IHQhzs7uB4jDZt36wvH8GWOBljvu0 fQoYSvGzvC9D9f1Wo4dbRFieLHrL0vig3pfmcMa1Mz5vHOMpiM5+oqiLebAsmzCysv RrKppTe35S8AVO7Tt2ClhhFuO8GKSN6A5zNCsAp5zSt9L31fSwR61/h/7+wV485C0/ 9qGjE0JJiZeFd2RU2IfgZkZae69fes9Lxru9IyuRkmXrojD2uD1fn66Syp991gSzlb su67qCTdVqrSQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 287A2693D7; Fri, 16 Jan 2026 17:58:02 -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 TQT726S5S-ig; Fri, 16 Jan 2026 17:58:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768611478; bh=tptlXywm8JNIB10ZObDXgFRP0wBjui0yMmElVtZvmMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+azO14VfeR51A+wgAF0Eqwlna0ecA/UyevPmUhTVC9UWGqhGALMMudZmn3j1dxmT FW3f6C2eNXfjKGM5eReAM8eGr1AXqdiIxQslhcBIh6FCbhJGpNFdZe8TD8bbJNhXGV rhPFkrqE2akxg8icT18CrkKhE+IMPq3CZQ941FZuFQsoZ9qv1Cd+o6CSjgMqycA6LQ Lo1GO9CihsOq34CSSJxi6M82yBglIQl5n8m/J7vuEGfyfmDkxVUb+Y3rWho6roUUQ9 mT0wkzp4WXzmuWA9Pf5E1x2bGNO57iXKdxq+RijGuHlEezJoQ2W+iyyEkpDPCOuOp8 Jn79ybgTRH+Eg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C9411693B1; Fri, 16 Jan 2026 17:57:57 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 17:56:48 -0700 Message-ID: <20260117005702.1684841-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260117005702.1684841-1-sjg@u-boot.org> References: <20260117005702.1684841-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5X3T2MHBGPTR2SC7LTSANKAVFXLNPQRQ X-Message-ID-Hash: 5X3T2MHBGPTR2SC7LTSANKAVFXLNPQRQ 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/18] video: Allocate vidconsole_ctx dynamically using ctx_size 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 Change the ctx field in vidconsole_priv from an embedded struct to a pointer, and allocate it dynamically in vidconsole_pre_probe(). The size is taken from the ctx_size field in vidconsole_uc_plat, falling back to sizeof(struct vidconsole_ctx) if ctx_size is 0 This allows drivers to specify a larger context size if they need to store additional per-context data beyond the base vidconsole_ctx. The context is freed in vidconsole_pre_remove() along with the cursor save data. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- board/atmel/common/video_display.c | 4 ++-- drivers/video/vidconsole-uclass.c | 18 +++++++++++++++--- include/video_console.h | 17 +++++++++-------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/board/atmel/common/video_display.c b/board/atmel/common/video_display.c index 4d6ac3a740e..55a49b45f16 100644 --- a/board/atmel/common/video_display.c +++ b/board/atmel/common/video_display.c @@ -68,8 +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->ctx.y_charsize - 1) / - priv->ctx.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/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 1ac8e2ddf3c..05426138b09 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -878,9 +878,18 @@ void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old) /* Set up the number of rows and colours (rotated drivers override this) */ static int vidconsole_pre_probe(struct udevice *dev) { - struct vidconsole_ctx *ctx = vidconsole_ctx(dev); + struct vidconsole_uc_plat *plat = dev_get_uclass_plat(dev); + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); struct udevice *vid = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid); + struct vidconsole_ctx *ctx; + uint size; + + size = plat->ctx_size ?: sizeof(struct vidconsole_ctx); + ctx = calloc(1, size); + if (!ctx) + return -ENOMEM; + priv->ctx = ctx; ctx->xsize_frac = VID_TO_POS(vid_priv->xsize); @@ -914,9 +923,12 @@ static int vidconsole_post_probe(struct udevice *dev) static int vidconsole_pre_remove(struct udevice *dev) { - struct vidconsole_ctx *ctx = vidconsole_ctx(dev); + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ctx *ctx = priv->ctx; free(ctx->curs.save_data); + free(ctx); + priv->ctx = NULL; return 0; } @@ -1036,5 +1048,5 @@ void *vidconsole_ctx(struct udevice *dev) { struct vidconsole_priv *uc_priv = dev_get_uclass_priv(dev); - return &uc_priv->ctx; + return uc_priv->ctx; } diff --git a/include/video_console.h b/include/video_console.h index 72bc0e5b0db..0e9784c8e3c 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -152,24 +152,25 @@ struct vidconsole_uc_plat { /** * struct vidconsole_priv - uclass-private data about a console device * - * Drivers must set up @ctx.rows, @ctx.cols, @ctx.x_charsize, @ctx.y_charsize - * in their probe() method. Drivers may set up @ctx.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 + * @ctx->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 * - * 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 + * 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 - * @ctx: Per-client context + * @ctx: Per-client context (allocated by the uclass) * @quiet: Suppress all output from stdio */ struct vidconsole_priv { struct stdio_dev sdev; - struct vidconsole_ctx ctx; + struct vidconsole_ctx *ctx; bool quiet; }; @@ -461,7 +462,7 @@ void *vidconsole_ctx(struct udevice *dev); */ static inline void *vidconsole_ctx_from_priv(struct vidconsole_priv *uc_priv) { - return &uc_priv->ctx; + return uc_priv->ctx; } /**