On 5 July 2017 at 13:21, Paolo Bonzini <pbonz...@redhat.com> wrote: > > > On 04/07/2017 19:02, Peter Maydell wrote: >> Many board models and several devices need to create auxiliary >> regions of RAM (in addition to the main lump of 'system' memory), >> to model static RAMs, video memory, ROMs, etc. Currently they do >> this with a sequence like: >> memory_region_init_ram(sram, NULL, "sram", 0x10000, &error_fatal); >> vmstate_register_ram_global(sram); > > Instead of vmstate_register_ram_global, you should use > > vmstate_register_ram(mr, owner); > > You should even do it for all memory regions, probably.
Slightly awkward because owner is an Object but vmstate_register_ram() needs a DeviceState. Is this OK, or too much magic? DeviceState *owner_dev; Error *err = NULL; memory_region_init_ram(mr, owner, name, ram_size, &err); if (err) { error_propagate(errp, err); return; } /* Note that owner_dev may be NULL if owner is not a DeviceState; * in that case this is equivalent to calling vmstate_register_ram_global(). */ owner_dev = object_dynamic_cast(owner, TYPE_DEVICE); vmstate_register_ram(mr, owner_dev); thanks -- PMM