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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* A bus for connecting virtio serial and console ports
|
|
|
|
*
|
2010-04-27 16:34:02 +04:00
|
|
|
* Copyright (C) 2009, 2010 Red Hat, Inc.
|
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 22:06:52 +03:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Amit Shah <amit.shah@redhat.com>
|
|
|
|
*
|
|
|
|
* Some earlier parts are:
|
|
|
|
* Copyright IBM, Corp. 2008
|
|
|
|
* authored by
|
|
|
|
* Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
2012-01-13 20:44:23 +04:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
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 22:06:52 +03:00
|
|
|
*/
|
|
|
|
|
2010-04-27 16:34:05 +04:00
|
|
|
#include "iov.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 22:06:52 +03:00
|
|
|
#include "monitor.h"
|
|
|
|
#include "qemu-queue.h"
|
|
|
|
#include "sysbus.h"
|
2011-07-05 15:06:39 +04: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 22:06:52 +03:00
|
|
|
#include "virtio-serial.h"
|
|
|
|
|
|
|
|
/* The virtio-serial bus on top of which the ports will ride as devices */
|
|
|
|
struct VirtIOSerialBus {
|
|
|
|
BusState qbus;
|
|
|
|
|
|
|
|
/* This is the parent device that provides the bus for ports. */
|
|
|
|
VirtIOSerial *vser;
|
|
|
|
|
|
|
|
/* The maximum number of ports that can ride on top of this bus */
|
|
|
|
uint32_t max_nr_ports;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VirtIOSerial {
|
|
|
|
VirtIODevice vdev;
|
|
|
|
|
|
|
|
VirtQueue *c_ivq, *c_ovq;
|
|
|
|
/* Arrays of ivqs and ovqs: one per port */
|
|
|
|
VirtQueue **ivqs, **ovqs;
|
|
|
|
|
2011-05-25 16:21:10 +04:00
|
|
|
VirtIOSerialBus bus;
|
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 22:06:52 +03:00
|
|
|
|
2010-08-19 05:21:04 +04:00
|
|
|
DeviceState *qdev;
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
QTAILQ_HEAD(, VirtIOSerialPort) ports;
|
2010-04-27 16:33:59 +04:00
|
|
|
|
|
|
|
/* bitmap for identifying active ports */
|
|
|
|
uint32_t *ports_map;
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
struct virtio_console_config config;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
|
|
|
|
{
|
|
|
|
VirtIOSerialPort *port;
|
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
if (id == VIRTIO_CONSOLE_BAD_ID) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
QTAILQ_FOREACH(port, &vser->ports, next) {
|
|
|
|
if (port->id == id)
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VirtIOSerialPort *find_port_by_vq(VirtIOSerial *vser, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtIOSerialPort *port;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(port, &vser->ports, next) {
|
|
|
|
if (port->ivq == vq || port->ovq == vq)
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
static bool use_multiport(VirtIOSerial *vser)
|
|
|
|
{
|
|
|
|
return vser->vdev.guest_features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
|
|
|
|
}
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
static size_t write_to_port(VirtIOSerialPort *port,
|
|
|
|
const uint8_t *buf, size_t size)
|
|
|
|
{
|
|
|
|
VirtQueueElement elem;
|
|
|
|
VirtQueue *vq;
|
2010-04-27 16:34:05 +04:00
|
|
|
size_t offset;
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
vq = port->ivq;
|
|
|
|
if (!virtio_queue_ready(vq)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:34:05 +04:00
|
|
|
offset = 0;
|
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 22:06:52 +03:00
|
|
|
while (offset < size) {
|
2010-04-27 16:34:05 +04:00
|
|
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
if (!virtqueue_pop(vq, &elem)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:34:05 +04:00
|
|
|
len = iov_from_buf(elem.in_sg, elem.in_num,
|
2011-07-11 17:02:23 +04:00
|
|
|
buf + offset, 0, size - offset);
|
2010-04-27 16:34:05 +04:00
|
|
|
offset += 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 22:06:52 +03:00
|
|
|
|
|
|
|
virtqueue_push(vq, &elem, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtio_notify(&port->vser->vdev, vq);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2011-01-07 12:03:36 +03:00
|
|
|
static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev)
|
2010-04-27 16:34:10 +04:00
|
|
|
{
|
|
|
|
VirtQueueElement elem;
|
|
|
|
|
2011-02-04 11:54:18 +03:00
|
|
|
if (!virtio_queue_ready(vq)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-07 12:03:36 +03:00
|
|
|
while (virtqueue_pop(vq, &elem)) {
|
|
|
|
virtqueue_push(vq, &elem, 0);
|
|
|
|
}
|
|
|
|
virtio_notify(vdev, vq);
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:34:11 +04:00
|
|
|
static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
|
2011-01-07 12:03:36 +03:00
|
|
|
VirtIODevice *vdev)
|
2010-04-27 16:34:10 +04:00
|
|
|
{
|
2011-12-04 22:38:12 +04:00
|
|
|
VirtIOSerialPortClass *vsc;
|
2011-05-25 16:21:13 +04:00
|
|
|
|
2011-01-07 12:03:36 +03:00
|
|
|
assert(port);
|
2010-07-01 13:28:17 +04:00
|
|
|
assert(virtio_queue_ready(vq));
|
2010-04-27 16:34:10 +04:00
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
2011-05-25 16:21:13 +04:00
|
|
|
|
2010-12-10 14:21:14 +03:00
|
|
|
while (!port->throttled) {
|
2010-12-10 14:59:49 +03:00
|
|
|
unsigned int i;
|
2010-04-27 16:34:10 +04:00
|
|
|
|
2010-12-10 14:21:14 +03:00
|
|
|
/* Pop an elem only if we haven't left off a previous one mid-way */
|
|
|
|
if (!port->elem.out_num) {
|
|
|
|
if (!virtqueue_pop(vq, &port->elem)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
port->iov_idx = 0;
|
|
|
|
port->iov_offset = 0;
|
|
|
|
}
|
2010-04-27 16:34:10 +04:00
|
|
|
|
2010-12-10 14:21:14 +03:00
|
|
|
for (i = port->iov_idx; i < port->elem.out_num; i++) {
|
|
|
|
size_t buf_size;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
buf_size = port->elem.out_sg[i].iov_len - port->iov_offset;
|
2011-12-04 22:38:12 +04:00
|
|
|
ret = vsc->have_data(port,
|
2011-05-25 16:21:13 +04:00
|
|
|
port->elem.out_sg[i].iov_base
|
|
|
|
+ port->iov_offset,
|
|
|
|
buf_size);
|
2010-12-10 14:21:14 +03:00
|
|
|
if (ret < 0 && ret != -EAGAIN) {
|
|
|
|
/* We don't handle any other type of errors here */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (ret == -EAGAIN || (ret >= 0 && ret < buf_size)) {
|
2011-12-29 16:47:43 +04:00
|
|
|
/*
|
|
|
|
* this is a temporary check until chardevs can signal to
|
|
|
|
* frontends that they are writable again. This prevents
|
|
|
|
* the console from going into throttled mode (forever)
|
|
|
|
* if virtio-console is connected to a pty without a
|
|
|
|
* listener. Otherwise the guest spins forever.
|
|
|
|
* We can revert this if
|
|
|
|
* 1: chardevs can notify frondends
|
|
|
|
* 2: the guest driver does not spin in these cases
|
|
|
|
*/
|
2011-12-04 22:38:12 +04:00
|
|
|
if (!vsc->is_console) {
|
2011-12-29 16:47:43 +04:00
|
|
|
virtio_serial_throttle_port(port, true);
|
|
|
|
}
|
2010-12-10 14:21:14 +03:00
|
|
|
port->iov_idx = i;
|
|
|
|
if (ret > 0) {
|
|
|
|
port->iov_offset += ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
port->iov_offset = 0;
|
2010-04-27 16:34:10 +04:00
|
|
|
}
|
2010-12-10 14:21:14 +03:00
|
|
|
if (port->throttled) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
virtqueue_push(vq, &port->elem, 0);
|
|
|
|
port->elem.out_num = 0;
|
2010-04-27 16:34:10 +04:00
|
|
|
}
|
|
|
|
virtio_notify(vdev, vq);
|
|
|
|
}
|
|
|
|
|
2011-01-07 12:03:36 +03:00
|
|
|
static void flush_queued_data(VirtIOSerialPort *port)
|
2010-04-27 16:34:11 +04:00
|
|
|
{
|
2010-04-30 15:13:55 +04:00
|
|
|
assert(port);
|
2010-04-27 16:34:11 +04:00
|
|
|
|
2010-07-01 13:28:16 +04:00
|
|
|
if (!virtio_queue_ready(port->ovq)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-07 12:03:36 +03:00
|
|
|
do_flush_queued_data(port, port->ovq, &port->vser->vdev);
|
2010-04-27 16:34:11 +04: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 22:06:52 +03:00
|
|
|
static size_t send_control_msg(VirtIOSerialPort *port, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
VirtQueueElement elem;
|
|
|
|
VirtQueue *vq;
|
|
|
|
struct virtio_console_control *cpkt;
|
|
|
|
|
|
|
|
vq = port->vser->c_ivq;
|
|
|
|
if (!virtio_queue_ready(vq)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!virtqueue_pop(vq, &elem)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpkt = (struct virtio_console_control *)buf;
|
|
|
|
stl_p(&cpkt->id, port->id);
|
|
|
|
memcpy(elem.in_sg[0].iov_base, buf, len);
|
|
|
|
|
|
|
|
virtqueue_push(vq, &elem, len);
|
|
|
|
virtio_notify(&port->vser->vdev, vq);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t send_control_event(VirtIOSerialPort *port, uint16_t event,
|
|
|
|
uint16_t value)
|
|
|
|
{
|
|
|
|
struct virtio_console_control cpkt;
|
|
|
|
|
|
|
|
stw_p(&cpkt.event, event);
|
|
|
|
stw_p(&cpkt.value, value);
|
|
|
|
|
2011-07-05 15:06:39 +04:00
|
|
|
trace_virtio_serial_send_control_event(port->id, event, value);
|
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 22:06:52 +03:00
|
|
|
return send_control_msg(port, &cpkt, sizeof(cpkt));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions for use inside qemu to open and read from/write to ports */
|
|
|
|
int virtio_serial_open(VirtIOSerialPort *port)
|
|
|
|
{
|
2010-01-19 22:06:53 +03:00
|
|
|
/* Don't allow opening an already-open port */
|
|
|
|
if (port->host_connected) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Send port open notification to the guest */
|
|
|
|
port->host_connected = true;
|
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 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 22:06:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virtio_serial_close(VirtIOSerialPort *port)
|
|
|
|
{
|
2010-01-19 22:06:53 +03:00
|
|
|
port->host_connected = false;
|
2010-04-27 16:34:11 +04:00
|
|
|
/*
|
|
|
|
* If there's any data the guest sent which the app didn't
|
|
|
|
* consume, reset the throttling flag and discard the data.
|
|
|
|
*/
|
|
|
|
port->throttled = false;
|
2011-01-07 12:03:36 +03:00
|
|
|
discard_vq_data(port->ovq, &port->vser->vdev);
|
2010-04-27 16:34:11 +04:00
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Individual ports/apps call this function to write to the guest. */
|
|
|
|
ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
|
|
|
|
size_t size)
|
|
|
|
{
|
2010-01-19 22:06:53 +03:00
|
|
|
if (!port || !port->host_connected || !port->guest_connected) {
|
|
|
|
return 0;
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
return write_to_port(port, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Readiness of the guest to accept data on a port.
|
|
|
|
* Returns max. data the guest can receive
|
|
|
|
*/
|
|
|
|
size_t virtio_serial_guest_ready(VirtIOSerialPort *port)
|
|
|
|
{
|
|
|
|
VirtQueue *vq = port->ivq;
|
|
|
|
|
|
|
|
if (!virtio_queue_ready(vq) ||
|
|
|
|
!(port->vser->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK) ||
|
|
|
|
virtio_queue_empty(vq)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-19 22:06:53 +03:00
|
|
|
if (use_multiport(port->vser) && !port->guest_connected) {
|
|
|
|
return 0;
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
if (virtqueue_avail_bytes(vq, 4096, 0)) {
|
|
|
|
return 4096;
|
|
|
|
}
|
|
|
|
if (virtqueue_avail_bytes(vq, 1, 0)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-29 15:25:06 +04:00
|
|
|
static void flush_queued_data_bh(void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOSerialPort *port = opaque;
|
|
|
|
|
|
|
|
flush_queued_data(port);
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:34:11 +04:00
|
|
|
void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle)
|
|
|
|
{
|
|
|
|
if (!port) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:06:39 +04:00
|
|
|
trace_virtio_serial_throttle_port(port->id, throttle);
|
2010-04-27 16:34:11 +04:00
|
|
|
port->throttled = throttle;
|
|
|
|
if (throttle) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-29 15:25:06 +04:00
|
|
|
qemu_bh_schedule(port->bh);
|
2010-04-27 16:34:11 +04: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 22:06:52 +03:00
|
|
|
/* Guest wants to notify us of some event */
|
2010-04-27 16:34:07 +04:00
|
|
|
static void handle_control_message(VirtIOSerial *vser, void *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 22:06:52 +03:00
|
|
|
{
|
|
|
|
struct VirtIOSerialPort *port;
|
2011-12-04 22:38:12 +04:00
|
|
|
VirtIOSerialPortClass *vsc;
|
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 22:06:52 +03:00
|
|
|
struct virtio_console_control cpkt, *gcpkt;
|
2010-01-19 22:06:54 +03:00
|
|
|
uint8_t *buffer;
|
|
|
|
size_t buffer_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 22:06:52 +03:00
|
|
|
|
|
|
|
gcpkt = buf;
|
|
|
|
|
2010-04-27 16:34:07 +04:00
|
|
|
if (len < sizeof(cpkt)) {
|
|
|
|
/* The guest sent an invalid control packet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
cpkt.event = lduw_p(&gcpkt->event);
|
|
|
|
cpkt.value = lduw_p(&gcpkt->value);
|
|
|
|
|
2011-07-05 15:06:39 +04:00
|
|
|
trace_virtio_serial_handle_control_message(cpkt.event, cpkt.value);
|
|
|
|
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
if (cpkt.event == VIRTIO_CONSOLE_DEVICE_READY) {
|
2010-04-27 16:34:03 +04:00
|
|
|
if (!cpkt.value) {
|
2011-06-22 16:03:54 +04:00
|
|
|
error_report("virtio-serial-bus: Guest failure in adding device %s",
|
2011-05-25 16:21:10 +04:00
|
|
|
vser->bus.qbus.name);
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
return;
|
2010-04-27 16:34:03 +04:00
|
|
|
}
|
2010-04-27 16:33:59 +04:00
|
|
|
/*
|
|
|
|
* The device is up, we can now tell the device about all the
|
|
|
|
* ports we have here.
|
|
|
|
*/
|
|
|
|
QTAILQ_FOREACH(port, &vser->ports, next) {
|
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_ADD, 1);
|
|
|
|
}
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-04-27 16:33:59 +04:00
|
|
|
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
port = find_port_by_id(vser, ldl_p(&gcpkt->id));
|
|
|
|
if (!port) {
|
2011-07-07 16:46:13 +04:00
|
|
|
error_report("virtio-serial-bus: Unexpected port id %u for device %s",
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
ldl_p(&gcpkt->id), vser->bus.qbus.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:06:39 +04:00
|
|
|
trace_virtio_serial_handle_control_message_port(port->id);
|
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
virtio-serial: Fix segfault on guest boot
If I start qemu with:
# qemu -hda disks/test.img -enable-kvm -m 1G -snapshot \
-device virtio-serial \
-chardev socket,host=localhost,port=1234,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.qemu.guest_agent
I get a segfault when booting a Fedora 14 guest. The backtrace says:
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000420850 in handle_control_message (vser=0x3732bd0, buf=0x2c173e0, len=8) at /home/lcapitulino/src/qmp-unstable/hw/virtio-serial-bus.c:335
335 info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
What's happening is VIRTIO_CONSOLE_DEVICE_READY is a message for the
whole device, not for an individual port. So port is NULL. This bug was
introduced by commit a15bb0d6a981de749452a5180fc8084d625671da.
This commit fixes that by making the port returned by find_port_by_id()
be used only by the VIRTIO_CONSOLE_PORT_READY and
VIRTIO_CONSOLE_PORT_OPEN messages.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-06-17 22:58:08 +04:00
|
|
|
|
|
|
|
switch(cpkt.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 22:06:52 +03:00
|
|
|
case VIRTIO_CONSOLE_PORT_READY:
|
2010-04-27 16:34:03 +04:00
|
|
|
if (!cpkt.value) {
|
2011-06-22 16:03:54 +04:00
|
|
|
error_report("virtio-serial-bus: Guest failure in adding port %u for device %s",
|
2011-05-25 16:21:10 +04:00
|
|
|
port->id, vser->bus.qbus.name);
|
2010-04-27 16:34:03 +04:00
|
|
|
break;
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* Now that we know the guest asked for the port name, we're
|
|
|
|
* sure the guest has initialised whatever state is necessary
|
|
|
|
* for this port. Now's a good time to let the guest know if
|
|
|
|
* this port is a console port so that the guest can hook it
|
|
|
|
* up to hvc.
|
|
|
|
*/
|
2011-12-04 22:38:12 +04:00
|
|
|
if (vsc->is_console) {
|
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 22:06:52 +03:00
|
|
|
send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
|
|
|
|
}
|
2010-01-19 22:06:53 +03:00
|
|
|
|
2010-01-19 22:06:54 +03:00
|
|
|
if (port->name) {
|
|
|
|
stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
|
|
|
|
stw_p(&cpkt.value, 1);
|
|
|
|
|
|
|
|
buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
|
2011-08-21 07:09:37 +04:00
|
|
|
buffer = g_malloc(buffer_len);
|
2010-01-19 22:06:54 +03:00
|
|
|
|
|
|
|
memcpy(buffer, &cpkt, sizeof(cpkt));
|
|
|
|
memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
|
|
|
|
buffer[buffer_len - 1] = 0;
|
|
|
|
|
|
|
|
send_control_msg(port, buffer, buffer_len);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(buffer);
|
2010-01-19 22:06:54 +03:00
|
|
|
}
|
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
if (port->host_connected) {
|
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* When the guest has asked us for this information it means
|
|
|
|
* the guest is all setup and has its virtqueues
|
|
|
|
* initialised. If some app is interested in knowing about
|
|
|
|
* this event, let it know.
|
|
|
|
*/
|
2011-12-04 22:38:12 +04:00
|
|
|
if (vsc->guest_ready) {
|
|
|
|
vsc->guest_ready(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 22:06:52 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-01-19 22:06:53 +03:00
|
|
|
|
|
|
|
case VIRTIO_CONSOLE_PORT_OPEN:
|
|
|
|
port->guest_connected = cpkt.value;
|
2011-12-04 22:38:12 +04:00
|
|
|
if (cpkt.value && vsc->guest_open) {
|
2010-01-19 22:06:53 +03:00
|
|
|
/* Send the guest opened notification if an app is interested */
|
2011-12-04 22:38:12 +04:00
|
|
|
vsc->guest_open(port);
|
2010-01-19 22:06:53 +03:00
|
|
|
}
|
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
if (!cpkt.value && vsc->guest_close) {
|
2010-01-19 22:06:53 +03:00
|
|
|
/* Send the guest closed notification if an app is interested */
|
2011-12-04 22:38:12 +04:00
|
|
|
vsc->guest_close(port);
|
2010-01-19 22:06:53 +03:00
|
|
|
}
|
|
|
|
break;
|
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 22:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void control_in(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void control_out(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtQueueElement elem;
|
|
|
|
VirtIOSerial *vser;
|
2010-04-27 16:34:07 +04:00
|
|
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
|
|
|
|
2010-04-27 16:34:07 +04:00
|
|
|
len = 0;
|
|
|
|
buf = NULL;
|
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 22:06:52 +03:00
|
|
|
while (virtqueue_pop(vq, &elem)) {
|
2010-04-27 16:34:07 +04:00
|
|
|
size_t cur_len, copied;
|
|
|
|
|
|
|
|
cur_len = iov_size(elem.out_sg, elem.out_num);
|
|
|
|
/*
|
|
|
|
* Allocate a new buf only if we didn't have one previously or
|
|
|
|
* if the size of the buf differs
|
|
|
|
*/
|
|
|
|
if (cur_len > len) {
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(buf);
|
2010-04-27 16:34:07 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
buf = g_malloc(cur_len);
|
2010-04-27 16:34:07 +04:00
|
|
|
len = cur_len;
|
|
|
|
}
|
|
|
|
copied = iov_to_buf(elem.out_sg, elem.out_num, buf, 0, len);
|
|
|
|
|
|
|
|
handle_control_message(vser, buf, copied);
|
2010-04-27 16:34:09 +04:00
|
|
|
virtqueue_push(vq, &elem, 0);
|
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 22:06:52 +03:00
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(buf);
|
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 22:06:52 +03:00
|
|
|
virtio_notify(vdev, vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Guest wrote something to some port. */
|
|
|
|
static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtIOSerial *vser;
|
2010-04-27 16:34:10 +04:00
|
|
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
2010-04-27 16:34:10 +04:00
|
|
|
port = find_port_by_vq(vser, vq);
|
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 22:06:52 +03:00
|
|
|
|
2011-12-21 10:58:29 +04:00
|
|
|
if (!port || !port->host_connected) {
|
2011-01-07 12:03:36 +03:00
|
|
|
discard_vq_data(vq, vdev);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-03 10:58:55 +03:00
|
|
|
|
|
|
|
if (!port->throttled) {
|
|
|
|
do_flush_queued_data(port, vq, vdev);
|
2010-04-27 16:34:11 +04:00
|
|
|
return;
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
|
|
|
|
{
|
2010-04-27 16:34:00 +04:00
|
|
|
VirtIOSerial *vser;
|
|
|
|
|
|
|
|
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
|
|
|
|
2011-05-25 16:21:10 +04:00
|
|
|
if (vser->bus.max_nr_ports > 1) {
|
2010-02-15 18:13:56 +03:00
|
|
|
features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT);
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Guest requested config info */
|
|
|
|
static void get_config(VirtIODevice *vdev, uint8_t *config_data)
|
|
|
|
{
|
|
|
|
VirtIOSerial *vser;
|
|
|
|
|
|
|
|
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
|
|
|
memcpy(config_data, &vser->config, sizeof(struct virtio_console_config));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_config(VirtIODevice *vdev, const uint8_t *config_data)
|
|
|
|
{
|
|
|
|
struct virtio_console_config config;
|
|
|
|
|
|
|
|
memcpy(&config, config_data, sizeof(config));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_serial_save(QEMUFile *f, void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOSerial *s = opaque;
|
2010-01-19 22:06:53 +03:00
|
|
|
VirtIOSerialPort *port;
|
|
|
|
uint32_t nr_active_ports;
|
2011-04-19 06:03:46 +04:00
|
|
|
unsigned int i, max_nr_ports;
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
/* The virtio device */
|
|
|
|
virtio_save(&s->vdev, f);
|
|
|
|
|
|
|
|
/* The config space */
|
|
|
|
qemu_put_be16s(f, &s->config.cols);
|
|
|
|
qemu_put_be16s(f, &s->config.rows);
|
2010-01-19 22:06:53 +03:00
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
qemu_put_be32s(f, &s->config.max_nr_ports);
|
|
|
|
|
|
|
|
/* The ports map */
|
2011-04-19 06:03:46 +04:00
|
|
|
max_nr_ports = tswap32(s->config.max_nr_ports);
|
|
|
|
for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
|
2010-04-27 16:33:59 +04:00
|
|
|
qemu_put_be32s(f, &s->ports_map[i]);
|
|
|
|
}
|
2010-01-19 22:06:53 +03:00
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
/* Ports */
|
2010-04-27 16:33:55 +04:00
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
nr_active_ports = 0;
|
2010-04-27 16:33:55 +04:00
|
|
|
QTAILQ_FOREACH(port, &s->ports, next) {
|
2010-01-19 22:06:53 +03:00
|
|
|
nr_active_ports++;
|
2010-04-27 16:33:55 +04:00
|
|
|
}
|
2010-01-19 22:06:53 +03:00
|
|
|
|
|
|
|
qemu_put_be32s(f, &nr_active_ports);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Items in struct VirtIOSerialPort.
|
|
|
|
*/
|
|
|
|
QTAILQ_FOREACH(port, &s->ports, next) {
|
2011-01-19 13:37:10 +03:00
|
|
|
uint32_t elem_popped;
|
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
qemu_put_be32s(f, &port->id);
|
|
|
|
qemu_put_byte(f, port->guest_connected);
|
2010-04-27 16:33:58 +04:00
|
|
|
qemu_put_byte(f, port->host_connected);
|
2011-01-19 13:37:10 +03:00
|
|
|
|
|
|
|
elem_popped = 0;
|
|
|
|
if (port->elem.out_num) {
|
|
|
|
elem_popped = 1;
|
|
|
|
}
|
|
|
|
qemu_put_be32s(f, &elem_popped);
|
|
|
|
if (elem_popped) {
|
|
|
|
qemu_put_be32s(f, &port->iov_idx);
|
|
|
|
qemu_put_be64s(f, &port->iov_offset);
|
|
|
|
|
|
|
|
qemu_put_buffer(f, (unsigned char *)&port->elem,
|
|
|
|
sizeof(port->elem));
|
|
|
|
}
|
2010-01-19 22:06:53 +03: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 22:06:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
VirtIOSerial *s = opaque;
|
2010-01-19 22:06:53 +03:00
|
|
|
VirtIOSerialPort *port;
|
2010-05-31 18:19:43 +04:00
|
|
|
uint32_t max_nr_ports, nr_active_ports, ports_map;
|
2010-01-19 22:06:53 +03:00
|
|
|
unsigned int i;
|
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 22:06:52 +03:00
|
|
|
|
2011-01-19 13:37:10 +03:00
|
|
|
if (version_id > 3) {
|
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 22:06:52 +03:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-01-19 22:06:53 +03: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 22:06:52 +03:00
|
|
|
/* The virtio device */
|
|
|
|
virtio_load(&s->vdev, f);
|
|
|
|
|
|
|
|
if (version_id < 2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The config space */
|
|
|
|
qemu_get_be16s(f, &s->config.cols);
|
|
|
|
qemu_get_be16s(f, &s->config.rows);
|
2010-04-27 16:33:56 +04:00
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
qemu_get_be32s(f, &max_nr_ports);
|
2011-04-19 06:03:46 +04:00
|
|
|
tswap32s(&max_nr_ports);
|
|
|
|
if (max_nr_ports > tswap32(s->config.max_nr_ports)) {
|
2010-04-27 16:33:59 +04:00
|
|
|
/* Source could have had more ports than us. Fail migration. */
|
2010-04-27 16:33:56 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
|
2010-05-31 18:19:43 +04:00
|
|
|
qemu_get_be32s(f, &ports_map);
|
2010-04-27 16:33:59 +04:00
|
|
|
|
2010-05-31 18:19:43 +04:00
|
|
|
if (ports_map != s->ports_map[i]) {
|
2010-04-27 16:33:59 +04:00
|
|
|
/*
|
|
|
|
* Ports active on source and destination don't
|
|
|
|
* match. Fail migration.
|
|
|
|
*/
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-04-27 16:33:55 +04:00
|
|
|
}
|
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
qemu_get_be32s(f, &nr_active_ports);
|
|
|
|
|
|
|
|
/* Items in struct VirtIOSerialPort */
|
|
|
|
for (i = 0; i < nr_active_ports; i++) {
|
|
|
|
uint32_t id;
|
2010-04-27 16:33:58 +04:00
|
|
|
bool host_connected;
|
2010-01-19 22:06:53 +03:00
|
|
|
|
|
|
|
id = qemu_get_be32(f);
|
|
|
|
port = find_port_by_id(s, id);
|
2011-03-22 19:32:50 +03:00
|
|
|
if (!port) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-01-19 22:06:53 +03:00
|
|
|
|
|
|
|
port->guest_connected = qemu_get_byte(f);
|
2010-04-27 16:33:58 +04:00
|
|
|
host_connected = qemu_get_byte(f);
|
|
|
|
if (host_connected != port->host_connected) {
|
|
|
|
/*
|
|
|
|
* We have to let the guest know of the host connection
|
|
|
|
* status change
|
|
|
|
*/
|
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN,
|
|
|
|
port->host_connected);
|
|
|
|
}
|
2011-01-19 13:37:10 +03:00
|
|
|
|
|
|
|
if (version_id > 2) {
|
|
|
|
uint32_t elem_popped;
|
|
|
|
|
|
|
|
qemu_get_be32s(f, &elem_popped);
|
|
|
|
if (elem_popped) {
|
|
|
|
qemu_get_be32s(f, &port->iov_idx);
|
|
|
|
qemu_get_be64s(f, &port->iov_offset);
|
|
|
|
|
|
|
|
qemu_get_buffer(f, (unsigned char *)&port->elem,
|
|
|
|
sizeof(port->elem));
|
|
|
|
virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
|
|
|
|
port->elem.in_num, 1);
|
|
|
|
virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
|
|
|
|
port->elem.out_num, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Port was throttled on source machine. Let's
|
|
|
|
* unthrottle it here so data starts flowing again.
|
|
|
|
*/
|
|
|
|
virtio_serial_throttle_port(port, false);
|
|
|
|
}
|
|
|
|
}
|
2010-01-19 22:06:53 +03: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 22:06:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
|
|
|
|
|
|
|
|
static struct BusInfo virtser_bus_info = {
|
|
|
|
.name = "virtio-serial-bus",
|
|
|
|
.size = sizeof(VirtIOSerialBus),
|
|
|
|
.print_dev = virtser_bus_dev_print,
|
2011-05-19 15:37:16 +04:00
|
|
|
.props = (Property[]) {
|
|
|
|
DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
|
|
|
|
DEFINE_PROP_STRING("name", VirtIOSerialPort, name),
|
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
}
|
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 22:06:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
|
|
|
|
{
|
2011-02-24 08:44:12 +03:00
|
|
|
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
|
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 22:06:52 +03:00
|
|
|
|
virtio-serial: Clean up virtser_bus_dev_print() output
Old version looks like this in info qtree (last four lines):
dev: virtconsole, id ""
dev-prop: is_console = 1
dev-prop: nr = 0
dev-prop: chardev = <null>
dev-prop: name = <null>
dev-prop-int: id: 0
dev-prop-int: guest_connected: 1
dev-prop-int: host_connected: 0
dev-prop-int: throttled: 0
Indentation is off, and "dev-prop-int" suggests these are properties
you can configure with -device, which isn't the case. The other
buses' print_dev() callbacks don't do that. For instance, PCI's
output looks like this:
class Ethernet controller, addr 00:03.0, pci id 1af4:1000 (sub 1af4:0001)
bar 0: i/o at 0xffffffffffffffff [0x1e]
bar 1: mem at 0xffffffffffffffff [0xffe]
bar 6: mem at 0xffffffffffffffff [0xfffe]
Change virtser_bus_dev_print() to that style. Result:
dev: virtconsole, id ""
dev-prop: is_console = 1
dev-prop: nr = 0
dev-prop: chardev = <null>
dev-prop: name = <null>
port 0, guest on, host off, throttle off
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-05-19 15:37:15 +04:00
|
|
|
monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n",
|
|
|
|
indent, "", port->id,
|
|
|
|
port->guest_connected ? "on" : "off",
|
|
|
|
port->host_connected ? "on" : "off",
|
|
|
|
port->throttled ? "on" : "off");
|
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 22:06:52 +03:00
|
|
|
}
|
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
/* This function is only used if a port id is not provided by the user */
|
|
|
|
static uint32_t find_free_port_id(VirtIOSerial *vser)
|
|
|
|
{
|
2011-04-19 06:03:46 +04:00
|
|
|
unsigned int i, max_nr_ports;
|
2010-04-27 16:33:59 +04:00
|
|
|
|
2011-04-19 06:03:46 +04:00
|
|
|
max_nr_ports = tswap32(vser->config.max_nr_ports);
|
|
|
|
for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
|
2010-04-27 16:33:59 +04:00
|
|
|
uint32_t map, bit;
|
|
|
|
|
|
|
|
map = vser->ports_map[i];
|
|
|
|
bit = ffs(~map);
|
|
|
|
if (bit) {
|
|
|
|
return (bit - 1) + i * 32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return VIRTIO_CONSOLE_BAD_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mark_port_added(VirtIOSerial *vser, uint32_t port_id)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
i = port_id / 32;
|
|
|
|
vser->ports_map[i] |= 1U << (port_id % 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_port(VirtIOSerial *vser, uint32_t port_id)
|
|
|
|
{
|
|
|
|
mark_port_added(vser, port_id);
|
|
|
|
|
|
|
|
send_control_event(find_port_by_id(vser, port_id),
|
|
|
|
VIRTIO_CONSOLE_PORT_ADD, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_port(VirtIOSerial *vser, uint32_t port_id)
|
|
|
|
{
|
2010-04-27 16:34:11 +04:00
|
|
|
VirtIOSerialPort *port;
|
2010-04-27 16:33:59 +04:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
i = port_id / 32;
|
|
|
|
vser->ports_map[i] &= ~(1U << (port_id % 32));
|
|
|
|
|
2010-04-27 16:34:11 +04:00
|
|
|
port = find_port_by_id(vser, port_id);
|
|
|
|
/* Flush out any unconsumed buffers first */
|
2011-01-07 12:03:36 +03:00
|
|
|
discard_vq_data(port->ovq, &port->vser->vdev);
|
2010-04-27 16:34:11 +04:00
|
|
|
|
|
|
|
send_control_event(port, VIRTIO_CONSOLE_PORT_REMOVE, 1);
|
2010-04-27 16:33:59 +04: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 22:06:52 +03:00
|
|
|
static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
|
|
|
|
{
|
2011-02-24 08:44:12 +03:00
|
|
|
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
|
2011-12-04 22:38:12 +04:00
|
|
|
VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(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 22:06:52 +03:00
|
|
|
VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus);
|
2011-04-19 06:03:46 +04:00
|
|
|
int ret, max_nr_ports;
|
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 22:06:52 +03:00
|
|
|
bool plugging_port0;
|
|
|
|
|
|
|
|
port->vser = bus->vser;
|
2011-04-29 15:25:06 +04:00
|
|
|
port->bh = qemu_bh_new(flush_queued_data_bh, 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 22:06:52 +03:00
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
assert(vsc->have_data);
|
2011-12-21 10:58:29 +04: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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* Is the first console port we're seeing? If so, put it up at
|
|
|
|
* location 0. This is done for backward compatibility (old
|
|
|
|
* kernel, new qemu).
|
|
|
|
*/
|
2011-12-04 22:38:12 +04:00
|
|
|
plugging_port0 = vsc->is_console && !find_port_by_id(port->vser, 0);
|
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 22:06:52 +03:00
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
if (find_port_by_id(port->vser, port->id)) {
|
2011-06-22 16:03:54 +04:00
|
|
|
error_report("virtio-serial-bus: A port already exists at id %u",
|
2010-04-27 16:33:59 +04:00
|
|
|
port->id);
|
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 22:06:52 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
if (port->id == VIRTIO_CONSOLE_BAD_ID) {
|
|
|
|
if (plugging_port0) {
|
|
|
|
port->id = 0;
|
|
|
|
} else {
|
|
|
|
port->id = find_free_port_id(port->vser);
|
|
|
|
if (port->id == VIRTIO_CONSOLE_BAD_ID) {
|
2011-06-22 16:03:54 +04:00
|
|
|
error_report("virtio-serial-bus: Maximum port limit for this device reached");
|
2010-04-27 16:33:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-19 06:03:46 +04:00
|
|
|
max_nr_ports = tswap32(port->vser->config.max_nr_ports);
|
|
|
|
if (port->id >= max_nr_ports) {
|
2011-06-22 16:03:54 +04:00
|
|
|
error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u",
|
2011-04-19 06:03:46 +04:00
|
|
|
max_nr_ports - 1);
|
2010-04-27 16:33:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
ret = vsc->init(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 22:06:52 +03:00
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-19 22:06:53 +03:00
|
|
|
if (!use_multiport(port->vser)) {
|
|
|
|
/*
|
|
|
|
* Allow writes to guest in this case; we have no way of
|
|
|
|
* knowing if a guest port is connected.
|
|
|
|
*/
|
|
|
|
port->guest_connected = true;
|
|
|
|
}
|
|
|
|
|
2010-12-10 14:21:14 +03:00
|
|
|
port->elem.out_num = 0;
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
QTAILQ_INSERT_TAIL(&port->vser->ports, port, next);
|
|
|
|
port->ivq = port->vser->ivqs[port->id];
|
|
|
|
port->ovq = port->vser->ovqs[port->id];
|
|
|
|
|
2010-04-27 16:33:59 +04:00
|
|
|
add_port(port->vser, port->id);
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
/* Send an update to the guest about this new port added */
|
|
|
|
virtio_notify_config(&port->vser->vdev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtser_port_qdev_exit(DeviceState *qdev)
|
|
|
|
{
|
2011-02-24 08:44:12 +03:00
|
|
|
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
|
2011-12-04 22:38:12 +04:00
|
|
|
VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(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 22:06:52 +03:00
|
|
|
VirtIOSerial *vser = port->vser;
|
|
|
|
|
2011-04-29 15:25:06 +04:00
|
|
|
qemu_bh_delete(port->bh);
|
2010-04-27 16:33:59 +04:00
|
|
|
remove_port(port->vser, port->id);
|
2010-01-19 22:06:55 +03: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 22:06:52 +03:00
|
|
|
QTAILQ_REMOVE(&vser->ports, port, next);
|
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
if (vsc->exit) {
|
|
|
|
vsc->exit(port);
|
2011-05-25 16:21:13 +04: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 22:06:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-04 22:38:12 +04:00
|
|
|
void virtio_serial_port_qdev_register(DeviceInfo *info)
|
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 22:06:52 +03:00
|
|
|
{
|
2011-12-04 22:38:12 +04:00
|
|
|
info->init = virtser_port_qdev_init;
|
|
|
|
info->bus_info = &virtser_bus_info;
|
|
|
|
info->exit = virtser_port_qdev_exit;
|
|
|
|
info->unplug = qdev_simple_unplug_cb;
|
|
|
|
qdev_register_subclass(info, TYPE_VIRTIO_SERIAL_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 22:06:52 +03:00
|
|
|
}
|
|
|
|
|
2011-02-03 08:52:32 +03:00
|
|
|
VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
|
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 22:06:52 +03:00
|
|
|
{
|
|
|
|
VirtIOSerial *vser;
|
|
|
|
VirtIODevice *vdev;
|
2010-07-21 13:38:30 +04:00
|
|
|
uint32_t i, max_supported_ports;
|
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 22:06:52 +03:00
|
|
|
|
2011-02-03 08:52:32 +03:00
|
|
|
if (!conf->max_virtserial_ports)
|
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 22:06:52 +03:00
|
|
|
return NULL;
|
|
|
|
|
2010-07-21 13:38:30 +04:00
|
|
|
/* Each port takes 2 queues, and one pair is for the control queue */
|
|
|
|
max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
|
|
|
|
|
2011-02-03 08:52:32 +03:00
|
|
|
if (conf->max_virtserial_ports > max_supported_ports) {
|
2010-07-21 13:38:30 +04:00
|
|
|
error_report("maximum ports supported: %u", max_supported_ports);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
|
|
|
|
sizeof(struct virtio_console_config),
|
|
|
|
sizeof(VirtIOSerial));
|
|
|
|
|
|
|
|
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
|
|
|
|
|
|
|
/* Spawn a new virtio-serial bus on which the ports will ride as devices */
|
2011-05-25 16:21:10 +04:00
|
|
|
qbus_create_inplace(&vser->bus.qbus, &virtser_bus_info, dev, NULL);
|
|
|
|
vser->bus.qbus.allow_hotplug = 1;
|
|
|
|
vser->bus.vser = vser;
|
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 22:06:52 +03:00
|
|
|
QTAILQ_INIT(&vser->ports);
|
|
|
|
|
2011-05-25 16:21:10 +04:00
|
|
|
vser->bus.max_nr_ports = conf->max_virtserial_ports;
|
2011-08-21 07:09:37 +04:00
|
|
|
vser->ivqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
|
|
|
|
vser->ovqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
/* Add a queue for host to guest transfers for port 0 (backward compat) */
|
|
|
|
vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
|
|
|
|
/* Add a queue for guest to host transfers for port 0 (backward compat) */
|
|
|
|
vser->ovqs[0] = virtio_add_queue(vdev, 128, handle_output);
|
|
|
|
|
2010-11-23 14:31:15 +03:00
|
|
|
/* TODO: host to guest notifications can get dropped
|
|
|
|
* if the queue fills up. Implement queueing in host,
|
|
|
|
* this might also make it possible to reduce the control
|
|
|
|
* queue size: as guest preposts buffers there,
|
|
|
|
* this will save 4Kbyte of guest memory per entry. */
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
/* control queue: host to guest */
|
2010-11-23 14:31:15 +03:00
|
|
|
vser->c_ivq = virtio_add_queue(vdev, 32, control_in);
|
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 22:06:52 +03:00
|
|
|
/* control queue: guest to host */
|
2010-11-23 14:31:15 +03:00
|
|
|
vser->c_ovq = virtio_add_queue(vdev, 32, control_out);
|
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 22:06:52 +03:00
|
|
|
|
2011-05-25 16:21:10 +04:00
|
|
|
for (i = 1; i < vser->bus.max_nr_ports; i++) {
|
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 22:06:52 +03:00
|
|
|
/* Add a per-port queue for host to guest transfers */
|
|
|
|
vser->ivqs[i] = virtio_add_queue(vdev, 128, handle_input);
|
|
|
|
/* Add a per-per queue for guest to host transfers */
|
|
|
|
vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
|
|
|
|
}
|
|
|
|
|
2011-04-19 06:03:46 +04:00
|
|
|
vser->config.max_nr_ports = tswap32(conf->max_virtserial_ports);
|
2011-08-21 07:09:37 +04:00
|
|
|
vser->ports_map = g_malloc0(((conf->max_virtserial_ports + 31) / 32)
|
2010-05-19 13:31:38 +04:00
|
|
|
* sizeof(vser->ports_map[0]));
|
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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* Reserve location 0 for a console port for backward compat
|
|
|
|
* (old kernel, new qemu)
|
|
|
|
*/
|
2010-04-27 16:33:59 +04:00
|
|
|
mark_port_added(vser, 0);
|
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 22:06:52 +03:00
|
|
|
|
|
|
|
vser->vdev.get_features = get_features;
|
|
|
|
vser->vdev.get_config = get_config;
|
|
|
|
vser->vdev.set_config = set_config;
|
|
|
|
|
2010-08-19 05:21:04 +04:00
|
|
|
vser->qdev = dev;
|
|
|
|
|
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 22:06:52 +03:00
|
|
|
/*
|
|
|
|
* Register for the savevm section with the virtio-console name
|
|
|
|
* to preserve backward compat
|
|
|
|
*/
|
2011-01-19 13:37:10 +03:00
|
|
|
register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save,
|
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 22:06:52 +03:00
|
|
|
virtio_serial_load, vser);
|
|
|
|
|
|
|
|
return vdev;
|
|
|
|
}
|
2010-08-19 05:21:04 +04:00
|
|
|
|
|
|
|
void virtio_serial_exit(VirtIODevice *vdev)
|
|
|
|
{
|
|
|
|
VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
|
|
|
|
|
|
|
|
unregister_savevm(vser->qdev, "virtio-console", vser);
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(vser->ivqs);
|
|
|
|
g_free(vser->ovqs);
|
|
|
|
g_free(vser->ports_map);
|
2010-08-19 05:21:04 +04:00
|
|
|
|
|
|
|
virtio_cleanup(vdev);
|
|
|
|
}
|
2011-12-04 22:38:12 +04:00
|
|
|
|
|
|
|
static TypeInfo virtio_serial_port_type_info = {
|
|
|
|
.name = TYPE_VIRTIO_SERIAL_PORT,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(VirtIOSerialPort),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(VirtIOSerialPortClass),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_serial_register_devices(void)
|
|
|
|
{
|
|
|
|
type_register_static(&virtio_serial_port_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_init(virtio_serial_register_devices);
|