From patchwork Fri Nov 16 15:35:58 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: 199664 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 D3F7A2C0082 for ; Sat, 17 Nov 2012 02:36:50 +1100 (EST) Received: from localhost ([::1]:55352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZNyK-00064i-TP for incoming@patchwork.ozlabs.org; Fri, 16 Nov 2012 10:36:48 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZNy0-0005qD-Fu for qemu-devel@nongnu.org; Fri, 16 Nov 2012 10:36:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZNxx-0002c7-8T for qemu-devel@nongnu.org; Fri, 16 Nov 2012 10:36:28 -0500 Received: from greensocs.com ([87.106.252.221]:38710 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZNxw-0002c2-Uq for qemu-devel@nongnu.org; Fri, 16 Nov 2012 10:36:25 -0500 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 4F0DA40F4C8 for ; Fri, 16 Nov 2012 15:36:24 +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 oQh9O9yOflWI; Fri, 16 Nov 2012 16:36:16 +0100 (CET) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id EEC98429FE1; Fri, 16 Nov 2012 16:36:14 +0100 (CET) Received: from compaq.katmai.xl.cx.katmai.xl.cx (bon31-2-82-224-104-128.fbx.proxad.net [82.224.104.128]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id 52D2640EF3D; Fri, 16 Nov 2012 16:36:14 +0100 (CET) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Fri, 16 Nov 2012 16:35:58 +0100 Message-Id: <1353080159-10536-3-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1353080159-10536-1-git-send-email-fred.konrad@greensocs.com> References: <1353080159-10536-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: mark.burton@greensocs.com, KONRAD Frederic Subject: [Qemu-devel] [RFC PATCH 2/3] virtio-pci : Add a virtio-bus interface 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 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 --- hw/virtio-pci.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-pci.h | 6 +++ 2 files changed, 148 insertions(+) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 9603150..09bbb2a 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" @@ -1039,13 +1040,154 @@ static TypeInfo virtio_scsi_info = { .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 */ + pci_config_set_device_id(proxy->pci_dev.config, + proxy->bus.pci_device_id); + pci_config_set_class(proxy->pci_dev.config, proxy->bus.pci_class); + + /* 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, + } +}; + +static int virtiopci_qdev_init(PCIDevice *dev) +{ + VirtIOPCIProxy *s = DO_UPCAST(VirtIOPCIProxy, pci_dev, dev); + + /* create a virtio-bus and attach virtio-pci to it */ + virtio_bus_new(&s->bus, &dev->qdev, &virtio_bus_info); + + return 0; +} + +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); + /* 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 ac9d522..d3ce579 100644 --- a/hw/virtio-pci.h +++ b/hw/virtio-pci.h @@ -19,6 +19,7 @@ #include "virtio-net.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. */ @@ -32,6 +33,7 @@ typedef struct { typedef struct { PCIDevice pci_dev; + /* This should be removed */ VirtIODevice *vdev; MemoryRegion bar; uint32_t flags; @@ -49,10 +51,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