Merge tag 'pull-testing-gdbstub-plugins-gitdm-061022-3' of https://github.com/stsquad...
[qemu.git] / hw / core / clock-vmstate.c
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 },
48 };
49
50 const VMStateDescription vmstate_clock = {
51 .name = "clock",
52 .version_id = 0,
53 .minimum_version_id = 0,
54 .pre_load = clock_pre_load,
55 .fields = (VMStateField[]) {
56 VMSTATE_UINT64(period, Clock),
57 VMSTATE_END_OF_LIST()
58 },
59 .subsections = (const VMStateDescription*[]) {
60 &vmstate_muldiv,
61 NULL
62 },
63 };