What's the documented way to construct a QOM path, given only an ID as
input ?
QOM paths a gap in our documentation, even though the composition tree
structure has been stable since day one, and is de facto ABI.
Short answer: "/machine/peripheral/ID".
Long answer follows.
We have three "containers" under /machine that serve as parents for
devices:
* /machine/peripheral/
Parent of user-created devices with ID. Children are named "ID".
Put there by qdev_set_id(), called from qdev_device_add_from_qdict().
On "user-created": Nothing stops board code to abuse qdev_set_id() for
onboard devices, directly or indirectly, but it really, really
shouldn't.
* /machine/peripheral-anon/
Parent of user-created devices without ID. Children are named
"device[N]", where N counts up from zero.
Put there by qdev_set_id(), called from qdev_device_add_from_qdict().
Again, abuse by board code is possible, but would be wrong.
Beware: a particular device's N changes when the set of devices
created before it grows or shrinks. Messing with the machine type can
change it (different onboard devices).
* /machine/unattached/
Surrogate parent of onboard devices created without a parent.
Put there by device_set_realized() (general case),
qdev_connect_gpio_out_named() (input pins) , memory_region_do_init()
(memory regions), qemu_create_machine() (the main sysbus).
I believe this container was created as a convenience, so we don't
have to retrofit parents to existing code. Probably abused ever
since.