clock-vmstate.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "qemu/osdep.h"
  13. #include "migration/vmstate.h"
  14. #include "hw/clock.h"
  15. static bool muldiv_needed(void *opaque)
  16. {
  17. Clock *clk = opaque;
  18. return clk->multiplier != 1 || clk->divider != 1;
  19. }
  20. static int clock_pre_load(void *opaque)
  21. {
  22. Clock *clk = opaque;
  23. /*
  24. * The initial out-of-reset settings of the Clock might have been
  25. * configured by the device to be different from what we set
  26. * in clock_initfn(), so we must here set the default values to
  27. * be used if they are not in the inbound migration state.
  28. */
  29. clk->multiplier = 1;
  30. clk->divider = 1;
  31. return 0;
  32. }
  33. const VMStateDescription vmstate_muldiv = {
  34. .name = "clock/muldiv",
  35. .version_id = 1,
  36. .minimum_version_id = 1,
  37. .needed = muldiv_needed,
  38. .fields = (VMStateField[]) {
  39. VMSTATE_UINT32(multiplier, Clock),
  40. VMSTATE_UINT32(divider, Clock),
  41. VMSTATE_END_OF_LIST()
  42. },
  43. };
  44. const VMStateDescription vmstate_clock = {
  45. .name = "clock",
  46. .version_id = 0,
  47. .minimum_version_id = 0,
  48. .pre_load = clock_pre_load,
  49. .fields = (VMStateField[]) {
  50. VMSTATE_UINT64(period, Clock),
  51. VMSTATE_END_OF_LIST()
  52. },
  53. .subsections = (const VMStateDescription*[]) {
  54. &vmstate_muldiv,
  55. NULL
  56. },
  57. };