>>> So this happens before any hotplug handler is called. Everything works >>> just fine. What you don't like about this is the qdev_get_machine(). I >>> also don't like it but in the short term I don't see any problem with >>> it. It is resource allocation and not a "device plug" in the typical form. >> >> It's not qdev_get_machine() that's issue, it's layer violation, >> where child device is allocating and mapping resources of one of its parents. > > Quite simple: introduce a function at the machine where the child can > "request" to get an address and "request" to plug/unplug a region. > > Or what would be wrong about that? >
To extend on such an idea (looking at virtio_bus_device_plugged() getting called from virtio realize functions) Make the machine implement some new interface "MemoryDeviceManager". >From virtio-mem/pmem realize, call a function like memory_device_plugged(). Lookup the machine (qdev_get_machine() or walk all the way up until we find one that implements MemoryDeviceManager) and call pre_plugged/plugged/unplugged. We could hide that in a new device class TYPE_VIRTIO_MEMORY_DEVICE. Opinions? Completely nonsense? :) Alternatives? -- Thanks, David / dhildenb