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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
e4a13758 89dd4aff

+26 -26
+26 -26
drivers/tty/serial/8250/8250_omap.c
··· 401 401 * interrupts disabled. 402 402 */ 403 403 pm_runtime_get_sync(port->dev); 404 - spin_lock_irq(&port->lock); 404 + uart_port_lock_irq(port); 405 405 406 406 /* 407 407 * Update the per-port timeout. ··· 504 504 } 505 505 omap8250_restore_regs(up); 506 506 507 - spin_unlock_irq(&up->port.lock); 507 + uart_port_unlock_irq(&up->port); 508 508 pm_runtime_mark_last_busy(port->dev); 509 509 pm_runtime_put_autosuspend(port->dev); 510 510 ··· 529 529 pm_runtime_get_sync(port->dev); 530 530 531 531 /* Synchronize UART_IER access against the console. */ 532 - spin_lock_irq(&port->lock); 532 + uart_port_lock_irq(port); 533 533 534 534 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 535 535 efr = serial_in(up, UART_EFR); ··· 541 541 serial_out(up, UART_EFR, efr); 542 542 serial_out(up, UART_LCR, 0); 543 543 544 - spin_unlock_irq(&port->lock); 544 + uart_port_unlock_irq(port); 545 545 546 546 pm_runtime_mark_last_busy(port->dev); 547 547 pm_runtime_put_autosuspend(port->dev); ··· 660 660 unsigned long delay; 661 661 662 662 /* Synchronize UART_IER access against the console. */ 663 - spin_lock(&port->lock); 663 + uart_port_lock(port); 664 664 up->ier = port->serial_in(port, UART_IER); 665 665 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { 666 666 port->ops->stop_rx(port); ··· 670 670 */ 671 671 cancel_delayed_work(&up->overrun_backoff); 672 672 } 673 - spin_unlock(&port->lock); 673 + uart_port_unlock(port); 674 674 675 675 delay = msecs_to_jiffies(up->overrun_backoff_time_ms); 676 676 schedule_delayed_work(&up->overrun_backoff, delay); ··· 717 717 } 718 718 719 719 /* Synchronize UART_IER access against the console. */ 720 - spin_lock_irq(&port->lock); 720 + uart_port_lock_irq(port); 721 721 up->ier = UART_IER_RLSI | UART_IER_RDI; 722 722 serial_out(up, UART_IER, up->ier); 723 - spin_unlock_irq(&port->lock); 723 + uart_port_unlock_irq(port); 724 724 725 725 #ifdef CONFIG_PM 726 726 up->capabilities |= UART_CAP_RPM; ··· 733 733 serial_out(up, UART_OMAP_WER, priv->wer); 734 734 735 735 if (up->dma && !(priv->habit & UART_HAS_EFR2)) { 736 - spin_lock_irq(&port->lock); 736 + uart_port_lock_irq(port); 737 737 up->dma->rx_dma(up); 738 - spin_unlock_irq(&port->lock); 738 + uart_port_unlock_irq(port); 739 739 } 740 740 741 741 enable_irq(up->port.irq); ··· 761 761 serial_out(up, UART_OMAP_EFR2, 0x0); 762 762 763 763 /* Synchronize UART_IER access against the console. */ 764 - spin_lock_irq(&port->lock); 764 + uart_port_lock_irq(port); 765 765 up->ier = 0; 766 766 serial_out(up, UART_IER, 0); 767 - spin_unlock_irq(&port->lock); 767 + uart_port_unlock_irq(port); 768 768 disable_irq_nosync(up->port.irq); 769 769 dev_pm_clear_wake_irq(port->dev); 770 770 ··· 789 789 790 790 pm_runtime_get_sync(port->dev); 791 791 792 - spin_lock_irqsave(&port->lock, flags); 792 + uart_port_lock_irqsave(port, &flags); 793 793 port->ops->stop_rx(port); 794 794 priv->throttled = true; 795 - spin_unlock_irqrestore(&port->lock, flags); 795 + uart_port_unlock_irqrestore(port, flags); 796 796 797 797 pm_runtime_mark_last_busy(port->dev); 798 798 pm_runtime_put_autosuspend(port->dev); ··· 807 807 pm_runtime_get_sync(port->dev); 808 808 809 809 /* Synchronize UART_IER access against the console. */ 810 - spin_lock_irqsave(&port->lock, flags); 810 + uart_port_lock_irqsave(port, &flags); 811 811 priv->throttled = false; 812 812 if (up->dma) 813 813 up->dma->rx_dma(up); 814 814 up->ier |= UART_IER_RLSI | UART_IER_RDI; 815 815 port->read_status_mask |= UART_LSR_DR; 816 816 serial_out(up, UART_IER, up->ier); 817 - spin_unlock_irqrestore(&port->lock, flags); 817 + uart_port_unlock_irqrestore(port, flags); 818 818 819 819 pm_runtime_mark_last_busy(port->dev); 820 820 pm_runtime_put_autosuspend(port->dev); ··· 958 958 unsigned long flags; 959 959 960 960 /* Synchronize UART_IER access against the console. */ 961 - spin_lock_irqsave(&p->port.lock, flags); 961 + uart_port_lock_irqsave(&p->port, &flags); 962 962 963 963 /* 964 964 * If the tx status is not DMA_COMPLETE, then this is a delayed ··· 967 967 */ 968 968 if (dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state) != 969 969 DMA_COMPLETE) { 970 - spin_unlock_irqrestore(&p->port.lock, flags); 970 + uart_port_unlock_irqrestore(&p->port, flags); 971 971 return; 972 972 } 973 973 __dma_rx_do_complete(p); ··· 978 978 omap_8250_rx_dma(p); 979 979 } 980 980 981 - spin_unlock_irqrestore(&p->port.lock, flags); 981 + uart_port_unlock_irqrestore(&p->port, flags); 982 982 } 983 983 984 984 static void omap_8250_rx_dma_flush(struct uart_8250_port *p) ··· 1083 1083 dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, 1084 1084 UART_XMIT_SIZE, DMA_TO_DEVICE); 1085 1085 1086 - spin_lock_irqsave(&p->port.lock, flags); 1086 + uart_port_lock_irqsave(&p->port, &flags); 1087 1087 1088 1088 dma->tx_running = 0; 1089 1089 ··· 1112 1112 serial8250_set_THRI(p); 1113 1113 } 1114 1114 1115 - spin_unlock_irqrestore(&p->port.lock, flags); 1115 + uart_port_unlock_irqrestore(&p->port, flags); 1116 1116 } 1117 1117 1118 1118 static int omap_8250_tx_dma(struct uart_8250_port *p) ··· 1278 1278 return IRQ_HANDLED; 1279 1279 } 1280 1280 1281 - spin_lock(&port->lock); 1281 + uart_port_lock(port); 1282 1282 1283 1283 status = serial_port_in(port, UART_LSR); 1284 1284 ··· 1761 1761 up = serial8250_get_port(priv->line); 1762 1762 1763 1763 if (up && omap8250_lost_context(up)) { 1764 - spin_lock_irq(&up->port.lock); 1764 + uart_port_lock_irq(&up->port); 1765 1765 omap8250_restore_regs(up); 1766 - spin_unlock_irq(&up->port.lock); 1766 + uart_port_unlock_irq(&up->port); 1767 1767 } 1768 1768 1769 1769 if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) { 1770 - spin_lock_irq(&up->port.lock); 1770 + uart_port_lock_irq(&up->port); 1771 1771 omap_8250_rx_dma(up); 1772 - spin_unlock_irq(&up->port.lock); 1772 + uart_port_unlock_irq(&up->port); 1773 1773 } 1774 1774 1775 1775 priv->latency = priv->calc_latency;