virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
/*
|
|
|
|
* Virtio Console and Generic Serial Port Devices
|
|
|
|
*
|
2010-04-27 14:34:02 +02:00
|
|
|
* Copyright Red Hat, Inc. 2009, 2010
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Amit Shah <amit.shah@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-char.h"
|
2011-02-03 08:35:07 +01:00
|
|
|
#include "qemu-error.h"
|
2011-07-05 13:07:49 +02:00
|
|
|
#include "trace.h"
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
#include "virtio-serial.h"
|
|
|
|
|
|
|
|
typedef struct VirtConsole {
|
|
|
|
VirtIOSerialPort port;
|
|
|
|
CharDriverState *chr;
|
|
|
|
} VirtConsole;
|
|
|
|
|
|
|
|
|
|
|
|
/* Callback function that's called when the guest sends us data */
|
2010-12-13 13:20:07 +01:00
|
|
|
static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
{
|
|
|
|
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
2011-07-05 13:07:49 +02:00
|
|
|
ssize_t ret;
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
|
2011-12-21 07:58:27 +01:00
|
|
|
if (!vcon->chr) {
|
|
|
|
/* If there's no backend, we can just say we consumed all data. */
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:28 +02:00
|
|
|
ret = qemu_chr_fe_write(vcon->chr, buf, len);
|
2011-07-05 13:07:49 +02:00
|
|
|
trace_virtio_console_flush_buf(port->id, len, ret);
|
2011-07-07 14:05:27 +02:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
/*
|
|
|
|
* Ideally we'd get a better error code than just -1, but
|
|
|
|
* that's what the chardev interface gives us right now. If
|
|
|
|
* we had a finer-grained message, like -EPIPE, we could close
|
|
|
|
* this connection. Absent such error messages, the most we
|
|
|
|
* can do is to return 0 here.
|
|
|
|
*
|
|
|
|
* This will prevent stray -1 values to go to
|
|
|
|
* virtio-serial-bus.c and cause abort()s in
|
|
|
|
* do_flush_queued_data().
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
}
|
2011-07-05 13:07:49 +02:00
|
|
|
return ret;
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
}
|
|
|
|
|
2011-03-24 11:12:03 +01:00
|
|
|
/* Callback function that's called when the guest opens the port */
|
|
|
|
static void guest_open(VirtIOSerialPort *port)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
|
|
|
|
2011-12-21 07:58:27 +01:00
|
|
|
if (!vcon->chr) {
|
|
|
|
return;
|
|
|
|
}
|
2011-08-15 18:17:32 +02:00
|
|
|
qemu_chr_fe_open(vcon->chr);
|
2011-03-24 11:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback function that's called when the guest closes the port */
|
|
|
|
static void guest_close(VirtIOSerialPort *port)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
|
|
|
|
2011-12-21 07:58:27 +01:00
|
|
|
if (!vcon->chr) {
|
|
|
|
return;
|
|
|
|
}
|
2011-08-15 18:17:33 +02:00
|
|
|
qemu_chr_fe_close(vcon->chr);
|
2011-03-24 11:12:03 +01:00
|
|
|
}
|
|
|
|
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
/* Readiness of the guest to accept data on a port */
|
|
|
|
static int chr_can_read(void *opaque)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = opaque;
|
|
|
|
|
|
|
|
return virtio_serial_guest_ready(&vcon->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send data from a char device over to the guest */
|
|
|
|
static void chr_read(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = opaque;
|
|
|
|
|
2011-07-05 13:07:49 +02:00
|
|
|
trace_virtio_console_chr_read(vcon->port.id, size);
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
virtio_serial_write(&vcon->port, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chr_event(void *opaque, int event)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = opaque;
|
|
|
|
|
2011-07-05 13:07:49 +02:00
|
|
|
trace_virtio_console_chr_event(vcon->port.id, event);
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
switch (event) {
|
2010-12-10 12:40:43 +01:00
|
|
|
case CHR_EVENT_OPENED:
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
virtio_serial_open(&vcon->port);
|
|
|
|
break;
|
|
|
|
case CHR_EVENT_CLOSED:
|
|
|
|
virtio_serial_close(&vcon->port);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:21:14 +02:00
|
|
|
static int virtconsole_initfn(VirtIOSerialPort *port)
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
{
|
2011-05-25 14:21:14 +02:00
|
|
|
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
2011-12-04 19:38:12 +01:00
|
|
|
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
2011-05-25 14:21:13 +02:00
|
|
|
|
2011-12-04 19:38:12 +01:00
|
|
|
if (port->id == 0 && !k->is_console) {
|
2011-05-25 14:21:14 +02:00
|
|
|
error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
if (vcon->chr) {
|
|
|
|
qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
|
|
|
|
vcon);
|
|
|
|
}
|
2010-04-05 10:50:29 +02:00
|
|
|
|
2011-05-25 14:21:14 +02:00
|
|
|
return 0;
|
2010-04-05 10:50:29 +02:00
|
|
|
}
|
|
|
|
|
2011-12-04 19:38:12 +01:00
|
|
|
static Property virtconsole_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtconsole_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:38:12 +01:00
|
|
|
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
|
|
|
|
|
|
|
|
k->is_console = true;
|
|
|
|
k->init = virtconsole_initfn;
|
|
|
|
k->have_data = flush_buf;
|
|
|
|
k->guest_open = guest_open;
|
|
|
|
k->guest_close = guest_close;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->props = virtconsole_properties;
|
2011-12-04 19:38:12 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static TypeInfo virtconsole_info = {
|
|
|
|
.name = "virtconsole",
|
|
|
|
.parent = TYPE_VIRTIO_SERIAL_PORT,
|
|
|
|
.instance_size = sizeof(VirtConsole),
|
|
|
|
.class_init = virtconsole_class_init,
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
};
|
|
|
|
|
2011-12-04 19:38:12 +01:00
|
|
|
static Property virtserialport_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtserialport_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:38:12 +01:00
|
|
|
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = virtconsole_initfn;
|
|
|
|
k->have_data = flush_buf;
|
|
|
|
k->guest_open = guest_open;
|
|
|
|
k->guest_close = guest_close;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->props = virtserialport_properties;
|
2011-12-04 19:38:12 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static TypeInfo virtserialport_info = {
|
|
|
|
.name = "virtserialport",
|
|
|
|
.parent = TYPE_VIRTIO_SERIAL_PORT,
|
|
|
|
.instance_size = sizeof(VirtConsole),
|
|
|
|
.class_init = virtserialport_class_init,
|
2010-01-19 20:06:56 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void virtconsole_register_types(void)
|
2010-01-19 20:06:56 +01:00
|
|
|
{
|
2012-02-09 15:20:55 +01:00
|
|
|
type_register_static(&virtconsole_info);
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&virtserialport_info);
|
2010-01-19 20:06:56 +01:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(virtconsole_register_types)
|