1 /* 2 * Clock migration structure 3 * 4 * Copyright GreenSocs 2019-2020 5 * 6 * Authors: 7 * Damien Hedde 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "migration/vmstate.h" 15 #include "hw/clock.h" 16 17 static bool muldiv_needed(void *opaque) 18 { 19 Clock *clk = opaque; 20 21 return clk->multiplier != 1 || clk->divider != 1; 22 } 23 24 static int clock_pre_load(void *opaque) 25 { 26 Clock *clk = opaque; 27 /* 28 * The initial out-of-reset settings of the Clock might have been 29 * configured by the device to be different from what we set 30 * in clock_initfn(), so we must here set the default values to 31 * be used if they are not in the inbound migration state. 32 */ 33 clk->multiplier = 1; 34 clk->divider = 1; 35 36 return 0; 37 } 38 39 const VMStateDescription vmstate_muldiv = { 40 .name = "clock/muldiv", 41 .version_id = 1, 42 .minimum_version_id = 1, 43 .needed = muldiv_needed, 44 .fields = (VMStateField[]) { 45 VMSTATE_UINT32(multiplier, Clock), 46 VMSTATE_UINT32(divider, Clock), 47 VMSTATE_END_OF_LIST() 48 }, 49 }; 50 51 const VMStateDescription vmstate_clock = { 52 .name = "clock", 53 .version_id = 0, 54 .minimum_version_id = 0, 55 .pre_load = clock_pre_load, 56 .fields = (VMStateField[]) { 57 VMSTATE_UINT64(period, Clock), 58 VMSTATE_END_OF_LIST() 59 }, 60 .subsections = (const VMStateDescription*[]) { 61 &vmstate_muldiv, 62 NULL 63 }, 64 }; 65