Commit 98b19252 authored by Amit Shah's avatar Amit Shah Committed by Anthony Liguori
Browse files

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: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent bb61564c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ ifdef CONFIG_SOFTMMU
obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
# virtio has to be here due to weird dependency between PCI and virtio-net.
# need to fix this properly
obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial.o virtio-serial-bus.o virtio-pci.o
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
LIBS+=-lz
+1 −10
Original line number Diff line number Diff line
@@ -1018,15 +1018,6 @@ static void pc_init1(ram_addr_t ram_size,
            pci_create_simple(pci_bus, -1, "lsi53c895a");
        }
    }

    /* Add virtio console devices */
    if (pci_enabled) {
        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
            if (virtcon_hds[i]) {
                pci_create_simple(pci_bus, -1, "virtio-console-pci");
            }
        }
    }
}

static void pc_init_pci(ram_addr_t ram_size,
@@ -1110,7 +1101,7 @@ static QEMUMachine pc_machine_v0_10 = {
            .property = "class",
            .value    = stringify(PCI_CLASS_STORAGE_OTHER),
        },{
            .driver   = "virtio-console-pci",
            .driver   = "virtio-serial-pci",
            .property = "class",
            .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
        },{
+0 −7
Original line number Diff line number Diff line
@@ -108,13 +108,6 @@ static void bamboo_init(ram_addr_t ram_size,
    env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);

    if (pcibus) {
        /* Add virtio console devices */
        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
            if (virtcon_hds[i]) {
                pci_create_simple(pcibus, -1, "virtio-console-pci");
            }
        }

        /* Register network interfaces. */
        for (i = 0; i < nb_nics; i++) {
            /* There are no PCI NICs on the Bamboo board, but there are
+3 −7
Original line number Diff line number Diff line
@@ -321,14 +321,10 @@ void qdev_machine_creation_done(void)
CharDriverState *qdev_init_chardev(DeviceState *dev)
{
    static int next_serial;
    static int next_virtconsole;
    /* FIXME: This is a nasty hack that needs to go away.  */
    if (strncmp(dev->info->name, "virtio", 6) == 0) {
        return virtcon_hds[next_virtconsole++];
    } else {

    /* FIXME: This function needs to go away: use chardev properties!  */
    return serial_hds[next_serial++];
}
}

BusState *qdev_get_parent_bus(DeviceState *dev)
{
+10 −7
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
#include "loader.h"
#include "elf.h"
#include "hw/virtio.h"
#include "hw/virtio-console.h"
#include "hw/virtio-serial.h"
#include "hw/sysbus.h"
#include "kvm.h"

@@ -131,7 +131,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
    return s390_virtio_device_init(dev, vdev);
}

static int s390_virtio_console_init(VirtIOS390Device *dev)
static int s390_virtio_serial_init(VirtIOS390Device *dev)
{
    VirtIOS390Bus *bus;
    VirtIODevice *vdev;
@@ -139,7 +139,7 @@ static int s390_virtio_console_init(VirtIOS390Device *dev)

    bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);

    vdev = virtio_console_init((DeviceState *)dev);
    vdev = virtio_serial_init((DeviceState *)dev, dev->max_virtserial_ports);
    if (!vdev) {
        return -1;
    }
@@ -342,11 +342,14 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
    },
};

static VirtIOS390DeviceInfo s390_virtio_console = {
    .init = s390_virtio_console_init,
    .qdev.name = "virtio-console-s390",
static VirtIOS390DeviceInfo s390_virtio_serial = {
    .init = s390_virtio_serial_init,
    .qdev.name = "virtio-serial-s390",
    .qdev.alias = "virtio-serial",
    .qdev.size = sizeof(VirtIOS390Device),
    .qdev.props = (Property[]) {
        DEFINE_PROP_UINT32("max_ports", VirtIOS390Device, max_virtserial_ports,
                           31),
        DEFINE_PROP_END_OF_LIST(),
    },
};
@@ -370,7 +373,7 @@ static void s390_virtio_bus_register_withprop(VirtIOS390DeviceInfo *info)

static void s390_virtio_register(void)
{
    s390_virtio_bus_register_withprop(&s390_virtio_console);
    s390_virtio_bus_register_withprop(&s390_virtio_serial);
    s390_virtio_bus_register_withprop(&s390_virtio_blk);
    s390_virtio_bus_register_withprop(&s390_virtio_net);
}
Loading