Patchwork [09/14] qdev: connect some links and move type to object

login
register
mail settings
Submitter Anthony Liguori
Date April 18, 2012, 8:56 p.m.
Message ID <1334782613-5421-10-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/153600/
State New
Headers show

Comments

Anthony Liguori - April 18, 2012, 8:56 p.m.
This makes sysbus part of the root hierarchy and all busses children of their
respective parent DeviceState.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/qdev.c    |   11 +++++------
 qom/object.c |   12 ++++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)
Andreas Färber - April 18, 2012, 9:25 p.m.
Am 18.04.2012 22:56, schrieb Anthony Liguori:
> This makes sysbus part of the root hierarchy and all busses children of their
> respective parent DeviceState.
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  hw/qdev.c    |   11 +++++------
>  qom/object.c |   12 ++++++++++++
>  2 files changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 26e6f09..b5eef22 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus, const char *typename,
>      if (parent) {
>          QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>          parent->num_child_bus++;
> +        object_property_add_child(OBJECT(parent), bus->name, OBJECT(bus), NULL);
>      } else if (bus != main_system_bus) {
>          /* TODO: once all bus devices are qdevified,
>             only reset handler for main_system_bus should be registered here. */
> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>      /* assign main_system_bus before qbus_create_inplace()
>       * in order to make "if (bus != main_system_bus)" work */
>      main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL, "main-system-bus");
> +    object_property_add_child(object_get_root(), "sysbus",
> +                              OBJECT(main_system_bus), NULL);

So this is adding /sysbus. Shouldn't this rather go into
/unassigned/sysbus?

>  }
>  
>  void qbus_free(BusState *bus)
> @@ -537,11 +540,6 @@ char *qdev_get_dev_path(DeviceState *dev)
>      return NULL;
>  }
>  
> -static char *qdev_get_type(Object *obj, Error **errp)
> -{
> -    return g_strdup(object_get_typename(obj));
> -}
> -
>  /**
>   * Legacy property handling
>   */
> @@ -657,7 +655,8 @@ static void device_initfn(Object *obj)
>  
>      qdev_add_properties(dev, dc->props);
>  
> -    object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
> +    object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
> +                             (Object **)&dev->parent_bus, NULL);
>  }
>  
>  /* Unlink device from bus and free the structure.  */
> diff --git a/qom/object.c b/qom/object.c
> index 94928c5..0268f2a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -256,12 +256,24 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
>      obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
>  }
>  
> +static char *object_get_typename_dup(Object *obj, Error **errp)
> +{
> +    return g_strdup(object_get_typename(obj));
> +}
> +
> +static void object_base_init(Object *obj)
> +{
> +    object_property_add_str(obj, "type", object_get_typename_dup, NULL, NULL);
> +}
> +
>  static void object_init_with_type(Object *obj, TypeImpl *ti)
>  {
>      int i;
>  
>      if (type_has_parent(ti)) {
>          object_init_with_type(obj, type_get_parent(ti));
> +    } else {
> +        object_base_init(obj);
>      }
>  
>      for (i = 0; i < ti->num_interfaces; i++) {

The move of the "type" property was a standalone patch in Paolo's series
already, so I'd suggest to prepend that here for deduplification.

Andreas
Anthony Liguori - April 18, 2012, 10:38 p.m.
On 04/18/2012 04:25 PM, Andreas Färber wrote:
> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>> This makes sysbus part of the root hierarchy and all busses children of their
>> respective parent DeviceState.
>>
>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>> ---
>>   hw/qdev.c    |   11 +++++------
>>   qom/object.c |   12 ++++++++++++
>>   2 files changed, 17 insertions(+), 6 deletions(-)
>>
>> diff --git a/hw/qdev.c b/hw/qdev.c
>> index 26e6f09..b5eef22 100644
>> --- a/hw/qdev.c
>> +++ b/hw/qdev.c
>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus, const char *typename,
>>       if (parent) {
>>           QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>           parent->num_child_bus++;
>> +        object_property_add_child(OBJECT(parent), bus->name, OBJECT(bus), NULL);
>>       } else if (bus != main_system_bus) {
>>           /* TODO: once all bus devices are qdevified,
>>              only reset handler for main_system_bus should be registered here. */
>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>       /* assign main_system_bus before qbus_create_inplace()
>>        * in order to make "if (bus != main_system_bus)" work */
>>       main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL, "main-system-bus");
>> +    object_property_add_child(object_get_root(), "sysbus",
>> +                              OBJECT(main_system_bus), NULL);
>
> So this is adding /sysbus. Shouldn't this rather go into
> /unassigned/sysbus?

What would sysbus be assigned too?  I think sysbus is a really special case and 
belongs in the /root directory.

FWIW, for 1.2, I'd like to eliminate sysbus for the pc machine...

>
>>   }
>>
>>   void qbus_free(BusState *bus)
>> @@ -537,11 +540,6 @@ char *qdev_get_dev_path(DeviceState *dev)
>>       return NULL;
>>   }
>>
>> -static char *qdev_get_type(Object *obj, Error **errp)
>> -{
>> -    return g_strdup(object_get_typename(obj));
>> -}
>> -
>>   /**
>>    * Legacy property handling
>>    */
>> @@ -657,7 +655,8 @@ static void device_initfn(Object *obj)
>>
>>       qdev_add_properties(dev, dc->props);
>>
>> -    object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
>> +    object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
>> +                             (Object **)&dev->parent_bus, NULL);
>>   }
>>
>>   /* Unlink device from bus and free the structure.  */
>> diff --git a/qom/object.c b/qom/object.c
>> index 94928c5..0268f2a 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -256,12 +256,24 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
>>       obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
>>   }
>>
>> +static char *object_get_typename_dup(Object *obj, Error **errp)
>> +{
>> +    return g_strdup(object_get_typename(obj));
>> +}
>> +
>> +static void object_base_init(Object *obj)
>> +{
>> +    object_property_add_str(obj, "type", object_get_typename_dup, NULL, NULL);
>> +}
>> +
>>   static void object_init_with_type(Object *obj, TypeImpl *ti)
>>   {
>>       int i;
>>
>>       if (type_has_parent(ti)) {
>>           object_init_with_type(obj, type_get_parent(ti));
>> +    } else {
>> +        object_base_init(obj);
>>       }
>>
>>       for (i = 0; i<  ti->num_interfaces; i++) {
>
> The move of the "type" property was a standalone patch in Paolo's series
> already, so I'd suggest to prepend that here for deduplification.

Ack.

Regards,

Anthony Liguori

>
> Andreas
>
Igor Mammedov - April 19, 2012, 8:19 a.m.
On 04/19/2012 12:38 AM, Anthony Liguori wrote:
> On 04/18/2012 04:25 PM, Andreas Färber wrote:
>> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>>> This makes sysbus part of the root hierarchy and all busses children of their
>>> respective parent DeviceState.
>>>
>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>> ---
>>> hw/qdev.c | 11 +++++------
>>> qom/object.c | 12 ++++++++++++
>>> 2 files changed, 17 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/hw/qdev.c b/hw/qdev.c
>>> index 26e6f09..b5eef22 100644
>>> --- a/hw/qdev.c
>>> +++ b/hw/qdev.c
>>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus, const char *typename,
>>> if (parent) {
>>> QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>> parent->num_child_bus++;
>>> + object_property_add_child(OBJECT(parent), bus->name, OBJECT(bus), NULL);
>>> } else if (bus != main_system_bus) {
>>> /* TODO: once all bus devices are qdevified,
>>> only reset handler for main_system_bus should be registered here. */
>>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>> /* assign main_system_bus before qbus_create_inplace()
>>> * in order to make "if (bus != main_system_bus)" work */
>>> main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL, "main-system-bus");
>>> + object_property_add_child(object_get_root(), "sysbus",
>>> + OBJECT(main_system_bus), NULL);
>>
>> So this is adding /sysbus. Shouldn't this rather go into
>> /unassigned/sysbus?
>
> What would sysbus be assigned too? I think sysbus is a really special case and belongs in the /root directory.
but why it should go into / and not under /machine?

>
> FWIW, for 1.2, I'd like to eliminate sysbus for the pc machine...
>
>>
>>> }
>>>
>>> void qbus_free(BusState *bus)
>>> @@ -537,11 +540,6 @@ char *qdev_get_dev_path(DeviceState *dev)
>>> return NULL;
>>> }
>>>
>>> -static char *qdev_get_type(Object *obj, Error **errp)
>>> -{
>>> - return g_strdup(object_get_typename(obj));
>>> -}
>>> -
>>> /**
>>> * Legacy property handling
>>> */
>>> @@ -657,7 +655,8 @@ static void device_initfn(Object *obj)
>>>
>>> qdev_add_properties(dev, dc->props);
>>>
>>> - object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
>>> + object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
>>> + (Object **)&dev->parent_bus, NULL);
>>> }
>>>
>>> /* Unlink device from bus and free the structure. */
>>> diff --git a/qom/object.c b/qom/object.c
>>> index 94928c5..0268f2a 100644
>>> --- a/qom/object.c
>>> +++ b/qom/object.c
>>> @@ -256,12 +256,24 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
>>> obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
>>> }
>>>
>>> +static char *object_get_typename_dup(Object *obj, Error **errp)
>>> +{
>>> + return g_strdup(object_get_typename(obj));
>>> +}
>>> +
>>> +static void object_base_init(Object *obj)
>>> +{
>>> + object_property_add_str(obj, "type", object_get_typename_dup, NULL, NULL);
>>> +}
>>> +
>>> static void object_init_with_type(Object *obj, TypeImpl *ti)
>>> {
>>> int i;
>>>
>>> if (type_has_parent(ti)) {
>>> object_init_with_type(obj, type_get_parent(ti));
>>> + } else {
>>> + object_base_init(obj);
>>> }
>>>
>>> for (i = 0; i< ti->num_interfaces; i++) {
>>
>> The move of the "type" property was a standalone patch in Paolo's series
>> already, so I'd suggest to prepend that here for deduplification.
>
> Ack.
>
> Regards,
>
> Anthony Liguori
>
>>
>> Andreas
>>
>
>
Andreas Färber - April 19, 2012, 2:46 p.m.
Am 19.04.2012 00:38, schrieb Anthony Liguori:
> On 04/18/2012 04:25 PM, Andreas Färber wrote:
>> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>>> This makes sysbus part of the root hierarchy and all busses children
>>> of their
>>> respective parent DeviceState.
>>>
>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>> ---
>>>   hw/qdev.c    |   11 +++++------
>>>   qom/object.c |   12 ++++++++++++
>>>   2 files changed, 17 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/hw/qdev.c b/hw/qdev.c
>>> index 26e6f09..b5eef22 100644
>>> --- a/hw/qdev.c
>>> +++ b/hw/qdev.c
>>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus,
>>> const char *typename,
>>>       if (parent) {
>>>           QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>>           parent->num_child_bus++;
>>> +        object_property_add_child(OBJECT(parent), bus->name,
>>> OBJECT(bus), NULL);
>>>       } else if (bus != main_system_bus) {
>>>           /* TODO: once all bus devices are qdevified,
>>>              only reset handler for main_system_bus should be
>>> registered here. */
>>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>>       /* assign main_system_bus before qbus_create_inplace()
>>>        * in order to make "if (bus != main_system_bus)" work */
>>>       main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL,
>>> "main-system-bus");
>>> +    object_property_add_child(object_get_root(), "sysbus",
>>> +                              OBJECT(main_system_bus), NULL);
>>
>> So this is adding /sysbus. Shouldn't this rather go into
>> /unassigned/sysbus?
> 
> What would sysbus be assigned too?  I think sysbus is a really special
> case and belongs in the /root directory.

I suggested /unassigned because of no explicit parenting. Either the
unstable /unassigned tree or qdev_get_machine() for the real device
hierarchy. It's a device bus so it should be in one of the device
containers, not form yet a new root node.
All devices trace back to some SysBus device currently (e.g., PReP PCI
host controller is-a SysBusDevice, has-a PCIBus has-a child<PCIDevice>
i82378 that in turn has-a ISABus etc. etc.), so if we argue that sysbus
were special and needs to be in /, then *all* devices will end up in
that special location.

Just wondering, can a node have two parents? If you add "child[%d]"
nodes to the busses and we then add i440fx explicitly somewhere, like we
do, will that remove it from the bus' child[] list or will we have it in
both locations with an indeterministic canonical path?

Andreas
Paolo Bonzini - April 19, 2012, 2:49 p.m.
Il 19/04/2012 16:46, Andreas Färber ha scritto:
> I suggested /unassigned because of no explicit parenting. Either the
> unstable /unassigned tree

There is /machine/unattached, not /unattached.

> or qdev_get_machine() for the real device
> hierarchy. It's a device bus so it should be in one of the device
> containers, not form yet a new root node.
> All devices trace back to some SysBus device currently (e.g., PReP PCI
> host controller is-a SysBusDevice, has-a PCIBus has-a child<PCIDevice>
> i82378 that in turn has-a ISABus etc. etc.), so if we argue that sysbus
> were special and needs to be in /, then *all* devices will end up in
> that special location.

But not as their canonical path.

Paolo
Anthony Liguori - April 19, 2012, 2:53 p.m.
On 04/19/2012 09:46 AM, Andreas Färber wrote:
> Am 19.04.2012 00:38, schrieb Anthony Liguori:
>> On 04/18/2012 04:25 PM, Andreas Färber wrote:
>>> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>>>> This makes sysbus part of the root hierarchy and all busses children
>>>> of their
>>>> respective parent DeviceState.
>>>>
>>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>>> ---
>>>>    hw/qdev.c    |   11 +++++------
>>>>    qom/object.c |   12 ++++++++++++
>>>>    2 files changed, 17 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/hw/qdev.c b/hw/qdev.c
>>>> index 26e6f09..b5eef22 100644
>>>> --- a/hw/qdev.c
>>>> +++ b/hw/qdev.c
>>>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus,
>>>> const char *typename,
>>>>        if (parent) {
>>>>            QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>>>            parent->num_child_bus++;
>>>> +        object_property_add_child(OBJECT(parent), bus->name,
>>>> OBJECT(bus), NULL);
>>>>        } else if (bus != main_system_bus) {
>>>>            /* TODO: once all bus devices are qdevified,
>>>>               only reset handler for main_system_bus should be
>>>> registered here. */
>>>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>>>        /* assign main_system_bus before qbus_create_inplace()
>>>>         * in order to make "if (bus != main_system_bus)" work */
>>>>        main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL,
>>>> "main-system-bus");
>>>> +    object_property_add_child(object_get_root(), "sysbus",
>>>> +                              OBJECT(main_system_bus), NULL);
>>>
>>> So this is adding /sysbus. Shouldn't this rather go into
>>> /unassigned/sysbus?
>>
>> What would sysbus be assigned too?  I think sysbus is a really special
>> case and belongs in the /root directory.
>
> I suggested /unassigned because of no explicit parenting.

Yes, but I view /machine/unattached as a TODO list.  I'd like to completely 
eliminate that hierarchy for PC in 1.2.

But if we stick sysbus in there, it needs to exist forever because there's no 
right place for sysbus to exist.

Maybe we can do something like make i440fx has-a sysbus?  I'm not sure if that 
would break anything but I assume it's a fixable problem.

> Either the
> unstable /unassigned tree or qdev_get_machine() for the real device
> hierarchy. It's a device bus so it should be in one of the device
> containers, not form yet a new root node.
> All devices trace back to some SysBus device currently (e.g., PReP PCI
> host controller is-a SysBusDevice, has-a PCIBus has-a child<PCIDevice>
> i82378 that in turn has-a ISABus etc. etc.), so if we argue that sysbus
> were special and needs to be in /, then *all* devices will end up in
> that special location.
>
> Just wondering, can a node have two parents?

'parent_bus' is just a link.  I'd like to refactor parent_bus out of DeviceState 
and into the appropriate subclasses so that we can introduce stronger typing.

You could certainly have a 'second_parent_bus' link too if you so desired. 
There's really nothing special about it.

> If you add "child[%d]"
> nodes to the busses and we then add i440fx explicitly somewhere, like we
> do, will that remove it from the bus' child[] list or will we have it in
> both locations with an indeterministic canonical path?

The 'child[%d]' properties are links so they don't factor into the canonical 
path.  IOW, the canonical path has nothing to do with the qbus hierarchy.

Regards,

Anthony Liguori

>
> Andreas
>
Peter Maydell - April 19, 2012, 3:05 p.m.
On 19 April 2012 15:53, Anthony Liguori <anthony@codemonkey.ws> wrote:
> Yes, but I view /machine/unattached as a TODO list.  I'd like to completely
> eliminate that hierarchy for PC in 1.2.
>
> But if we stick sysbus in there, it needs to exist forever because there's
> no right place for sysbus to exist.

...well, in the medium term I think sysbus should go away completely.
So in that sense it's entirely reasonable to have it be in your
TODO list :-)

-- PMM
Andreas Färber - April 19, 2012, 3:06 p.m.
Am 19.04.2012 16:53, schrieb Anthony Liguori:
> On 04/19/2012 09:46 AM, Andreas Färber wrote:
>> Am 19.04.2012 00:38, schrieb Anthony Liguori:
>>> On 04/18/2012 04:25 PM, Andreas Färber wrote:
>>>> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>>>>> This makes sysbus part of the root hierarchy and all busses children
>>>>> of their
>>>>> respective parent DeviceState.
>>>>>
>>>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>>>> ---
>>>>>    hw/qdev.c    |   11 +++++------
>>>>>    qom/object.c |   12 ++++++++++++
>>>>>    2 files changed, 17 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/hw/qdev.c b/hw/qdev.c
>>>>> index 26e6f09..b5eef22 100644
>>>>> --- a/hw/qdev.c
>>>>> +++ b/hw/qdev.c
>>>>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus,
>>>>> const char *typename,
>>>>>        if (parent) {
>>>>>            QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>>>>            parent->num_child_bus++;
>>>>> +        object_property_add_child(OBJECT(parent), bus->name,
>>>>> OBJECT(bus), NULL);
>>>>>        } else if (bus != main_system_bus) {
>>>>>            /* TODO: once all bus devices are qdevified,
>>>>>               only reset handler for main_system_bus should be
>>>>> registered here. */
>>>>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>>>>        /* assign main_system_bus before qbus_create_inplace()
>>>>>         * in order to make "if (bus != main_system_bus)" work */
>>>>>        main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL,
>>>>> "main-system-bus");
>>>>> +    object_property_add_child(object_get_root(), "sysbus",
>>>>> +                              OBJECT(main_system_bus), NULL);
>>>>
>>>> So this is adding /sysbus. Shouldn't this rather go into
>>>> /unassigned/sysbus?
>>>
>>> What would sysbus be assigned too?  I think sysbus is a really special
>>> case and belongs in the /root directory.
>>
>> I suggested [qdev_get_machine()]/unassigned because of no explicit parenting.
> 
> Yes, but I view /machine/unattached as a TODO list.  I'd like to
> completely eliminate that hierarchy for PC in 1.2.
> 
> But if we stick sysbus in there, it needs to exist forever because
> there's no right place for sysbus to exist.

I thought SysBus would go away for 1.2 as well? AFAIU SysBus has no real
bus state and is just a container for devices because qdev requires
devices to be attached to a bus. SysBusDevices could then become direct
childs of /machine, and we'd need no special sysbus node at all long-term.

Andreas
Anthony Liguori - April 19, 2012, 3:39 p.m.
On 04/19/2012 10:06 AM, Andreas Färber wrote:
> Am 19.04.2012 16:53, schrieb Anthony Liguori:
>> On 04/19/2012 09:46 AM, Andreas Färber wrote:
>>> Am 19.04.2012 00:38, schrieb Anthony Liguori:
>>>> On 04/18/2012 04:25 PM, Andreas Färber wrote:
>>>>> Am 18.04.2012 22:56, schrieb Anthony Liguori:
>>>>>> This makes sysbus part of the root hierarchy and all busses children
>>>>>> of their
>>>>>> respective parent DeviceState.
>>>>>>
>>>>>> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
>>>>>> ---
>>>>>>     hw/qdev.c    |   11 +++++------
>>>>>>     qom/object.c |   12 ++++++++++++
>>>>>>     2 files changed, 17 insertions(+), 6 deletions(-)
>>>>>>
>>>>>> diff --git a/hw/qdev.c b/hw/qdev.c
>>>>>> index 26e6f09..b5eef22 100644
>>>>>> --- a/hw/qdev.c
>>>>>> +++ b/hw/qdev.c
>>>>>> @@ -427,6 +427,7 @@ static void do_qbus_create_inplace(BusState *bus,
>>>>>> const char *typename,
>>>>>>         if (parent) {
>>>>>>             QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
>>>>>>             parent->num_child_bus++;
>>>>>> +        object_property_add_child(OBJECT(parent), bus->name,
>>>>>> OBJECT(bus), NULL);
>>>>>>         } else if (bus != main_system_bus) {
>>>>>>             /* TODO: once all bus devices are qdevified,
>>>>>>                only reset handler for main_system_bus should be
>>>>>> registered here. */
>>>>>> @@ -456,6 +457,8 @@ static void main_system_bus_create(void)
>>>>>>         /* assign main_system_bus before qbus_create_inplace()
>>>>>>          * in order to make "if (bus != main_system_bus)" work */
>>>>>>         main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL,
>>>>>> "main-system-bus");
>>>>>> +    object_property_add_child(object_get_root(), "sysbus",
>>>>>> +                              OBJECT(main_system_bus), NULL);
>>>>>
>>>>> So this is adding /sysbus. Shouldn't this rather go into
>>>>> /unassigned/sysbus?
>>>>
>>>> What would sysbus be assigned too?  I think sysbus is a really special
>>>> case and belongs in the /root directory.
>>>
>>> I suggested [qdev_get_machine()]/unassigned because of no explicit parenting.
>>
>> Yes, but I view /machine/unattached as a TODO list.  I'd like to
>> completely eliminate that hierarchy for PC in 1.2.
>>
>> But if we stick sysbus in there, it needs to exist forever because
>> there's no right place for sysbus to exist.
>
> I thought SysBus would go away for 1.2 as well?

For PC devices...

But yeah, okay, as long as we all agree on nuking SysBus in the medium term, 
I'll change the patch to put it in /machine/unattached.

Regards,

Anthony Liguori

  AFAIU SysBus has no real
> bus state and is just a container for devices because qdev requires
> devices to be attached to a bus. SysBusDevices could then become direct
> childs of /machine, and we'd need no special sysbus node at all long-term.
>
> Andreas
>

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 26e6f09..b5eef22 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -427,6 +427,7 @@  static void do_qbus_create_inplace(BusState *bus, const char *typename,
     if (parent) {
         QLIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
         parent->num_child_bus++;
+        object_property_add_child(OBJECT(parent), bus->name, OBJECT(bus), NULL);
     } else if (bus != main_system_bus) {
         /* TODO: once all bus devices are qdevified,
            only reset handler for main_system_bus should be registered here. */
@@ -456,6 +457,8 @@  static void main_system_bus_create(void)
     /* assign main_system_bus before qbus_create_inplace()
      * in order to make "if (bus != main_system_bus)" work */
     main_system_bus = qbus_create(TYPE_SYSTEM_BUS, NULL, "main-system-bus");
+    object_property_add_child(object_get_root(), "sysbus",
+                              OBJECT(main_system_bus), NULL);
 }
 
 void qbus_free(BusState *bus)
@@ -537,11 +540,6 @@  char *qdev_get_dev_path(DeviceState *dev)
     return NULL;
 }
 
-static char *qdev_get_type(Object *obj, Error **errp)
-{
-    return g_strdup(object_get_typename(obj));
-}
-
 /**
  * Legacy property handling
  */
@@ -657,7 +655,8 @@  static void device_initfn(Object *obj)
 
     qdev_add_properties(dev, dc->props);
 
-    object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
+    object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
+                             (Object **)&dev->parent_bus, NULL);
 }
 
 /* Unlink device from bus and free the structure.  */
diff --git a/qom/object.c b/qom/object.c
index 94928c5..0268f2a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -256,12 +256,24 @@  static void object_interface_init(Object *obj, InterfaceImpl *iface)
     obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
 }
 
+static char *object_get_typename_dup(Object *obj, Error **errp)
+{
+    return g_strdup(object_get_typename(obj));
+}
+
+static void object_base_init(Object *obj)
+{
+    object_property_add_str(obj, "type", object_get_typename_dup, NULL, NULL);
+}
+
 static void object_init_with_type(Object *obj, TypeImpl *ti)
 {
     int i;
 
     if (type_has_parent(ti)) {
         object_init_with_type(obj, type_get_parent(ti));
+    } else {
+        object_base_init(obj);
     }
 
     for (i = 0; i < ti->num_interfaces; i++) {