From patchwork Tue Dec 5 07:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 173763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3265642vqy; Mon, 4 Dec 2023 23:34:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfkTVdPMExxX1buZ5zDUbPc1HpHugtjjnHTb17LU3OoMfVypPhHjI6LgdcV/qrJIzZkY4K X-Received: by 2002:a17:902:c943:b0:1d0:6ffd:6112 with SMTP id i3-20020a170902c94300b001d06ffd6112mr1319664pla.52.1701761673698; Mon, 04 Dec 2023 23:34:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761673; cv=none; d=google.com; s=arc-20160816; b=de0Xg7a1j86b+1hbgFp52pXji1CkGyVupuam2qTxIJENJz7iVhg9NHCvyn5gGsA7C3 Ol+b1QZqCd0JwtyEHIK5wOSpos5e8nVAlKyNKrtpKYWeTUHOCr9qr7sF6eGhBonayFeH mF91xahyXKKU8SXvfp8DLUWJukMVvN98k2e37FJYF+ZFH8qVeDjOD6mst+rYDn9n0n7D Nc80Qf0FScI9lmlqDoVd996PItzeMTkzxRBi749jSqwB9gV3Z5QrkytgckckqoOrnK3O ZItGkGwV7Pk+FufN5HDMhT58+AR50gA14PQz/5SYx665yIJm8uV6ezfwaxRfOb4ctYAx SWug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0sV2eE/0/qpqClT/7Gu5C5lmb80ZWF2ytmdtjmp0qvM=; fh=OQrZIrddo55Tm+afxTOsnGwFgD38y2NNd7tU+1OGSCE=; b=DJRoJu5vAnz4UoSU5EW3pnL4j568bts22bGtP6QEVGhtpNeATHRtq5p1hgcJqDq3uG glBgotQwxwRotzYHDjNEZL3GgiueEGR/UHg84ce+agv/tdB2OwpyPYEQIr0FtUdenFvP hB4PDppQYGSRvVJhd+obGwPlrcZifYDtPg17xx4XrEJ7kwwlTzico38PCEOACj4IlkWL lfxddSbbfh+IPOOfhl3svhlX36mIoczoXvCTiE+njggF7Kl7o7R5vSD6bOLNory85hr8 JhAAW3RDxMOzY8BKTv6hXOY4NU0y6OH1gndO/cD2uX/UJ/hXdhc0TJUTxdPA0LtmBinY Uhjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=CbT9QWaE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z16-20020a170903019000b001d0c6fd313fsi507406plg.157.2023.12.04.23.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:34:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=CbT9QWaE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A380B809E221; Mon, 4 Dec 2023 23:34:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234796AbjLEHeT (ORCPT + 99 others); Tue, 5 Dec 2023 02:34:19 -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_J=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 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:34:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426448548887274 X-GMAIL-MSGID: 1784426448548887274 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=DEVNAME:0.0 style hardware based addressing in addition to the current console=ttyS0 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 +int add_preferred_console_match(const char *match, const char *name, + const short idx); + extern int console_printk[]; #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 = printk.o +obj-y = printk.o conopt.o obj-$(CONFIG_PRINTK) += printk_safe.o nbcon.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o obj-$(CONFIG_PRINTK_INDEX) += 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() only. + * + * 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 = NULL; + size_t namelen, optlen; + int i; + + namelen = strcspn(str, ","); + if (!namelen) + return -EINVAL; + + optlen = strlen(str) - namelen; + if (optlen > 1) + opt = str + namelen + 1; + + if (namelen >= CONSOLE_NAME_MAX || optlen >= CONSOLE_OPT_MAX) + return -EINVAL; + + for (i = 0; i < MAX_CMDLINECONSOLES; i++) { + con = &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 = 0; i < MAX_CMDLINECONSOLES; i++) { + con = &conopt[i]; + if (!strcmp(name, con->name)) + return con; + } + + return NULL; +} + +/** + * add_preferred_console_match - Adds a preferred console if a match is found + * @match: Expected console on kernel command line, such as console=DEVNAME: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 preferred + * 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 = 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_cmdline.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 +#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=) */ - -#define MAX_CMDLINECONSOLES 8 - static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; static int preferred_console = -1; @@ -2458,6 +2455,10 @@ static int __init console_setup(char *str) if (_braille_console_setup(&str, &brl_options)) return 1; + /* 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=", console_setup); +/* 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 From patchwork Tue Dec 5 07:32:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 173764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3265841vqy; Mon, 4 Dec 2023 23:35:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDG3JOuoymqsfXfA+MGfLiHvCT6GhFcQuzWc0WheAxqVarj4McI5vIe9jM57Z4Q2EbyFC4 X-Received: by 2002:a05:6a20:e595:b0:18f:97c:8a3b with SMTP id ng21-20020a056a20e59500b0018f097c8a3bmr5465334pzb.102.1701761709345; Mon, 04 Dec 2023 23:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761709; cv=none; d=google.com; s=arc-20160816; b=pelNBESHxToYgiiksA2aKhagYthmV0/P4xT0ENx5/vvBEYxHb/pG6YaYWMXJTtV9HG k8r+g2G5KbpoSNbHMJOro2KrZs+txQM++vILMZAqXMAtuP1nX9+zVVC/ZUD/MfJizFDY BaFl7jxUipspPZuAMv3Qppaw1VkIQPV1fDsGBvC5K15NzXdtMm3V0piJKHNNPbGN9JaW EPHvqFwQN5rXXAWY3YuGLNvafDv8nyJvrULtpFGfqkUQaS2akOEJY6++plc1QC88bb8b xlpngn8Zhtzy75SEr2qNC+vVha6ohDlO6wGvYyADjzHnUZozKjQTcnCzDydYIDS/WoZG U/Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MMuS+qd1fR11f3yVamkpRtWpH5jfkM+iuYbwiGhl+Ls=; fh=OQrZIrddo55Tm+afxTOsnGwFgD38y2NNd7tU+1OGSCE=; b=rwZKPX7jmx2TpZBNCWOAUX5b1eQBjOoagVQO1+B33ds81EOXotjlyUmWrEGNSMnlSh YGUoPcAnbHHkkMHBAz+VZ7zLUiTElSJjzs+5XAYMokvTAVniLj6aU2D5gsMot2r0PXpO sAzxeXly/8zCEXWCFR7BGPO2Q/8qxtfhTSc8Gr12mQCSmmFfixfw0jz5K2wBH6tTDXtM KwWHeuoIWtLJUyrtPRyrE1K9O8fchjFDn63XgwkJPLa3xj48MgHxmI5wB7aPA+Xg6w9U 4f9MKsJJz/1v8svGQJgYZlO3QDj4MHVo0S9YnTk3B1ASzFpZuEolVAPVYvd3txD4t/Lu N3Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=dScPxv1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z9-20020a17090a1fc900b00286e753e2efsi254123pjz.141.2023.12.04.23.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:35:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=dScPxv1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DB99480A851B; Mon, 4 Dec 2023 23:35:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344331AbjLEHey (ORCPT + 99 others); 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_J=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 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:35:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426486025467544 X-GMAIL-MSGID: 1784426486025467544 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_base.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 int serial_core_register_port(struct uart_driver *drv, struct uart_port *port); 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/serial_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. */ +#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); } +#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 = add_preferred_console_match(match, dev_name, port_id); + if (ret == -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=ttyS0, and a hardware addressing based console=DEVNAME:0.0 + * style name. + * + * Translates the kernel command line option using a hardware based addressing + * console=DEVNAME: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 = 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=DEVNAME: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_core.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 *drv, struct uart_port *port) if (ret) goto err_unregister_ctrl_dev; + ret = serial_base_add_preferred_console(drv, port); + if (ret) + goto err_unregister_port_dev; + ret = serial_core_add_one_port(drv, port); if (ret) goto err_unregister_port_dev; From patchwork Tue Dec 5 07:32:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 173765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3266093vqy; Mon, 4 Dec 2023 23:35:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLUd9FWDcAmFqvRfsGcsOOUgcWCfdoqdmqNoA4KrFJulK3HFQnKyYYgIykVndZlWe/gz2L X-Received: by 2002:a17:90a:e7c4:b0:286:1e90:fe2f with SMTP id kb4-20020a17090ae7c400b002861e90fe2fmr848253pjb.15.1701761749207; Mon, 04 Dec 2023 23:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761749; cv=none; d=google.com; s=arc-20160816; b=A89dxAJsTaomEivNjg3xH/PzUPVrFp3TyIyqSmHjXrguO66HnU+fElO55PQsBTs51W 6VSqexSIYOnq4MBskfNW9uSYCwAe1/0ipKS6TIhdxxzJGwvPg9lEjIyR+EiY5KJr4tc7 vURtQhXK3Bdw4uA8CjaFVKHkLdiqIALhi13AkZ6pnv7qZyZ98ejWrow/BSlM4IBt9WwM otjgMEl7i5AKXTtx/NXVrC7aBB+QCWw0RNTyJbWcoCIzMpFmKhWKPUAQPdLPbFUrX/5Q hzYfTxZj4FVM1swA/MMtT4CGh4dygXZxk96wjfknS0OLdMC0VCAS7lKNCo09tL6NZUBs fNIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N1BVdxh8ER8Wxvu7pAmmRB981/3DLJQg53C27T/UvIc=; fh=OQrZIrddo55Tm+afxTOsnGwFgD38y2NNd7tU+1OGSCE=; b=jNOqH/L1xy5htrbzKJpKHxHTdJkOVvC6cn8X1phQG735lztAmPl4ZZG9/VBFfCEoq7 uMyyyxMTG99xvtpDcc7OUsH3zXXFBHeveBcEN4GTBpAl7VMwoHuMNGmYVRjle47o+I+E mMpeVEQfAQv06C2BfO+O66DMdB9ILz7GKQ9QM2kRTa/LywE8GQHrlgkuNVax2GGkqOn6 wJ/Y/wNtnmGvdeBSB80qpZXyYI1akuYnzdbp/R47bWtheHFQSo2zPuKXkPpEcfux5fXn E88oA8RQasTnW+hY+Ae25fXNPi2mRFF7vM7wO/65Rf4KUzHfdKJacVETBWh6eCmi4gE8 OIVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=iiapsB0i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x14-20020a17090a46ce00b0028669c1a54bsi5722543pjg.141.2023.12.04.23.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=iiapsB0i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C1FB780A3114; Mon, 4 Dec 2023 23:35:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344587AbjLEHfa (ORCPT + 99 others); Tue, 5 Dec 2023 02:35:30 -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_J=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 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:35:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426527943547360 X-GMAIL-MSGID: 1784426527943547360 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/serial_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) #ifdef CONFIG_SERIAL_CORE_CONSOLE +#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 = NULL; + int ret; + + switch (port->line) { + case 0: + name = "ttya"; + break; + case 1: + name = "ttyb"; + break; + default: + return 0; + } + + ret = add_preferred_console_match(name, drv->dev_name, port->line); + if (ret && ret != -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_driver *drv, struct uart_port *port) { const char *port_match __free(kfree); + const char *char_match __free(kfree) = NULL; + const char *nmbr_match __free(kfree) = NULL; + int ret; port_match = kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), port->ctrl_id, port->port_id); if (!port_match) return -ENOMEM; + char_match = 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 = kasprintf(GFP_KERNEL, "%i", port->line); + if (!nmbr_match) + return -ENODEV; + + ret = serial_base_add_one_prefcon(nmbr_match, drv->dev_name, + port->line); + if (ret) + return ret; + + /* Sparc ttya and ttyb */ + ret = serial_base_add_sparc_console(drv, port); + if (ret) + return ret; + } + + /* Handle the traditional character device name style console=ttyS0 */ + ret = serial_base_add_one_prefcon(char_match, drv->dev_name, port->line); + if (ret) + return ret; + /* Translate a hardware addressing style console=DEVNAME:0.0 */ return serial_base_add_one_prefcon(port_match, drv->dev_name, port->line); } From patchwork Tue Dec 5 07:32:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 173766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3266243vqy; Mon, 4 Dec 2023 23:36:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0MibP/MSDHtM79rTnqR0mA5MVVu4STNBAr2wF0k4y1M5IKJFdrZRtBkUJAoH/09I4U6aD X-Received: by 2002:a05:6a20:2214:b0:181:15:5755 with SMTP id u20-20020a056a20221400b0018100155755mr5057973pzb.56.1701761780485; Mon, 04 Dec 2023 23:36:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761780; cv=none; d=google.com; s=arc-20160816; b=PAKHxEYtAnqblM8qLz7m7o3ZAj4XeOtfE+wCgLqCeQZJnB+UYFagaLuFj2poh/ubXQ Z6xf+vdp/Hjz3kXNYYl6Uldw7WlNabCtpVu5mIYTO+5vp/oBdFlKd3gAMNmteuWJrJKU WCP9blhsMhvhL/ZLhB6Ub2waSeNzmkBU/vRyEMbm5b5eSj1pkfQu92bf6N/xWgBWGSUU mUjRnq36JhpggIRqSsUsaz7OrP8PYRL56Ef25sFfkR+29eLJFYRsmazujAPpCI3JgHQ3 QbLaFvG35/o9pORsA1g5T3o/32GaozaJesj7S65OBiNq4/JrQlyNYgaX5B3UTseJiGhX Q0rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=54xGuup/UmdGELeRKFDlzpZM5tgkUbP0ZgeeXRy3GBc=; fh=OQrZIrddo55Tm+afxTOsnGwFgD38y2NNd7tU+1OGSCE=; b=VNdIBWfltTU+2B3u4odBIScG0piTd87rUoQ2IO/wgyW0Q9S7s5DG+cIEO+3UXIXcqr PpzpElfouutZaSrtSNxltmO1Kv/v5EU7ziVV417GMppHAWQ7im4uMAdME05cVnZctIpV sLNkQphWRG9P4P7FusxFo7etONC3SMaPkryqMXPb4Z0j4eXPRpEyr2usUZsCC/5//960 CjxsPa/HbVAgDS57KQA8S5mMF59YQVlnrsHRSmjZm4sMQQvfC1CVjDnVVTUPuGxuKQhm Kya2Y27uFyAiWVgUyjTYczR4XDCSAkWqJYyqhiUai+/uk2bWHKtzoSVCgOdgnDY0SCDr flag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=dfOVSwKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ca23-20020a056a02069700b00578b487825asi4405374pgb.208.2023.12.04.23.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:36:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=dfOVSwKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BD4F280A281E; Mon, 4 Dec 2023 23:36:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344587AbjLEHgG (ORCPT + 99 others); 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_J=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 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:36:15 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426560955673919 X-GMAIL-MSGID: 1784426560955673919 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 @@ */ #include +#include #include #include #include @@ -517,6 +518,35 @@ static struct uart_8250_port *serial8250_setup_port(int index) return up; } +#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 = kasprintf(GFP_KERNEL, "%s%i", serial8250_reg.dev_name, idx); + ret = add_preferred_console_match(name, serial8250_reg.dev_name, idx); + if (!ret || ret == -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 |= irqflag; if (serial8250_isa_config != NULL) serial8250_isa_config(i, &up->port, &up->capabilities); + + serial8250_isa_init_preferred_console(i); } }