Skip to content

Commit e58d551

Browse files
KAGA-KOKOgregkh
authored andcommitted
serial: sprd: 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 <[email protected]> Signed-off-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 93614ef commit e58d551

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

drivers/tty/serial/sprd_serial.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void sprd_complete_tx_dma(void *data)
247247
struct circ_buf *xmit = &port->state->xmit;
248248
unsigned long flags;
249249

250-
spin_lock_irqsave(&port->lock, flags);
250+
uart_port_lock_irqsave(port, &flags);
251251
dma_unmap_single(port->dev, sp->tx_dma.phys_addr,
252252
sp->tx_dma.trans_len, DMA_TO_DEVICE);
253253

@@ -260,7 +260,7 @@ static void sprd_complete_tx_dma(void *data)
260260
sprd_tx_dma_config(port))
261261
sp->tx_dma.trans_len = 0;
262262

263-
spin_unlock_irqrestore(&port->lock, flags);
263+
uart_port_unlock_irqrestore(port, flags);
264264
}
265265

266266
static int sprd_uart_dma_submit(struct uart_port *port,
@@ -429,13 +429,13 @@ static void sprd_complete_rx_dma(void *data)
429429
enum dma_status status;
430430
unsigned long flags;
431431

432-
spin_lock_irqsave(&port->lock, flags);
432+
uart_port_lock_irqsave(port, &flags);
433433

434434
status = dmaengine_tx_status(sp->rx_dma.chn,
435435
sp->rx_dma.cookie, &state);
436436
if (status != DMA_COMPLETE) {
437437
sprd_stop_rx(port);
438-
spin_unlock_irqrestore(&port->lock, flags);
438+
uart_port_unlock_irqrestore(port, flags);
439439
return;
440440
}
441441

@@ -449,7 +449,7 @@ static void sprd_complete_rx_dma(void *data)
449449
if (sprd_start_dma_rx(port))
450450
sprd_stop_rx(port);
451451

452-
spin_unlock_irqrestore(&port->lock, flags);
452+
uart_port_unlock_irqrestore(port, flags);
453453
}
454454

455455
static int sprd_start_dma_rx(struct uart_port *port)
@@ -638,12 +638,12 @@ static irqreturn_t sprd_handle_irq(int irq, void *dev_id)
638638
struct uart_port *port = dev_id;
639639
unsigned int ims;
640640

641-
spin_lock(&port->lock);
641+
uart_port_lock(port);
642642

643643
ims = serial_in(port, SPRD_IMSR);
644644

645645
if (!ims) {
646-
spin_unlock(&port->lock);
646+
uart_port_unlock(port);
647647
return IRQ_NONE;
648648
}
649649

@@ -660,7 +660,7 @@ static irqreturn_t sprd_handle_irq(int irq, void *dev_id)
660660
if (ims & SPRD_IMSR_TX_FIFO_EMPTY)
661661
sprd_tx(port);
662662

663-
spin_unlock(&port->lock);
663+
uart_port_unlock(port);
664664

665665
return IRQ_HANDLED;
666666
}
@@ -727,13 +727,13 @@ static int sprd_startup(struct uart_port *port)
727727
serial_out(port, SPRD_CTL1, fc);
728728

729729
/* enable interrupt */
730-
spin_lock_irqsave(&port->lock, flags);
730+
uart_port_lock_irqsave(port, &flags);
731731
ien = serial_in(port, SPRD_IEN);
732732
ien |= SPRD_IEN_BREAK_DETECT | SPRD_IEN_TIMEOUT;
733733
if (!sp->rx_dma.enable)
734734
ien |= SPRD_IEN_RX_FULL;
735735
serial_out(port, SPRD_IEN, ien);
736-
spin_unlock_irqrestore(&port->lock, flags);
736+
uart_port_unlock_irqrestore(port, flags);
737737

738738
return 0;
739739
}
@@ -793,7 +793,7 @@ static void sprd_set_termios(struct uart_port *port, struct ktermios *termios,
793793
lcr |= SPRD_LCR_EVEN_PAR;
794794
}
795795

796-
spin_lock_irqsave(&port->lock, flags);
796+
uart_port_lock_irqsave(port, &flags);
797797

798798
/* update the per-port timeout */
799799
uart_update_timeout(port, termios->c_cflag, baud);
@@ -837,7 +837,7 @@ static void sprd_set_termios(struct uart_port *port, struct ktermios *termios,
837837
fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF;
838838
serial_out(port, SPRD_CTL1, fc);
839839

840-
spin_unlock_irqrestore(&port->lock, flags);
840+
uart_port_unlock_irqrestore(port, flags);
841841

842842
/* Don't rewrite B0 */
843843
if (tty_termios_baud_rate(termios))
@@ -974,17 +974,17 @@ static void sprd_console_write(struct console *co, const char *s,
974974
if (port->sysrq)
975975
locked = 0;
976976
else if (oops_in_progress)
977-
locked = spin_trylock_irqsave(&port->lock, flags);
977+
locked = uart_port_trylock_irqsave(port, &flags);
978978
else
979-
spin_lock_irqsave(&port->lock, flags);
979+
uart_port_lock_irqsave(port, &flags);
980980

981981
uart_console_write(port, s, count, sprd_console_putchar);
982982

983983
/* wait for transmitter to become empty */
984984
wait_for_xmitr(port);
985985

986986
if (locked)
987-
spin_unlock_irqrestore(&port->lock, flags);
987+
uart_port_unlock_irqrestore(port, flags);
988988
}
989989

990990
static int sprd_console_setup(struct console *co, char *options)

0 commit comments

Comments
 (0)