Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: mvebu-uart: Use port lock wrappers

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

To avoid adding this functionality to all UART drivers, wrap the
spin_[un]lock*() invocations for uart_port::lock into helper functions
which just contain the spin_[un]lock*() invocations for now. In a
subsequent step these helpers will gain the console synchronization
mechanisms.

Converted with coccinelle. No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/20230914183831.587273-43-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
f9b7652c 6cbd9790

+9 -9
+9 -9
drivers/tty/serial/mvebu-uart.c
··· 187 187 unsigned long flags; 188 188 unsigned int st; 189 189 190 - spin_lock_irqsave(&port->lock, flags); 190 + uart_port_lock_irqsave(port, &flags); 191 191 st = readl(port->membase + UART_STAT); 192 - spin_unlock_irqrestore(&port->lock, flags); 192 + uart_port_unlock_irqrestore(port, flags); 193 193 194 194 return (st & STAT_TX_EMP) ? TIOCSER_TEMT : 0; 195 195 } ··· 249 249 unsigned int ctl; 250 250 unsigned long flags; 251 251 252 - spin_lock_irqsave(&port->lock, flags); 252 + uart_port_lock_irqsave(port, &flags); 253 253 ctl = readl(port->membase + UART_CTRL(port)); 254 254 if (brk == -1) 255 255 ctl |= CTRL_SND_BRK_SEQ; 256 256 else 257 257 ctl &= ~CTRL_SND_BRK_SEQ; 258 258 writel(ctl, port->membase + UART_CTRL(port)); 259 - spin_unlock_irqrestore(&port->lock, flags); 259 + uart_port_unlock_irqrestore(port, flags); 260 260 } 261 261 262 262 static void mvebu_uart_rx_chars(struct uart_port *port, unsigned int status) ··· 540 540 unsigned long flags; 541 541 unsigned int baud, min_baud, max_baud; 542 542 543 - spin_lock_irqsave(&port->lock, flags); 543 + uart_port_lock_irqsave(port, &flags); 544 544 545 545 port->read_status_mask = STAT_RX_RDY(port) | STAT_OVR_ERR | 546 546 STAT_TX_RDY(port) | STAT_TX_FIFO_FUL; ··· 589 589 uart_update_timeout(port, termios->c_cflag, baud); 590 590 } 591 591 592 - spin_unlock_irqrestore(&port->lock, flags); 592 + uart_port_unlock_irqrestore(port, flags); 593 593 } 594 594 595 595 static const char *mvebu_uart_type(struct uart_port *port) ··· 735 735 int locked = 1; 736 736 737 737 if (oops_in_progress) 738 - locked = spin_trylock_irqsave(&port->lock, flags); 738 + locked = uart_port_trylock_irqsave(port, &flags); 739 739 else 740 - spin_lock_irqsave(&port->lock, flags); 740 + uart_port_lock_irqsave(port, &flags); 741 741 742 742 ier = readl(port->membase + UART_CTRL(port)) & CTRL_BRK_INT; 743 743 intr = readl(port->membase + UART_INTR(port)) & ··· 758 758 } 759 759 760 760 if (locked) 761 - spin_unlock_irqrestore(&port->lock, flags); 761 + uart_port_unlock_irqrestore(port, flags); 762 762 } 763 763 764 764 static int mvebu_uart_console_setup(struct console *co, char *options)