mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: John Ogness <john.ogness@linutronix.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Petr Mladek" <pmladek@suse.com>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Esben Haabendal" <esben@geanix.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Tony Lindgren" <tony@atomide.com>,
	"Rengarajan S" <rengarajan.s@microchip.com>,
	"Peter Collingbourne" <pcc@google.com>,
	"Serge Semin" <fancer.lancer@gmail.com>,
	"Lino Sanfilippo" <l.sanfilippo@kunbus.com>
Subject: Re: [PATCH tty-next v3 5/6] serial: 8250: Switch to nbcon console
Date: Wed, 30 Oct 2024 07:33:24 +0100	[thread overview]
Message-ID: <419edf13-3f5e-4d30-90d8-88118f77f704@kernel.org> (raw)
In-Reply-To: <20241025105728.602310-6-john.ogness@linutronix.de>

On 25. 10. 24, 12:57, John Ogness wrote:
> Implement the necessary callbacks to switch the 8250 console driver
> to perform as an nbcon console.
> 
> Add implementations for the nbcon console callbacks (write_atomic,
> write_thread, device_lock, device_unlock) and add CON_NBCON to the
> initial flags.
> 
> All register access in the callbacks are within unsafe sections.
> The write callbacks allow safe handover/takeover per byte and add
> a preceding newline if they take over mid-line.
> 
> For the write_atomic() case, a new irq_work is used to defer modem
> control since it may be a context that does not allow waking up
> tasks.
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
>   drivers/tty/serial/8250/8250_core.c |  35 +++++-
>   drivers/tty/serial/8250/8250_port.c | 159 ++++++++++++++++++++++------
>   include/linux/serial_8250.h         |   7 +-
>   3 files changed, 164 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 5f9f06911795..7184100129bd 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -388,12 +388,34 @@ void __init serial8250_register_ports(struct uart_driver *drv, struct device *de
>   
>   #ifdef CONFIG_SERIAL_8250_CONSOLE
>   
> -static void univ8250_console_write(struct console *co, const char *s,
> -				   unsigned int count)
> +static void univ8250_console_write_atomic(struct console *co,

Once 'co'.

> +					  struct nbcon_write_context *wctxt)
>   {
>   	struct uart_8250_port *up = &serial8250_ports[co->index];
>   
> -	serial8250_console_write(up, s, count);
> +	serial8250_console_write(up, wctxt, true);
> +}
> +
> +static void univ8250_console_write_thread(struct console *co,

Second time co.

> +					  struct nbcon_write_context *wctxt)
> +{
> +	struct uart_8250_port *up = &serial8250_ports[co->index];
> +
> +	serial8250_console_write(up, wctxt, false);
> +}
> +
> +static void univ8250_console_device_lock(struct console *con, unsigned long *flags)

And suddenly, it is 'con'.

> +{
> +	struct uart_port *up = &serial8250_ports[con->index].port;
> +
> +	__uart_port_lock_irqsave(up, flags);
> +}
> +
> +static void univ8250_console_device_unlock(struct console *con, unsigned long flags)
> +{
> +	struct uart_port *up = &serial8250_ports[con->index].port;
> +
> +	__uart_port_unlock_irqrestore(up, flags);
>   }
>   

...
>   static void serial8250_console_putchar(struct uart_port *port, unsigned char ch)
>   {
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +
>   	serial_port_out(port, UART_TX, ch);
> +
> +	if (ch == '\n')
> +		up->console_line_ended = true;
> +	else
> +		up->console_line_ended = false;

So simply:
    up->console_line_ended = ch == '\n';
?

...
> -void serial8250_console_write(struct uart_8250_port *up, const char *s,
> -			      unsigned int count)
> +void serial8250_console_write(struct uart_8250_port *up,
> +			      struct nbcon_write_context *wctxt,
> +			      bool is_atomic)
>   {
>   	struct uart_8250_em485 *em485 = up->em485;
>   	struct uart_port *port = &up->port;
> -	unsigned long flags;
> -	unsigned int ier, use_fifo;
> -	int locked = 1;
> -
> -	touch_nmi_watchdog();
> +	unsigned int ier;
> +	bool use_fifo;
>   
> -	if (oops_in_progress)
> -		locked = uart_port_trylock_irqsave(port, &flags);
> -	else
> -		uart_port_lock_irqsave(port, &flags);
> +	if (!nbcon_enter_unsafe(wctxt))
> +		return;
>   
>   	/*
> -	 *	First save the IER then disable the interrupts
> +	 * First save IER then disable the interrupts. The special variant

When you are at it:
"First, save the IER, then"

(BTW why did you remove the "the"?)

> +	 * to clear IER is used because console printing may occur without
> +	 * holding the port lock.
>   	 */
>   	ier = serial_port_in(port, UART_IER);
> -	serial8250_clear_IER(up);
> +	__serial8250_clear_IER(up);
>   
>   	/* check scratch reg to see if port powered off during system sleep */
>   	if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) {

> @@ -3497,6 +3593,9 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
>   	if (!port->iobase && !port->membase)
>   		return -ENODEV;
>   
> +	up->console_line_ended = true;
> +	up->modem_status_work = IRQ_WORK_INIT(modem_status_handler);

Looks weird ^^^.

Do:
   init_irq_work(&up->modem_status_work, modem_status_handler)

thanks,
-- 
js
suse labs

  parent reply	other threads:[~2024-10-30  6:33 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 10:57 [PATCH tty-next v3 0/6] convert 8250 to nbcon John Ogness
2024-10-25 10:57 ` [PATCH tty-next v3 1/6] serial: 8250: Adjust the timeout for FIFO mode John Ogness
2024-10-25 13:45   ` Andy Shevchenko
2024-10-25 13:51     ` Andy Shevchenko
2024-10-29 16:24     ` Wander Lairson Costa
2024-10-30  6:05   ` Jiri Slaby
2024-10-31  4:44     ` Maciej W. Rozycki
2024-10-31  8:49       ` John Ogness
2024-11-01  1:24         ` Maciej W. Rozycki
2024-11-01  8:21           ` Andy Shevchenko
2024-11-04  6:44         ` Jiri Slaby
2024-11-04  6:34       ` Jiri Slaby
2024-11-04 14:13         ` John Ogness
2024-12-02  6:12           ` Jiri Slaby
2024-12-02 16:41             ` John Ogness
2024-12-01  0:04         ` Maciej W. Rozycki
2024-10-25 10:57 ` [PATCH tty-next v3 2/6] serial: 8250: Use high-level write function for FIFO John Ogness
2024-10-25 13:50   ` Andy Shevchenko
2024-11-05 16:12   ` Petr Mladek
2024-10-25 10:57 ` [PATCH tty-next v3 3/6] serial: 8250: Split out rx stop/start code into helpers John Ogness
2024-10-25 13:55   ` Andy Shevchenko
2024-11-06 10:54   ` Petr Mladek
2024-10-25 10:57 ` [PATCH tty-next v3 4/6] serial: 8250: Specify console context for rs485_start/stop_tx John Ogness
2024-10-25 14:04   ` Andy Shevchenko
2024-10-25 14:25     ` John Ogness
2024-10-25 14:34       ` Andy Shevchenko
2024-10-30  6:13   ` Jiri Slaby
2024-10-31  9:13     ` John Ogness
2024-11-06 15:42   ` Petr Mladek
2024-11-29 17:45     ` John Ogness
2024-10-25 10:57 ` [PATCH tty-next v3 5/6] serial: 8250: Switch to nbcon console John Ogness
2024-10-25 14:22   ` Andy Shevchenko
2024-10-28 13:22     ` John Ogness
2024-11-07  9:48       ` Petr Mladek
2024-10-30  6:33   ` Jiri Slaby [this message]
2024-10-31  9:25     ` John Ogness
2024-10-25 10:57 ` [PATCH tty-next v3 6/6] serial: 8250: Revert "drop lockdep annotation from serial8250_clear_IER()" John Ogness
2024-10-25 14:05   ` Andy Shevchenko
2024-10-25 13:58 ` [PATCH tty-next v3 0/6] convert 8250 to nbcon Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=419edf13-3f5e-4d30-90d8-88118f77f704@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=esben@geanix.com \
    --cc=fancer.lancer@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=l.sanfilippo@kunbus.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pcc@google.com \
    --cc=pmladek@suse.com \
    --cc=rengarajan.s@microchip.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®