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

serial: sifive: 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-62-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
93614eff 94c53770

+8 -8
+8 -8
drivers/tty/serial/sifive.c
··· 521 521 struct sifive_serial_port *ssp = dev_id; 522 522 u32 ip; 523 523 524 - spin_lock(&ssp->port.lock); 524 + uart_port_lock(&ssp->port); 525 525 526 526 ip = __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); 527 527 if (!ip) { 528 - spin_unlock(&ssp->port.lock); 528 + uart_port_unlock(&ssp->port); 529 529 return IRQ_NONE; 530 530 } 531 531 ··· 534 534 if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) 535 535 __ssp_transmit_chars(ssp); 536 536 537 - spin_unlock(&ssp->port.lock); 537 + uart_port_unlock(&ssp->port); 538 538 539 539 return IRQ_HANDLED; 540 540 } ··· 653 653 ssp->port.uartclk / 16); 654 654 __ssp_update_baud_rate(ssp, rate); 655 655 656 - spin_lock_irqsave(&ssp->port.lock, flags); 656 + uart_port_lock_irqsave(&ssp->port, &flags); 657 657 658 658 /* Update the per-port timeout */ 659 659 uart_update_timeout(port, termios->c_cflag, rate); ··· 670 670 if (v != old_v) 671 671 __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); 672 672 673 - spin_unlock_irqrestore(&ssp->port.lock, flags); 673 + uart_port_unlock_irqrestore(&ssp->port, flags); 674 674 } 675 675 676 676 static void sifive_serial_release_port(struct uart_port *port) ··· 795 795 if (ssp->port.sysrq) 796 796 locked = 0; 797 797 else if (oops_in_progress) 798 - locked = spin_trylock(&ssp->port.lock); 798 + locked = uart_port_trylock(&ssp->port); 799 799 else 800 - spin_lock(&ssp->port.lock); 800 + uart_port_lock(&ssp->port); 801 801 802 802 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); 803 803 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); ··· 807 807 __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); 808 808 809 809 if (locked) 810 - spin_unlock(&ssp->port.lock); 810 + uart_port_unlock(&ssp->port); 811 811 local_irq_restore(flags); 812 812 } 813 813