From: Peter Maydell <peter.maydell@linaro.org>
To: fred.konrad@greensocs.com
Cc: aliguori@us.ibm.com, e.voevodin@samsung.com,
mark.burton@greensocs.com, qemu-devel@nongnu.org,
stefanha@redhat.com, cornelia.huck@de.ibm.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [RFC PATCH V4 2/6] virtio-bus : Introduce virtio-bus
Date: Fri, 30 Nov 2012 18:36:04 +0000 [thread overview]
Message-ID: <CAFEAcA8rtPcQ6hGiyRVVBKtAGYT8djBK_kJhghQoQwf7K5gJBw@mail.gmail.com> (raw)
In-Reply-To: <1354295530-18644-3-git-send-email-fred.konrad@greensocs.com>
On 30 November 2012 17:12, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/Makefile.objs | 1 +
> hw/virtio-bus.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-bus.h | 78 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 193 insertions(+), 0 deletions(-)
> create mode 100644 hw/virtio-bus.c
> create mode 100644 hw/virtio-bus.h
>
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index d581d8d..6fa4de4 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -3,6 +3,7 @@ common-obj-y += loader.o
> common-obj-$(CONFIG_VIRTIO) += virtio-console.o
> common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
> common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
> common-obj-y += fw_cfg.o
> common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
> common-obj-$(CONFIG_PCI) += msix.o msi.o
> diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
> new file mode 100644
> index 0000000..ed9c146
> --- /dev/null
> +++ b/hw/virtio-bus.c
> @@ -0,0 +1,114 @@
> +/*
> + * VirtioBus
> + *
> + * Copyright (C) 2012 : GreenSocs Ltd
> + * http://www.greensocs.com/ , email: info@greensocs.com
> + *
> + * Developed by :
> + * Frederic Konrad <fred.konrad@greensocs.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#include "hw.h"
> +#include "qemu-error.h"
> +#include "qdev.h"
> +#include "virtio-bus.h"
> +#include "virtio.h"
> +
> +#define DEBUG_VIRTIO_BUS
Don't enable debug by default.
> +
> +#ifdef DEBUG_VIRTIO_BUS
> +#define DPRINTF(fmt, ...) \
> +do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
> +#else
> +#define DPRINTF(fmt, ...) do { } while (0)
> +#endif
> +
> +/* Is the bus used ? */
> +static inline int virtio_bus_in_use(VirtioBusState *bus)
> +{
> + return (bus->vdev != NULL);
> +}
> +
> +/* Plug the VirtIODevice */
> +int virtio_bus_plug_device(VirtioBusState *bus, VirtIODevice *vdev)
> +{
> + BusState *qbus = BUS(bus);
> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> + DPRINTF("plug device into %s.\n", qbus->name);
> + if (virtio_bus_in_use(bus)) {
> + /*
> + * that couldn't be reached if we modify qdev-monitor.c
> + * ( see other patch ).
> + */
> + error_report("%s in use.\n", qbus->name);
> + return -1;
You can assume that patch 1 in your series has been applied
here: just assert(bus->vdev == NULL) (and drop the virtio_bus_in_use
function).
> + }
> +
> + /* keep the VirtIODevice in the VirtioBus. */
This comment is useless: say something useful, not something which
is obvious from the code.
> + bus->vdev = vdev;
> +
> + /* call the "transport" callback. */
> + if (klass->init != NULL) {
> + klass->init(qbus->parent);
> + }
Comment and code disagree about what's happening.
> + return 0;
> +}
> +
> +/* Bind the VirtIODevice to the VirtioBus. */
> +void virtio_bus_bind_device(VirtioBusState *bus)
> +{
> + BusState *qbus = BUS(bus);
> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> + assert(bus != NULL);
> + assert(bus->vdev != NULL);
> + /*
> + * The lines below will disappear, as we will refactor virtio-device.
> + */
> + bus->bindings.notify = klass->notify;
> + bus->bindings.save_config = klass->save_config;
> + bus->bindings.save_queue = klass->save_queue;
> + bus->bindings.load_config = klass->load_config;
> + bus->bindings.load_queue = klass->load_queue;
> + bus->bindings.load_done = klass->load_done;
> + bus->bindings.get_features = klass->get_features;
> + bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
> + bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
> + bus->bindings.set_host_notifier = klass->set_host_notifier;
> + bus->bindings.vmstate_change = klass->vmstate_change;
> + virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
> +}
> +
> +/* Return the virtio device id of the plugged device. */
> +uint16_t get_virtio_device_id(VirtioBusState *bus)
> +{
> + return bus->vdev->device_id;
> +}
> +
> +static const TypeInfo virtio_bus_info = {
> + .name = TYPE_VIRTIO_BUS,
> + .parent = TYPE_BUS,
> + .instance_size = sizeof(VirtioBusState),
> + .abstract = true,
> + .class_size = sizeof(VirtioBusClass),
> +};
> +
> +static void virtio_register_types(void)
> +{
> + type_register_static(&virtio_bus_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
> new file mode 100644
> index 0000000..90ae67c
> --- /dev/null
> +++ b/hw/virtio-bus.h
> @@ -0,0 +1,78 @@
> +/*
> + * VirtioBus
> + *
> + * Copyright (C) 2012 : GreenSocs Ltd
> + * http://www.greensocs.com/ , email: info@greensocs.com
> + *
> + * Developed by :
> + * Frederic Konrad <fred.konrad@greensocs.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#ifndef VIRTIO_BUS_H
> +#define VIRTIO_BUS_H
> +
> +#include "qdev.h"
> +#include "sysemu.h"
> +#include "virtio.h"
> +
> +#define TYPE_VIRTIO_BUS "virtio-bus"
> +#define VIRTIO_BUS_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
> +#define VIRTIO_BUS_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
> +#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
> +
> +typedef struct VirtioBusState VirtioBusState;
> +
> +typedef struct VirtioBusClass {
> + /* This is what a VirtioBus must implement */
> + BusClass parent;
> + /* Old VirtioBindings */
This is not a particularly useful comment. There's an opportunity
here to provide some doc comments which describe what all these
callbacks a VirtioBus must implement are for.
> + void (*notify)(void *opaque, uint16_t vector);
> + void (*save_config)(void *opaque, QEMUFile *f);
> + void (*save_queue)(void *opaque, int n, QEMUFile *f);
> + int (*load_config)(void *opaque, QEMUFile *f);
> + int (*load_queue)(void *opaque, int n, QEMUFile *f);
> + int (*load_done)(void *opaque, QEMUFile *f);
> + unsigned (*get_features)(void *opaque);
> + bool (*query_guest_notifiers)(void *opaque);
> + int (*set_guest_notifiers)(void *opaque, bool assigned);
> + int (*set_host_notifier)(void *opaque, int n, bool assigned);
> + void (*vmstate_change)(void *opaque, bool running);
> + /* transport independent init function. */
> + void (*init)(void *opaque);
> + /* transport independent exit function. */
> + void (*exit)(void *opaque);
> +} VirtioBusClass;
> +
> +struct VirtioBusState {
> + BusState parent_obj;
> + /*
> + * Only one VirtIODevice can be plugged on the bus.
> + */
> + VirtIODevice *vdev;
> + /*
> + * This should be removed when we refactor virtio-device.
> + */
> + VirtIOBindings bindings;
> +};
> +
> +void virtio_bus_bind_device(VirtioBusState *bus);
> +int virtio_bus_plug_device(VirtioBusState *bus, VirtIODevice *vdev);
> +uint16_t get_virtio_device_id(VirtioBusState *bus);
> +
> +#endif /* VIRTIO_BUS_H */
> --
> 1.7.1
>
-- PMM
next prev parent reply other threads:[~2012-11-30 18:36 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 [this message]
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 ` [Qemu-devel] [RFC PATCH V4 5/6] virtio-device : Introduce virtio-device fred.konrad
2012-11-30 18:40 ` 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=CAFEAcA8rtPcQ6hGiyRVVBKtAGYT8djBK_kJhghQoQwf7K5gJBw@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=e.voevodin@samsung.com \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--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).