From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Petr Mladek" <pmladek@suse.com>,
"Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
"Tony Lindgren" <tony@atomide.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Serge Semin" <fancer.lancer@gmail.com>,
"Rengarajan S" <rengarajan.s@microchip.com>,
"Wolfram Sang" <wsa+renesas@sang-engineering.com>
Subject: Re: [PATCH next v1 1/2] serial: 8250: Switch to nbcon console
Date: Thu, 5 Sep 2024 17:15:01 +0300 [thread overview]
Message-ID: <Ztm85Y_mo5-OJveq@smile.fi.intel.com> (raw)
In-Reply-To: <20240905134719.142554-2-john.ogness@linutronix.de>
On Thu, Sep 05, 2024 at 03:53:18PM +0206, 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.
>
> The legacy code is kept in order to easily switch back to legacy mode
> by defining USE_SERIAL_8250_LEGACY_CONSOLE.
...
> static struct console univ8250_console = {
> .name = "ttyS",
> +#ifdef USE_SERIAL_8250_LEGACY_CONSOLE
Can it be done at run-time (theoretically or even practically)?
(Note that we have already knob to disable / enable consoles.)
> .write = univ8250_console_write,
> + .flags = CON_PRINTBUFFER | CON_ANYTIME,
> +#else
> + .write_atomic = univ8250_console_write_atomic,
> + .write_thread = univ8250_console_write_thread,
> + .device_lock = univ8250_console_device_lock,
> + .device_unlock = univ8250_console_device_unlock,
> + .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_NBCON,
> +#endif
> .device = uart_console_device,
> .setup = univ8250_console_setup,
> .exit = univ8250_console_exit,
> .match = univ8250_console_match,
> - .flags = CON_PRINTBUFFER | CON_ANYTIME,
> .index = -1,
> .data = &serial8250_reg,
> };
I would arrange this slightly differently, but not a big deal.
static struct console univ8250_console = {
.name = "ttyS",
.device = uart_console_device,
#ifndef USE_SERIAL_8250_LEGACY_CONSOLE
.flags = CON_PRINTBUFFER | CON_ANYTIME | CON_NBCON,
.write_atomic = univ8250_console_write_atomic,
.write_thread = univ8250_console_write_thread,
.device_lock = univ8250_console_device_lock,
.device_unlock = univ8250_console_device_unlock,
#else
.flags = CON_PRINTBUFFER | CON_ANYTIME,
.write = univ8250_console_write,
#endif
.setup = univ8250_console_setup,
.exit = univ8250_console_exit,
.match = univ8250_console_match,
.index = -1,
.data = &serial8250_reg,
};
...
> + if (nbcon_exit_unsafe(wctxt)) {
> + int len = READ_ONCE(wctxt->len);
> + int i;
unsigned ?
> + /*
> + * Write out the message. Toggle unsafe for each byte in order
> + * to give another (higher priority) context the opportunity
> + * for a friendly takeover. If such a takeover occurs, this
> + * must abort writing since wctxt->outbuf and wctxt->len are
> + * no longer valid.
> + */
> + for (i = 0; i < len; i++) {
> + if (!nbcon_enter_unsafe(wctxt))
> + break;
> +
> + uart_console_write(port, wctxt->outbuf + i, 1, serial8250_console_putchar);
> +
> + if (!nbcon_exit_unsafe(wctxt))
> + break;
> + }
> + }
...
> + /* Finally, wait for transmitter to become empty and restore IER. */
> + wait_for_xmitr(up, UART_LSR_BOTH_EMPTY);
> + if (em485) {
> + mdelay(port->rs485.delay_rts_after_send);
> + if (em485->tx_stopped)
> + up->rs485_stop_tx(up);
> + }
> + serial_port_out(port, UART_IER, ier);
> +
> + /*
> + * The receive handling will happen properly because the receive ready
> + * bit will still be set; it is not cleared on read. However, modem
> + * control will not, we must call it if we have saved something in the
> + * saved flags while processing with interrupts off.
> + */
> + if (up->msr_saved_flags)
> + serial8250_modem_status(up);
(1)
...
> + /* Atomic console not supported for rs485 mode. */
RS485
...
> + /*
> + * First save IER then disable the interrupts. The special variant to
> + * clear IER is used because atomic printing may occur without holding
> + * the port lock.
> + */
> + ier = serial_port_in(port, UART_IER);
> + __serial8250_clear_IER(up);
> +
> + /* Check scratch reg if port powered off during system sleep. */
> + if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) {
> + serial8250_console_restore(up);
> + up->canary = 0;
> + }
> +
> + if (up->console_newline_needed)
> + uart_console_write(port, "\n", 1, serial8250_console_putchar);
> + uart_console_write(port, wctxt->outbuf, wctxt->len, serial8250_console_putchar);
> +
> + /* Finally, wait for transmitter to become empty and restore IER. */
> + wait_for_xmitr(up, UART_LSR_BOTH_EMPTY);
> + serial_port_out(port, UART_IER, ier);
(2)
Feels like parts (1) and (2) duplicates existing pieces of code. May it be
refactored to minimize the duplication?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2024-09-05 14:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 13:47 [PATCH tty-next v1 0/2] convert 8250 to nbcon John Ogness
2024-09-05 13:47 ` [PATCH next v1 1/2] serial: 8250: Switch to nbcon console John Ogness
2024-09-05 14:15 ` Andy Shevchenko [this message]
2024-09-05 19:23 ` John Ogness
2024-09-05 19:30 ` Andy Shevchenko
2024-09-06 10:10 ` Greg Kroah-Hartman
2024-09-06 12:37 ` Petr Mladek
2024-09-06 13:35 ` John Ogness
2024-09-06 16:38 ` John Ogness
2024-09-07 20:39 ` Thomas Gleixner
2024-09-09 9:53 ` Andy Shevchenko
2024-09-09 12:13 ` Thomas Gleixner
2024-09-09 9:50 ` Andy Shevchenko
2024-09-05 13:47 ` [PATCH next v1 2/2] serial: 8250: Revert "drop lockdep annotation from serial8250_clear_IER()" John Ogness
2024-09-05 13:53 ` [PATCH tty-next v1 0/2] convert 8250 to nbcon Andy Shevchenko
2024-09-05 14:05 ` John Ogness
2024-09-05 14:09 ` Greg Kroah-Hartman
2024-09-05 14:12 ` John Ogness
2024-09-05 14:17 ` 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=Ztm85Y_mo5-OJveq@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=fancer.lancer@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=paulmck@kernel.org \
--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 \
--cc=wsa+renesas@sang-engineering.com \
/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;
as well as URLs for NNTP newsgroup(s).