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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
3ea01838 71007c5e

+13 -13
+13 -13
drivers/tty/serial/sunplus-uart.c
··· 184 184 unsigned long flags; 185 185 unsigned int lcr; 186 186 187 - spin_lock_irqsave(&port->lock, flags); 187 + uart_port_lock_irqsave(port, &flags); 188 188 189 189 lcr = readl(port->membase + SUP_UART_LCR); 190 190 ··· 195 195 196 196 writel(lcr, port->membase + SUP_UART_LCR); 197 197 198 - spin_unlock_irqrestore(&port->lock, flags); 198 + uart_port_unlock_irqrestore(port, flags); 199 199 } 200 200 201 201 static void transmit_chars(struct uart_port *port) ··· 277 277 struct uart_port *port = args; 278 278 unsigned int isc; 279 279 280 - spin_lock(&port->lock); 280 + uart_port_lock(port); 281 281 282 282 isc = readl(port->membase + SUP_UART_ISC); 283 283 ··· 287 287 if (isc & SUP_UART_ISC_TX) 288 288 transmit_chars(port); 289 289 290 - spin_unlock(&port->lock); 290 + uart_port_unlock(port); 291 291 292 292 return IRQ_HANDLED; 293 293 } ··· 302 302 if (ret) 303 303 return ret; 304 304 305 - spin_lock_irqsave(&port->lock, flags); 305 + uart_port_lock_irqsave(port, &flags); 306 306 /* isc define Bit[7:4] int setting, Bit[3:0] int status 307 307 * isc register will clean Bit[3:0] int status after read 308 308 * only do a write to Bit[7:4] int setting 309 309 */ 310 310 isc |= SUP_UART_ISC_RXM; 311 311 writel(isc, port->membase + SUP_UART_ISC); 312 - spin_unlock_irqrestore(&port->lock, flags); 312 + uart_port_unlock_irqrestore(port, flags); 313 313 314 314 return 0; 315 315 } ··· 318 318 { 319 319 unsigned long flags; 320 320 321 - spin_lock_irqsave(&port->lock, flags); 321 + uart_port_lock_irqsave(port, &flags); 322 322 /* isc define Bit[7:4] int setting, Bit[3:0] int status 323 323 * isc register will clean Bit[3:0] int status after read 324 324 * only do a write to Bit[7:4] int setting 325 325 */ 326 326 writel(0, port->membase + SUP_UART_ISC); /* disable all interrupt */ 327 - spin_unlock_irqrestore(&port->lock, flags); 327 + uart_port_unlock_irqrestore(port, flags); 328 328 329 329 free_irq(port->irq, port); 330 330 } ··· 372 372 lcr |= UART_LCR_EPAR; 373 373 } 374 374 375 - spin_lock_irqsave(&port->lock, flags); 375 + uart_port_lock_irqsave(port, &flags); 376 376 377 377 uart_update_timeout(port, termios->c_cflag, baud); 378 378 ··· 407 407 writel(div_l, port->membase + SUP_UART_DIV_L); 408 408 writel(lcr, port->membase + SUP_UART_LCR); 409 409 410 - spin_unlock_irqrestore(&port->lock, flags); 410 + uart_port_unlock_irqrestore(port, flags); 411 411 } 412 412 413 413 static void sunplus_set_ldisc(struct uart_port *port, struct ktermios *termios) ··· 517 517 if (sunplus_console_ports[co->index]->port.sysrq) 518 518 locked = 0; 519 519 else if (oops_in_progress) 520 - locked = spin_trylock(&sunplus_console_ports[co->index]->port.lock); 520 + locked = uart_port_trylock(&sunplus_console_ports[co->index]->port); 521 521 else 522 - spin_lock(&sunplus_console_ports[co->index]->port.lock); 522 + uart_port_lock(&sunplus_console_ports[co->index]->port); 523 523 524 524 uart_console_write(&sunplus_console_ports[co->index]->port, s, count, 525 525 sunplus_uart_console_putchar); 526 526 527 527 if (locked) 528 - spin_unlock(&sunplus_console_ports[co->index]->port.lock); 528 + uart_port_unlock(&sunplus_console_ports[co->index]->port); 529 529 530 530 local_irq_restore(flags); 531 531 }