diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-04 12:38:12 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-01-27 10:50:49 -0600 |
commit | f82e35e38c0149dc201f1e329a215e6a6b739974 (patch) | |
tree | 07767ff861c1fbb57ee6232ff0295c3ba0fcfc15 /hw/virtio-serial-bus.c | |
parent | 3954d33ab7f82f5a5fa0ced231849920265a5fec (diff) |
virtio-serial: convert to QEMU Object Model
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-serial-bus.c')
-rw-r--r-- | hw/virtio-serial-bus.c | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 982ffbf668..70f5d48706 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -133,12 +133,12 @@ static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev) static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, VirtIODevice *vdev) { - VirtIOSerialPortInfo *info; + VirtIOSerialPortClass *vsc; assert(port); assert(virtio_queue_ready(vq)); - info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev)); + vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); while (!port->throttled) { unsigned int i; @@ -157,7 +157,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, ssize_t ret; buf_size = port->elem.out_sg[i].iov_len - port->iov_offset; - ret = info->have_data(port, + ret = vsc->have_data(port, port->elem.out_sg[i].iov_base + port->iov_offset, buf_size); @@ -176,7 +176,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, * 1: chardevs can notify frondends * 2: the guest driver does not spin in these cases */ - if (!info->is_console) { + if (!vsc->is_console) { virtio_serial_throttle_port(port, true); } port->iov_idx = i; @@ -331,7 +331,7 @@ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle) static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len) { struct VirtIOSerialPort *port; - struct VirtIOSerialPortInfo *info; + VirtIOSerialPortClass *vsc; struct virtio_console_control cpkt, *gcpkt; uint8_t *buffer; size_t buffer_len; @@ -373,7 +373,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len) trace_virtio_serial_handle_control_message_port(port->id); - info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev)); + vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); switch(cpkt.event) { case VIRTIO_CONSOLE_PORT_READY: @@ -389,7 +389,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len) * this port is a console port so that the guest can hook it * up to hvc. */ - if (info->is_console) { + if (vsc->is_console) { send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1); } @@ -418,21 +418,21 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len) * initialised. If some app is interested in knowing about * this event, let it know. */ - if (info->guest_ready) { - info->guest_ready(port); + if (vsc->guest_ready) { + vsc->guest_ready(port); } break; case VIRTIO_CONSOLE_PORT_OPEN: port->guest_connected = cpkt.value; - if (cpkt.value && info->guest_open) { + if (cpkt.value && vsc->guest_open) { /* Send the guest opened notification if an app is interested */ - info->guest_open(port); + vsc->guest_open(port); } - if (!cpkt.value && info->guest_close) { + if (!cpkt.value && vsc->guest_close) { /* Send the guest closed notification if an app is interested */ - info->guest_close(port); + vsc->guest_close(port); } break; } @@ -751,7 +751,7 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id) static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) { VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); - VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev, base); + VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus); int ret, max_nr_ports; bool plugging_port0; @@ -759,14 +759,14 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) port->vser = bus->vser; port->bh = qemu_bh_new(flush_queued_data_bh, port); - assert(info->have_data); + assert(vsc->have_data); /* * 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). */ - plugging_port0 = info->is_console && !find_port_by_id(port->vser, 0); + 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", @@ -793,7 +793,7 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) return -1; } - ret = info->init(port); + ret = vsc->init(port); if (ret) { return ret; } @@ -823,8 +823,7 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) static int virtser_port_qdev_exit(DeviceState *qdev) { VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); - VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev, - qdev_get_info(&port->dev)); + VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); VirtIOSerial *vser = port->vser; qemu_bh_delete(port->bh); @@ -832,19 +831,19 @@ static int virtser_port_qdev_exit(DeviceState *qdev) QTAILQ_REMOVE(&vser->ports, port, next); - if (info->exit) { - info->exit(port); + if (vsc->exit) { + vsc->exit(port); } return 0; } -void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info) +void virtio_serial_port_qdev_register(DeviceInfo *info) { - info->qdev.init = virtser_port_qdev_init; - info->qdev.bus_info = &virtser_bus_info; - info->qdev.exit = virtser_port_qdev_exit; - info->qdev.unplug = qdev_simple_unplug_cb; - qdev_register(&info->qdev); + 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); } VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) @@ -940,3 +939,18 @@ void virtio_serial_exit(VirtIODevice *vdev) virtio_cleanup(vdev); } + +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); |