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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
01d6461a 0783a74f

+10 -10
+10 -10
drivers/tty/serial/amba-pl010.c
··· 207 207 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; 208 208 int handled = 0; 209 209 210 - spin_lock(&port->lock); 210 + uart_port_lock(port); 211 211 212 212 status = readb(port->membase + UART010_IIR); 213 213 if (status) { ··· 228 228 handled = 1; 229 229 } 230 230 231 - spin_unlock(&port->lock); 231 + uart_port_unlock(port); 232 232 233 233 return IRQ_RETVAL(handled); 234 234 } ··· 270 270 unsigned long flags; 271 271 unsigned int lcr_h; 272 272 273 - spin_lock_irqsave(&port->lock, flags); 273 + uart_port_lock_irqsave(port, &flags); 274 274 lcr_h = readb(port->membase + UART010_LCRH); 275 275 if (break_state == -1) 276 276 lcr_h |= UART01x_LCRH_BRK; 277 277 else 278 278 lcr_h &= ~UART01x_LCRH_BRK; 279 279 writel(lcr_h, port->membase + UART010_LCRH); 280 - spin_unlock_irqrestore(&port->lock, flags); 280 + uart_port_unlock_irqrestore(port, flags); 281 281 } 282 282 283 283 static int pl010_startup(struct uart_port *port) ··· 385 385 if (port->fifosize > 1) 386 386 lcr_h |= UART01x_LCRH_FEN; 387 387 388 - spin_lock_irqsave(&port->lock, flags); 388 + uart_port_lock_irqsave(port, &flags); 389 389 390 390 /* 391 391 * Update the per-port timeout. ··· 438 438 writel(lcr_h, port->membase + UART010_LCRH); 439 439 writel(old_cr, port->membase + UART010_CR); 440 440 441 - spin_unlock_irqrestore(&port->lock, flags); 441 + uart_port_unlock_irqrestore(port, flags); 442 442 } 443 443 444 444 static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termios) 445 445 { 446 446 if (termios->c_line == N_PPS) { 447 447 port->flags |= UPF_HARDPPS_CD; 448 - spin_lock_irq(&port->lock); 448 + uart_port_lock_irq(port); 449 449 pl010_enable_ms(port); 450 - spin_unlock_irq(&port->lock); 450 + uart_port_unlock_irq(port); 451 451 } else { 452 452 port->flags &= ~UPF_HARDPPS_CD; 453 453 if (!UART_ENABLE_MS(port, termios->c_cflag)) { 454 - spin_lock_irq(&port->lock); 454 + uart_port_lock_irq(port); 455 455 pl010_disable_ms(port); 456 - spin_unlock_irq(&port->lock); 456 + uart_port_unlock_irq(port); 457 457 } 458 458 } 459 459 }