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, stefanha@redhat.com,
cornelia.huck@de.ibm.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [RFC PATCH v2 2/3] virtio-pci : add a virtio-bus interface
Date: Mon, 26 Nov 2012 08:43:42 -0600 [thread overview]
Message-ID: <87haocqva9.fsf@codemonkey.ws> (raw)
In-Reply-To: <1353595852-30776-3-git-send-email-fred.konrad@greensocs.com>
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This patch add a VirtioBus in the VirtIOPCIProxy structure. It creates a new
> device : "virtio-pci" which init the VirtioBus. Two callback are written :
>
> * void virtio_pci_init_cb(DeviceState *dev) to initialize the PCI interface
> after the VirtIODevice init, it is approximately the same as
> virtio_init_pci.
>
> * void virtio_pci_exit_cb(DeviceState *dev) to stop the ioevent before the
> VirtIODevice exit.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-pci.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-pci.h | 6 +++
> 2 files changed, 158 insertions(+)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 71f4fb5..78aa5e8 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -22,6 +22,7 @@
> #include "virtio-net.h"
> #include "virtio-serial.h"
> #include "virtio-scsi.h"
> +#include "virtio-bus.h"
> #include "pci.h"
> #include "qemu-error.h"
> #include "msi.h"
> @@ -1117,15 +1118,166 @@ static TypeInfo virtio_scsi_info = {
> .instance_size = sizeof(VirtIOPCIProxy),
> .class_init = virtio_scsi_class_init,
> };
> +/* The new virtio-pci device */
> +
> +void virtio_pci_init_cb(DeviceState *dev)
> +{
> + PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev);
> + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, d);
> + uint8_t *config;
> + uint32_t size;
> +
> + /* Put the PCI IDs */
> + switch (get_virtio_device_id(proxy->bus)) {
> +
> + case VIRTIO_ID_BLOCK:
> + pci_config_set_device_id(proxy->pci_dev.config,
> + PCI_DEVICE_ID_VIRTIO_BLOCK);
> + pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
> + break;
> + default:
> + error_report("unknown device id\n");
> + break;
> +
> + }
> +
> + /* virtio_init_pci code without bindings */
> +
> + /* This should disappear */
> + proxy->vdev = proxy->bus->vdev;
> +
> + config = proxy->pci_dev.config;
> +
> + if (proxy->class_code) {
> + pci_config_set_class(config, proxy->class_code);
> + }
> + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> + pci_get_word(config + PCI_VENDOR_ID));
> + pci_set_word(config + PCI_SUBSYSTEM_ID, proxy->bus->vdev->device_id);
> + config[PCI_INTERRUPT_PIN] = 1;
> +
> + if (proxy->bus->vdev->nvectors &&
> + msix_init_exclusive_bar(&proxy->pci_dev, proxy->bus->vdev->nvectors,
> + 1)) {
> + proxy->bus->vdev->nvectors = 0;
> + }
> +
> + proxy->pci_dev.config_write = virtio_write_config;
> +
> + size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
> + + proxy->bus->vdev->config_len;
> + if (size & (size-1)) {
> + size = 1 << qemu_fls(size);
> + }
> +
> + memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
> + "virtio-pci", size);
> + pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
> + &proxy->bar);
> +
> + if (!kvm_has_many_ioeventfds()) {
> + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> + }
> +
> + /* Bind the VirtIODevice to the VirtioBus. */
> + virtio_bus_bind_device(proxy->bus);
> +
> + proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
> + proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
> + /* Should be modified */
> + proxy->host_features = proxy->bus->vdev->get_features(proxy->bus->vdev,
> + proxy->host_features);
> +}
> +
> +void virtio_pci_exit_cb(DeviceState *dev)
> +{
> + PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev);
> + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, d);
> + /* Put the PCI IDs */
> + pci_config_set_device_id(proxy->pci_dev.config, 0x0000);
> + pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS);
> +
> + virtio_pci_stop_ioeventfd(proxy);
> +}
> +
> +static const struct VirtioBusInfo virtio_bus_info = {
> + .init_cb = virtio_pci_init_cb,
> + .exit_cb = virtio_pci_exit_cb,
> +
> + .virtio_bindings = {
> + .notify = virtio_pci_notify,
> + .save_config = virtio_pci_save_config,
> + .load_config = virtio_pci_load_config,
> + .save_queue = virtio_pci_save_queue,
> + .load_queue = virtio_pci_load_queue,
> + .get_features = virtio_pci_get_features,
> + .query_guest_notifiers = virtio_pci_query_guest_notifiers,
> + .set_host_notifier = virtio_pci_set_host_notifier,
> + .set_guest_notifiers = virtio_pci_set_guest_notifiers,
> + .vmstate_change = virtio_pci_vmstate_change,
> + }
> +};
So this looks wrong.
The interactions should roughly look like:
(1) VirtioDevice only interacts with VirtioBus through it's class
methods. 'notify' is a method.
(2) Since VirtioBus is a descrete object, it needs to interact with
whatever the actual bus is. There are two ways to do this:
(a) Each bus-type can sub-class VirtioBus and implement each method
using a private interface. This is probably the easiest
approach because you can just give VirtioPCIBus a pointer to the
PCIDevice, and then implement the methods within VirtioPCIBus.
(b) There can be only one VirtioBus object type with a well defined
proxy interface. This should basically mirror the VirtioBus
class methods. VirtioPCI can then implement this proxy
interface.
Seeing how the code is turning out, I think 2.a would require the least
amount of coding.
> +
> +static int virtiopci_qdev_init(PCIDevice *dev)
> +{
> + VirtIOPCIProxy *s = DO_UPCAST(VirtIOPCIProxy, pci_dev, dev);
> + DeviceState *qdev = DEVICE(dev);
> +
> + /* create a virtio-bus and attach virtio-pci to it */
> + s->bus = virtio_bus_new(qdev, &virtio_bus_info);
You basically end up with virtio_pci_bus_new() here and you pass 'dev'
to it. VirtioPCIBus is a 'friend' to VirtioPCI so it can access it's
private data.
> +
> + return 0;
> +}
> +
Regards,
Anthony Liguori
> +static Property virtiopci_properties[] = {
> + /* TODO : Add the correct properties */
> + DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void virtiopci_class_init(ObjectClass *oc, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(oc);
> + PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc);
> +
> + pc->init = virtiopci_qdev_init;
> + pc->exit = virtio_exit_pci;
> + pc->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
> + pc->revision = VIRTIO_PCI_ABI_VERSION;
> + pc->class_id = PCI_CLASS_OTHERS;
> + /* TODO : Add the correct device information below */
> + /* pc->exit =
> + * pc->device_id =
> + * pc->subsystem_vendor_id =
> + * pc->subsystem_id =
> + * dc->reset =
> + * dc->vmsd =
> + */
> + dc->props = virtiopci_properties;
> + dc->desc = "virtio-pci transport.";
> +}
> +
> +static const TypeInfo virtio_pci_info = {
> + .name = "virtio-pci",
> + .parent = TYPE_PCI_DEVICE,
> + .instance_size = sizeof(VirtIOPCIProxy),
> + .class_init = virtiopci_class_init,
> +};
> +
> +
> +/************************************/
> +
>
> static void virtio_pci_register_types(void)
> {
> + /* This should disappear */
> type_register_static(&virtio_blk_info);
> type_register_static(&virtio_net_info);
> type_register_static(&virtio_serial_info);
> type_register_static(&virtio_balloon_info);
> type_register_static(&virtio_scsi_info);
> type_register_static(&virtio_rng_info);
> + /* new virtio-pci device */
> + type_register_static(&virtio_pci_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index b58d9a2..a7a9847 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -20,6 +20,7 @@
> #include "virtio-rng.h"
> #include "virtio-serial.h"
> #include "virtio-scsi.h"
> +#include "virtio-bus.h"
>
> /* Performance improves when virtqueue kick processing is decoupled from the
> * vcpu thread using ioeventfd for some devices. */
> @@ -33,6 +34,7 @@ typedef struct {
>
> typedef struct {
> PCIDevice pci_dev;
> + /* This should be removed */
> VirtIODevice *vdev;
> MemoryRegion bar;
> uint32_t flags;
> @@ -51,10 +53,14 @@ typedef struct {
> bool ioeventfd_disabled;
> bool ioeventfd_started;
> VirtIOIRQFD *vector_irqfd;
> + /* VirtIOBus to connect the VirtIODevice */
> + VirtioBus *bus;
> } VirtIOPCIProxy;
>
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> void virtio_pci_reset(DeviceState *d);
> +void virtio_pci_init_cb(DeviceState *dev);
> +void virtio_pci_exit_cb(DeviceState *dev);
>
> /* Virtio ABI version, if we increment this, we break the guest driver. */
> #define VIRTIO_PCI_ABI_VERSION 0
> --
> 1.7.11.7
next prev parent reply other threads:[~2012-11-26 14:44 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-22 14:50 [Qemu-devel] [RFC PATCH v2 0/3] Virtio-refactoring fred.konrad
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 1/3] virtio-bus : Introduce VirtioBus fred.konrad
2012-11-23 12:08 ` Cornelia Huck
2012-11-23 14:12 ` Konrad Frederic
2012-11-23 14:35 ` Cornelia Huck
2012-11-26 13:55 ` Konrad Frederic
2012-11-26 14:03 ` Cornelia Huck
2012-11-23 12:23 ` Stefan Hajnoczi
2012-11-23 14:21 ` Konrad Frederic
2012-11-23 16:13 ` Stefan Hajnoczi
2012-11-24 22:29 ` Andreas Färber
2012-11-26 14:33 ` Anthony Liguori
2012-11-26 14:37 ` Peter Maydell
2012-11-26 16:59 ` Anthony Liguori
2012-11-29 12:37 ` Konrad Frederic
2012-11-29 13:09 ` Peter Maydell
2012-11-29 13:47 ` Konrad Frederic
2012-11-29 13:53 ` Peter Maydell
2012-11-29 13:55 ` Andreas Färber
2012-11-29 14:28 ` Konrad Frederic
2012-11-29 13:52 ` Anthony Liguori
2012-11-26 14:45 ` Andreas Färber
2012-11-26 16:55 ` Anthony Liguori
2012-11-26 15:33 ` Konrad Frederic
2012-11-26 15:40 ` Stefan Hajnoczi
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 2/3] virtio-pci : add a virtio-bus interface fred.konrad
2012-11-23 12:11 ` Cornelia Huck
2012-11-23 12:29 ` Stefan Hajnoczi
2012-11-23 12:34 ` Peter Maydell
2012-11-23 14:23 ` Konrad Frederic
2012-11-23 14:26 ` Peter Maydell
2012-11-23 14:33 ` Konrad Frederic
2012-11-26 14:43 ` Anthony Liguori [this message]
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 3/3] virtio-blk : add the virtio-blk device fred.konrad
2012-11-23 12:32 ` Stefan Hajnoczi
2012-11-22 15:08 ` [Qemu-devel] [RFC PATCH v2 0/3] Virtio-refactoring Peter Maydell
2012-11-22 15:15 ` KONRAD Frédéric
2012-11-23 12:38 ` Stefan Hajnoczi
2012-11-23 14:29 ` Konrad Frederic
2012-11-23 16:18 ` Stefan Hajnoczi
2012-11-26 9:00 ` Konrad Frederic
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=87haocqva9.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=afaerber@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.