summaryrefslogtreecommitdiff
path: root/hw/virtio-console.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2010-01-20 00:36:52 +0530
committerAnthony Liguori <aliguori@us.ibm.com>2010-01-20 08:25:23 -0600
commit98b19252cf1bd97c54bc4613f3537c5ec0aae263 (patch)
tree99d4444e2ded31e2370108d95beab958baa3a7e3 /hw/virtio-console.c
parentbb61564c77ec95b258465c05c8e429a748ff24d9 (diff)
downloadqemu-98b19252cf1bd97c54bc4613f3537c5ec0aae263.tar.gz
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>
Diffstat (limited to 'hw/virtio-console.c')
-rw-r--r--hw/virtio-console.c143
1 files changed, 0 insertions, 143 deletions
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
deleted file mode 100644
index 4f18ef29cb..0000000000
--- a/hw/virtio-console.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Virtio Console Device
- *
- * Copyright IBM, Corp. 2008
- *
- * Authors:
- * 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.
- *
- */
-
-#include "hw.h"
-#include "qemu-char.h"
-#include "virtio.h"
-#include "virtio-console.h"
-
-
-typedef struct VirtIOConsole
-{
- VirtIODevice vdev;
- VirtQueue *ivq, *ovq;
- CharDriverState *chr;
-} VirtIOConsole;
-
-static VirtIOConsole *to_virtio_console(VirtIODevice *vdev)
-{
- return (VirtIOConsole *)vdev;
-}
-
-static void virtio_console_handle_output(VirtIODevice *vdev, VirtQueue *vq)
-{
- VirtIOConsole *s = to_virtio_console(vdev);
- VirtQueueElement elem;
-
- while (virtqueue_pop(vq, &elem)) {
- ssize_t len = 0;
- int d;
-
- for (d = 0; d < elem.out_num; d++) {
- len += qemu_chr_write(s->chr, (uint8_t *)elem.out_sg[d].iov_base,
- elem.out_sg[d].iov_len);
- }
- virtqueue_push(vq, &elem, len);
- virtio_notify(vdev, vq);
- }
-}
-
-static void virtio_console_handle_input(VirtIODevice *vdev, VirtQueue *vq)
-{
-}
-
-static uint32_t virtio_console_get_features(VirtIODevice *vdev, uint32_t f)
-{
- return f;
-}
-
-static int vcon_can_read(void *opaque)
-{
- VirtIOConsole *s = (VirtIOConsole *) opaque;
-
- if (!virtio_queue_ready(s->ivq) ||
- !(s->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK) ||
- virtio_queue_empty(s->ivq))
- return 0;
-
- /* current implementations have a page sized buffer.
- * We fall back to a one byte per read if there is not enough room.
- * It would be cool to have a function that returns the available byte
- * instead of checking for a limit */
- if (virtqueue_avail_bytes(s->ivq, TARGET_PAGE_SIZE, 0))
- return TARGET_PAGE_SIZE;
- if (virtqueue_avail_bytes(s->ivq, 1, 0))
- return 1;
- return 0;
-}
-
-static void vcon_read(void *opaque, const uint8_t *buf, int size)
-{
- VirtIOConsole *s = (VirtIOConsole *) opaque;
- VirtQueueElement elem;
- int offset = 0;
-
- /* The current kernel implementation has only one outstanding input
- * buffer of PAGE_SIZE. Nevertheless, this function is prepared to
- * handle multiple buffers with multiple sg element for input */
- while (offset < size) {
- int i = 0;
- if (!virtqueue_pop(s->ivq, &elem))
- break;
- while (offset < size && i < elem.in_num) {
- int len = MIN(elem.in_sg[i].iov_len, size - offset);
- memcpy(elem.in_sg[i].iov_base, buf + offset, len);
- offset += len;
- i++;
- }
- virtqueue_push(s->ivq, &elem, size);
- }
- virtio_notify(&s->vdev, s->ivq);
-}
-
-static void vcon_event(void *opaque, int event)
-{
- /* we will ignore any event for the time being */
-}
-
-static void virtio_console_save(QEMUFile *f, void *opaque)
-{
- VirtIOConsole *s = opaque;
-
- virtio_save(&s->vdev, f);
-}
-
-static int virtio_console_load(QEMUFile *f, void *opaque, int version_id)
-{
- VirtIOConsole *s = opaque;
-
- if (version_id != 1)
- return -EINVAL;
-
- virtio_load(&s->vdev, f);
- return 0;
-}
-
-VirtIODevice *virtio_console_init(DeviceState *dev)
-{
- VirtIOConsole *s;
- s = (VirtIOConsole *)virtio_common_init("virtio-console",
- VIRTIO_ID_CONSOLE,
- 0, sizeof(VirtIOConsole));
- s->vdev.get_features = virtio_console_get_features;
-
- s->ivq = virtio_add_queue(&s->vdev, 128, virtio_console_handle_input);
- s->ovq = virtio_add_queue(&s->vdev, 128, virtio_console_handle_output);
-
- s->chr = qdev_init_chardev(dev);
- qemu_chr_add_handlers(s->chr, vcon_can_read, vcon_read, vcon_event, s);
-
- register_savevm("virtio-console", -1, 1, virtio_console_save, virtio_console_load, s);
-
- return &s->vdev;
-}