From: fred.konrad@greensocs.com
To: qemu-devel@nongnu.org
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.
Date: Fri, 30 Nov 2012 18:12:09 +0100 [thread overview]
Message-ID: <1354295530-18644-6-git-send-email-fred.konrad@greensocs.com> (raw)
In-Reply-To: <1354295530-18644-1-git-send-email-fred.konrad@greensocs.com>
From: KONRAD Frederic <fred.konrad@greensocs.com>
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
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
--
1.7.1
next prev parent reply other threads:[~2012-11-30 17:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-30 17:12 [Qemu-devel] [RFC PATCH V4 0/6] Virtio refactoring fred.konrad
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 1/6] qdev : add a maximum device allowed field for the bus fred.konrad
2012-11-30 18:26 ` Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 2/6] virtio-bus : Introduce virtio-bus fred.konrad
2012-11-30 18:36 ` Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 3/6] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 4/6] virtio-pci : Introduce virtio-pci device fred.konrad
2012-11-30 17:12 ` fred.konrad [this message]
2012-11-30 18:40 ` [Qemu-devel] [RFC PATCH V4 5/6] virtio-device : Introduce virtio-device Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 6/6] virtio-blk : Refactoring virtio-blk fred.konrad
2012-11-30 18:42 ` Peter Maydell
2012-11-30 18:43 ` [Qemu-devel] [RFC PATCH V4 0/6] Virtio refactoring Peter Maydell
2012-12-03 9:25 ` KONRAD Frédéric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1354295530-18644-6-git-send-email-fred.konrad@greensocs.com \
--to=fred.konrad@greensocs.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=e.voevodin@samsung.com \
--cc=mark.burton@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).