From patchwork Fri Apr 11 06:34:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 338393 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F17A314008F for ; Fri, 11 Apr 2014 16:37:35 +1000 (EST) Received: from localhost ([::1]:56158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV5h-0007Rc-Up for incoming@patchwork.ozlabs.org; Fri, 11 Apr 2014 02:37:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV3O-0004ZH-SW for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:35:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYV3I-0007rp-KS for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:35:10 -0400 Received: from mail-pb0-x22e.google.com ([2607:f8b0:400e:c01::22e]:59181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV3I-0007p0-AJ for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:35:04 -0400 Received: by mail-pb0-f46.google.com with SMTP id rq2so4985595pbb.19 for ; Thu, 10 Apr 2014 23:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ctGPFifgEWDR97JscKsIdFSr6OHce4F2TDaBICMTNGs=; b=qmf+zcIjmkcpbiVJY9Sh8NPHPdO6Ch0lj+QrpVgPr3Q+HCVlvrcviEoh8J4A8/e4V6 7V4N2TSA1gAVJbvP5lT1jwJuD29ygTl8mLmfV4XfUPKauCf4VM/ys60qEFl2drnioPXu R8akDw+wB0986lVfxFpsytWrNSXi+TJAKv2BgjTwG/i5ciaAlA6gHoFSbzfuSQhrXnwH 6VUrWetUYpi/LL044DSKt/ExmqvOE2q06eUIKQy1G8864etuZ4cCTERv9+xV3jOW7kg9 VEgESqikZ1uw7OlQtdiJV/ykjzENZhoBfoUaboO1AL5M5ASfBZtBdvby8Dye9vI8BY92 IhXw== X-Received: by 10.66.155.102 with SMTP id vv6mr25114833pab.89.1397198103356; Thu, 10 Apr 2014 23:35:03 -0700 (PDT) Received: from localhost ([203.126.243.116]) by mx.google.com with ESMTPSA id qh2sm31218858pab.13.2014.04.10.23.35.01 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 10 Apr 2014 23:35:02 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Date: Fri, 11 Apr 2014 16:34:58 +1000 Message-Id: X-Mailer: git-send-email 1.9.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22e Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, eric.auger@linaro.org, kim.phillips@linaro.org, agraf@suse.de, armbru@redhat.com, edgar.iglesias@gmail.com, alistair.francis@xilinx.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 3/4] vl.c: Enable adding devices to the system bus 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 removes the old method to connect devices and replaces it with three calls to the three qdev-monitor functions added in the previous patch. This allows complete machines to be built via the command line as well as just attaching simple sysbus devices. Signed-off-by: Alistair Francis --- vl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index 9975e5a..809882c 100644 --- a/vl.c +++ b/vl.c @@ -97,6 +97,7 @@ int main(int argc, char **argv) #include "qemu-options.h" #include "qmp-commands.h" #include "qemu/main-loop.h" +#include "qemu/option_int.h" #ifdef CONFIG_VIRTFS #include "fsdev/qemu-fsdev.h" #endif @@ -2381,14 +2382,63 @@ static int device_help_func(QemuOpts *opts, void *opaque) return qdev_device_help(opts); } +static int device_add_func(QemuOpts *opts, void *opaque) +{ + DeviceState *dev; + + if (strcmp(qemu_opt_get(opts, "driver"), "memory") && + strcmp(qemu_opt_get(opts, "driver"), "cpu") && + opts->opaque == NULL) { + dev = qdev_device_add(opts); + if (!dev) { + return -1; + } + object_unref(OBJECT(dev)); + } + return 0; +} + +static int device_create_func(QemuOpts *opts, void *opaque) +{ + DeviceState *dev; + + dev = qdev_device_create(opts); + + return 0; +} + static int device_init_func(QemuOpts *opts, void *opaque) { DeviceState *dev; + QEMUMachineInitArgs *current_machine = (QEMUMachineInitArgs *) opaque; + DeviceState *intc = current_machine->intc; - dev = qdev_device_add(opts); - if (!dev) - return -1; - object_unref(OBJECT(dev)); + dev = qdev_device_init(opts, intc); + + if (dev && (dev->num_gpio_in > 32)) { + /* Store the Interupt Controller */ + current_machine->intc = dev; + } + + return 0; +} + +static int device_connect_func(QemuOpts *opts, void *opaque) +{ + DeviceState *dev; + QEMUMachineInitArgs *current_machine = (QEMUMachineInitArgs *) opaque; + DeviceState *intc = current_machine->intc; + + dev = qdev_device_connect(opts, intc); + + if (dev && (dev->num_gpio_in > 0)) { + /* Store the Interupt Controller */ + current_machine->intc = dev; + } + + if (dev) { + object_unref(OBJECT(dev)); + } return 0; } @@ -4377,11 +4427,21 @@ int main(int argc, char **argv, char **envp) .kernel_filename = kernel_filename, .kernel_cmdline = kernel_cmdline, .initrd_filename = initrd_filename, - .cpu_model = cpu_model }; + .cpu_model = cpu_model, + .intc = NULL }; current_machine->init_args = args; machine->init(¤t_machine->init_args); + /* Create devices */ + qemu_opts_foreach(qemu_find_opts("device"), device_create_func, NULL, 1); + /* Init devices */ + qemu_opts_foreach(qemu_find_opts("device"), device_init_func, + ¤t_machine->init_args, 1); + /* Init devices */ + qemu_opts_foreach(qemu_find_opts("device"), device_connect_func, + ¤t_machine->init_args, 1); + audio_init(); cpu_synchronize_all_post_init(); @@ -4395,8 +4455,10 @@ int main(int argc, char **argv, char **envp) } /* init generic devices */ - if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) + if (qemu_opts_foreach(qemu_find_opts("device"), device_add_func, + NULL, 1) != 0) { exit(1); + } net_check_clients();