From patchwork Sun Apr 14 13:01:05 2013 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: 236434 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 BCD2E2C0092 for ; Sun, 14 Apr 2013 23:02:16 +1000 (EST) Received: from localhost ([::1]:37598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URMZS-0003A8-Vz for incoming@patchwork.ozlabs.org; Sun, 14 Apr 2013 09:02:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URMYo-000352-RJ for qemu-devel@nongnu.org; Sun, 14 Apr 2013 09:01:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URMYn-0001MR-CP for qemu-devel@nongnu.org; Sun, 14 Apr 2013 09:01:34 -0400 Received: from greensocs.com ([87.106.252.221]:34301 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URMYn-0001ME-1t for qemu-devel@nongnu.org; Sun, 14 Apr 2013 09:01:33 -0400 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 7102140B250; Sun, 14 Apr 2013 13:01:32 +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 4nxc3OnXsnXK; Sun, 14 Apr 2013 15:01:30 +0200 (CEST) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id D1B3A40EC64; Sun, 14 Apr 2013 15:01:19 +0200 (CEST) Received: from compaq.katmai.xl.cx.katmai.xl.cx (lan31-11-83-155-143-136.fbx.proxad.net [83.155.143.136]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id 64F31400091; Sun, 14 Apr 2013 15:01:18 +0200 (CEST) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com, amit.shah@redhat.com Date: Sun, 14 Apr 2013 15:01:05 +0200 Message-Id: <1365944470-13837-4-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1365944470-13837-1-git-send-email-fred.konrad@greensocs.com> References: <1365944470-13837-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: cornelia.huck@de.ibm.com, peter.maydell@linaro.org, mark.burton@greensocs.com, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v3 3/8] virtio-rng-pci: switch to the new API. 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 Here the virtio-rng-pci is modified for the new API. The device virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device during the init. The properties are not changed. The virtio_pci_reset function, is removed as no longer used. The virtio_pci_rst function, is renamed virtio_pci_reset. Signed-off-by: KONRAD Frederic --- hw/virtio/virtio-pci.c | 150 ++++++++++++++++++++----------------------------- hw/virtio/virtio-pci.h | 14 ++++- 2 files changed, 74 insertions(+), 90 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 8ea130a..2929971 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -256,15 +256,6 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) proxy->ioeventfd_started = false; } -static void virtio_pci_reset(DeviceState *d) -{ - VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); - virtio_pci_stop_ioeventfd(proxy); - virtio_reset(proxy->vdev); - msix_unuse_all_vectors(&proxy->pci_dev); - proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG; -} - static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) { VirtIOPCIProxy *proxy = opaque; @@ -942,79 +933,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev) msix_uninit_exclusive_bar(pci_dev); } -static int virtio_rng_init_pci(PCIDevice *pci_dev) -{ - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); - VirtIODevice *vdev; - - if (proxy->rng.rng == NULL) { - proxy->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM)); - - object_property_add_child(OBJECT(pci_dev), - "default-backend", - OBJECT(proxy->rng.default_backend), - NULL); - - object_property_set_link(OBJECT(pci_dev), - OBJECT(proxy->rng.default_backend), - "rng", NULL); - } - - vdev = virtio_rng_init(&pci_dev->qdev, &proxy->rng); - if (!vdev) { - return -1; - } - virtio_init_pci(proxy, vdev); - return 0; -} - -static void virtio_rng_exit_pci(PCIDevice *pci_dev) -{ - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); - - virtio_pci_stop_ioeventfd(proxy); - virtio_rng_exit(proxy->vdev); - virtio_exit_pci(pci_dev); -} - -static void virtio_rng_initfn(Object *obj) -{ - PCIDevice *pci_dev = PCI_DEVICE(obj); - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); - - object_property_add_link(obj, "rng", TYPE_RNG_BACKEND, - (Object **)&proxy->rng.rng, NULL); -} - -static Property virtio_rng_properties[] = { - DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), - DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng), - DEFINE_PROP_END_OF_LIST(), -}; - -static void virtio_rng_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - - k->init = virtio_rng_init_pci; - k->exit = virtio_rng_exit_pci; - k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; - k->device_id = PCI_DEVICE_ID_VIRTIO_RNG; - k->revision = VIRTIO_PCI_ABI_VERSION; - k->class_id = PCI_CLASS_OTHERS; - dc->reset = virtio_pci_reset; - dc->props = virtio_rng_properties; -} - -static const TypeInfo virtio_rng_info = { - .name = "virtio-rng-pci", - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(VirtIOPCIProxy), - .instance_init = virtio_rng_initfn, - .class_init = virtio_rng_class_init, -}; - #ifdef CONFIG_VIRTFS static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev) { @@ -1136,11 +1054,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev) virtio_exit_pci(pci_dev); } -/* - * This will be renamed virtio_pci_reset at the end of the series. - * virtio_pci_reset is still in use at this moment. - */ -static void virtio_pci_rst(DeviceState *qdev) +static void virtio_pci_reset(DeviceState *qdev) { VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev); VirtioBusState *bus = VIRTIO_BUS(&proxy->bus); @@ -1160,7 +1074,7 @@ static void virtio_pci_class_init(ObjectClass *klass, void *data) k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; k->revision = VIRTIO_PCI_ABI_VERSION; k->class_id = PCI_CLASS_OTHERS; - dc->reset = virtio_pci_rst; + dc->reset = virtio_pci_reset; } static const TypeInfo virtio_pci_info = { @@ -1456,6 +1370,64 @@ static const TypeInfo virtio_net_pci_info = { .class_init = virtio_net_pci_class_init, }; +/* virtio-rng-pci */ + +static Property virtio_rng_pci_properties[] = { + DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), + DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORngPCI, vdev.conf), + DEFINE_PROP_END_OF_LIST(), +}; + +static int virtio_rng_pci_init(VirtIOPCIProxy *vpci_dev) +{ + VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&vrng->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + if (qdev_init(vdev) < 0) { + return -1; + } + + object_property_set_link(OBJECT(vrng), + OBJECT(vrng->vdev.conf.default_backend), "rng", + NULL); + + return 0; +} + +static void virtio_rng_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + + k->init = virtio_rng_pci_init; + dc->props = virtio_rng_pci_properties; + + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG; + pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id = PCI_CLASS_OTHERS; +} + +static void virtio_rng_initfn(Object *obj) +{ + VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj); + object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG); + object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); + object_property_add_link(obj, "rng", TYPE_RNG_BACKEND, + (Object **)&dev->vdev.conf.rng, NULL); + +} + +static const TypeInfo virtio_rng_pci_info = { + .name = TYPE_VIRTIO_RNG_PCI, + .parent = TYPE_VIRTIO_PCI, + .instance_size = sizeof(VirtIORngPCI), + .instance_init = virtio_rng_initfn, + .class_init = virtio_rng_pci_class_init, +}; + /* virtio-pci-bus */ void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev) @@ -1494,7 +1466,7 @@ static const TypeInfo virtio_pci_bus_info = { static void virtio_pci_register_types(void) { - type_register_static(&virtio_rng_info); + type_register_static(&virtio_rng_pci_info); type_register_static(&virtio_pci_bus_info); type_register_static(&virtio_pci_info); #ifdef CONFIG_VIRTFS diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 6f7116e..44f2fb3 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -34,6 +34,7 @@ typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; typedef struct VirtIOSerialPCI VirtIOSerialPCI; typedef struct VirtIONetPCI VirtIONetPCI; +typedef struct VirtIORngPCI VirtIORngPCI; /* virtio-pci-bus */ @@ -83,7 +84,6 @@ struct VirtIOPCIProxy { uint32_t class_code; uint32_t nvectors; uint32_t host_features; - VirtIORNGConf rng; bool ioeventfd_disabled; bool ioeventfd_started; VirtIOIRQFD *vector_irqfd; @@ -170,6 +170,18 @@ struct VirtIONetPCI { VirtIONet vdev; }; +/* + * virtio-rng-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci" +#define VIRTIO_RNG_PCI(obj) \ + OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI) + +struct VirtIORngPCI { + VirtIOPCIProxy parent_obj; + VirtIORNG vdev; +}; + void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev); void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);