From patchwork Tue Jul 10 06:16:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 170053 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 5F3142C0886 for ; Tue, 10 Jul 2012 16:16:54 +1000 (EST) Received: from localhost ([::1]:58041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTki-0007ET-3X for incoming@patchwork.ozlabs.org; Tue, 10 Jul 2012 02:16:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTkP-0006vo-SM for qemu-devel@nongnu.org; Tue, 10 Jul 2012 02:16:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoTkL-0001I7-4Q for qemu-devel@nongnu.org; Tue, 10 Jul 2012 02:16:33 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:37538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTkK-0001Hd-Rh for qemu-devel@nongnu.org; Tue, 10 Jul 2012 02:16:29 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so22057070pbb.4 for ; Mon, 09 Jul 2012 23:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=elVFN59Pr7zgGRdVgtJrluldt9rIbL7FjSbz0L6fjh8=; b=rPhcKnRJ2WiYv8/IP7jZlOfYDpdv+Px3oC4gnCzA5n1cC+f9D2EyOaAhSHvSEgIwIP x4g0mboyhmkTuiiFhEAoSitNiBBGVDF5s4d2N78pApjTADmdLND/t4uRYwDpgvEUrrMI EdKP/EWq/BG2QgeVZ+SBctOddFWNg/JT2ewkaOom5CiItFHuKRafbMYbquybK67XYS6Z jwEzytEB77/D1Ba0lLCAHoxQ4OnfGwdGMDy8SPAzTyZsuAgbfjlouPGkU68NsI3UfEq0 oX0H+yr2v2b4FanVvnvIBtdCSbaJCCz8SgpOcG1XRkMlbKH+WBzIsLqSbOtUw5cTrmRp dt7Q== Received: by 10.68.195.167 with SMTP id if7mr66531572pbc.16.1341900987955; Mon, 09 Jul 2012 23:16:27 -0700 (PDT) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPS id rg9sm29214942pbc.67.2012.07.09.23.16.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 23:16:27 -0700 (PDT) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2012 14:16:03 +0800 Message-Id: <1341900967-4344-2-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1341900967-4344-1-git-send-email-qemulist@gmail.com> References: <1341900967-4344-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Blue Swirl , Jan Kiszka , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type) 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 DeviceState can be created as kid of DeviceState/CPUState, not neccesary attached to bus. This will be helpful to simulate the real hardware submodule which sits inside package. Signed-off-by: Liu Ping Fan --- hw/qdev.c | 28 ++++++++++++++++++++++++++++ hw/qdev.h | 1 + 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index af54467..d2100a1 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -26,6 +26,7 @@ this API directly. */ #include "net.h" +#include "qemu/cpu.h" #include "qdev.h" #include "sysemu.h" #include "error.h" @@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char *type) return dev; } +DeviceState *qdev_create_kid(Object *parent, const char *type) +{ + DeviceState *dev; + assert(parent); + + if (object_class_by_name(type) == NULL) { + return NULL; + } + + if (object_is_type_str(parent, TYPE_BUS)) { + return qdev_create(BUS(parent), type); + } + + if (!object_is_type_str(parent, TYPE_DEVICE) + || !object_is_type_str(parent, TYPE_CPU)) { + return NULL; + } + + dev = DEVICE(object_new(type)); + if (!dev) { + return NULL; + } + object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL); + + return dev; +} + /* Initialize a device. Device properties should be set before calling this function. IRQs and MMIO regions should be connected/mapped after calling this function. diff --git a/hw/qdev.h b/hw/qdev.h index f4683dc..aecc69e 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -154,6 +154,7 @@ typedef struct GlobalProperty { DeviceState *qdev_create(BusState *bus, const char *name); DeviceState *qdev_try_create(BusState *bus, const char *name); +DeviceState *qdev_create_kid(Object *parent, const char *type); bool qdev_exists(const char *name); int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts);