[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] hw/sysbus.h: New sysbus_init_child() helper
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] hw/sysbus.h: New sysbus_init_child() helper function |
Date: |
Fri, 16 Feb 2018 14:40:54 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 02/16/2018 01:28 PM, Igor Mammedov wrote:
> On Fri, 16 Feb 2018 13:45:15 +0000
> Peter Maydell <address@hidden> wrote:
...
>> static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
>> static char *sysbus_get_fw_dev_path(DeviceState *dev);
>> @@ -372,6 +373,19 @@ BusState *sysbus_get_default(void)
>> return main_system_bus;
>> }
>>
>> +void sysbus_init_child(Object *parent, const char *childname,
>> + void *child, size_t childsize,
>> + const char *childtype)
>> +{
>
>
>> + object_initialize(child, childsize, childtype);
>> + /* error_abort is fine here because this can only fail for
>> + * programming-error reasons: child already parented, or
>> + * parent already has a child with the given name.
>> + */
>> + object_property_add_child(parent, childname, OBJECT(child),
>> &error_abort);
> It would be useful not only for sysbus devices.
> maybe we should extend object_initialize instead,
> something like this:
> void object_initialize(void *data, size_t size, const char *typename,
> Object *parent, const char *name)
> and set parent in it.
> git counts about 152 uses, so it would be tree wide change
> but still not too much.
we can keep object_initialize() when no parent,
and add object_initialize_child(, const char *childname, Object *parent)
'parent' last because all previous args are child-related.
>
>
>> + qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
> and then assuming we don't create sysbus devices, nor should be able to,
> which are not attached to sysbus_get_default() this one can go sysbus'
> instance_init()
good idea.
>
> then there won't be need for sysbus specific helper,
> inheritance will do the rest of the job.
>
>> +}
>> +
[Qemu-devel] [PATCH 2/2] hw/arm/bcm2835_peripherals: Use sysbus_init_child(), Peter Maydell, 2018/02/16