From patchwork Mon May 8 11:19:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 91071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2093089vqo; Mon, 8 May 2023 04:54:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Ckqpumn0vjWMPIseluWBgTsKDGFiltJfyLA3kmeaz+EqNzYGxWOkcjI0Gazqzw+APmpOh X-Received: by 2002:a17:90b:1d87:b0:24f:13e7:e42a with SMTP id pf7-20020a17090b1d8700b0024f13e7e42amr10311327pjb.28.1683546860314; Mon, 08 May 2023 04:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683546860; cv=none; d=google.com; s=arc-20160816; b=hfzR/x4MBrjUoYHwrmveH2zcutNHE/tkDo/YUCe1EtY1OA8SseJOus5PT9oOduHHU1 df6HfwkTADjERu6uCRJi2GZwcj2xsleBZh39EwVagluGyqUIMgBhIO5PMHkbiGmV6uzs GVky9K707tzZ77llj18UdqKpFtGStxvCneyNzeqbJm63LRPJly+jzz21Z7xVM7H4MhI9 gpYo4Nl/Z6tTC08mx1hZLFqYuUTUoH+jDG3u2dQvaGuWPMW6GvQQsTiMdpfqXtwIYWIA PS9b1AK0QO2jMawfGv31Mtzu+jIdIAz7uzsb8Nle9dBTbxDRtWt+5Cb15bsadTlSxRWg 8STQ== 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 :message-id:date:subject:cc:to:from; bh=RAPyWXSQ81IC7Yy3w9nlCg8UVq7B+nZ6soVfqLNSe2I=; b=tqbAQeZYUwtGVFtZyPZuBDslE0sxpZdJPTf8qki7zkBrKtt0fLpDhUCjnH+U43UF5x TLRtT9uXlIRVqHvoizd+8OM1zBKIcuNLE1ztUn/5wPElj2N0eZUNhePUvtahvHWcUNje xTsN6PUCY+XGkDVvt4YsinjkPq5X12BED5QTspUiEe9z2fymuc+Rr3TbLI+qvdbsktfs r531Ra+KvygPJte3Wxz6n9EAgAGsPzoe33iS2oLQm83VUkWgNfu0f6T0rNdhV6YjTuSa To1Ir6I5YRjCpPf5MDM9QYAIjQFO7C4xzLNTGA9SR/7FRGC1myHedmBkZrxD2idiTf4X 3ozw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu18-20020a17090b389200b0023f0955f301si13905214pjb.166.2023.05.08.04.54.07; Mon, 08 May 2023 04:54:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235529AbjEHLTO (ORCPT + 99 others); Mon, 8 May 2023 07:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235523AbjEHLTL (ORCPT ); Mon, 8 May 2023 07:19:11 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61F0037C46; Mon, 8 May 2023 04:19:10 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 1F39D8111; Mon, 8 May 2023 11:19:07 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, Andrew Davis , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] serial: 8250: Allow using ports higher than SERIAL_8250_RUNTIME_UARTS Date: Mon, 8 May 2023 14:19:02 +0300 Message-Id: <20230508111903.39339-1-tony@atomide.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765326832784090175?= X-GMAIL-MSGID: =?utf-8?q?1765326832784090175?= We already allocate CONFIG_SERIAL_8250_NR_UARTS, but only allow using CONFIG_SERIAL_8250_RUNTIME_UARTS uarts unless nr_uarts module params is set. This causes issues for using distro kernels on SoCs with a large number of serial ports. Let's allow up to CONFIG_SERIAL_8250_NR_UARTS instead. To do this, we init the ports as needed if the initial uarts was too low. This way there's no need to set the value for CONFIG_SERIAL_8250_RUNTIME_UARTS to some SoC specific higher value. Typically the default value of 4 can be used as set for legacy reasons. Note that limiting the number of intial uarts still works as before unless a serial console on a higher port is specified. In this case we will increase the nr_ports up to the console port specified. Suggested-by: Andrew Davis Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_core.c | 86 +++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 23 deletions(-) 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 @@ -488,6 +488,34 @@ static inline void serial8250_apply_quirks(struct uart_8250_port *up) up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0; } +static struct uart_8250_port *serial8250_setup_port(int index) +{ + struct uart_8250_port *up; + + if (index >= UART_NR) + return NULL; + + up = &serial8250_ports[index]; + up->port.line = index; + + serial8250_init_port(up); + if (!base_ops) + base_ops = up->port.ops; + up->port.ops = &univ8250_port_ops; + + timer_setup(&up->timer, serial8250_timeout, 0); + + up->ops = &univ8250_driver_ops; + + if (IS_ENABLED(CONFIG_ALPHA_JENSEN) || + (IS_ENABLED(CONFIG_ALPHA_GENERIC) && alpha_jensen())) + up->port.set_mctrl = alpha_jensen_set_mctrl; + + serial8250_set_defaults(up); + + return up; +} + static void __init serial8250_isa_init_ports(void) { struct uart_8250_port *up; @@ -501,26 +529,13 @@ static void __init serial8250_isa_init_ports(void) if (nr_uarts > UART_NR) nr_uarts = UART_NR; - for (i = 0; i < nr_uarts; i++) { - struct uart_8250_port *up = &serial8250_ports[i]; - struct uart_port *port = &up->port; - - port->line = i; - serial8250_init_port(up); - if (!base_ops) - base_ops = port->ops; - port->ops = &univ8250_port_ops; - - timer_setup(&up->timer, serial8250_timeout, 0); - - up->ops = &univ8250_driver_ops; - - if (IS_ENABLED(CONFIG_ALPHA_JENSEN) || - (IS_ENABLED(CONFIG_ALPHA_GENERIC) && alpha_jensen())) - port->set_mctrl = alpha_jensen_set_mctrl; - - serial8250_set_defaults(up); - } + /* + * Set up initial isa ports based on nr_uart module param, or else + * default to CONFIG_SERIAL_8250_RUNTIME_UARTS. Note that we do not + * need to increase nr_uarts when setting up the initial isa ports. + */ + for (i = 0; i < nr_uarts; i++) + serial8250_setup_port(i); /* chain base port ops to support Remote Supervisor Adapter */ univ8250_port_ops = *base_ops; @@ -586,16 +601,29 @@ static void univ8250_console_write(struct console *co, const char *s, static int univ8250_console_setup(struct console *co, char *options) { + struct uart_8250_port *up; struct uart_port *port; - int retval; + int retval, i; /* * Check whether an invalid uart number has been specified, and * if so, search for the first available port that does have * console support. */ - if (co->index >= nr_uarts) + if (co->index >= UART_NR) co->index = 0; + + /* + * If the console is past the initial isa ports, init more ports up to + * co->index as needed and increment nr_uarts accordingly. + */ + for (i = nr_uarts; i <= co->index; i++) { + up = serial8250_setup_port(i); + if (!up) + return -ENODEV; + nr_uarts++; + } + port = &serial8250_ports[co->index].port; /* link port to console */ port->cons = co; @@ -990,7 +1018,18 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) mutex_lock(&serial_mutex); uart = serial8250_find_match_or_unused(&up->port); - if (uart && uart->port.type != PORT_8250_CIR) { + if (!uart) { + /* + * If the port is past the initial isa ports, initialize a new + * port and increment nr_uarts accordingly. + */ + uart = serial8250_setup_port(nr_uarts); + if (!uart) + goto unlock; + nr_uarts++; + } + + if (uart->port.type != PORT_8250_CIR) { struct mctrl_gpios *gpios; if (uart->port.dev) @@ -1120,6 +1159,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) } } +unlock: mutex_unlock(&serial_mutex); return ret;