* [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent
@ 2019-05-23 15:05 Peter Maydell
2019-05-24 15:55 ` Damien Hedde
2019-05-24 17:44 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2019-05-23 15:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Damien Hedde, Markus Armbruster
In commit 80376c3fc2c38fdd453 in 2010 we added a workaround for
some qbus buses not being connected to qdev devices -- if the
bus has no parent object then we register a reset function which
resets the bus on system reset (and unregister it when the
bus is unparented).
Nearly a decade later, we have now no buses in the tree which
are created with non-NULL parents, so we can remove the
workaround and instead just assert that if the bus has a NULL
parent then it is the main system bus.
(The absence of other parentless buses was confirmed by
code inspection of all the callsites of qbus_create() and
qbus_create_inplace() and cross-checked by 'make check'.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
v1->v2: clean up also the bus_unparent() code
---
hw/core/bus.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/hw/core/bus.c b/hw/core/bus.c
index e09843f6abe..b8839c7268d 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -96,10 +96,9 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
bus->parent->num_child_bus++;
object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL);
object_unref(OBJECT(bus));
- } else if (bus != sysbus_get_default()) {
- /* TODO: once all bus devices are qdevified,
- only reset handler for main_system_bus should be registered here. */
- qemu_register_reset(qbus_reset_all_fn, bus);
+ } else {
+ /* The only bus without a parent is the main system bus */
+ assert(bus == sysbus_get_default());
}
}
@@ -108,18 +107,16 @@ static void bus_unparent(Object *obj)
BusState *bus = BUS(obj);
BusChild *kid;
+ /* Only the main system bus has no parent, and that bus is never freed */
+ assert(bus->parent);
+
while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
DeviceState *dev = kid->child;
object_unparent(OBJECT(dev));
}
- if (bus->parent) {
- QLIST_REMOVE(bus, sibling);
- bus->parent->num_child_bus--;
- bus->parent = NULL;
- } else {
- assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
- qemu_unregister_reset(qbus_reset_all_fn, bus);
- }
+ QLIST_REMOVE(bus, sibling);
+ bus->parent->num_child_bus--;
+ bus->parent = NULL;
}
void qbus_create_inplace(void *bus, size_t size, const char *typename,
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent
2019-05-23 15:05 [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent Peter Maydell
@ 2019-05-24 15:55 ` Damien Hedde
2019-05-24 17:44 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Damien Hedde @ 2019-05-24 15:55 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Markus Armbruster
On 5/23/19 5:05 PM, Peter Maydell wrote:
> In commit 80376c3fc2c38fdd453 in 2010 we added a workaround for
> some qbus buses not being connected to qdev devices -- if the
> bus has no parent object then we register a reset function which
> resets the bus on system reset (and unregister it when the
> bus is unparented).
>
> Nearly a decade later, we have now no buses in the tree which
> are created with non-NULL parents, so we can remove the
> workaround and instead just assert that if the bus has a NULL
> parent then it is the main system bus.
>
> (The absence of other parentless buses was confirmed by
> code inspection of all the callsites of qbus_create() and
> qbus_create_inplace() and cross-checked by 'make check'.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
> v1->v2: clean up also the bus_unparent() code
> ---
> hw/core/bus.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/hw/core/bus.c b/hw/core/bus.c
> index e09843f6abe..b8839c7268d 100644
> --- a/hw/core/bus.c
> +++ b/hw/core/bus.c
> @@ -96,10 +96,9 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
> bus->parent->num_child_bus++;
> object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL);
> object_unref(OBJECT(bus));
> - } else if (bus != sysbus_get_default()) {
> - /* TODO: once all bus devices are qdevified,
> - only reset handler for main_system_bus should be registered here. */
> - qemu_register_reset(qbus_reset_all_fn, bus);
> + } else {
> + /* The only bus without a parent is the main system bus */
> + assert(bus == sysbus_get_default());
> }
> }
>
> @@ -108,18 +107,16 @@ static void bus_unparent(Object *obj)
> BusState *bus = BUS(obj);
> BusChild *kid;
>
> + /* Only the main system bus has no parent, and that bus is never freed */
> + assert(bus->parent);
> +
> while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
> DeviceState *dev = kid->child;
> object_unparent(OBJECT(dev));
> }
> - if (bus->parent) {
> - QLIST_REMOVE(bus, sibling);
> - bus->parent->num_child_bus--;
> - bus->parent = NULL;
> - } else {
> - assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
> - qemu_unregister_reset(qbus_reset_all_fn, bus);
> - }
> + QLIST_REMOVE(bus, sibling);
> + bus->parent->num_child_bus--;
> + bus->parent = NULL;
> }
>
> void qbus_create_inplace(void *bus, size_t size, const char *typename,
>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent
2019-05-23 15:05 [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent Peter Maydell
2019-05-24 15:55 ` Damien Hedde
@ 2019-05-24 17:44 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-05-24 17:44 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Damien Hedde, Markus Armbruster
On 5/23/19 5:05 PM, Peter Maydell wrote:
> In commit 80376c3fc2c38fdd453 in 2010 we added a workaround for
> some qbus buses not being connected to qdev devices -- if the
> bus has no parent object then we register a reset function which
> resets the bus on system reset (and unregister it when the
> bus is unparented).
>
> Nearly a decade later, we have now no buses in the tree which
> are created with non-NULL parents, so we can remove the
> workaround and instead just assert that if the bus has a NULL
> parent then it is the main system bus.
>
> (The absence of other parentless buses was confirmed by
> code inspection of all the callsites of qbus_create() and
> qbus_create_inplace() and cross-checked by 'make check'.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
> v1->v2: clean up also the bus_unparent() code
> ---
> hw/core/bus.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/hw/core/bus.c b/hw/core/bus.c
> index e09843f6abe..b8839c7268d 100644
> --- a/hw/core/bus.c
> +++ b/hw/core/bus.c
> @@ -96,10 +96,9 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
> bus->parent->num_child_bus++;
> object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL);
> object_unref(OBJECT(bus));
> - } else if (bus != sysbus_get_default()) {
> - /* TODO: once all bus devices are qdevified,
> - only reset handler for main_system_bus should be registered here. */
> - qemu_register_reset(qbus_reset_all_fn, bus);
> + } else {
> + /* The only bus without a parent is the main system bus */
> + assert(bus == sysbus_get_default());
> }
> }
>
> @@ -108,18 +107,16 @@ static void bus_unparent(Object *obj)
> BusState *bus = BUS(obj);
> BusChild *kid;
>
> + /* Only the main system bus has no parent, and that bus is never freed */
> + assert(bus->parent);
> +
> while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
> DeviceState *dev = kid->child;
> object_unparent(OBJECT(dev));
> }
> - if (bus->parent) {
> - QLIST_REMOVE(bus, sibling);
> - bus->parent->num_child_bus--;
> - bus->parent = NULL;
> - } else {
> - assert(bus != sysbus_get_default()); /* main_system_bus is never freed */
> - qemu_unregister_reset(qbus_reset_all_fn, bus);
> - }
> + QLIST_REMOVE(bus, sibling);
> + bus->parent->num_child_bus--;
> + bus->parent = NULL;
> }
>
> void qbus_create_inplace(void *bus, size_t size, const char *typename,
>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-24 17:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 15:05 [Qemu-devel] [PATCH v2] hw/core/bus.c: Only the main system bus can have no parent Peter Maydell
2019-05-24 15:55 ` Damien Hedde
2019-05-24 17:44 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.