From: Anthony Liguori <aliguori@us.ibm.com>
To: fred.konrad@greensocs.com, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, e.voevodin@samsung.com,
mark.burton@greensocs.com, agraf@suse.de, stefanha@redhat.com,
cornelia.huck@de.ibm.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device.
Date: Wed, 02 Jan 2013 08:15:33 -0600 [thread overview]
Message-ID: <87d2xnd62i.fsf@codemonkey.ws> (raw)
In-Reply-To: <1355910821-21302-6-git-send-email-fred.konrad@greensocs.com>
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create the virtio-device which is abstract. All the virtio-device can extend
> this class.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> ---
> hw/virtio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
> hw/virtio.h | 31 +++++++++++++++++++++++++++
> 2 files changed, 89 insertions(+), 12 deletions(-)
>
> diff --git a/hw/virtio.c b/hw/virtio.c
> index f40a8c5..e40fa12 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.
> @@ -875,11 +876,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
> return 0;
> }
>
> -void virtio_cleanup(VirtIODevice *vdev)
> +void virtio_common_cleanup(VirtIODevice *vdev)
> {
> qemu_del_vm_change_state_handler(vdev->vmstate);
> g_free(vdev->config);
> g_free(vdev->vq);
> +}
> +
> +void virtio_cleanup(VirtIODevice *vdev)
> +{
> + virtio_common_cleanup(vdev);
> g_free(vdev);
> }
>
> @@ -902,14 +908,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
> }
> }
>
> -VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> - size_t config_size, size_t struct_size)
> +void virtio_init(VirtIODevice *vdev, const char *name,
> + uint16_t device_id, size_t config_size)
> {
> - VirtIODevice *vdev;
> int i;
> -
> - vdev = g_malloc0(struct_size);
> -
> vdev->device_id = device_id;
> vdev->status = 0;
> vdev->isr = 0;
> @@ -917,20 +919,28 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> vdev->config_vector = VIRTIO_NO_VECTOR;
> vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
> vdev->vm_running = runstate_is_running();
> - for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
> + for (i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
> vdev->vq[i].vector = VIRTIO_NO_VECTOR;
> vdev->vq[i].vdev = vdev;
> }
>
> vdev->name = name;
> vdev->config_len = config_size;
> - if (vdev->config_len)
> + if (vdev->config_len) {
> vdev->config = g_malloc0(config_size);
> - else
> + } else {
> vdev->config = NULL;
> + }
> + vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
> + vdev);
> +}
>
> - vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev);
> -
> +VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> + size_t config_size, size_t struct_size)
> +{
> + VirtIODevice *vdev;
> + vdev = g_malloc0(struct_size);
> + virtio_init(vdev, name, device_id, config_size);
> return vdev;
> }
>
> @@ -1056,3 +1066,39 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
> {
> return &vq->host_notifier;
> }
> +
> +static int virtio_device_init(DeviceState *qdev)
> +{
> + VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
> + assert(k->init != NULL);
> + if (k->init(vdev) < 0) {
> + return -1;
> + }
> + virtio_bus_plug_device(vdev);
> + return 0;
> +}
> +
> +static void virtio_device_class_init(ObjectClass *klass, void *data)
> +{
> + /* Set the default value here. */
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + dc->init = virtio_device_init;
> + 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..98596a9 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -108,8 +108,17 @@ typedef struct {
>
> #define VIRTIO_NO_VECTOR 0xffff
>
> +#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)
> +
> struct VirtIODevice
> {
> + DeviceState parent_obj;
> const char *name;
> uint8_t status;
> uint8_t isr;
> @@ -119,6 +128,10 @@ struct VirtIODevice
> void *config;
> uint16_t config_vector;
> int nvectors;
> + /*
> + * Will be removed ( at the end of the series ) as we have it in
> + * VirtioDeviceClass.
> + */
> uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
> uint32_t (*bad_features)(VirtIODevice *vdev);
> void (*set_features)(VirtIODevice *vdev, uint32_t val);
> @@ -126,6 +139,7 @@ struct VirtIODevice
> void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
> void (*reset)(VirtIODevice *vdev);
> void (*set_status)(VirtIODevice *vdev, uint8_t val);
> + /***/
> VirtQueue *vq;
> const VirtIOBindings *binding;
> void *binding_opaque;
> @@ -134,6 +148,23 @@ struct VirtIODevice
> VMChangeStateEntry *vmstate;
> };
>
> +typedef struct {
> + /* This is what a VirtioDevice must implement */
> + DeviceClass parent;
> + int (*init)(VirtIODevice *vdev);
> + 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;
> +
> +void virtio_init(VirtIODevice *vdev, const char *name,
> + uint16_t device_id, size_t config_size);
> +void virtio_common_cleanup(VirtIODevice *vdev);
> +
> VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
> void (*handle_output)(VirtIODevice *,
> VirtQueue *));
> --
> 1.7.11.7
next prev parent reply other threads:[~2013-01-02 14:15 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus fred.konrad
2013-01-02 14:08 ` Anthony Liguori
2013-01-02 14:16 ` Andreas Färber
2013-01-02 14:30 ` KONRAD Frédéric
2013-01-03 14:03 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2013-01-03 9:57 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
2012-12-19 19:53 ` Blue Swirl
2013-01-02 14:14 ` Anthony Liguori
2013-01-02 14:17 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device fred.konrad
2013-01-02 14:15 ` Anthony Liguori [this message]
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus fred.konrad
2012-12-19 18:09 ` Cornelia Huck
2012-12-20 8:03 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device fred.konrad
2012-12-19 20:00 ` Blue Swirl
2012-12-19 23:22 ` Peter Maydell
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API fred.konrad
2013-01-02 14:18 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the " fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer fred.konrad
2012-12-19 19:50 ` Blue Swirl
2012-12-20 8:02 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings fred.konrad
2012-12-19 19:54 ` Blue Swirl
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function fred.konrad
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=87d2xnd62i.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=cornelia.huck@de.ibm.com \
--cc=e.voevodin@samsung.com \
--cc=fred.konrad@greensocs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.