From patchwork Fri Oct 26 17:21:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 194540 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 A59332C008B for ; Sat, 27 Oct 2012 04:21:59 +1100 (EST) Received: from localhost ([::1]:44640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRnbZ-0006ge-QB for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2012 13:21:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRnbO-0006gZ-CR for qemu-devel@nongnu.org; Fri, 26 Oct 2012 13:21:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRnbN-0005b4-2G for qemu-devel@nongnu.org; Fri, 26 Oct 2012 13:21:46 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:54717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRnbM-0005Zo-CI for qemu-devel@nongnu.org; Fri, 26 Oct 2012 13:21:44 -0400 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 26 Oct 2012 22:51:40 +0530 Received: from d28relay02.in.ibm.com (9.184.220.59) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 26 Oct 2012 22:51:39 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9QHLdRF39256272 for ; Fri, 26 Oct 2012 22:51:39 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9QMpUdI004306 for ; Sat, 27 Oct 2012 09:51:30 +1100 Received: from titi.austin.rr.com ([9.57.74.46]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q9QMpL7o003796; Sat, 27 Oct 2012 09:51:28 +1100 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2012 12:21:26 -0500 Message-Id: <1351272088-7942-3-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1351272088-7942-1-git-send-email-aliguori@us.ibm.com> References: <1351272088-7942-1-git-send-email-aliguori@us.ibm.com> x-cbid: 12102617-9574-0000-0000-0000050A4AC2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.6 Cc: Amit Shah , Paolo Bonzini , Anthony Liguori , Andreas Faerber Subject: [Qemu-devel] [PATCH 2/4] virtio-rng-pci: create a default backend if none exists 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 This allows you to specify: $ qemu -device virtio-rng-pci And things will Just Work with a reasonable default. Signed-off-by: Anthony Liguori --- hw/virtio-pci.c | 13 +++++++++++++ hw/virtio-rng.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 0dc2a06..cfdb779 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -885,6 +885,19 @@ 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; diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h index fbb0104..63ddb96 100644 --- a/hw/virtio-rng.h +++ b/hw/virtio-rng.h @@ -13,12 +13,14 @@ #define _QEMU_VIRTIO_RNG_H #include "qemu/rng.h" +#include "qemu/rng-random.h" /* The Virtio ID for the virtio rng device */ #define VIRTIO_ID_RNG 4 struct VirtIORNGConf { RngBackend *rng; + RndRandom *default_backend; }; #endif