From patchwork Thu Oct 13 08:17:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Hundeb=C3=B8ll?= X-Patchwork-Id: 615053 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 5E4BFC4332F for ; Thu, 13 Oct 2022 08:25:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbiJMIZq (ORCPT ); Thu, 13 Oct 2022 04:25:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbiJMIZp (ORCPT ); Thu, 13 Oct 2022 04:25:45 -0400 X-Greylist: delayed 464 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Oct 2022 01:25:41 PDT Received: from first.geanix.com (first.geanix.com [116.203.34.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1F9BE0C for ; Thu, 13 Oct 2022 01:25:40 -0700 (PDT) Received: from xps.lan (85.184.138.169.dynamic.dhcp.aura-net.dk [85.184.138.169]) by first.geanix.com (Postfix) with ESMTPSA id 5487214014D; Thu, 13 Oct 2022 08:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1665649073; bh=IV/De8+ALYMctYGGtVoa1YOHt96F1KUg8Fig3NwI23U=; h=From:To:Cc:Subject:Date; b=Qxa9+AHIAqA1QDnZJ0IhW+hyz+dHqa3H/K7/ZPekmx2saXnqwnp196Ts7GqHioHkF EONH8Mx2AAdxEromZEOL7xxr3CFSG1f0o7epVrahbZ0uycLWg4LPqdksb+9W9jHNzE im34xilEexGqEDDXX6PvMeuNlDmSbYrX5Mv+0FNg+wfVjh6ZbgZGykJWbrDQvY+SQy QDz5F8ZsVzbr4fpTn9lsSR3IYqMLaN39H8+DJbLo2qisgQhO0fGN2l5Dht7cY/IWwp LBpBOz9oy4PLZ9MPn9Tla55Z6gw1vL/1ba5o2VTyiAl/0Le7IQAovLQZblKtI4W2vq rJyJMkKcGYz9g== From: =?utf-8?q?Martin_Hundeb=C3=B8ll?= To: linux-serial@vger.kernel.org Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= , Greg Kroah-Hartman Subject: [PATCH 1/3] serial: 8250: allow use of non-runtime configured uart ports Date: Thu, 13 Oct 2022 10:17:46 +0200 Message-Id: <20221013081748.25699-1-martin@geanix.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The logic to find unused ports when registering new 8250 uart ports searches only up to CONFIG_SERIAL_8250_RUNTIME_UARTS, which forces users of external 8250 ports to increase the number of runtime ports artificially. Fix this by initializing each allocated port structure with basic settings like line number and uart operation callbacks, and by searching the entire array of allocated ports to find an unused one. Signed-off-by: Martin Hundebøll --- drivers/tty/serial/8250/8250_core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 94fbf0add2ce..a166cc66e7d1 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -500,7 +500,7 @@ static void __init serial8250_isa_init_ports(void) if (nr_uarts > UART_NR) nr_uarts = UART_NR; - for (i = 0; i < nr_uarts; i++) { + for (i = 0; i < UART_NR; i++) { struct uart_8250_port *up = &serial8250_ports[i]; struct uart_port *port = &up->port; @@ -926,15 +926,16 @@ static struct uart_8250_port *serial8250_find_match_or_unused(const struct uart_ /* try line number first if still available */ i = port->line; - if (i < nr_uarts && serial8250_ports[i].port.type == PORT_UNKNOWN && + if (i < UART_NR && serial8250_ports[i].port.type == PORT_UNKNOWN && serial8250_ports[i].port.iobase == 0) return &serial8250_ports[i]; + /* * We didn't find a matching entry, so look for the first * free entry. We look for one which hasn't been previously * used (indicated by zero iobase). */ - for (i = 0; i < nr_uarts; i++) + for (i = 0; i < UART_NR; i++) if (serial8250_ports[i].port.type == PORT_UNKNOWN && serial8250_ports[i].port.iobase == 0) return &serial8250_ports[i]; @@ -943,7 +944,7 @@ static struct uart_8250_port *serial8250_find_match_or_unused(const struct uart_ * That also failed. Last resort is to find any entry which * doesn't have a real port associated with it. */ - for (i = 0; i < nr_uarts; i++) + for (i = 0; i < UART_NR; i++) if (serial8250_ports[i].port.type == PORT_UNKNOWN) return &serial8250_ports[i]; From patchwork Thu Oct 13 08:17:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Hundeb=C3=B8ll?= X-Patchwork-Id: 615213 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 24BCDC4332F for ; Thu, 13 Oct 2022 08:25:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbiJMIZr (ORCPT ); Thu, 13 Oct 2022 04:25:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiJMIZq (ORCPT ); Thu, 13 Oct 2022 04:25:46 -0400 Received: from first.geanix.com (first.geanix.com [116.203.34.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 137D84D4EF for ; Thu, 13 Oct 2022 01:25:40 -0700 (PDT) Received: from xps.lan (85.184.138.169.dynamic.dhcp.aura-net.dk [85.184.138.169]) by first.geanix.com (Postfix) with ESMTPSA id 23B2B146402; Thu, 13 Oct 2022 08:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1665649075; bh=qgyEyCvSf1EUnMEEIVOGiR7AxKMbjmYW6a0T6PsLLEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=A6Ovb3ChLKKHS6lOI45vhYnLnzd0Z0n5gkxhbaQtKaCebap+itvtEDKd8tHCQhsjM w1j+WBS5ESOWxk3Ph9RhjZtXPtVaYI5VEdcbxWlz4Ed4OcIxRkC+AcTX+G+mAnkydf 79gbNYxyLrOz+vycEUgu7ZWPwlbXPnqaKAg8V2BWJwDrfoJECskDoHIlMClyB/jRr9 Tuz3sgNHyvd+s5wi42POpQYcAYmy5OO+dsppLfR8ogbsjQGZ+JiihaS7IqExstHhmD 72dEClN0u0P0xm+mnZmkebQFw7HpX6JcaLn7oLIn8hCO4ntWraCg2R/q8O9n0Dl/89 BW8LiEFV/7sUA== From: =?utf-8?q?Martin_Hundeb=C3=B8ll?= To: linux-serial@vger.kernel.org Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= , Greg Kroah-Hartman Subject: [PATCH 2/3] serial: 8250: allow zero runtime-configured ports Date: Thu, 13 Oct 2022 10:17:47 +0200 Message-Id: <20221013081748.25699-2-martin@geanix.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013081748.25699-1-martin@geanix.com> References: <20221013081748.25699-1-martin@geanix.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org One should be able to set CONFIG_SERIAL_8250_RUNTIME_UARTS=0 on platforms with zero built-in 8250-like ports. However, that case was prohibited in commit 59cfc45f17d6 ("serial: 8250: Do nothing if nr_uarts=0"), because of missing array initialization, effectively disabling the driver entirely. The missing array initialization has been fixed in the previous commit, so remove check for zero runtime ports. Said check gets to stay when initializing early consoles, though, because that makes sense for built-in ports only. Signed-off-by: Martin Hundebøll --- drivers/tty/serial/8250/8250_core.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index a166cc66e7d1..ba48431ec6e2 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -680,9 +680,6 @@ static struct console univ8250_console = { static int __init univ8250_console_init(void) { - if (nr_uarts == 0) - return -ENODEV; - serial8250_isa_init_ports(); register_console(&univ8250_console); return 0; @@ -1171,9 +1168,6 @@ static int __init serial8250_init(void) { int ret; - if (nr_uarts == 0) - return -ENODEV; - serial8250_isa_init_ports(); pr_info("Serial: 8250/16550 driver, %d ports, IRQ sharing %sabled\n", From patchwork Thu Oct 13 08:17:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Hundeb=C3=B8ll?= X-Patchwork-Id: 615052 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 BA735C433FE for ; Thu, 13 Oct 2022 08:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbiJMIZv (ORCPT ); Thu, 13 Oct 2022 04:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiJMIZu (ORCPT ); Thu, 13 Oct 2022 04:25:50 -0400 Received: from first.geanix.com (first.geanix.com [116.203.34.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B05753A79 for ; Thu, 13 Oct 2022 01:25:40 -0700 (PDT) Received: from xps.lan (85.184.138.169.dynamic.dhcp.aura-net.dk [85.184.138.169]) by first.geanix.com (Postfix) with ESMTPSA id EFEE5146403; Thu, 13 Oct 2022 08:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1665649077; bh=T4ZTdriQe48UUW4+bGtFVqkTVvwmO0ozeAu31DqCdnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=edG3xXUbfG3VLj9j7KywFgG/ag2kJuZv7WHJ5MlekSUbMTVihnQm/O76TYctTWNoB KYJ59vw0bfJeWhedgHEnGPpKqIfZBYZEIqfn+khjq6aBlI6eEan/hf1XqR11KpnOH+ q4Yks8/cIrBFnzKCsKSUqxLtEr24xWlXDNegieHl0iueqfX0Y+o/xrAI/kLe8BhDVw aWDEhivZWTnHD8Uzv8ceJREtS482Y6s0WTQiM8Fbc9705COKSc3nzaY3gU0q+ZcJ3t 4pGeHbcHDfzUJQaBMN7NlKVPFTKWyGvX0wqK2c83NpLTtce41n/IOarLDRGPIEmAXZ e249l0GVNmPEg== From: =?utf-8?q?Martin_Hundeb=C3=B8ll?= To: linux-serial@vger.kernel.org Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= , Greg Kroah-Hartman Subject: [PATCH 3/3] serial: 8250: skip platform device registration with no runtime ports Date: Thu, 13 Oct 2022 10:17:48 +0200 Message-Id: <20221013081748.25699-3-martin@geanix.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013081748.25699-1-martin@geanix.com> References: <20221013081748.25699-1-martin@geanix.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Skip registration of the platform device used for built-in ports, if no such ports are configured/created. Signed-off-by: Martin Hundebøll --- drivers/tty/serial/8250/8250_core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index ba48431ec6e2..3161f32c1e90 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -1182,6 +1182,14 @@ static int __init serial8250_init(void) if (ret) goto out; + if (nr_uarts == 0) { + ret = platform_driver_register(&serial8250_isa_driver); + if (ret) + goto unreg_uart_drv; + + goto out; + } + ret = serial8250_pnp_init(); if (ret) goto unreg_uart_drv; @@ -1230,9 +1238,11 @@ static void __exit serial8250_exit(void) serial8250_isa_devs = NULL; platform_driver_unregister(&serial8250_isa_driver); - platform_device_unregister(isa_dev); - serial8250_pnp_exit(); + if (nr_uarts) { + platform_device_unregister(isa_dev); + serial8250_pnp_exit(); + } #ifdef CONFIG_SPARC sunserial_unregister_minors(&serial8250_reg, UART_NR);