From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffBRi-0008MT-Jn for qemu-devel@nongnu.org; Mon, 16 Jul 2018 17:54:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffBRh-0006fN-Bk for qemu-devel@nongnu.org; Mon, 16 Jul 2018 17:54:18 -0400 MIME-Version: 1.0 In-Reply-To: <1531745974-17187-3-git-send-email-thuth@redhat.com> References: <1531745974-17187-1-git-send-email-thuth@redhat.com> <1531745974-17187-3-git-send-email-thuth@redhat.com> From: Alistair Francis Date: Mon, 16 Jul 2018 14:53:44 -0700 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [PATCH v3 02/17] hw/core/sysbus: Add a function for creating and attaching an object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: "qemu-devel@nongnu.org Developers" , Peter Maydell , Paolo Bonzini , Eduardo Habkost , Alistair Francis , Markus Armbruster , Subbaraya Sundeep , Beniamino Galvani , qemu-arm , "Edgar E. Iglesias" , =?UTF-8?Q?Andreas_F=C3=A4rber?= On Mon, Jul 16, 2018 at 5:59 AM, Thomas Huth wrote: > A lot of functions are initializing an object and attach it immediately > afterwards to the system bus. Provide a common function for this, which > also uses object_initialize_child() to make sure that the reference > counter is correctly initialized to 1 afterwards. > > Reviewed-by: Richard Henderson > Reviewed-by: Paolo Bonzini > Reviewed-by: Eduardo Habkost > Signed-off-by: Thomas Huth Reviewed-by: Alistair Francis Alistair > --- > hw/core/sysbus.c | 8 ++++++++ > include/hw/sysbus.h | 17 +++++++++++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c > index ecfb0cf..3c8e53b 100644 > --- a/hw/core/sysbus.c > +++ b/hw/core/sysbus.c > @@ -376,6 +376,14 @@ BusState *sysbus_get_default(void) > return main_system_bus; > } > > +void sysbus_init_child_obj(Object *parent, const char *childname, void *child, > + size_t childsize, const char *childtype) > +{ > + object_initialize_child(parent, childname, child, childsize, childtype, > + &error_abort, NULL); > + qdev_set_parent_bus(DEVICE(child), sysbus_get_default()); > +} > + > static void sysbus_register_types(void) > { > type_register_static(&system_bus_info); > diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h > index e88bb6d..0b59a3b 100644 > --- a/include/hw/sysbus.h > +++ b/include/hw/sysbus.h > @@ -96,6 +96,23 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr, > MemoryRegion *mem); > MemoryRegion *sysbus_address_space(SysBusDevice *dev); > > +/** > + * sysbus_init_child_obj: > + * @parent: The parent object > + * @childname: Used as name of the "child<>" property in the parent > + * @child: A pointer to the memory to be used for the object. > + * @childsize: The maximum size available at @child for the object. > + * @childtype: The name of the type of the object to instantiate. > + * > + * This function will initialize an object and attach it to the main system > + * bus. The memory for the object should have already been allocated. The > + * object will then be added as child to the given parent. The returned object > + * has a reference count of 1 (for the "child<...>" property from the parent), > + * so the object will be finalized automatically when the parent gets removed. > + */ > +void sysbus_init_child_obj(Object *parent, const char *childname, void *child, > + size_t childsize, const char *childtype); > + > /* Call func for every dynamically created sysbus device in the system */ > void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); > > -- > 1.8.3.1 > >