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>
This commit is contained in:
Hugo Villeneuve 2026-05-21 14:16:50 -04:00 committed by Greg Kroah-Hartman
parent 11f1d49122
commit 86305190f3
3 changed files with 47 additions and 47 deletions

View File

@ -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)

View File

@ -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 const char *uart_get_mmio_width(struct uart_port *port)
{
switch (port->iotype) {
case UPIO_MEM16:
return "16";
case UPIO_MEM32:
case UPIO_MEM32BE:
return "32be";
case UPIO_AU:
case UPIO_MEM:
default:
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 address[64];
char ioinfos[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:
case UPIO_MEM32:
case UPIO_MEM32BE:
case UPIO_AU:
case UPIO_TSI:
snprintf(address, sizeof(address),
"MMIO 0x%llx", (unsigned long long)port->mapbase);
break;
default:
strscpy(address, "*unknown*", sizeof(address));
break;
}
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)

View File

@ -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);