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:
parent
76bf6285c1
commit
3fecf46097
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user