From patchwork Tue Sep 12 11:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 138146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp371893vqx; Tue, 12 Sep 2023 05:33:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH16kMFAAGrUegZI00RayGBYlT0mwMKmvVoboDrdwDD7U6h2QvxAymG7jV33xQMYlDr5jU X-Received: by 2002:a17:90a:990a:b0:268:1b62:2f6c with SMTP id b10-20020a17090a990a00b002681b622f6cmr11595412pjp.2.1694521986726; Tue, 12 Sep 2023 05:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694521986; cv=none; d=google.com; s=arc-20160816; b=HmA0SvveSBYCtRIBe2DVACLTr6RxWX/zVu4UffYRTJPc3EiUdBhYIt3mmeXOFtmLsv 4N3/w5GlzltyINI1jQ3vBntTkP1E76iSgBYlkOoiCz9DQgqUu9dVllgWtRHQekSucri1 GB2OtTI80vcXV/HMLNJBus7BKBzJVkpWlgJ65xVGZzxD2qAUlo1QSeF8zh+q3/xibIv2 uRU5MK0EiFMv+guMaHaVnDwJqcZRrflrePGV7JlAEMTEWdbU+7tA66+SzeRmJ+8BgETC wTA8i+NPRFovDIzx7/7DMebxWW0a0SNUjdobDg+b9LHzYi4U9jbEuCMS2QeQMHWkZt31 jS+g== 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; bh=ZsmWTIj+YpkVwpoqu9EiSWN4CRc9tEaN9ASH2sPsVvk=; fh=W1MwYucirABiDn2IBBfC2XauxZd5y0E72qME+lLcRs4=; b=PPeTghlquMEOpUdm52rm5nWxnGXVwNWXjTI9NrMlZvELvDA0iqfjzjgpBxLT955cHn Y4h3lWsPfCuXEy7gYrFgx7Hkt0m1TfDuqdwVxpYWcvpxI251hZSc4Gt+yRNTOT6hMe95 6wEq0TdvQwTRvuoo44F01BmfeD+pj7TjnG0530LifxhXYY6xtSqltZXdLkfH4X+vPxMk Hno8cP+I30fks2NAzQGtYjRhH3vd79zXgp4MSMR26kOLEMjnYiJttC3aFkIREEaNPhqv A2SbH4PUAcNdM4nb5+YZH10k2trIPdpIW2DhMjqQvZ/qIdm8WBgcniSy3OwZXrj9mo0j lEOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l20-20020a17090aaa9400b0027198fe5672si7797353pjq.129.2023.09.12.05.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:33:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id C052F80AFE9A; Tue, 12 Sep 2023 04:05:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234282AbjILLFI (ORCPT + 37 others); Tue, 12 Sep 2023 07:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234555AbjILLEX (ORCPT ); Tue, 12 Sep 2023 07:04:23 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E190A9F; Tue, 12 Sep 2023 04:04:14 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 3BF168106; Tue, 12 Sep 2023 11:04:12 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness Cc: 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 v2 1/3] printk: Constify name for add_preferred_console() Date: Tue, 12 Sep 2023 14:03:43 +0300 Message-ID: <20230912110350.14482-2-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912110350.14482-1-tony@atomide.com> References: <20230912110350.14482-1-tony@atomide.com> MIME-Version: 1.0 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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:05:34 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776835087028484440 X-GMAIL-MSGID: 1776835087028484440 While adding a preferred console handling for serial_core for serial port hardware based device addressing, Jiri suggested we constify name for add_preferred_console(). The gets copied anyways. This allows serial core to add a preferred console using serial drv->dev_name without copying it. Note that constifying options causes changes all over the place because of struct console for match(). Cc: John Ogness Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Steven Rostedt Suggested-by: Jiri Slaby Signed-off-by: Tony Lindgren Reviewed-by: Petr Mladek --- include/linux/console.h | 2 +- kernel/printk/printk.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h --- a/include/linux/console.h +++ b/include/linux/console.h @@ -337,7 +337,7 @@ enum con_flush_mode { CONSOLE_REPLAY_ALL, }; -extern int add_preferred_console(char *name, int idx, char *options); +extern int add_preferred_console(const char *name, int idx, char *options); extern void console_force_preferred_locked(struct console *con); extern void register_console(struct console *); extern int unregister_console(struct console *); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2400,7 +2400,7 @@ static void set_user_specified(struct console_cmdline *c, bool user_specified) console_set_on_cmdline = 1; } -static int __add_preferred_console(char *name, int idx, char *options, +static int __add_preferred_console(const char *name, int idx, char *options, char *brl_options, bool user_specified) { struct console_cmdline *c; @@ -2509,7 +2509,7 @@ __setup("console=", console_setup); * commonly to provide a default console (ie from PROM variables) when * the user has not supplied one. */ -int add_preferred_console(char *name, int idx, char *options) +int add_preferred_console(const char *name, int idx, char *options) { return __add_preferred_console(name, idx, options, NULL, false); } From patchwork Tue Sep 12 11:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 138145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp371747vqx; Tue, 12 Sep 2023 05:32:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEC4PQDxRASoA9k9poSUuUmXM3osNgTY0v3I7jgN5SyEvnocHLK11Y+xoR/j+42Z9Hmk+Um X-Received: by 2002:a05:6870:f116:b0:1c8:bfd1:ecb8 with SMTP id k22-20020a056870f11600b001c8bfd1ecb8mr15440505oac.30.1694521970237; Tue, 12 Sep 2023 05:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694521970; cv=none; d=google.com; s=arc-20160816; b=Eq2OT4T/MlX0I+5q+6eMl1uK7DaUUUa6FNfBvigI7r0ivm8HW2i1coq5p055xiFJEh O2yJpKGv4EnpSrJ4ZdVX0dpeDq83qLFzN3FTJez1FhgiOSZ3h+vJrHTD+5Ie6B29gT5/ P0DA0gl7GsNOEUzbrLNnxHv2/YJAJse8dvieAQJbsC09JdICFq3jm5P1QowQJhKyAxUg ypsyAZboNM7hM6R5OLZr9AUJBZCT71lM92xIUH8fAwg+E2U0yb6lceyfDp+gI4CgIDy8 dN5gsUl1DakrReJcP1+rdiWMZI9fk6gG8mOAF4lDXCbFUDgwMLiK2+56fCooJ/fHonvY 3u3g== 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; bh=iGFmkklAH/4SpC7pzz/c0drG/5ssXAoE24bcpE+wVAw=; fh=n7dM+f7LjYuLx+o4gzxXNkEWC9u7qeJi6cmcRDZcVew=; b=cekX4F4n0JVT1IpkTIxdDhJQKfVx4E5srIeLO0/ZzX/YhrEsbwhi9rV6yjbkDlWfaO Xo6kLpBC8aMzAvkbCZ4/nYlur+aUh2+1D+0HlBw8btFfXIAYyRNLSJFOxi/wnglnko4C EAS6fPa9IIPW25t8B8QgFEd1y6ty/I51uOwif//2WB9cHIDGbmSKyU2VIwCqf5ZtDgRF 7qDGqXsxNG8MvcCa7QkyvFREBK11bNuHjjvJ7acuRi7fkoMAP9s8zBKVGVY342+QMVHJ ismtNyvVm/HMrEy5Oxk3ly82hh98W++cpFEdkKnQfy2Cr7NY1s19B24L1Yclcgil7cyJ 9DzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id i76-20020a636d4f000000b0056534300dc2si365498pgc.247.2023.09.12.05.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:32:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 0708380A9E32; Tue, 12 Sep 2023 04:05:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234373AbjILLFA (ORCPT + 37 others); Tue, 12 Sep 2023 07:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233867AbjILLE0 (ORCPT ); Tue, 12 Sep 2023 07:04:26 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94171B9; Tue, 12 Sep 2023 04:04:22 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 6587D80FC; Tue, 12 Sep 2023 11:04:20 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v2 2/3] serial: core: Add support for DEVNAME:0.0 style naming for kernel console Date: Tue, 12 Sep 2023 14:03:44 +0300 Message-ID: <20230912110350.14482-3-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912110350.14482-1-tony@atomide.com> References: <20230912110350.14482-1-tony@atomide.com> MIME-Version: 1.0 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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:05:37 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776835069935933500 X-GMAIL-MSGID: 1776835069935933500 We can now add hardware based addressing to 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, we need a custom init time parser for the console= command line option as printk already handles parsing it with console_setup(). Also early_param() gets handled by console_setup() if "console" and "earlycon" are used. Signed-off-by: Tony Lindgren --- drivers/tty/serial/Makefile | 3 + drivers/tty/serial/serial_base.h | 11 +++ drivers/tty/serial/serial_base_con.c | 133 +++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 4 + 4 files changed, 151 insertions(+) create mode 100644 drivers/tty/serial/serial_base_con.c diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile @@ -3,6 +3,9 @@ # Makefile for the kernel serial device drivers. # +# Parse kernel command line consoles before the serial drivers probe +obj-$(CONFIG_SERIAL_CORE_CONSOLE) += serial_base_con.o + obj-$(CONFIG_SERIAL_CORE) += serial_base.o serial_base-y := serial_core.o serial_base_bus.o serial_ctrl.o serial_port.o 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,14 @@ 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_con.c b/drivers/tty/serial/serial_base_con.c new file mode 100644 --- /dev/null +++ b/drivers/tty/serial/serial_base_con.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Serial base console options handling + * + * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ + * Author: Tony Lindgren + */ + +#include +#include +#include +#include +#include + +#include "serial_base.h" + +static LIST_HEAD(serial_base_consoles); + +struct serial_base_console { + struct list_head node; + char *name; + char *opt; +}; + +/* + * Adds a preferred console for a serial port if console=DEVNAME:0.0 + * style addressing is used for the kernel command line. Translates + * from DEVNAME:0.0 to port->dev_name such as ttyS. Duplicates are + * ignored by add_preferred_console(). + */ +int serial_base_add_preferred_console(struct uart_driver *drv, + struct uart_port *port) +{ + struct serial_base_console *entry; + char *port_match; + + port_match = kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), + port->ctrl_id, port->port_id); + if (!port_match) + return -ENOMEM; + + list_for_each_entry(entry, &serial_base_consoles, node) { + if (!strcmp(port_match, entry->name)) { + add_preferred_console(drv->dev_name, port->line, + entry->opt); + break; + } + } + + kfree(port_match); + + return 0; +} +EXPORT_SYMBOL_GPL(serial_base_add_preferred_console); + +/* Adds a command line console to the list of consoles for driver probe time */ +static int __init serial_base_add_con(char *name, char *opt) +{ + struct serial_base_console *con; + + con = kzalloc(sizeof(*con), GFP_KERNEL); + if (!con) + return -ENOMEM; + + con->name = kstrdup(name, GFP_KERNEL); + if (!con->name) + goto free_con; + + if (opt) { + con->opt = kstrdup(opt, GFP_KERNEL); + if (!con->name) + goto free_name; + } + + list_add_tail(&con->node, &serial_base_consoles); + + return 0; + +free_name: + kfree(con->name); + +free_con: + kfree(con); + + return -ENOMEM; +} + +/* Parse console name and options */ +static int __init serial_base_parse_one(char *param, char *val, + const char *unused, void *arg) +{ + char *opt; + + if (strcmp(param, "console")) + return 0; + + if (!val) + return 0; + + opt = strchr(val, ','); + if (opt) { + opt[0] = '\0'; + opt++; + } + + if (!strlen(val)) + return 0; + + return serial_base_add_con(val, opt); +} + +/* + * The "console=" option is handled by console_setup() in printk. We can't use + * early_param() as do_early_param() checks for "console" and "earlycon" options + * so console_setup() potentially handles console also early. Use parse_args(). + */ +static int __init serial_base_opts_init(void) +{ + char *command_line; + + command_line = kstrdup(boot_command_line, GFP_KERNEL); + if (!command_line) + return -ENOMEM; + + parse_args("Setting serial core console", command_line, + NULL, 0, -1, -1, NULL, serial_base_parse_one); + + kfree(command_line); + + return 0; +} + +arch_initcall(serial_base_opts_init); 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 @@ -3358,6 +3358,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 Sep 12 11:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 138133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp361035vqx; Tue, 12 Sep 2023 05:13:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/iDh2Wo9wKGUl8IrkKYqL0xtCTk91S+cWB7tJzRZ8fl9J8Tkgq94SP3wy7/TRTr/vjt3H X-Received: by 2002:a17:903:41cd:b0:1c0:c174:3695 with SMTP id u13-20020a17090341cd00b001c0c1743695mr13450087ple.13.1694520806230; Tue, 12 Sep 2023 05:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694520806; cv=none; d=google.com; s=arc-20160816; b=kpRvJEUdkWizBQ3UttI9SXf6xa7YbMrLbAMScRq2VtxaJ+ohlubIq2LR13t9vwOhZy Ppyg0g8cu+rxXoRgRVZBey5ffjWNqnjf1KcJwSwdsqBa5kJrGfatikhgEAHkyzs7bSAI inH+999PO31jlvzIJSL4KAFLBZPljzsL21d4nu7jxaRx65n6PVk9vNQd/B8KoVMfqHyo fVsw+U7qUaS+GXWfEIymjuSeMZ8c65/iVWlXjIMUpOVMmUjTUmnzepP1IYQ/6cY+d5dC LoTMr4M/AIIRM0ni+iarAmySan2vF58NSlp9/HmFd7I3aq4RHQNOtM2liIZ5ZSlvYhVg 6wVg== 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; bh=y1oawU0bYV2LD8U6dihdHbDgCZChx5QIA3SKqVndsSI=; fh=n7dM+f7LjYuLx+o4gzxXNkEWC9u7qeJi6cmcRDZcVew=; b=hOMmUq3UR4ioAAf+uPyg3EHzjzzTl8ED/Limul5F0OQzHIfkjQxoOquKmakxl8Ct77 49wr0XEX9/IJcctjEtFKaYxPsYYBD19luSuIeQ8vxuimRISHgSLTvthR1WFQtbwL/kPO Ll8y3Vuwscv/WkGMC+JciFcBvAmNlKRN+u2B/J9b3Z15k9qChVczIcCWTtnmfwFutneP mOlhmtETd3UG3BesecXkB8Na6UOaGpkwvxfNkTF8Xy0/zDGEcD4lhPfKc0/jl06kq8pZ t7f35E5VBXkEpygdALnJbWnkwlntpF3imzxqGsxJBtl5HU8Rm31t0IPqagQR5KL/av/q 7osQ== ARC-Authentication-Results: i=1; mx.google.com; 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 u7-20020a170903124700b001b7fee7d5f0si8138642plh.25.2023.09.12.05.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:13:26 -0700 (PDT) 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; 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 088F580BD5F1; Tue, 12 Sep 2023 04:05:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234179AbjILLEo (ORCPT + 37 others); Tue, 12 Sep 2023 07:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjILLEb (ORCPT ); Tue, 12 Sep 2023 07:04:31 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72DFF10E2; Tue, 12 Sep 2023 04:04:27 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 461AF80FC; Tue, 12 Sep 2023 11:04:25 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v2 3/3] serial: core: Add sysfs links for serial core port instances for ttys Date: Tue, 12 Sep 2023 14:03:45 +0300 Message-ID: <20230912110350.14482-4-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912110350.14482-1-tony@atomide.com> References: <20230912110350.14482-1-tony@atomide.com> MIME-Version: 1.0 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]); Tue, 12 Sep 2023 04:05:02 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776833848948502921 X-GMAIL-MSGID: 1776833848948502921 Let's allow the userspace to find out the ttyS style name for a serial core port device if a tty exists. This can be done with: $ grep DEVNAME /sys/bus/serial-base/devices/*/tty/uevent /sys/bus/serial-base/devices/00:04:0.0/tty/uevent:DEVNAME=ttyS0 /sys/bus/serial-base/devices/serial8250:0.1/tty/uevent:DEVNAME=ttyS1 /sys/bus/serial-base/devices/serial8250:0.2/tty/uevent:DEVNAME=ttyS2 /sys/bus/serial-base/devices/serial8250:0.3/tty/uevent:DEVNAME=ttyS3 With this change, we can add /dev/serial/by-id symlinks for the serial core port device instances. This allows using hardware based port addressing in addition to the legacy ttyS style naming. The serial core port naming is DEVNAME:0.0, such as the 00:04:0.0 above. The 0.0 above are serial core controller id and port id. The port id and controller id are typically both zero unless the serial port hardware controller has multiple controllers or ports. Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 @@ -3328,6 +3328,8 @@ static int serial_core_port_device_add(struct serial_ctrl_device *ctrl_dev, int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) { struct serial_ctrl_device *ctrl_dev, *new_ctrl_dev = NULL; + struct uart_match match = {port, drv}; + struct device *tty_dev; int ret; mutex_lock(&port_mutex); @@ -3368,10 +3370,22 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) port->flags &= ~UPF_DEAD; + tty_dev = device_find_child(port->dev, &match, serial_match_port); + if (tty_dev) { + ret = sysfs_create_link(&port->port_dev->dev.kobj, &tty_dev->kobj, + "tty"); + put_device(tty_dev); + if (ret) + goto err_remove_port; + } + mutex_unlock(&port_mutex); return 0; +err_remove_port: + serial_core_remove_one_port(drv, port); + err_unregister_port_dev: serial_base_port_device_remove(port->port_dev); @@ -3393,12 +3407,20 @@ void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port struct device *phys_dev = port->dev; struct serial_port_device *port_dev = port->port_dev; struct serial_ctrl_device *ctrl_dev = serial_core_get_ctrl_dev(port_dev); + struct uart_match match = {port, drv}; int ctrl_id = port->ctrl_id; + struct device *tty_dev; mutex_lock(&port_mutex); port->flags |= UPF_DEAD; + tty_dev = device_find_child(port->dev, &match, serial_match_port); + if (tty_dev) { + sysfs_remove_link(&port->port_dev->dev.kobj, "tty"); + put_device(tty_dev); + } + serial_core_remove_one_port(drv, port); /* Note that struct uart_port *port is no longer valid at this point */