summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Villeneuve <hvilleneuve@dimonoff.com>2026-05-21 14:16:50 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-07-10 14:50:12 +0200
commit86305190f307c05bc2e0660f4ce16b7aeca6711b (patch)
tree063f8cb3f1a97465d4e847a2b6df7f8192eadffc
parent11f1d49122ec2227b050f4596a7422606237347e (diff)
downloadlinux-next-86305190f307c05bc2e0660f4ce16b7aeca6711b.tar.gz
linux-next-86305190f307c05bc2e0660f4ce16b7aeca6711b.zip
serial: uniformize serial port I/O infos display
Uniformize serial port I/O infos display from three different functions that display mostly the same information, but with some variations, by adding a common function. This make use of new functions uart_iotype_mmio() and uart_iotype_legacy_io() to simplify and improve code readability. This will prevent displaying irrelevant information for future IO types (ex: UPIO_BUS), while also addressing the (eventually) invalid check for "iotype >= UPIO_MEM". This also allows us to remove the confusing cast to (unsigned long long) for iobase which is defined as an unsigned long, and use %pa to display the mapbase pointer, as it is done in earlycon_print_info(). Replace snprintf with more robust scnprintf so we could perhaps one day get rid of snprintf() entirely. Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com> Link: https://patch.msgid.link/20260521-tty-upio-v3-4-bf74567994a0@dimonoff.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/serial/earlycon.c17
-rw-r--r--drivers/tty/serial/serial_core.c68
-rw-r--r--include/linux/serial_core.h1
3 files changed, 43 insertions, 43 deletions
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index ab9af37f6cda..ce740cdc7ceb 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -75,19 +75,12 @@ static void __init earlycon_print_info(struct earlycon_device *device)
{
struct console *earlycon = device->con;
struct uart_port *port = &device->port;
+ char ioinfos[64];
- if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM16 ||
- port->iotype == UPIO_MEM32 || port->iotype == UPIO_MEM32BE)
- pr_info("%s%d at MMIO%s %pa (options '%s')\n",
- earlycon->name, earlycon->index,
- (port->iotype == UPIO_MEM) ? "" :
- (port->iotype == UPIO_MEM16) ? "16" :
- (port->iotype == UPIO_MEM32) ? "32" : "32be",
- &port->mapbase, device->options);
- else
- pr_info("%s%d at I/O port 0x%lx (options '%s')\n",
- earlycon->name, earlycon->index,
- port->iobase, device->options);
+ uart_get_ioinfos(port, ioinfos, sizeof(ioinfos));
+
+ pr_info("%s%d%s (options '%s')\n", earlycon->name, earlycon->index,
+ ioinfos, device->options);
}
static int __init parse_options(struct earlycon_device *device, char *options)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6a8f27718648..9b16480b374a 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1998,9 +1998,9 @@ static void uart_line_info(struct seq_file *m, struct uart_state *state)
struct tty_port *port = &state->port;
enum uart_pm_state pm_state;
struct uart_port *uport;
+ char ioinfos[64];
char stat_buf[32];
unsigned int status;
- int mmio;
guard(mutex)(&port->mutex);
@@ -2008,13 +2008,10 @@ static void uart_line_info(struct seq_file *m, struct uart_state *state)
if (!uport)
return;
- mmio = uport->iotype >= UPIO_MEM;
- seq_printf(m, "%u: uart:%s %s%08llX irq:%u",
- uport->line, uart_type(uport),
- mmio ? "mmio:0x" : "port:",
- mmio ? (unsigned long long)uport->mapbase
- : (unsigned long long)uport->iobase,
- uport->irq);
+ seq_printf(m, "%u: uart:%s", uport->line, uart_type(uport));
+ uart_get_ioinfos(uport, ioinfos, sizeof(ioinfos));
+ seq_printf(m, "%s", ioinfos);
+ seq_printf(m, " irq:%u", uport->irq);
if (uport->type == PORT_UNKNOWN) {
seq_putc(m, '\n');
@@ -2488,38 +2485,47 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
}
EXPORT_SYMBOL(uart_resume_port);
-static inline void
-uart_report_port(struct uart_driver *drv, struct uart_port *port)
+static const char *uart_get_mmio_width(struct uart_port *port)
{
- char address[64];
-
switch (port->iotype) {
- case UPIO_PORT:
- snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase);
- break;
- case UPIO_HUB6:
- snprintf(address, sizeof(address),
- "I/O 0x%lx offset 0x%x", port->iobase, port->hub6);
- break;
- case UPIO_MEM:
case UPIO_MEM16:
+ return "16";
case UPIO_MEM32:
case UPIO_MEM32BE:
+ return "32be";
case UPIO_AU:
- case UPIO_TSI:
- snprintf(address, sizeof(address),
- "MMIO 0x%llx", (unsigned long long)port->mapbase);
- break;
+ case UPIO_MEM:
default:
- strscpy(address, "*unknown*", sizeof(address));
- break;
+ return "";
}
+}
+
+void uart_get_ioinfos(struct uart_port *port, char *buf, size_t size)
+{
+ buf[0] = '\0';
+
+ if (uart_iotype_mmio(port->iotype)) {
+ scnprintf(buf, size, " MMIO%s:%pa", uart_get_mmio_width(port), &port->mapbase);
+ } else if (uart_iotype_io(port->iotype)) {
+ if (port->iotype == UPIO_PORT)
+ scnprintf(buf, size, " I/O:0x%lx", port->iobase);
+ else if (port->iotype == UPIO_HUB6)
+ scnprintf(buf, size, " I/O:0x%lx, offset 0x%x", port->iobase, port->hub6);
+ }
+}
+EXPORT_SYMBOL(uart_get_ioinfos);
+
+static inline void
+uart_report_port(struct uart_driver *drv, struct uart_port *port)
+{
+ char ioinfos[64];
+
+ uart_get_ioinfos(port, ioinfos, sizeof(ioinfos));
- pr_info("%s%s%s at %s (irq = %u, base_baud = %u) is a %s\n",
- port->dev ? dev_name(port->dev) : "",
- port->dev ? ": " : "",
- port->name,
- address, port->irq, port->uartclk / 16, uart_type(port));
+ pr_info("%s%s%s%s (irq = %u, base_baud = %u) is a %s\n",
+ port->dev ? dev_name(port->dev) : "",
+ port->dev ? ": " : "",
+ port->name, ioinfos, port->irq, port->uartclk / 16, uart_type(port));
/* The magic multiplier feature is a bit obscure, so report it too. */
if (port->flags & UPF_MAGIC_MULTIPLIER)
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 3cfde1af12fe..66b1459d53fc 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -1339,6 +1339,7 @@ static inline int uart_handle_break(struct uart_port *port)
int uart_get_rs485_mode(struct uart_port *port);
+void uart_get_ioinfos(struct uart_port *port, char *buf, size_t size);
bool uart_iotype_mmio(enum uart_iotype iotype);
bool uart_iotype_io(enum uart_iotype iotype);