From patchwork Fri Nov 30 17:12:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fred.konrad@greensocs.com X-Patchwork-Id: 203008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D6B1B2C008F for ; Sat, 1 Dec 2012 04:46:09 +1100 (EST) Received: from localhost ([::1]:48482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeU8n-0004SK-NK for incoming@patchwork.ozlabs.org; Fri, 30 Nov 2012 12:12:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeU87-0002Xy-G3 for qemu-devel@nongnu.org; Fri, 30 Nov 2012 12:12:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TeU82-0000Rr-SA for qemu-devel@nongnu.org; Fri, 30 Nov 2012 12:11:59 -0500 Received: from greensocs.com ([87.106.252.221]:41248 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeU82-0000Re-GZ for qemu-devel@nongnu.org; Fri, 30 Nov 2012 12:11:54 -0500 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 188EA439E21; Fri, 30 Nov 2012 17:11:54 +0000 (UTC) Received: from s15328186.onlinehome-server.info ([127.0.0.1]) by localhost (s15328186.onlinehome-server.info [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pMzM+SAc9kPz; Fri, 30 Nov 2012 18:11:53 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id D53C8439E22; Fri, 30 Nov 2012 18:11:53 +0100 (CET) Received: from localhost.localdomain (214.155.72.86.rev.sfr.net [86.72.155.214]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id B757F439E21; Fri, 30 Nov 2012 18:11:52 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2012 18:12:09 +0100 Message-Id: <1354295530-18644-6-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1354295530-18644-1-git-send-email-fred.konrad@greensocs.com> References: <1354295530-18644-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 87.106.252.221 Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, e.voevodin@samsung.com, mark.burton@greensocs.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH V4 5/6] virtio-device : Introduce virtio-device. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: KONRAD Frederic Signed-off-by: KONRAD Frederic --- hw/virtio.c | 28 ++++++++++++++++++++++++++++ hw/virtio.h | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index f40a8c5..1c72d17 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -16,6 +16,7 @@ #include "trace.h" #include "qemu-error.h" #include "virtio.h" +#include "virtio-bus.h" #include "qemu-barrier.h" /* The alignment to use between consumer and producer parts of vring. @@ -1056,3 +1057,30 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq) { return &vq->host_notifier; } + +/* + * Refactored VirtioDevice. + */ + +static void virtio_device_class_init(ObjectClass *klass, void *data) +{ + /* Set the default value here. */ + DeviceClass *dc = DEVICE_CLASS(klass); + dc->bus_type = TYPE_VIRTIO_BUS; +} + +static const TypeInfo virtio_device_info = { + .name = TYPE_VIRTIO_DEVICE, + .parent = TYPE_DEVICE, + .instance_size = sizeof(VirtIODevice), + .class_init = virtio_device_class_init, + .abstract = true, + .class_size = sizeof(VirtioDeviceClass), +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_device_info); +} + +type_init(virtio_register_types) diff --git a/hw/virtio.h b/hw/virtio.h index 7c17f7b..b890eb1 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -108,8 +108,22 @@ typedef struct { #define VIRTIO_NO_VECTOR 0xffff +/* + * Refactored VirtioDevice. + */ + +#define TYPE_VIRTIO_DEVICE "virtio-device" +#define VIRTIO_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE) +#define VIRTIO_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE) +#define VIRTIO_DEVICE(obj) \ + OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE) + +/* This should be renammed VirtioDeviceState at the end. */ struct VirtIODevice { + DeviceState parent_obj; const char *name; uint8_t status; uint8_t isr; @@ -134,6 +148,18 @@ struct VirtIODevice VMChangeStateEntry *vmstate; }; +typedef struct { + /* This is what a VirtioDevice must implement */ + DeviceClass parent; + uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features); + uint32_t (*bad_features)(VirtIODevice *vdev); + void (*set_features)(VirtIODevice *vdev, uint32_t val); + void (*get_config)(VirtIODevice *vdev, uint8_t *config); + void (*set_config)(VirtIODevice *vdev, const uint8_t *config); + void (*reset)(VirtIODevice *vdev); + void (*set_status)(VirtIODevice *vdev, uint8_t val); +} VirtioDeviceClass; + VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, void (*handle_output)(VirtIODevice *, VirtQueue *)); @@ -244,4 +270,5 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign, bool set_handler); void virtio_queue_notify_vq(VirtQueue *vq); void virtio_irq(VirtQueue *vq); + #endif