Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-p…
Browse files Browse the repository at this point in the history
…eter' into staging

QOM/QTest infrastructure fixes and device conversions

* QTest cleanups and test cases for some virtio devices
* QTest for sPAPR PCI host bridge
* qom-test now tests reading all properties beneath /machine
* QOM API leak fixes
* QOM cleanups for SSI devices
* QOM conversion of QEMUMachine
* QOM realize for buses
* sPAPR PCI bus name change

# gpg: Signature made Thu 13 Mar 2014 00:22:40 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/qom-devices-for-peter: (31 commits)
  libqtest: Fix possible deadlock in qtest initialization
  pci: Move VMState registration/unregistration to QOM realize/unrealize
  qdev: Realize buses on device realization
  qdev: Prepare realize/unrealize hooks for BusState
  tests: Add spapr-pci-host-bridge qtest
  virtio-serial-port: Convert to QOM realize/unrealize
  virtio-console: QOM cast cleanup for VirtConsole
  tests: Add virtio-console qtest
  tests: Add virtio-serial qtest
  tests: Add virtio-scsi qtest
  tests: Add virtio-rng qtest
  tests: Add virtio-balloon qtest
  tests: Add virtio-blk qtest
  tests: Clean up IndustryPack TPCI200 gcov paths
  qom-test: Test QOM properties
  hw/boards: Convert current_machine to MachineState
  vl: Use MachineClass instead of global QEMUMachine list
  hw/core: Introduce QEMU machine as QOM object
  qdev-monitor-test: Don't test human-readable error message
  qdev-monitor-test: Simplify using g_assert_cmpstr()
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Mar 13, 2014
2 parents 0100f42 + f876202 commit c8d146a
Show file tree
Hide file tree
Showing 34 changed files with 753 additions and 216 deletions.
4 changes: 3 additions & 1 deletion device-hotplug.c
Expand Up @@ -33,12 +33,14 @@ DriveInfo *add_init_drive(const char *optstr)
{
DriveInfo *dinfo;
QemuOpts *opts;
MachineClass *mc;

opts = drive_def(optstr);
if (!opts)
return NULL;

dinfo = drive_init(opts, current_machine->block_default_type);
mc = MACHINE_GET_CLASS(current_machine);
dinfo = drive_init(opts, mc->qemu_machine->block_default_type);
if (!dinfo) {
qemu_opts_del(opts);
return NULL;
Expand Down
13 changes: 7 additions & 6 deletions hw/arm/spitz.c
Expand Up @@ -658,14 +658,15 @@ static void spitz_adc_temp_on(void *opaque, int line, int level)
max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
}

static int corgi_ssp_init(SSISlave *dev)
static int corgi_ssp_init(SSISlave *d)
{
CorgiSSPState *s = FROM_SSI_SLAVE(CorgiSSPState, dev);
DeviceState *dev = DEVICE(d);
CorgiSSPState *s = FROM_SSI_SLAVE(CorgiSSPState, d);

qdev_init_gpio_in(&dev->qdev, corgi_ssp_gpio_cs, 3);
s->bus[0] = ssi_create_bus(&dev->qdev, "ssi0");
s->bus[1] = ssi_create_bus(&dev->qdev, "ssi1");
s->bus[2] = ssi_create_bus(&dev->qdev, "ssi2");
qdev_init_gpio_in(dev, corgi_ssp_gpio_cs, 3);
s->bus[0] = ssi_create_bus(dev, "ssi0");
s->bus[1] = ssi_create_bus(dev, "ssi1");
s->bus[2] = ssi_create_bus(dev, "ssi2");

return 0;
}
Expand Down
9 changes: 5 additions & 4 deletions hw/block/m25p80.c
Expand Up @@ -241,7 +241,8 @@ typedef enum {
} CMDState;

typedef struct Flash {
SSISlave ssidev;
SSISlave parent_obj;

uint32_t r;

BlockDriverState *bdrv;
Expand Down Expand Up @@ -545,7 +546,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)

static int m25p80_cs(SSISlave *ss, bool select)
{
Flash *s = FROM_SSI_SLAVE(Flash, ss);
Flash *s = M25P80(ss);

if (select) {
s->len = 0;
Expand All @@ -561,7 +562,7 @@ static int m25p80_cs(SSISlave *ss, bool select)

static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
{
Flash *s = FROM_SSI_SLAVE(Flash, ss);
Flash *s = M25P80(ss);
uint32_t r = 0;

switch (s->state) {
Expand Down Expand Up @@ -610,7 +611,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
static int m25p80_init(SSISlave *ss)
{
DriveInfo *dinfo;
Flash *s = FROM_SSI_SLAVE(Flash, ss);
Flash *s = M25P80(ss);
M25P80Class *mc = M25P80_GET_CLASS(s);

s->pi = mc->pi;
Expand Down
57 changes: 31 additions & 26 deletions hw/char/virtio-console.c
Expand Up @@ -15,8 +15,13 @@
#include "trace.h"
#include "hw/virtio/virtio-serial.h"

#define TYPE_VIRTIO_CONSOLE "virtconsole"
#define VIRTIO_CONSOLE(obj) \
OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE)

typedef struct VirtConsole {
VirtIOSerialPort port;
VirtIOSerialPort parent_obj;

CharDriverState *chr;
guint watch;
} VirtConsole;
Expand All @@ -31,15 +36,15 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
VirtConsole *vcon = opaque;

vcon->watch = 0;
virtio_serial_throttle_port(&vcon->port, false);
virtio_serial_throttle_port(VIRTIO_SERIAL_PORT(vcon), false);
return FALSE;
}

/* Callback function that's called when the guest sends us data */
static ssize_t flush_buf(VirtIOSerialPort *port,
const uint8_t *buf, ssize_t len)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtConsole *vcon = VIRTIO_CONSOLE(port);
ssize_t ret;

if (!vcon->chr) {
Expand Down Expand Up @@ -75,7 +80,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
/* Callback function that's called when the guest opens/closes the port */
static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtConsole *vcon = VIRTIO_CONSOLE(port);

if (!vcon->chr) {
return;
Expand All @@ -88,65 +93,65 @@ static int chr_can_read(void *opaque)
{
VirtConsole *vcon = opaque;

return virtio_serial_guest_ready(&vcon->port);
return virtio_serial_guest_ready(VIRTIO_SERIAL_PORT(vcon));
}

/* Send data from a char device over to the guest */
static void chr_read(void *opaque, const uint8_t *buf, int size)
{
VirtConsole *vcon = opaque;
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);

trace_virtio_console_chr_read(vcon->port.id, size);
virtio_serial_write(&vcon->port, buf, size);
trace_virtio_console_chr_read(port->id, size);
virtio_serial_write(port, buf, size);
}

static void chr_event(void *opaque, int event)
{
VirtConsole *vcon = opaque;
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);

trace_virtio_console_chr_event(vcon->port.id, event);
trace_virtio_console_chr_event(port->id, event);
switch (event) {
case CHR_EVENT_OPENED:
virtio_serial_open(&vcon->port);
virtio_serial_open(port);
break;
case CHR_EVENT_CLOSED:
if (vcon->watch) {
g_source_remove(vcon->watch);
vcon->watch = 0;
}
virtio_serial_close(&vcon->port);
virtio_serial_close(port);
break;
}
}

static int virtconsole_initfn(VirtIOSerialPort *port)
static void virtconsole_realize(DeviceState *dev, Error **errp)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
VirtConsole *vcon = VIRTIO_CONSOLE(dev);
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(dev);

if (port->id == 0 && !k->is_console) {
error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
return -1;
error_setg(errp, "Port number 0 on virtio-serial devices reserved "
"for virtconsole devices for backward compatibility.");
return;
}

if (vcon->chr) {
vcon->chr->explicit_fe_open = 1;
qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
vcon);
}

return 0;
}

static int virtconsole_exitfn(VirtIOSerialPort *port)
static void virtconsole_unrealize(DeviceState *dev, Error **errp)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtConsole *vcon = VIRTIO_CONSOLE(dev);

if (vcon->watch) {
g_source_remove(vcon->watch);
}

return 0;
}

static Property virtconsole_properties[] = {
Expand All @@ -160,15 +165,15 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);

k->is_console = true;
k->init = virtconsole_initfn;
k->exit = virtconsole_exitfn;
k->realize = virtconsole_realize;
k->unrealize = virtconsole_unrealize;
k->have_data = flush_buf;
k->set_guest_connected = set_guest_connected;
dc->props = virtconsole_properties;
}

static const TypeInfo virtconsole_info = {
.name = "virtconsole",
.name = TYPE_VIRTIO_CONSOLE,
.parent = TYPE_VIRTIO_SERIAL_PORT,
.instance_size = sizeof(VirtConsole),
.class_init = virtconsole_class_init,
Expand All @@ -184,8 +189,8 @@ static void virtserialport_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);

k->init = virtconsole_initfn;
k->exit = virtconsole_exitfn;
k->realize = virtconsole_realize;
k->unrealize = virtconsole_unrealize;
k->have_data = flush_buf;
k->set_guest_connected = set_guest_connected;
dc->props = virtserialport_properties;
Expand Down
51 changes: 26 additions & 25 deletions hw/char/virtio-serial-bus.c
Expand Up @@ -808,13 +808,14 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)
send_control_event(vser, port->id, VIRTIO_CONSOLE_PORT_REMOVE, 1);
}

static int virtser_port_qdev_init(DeviceState *qdev)
static void virtser_port_device_realize(DeviceState *dev, Error **errp)
{
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus);
int ret, max_nr_ports;
VirtIOSerialBus *bus = VIRTIO_SERIAL_BUS(qdev_get_parent_bus(dev));
int max_nr_ports;
bool plugging_port0;
Error *err = NULL;

port->vser = bus->vser;
port->bh = qemu_bh_new(flush_queued_data_bh, port);
Expand All @@ -829,9 +830,9 @@ static int virtser_port_qdev_init(DeviceState *qdev)
plugging_port0 = vsc->is_console && !find_port_by_id(port->vser, 0);

if (find_port_by_id(port->vser, port->id)) {
error_report("virtio-serial-bus: A port already exists at id %u",
port->id);
return -1;
error_setg(errp, "virtio-serial-bus: A port already exists at id %u",
port->id);
return;
}

if (port->id == VIRTIO_CONSOLE_BAD_ID) {
Expand All @@ -840,22 +841,24 @@ static int virtser_port_qdev_init(DeviceState *qdev)
} else {
port->id = find_free_port_id(port->vser);
if (port->id == VIRTIO_CONSOLE_BAD_ID) {
error_report("virtio-serial-bus: Maximum port limit for this device reached");
return -1;
error_setg(errp, "virtio-serial-bus: Maximum port limit for "
"this device reached");
return;
}
}
}

max_nr_ports = tswap32(port->vser->config.max_nr_ports);
if (port->id >= max_nr_ports) {
error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u",
max_nr_ports - 1);
return -1;
error_setg(errp, "virtio-serial-bus: Out-of-range port id specified, "
"max. allowed: %u", max_nr_ports - 1);
return;
}

ret = vsc->init(port);
if (ret) {
return ret;
vsc->realize(dev, &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}

port->elem.out_num = 0;
Expand All @@ -868,25 +871,22 @@ static int virtser_port_qdev_init(DeviceState *qdev)

/* Send an update to the guest about this new port added */
virtio_notify_config(VIRTIO_DEVICE(port->vser));

return ret;
}

static int virtser_port_qdev_exit(DeviceState *qdev)
static void virtser_port_device_unrealize(DeviceState *dev, Error **errp)
{
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(dev);
VirtIOSerial *vser = port->vser;

qemu_bh_delete(port->bh);
remove_port(port->vser, port->id);

QTAILQ_REMOVE(&vser->ports, port, next);

if (vsc->exit) {
vsc->exit(port);
if (vsc->unrealize) {
vsc->unrealize(dev, errp);
}
return 0;
}

static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
Expand Down Expand Up @@ -971,10 +971,11 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
k->init = virtser_port_qdev_init;

set_bit(DEVICE_CATEGORY_INPUT, k->categories);
k->bus_type = TYPE_VIRTIO_SERIAL_BUS;
k->exit = virtser_port_qdev_exit;
k->realize = virtser_port_device_realize;
k->unrealize = virtser_port_device_unrealize;
k->unplug = qdev_simple_unplug_cb;
k->props = virtser_props;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/core/Makefile.objs
Expand Up @@ -8,7 +8,7 @@ common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
common-obj-$(CONFIG_XILINX_AXI) += stream.o
common-obj-$(CONFIG_PTIMER) += ptimer.o
common-obj-$(CONFIG_SOFTMMU) += sysbus.o
common-obj-$(CONFIG_SOFTMMU) += machine.o
common-obj-$(CONFIG_SOFTMMU) += null-machine.o
common-obj-$(CONFIG_SOFTMMU) += loader.o
common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o

28 changes: 28 additions & 0 deletions hw/core/machine.c
@@ -0,0 +1,28 @@
/*
* QEMU Machine
*
* Copyright (C) 2014 Red Hat Inc
*
* Authors:
* Marcel Apfelbaum <marcel.a@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/

#include "hw/boards.h"

static const TypeInfo machine_info = {
.name = TYPE_MACHINE,
.parent = TYPE_OBJECT,
.abstract = true,
.class_size = sizeof(MachineClass),
.instance_size = sizeof(MachineState),
};

static void machine_register_types(void)
{
type_register_static(&machine_info);
}

type_init(machine_register_types)

0 comments on commit c8d146a

Please sign in to comment.