Hi, Various issues related to implementing dynamic machines have been documented in [1].
We are trying to understand what means "a qdev is realized". One explanation was "the device is guest visible"; however many devices are realized before being mapped, thus are not "guest visible". Some devices map / wire their IRQs before being realized (such ISA devices). There is a need for devices to be "automatically" mapped/wired (see [2]) such CLI-created devices, but this apply generically to dynamic machines. Currently the device creation steps are expected to roughly be: (external use) (QDev core) (Device Impl) ~~~~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~ INIT enter -----> +----------------------+ | Allocate state | +----------------------+ -----> +---------------------+ | INIT children | | | | Alias children properties | | | Expose properties | INIT exit +---------------------+ <----------------------------------- +----------------+ | set properties | | | | set ClkIn | +----------------+ REALIZE enter ----------------------------------> +----------------------+ | Use config properties| | | | Realize children | | | | Init GPIOs/IRQs | | | | Init MemoryRegions | +----------------------+ REALIZE exit <----------------------------------- ---- "realized" / "guest visible" +-----------------+ | Explicit wiring:| | IRQs | | I/O / Mem | | ClkOut | +-----------------+ RESET enter ---------------------------------> +----------------------+ | Reset default values | +----------------------+ But as mentioned, various devices "wire" parts before they exit the "realize" step. In order to clarify, I'm trying to enforce what can be done *before* and *after* realization. *after* a device is expected to be stable (no more configurable) and fully usable. To be able to use internal/auto wiring (such ISA devices) and keep the current external/explicit wiring, I propose to add an extra "internal wiring" step, happening after the REALIZE step as: (external use) (QDev core) (Device Impl) ~~~~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~ INIT enter -----> +----------------------+ | Allocate state | +----------------------+ -----> +---------------------+ | INIT children | | | | Alias children properties | | | Expose properties | INIT exit +---------------------+ <----------------------------------- +----------------+ | set properties | | | | set ClkIn | +----------------+ REALIZE enter ----------------------------------> +----------------------+ | Use config properties| | | | Realize children | | | | Init GPIOs/IRQs | | | | Init MemoryRegions | +----------------------+ REALIZE exit <--- +----------------------+ | Internal auto wiring | | IRQs | (i.e. ISA bus) | I/O / Mem | | ClkOut | +----------------------+ <--- ---- "realized" +-----------------+ | External wiring:| | IRQs | | I/O / Mem | | ClkOut | +-----------------+ RESET enter ---- "guest visible" ---------------------------------> +----------------------+ | Reset default values | +----------------------+ The "realized" point is not changed. "guest visible" concept only occurs *after* wiring, just before the reset phase. This series introduces the DeviceClass::wire handler within qdev core realization code, and convert devices using the implicit wiring to using that explicit handler. QDev API assertions patches will be posted later as another series. Thoughts? Regards, Phil. [1] https://lore.kernel.org/all/87o7d1i7ky....@pond.sub.org/ [2] https://lore.kernel.org/qemu-devel/20231127052024.435743-1-gustavo.rom...@linaro.org/ Cc: Eduardo Habkost <edua...@habkost.net> Cc: Markus Armbruster <arm...@redhat.com>' --cc ' Cc: Edgar E. Iglesias <edgar.igles...@gmail.com>' Cc: Richard Henderson <richard.hender...@linaro.org> Cc: Mark Cave-Ayland <mark.cave-ayl...@ilande.co.uk> Cc: Thomas Huth <th...@redhat.com> Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: Alexander Graf <ag...@csgraf.de> Cc: Bernhard Beschow <shen...@gmail.com> Cc: Stefan Hajnoczi <stefa...@redhat.com> Cc: Peter Maydell <peter.mayd...@linaro.org> Cc: Cédric Le Goater <c...@kaod.org> Cc: Luc Michel <luc.mic...@amd.com> Cc: Zhao Liu <zhao1....@linux.intel.com> Cc: Gustavo Romero <gustavo.rom...@linaro.org> Philippe Mathieu-Daudé (7): hw/qdev: Introduce DeviceClass::[un]wire() handlers hw/input/pckbd: Connect i8042 GPIOs once mouse/keyboard are realized hw/ide/cmd646: Configure IDE bus IRQs after realization hw/ide/sii3112: Configure IDE bus IRQs after realization hw/ide/via: Configure IDE bus IRQs after realization hw/intc/mips_gic: Initialize IRQ array once device is realized hw/misc/mac_via: Have VIA1 child access parent IRQ once realized include/hw/qdev-core.h | 8 +++++++- hw/core/qdev.c | 21 ++++++++++++++++++++- hw/ide/cmd646.c | 12 +++++++++++- hw/ide/sii3112.c | 10 ++++++++++ hw/ide/via.c | 10 ++++++++++ hw/input/pckbd.c | 38 +++++++++++++++++++++++++++----------- hw/intc/mips_gic.c | 11 +++++++++-- hw/misc/mac_via.c | 9 ++++++++- 8 files changed, 102 insertions(+), 17 deletions(-) -- 2.41.0