* [PATCH v2 0/2] serial: qcom-geni: Add support to increase UART ports efficiently @ 2025-08-12 5:48 Zong Jiang 2025-08-12 5:48 ` [PATCH 1/2] serial: qcom-geni: Dynamically allocate UART ports Zong Jiang 2025-08-12 5:48 ` [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig Zong Jiang 0 siblings, 2 replies; 5+ messages in thread From: Zong Jiang @ 2025-08-12 5:48 UTC (permalink / raw) To: gregkh, linux-serial, linux-kernel Cc: quic_ztu, quic_anupkulk, quic_msavaliy, quic_vdadhani, Zong Jiang This patch series improves the flexibility and scalability of the Qualcomm GENI serial driver by refactoring UART port allocation and introducing a Kconfig option to configure the number of supported UART ports. Changes since v1: - Based on Greg KH's comments, the following changes have been made in v2: - Split the original patch into two separate patches. - Replaced static UART port allocation with dynamic allocation. - Added a Kconfig option to configure UART port count. - Improved commit messages and changelog to better justify the changes. Patch 1 replaces the hardcoded static array of UART ports with dynamic allocation, reducing memory usage and improving maintainability. Patch 2 introduces a new Kconfig option, SERIAL_QCOM_GENI_UART_PORTS, allowing platforms to configure the maximum number of UART ports at build time. These changes are useful for platforms that require more than the previously hardcoded number of UART ports, and help avoid unnecessary allocation for unused ports. Patch summary: [PATCH v2 1/2] serial: qcom-geni: Dynamically allocate UART ports [PATCH v2 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] serial: qcom-geni: Dynamically allocate UART ports 2025-08-12 5:48 [PATCH v2 0/2] serial: qcom-geni: Add support to increase UART ports efficiently Zong Jiang @ 2025-08-12 5:48 ` Zong Jiang 2025-08-12 5:48 ` [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig Zong Jiang 1 sibling, 0 replies; 5+ messages in thread From: Zong Jiang @ 2025-08-12 5:48 UTC (permalink / raw) To: gregkh, linux-serial, linux-kernel Cc: quic_ztu, quic_anupkulk, quic_msavaliy, quic_vdadhani, Zong Jiang Replace the static allocation of UART ports with dynamic allocation using devm_kzalloc. This change removes the fixed-size array and instead allocates each UART port structure on demand during probe, improving memory efficiency and scalability. Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> --- drivers/tty/serial/qcom_geni_serial.c | 44 ++++++++------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 32ec632fd080..080c18ddbdde 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -164,33 +164,6 @@ static inline struct qcom_geni_serial_port *to_dev_port(struct uart_port *uport) return container_of(uport, struct qcom_geni_serial_port, uport); } -static struct qcom_geni_serial_port qcom_geni_uart_ports[GENI_UART_PORTS] = { - [0] = { - .uport = { - .iotype = UPIO_MEM, - .ops = &qcom_geni_uart_pops, - .flags = UPF_BOOT_AUTOCONF, - .line = 0, - }, - }, - [1] = { - .uport = { - .iotype = UPIO_MEM, - .ops = &qcom_geni_uart_pops, - .flags = UPF_BOOT_AUTOCONF, - .line = 1, - }, - }, - [2] = { - .uport = { - .iotype = UPIO_MEM, - .ops = &qcom_geni_uart_pops, - .flags = UPF_BOOT_AUTOCONF, - .line = 2, - }, - }, -}; - static struct qcom_geni_serial_port qcom_geni_console_port = { .uport = { .iotype = UPIO_MEM, @@ -285,7 +258,7 @@ static const char *qcom_geni_serial_get_type(struct uart_port *uport) return "MSM"; } -static struct qcom_geni_serial_port *get_port_from_line(int line, bool console) +static struct qcom_geni_serial_port *get_port_from_line(int line, bool console, struct device *dev) { struct qcom_geni_serial_port *port; int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS; @@ -306,7 +279,14 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console) if (line < 0) return ERR_PTR(-ENXIO); - port = &qcom_geni_uart_ports[line]; + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return ERR_PTR(-ENOMEM); + + port->uport.iotype = UPIO_MEM; + port->uport.ops = &qcom_geni_uart_pops; + port->uport.flags = UPF_BOOT_AUTOCONF; + port->uport.line = line; } return port; } @@ -554,7 +534,7 @@ static void qcom_geni_serial_console_write(struct console *co, const char *s, WARN_ON(co->index < 0 || co->index >= GENI_UART_CONS_PORTS); - port = get_port_from_line(co->index, true); + port = get_port_from_line(co->index, true, NULL); if (IS_ERR(port)) return; @@ -1511,7 +1491,7 @@ static int qcom_geni_console_setup(struct console *co, char *options) if (co->index >= GENI_UART_CONS_PORTS || co->index < 0) return -ENXIO; - port = get_port_from_line(co->index, true); + port = get_port_from_line(co->index, true, NULL); if (IS_ERR(port)) { pr_err("Invalid line %d\n", co->index); return PTR_ERR(port); @@ -1866,7 +1846,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) line = of_alias_get_id(pdev->dev.of_node, "hsuart"); } - port = get_port_from_line(line, data->console); + port = get_port_from_line(line, data->console, &pdev->dev); if (IS_ERR(port)) { dev_err(&pdev->dev, "Invalid line %d\n", line); return PTR_ERR(port); -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig 2025-08-12 5:48 [PATCH v2 0/2] serial: qcom-geni: Add support to increase UART ports efficiently Zong Jiang 2025-08-12 5:48 ` [PATCH 1/2] serial: qcom-geni: Dynamically allocate UART ports Zong Jiang @ 2025-08-12 5:48 ` Zong Jiang 2025-08-12 6:29 ` Greg KH 1 sibling, 1 reply; 5+ messages in thread From: Zong Jiang @ 2025-08-12 5:48 UTC (permalink / raw) To: gregkh, linux-serial, linux-kernel Cc: quic_ztu, quic_anupkulk, quic_msavaliy, quic_vdadhani, Zong Jiang Replace the hardcoded GENI_UART_PORTS macro with a new Kconfig option SERIAL_QCOM_GENI_UART_PORTS to allow platforms to configure the maximum number of UART ports supported by the driver at build time. This improves flexibility for platforms that require more than the previously fixed number of UART ports, and avoids unnecessary allocation for unused ports. Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> --- drivers/tty/serial/Kconfig | 8 ++++++++ drivers/tty/serial/qcom_geni_serial.c | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 44427415a80d..e661f5951f55 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -928,6 +928,14 @@ config SERIAL_QCOM_GENI_CONSOLE Serial console driver for Qualcomm Technologies Inc's GENI based QUP hardware. +config SERIAL_QCOM_GENI_UART_PORTS + int "Maximum number of GENI UART ports" + depends on SERIAL_QCOM_GENI + default "8" + help + Set this to the maximum number of serial ports you want the driver + to support. + config SERIAL_VT8500 bool "VIA VT8500 on-chip serial port support" depends on ARCH_VT8500 || COMPILE_TEST diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 080c18ddbdde..9c7b1cea7cfe 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -77,7 +77,6 @@ #define STALE_TIMEOUT 16 #define DEFAULT_BITS_PER_CHAR 10 #define GENI_UART_CONS_PORTS 1 -#define GENI_UART_PORTS 3 #define DEF_FIFO_DEPTH_WORDS 16 #define DEF_TX_WM 2 #define DEF_FIFO_WIDTH_BITS 32 @@ -261,7 +260,7 @@ static const char *qcom_geni_serial_get_type(struct uart_port *uport) static struct qcom_geni_serial_port *get_port_from_line(int line, bool console, struct device *dev) { struct qcom_geni_serial_port *port; - int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS; + int nr_ports = console ? GENI_UART_CONS_PORTS : CONFIG_SERIAL_QCOM_GENI_UART_PORTS; if (console) { if (line < 0 || line >= nr_ports) @@ -1652,7 +1651,7 @@ static struct uart_driver qcom_geni_uart_driver = { .owner = THIS_MODULE, .driver_name = "qcom_geni_uart", .dev_name = "ttyHS", - .nr = GENI_UART_PORTS, + .nr = CONFIG_SERIAL_QCOM_GENI_UART_PORTS, }; static int geni_serial_resources_on(struct uart_port *uport) -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig 2025-08-12 5:48 ` [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig Zong Jiang @ 2025-08-12 6:29 ` Greg KH 2025-08-13 6:51 ` Zong Jiang (QUIC) 0 siblings, 1 reply; 5+ messages in thread From: Greg KH @ 2025-08-12 6:29 UTC (permalink / raw) To: Zong Jiang Cc: linux-serial, linux-kernel, quic_ztu, quic_anupkulk, quic_msavaliy, quic_vdadhani On Tue, Aug 12, 2025 at 01:48:19PM +0800, Zong Jiang wrote: > Replace the hardcoded GENI_UART_PORTS macro with a new Kconfig option > SERIAL_QCOM_GENI_UART_PORTS to allow platforms to configure the maximum > number of UART ports supported by the driver at build time. > > This improves flexibility for platforms that require more than the > previously fixed number of UART ports, and avoids unnecessary allocation > for unused ports. > > Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> > --- > drivers/tty/serial/Kconfig | 8 ++++++++ > drivers/tty/serial/qcom_geni_serial.c | 5 ++--- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig > index 44427415a80d..e661f5951f55 100644 > --- a/drivers/tty/serial/Kconfig > +++ b/drivers/tty/serial/Kconfig > @@ -928,6 +928,14 @@ config SERIAL_QCOM_GENI_CONSOLE > Serial console driver for Qualcomm Technologies Inc's GENI based > QUP hardware. > > +config SERIAL_QCOM_GENI_UART_PORTS > + int "Maximum number of GENI UART ports" > + depends on SERIAL_QCOM_GENI > + default "8" > + help > + Set this to the maximum number of serial ports you want the driver > + to support. Why do you need a static number of ports at all? Why not just handle how ever many there are in the system at the moment? Or is this due to some restriction in the serial core that requires this? thanks, greg k-h ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig 2025-08-12 6:29 ` Greg KH @ 2025-08-13 6:51 ` Zong Jiang (QUIC) 0 siblings, 0 replies; 5+ messages in thread From: Zong Jiang (QUIC) @ 2025-08-13 6:51 UTC (permalink / raw) To: Greg KH Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Zhiqiang Tu (QUIC), Anup Kulkarni (QUIC), Mukesh Savaliya (QUIC), Viken Dadhaniya (QUIC), Haixu Cui (QUIC) Hi Greg, Thanks for the question! Yes, this is indeed due to a restriction in the serial core. Specifically, the serial core requires the uart_driver->nr field to be set at registration time via uart_register_driver(). This value determines how many uart_port slots are allocated internally, it cannot be changed dynamically afterward. As a result, we need to define the maximum number of ports up front. By making this configurable via Kconfig, platforms can tailor the driver to match their actual hardware needs, avoiding unnecessary allocation for unused ports while still complying with the serial core's expectations. Thanks again for the feedback! Best regards, Zong Jiang -----Original Message----- From: Greg KH <gregkh@linuxfoundation.org> Sent: Tuesday, August 12, 2025 2:30 PM To: Zong Jiang (QUIC) <quic_zongjian@quicinc.com> Cc: linux-serial@vger.kernel.org; linux-kernel@vger.kernel.org; Zhiqiang Tu (QUIC) <quic_ztu@quicinc.com>; Anup Kulkarni (QUIC) <quic_anupkulk@quicinc.com>; Mukesh Savaliya (QUIC) <quic_msavaliy@quicinc.com>; Viken Dadhaniya (QUIC) <quic_vdadhani@quicinc.com> Subject: Re: [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig On Tue, Aug 12, 2025 at 01:48:19PM +0800, Zong Jiang wrote: > Replace the hardcoded GENI_UART_PORTS macro with a new Kconfig option > SERIAL_QCOM_GENI_UART_PORTS to allow platforms to configure the > maximum number of UART ports supported by the driver at build time. > > This improves flexibility for platforms that require more than the > previously fixed number of UART ports, and avoids unnecessary > allocation for unused ports. > > Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> > --- > drivers/tty/serial/Kconfig | 8 ++++++++ > drivers/tty/serial/qcom_geni_serial.c | 5 ++--- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig > index 44427415a80d..e661f5951f55 100644 > --- a/drivers/tty/serial/Kconfig > +++ b/drivers/tty/serial/Kconfig > @@ -928,6 +928,14 @@ config SERIAL_QCOM_GENI_CONSOLE > Serial console driver for Qualcomm Technologies Inc's GENI based > QUP hardware. > > +config SERIAL_QCOM_GENI_UART_PORTS > + int "Maximum number of GENI UART ports" > + depends on SERIAL_QCOM_GENI > + default "8" > + help > + Set this to the maximum number of serial ports you want the driver > + to support. Why do you need a static number of ports at all? Why not just handle how ever many there are in the system at the moment? Or is this due to some restriction in the serial core that requires this? thanks, greg k-h ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-13 6:51 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-12 5:48 [PATCH v2 0/2] serial: qcom-geni: Add support to increase UART ports efficiently Zong Jiang 2025-08-12 5:48 ` [PATCH 1/2] serial: qcom-geni: Dynamically allocate UART ports Zong Jiang 2025-08-12 5:48 ` [PATCH 2/2] serial: qcom-geni: Make UART port count configurable via Kconfig Zong Jiang 2025-08-12 6:29 ` Greg KH 2025-08-13 6:51 ` Zong Jiang (QUIC)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox