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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
adcdb2c7 cbc35085

+14 -14
+14 -14
drivers/tty/serial/altera_jtaguart.c
··· 147 147 isr = (readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) >> 148 148 ALTERA_JTAGUART_CONTROL_RI_OFF) & port->read_status_mask; 149 149 150 - spin_lock(&port->lock); 150 + uart_port_lock(port); 151 151 152 152 if (isr & ALTERA_JTAGUART_CONTROL_RE_MSK) 153 153 altera_jtaguart_rx_chars(port); 154 154 if (isr & ALTERA_JTAGUART_CONTROL_WE_MSK) 155 155 altera_jtaguart_tx_chars(port); 156 156 157 - spin_unlock(&port->lock); 157 + uart_port_unlock(port); 158 158 159 159 return IRQ_RETVAL(isr); 160 160 } ··· 180 180 return ret; 181 181 } 182 182 183 - spin_lock_irqsave(&port->lock, flags); 183 + uart_port_lock_irqsave(port, &flags); 184 184 185 185 /* Enable RX interrupts now */ 186 186 port->read_status_mask = ALTERA_JTAGUART_CONTROL_RE_MSK; 187 187 writel(port->read_status_mask, 188 188 port->membase + ALTERA_JTAGUART_CONTROL_REG); 189 189 190 - spin_unlock_irqrestore(&port->lock, flags); 190 + uart_port_unlock_irqrestore(port, flags); 191 191 192 192 return 0; 193 193 } ··· 196 196 { 197 197 unsigned long flags; 198 198 199 - spin_lock_irqsave(&port->lock, flags); 199 + uart_port_lock_irqsave(port, &flags); 200 200 201 201 /* Disable all interrupts now */ 202 202 port->read_status_mask = 0; 203 203 writel(port->read_status_mask, 204 204 port->membase + ALTERA_JTAGUART_CONTROL_REG); 205 205 206 - spin_unlock_irqrestore(&port->lock, flags); 206 + uart_port_unlock_irqrestore(port, flags); 207 207 208 208 free_irq(port->irq, port); 209 209 } ··· 264 264 unsigned long flags; 265 265 u32 status; 266 266 267 - spin_lock_irqsave(&port->lock, flags); 267 + uart_port_lock_irqsave(port, &flags); 268 268 while (!altera_jtaguart_tx_space(port, &status)) { 269 - spin_unlock_irqrestore(&port->lock, flags); 269 + uart_port_unlock_irqrestore(port, flags); 270 270 271 271 if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) == 0) { 272 272 return; /* no connection activity */ 273 273 } 274 274 275 275 cpu_relax(); 276 - spin_lock_irqsave(&port->lock, flags); 276 + uart_port_lock_irqsave(port, &flags); 277 277 } 278 278 writel(c, port->membase + ALTERA_JTAGUART_DATA_REG); 279 - spin_unlock_irqrestore(&port->lock, flags); 279 + uart_port_unlock_irqrestore(port, flags); 280 280 } 281 281 #else 282 282 static void altera_jtaguart_console_putc(struct uart_port *port, unsigned char c) 283 283 { 284 284 unsigned long flags; 285 285 286 - spin_lock_irqsave(&port->lock, flags); 286 + uart_port_lock_irqsave(port, &flags); 287 287 while (!altera_jtaguart_tx_space(port, NULL)) { 288 - spin_unlock_irqrestore(&port->lock, flags); 288 + uart_port_unlock_irqrestore(port, flags); 289 289 cpu_relax(); 290 - spin_lock_irqsave(&port->lock, flags); 290 + uart_port_lock_irqsave(port, &flags); 291 291 } 292 292 writel(c, port->membase + ALTERA_JTAGUART_DATA_REG); 293 - spin_unlock_irqrestore(&port->lock, flags); 293 + uart_port_unlock_irqrestore(port, flags); 294 294 } 295 295 #endif 296 296