From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNYTR-0002v3-2H for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:05:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNYTQ-0002uC-B1 for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:05:52 -0500 Received: from [199.232.76.173] (port=48150 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNYTQ-0002u2-5x for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:05:52 -0500 Received: from savannah.gnu.org ([199.232.41.3]:51058 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LNYTP-0001BH-MF for qemu-devel@nongnu.org; Thu, 15 Jan 2009 15:05:51 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LNYTP-000226-2f for qemu-devel@nongnu.org; Thu, 15 Jan 2009 20:05:51 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LNYTO-000222-SS for qemu-devel@nongnu.org; Thu, 15 Jan 2009 20:05:50 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 15 Jan 2009 20:05:50 +0000 Subject: [Qemu-devel] [6316] Add missing files from last commit. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6316 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6316 Author: aliguori Date: 2009-01-15 20:05:50 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Add missing files from last commit. Signed-off-by: Anthony Liguori Added Paths: ----------- trunk/hw/virtio-console.c trunk/hw/virtio-console.h Added: trunk/hw/virtio-console.c =================================================================== --- trunk/hw/virtio-console.c (rev 0) +++ trunk/hw/virtio-console.c 2009-01-15 20:05:50 UTC (rev 6316) @@ -0,0 +1,147 @@ +/* + * Virtio Console Device + * + * Copyright IBM, Corp. 2008 + * + * Authors: + * Christian Ehrhardt + * + * 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, *dvq; + 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, 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) +{ + return 0; +} + +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; +} + +void *virtio_console_init(PCIBus *bus, CharDriverState *chr) +{ + VirtIOConsole *s; + + s = (VirtIOConsole *)virtio_init_pci(bus, "virtio-console", + 6900, 0x1003, + 0, VIRTIO_ID_CONSOLE, + 0x03, 0x80, 0x00, + 0, sizeof(VirtIOConsole)); + if (s == NULL) + return NULL; + + s->vdev.get_features = virtio_console_get_features; + + s->ivq = virtio_add_queue(&s->vdev, 128, virtio_console_handle_input); + s->dvq = virtio_add_queue(&s->vdev, 128, virtio_console_handle_output); + + s->chr = chr; + qemu_chr_add_handlers(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; +} Added: trunk/hw/virtio-console.h =================================================================== --- trunk/hw/virtio-console.h (rev 0) +++ trunk/hw/virtio-console.h 2009-01-15 20:05:50 UTC (rev 6316) @@ -0,0 +1,22 @@ +/* + * Virtio Console Support + * + * Copyright IBM, Corp. 2008 + * + * Authors: + * Christian Ehrhardt + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ +#ifndef _QEMU_VIRTIO_CONSOLE_H +#define _QEMU_VIRTIO_CONSOLE_H + +/* The ID for virtio console */ +#define VIRTIO_ID_CONSOLE 3 + +/* Creates a virtio console */ +void *virtio_console_init(PCIBus *bus, CharDriverState *chr); + +#endif