virtio/serial: initial CONSOLE support

This adds DRIVERS_VIRTIO_SERIAL_CONSOLE config and related logic to
virtio serial so that it can be used as console device. Note that
due to its dependency on OS services, this console is available late
so it is not proper for debugging too early booting issues.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu 2024-07-24 14:51:00 +08:00 committed by Xiang Xiao
parent 76bf6285c1
commit 3fecf46097
2 changed files with 45 additions and 0 deletions

View File

@ -74,6 +74,14 @@ if DRIVERS_VIRTIO_SERIAL
config DRIVERS_VIRTIO_SERIAL_BUFSIZE
int "Virtio serial driver buffer size"
default 256
config DRIVERS_VIRTIO_SERIAL_CONSOLE
bool "Virtio serial console"
default n
select SERIAL_CONSOLE
---help---
This enables using first virtio serial device as console.
endif
config DRIVERS_VIRTIO_SOUND

View File

@ -132,6 +132,10 @@ static const struct uart_ops_s g_virtio_serial_ops =
static int g_virtio_serial_idx = 0;
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE
static struct uart_dev_s *g_virtio_console;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@ -558,6 +562,16 @@ static int virtio_serial_probe(FAR struct virtio_device *vdev)
goto err_with_init;
}
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE
if (g_virtio_console == NULL)
{
DEBUGVERIFY(uart_register("/dev/console", &priv->udev));
g_virtio_console = &priv->udev;
g_virtio_console->isconsole = true;
}
#endif
g_virtio_serial_idx++;
return ret;
@ -595,3 +609,26 @@ int virtio_register_serial_driver(void)
int ret2 = virtio_register_driver(&g_virtio_rprocserial_driver);
return ret1 < 0 ? ret1 : ret2;
}
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE
/****************************************************************************
* Name: up_putc
****************************************************************************/
int up_putc(int ch)
{
if (g_virtio_console != NULL)
{
if (ch == '\n')
{
/* Add CR */
virtio_serial_send(g_virtio_console, '\r');
}
virtio_serial_send(g_virtio_console, ch);
}
return ch;
}
#endif