99abcbc760
It is quite common for a clock tree to involve possibly programmable clock multipliers or dividers, where the frequency of a clock is for instance divided by 8 to produce a slower clock to feed to a particular device. Currently we provide no convenient mechanism for modelling this. You can implement it by having an input Clock and an output Clock, and manually setting the period of the output clock in the period-changed callback of the input clock, but that's quite clunky. This patch adds support in the Clock objects themselves for setting a multiplier or divider. The effect of setting this on a clock is that when the clock's period is changed, all the children of the clock are set to period * multiplier / divider, rather than being set to the same period as the parent clock. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Luc Michel <luc@lmichel.fr> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Message-id: 20210812093356.1946-10-peter.maydell@linaro.org
64 lines
1.5 KiB
C
64 lines
1.5 KiB
C
/*
|
|
* Clock migration structure
|
|
*
|
|
* Copyright GreenSocs 2019-2020
|
|
*
|
|
* Authors:
|
|
* Damien Hedde
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "migration/vmstate.h"
|
|
#include "hw/clock.h"
|
|
|
|
static bool muldiv_needed(void *opaque)
|
|
{
|
|
Clock *clk = opaque;
|
|
|
|
return clk->multiplier != 1 || clk->divider != 1;
|
|
}
|
|
|
|
static int clock_pre_load(void *opaque)
|
|
{
|
|
Clock *clk = opaque;
|
|
/*
|
|
* The initial out-of-reset settings of the Clock might have been
|
|
* configured by the device to be different from what we set
|
|
* in clock_initfn(), so we must here set the default values to
|
|
* be used if they are not in the inbound migration state.
|
|
*/
|
|
clk->multiplier = 1;
|
|
clk->divider = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
const VMStateDescription vmstate_muldiv = {
|
|
.name = "clock/muldiv",
|
|
.version_id = 1,
|
|
.minimum_version_id = 1,
|
|
.needed = muldiv_needed,
|
|
.fields = (VMStateField[]) {
|
|
VMSTATE_UINT32(multiplier, Clock),
|
|
VMSTATE_UINT32(divider, Clock),
|
|
},
|
|
};
|
|
|
|
const VMStateDescription vmstate_clock = {
|
|
.name = "clock",
|
|
.version_id = 0,
|
|
.minimum_version_id = 0,
|
|
.pre_load = clock_pre_load,
|
|
.fields = (VMStateField[]) {
|
|
VMSTATE_UINT64(period, Clock),
|
|
VMSTATE_END_OF_LIST()
|
|
},
|
|
.subsections = (const VMStateDescription*[]) {
|
|
&vmstate_muldiv,
|
|
NULL
|
|
},
|
|
};
|