From nobody Sun Dec 28 21:15:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77CCDC4167B for ; Tue, 5 Dec 2023 07:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234709AbjLEHeV (ORCPT ); Tue, 5 Dec 2023 02:34:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbjLEHeR (ORCPT ); Tue, 5 Dec 2023 02:34:17 -0500 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11B72188; Mon, 4 Dec 2023 23:34:23 -0800 (PST) Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id 7431C60354; Tue, 5 Dec 2023 07:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1701761662; bh=4xP9cJSfauOpucthPnTkf58g4HcyVjB8aEQlHWQSQnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbT9QWaEYFQLKrxaTbjS4aBKV0kxVM1AE//mdrOCn2xvsSTY+ec36le42LxOTqzfL hdBZx6Qs151OA27uuifHl0cbtcFYqyZ5Qn56Thmg6gv8/hnez9iX0mGniY+1bU+5Bz PmeuJDdQV14RAeQIxGjrPLUm8JDr7pn6Gi3u7WsGPoN2qoAQ6XAbhi9O/lGOJ3oEIU 1+C1yEHLF9P0osH1T4yCNF7D9NeivQRcM3kmLl409vRoorenFTPzpfvIr7Qi6XUF8I dqEHYpglGEei3u8/1pTL94Qk9ZGU4yjKseUf83bq4dSw7OfSnOKqWkRHge6B3GTWwW KzVY5nHkClNHQ== From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: "David S . Miller" , Andy Shevchenko , Dhruva Gole , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v4 1/4] printk: Save console options for add_preferred_console_match() Date: Tue, 5 Dec 2023 09:32:33 +0200 Message-ID: <20231205073255.20562-2-tony@atomide.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205073255.20562-1-tony@atomide.com> References: <20231205073255.20562-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Driver subsystems may need to translate the preferred console name to the character device name used. We already do some of this in console_setup() with a few hardcoded names, but that does not scale well. The console options are parsed early in console_setup(), and the consoles are added with __add_preferred_console(). At this point we don't know much about the character device names and device drivers getting probed. To allow drivers subsystems to set up a preferred console, let's save the kernel command line console options. To add a preferred console from a driver subsystem with optional character device name translation, let's add a new function add_preferred_console_match(). This allows the serial core layer to support console=3DDEVNAME:0.0 style hardware based addressing in addition to the current console=3DttyS0 style naming. And we can start moving console_setup() character device parsing to the driver subsystem specific code. We use a separate array from the console_cmdline array as the character device name and index may be unknown at the console_setup() time. And eventually there's no need to call __add_preferred_console() until the character device name and index are known. Adding the console name in addition to the character device name, and a flag for an added console, could be added to the struct console_cmdline. And the console_cmdline array handling could be modified accordingly. But that complicates things compared saving the console options, and then adding the consoles when the subsystems handling the consoles are ready. Signed-off-by: Tony Lindgren --- include/linux/printk.h | 3 + kernel/printk/Makefile | 2 +- kernel/printk/conopt.c | 128 ++++++++++++++++++++++++++++++++ kernel/printk/console_cmdline.h | 6 ++ kernel/printk/printk.c | 14 +++- 5 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 kernel/printk/conopt.c diff --git a/include/linux/printk.h b/include/linux/printk.h --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -60,6 +60,9 @@ static inline const char *printk_skip_headers(const char = *buffer) #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET =20 +int add_preferred_console_match(const char *match, const char *name, + const short idx); + extern int console_printk[]; =20 #define console_loglevel (console_printk[0]) diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile --- a/kernel/printk/Makefile +++ b/kernel/printk/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y =3D printk.o +obj-y =3D printk.o conopt.o obj-$(CONFIG_PRINTK) +=3D printk_safe.o nbcon.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) +=3D braille.o obj-$(CONFIG_PRINTK_INDEX) +=3D index.o diff --git a/kernel/printk/conopt.c b/kernel/printk/conopt.c new file mode 100644 --- /dev/null +++ b/kernel/printk/conopt.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kernel command line console options for hardware based addressing + * + * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ + * Author: Tony Lindgren + */ + +#include +#include +#include + +#include + +#include "console_cmdline.h" + +/* + * Allow longer DEVNAME:0.0 style console naming such as abcd0000.serial:0= .0 + * in addition to the legacy ttyS0 style naming. + */ +#define CONSOLE_NAME_MAX 32 + +#define CONSOLE_OPT_MAX 16 +#define CONSOLE_BRL_OPT_MAX 16 + +struct console_option { + char name[CONSOLE_NAME_MAX]; + char opt[CONSOLE_OPT_MAX]; + char brl_opt[CONSOLE_BRL_OPT_MAX]; +}; + +/* Updated only at console_setup() time, no locking needed */ +static struct console_option conopt[MAX_CMDLINECONSOLES]; + +/** + * console_opt_save - Saves kernel command line console option for driver = use + * @str: Kernel command line console name and option + * @brl_opt: Braille console options + * + * Saves a kernel command line console option for driver subsystems to use= for + * adding a preferred console during init. Called from console_setup() onl= y. + * + * Return: 0 on success, negative error code on failure. + */ +int __init console_opt_save(const char *str, const char *brl_opt) +{ + struct console_option *con; + const char *opt =3D NULL; + size_t namelen, optlen; + int i; + + namelen =3D strcspn(str, ","); + if (!namelen) + return -EINVAL; + + optlen =3D strlen(str) - namelen; + if (optlen > 1) + opt =3D str + namelen + 1; + + if (namelen >=3D CONSOLE_NAME_MAX || optlen >=3D CONSOLE_OPT_MAX) + return -EINVAL; + + for (i =3D 0; i < MAX_CMDLINECONSOLES; i++) { + con =3D &conopt[i]; + + if (con->name[0]) { + if (!strncmp(str, con->name, namelen)) + return 0; + continue; + } + + strscpy(con->name, str, namelen + 1); + if (opt) + strscpy(con->opt, opt, optlen + 1); + + if (brl_opt) + strscpy(con->brl_opt, brl_opt, CONSOLE_BRL_OPT_MAX); + + return 0; + } + + return -ENOMEM; +} + +static struct console_option *console_opt_find(const char *name) +{ + struct console_option *con; + int i; + + for (i =3D 0; i < MAX_CMDLINECONSOLES; i++) { + con =3D &conopt[i]; + if (!strcmp(name, con->name)) + return con; + } + + return NULL; +} + +/** + * add_preferred_console_match - Adds a preferred console if a match is fo= und + * @match: Expected console on kernel command line, such as console=3DDEVN= AME:0.0 + * @name: Name of the console character device to add such as ttyS + * @idx: Index for the console + * + * Allows driver subsystems to add a console after translating the command + * line name to the character device name used for the console. Options are + * added automatically based on the kernel command line. Duplicate preferr= ed + * consoles are ignored by __add_preferred_console(). + * + * Return: 0 on success, negative error code on failure. + */ +int add_preferred_console_match(const char *match, const char *name, + const short idx) +{ + struct console_option *con; + + if (!match || !strlen(match) || !name || !strlen(name) || + idx < 0) + return -EINVAL; + + con =3D console_opt_find(match); + if (!con) + return -ENOENT; + + console_opt_add_preferred_console(name, idx, con->opt, con->brl_opt); + + return 0; +} diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdlin= e.h --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_cmdline.h @@ -2,6 +2,12 @@ #ifndef _CONSOLE_CMDLINE_H #define _CONSOLE_CMDLINE_H =20 +#define MAX_CMDLINECONSOLES 8 + +int console_opt_save(const char *str, const char *brl_opt); +int console_opt_add_preferred_console(const char *name, const short idx, + char *options, char *brl_options); + struct console_cmdline { char name[16]; /* Name of the driver */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -360,9 +360,6 @@ static int console_locked; /* * Array of consoles built from command line options (console=3D) */ - -#define MAX_CMDLINECONSOLES 8 - static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; =20 static int preferred_console =3D -1; @@ -2458,6 +2455,10 @@ static int __init console_setup(char *str) if (_braille_console_setup(&str, &brl_options)) return 1; =20 + /* Save the console for driver subsystem use */ + if (console_opt_save(str, brl_options)) + return 1; + /* * Decode str into name, index, options. */ @@ -2488,6 +2489,13 @@ static int __init console_setup(char *str) } __setup("console=3D", console_setup); =20 +/* Only called from add_preferred_console_match() */ +int console_opt_add_preferred_console(const char *name, const short idx, + char *options, char *brl_options) +{ + return __add_preferred_console(name, idx, options, brl_options, true); +} + /** * add_preferred_console - add a device to the list of preferred consoles. * @name: device name --=20 2.43.0 From nobody Sun Dec 28 21:15:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3B9DC4167B for ; Tue, 5 Dec 2023 07:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344614AbjLEHey (ORCPT ); Tue, 5 Dec 2023 02:34:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjLEHew (ORCPT ); Tue, 5 Dec 2023 02:34:52 -0500 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26CACCB; Mon, 4 Dec 2023 23:34:59 -0800 (PST) Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id 95683604C8; Tue, 5 Dec 2023 07:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1701761698; bh=p9bVc8SN18pkf5fGyGvpGvB/HvwuCPyy9bQrY91rxWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dScPxv1TXRzix3fva8AOs/JaPP4lI65gYaqPanXdcc1f25QWeaOm8Sb/gVvG/5QwQ zsEMi7JHw2bi+Cxs3kaxWB7HYs0NQFlsqkv00yzwQsMcsl8uCul7fRanNx6wKamll2 MjPaHI+cpT3q7tGAYfCbkLlrB6ADe+pTPB7eIqpS15etC8/UtQOEggzu+wtTDPHv/U LgFmN8y5WCQELZVjdP7AtWI3TT8ARiPlSoQ56Y2NOmeq2c9u578AVrhQUtrOE9YFGs 046vEiUSRFMNqb3bxbqEWo4SYlB6KLYJ6RwYU7/fVZk9OT/U2N4OihHequkOL8/1h0 eOzdAfCZIL+bw== From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: "David S . Miller" , Andy Shevchenko , Dhruva Gole , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v4 2/4] serial: core: Add support for DEVNAME:0.0 style naming for kernel console Date: Tue, 5 Dec 2023 09:32:34 +0200 Message-ID: <20231205073255.20562-3-tony@atomide.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205073255.20562-1-tony@atomide.com> References: <20231205073255.20562-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can now add hardware based addressing for serial ports. Starting with commit 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM"), and all the related fixes to this commit, the serial core now knows to which serial port controller the ports are connected. The serial ports can be addressed with DEVNAME:0.0 style naming. The names are something like 00:04:0.0 for a serial port on qemu, and something like 2800000.serial:0.0 on platform device using systems like ARM64 for example. The DEVNAME is the unique serial port hardware controller device name, AKA the name for port->dev. The 0.0 are the serial core controller id and port id. Typically 0.0 are used for each controller and port instance unless the serial port hardware controller has multiple controllers or ports. Using DEVNAME:0.0 style naming actually solves two long term issues for addressing the serial ports: 1. According to Andy Shevchenko, using DEVNAME:0.0 style naming fixes an issue where depending on the BIOS settings, the kernel serial port ttyS instance number may change if HSUART is enabled 2. Device tree using architectures no longer necessarily need to specify aliases to find a specific serial port, and we can just allocate the ttyS instance numbers dynamically in whatever probe order To do this, let's match the hardware addressing style console name to the character device name used, and add a preferred console using the character device name. Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_base.h | 14 ++++++++ drivers/tty/serial/serial_base_bus.c | 48 ++++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 4 +++ 3 files changed, 66 insertions(+) diff --git a/drivers/tty/serial/serial_base.h b/drivers/tty/serial/serial_b= ase.h --- a/drivers/tty/serial/serial_base.h +++ b/drivers/tty/serial/serial_base.h @@ -45,3 +45,17 @@ void serial_ctrl_unregister_port(struct uart_driver *drv= , struct uart_port *port =20 int serial_core_register_port(struct uart_driver *drv, struct uart_port *p= ort); void serial_core_unregister_port(struct uart_driver *drv, struct uart_port= *port); + +#ifdef CONFIG_SERIAL_CORE_CONSOLE + +int serial_base_add_preferred_console(struct uart_driver *drv, + struct uart_port *port); +#else +static inline +int serial_base_add_preferred_console(struct uart_driver *drv, + struct uart_port *port) +{ + return 0; +} + +#endif diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -8,6 +8,7 @@ * The serial core bus manages the serial core controller instances. */ =20 +#include #include #include #include @@ -204,6 +205,53 @@ void serial_base_port_device_remove(struct serial_port= _device *port_dev) put_device(&port_dev->dev); } =20 +#ifdef CONFIG_SERIAL_CORE_CONSOLE + +static int serial_base_add_one_prefcon(const char *match, const char *dev_= name, + int port_id) +{ + int ret; + + ret =3D add_preferred_console_match(match, dev_name, port_id); + if (ret =3D=3D -ENOENT) + return 0; + + return ret; +} + +/** + * serial_base_add_preferred_console - Adds a preferred console + * @drv: Serial port device driver + * @port: Serial port instance + * + * Tries to add a preferred console for a serial port if specified in the + * kernel command line. Supports both the traditional character device such + * as console=3DttyS0, and a hardware addressing based console=3DDEVNAME:0= .0 + * style name. + * + * Translates the kernel command line option using a hardware based addres= sing + * console=3DDEVNAME:0.0 to the serial port character device such as ttyS0. + * + * Note that duplicates are ignored by add_preferred_console(). + * + * Return: 0 on success, negative error code on failure. + */ +int serial_base_add_preferred_console(struct uart_driver *drv, + struct uart_port *port) +{ + const char *port_match __free(kfree); + + port_match =3D kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), + port->ctrl_id, port->port_id); + if (!port_match) + return -ENOMEM; + + /* Translate a hardware addressing style console=3DDEVNAME:0.0 */ + return serial_base_add_one_prefcon(port_match, drv->dev_name, port->line); +} + +#endif + static int serial_base_init(void) { int ret; diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3359,6 +3359,10 @@ int serial_core_register_port(struct uart_driver *dr= v, struct uart_port *port) if (ret) goto err_unregister_ctrl_dev; =20 + ret =3D serial_base_add_preferred_console(drv, port); + if (ret) + goto err_unregister_port_dev; + ret =3D serial_core_add_one_port(drv, port); if (ret) goto err_unregister_port_dev; --=20 2.43.0 From nobody Sun Dec 28 21:15:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62010C10DC3 for ; Tue, 5 Dec 2023 07:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344623AbjLEHfb (ORCPT ); Tue, 5 Dec 2023 02:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjLEHf2 (ORCPT ); Tue, 5 Dec 2023 02:35:28 -0500 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFDCC9; Mon, 4 Dec 2023 23:35:35 -0800 (PST) Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id AA5FA60354; Tue, 5 Dec 2023 07:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1701761734; bh=KP1Y9auzSXohgEBe/nM2pmeM9gWKTqhwu5purIjrJ30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iiapsB0ixP6Lf5/Ezprk5y448kv3RZzHmd3IR5yz1x4boItzQnnZN11PbSNvN4enQ lDKVr1994kakOMmX+ogP1Op4G+bxETd9sZFScCMmtNYjxc1UwE4+y2gdGMvfJwaE9s V8kI5Jt0inhXmcn+M91J/uYeJpf4vh/NYcboNbJ4JUPcibvYlOIKc0IgVghIOL7FId TkU901sjzOfjZBktm6wHzHswdJLjBfsRSQjvyiY4kqUFAIokWViTP25Dif4IJ6Bw2+ 4iVNJ1o9hw3SqFTC2GeJa7rcONy9JExiEdV/pd1/gfybmm0MI3wnz+JJk5lfEvJxVj z5jGjoOALQFpA== From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: "David S . Miller" , Andy Shevchenko , Dhruva Gole , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v4 3/4] serial: core: Handle serial console options Date: Tue, 5 Dec 2023 09:32:35 +0200 Message-ID: <20231205073255.20562-4-tony@atomide.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205073255.20562-1-tony@atomide.com> References: <20231205073255.20562-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to start moving the serial console quirks out of console_setup(), let's add parsing for the quirks to the serial core layer. We can use add_preferred_console_match() to handle the quirks. At this point we can't drop the quirks from console_setup() because it would confuse add_preferred_console(). And try_enable_default_console() would get called before try_enable_preferred_console(). Note that eventually we may want to set up driver specific console quirk handling for the serial port device drivers to use. But we need to figure out which driver(s) need to call the quirk. So for now, we just handle the sparc quirk directly. Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_base_bus.c | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -207,6 +207,43 @@ void serial_base_port_device_remove(struct serial_port= _device *port_dev) =20 #ifdef CONFIG_SERIAL_CORE_CONSOLE =20 +#ifdef __sparc__ + +/* Handle Sparc ttya and ttyb options as done in console_setup() */ +static int serial_base_add_sparc_console(struct uart_driver *drv, + struct uart_port *port) +{ + const char *name =3D NULL; + int ret; + + switch (port->line) { + case 0: + name =3D "ttya"; + break; + case 1: + name =3D "ttyb"; + break; + default: + return 0; + } + + ret =3D add_preferred_console_match(name, drv->dev_name, port->line); + if (ret && ret !=3D -ENOENT) + return ret; + + return 0; +} + +#else + +static inline int serial_base_add_sparc_console(struct uart_driver *drv, + struct uart_port *port) +{ + return 0; +} + +#endif + static int serial_base_add_one_prefcon(const char *match, const char *dev_= name, int port_id) { @@ -240,12 +277,42 @@ int serial_base_add_preferred_console(struct uart_dri= ver *drv, struct uart_port *port) { const char *port_match __free(kfree); + const char *char_match __free(kfree) =3D NULL; + const char *nmbr_match __free(kfree) =3D NULL; + int ret; =20 port_match =3D kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), port->ctrl_id, port->port_id); if (!port_match) return -ENOMEM; =20 + char_match =3D kasprintf(GFP_KERNEL, "%s%i", drv->dev_name, port->line); + if (!char_match) + return -ENOMEM; + + /* Handle ttyS specific options */ + if (!strncmp(drv->dev_name, "ttyS", 4)) { + /* No name, just a number */ + nmbr_match =3D kasprintf(GFP_KERNEL, "%i", port->line); + if (!nmbr_match) + return -ENODEV; + + ret =3D serial_base_add_one_prefcon(nmbr_match, drv->dev_name, + port->line); + if (ret) + return ret; + + /* Sparc ttya and ttyb */ + ret =3D serial_base_add_sparc_console(drv, port); + if (ret) + return ret; + } + + /* Handle the traditional character device name style console=3DttyS0 */ + ret =3D serial_base_add_one_prefcon(char_match, drv->dev_name, port->line= ); + if (ret) + return ret; + /* Translate a hardware addressing style console=3DDEVNAME:0.0 */ return serial_base_add_one_prefcon(port_match, drv->dev_name, port->line); } --=20 2.43.0 From nobody Sun Dec 28 21:15:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE349C4167B for ; Tue, 5 Dec 2023 07:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344627AbjLEHgG (ORCPT ); Tue, 5 Dec 2023 02:36:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjLEHgE (ORCPT ); Tue, 5 Dec 2023 02:36:04 -0500 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53094C9; Mon, 4 Dec 2023 23:36:11 -0800 (PST) Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id C124C60354; Tue, 5 Dec 2023 07:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1701761770; bh=fXSH3oMsVEjAG6Eqr9C167WFqrDgpOZtF9UGQTqSwU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dfOVSwKV+A03I7NcIu++5eksbifygpC+AGE8AH7L/hcrmxSYUyUxqCRGQzrZuG+D9 yMWaHvnJDLDgzb+9gZbeorWy2I7T1+gHnUPr4oPy6AwZ2mJFK3U6fOFkTdhv+useMZ TIk4XA+NoO80oiaqyj59Qs6WnpiuB31TWWC+vRM+UXzgzHrfbsOisucKxIrHfQZ1T7 crXax9KkFI5IiZ/EfRYbp046VCSnvRjO+ptPcjgypTSynnohWD2AfFSyrCysJZd7b9 zpqMDOffXNue7nlh907Tedjh4LYVNPEyi6ifksOhUC0qGyUHBF8Da3Bpp4xqF3q8uk hxCt+oSeruevg== From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: "David S . Miller" , Andy Shevchenko , Dhruva Gole , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v4 4/4] serial: 8250: Add preferred console in serial8250_isa_init_ports() Date: Tue, 5 Dec 2023 09:32:36 +0200 Message-ID: <20231205073255.20562-5-tony@atomide.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205073255.20562-1-tony@atomide.com> References: <20231205073255.20562-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Prepare 8250 isa ports to drop kernel command line serial console handling from console_setup(). We need to set the preferred console in serial8250_isa_init_ports(). Otherwise the console gets initialized only later on when the hardware specific driver takes over, and console_setup() is no longer handling the ttyS related quirks. Note that this mostly affects x86 as this happens based on define SERIAL_PORT_DFNS. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_core.c | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/= 8250_core.c --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -15,6 +15,7 @@ */ =20 #include +#include #include #include #include @@ -517,6 +518,35 @@ static struct uart_8250_port *serial8250_setup_port(in= t index) return up; } =20 +#ifdef CONFIG_SERIAL_8250_CONSOLE + +/* + * There is no struct device at this point, so let's not try to use + * serial_base_add_preferred_console(). + */ +static void __init serial8250_isa_init_preferred_console(int idx) +{ + const char *name __free(kfree); + int ret; + + name =3D kasprintf(GFP_KERNEL, "%s%i", serial8250_reg.dev_name, idx); + ret =3D add_preferred_console_match(name, serial8250_reg.dev_name, idx); + if (!ret || ret =3D=3D -ENOENT) + return; + + pr_err("Could not add preferred console for %s idx %i\n", + serial8250_reg.dev_name, idx); +} + +#else + +static inline void serial8250_isa_init_preferred_console(struct uart_port = *port, + int idx) +{ +} + +#endif + static void __init serial8250_isa_init_ports(void) { struct uart_8250_port *up; @@ -563,6 +593,8 @@ static void __init serial8250_isa_init_ports(void) port->irqflags |=3D irqflag; if (serial8250_isa_config !=3D NULL) serial8250_isa_config(i, &up->port, &up->capabilities); + + serial8250_isa_init_preferred_console(i); } } =20 --=20 2.43.0