[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a quetion about sysbus_realize_and_unref function
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: a quetion about sysbus_realize_and_unref function |
Date: |
Mon, 18 Oct 2021 14:43:36 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 |
Hi,
On 10/18/21 14:01, Chan Kim wrote:
> Hi, list members,
>
> I see for example in hw/arm/virt.c, when it creates a device to attach
> to a system bus, it calls “sysbus_realize_and_unref(SYS_BUS_DEVICE(dev),
> &error_fatal);” function
>
> .
>
> static void create_its(VirtMachineState *vms)
>
> {
>
> const char *itsclass = its_class_name();
>
> DeviceState *dev;
>
>
>
> if (!itsclass) {
>
> /* Do nothing if not supported */
>
> return;
>
> }
>
>
>
> dev = qdev_new(itsclass);
>
>
>
> object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),
>
> &error_abort);
>
> sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>
> sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, vms->memmap[VIRT_GIC_ITS].base);
>
>
>
> fdt_add_its_gic_node(vms);
>
> vms->msi_controller = VIRT_MSI_CTRL_ITS;
>
> }
>
>
>
> The document says it decrements the reference counter and when the ref
> count is non zero, the object can’t be removed.
>
> Then why does it call sysbus_realize_and_unref function to reduce the
> ref count of the system bus(=parent object) of the device being create?
The qemu-devel@nongnu.org is better for developer questions.
Cc'ing Markus for:
commit 496a8525622d4ac5d276f76840dd30eddb73672d
Author: Markus Armbruster <armbru@redhat.com>
Date: Wed Jun 10 07:32:33 2020 +0200
sysbus: New sysbus_realize(), sysbus_realize_and_unref()
Sysbus devices almost always plug into the main system bus.
qdev_create() even has a convenience feature to make that easy:
a null bus argument gets replaced by the main system bus.
qdev_realize() and qdev_realize_and_unref() do the same.
We can do better. Provide convenience wrappers around
qdev_realize() and qdev_realize_and_unref() that don't take a
@bus argument. They always pass the main system bus.