From patchwork Wed Oct 31 22:00:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 196014 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 EEA5D2C00A4 for ; Thu, 1 Nov 2012 09:01:43 +1100 (EST) Received: from localhost ([::1]:60750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTgM2-000085-2V for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 18:01:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTgLh-0008Qg-5F for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:01:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTgLf-0005EN-TI for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:01:21 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:35291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTgLf-0005Dv-5b for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:01:19 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Nov 2012 03:31:17 +0530 Received: from d28relay02.in.ibm.com (9.184.220.59) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 1 Nov 2012 03:31:15 +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 q9VM1EYr19595492 for ; Thu, 1 Nov 2012 03:31:14 +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 qA13V590021469 for ; Thu, 1 Nov 2012 14:31:05 +1100 Received: from titi.austin.rr.com (sig-9-48-82-197.mts.ibm.com [9.48.82.197]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qA13UWFX019674; Thu, 1 Nov 2012 14:31:02 +1100 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2012 17:00:34 -0500 Message-Id: <1351720834-22805-9-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1351720834-22805-1-git-send-email-aliguori@us.ibm.com> References: <1351720834-22805-1-git-send-email-aliguori@us.ibm.com> x-cbid: 12103122-8256-0000-0000-000004D0353F X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: Amit Shah , Paolo Bonzini , Anthony Liguori , Andreas Faerber , "H. Peter Anvin" Subject: [Qemu-devel] [PATCH 8/8] 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 f90296d..71f4fb5 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -857,6 +857,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 7324d0a..f42d748 100644 --- a/hw/virtio-rng.h +++ b/hw/virtio-rng.h @@ -13,6 +13,7 @@ #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 @@ -21,6 +22,7 @@ struct VirtIORNGConf { RngBackend *rng; uint64_t max_bytes; uint32_t period_ms; + RndRandom *default_backend; }; #endif