qemu-e2k/hw/ppc
David Hildenbrand 07578b0ad6 qdev: Let the hotplug_handler_unplug() caller delete the device
When unplugging a device, at one point the device will be destroyed
via object_unparent(). This will, one the one hand, unrealize the
removed device hierarchy, and on the other hand, destroy/free the
device hierarchy.

When chaining hotplug handlers, we want to overwrite a bus hotplug
handler by the machine hotplug handler, to be able to perform
some part of the plug/unplug and to forward the calls to the bus hotplug
handler.

For now, the bus hotplug handler would trigger an object_unparent(), not
allowing us to perform some unplug action on a device after we forwarded
the call to the bus hotplug handler. The device would be gone at that
point.

machine_unplug_handler(dev)
    /* eventually do unplug stuff */
    bus_unplug_handler(dev)
    /* dev is gone, we can't do more unplug stuff */

So move the object_unparent() to the original caller of the unplug. For
now, keep the unrealize() at the original places of the
object_unparent(). For implicitly chained hotplug handlers (e.g. pc
code calling acpi hotplug handlers), the object_unparent() has to be
done by the outermost caller. So when calling hotplug_handler_unplug()
from inside an unplug handler, nothing is to be done.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> calls unrealize(dev)
        /* we can do more unplug stuff but device already unrealized */
    }
object_unparent(dev)

In the long run, every unplug action should be factored out of the
unrealize() function into the unplug handler (especially for PCI). Then
we can get rid of the additonal unrealize() calls and object_unparent()
will properly unrealize the device hierarchy after the device has been
unplugged.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> only unplugs, does not unrealize
        /* we can do more unplug stuff */
    }
object_unparent(dev) -> will unrealize

The original approach was suggested by Igor Mammedov for the PCI
part, but I extended it to all hotplug handlers. I consider this one
step into the right direction.

To summarize:
- object_unparent() on synchronous unplugs is done by common code
-- "Caller of hotplug_handler_unplug"
- object_unparent() on asynchronous unplugs ("unplug requests") has to
  be done manually
-- "Caller of hotplug_handler_unplug"

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20190228122849.4296-2-david@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-03-06 11:51:08 -03:00
..
e500-ccsr.h
e500.c elf: Add optional function ptr to load_elf() to parse ELF notes 2019-02-05 16:50:16 +01:00
e500.h
e500plat.c
fdt.c
mac_newworld.c hw/boards: Add a MachineState parameter to kvm_type callback 2019-03-05 15:55:09 +00:00
mac_oldworld.c hw/boards: Add a MachineState parameter to kvm_type callback 2019-03-05 15:55:09 +00:00
mac.h
Makefile.objs hw/ppc/Makefile.objs: Build all boards conditinally with CONFIG_* 2019-02-05 16:50:20 +01:00
mpc8544_guts.c
mpc8544ds.c
pnv_bmc.c
pnv_core.c
pnv_lpc.c
pnv_occ.c
pnv_psi.c hw/ppc: Use object_initialize_child for correct reference counting 2019-02-26 09:21:25 +11:00
pnv_xscom.c
pnv.c ppc/pnv: use IEC binary prefixes to represent sizes 2019-02-26 14:20:30 +11:00
ppc4xx_devs.c
ppc4xx_pci.c
ppc405_boards.c
ppc405_uc.c
ppc405.h
ppc440_bamboo.c elf: Add optional function ptr to load_elf() to parse ELF notes 2019-02-05 16:50:16 +01:00
ppc440_pcix.c
ppc440_uc.c
ppc440.h
ppc_booke.c
ppc.c target/ppc: Add POWER9 external interrupt model 2019-02-26 09:21:24 +11:00
ppce500_spin.c
prep_systemio.c
prep.c hw/ppc/prep: Drop useless inclusion of "hw/i386/pc.h" 2019-02-17 21:54:02 +11:00
rs6000_mc.c
sam460ex.c i2c: Split smbus into parts 2019-02-27 21:06:08 -06:00
spapr_caps.c
spapr_cpu_core.c
spapr_drc.c spapr: add hotplug hooks for PHB hotplug 2019-02-26 09:21:25 +11:00
spapr_events.c spapr_events: add support for phb hotplug events 2019-02-26 09:21:25 +11:00
spapr_hcall.c target/ppc: Rename PATB/PATBE -> PATE 2019-02-26 09:21:25 +11:00
spapr_iommu.c
spapr_irq.c spapr_irq: Expose the phandle of the interrupt controller 2019-02-26 09:21:25 +11:00
spapr_ovec.c spapr: support memory unplug for qtest 2019-02-26 09:21:25 +11:00
spapr_pci_vfio.c
spapr_pci.c qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
spapr_rng.c
spapr_rtas_ddw.c
spapr_rtas.c target/ppc/spapr: Set LPCR:HR when using Radix mode 2019-02-26 09:21:25 +11:00
spapr_rtc.c qapi: move RTC_CHANGE to the target schema 2019-02-18 14:44:05 +01:00
spapr_vio.c spapr: Rename xics to intc in interrupt controller agnostic code 2019-02-17 21:54:02 +11:00
spapr.c qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
trace-events
virtex_ml507.c elf: Add optional function ptr to load_elf() to parse ELF notes 2019-02-05 16:50:16 +01:00