{ 'type': 'ChardevFile', 'data': { '*in' : 'str',
'out' : 'str' } }
+##
+# @ChardevPort:
+#
+# Configuration info for device chardevs.
+#
+# @device: The name of the special file for the device,
+# i.e. /dev/ttyS0 on Unix or COM1: on Windows
+# @type: What kind of device this is.
+#
+# Since: 1.4
+##
+{ 'enum': 'ChardevPortKind', 'data': [ 'serial' ] }
+
+{ 'type': 'ChardevPort', 'data': { 'device' : 'str',
+ 'type' : 'ChardevPortKind'} }
+
##
# @ChardevBackend:
#
{ 'type': 'ChardevDummy', 'data': { } }
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
+ 'port' : 'ChardevPort',
'null' : 'ChardevDummy' } }
##
}
}
+static CharDriverState *qemu_chr_open_tty_fd(int fd)
+{
+ CharDriverState *chr;
+
+ tty_serial_init(fd, 115200, 'N', 8, 1);
+ chr = qemu_chr_open_fd(fd, fd);
+ chr->chr_ioctl = tty_serial_ioctl;
+ chr->chr_close = qemu_chr_close_tty;
+ return chr;
+}
+
static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
{
const char *filename = qemu_opt_get(opts, "path");
- CharDriverState *chr;
int fd;
TFR(fd = qemu_open(filename, O_RDWR | O_NONBLOCK));
if (fd < 0) {
return NULL;
}
- tty_serial_init(fd, 115200, 'N', 8, 1);
- chr = qemu_chr_open_fd(fd, fd);
- chr->chr_ioctl = tty_serial_ioctl;
- chr->chr_close = qemu_chr_close_tty;
- return chr;
+ return qemu_chr_open_tty_fd(fd);
}
#endif /* __linux__ || __sun__ */
return 0;
}
-static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
+static CharDriverState *qemu_chr_open_win_path(const char *filename)
{
- const char *filename = qemu_opt_get(opts, "path");
CharDriverState *chr;
WinCharState *s;
return chr;
}
+static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
+{
+ return qemu_chr_open_win_path(qemu_opt_get(opts, "path"));
+}
+
static int win_chr_pipe_poll(void *opaque)
{
CharDriverState *chr = opaque;
#endif
#ifdef HAVE_CHARDEV_TTY
{ .name = "tty", .open = qemu_chr_open_tty },
+ { .name = "serial", .open = qemu_chr_open_tty },
{ .name = "pty", .open = qemu_chr_open_pty },
#endif
#ifdef HAVE_CHARDEV_PARPORT
return qemu_chr_open_win_file(out);
}
+static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)
+{
+ switch (port->type) {
+ case CHARDEV_PORT_KIND_SERIAL:
+ return qemu_chr_open_win_path(port->device);
+ default:
+ error_setg(errp, "unknown chardev port (%d)", port->type);
+ return NULL;
+ }
+}
+
#else /* WIN32 */
static int qmp_chardev_open_file_source(char *src, int flags,
return qemu_chr_open_fd(in, out);
}
+static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)
+{
+ int flags, fd;
+
+ switch (port->type) {
+#ifdef HAVE_CHARDEV_TTY
+ case CHARDEV_PORT_KIND_SERIAL:
+ flags = O_RDWR;
+ fd = qmp_chardev_open_file_source(port->device, flags, errp);
+ if (error_is_set(errp)) {
+ return NULL;
+ }
+ socket_set_nonblock(fd);
+ return qemu_chr_open_tty_fd(fd);
+#endif
+ default:
+ error_setg(errp, "unknown chardev port (%d)", port->type);
+ return NULL;
+ }
+}
+
#endif /* WIN32 */
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
case CHARDEV_BACKEND_KIND_FILE:
chr = qmp_chardev_open_file(backend->file, errp);
break;
+ case CHARDEV_BACKEND_KIND_PORT:
+ chr = qmp_chardev_open_port(backend->port, errp);
+ break;
case CHARDEV_BACKEND_KIND_NULL:
chr = qemu_chr_open_null(NULL);
break;
#endif
#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+ "-chardev serial,id=id,path=path[,mux=on|off]\n"
"-chardev tty,id=id,path=path[,mux=on|off]\n"
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
Send traffic from the guest to a serial device on the host.
-@option{serial} is
-only available on Windows hosts.
+On Unix hosts serial will actually accept any tty device,
+not only serial lines.
@option{path} specifies the name of the serial device to open.
@item -chardev tty ,id=@var{id} ,path=@var{path}
-Connect to a local tty device.
-
@option{tty} is only available on Linux, Sun, FreeBSD, NetBSD, OpenBSD and
-DragonFlyBSD hosts.
+DragonFlyBSD hosts. It is an alias for -serial.
@option{path} specifies the path to the tty. @option{path} is required.