Clock framework API.
Subsystems (2)
v3 cover Clock framework API.
From: KONRAD Frederic <[email protected]>
Hi,
This is the third version of the clock framework API it contains:
* The first 6 patches which introduce the framework.
* The 7th patch which introduces a fixed-clock model.
* The rest which gives an example how to model a PLL from the existing zynqmp-crf extracted from the qemu xilinx tree.
No specific behavior is expected yet when the CRF register set is accessed but the user can see for example the dp_video_ref and vpll_to_lpd rate changing in the monitor with the "info qtree" command when the vpll_ctrl register is modified.
bus: main-system-bus
type System
dev: xlnx.zynqmp_crf, id ""
gpio-out "sysbus-irq" 1
qemu-clk "dbg_trace" 0
qemu-clk "dp_stc_ref" 0
qemu-clk "dpll_to_lpd" 12500000
qemu-clk "acpu_clk" 0
qemu-clk "pcie_ref" 0
qemu-clk "topsw_main" 0
qemu-clk "topsw_lsbus" 0
qemu-clk "dp_audio_ref" 0
qemu-clk "sata_ref" 0
qemu-clk "dp_video_ref" 1428571
qemu-clk "vpll_clk" 50000000
qemu-clk "apll_to_lpd" 12500000
qemu-clk "dpll_clk" 50000000
qemu-clk "gpu_ref" 0
qemu-clk "aux_refclk" 0
qemu-clk "video_clk" 27000000
qemu-clk "gdma_ref" 0
qemu-clk "gt_crx_ref_clk" 0
qemu-clk "dbg_fdp" 0
qemu-clk "apll_clk" 50000000
qemu-clk "pss_alt_ref_clk" 0
qemu-clk "ddr" 0
qemu-clk "dbg_tstmp" 0
qemu-clk "pss_ref_clk" 50000000
qemu-clk "dpdma_ref" 0
qemu-clk "vpll_to_lpd" 12500000
mmio 00000000fd1a0000/000000000000010c
This series is based on the current master
(d992f2f1368ceb92e6bfd8efece174110f4236ff).
Thanks,
Fred
V2 -> V3:
* Rebased on current master.
* Renamed qemu_clk / QEMUClock as suggested by Cédric.
* Renamed in_rate to ref_rate and out_rate to rate.
* Renamed qemu_clk_bind_clock to qemu_clk_bind.
* Example added to the documentation as suggested by Peter.
V1 -> V2:
* Rebased on current master.
* Some function renamed and documentation fixed.
RFC -> V1:
* Rebased on current master.
* The docs has been fixed.
* qemu_clk_init_device helper has been provided to ease the initialization of the devices.
KONRAD Frederic (10):
qemu-clk: introduce qemu-clk qom object
qemu-clk: allow to add a clock to a device
qemu-clk: allow to bind two clocks together
qemu-clk: introduce an init array to help the device construction
qdev-monitor: print the device's clock with info qtree
docs: add qemu-clock documentation
introduce fixed-clock
introduce zynqmp_crf
zynqmp: add the zynqmp_crf to the platform
zynqmp: add reference clock
Makefile.objs | 1 + docs/clock.txt | 278 ++++++++++++ hw/arm/xlnx-zynqmp.c | 56 +++ hw/misc/Makefile.objs | 2 + hw/misc/fixed-clock.c | 88 ++++ hw/misc/xilinx_zynqmp_crf.c | 968 ++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 8 + include/hw/misc/fixed-clock.h | 30 ++ include/qemu/qemu-clock.h | 161 +++++++ qdev-monitor.c | 2 + qemu-clock.c | 176 ++++++++ 11 files changed, 1770 insertions(+) create mode 100644 docs/clock.txt create mode 100644 hw/misc/fixed-clock.c create mode 100644 hw/misc/xilinx_zynqmp_crf.c create mode 100644 include/hw/misc/fixed-clock.h create mode 100644 include/qemu/qemu-clock.h create mode 100644 qemu-clock.c
Signature · 1 line
1.8.3.1
PATCH v3 1/10 qemu-clk: introduce qemu-clk qom object
From: KONRAD Frederic <[email protected]>
This introduces qemu-clk qom object.
V2 -> V3:
* s/qemu_clk/QEMUClock/g
--- Makefile.objs | 1 + include/qemu/qemu-clock.h | 40 +++++++++++++++++++++++++++++++++++++ qemu-clock.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 include/qemu/qemu-clock.h create mode 100644 qemu-clock.c
Makefile.objs +1 -0
@@ -75,6 +75,7 @@ common-obj-y += backends/ common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o common-obj-$(CONFIG_FDT) += device_tree.o +common-obj-y += qemu-clock.o ###################################################################### # qapi
include/qemu/qemu-clock.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* QEMU Clock +* +* Copyright (C) 2016 : GreenSocs Ltd +* http://www.greensocs.com/ , email: [email protected] +* +* Frederic Konrad <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef QEMU_CLOCK_H +#define QEMU_CLOCK_H + +#include "qemu/osdep.h" +#include "qom/object.h" + +#define TYPE_CLOCK "qemu-clk" +#define QEMU_CLOCK (obj) OBJECT_CHECK(QEMUClock, (obj), TYPE_CLOCK) + +typedef struct QEMUClock { +/*< private >*/ +Object parent_obj; +}QEMUClock ; + +#endif /* QEMU_CLOCK_H */ + +
qemu-clock.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/10 qemu-clk: allow to add a clock to a device
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This allows to add a clock to a DeviceState.
Contrary to gpios, the clock pins are not contained in the DeviceState but with the child property so they can appears in the qom-tree.
V2 -> V3:
* s/qemu_clk/QEMUClock/g
V1 -> V2:
* Rename the function use 'add' instead of 'attach'
--- include/qemu/qemu-clock.h | 24 +++++++++++++++++++++++- qemu-clock.c | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)
include/qemu/qemu-clock.h +23 -1
@@ -33,8 +33,30 @@typedef struct QEMUClock {/*< private >*/ Object parent_obj; +char *name;/* name of this clock in the device. */ }QEMUClock ; -#endif /* QEMU_CLOCK_H */ +/** +* qemu_clk_device_add_clock: +* @dev: the device on which the clock needs to be added. +* @clk: the clock which needs to be added. +* @name: the name of the clock can't be NULL. +* +* Add @clk to device @dev as a clock named @name. +* +*/ +void qemu_clk_device_add_clock (DeviceState *dev,QEMUClock *clk, +const char *name); +/** +* qemu_clk_device_get_clock: +* @dev: the device which contains the clock. +* @name: the name of the clock. +* +* Get the clock named @name contained in the device @dev, or NULL if not found. +* +* Returns the clock named @name contained in @dev. +*/ +QEMUClock *qemu_clk_device_get_clock (DeviceState *dev,const char *name); +#endif /* QEMU_CLOCK_H */
qemu-clock.c +23 -0
@@ -25,6 +25,7 @@#include "qemu/qemu-clock.h" #include "hw/hw.h" #include "qemu/log.h" +#include "qapi/error.h" #ifndef DEBUG_QEMU_CLOCK #define DEBUG_QEMU_CLOCK 0
@@ -36,6 +37,28 @@ } \ }while (0 ); +void qemu_clk_device_add_clock (DeviceState *dev,QEMUClock *clk, +const char *name) +{ +assert (name); +assert (!clk->name); +object_property_add_child (OBJECT (dev), name,OBJECT (clk), &error_abort); + clk->name =g_strdup (name); +} + +QEMUClock *qemu_clk_device_get_clock (DeviceState *dev,const char *name) +{ +gchar *path =NULL ; +Object *clk; +bool ambiguous; + + path =g_strdup_printf ("%s/%s" ,object_get_canonical_path (OBJECT (dev)), + name); + clk =object_resolve_path (path, &ambiguous); +g_free (path); +return QEMU_CLOCK (clk); +} +static const TypeInfo qemu_clk_info = { .name =TYPE_CLOCK , .parent =TYPE_OBJECT ,
Signature · 1 line
1.8.3.1
PATCH v3 3/10 qemu-clk: allow to bind two clocks together
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This introduces the clock binding and the update part.
When the qemu_clk_rate_update(qemu_clk, int) function is called:
* The clock callback is called on the qemu_clk so it can change the rate.
* The qemu_clk_rate_update function is called on all the driven clock.
V2 -> V3:
* s/qemu_clk/QEMUClock/g
* Rename in_rate to ref_rate
* Rename out_rate to rate
* Rename qemu_clk_bind_clock to qemu_clk_bind
V1 -> V2:
* Rename qemu_clk_on_rate_update_cb to QEMUClkRateUpdateCallback and move the pointer to the structure instead of having a pointer-to-function type.
--- include/qemu/qemu-clock.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++ qemu-clock.c | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+)
include/qemu/qemu-clock.h +67 -0
@@ -30,12 +30,25 @@#define TYPE_CLOCK "qemu-clk"#define QEMU_CLOCK (obj) OBJECT_CHECK(QEMUClock, (obj), TYPE_CLOCK) +typedef struct ClkList ClkList ; +typedef uint64_t QEMUClkRateUpdateCallback (void *opaque,uint64_t rate); +typedef struct QEMUClock {/*< private >*/ Object parent_obj;char *name;/* name of this clock in the device. */ +uint64_t ref_rate;/* rate of the clock which drive this pin. */ +uint64_t rate;/* rate of this clock pin. */ +void *opaque; +QEMUClkRateUpdateCallback *cb; + QLIST_HEAD(, ClkList) bound; }QEMUClock ; +struct ClkList { +QEMUClock *clk; +QLIST_ENTRY (ClkList) node; +}; +/** * qemu_clk_device_add_clock: * @dev: the device on which the clock needs to be added.
@@ -59,4 +72,58 @@ void qemu_clk_device_add_clock(DeviceState *dev, QEMUClock *clk,*/ QEMUClock *qemu_clk_device_get_clock (DeviceState *dev,const char *name); +/** +* qemu_clk_bind: +* @out: the clock output. +* @in: the clock input. +* +* Connect the clock together. This is unidirectional so a +* qemu_clk_update_rate will go from @out to @in. +* +*/ +void qemu_clk_bind (QEMUClock *out,QEMUClock *in); + +/** +* qemu_clk_unbind: +* @out: the clock output. +* @in: the clock input. +* +* Disconnect the clocks if they were bound together. +* +*/ +void qemu_clk_unbind (QEMUClock *out,QEMUClock *in); + +/** +* qemu_clk_update_rate: +* @clk: the clock to update. +* @rate: the new rate in Hz. +* +* Update the @clk to the new @rate. +* +*/ +void qemu_clk_update_rate (QEMUClock *clk,uint64_t rate); + +/** +* qemu_clk_refresh: +* @clk: the clock to be refreshed. +* +* If a model alters the topology of a clock tree, it must call this function on +* the clock source to refresh the clock tree. +* +*/ +void qemu_clk_refresh (QEMUClock *clk); + +/** +* qemu_clk_set_callback: +* @clk: the clock associated to the callback. +* @cb: the function which is called when a refresh happen on the clock @clk. +* @opaque: the opaque data passed to the callback. +* +* Set the callback @cb which will be called when the clock @clk is updated. +* +*/ +void qemu_clk_set_callback (QEMUClock *clk, +QEMUClkRateUpdateCallback *cb, +void *opaque); +#endif /* QEMU_CLOCK_H */
qemu-clock.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 4/10 qemu-clk: introduce an init array to help the device construction
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This introduces a clock init array to ease the clock tree construction.
V2 -> V3:
* s/QEMUClock/qemu_clk/g
--- include/qemu/qemu-clock.h | 23 +++++++++++++++++++++++ qemu-clock.c | 17 +++++++++++++++++ 2 files changed, 40 insertions(+)
include/qemu/qemu-clock.h +23 -0
@@ -49,6 +49,29 @@ struct ClkList {QLIST_ENTRY (ClkList) node; }; +typedef struct ClockInitElement { +const char *name;/* Name to give to the clock. */ +size_t offset;/* Offset of the qemu_clk field in the object. */ +QEMUClkRateUpdateCallback *cb; +}ClockInitElement ; + +#define DEVICE_CLOCK (_state, _field, _cb) { \ + .name = #_field, \ + .offset = offsetof(_state, _field), \ + .cb = _cb \ +} + +#define DEVICE_CLOCK_END () { \ + .name = NULL \ +} + +/** +* qemu_clk_init_device: +* @obj: the Object which need to be initialized. +* @array: the array of ClockInitElement to be used. +*/ +void qemu_clk_init_device (Object *obj,ClockInitElement *array); +/** * qemu_clk_device_add_clock: * @dev: the device on which the clock needs to be added.
qemu-clock.c +17 -0
@@ -26,6 +26,7 @@#include "hw/hw.h" #include "qemu/log.h" #include "qapi/error.h" +#include "hw/qdev-core.h" #ifndef DEBUG_QEMU_CLOCK #define DEBUG_QEMU_CLOCK 0
@@ -37,6 +38,22 @@ } \ }while (0 ); +void qemu_clk_init_device (Object *obj,ClockInitElement *array) +{ +QEMUClock **cur =NULL ; + +while (array->name !=NULL ) { +DPRINTF ("init clock named %s\n" , array->name); + cur = (((void *)obj) + array->offset); + *cur =QEMU_CLOCK (object_new (TYPE_CLOCK )); +qemu_clk_device_add_clock (DEVICE (obj), *cur, array->name); +if (array->cb) { +qemu_clk_set_callback (*cur, array->cb, obj); + } + array++; + } +} +void qemu_clk_refresh (QEMUClock *clk) {qemu_clk_update_rate (clk, clk->ref_rate);
Signature · 1 line
1.8.3.1
PATCH v3 5/10 qdev-monitor: print the device's clock with info qtree
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This prints the clock attached to a DeviceState when using "info qtree" monitor command.
For example:
bus: main-system-bus
type System
dev: xlnx.zynqmp_crf, id ""
gpio-out "sysbus-irq" 1
gpio-out "RST_A9" 4
qemu-clk "dbg_trace" 0.0
qemu-clk "vpll_to_lpd" 12500000.0
qemu-clk "dp_stc_ref" 0.0
qemu-clk "dpll_to_lpd" 12500000.0
qemu-clk "acpu_clk" 0.0
qemu-clk "pcie_ref" 0.0
qemu-clk "topsw_main" 0.0
qemu-clk "topsw_lsbus" 0.0
qemu-clk "dp_audio_ref" 0.0
qemu-clk "sata_ref" 0.0
qemu-clk "dp_video_ref" 1428571.4
qemu-clk "vpll_clk" 50000000.0
qemu-clk "apll_to_lpd" 12500000.0
qemu-clk "dpll_clk" 50000000.0
qemu-clk "gpu_ref" 0.0
qemu-clk "aux_refclk" 0.0
qemu-clk "video_clk" 27000000.0
qemu-clk "gdma_ref" 0.0
qemu-clk "gt_crx_ref_clk" 0.0
qemu-clk "dbg_fdp" 0.0
qemu-clk "apll_clk" 50000000.0
qemu-clk "pss_alt_ref_clk" 0.0
qemu-clk "ddr" 0.0
qemu-clk "pss_ref_clk" 50000000.0
qemu-clk "dpdma_ref" 0.0
qemu-clk "dbg_tstmp" 0.0
mmio 00000000fd1a0000/000000000000010c--- include/qemu/qemu-clock.h | 9 +++++++++ qdev-monitor.c | 2 ++ qemu-clock.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+)
include/qemu/qemu-clock.h +9 -0
@@ -149,4 +149,13 @@ void qemu_clk_set_callback(QEMUClock *clk, QEMUClkRateUpdateCallback *cb, void *opaque); +/** +* qemu_clk_print: +* @dev: the device for which the clock need to be printed. +* +* Print the clock information for a given device. +* +*/ +void qemu_clk_print (Monitor *mon,DeviceState *dev,int indent); +#endif /* QEMU_CLOCK_H */
qdev-monitor.c +2 -0
@@ -30,6 +30,7 @@#include "qemu/help_option.h" #include "sysemu/block-backend.h" #include "migration/migration.h" +#include "qemu/qemu-clock.h" /* * Aliases were a bad idea from the start. Let's keep them
@@ -699,6 +700,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) ngl->num_out); } } +qemu_clk_print (mon, dev, indent); class =object_get_class (OBJECT (dev)); do { qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
qemu-clock.c +28 -0
@@ -27,6 +27,7 @@#include "qemu/log.h" #include "qapi/error.h" #include "hw/qdev-core.h" +#include "monitor/monitor.h" #ifndef DEBUG_QEMU_CLOCK #define DEBUG_QEMU_CLOCK 0
@@ -134,6 +135,33 @@ QEMUClock *qemu_clk_device_get_clock(DeviceState *dev, const char *name)return QEMU_CLOCK (clk); } +struct print_opaque { +Monitor *mon; +int indent; +}; + +static int qemu_clk_print_rec (Object *obj,void *opaque) +{ +QEMUClock *clk = (QEMUClock *)(object_dynamic_cast (obj,TYPE_CLOCK )); +struct print_opaque *po = opaque; + +if (clk) { +monitor_printf (po->mon,"%*s" "qemu-clk \"%s\" %" PRIu64"\n" , + po->indent," " , clk->name, clk->rate); + } + +return 0 ; +} + +void qemu_clk_print (Monitor *mon,DeviceState *dev,int indent) +{ +struct print_opaque po; + + po.indent = indent; + po.mon = mon; +object_child_foreach (OBJECT (dev), qemu_clk_print_rec, &po); +} +static const TypeInfo qemu_clk_info = { .name =TYPE_CLOCK , .parent =TYPE_OBJECT ,
Signature · 1 line
1.8.3.1
PATCH v3 6/10 docs: add qemu-clock documentation
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This adds the qemu-clock documentation.
V1 -> V2:
* Fixed in accordance with the changes in the previous patches.
--- docs/clock.txt | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 docs/clock.txt
docs/clock.txt new file +278 -0
@@ -0,0 +1,278 @@ + +What is a QEMU_CLOCK +==================== + +A QEMU_CLOCK is a QOM Object developed for the purpose of modeling a clock tree +with QEMU. + +It only simulates the clock by keeping a copy of the current frequency and +doesn't model the signal itself such as pin toggle or duty cycle. + +It allows to model the impact of badly configured PLL, clock source selection +or disabled clock on the models. + +Binding the clock together to create a tree +=========================================== + +In order to create a clock tree with QEMU_CLOCK two or more clock must be bound +together. Let's say there are two clocks clk_a and clk_b: +Using qemu_clk_bind(clk_a, clk_b) will bind clk_a and clk_b. + +Binding two qemu-clk together creates a unidirectional link which means that +changing the rate of clk_a will propagate to clk_b and not the opposite. +The binding process automatically refreshes clk_b rate. + +Clock can be bound and unbound during execution for modeling eg: a clock +selector. + +A clock can drive more than one other clock. eg with this code: +qemu_clk_bind(clk_a, clk_b); +qemu_clk_bind(clk_a, clk_c); + +A clock rate change one clk_a will propagate to clk_b and clk_c. + +Implementing a callback on a rate change +======================================== + +The function prototype is the following: +typedef uint64_t QEMUClkRateUpdateCallback(void *opaque, uint64_t rate); + +It's main goal is to modify the rate before it's passed to the next clocks in +the tree. + +eg: for a 4x PLL the function will be: +uint64_t qemu_clk_rate_change_cb(void *opaque, uint64_t rate) +{ + return 4 * rate; +} + +To set the callback for the clock: +void qemu_clk_set_callback(qemu_clk clk, QEMUClkRateUpdateCallback *cb, + void *opaque); +can be called. + +The rate update process +======================= + +The rate update happen in this way: +When a model wants to update a clock frequency (eg: based on a register change +or something similar) it will call qemu_clk_update_rate(..) on the clock: + * The callback associated to the clock is called with the new rate. + * qemu_clk_update_rate(..) is then called on all bound clocks with the value + returned by the callback. + +NOTE: When no callback is attached, the clock qemu_clk_update_rate(..) is called +on the next clock in the tree with the rate unmodified. + +Adding a QEMU_CLOCK to a DeviceState +==================================== + +Adding a qemu-clk to a DeviceState is required to be able to get the clock +outside the model through qemu_clk_device_get_clock(..). + +It is also required to be able to print the clock and its rate with info qtree. +For example: + + type System + dev: xlnx.zynqmp_crf, id "" + gpio-out "sysbus-irq" 1 + gpio-out "RST_A9" 4 + qemu-clk "dbg_trace" 0 + qemu-clk "vpll_to_lpd" 625000000 + qemu-clk "dp_stc_ref" 0 + qemu-clk "dpll_to_lpd" 12500000 + qemu-clk "acpu_clk" 0 + qemu-clk "pcie_ref" 0 + qemu-clk "topsw_main" 0 + qemu-clk "topsw_lsbus" 0 + qemu-clk "dp_audio_ref" 0 + qemu-clk "sata_ref" 0 + qemu-clk "dp_video_ref" 71428568 + qemu-clk "vpll_clk" 2500000000 + qemu-clk "apll_to_lpd" 12500000 + qemu-clk "dpll_clk" 50000000 + qemu-clk "gpu_ref" 0 + qemu-clk "aux_refclk" 0 + qemu-clk "video_clk" 27000000 + qemu-clk "gdma_ref" 0 + qemu-clk "gt_crx_ref_clk" 0 + qemu-clk "dbg_fdp" 0 + qemu-clk "apll_clk" 50000000 + qemu-clk "pss_alt_ref_clk" 0 + qemu-clk "ddr" 0 + qemu-clk "pss_ref_clk" 50000000 + qemu-clk "dpdma_ref" 0 + qemu-clk "dbg_tstmp" 0 + mmio 00000000fd1a0000/000000000000010c + +This way a DeviceState can have multiple clock input or output. + +Examples +======== + +Those are the different way of using the QEMUClock object. + +Modelling a fixed clock generator +================================= + +Here is a brief example of a device acting as a clock source: + +typedef struct { + DeviceState parent_obj; + + uint32_t rate; + QEMUClock out; +} FixedClock; + +During the initialization the device must initialize its clock object: + +static void fixed_clock_instance_init(Object *obj) +{ + FixedClock *s = FIXED_CLOCK(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); +} + +As the device acts as a clock source it must refresh the clock tree during the +realize phase: + +static void fixed_clock_realizefn(DeviceState *dev, Error **errp) +{ + FixedClock *s = FIXED_CLOCK(dev); + + qemu_clk_update_rate(&s->out, s->rate); +} + +This means that the clock tree must be finished before realize is called on the +fixed clock. + +Modelling a clock user device +============================= + +Here is a brief example of a clock user: + +typedef struct { + DeviceState parent_obj; + + QEMUClock in; +} ClockUser; + +As before the clock must be initialized through the device initialize function: + +static void clock_user_instance_init(Object *obj) +{ + ClockUser *s = CLOCK_USER(obj); + + object_initialize(&s->in, sizeof(s->in), TYPE_CLOCK); + qemu_clk_device_add_clock(DEVICE(obj), &s->in, "clk_in"); + /* + * Call on_rate_change_cb when something change on clk_in. + */ + qemu_clk_set_callback(s->in, on_rate_change_cb, obj); +} + +The callback is in this case used as a notifier when the clock tree which +sources the device change: + +static uint64_t on_rate_change_cb(void *opaque, uint64_t input_rate) +{ + printf("the new rate is %ld\n", input_rate); + + /* The return is ignored if nothing is bound to clk_in. */ + return input_rate; +} + +Modelling a clock multiplier +============================ + +Here is a brief example of a device acting as a clock modifier: + +typedef struct { + DeviceState parent_obj; + + uint32_t rate; + QEMUClock out; + QEMUClock in; +} ClockMultiplier; + +As before the clocks must be initialized through the device initialize function +but they must be bound together so a change on the input will propagate on the +output: + +static void clock_multiplier_instance_init(Object *obj) +{ + ClockMultiplier *s = CLOCK_MULTIPLIER(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + object_initialize(&s->in, sizeof(s->in), TYPE_CLOCK); + + qemu_clk_device_add_clock(DEVICE(obj), &s->in, "clk_in"); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); + /* + * Propagate the change from in to out, this can be done dynamically during + * the simulation but we need to do the initial binding here to get the + * initial refresh happening when the realize function is called on the + * fixed clock. + */ + qemu_clk_bind(s->in, s->out); + /* + * But before propagating the rate modify it with multiplier_cb. + */ + qemu_clk_set_callback(s->out, multiplier_cb, obj); +} + +In this example when clk_in changes it will trigger a change on clk_out and this +callback can modify the rate of clk_out (the return value of this callback) +accordingly to clk_in rate (input_rate). + +static uint64_t multiplier_cb(void *opaque, uint64_t input_rate) +{ + return input_rate * 4; +} + +This device doesn't refresh the clock tree as it will be done by the clock tree +source. + +Modelling a clock selector +========================== + +Here is a brief example of a device acting as a device which alter the clock +topology such as a clock selector: + +typedef struct { + DeviceState parent_obj; + + QEMUClock out; + QEMUClock in_a; + QEMUClock in_b; +} ClockSelector; + +The clocks must be initialized through the device initialize function but they +must be bound together like they will be when the device is reset so a change on +the input during the realize of the fixed clock will propagate to the output: + +static void clock_selector_instance_init(Object *obj) +{ + ClockSelector *s = CLOCK_SELECTOR(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + object_initialize(&s->in_a, sizeof(s->in_a), TYPE_CLOCK); + object_initialize(&s->in_b, sizeof(s->in_b), TYPE_CLOCK); + + qemu_clk_device_add_clock(DEVICE(obj), &s->in_a, "clk_in_a"); + qemu_clk_device_add_clock(DEVICE(obj), &s->in_b, "clk_in_b"); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); + + /* Assuming at the reset that the input_a is connected to output. */ + qemu_clk_bind(s->in_a, s->out); +} + +/* This is called for example by a register change or something like that */ +void update_topology(ClockSelector *s) +{ + /* Unbind the old clock */ + qemu_clk_unbind(s->in_a, s->out); + /* Bind the new one, the rate is automatically refreshed. */ + qemu_clk_bind(s->in_b, s->out); +}
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 06/10] docs: add qemu-clock documentation
Quoted 3 lines · On Tue, Feb 28, 2017 at 11:03:01AM +0100, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This adds the qemu-clock documentation.
Hi Fred
Quoted 53 lines
Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Fixed in accordance with the changes in the previous patches.--- docs/clock.txt | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 docs/clock.txtdocs/clock.txt new file +37
-0@@ -0,0 +1,278 @@ + +What is a QEMU_CLOCK +==================== + +A QEMU_CLOCK is a QOM Object developed for the purpose of modeling a clock tree +with QEMU. + +It only simulates the clock by keeping a copy of the current frequency and +doesn't model the signal itself such as pin toggle or duty cycle. + +It allows to model the impact of badly configured PLL, clock source selection +or disabled clock on the models. + +Binding the clock together to create a tree +=========================================== + +In order to create a clock tree with QEMU_CLOCK two or more clock must be bound +together. Let's say there are two clocks clk_a and clk_b: +Using qemu_clk_bind(clk_a, clk_b) will bind clk_a and clk_b. + +Binding two qemu-clk together creates a unidirectional link which means that +changing the rate of clk_a will propagate to clk_b and not the opposite. +The binding process automatically refreshes clk_b rate. + +Clock can be bound and unbound during execution for modeling eg: a clock +selector. + +A clock can drive more than one other clock. eg with this code: +qemu_clk_bind(clk_a, clk_b); +qemu_clk_bind(clk_a, clk_c); + +A clock rate change one clk_a will propagate to clk_b and clk_c. + +Implementing a callback on a rate change +======================================== + +The function prototype is the following:
docs/clock.txt line 47
Quoted 10 lines
docs/clock.txt new file +10
-0+typedef uint64_t QEMUClkRateUpdateCallback(void *opaque, uint64_t rate); + +It's main goal is to modify the rate before it's passed to the next clocks in +the tree. + +eg: for a 4x PLL the function will be: +uint64_t qemu_clk_rate_change_cb(void *opaque, uint64_t rate) +{ + return 4 * rate; +}
I was thinking that this would work a little different.
Clocks would notify other objects when rates change by somehow calling registered callbacks. Devices that derive and propagates new clocks would:
1. Bind to a clock source by registering a callback.
2. When the callback gets called, they would compute a new rate and actively set that new rate to another clock object. I.e, a clock_in object does not exist, input clocks are just registered callbacks.
As the new rate gets set, more callbacks are potentially triggered across the clock tree.
That would get rid of the need for storing ref_rate in the clock objects.
rate would perhaps still be useful making it easy to print stuff in qom-tree, but it would really only be a cache of state that at any time can be derived by a devices internal state + rate change of any of the clocks the device has registered to.
Does this make sense?
I think this brings us closer to how gpios/interrupts work and makes migration simpler. I personally also find it more natural and easier to understand but that may be subjective.
What do you and others think?
Cheers,
Edgar
Quoted 235 lines
docs/clock.txt new file +231
-0+ +To set the callback for the clock: +void qemu_clk_set_callback(qemu_clk clk, QEMUClkRateUpdateCallback *cb, + void *opaque); +can be called. + +The rate update process +======================= + +The rate update happen in this way: +When a model wants to update a clock frequency (eg: based on a register change +or something similar) it will call qemu_clk_update_rate(..) on the clock: + * The callback associated to the clock is called with the new rate. + * qemu_clk_update_rate(..) is then called on all bound clocks with the value + returned by the callback. + +NOTE: When no callback is attached, the clock qemu_clk_update_rate(..) is called +on the next clock in the tree with the rate unmodified. + +Adding a QEMU_CLOCK to a DeviceState +==================================== + +Adding a qemu-clk to a DeviceState is required to be able to get the clock +outside the model through qemu_clk_device_get_clock(..). + +It is also required to be able to print the clock and its rate with info qtree. +For example: + + type System + dev: xlnx.zynqmp_crf, id "" + gpio-out "sysbus-irq" 1 + gpio-out "RST_A9" 4 + qemu-clk "dbg_trace" 0 + qemu-clk "vpll_to_lpd" 625000000 + qemu-clk "dp_stc_ref" 0 + qemu-clk "dpll_to_lpd" 12500000 + qemu-clk "acpu_clk" 0 + qemu-clk "pcie_ref" 0 + qemu-clk "topsw_main" 0 + qemu-clk "topsw_lsbus" 0 + qemu-clk "dp_audio_ref" 0 + qemu-clk "sata_ref" 0 + qemu-clk "dp_video_ref" 71428568 + qemu-clk "vpll_clk" 2500000000 + qemu-clk "apll_to_lpd" 12500000 + qemu-clk "dpll_clk" 50000000 + qemu-clk "gpu_ref" 0 + qemu-clk "aux_refclk" 0 + qemu-clk "video_clk" 27000000 + qemu-clk "gdma_ref" 0 + qemu-clk "gt_crx_ref_clk" 0 + qemu-clk "dbg_fdp" 0 + qemu-clk "apll_clk" 50000000 + qemu-clk "pss_alt_ref_clk" 0 + qemu-clk "ddr" 0 + qemu-clk "pss_ref_clk" 50000000 + qemu-clk "dpdma_ref" 0 + qemu-clk "dbg_tstmp" 0 + mmio 00000000fd1a0000/000000000000010c + +This way a DeviceState can have multiple clock input or output. + +Examples +======== + +Those are the different way of using the QEMUClock object. + +Modelling a fixed clock generator +================================= + +Here is a brief example of a device acting as a clock source: + +typedef struct { + DeviceState parent_obj; + + uint32_t rate; + QEMUClock out; +} FixedClock; + +During the initialization the device must initialize its clock object: + +static void fixed_clock_instance_init(Object *obj) +{ + FixedClock *s = FIXED_CLOCK(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); +} + +As the device acts as a clock source it must refresh the clock tree during the +realize phase: + +static void fixed_clock_realizefn(DeviceState *dev, Error **errp) +{ + FixedClock *s = FIXED_CLOCK(dev); + + qemu_clk_update_rate(&s->out, s->rate); +} + +This means that the clock tree must be finished before realize is called on the +fixed clock. + +Modelling a clock user device +============================= + +Here is a brief example of a clock user: + +typedef struct { + DeviceState parent_obj; + + QEMUClock in; +} ClockUser; + +As before the clock must be initialized through the device initialize function: + +static void clock_user_instance_init(Object *obj) +{ + ClockUser *s = CLOCK_USER(obj); + + object_initialize(&s->in, sizeof(s->in), TYPE_CLOCK); + qemu_clk_device_add_clock(DEVICE(obj), &s->in, "clk_in"); + /* + * Call on_rate_change_cb when something change on clk_in. + */ + qemu_clk_set_callback(s->in, on_rate_change_cb, obj); +} + +The callback is in this case used as a notifier when the clock tree which +sources the device change: + +static uint64_t on_rate_change_cb(void *opaque, uint64_t input_rate) +{ + printf("the new rate is %ld\n", input_rate); + + /* The return is ignored if nothing is bound to clk_in. */ + return input_rate; +} + +Modelling a clock multiplier +============================ + +Here is a brief example of a device acting as a clock modifier: + +typedef struct { + DeviceState parent_obj; + + uint32_t rate; + QEMUClock out; + QEMUClock in; +} ClockMultiplier; + +As before the clocks must be initialized through the device initialize function +but they must be bound together so a change on the input will propagate on the +output: + +static void clock_multiplier_instance_init(Object *obj) +{ + ClockMultiplier *s = CLOCK_MULTIPLIER(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + object_initialize(&s->in, sizeof(s->in), TYPE_CLOCK); + + qemu_clk_device_add_clock(DEVICE(obj), &s->in, "clk_in"); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); + /* + * Propagate the change from in to out, this can be done dynamically during + * the simulation but we need to do the initial binding here to get the + * initial refresh happening when the realize function is called on the + * fixed clock. + */ + qemu_clk_bind(s->in, s->out); + /* + * But before propagating the rate modify it with multiplier_cb. + */ + qemu_clk_set_callback(s->out, multiplier_cb, obj); +} + +In this example when clk_in changes it will trigger a change on clk_out and this +callback can modify the rate of clk_out (the return value of this callback) +accordingly to clk_in rate (input_rate). + +static uint64_t multiplier_cb(void *opaque, uint64_t input_rate) +{ + return input_rate * 4; +} + +This device doesn't refresh the clock tree as it will be done by the clock tree +source. + +Modelling a clock selector +========================== + +Here is a brief example of a device acting as a device which alter the clock +topology such as a clock selector: + +typedef struct { + DeviceState parent_obj; + + QEMUClock out; + QEMUClock in_a; + QEMUClock in_b; +} ClockSelector; + +The clocks must be initialized through the device initialize function but they +must be bound together like they will be when the device is reset so a change on +the input during the realize of the fixed clock will propagate to the output: + +static void clock_selector_instance_init(Object *obj) +{ + ClockSelector *s = CLOCK_SELECTOR(obj); + + object_initialize(&s->out, sizeof(s->out), TYPE_CLOCK); + object_initialize(&s->in_a, sizeof(s->in_a), TYPE_CLOCK); + object_initialize(&s->in_b, sizeof(s->in_b), TYPE_CLOCK); + + qemu_clk_device_add_clock(DEVICE(obj), &s->in_a, "clk_in_a"); + qemu_clk_device_add_clock(DEVICE(obj), &s->in_b, "clk_in_b"); + qemu_clk_device_add_clock(DEVICE(obj), &s->out, "clk_out"); + + /* Assuming at the reset that the input_a is connected to output. */ + qemu_clk_bind(s->in_a, s->out); +} + +/* This is called for example by a register change or something like that */ +void update_topology(ClockSelector *s) +{ + /* Unbind the old clock */ + qemu_clk_unbind(s->in_a, s->out); + /* Bind the new one, the rate is automatically refreshed. */ + qemu_clk_bind(s->in_b, s->out); +}Signature · 1 line
1.8.3.1
PATCH v3 7/10 introduce fixed-clock
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This is a fixed clock device.
It justs behave as an empty device with a parametrable output rate.
--- hw/misc/Makefile.objs | 1 + hw/misc/fixed-clock.c | 88 +++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/fixed-clock.h | 30 +++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 hw/misc/fixed-clock.c create mode 100644 include/hw/misc/fixed-clock.h
hw/misc/Makefile.objs +1 -0
@@ -55,3 +55,4 @@ obj-$(CONFIG_EDU) += edu.o obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o obj-$(CONFIG_AUX) += auxbus.o obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o +obj-y += fixed-clock.o
hw/misc/fixed-clock.c new file +88 -0
88 lines not on this page · raw message
include/hw/misc/fixed-clock.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Fixed clock +* +* Copyright (C) 2016 : GreenSocs Ltd +* http://www.greensocs.com/ , email: [email protected] +* +* Frederic Konrad <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef FIXED_CLOCK_H +#define FIXED_CLOCK_H + +#define TYPE_FIXED_CLOCK "fixed-clock" +#define FIXED_CLOCK (obj) OBJECT_CHECK(FixedClock, (obj), TYPE_FIXED_CLOCK) + +#endif /* FIXED_CLOCK_H */
Signature · 1 line
1.8.3.1
PATCH v3 8/10 introduce zynqmp_crf
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This introduce Xilinx zynqmp-crf.
It is extracted from the qemu xilinx tree (02d2f0203dd489ed30d9c8d90c14a52c57332b25) and is used as an example for the clock framework.
--- hw/misc/Makefile.objs | 1 + hw/misc/xilinx_zynqmp_crf.c | 968 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 969 insertions(+) create mode 100644 hw/misc/xilinx_zynqmp_crf.c
hw/misc/Makefile.objs +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_RASPI) += bcm2835_property.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.o +obj-$(CONFIG_ZYNQ) += xilinx_zynqmp_crf.o obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
hw/misc/xilinx_zynqmp_crf.c new file +968 -0
968 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 9/10 zynqmp: add the zynqmp_crf to the platform
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This adds the zynqmp_crf to the zynqmp platform.
--- hw/arm/xlnx-zynqmp.c | 7 +++++++ include/hw/arm/xlnx-zynqmp.h | 2 ++ 2 files changed, 9 insertions(+)
hw/arm/xlnx-zynqmp.c +7 -0
@@ -177,6 +177,11 @@ static void xlnx_zynqmp_init(Object *obj)object_initialize (&s->dpdma,sizeof (s->dpdma),TYPE_XLNX_DPDMA );qdev_set_parent_bus (DEVICE (&s->dpdma),sysbus_get_default ()); + + s->crf =object_new ("xlnx.zynqmp_crf" ); +qdev_set_parent_bus (DEVICE (s->crf),sysbus_get_default ()); +object_property_add_child (obj,"xlnx.zynqmp_crf" ,OBJECT (s->crf), + &error_abort); }static void xlnx_zynqmp_realize (DeviceState *dev,Error **errp)
@@ -424,6 +429,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) &error_abort);sysbus_mmio_map (SYS_BUS_DEVICE (&s->dpdma),0 ,DPDMA_ADDR );sysbus_connect_irq (SYS_BUS_DEVICE (&s->dpdma),0 , gic_spi[DPDMA_IRQ ]); + +sysbus_mmio_map (SYS_BUS_DEVICE (s->crf),0 ,0xFD1A0000 ); }static Property xlnx_zynqmp_props[] = {
include/hw/arm/xlnx-zynqmp.h +2 -0
@@ -86,6 +86,8 @@ typedef struct XlnxZynqMPState {XlnxDPState dp;XlnxDPDMAState dpdma; +Object *crf; +char *boot_cpu;ARMCPU *boot_cpu_ptr;
Signature · 1 line
1.8.3.1
PATCH v3 10/10 zynqmp: add reference clock
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This adds some fixed reference clock to the zynqmp platform. They will feed the zynqmp_crf block.
--- hw/arm/xlnx-zynqmp.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 6 ++++++ 2 files changed, 55 insertions(+)
hw/arm/xlnx-zynqmp.c +49 -0
@@ -24,6 +24,7 @@#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "kvm_arm.h" +#include "qemu/qemu-clock.h" #define GIC_NUM_SPI_INTR 160
@@ -182,6 +183,22 @@ static void xlnx_zynqmp_init(Object *obj)qdev_set_parent_bus (DEVICE (s->crf),sysbus_get_default ());object_property_add_child (obj,"xlnx.zynqmp_crf" ,OBJECT (s->crf), &error_abort); + + s->pss_ref_clk =object_new (TYPE_FIXED_CLOCK ); +object_property_add_child (obj,"pss_ref_clk" , s->pss_ref_clk, + &error_abort); +object_property_set_int (s->pss_ref_clk,50000000 ,"rate" , &error_abort); + s->video_clk =object_new (TYPE_FIXED_CLOCK ); +object_property_add_child (obj,"video_clk" , s->video_clk, &error_abort); +object_property_set_int (s->video_clk,27000000 ,"rate" , &error_abort); + s->pss_alt_ref_clk =object_new (TYPE_FIXED_CLOCK ); +object_property_add_child (obj,"pss_alt_ref_clk" , s->pss_alt_ref_clk, + &error_abort); + s->aux_refclk =object_new (TYPE_FIXED_CLOCK ); +object_property_add_child (obj,"aux_refclk" , s->aux_refclk, &error_abort); + s->gt_crx_ref_clk =object_new (TYPE_FIXED_CLOCK ); +object_property_add_child (obj,"gt_crx_ref_clk" , s->gt_crx_ref_clk, + &error_abort); }static void xlnx_zynqmp_realize (DeviceState *dev,Error **errp)
@@ -431,6 +448,38 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->dpdma),0 , gic_spi[DPDMA_IRQ ]);sysbus_mmio_map (SYS_BUS_DEVICE (s->crf),0 ,0xFD1A0000 ); + +/* Bind the clock */ +qemu_clk_bind (qemu_clk_device_get_clock (DEVICE (s->pss_ref_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"pss_ref_clk" )); + +qemu_clk_bind (qemu_clk_device_get_clock (DEVICE (s->video_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf),"video_clk" )); + +qemu_clk_bind (qemu_clk_device_get_clock (DEVICE (s->pss_alt_ref_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"pss_alt_ref_clk" )); + +qemu_clk_bind (qemu_clk_device_get_clock (DEVICE (s->aux_refclk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"aux_refclk" )); + +qemu_clk_bind (qemu_clk_device_get_clock (DEVICE (s->gt_crx_ref_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"gt_crx_ref_clk" )); + +object_property_set_bool (s->crf, true,"realized" , &err); +object_property_set_bool (s->pss_ref_clk, true,"realized" , &err); +object_property_set_bool (s->video_clk, true,"realized" , &err); +object_property_set_bool (s->pss_alt_ref_clk, true,"realized" , &err); +object_property_set_bool (s->aux_refclk, true,"realized" , &err); +object_property_set_bool (s->gt_crx_ref_clk, true,"realized" , &err); }static Property xlnx_zynqmp_props[] = {
include/hw/arm/xlnx-zynqmp.h +6 -0
@@ -28,6 +28,7 @@#include "hw/ssi/xilinx_spips.h" #include "hw/dma/xlnx_dpdma.h" #include "hw/display/xlnx_dp.h" +#include "hw/misc/fixed-clock.h" #define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"#define XLNX_ZYNQMP (obj) OBJECT_CHECK(XlnxZynqMPState, (obj), \
@@ -86,6 +87,11 @@ typedef struct XlnxZynqMPState {XlnxDPState dp;XlnxDPDMAState dpdma; +Object *pss_ref_clk; +Object *video_clk; +Object *pss_alt_ref_clk; +Object *aux_refclk; +Object *gt_crx_ref_clk;Object *crf;char *boot_cpu;
Signature · 1 line
1.8.3.1
Ping.
Thanks,
Fred
Quoted 102 lines · Le 28/02/2017 à 11:02, [email protected] a écrit :
From: KONRAD Frederic <[email protected]>
Hi,
This is the third version of the clock framework API it contains:
* The first 6 patches which introduce the framework.
* The 7th patch which introduces a fixed-clock model.
* The rest which gives an example how to model a PLL from the existing zynqmp-crf extracted from the qemu xilinx tree.No specific behavior is expected yet when the CRF register set is accessed but the user can see for example the
dp_video_refandvpll_to_lpdrate changing in the monitor with the "info qtree" command when thevpll_ctrlregister is modified.bus: main-system-bus
type System
dev: xlnx.zynqmp_crf, id ""
gpio-out "sysbus-irq" 1
qemu-clk "dbg_trace" 0
qemu-clk "dp_stc_ref" 0
qemu-clk "dpll_to_lpd" 12500000
qemu-clk "acpu_clk" 0
qemu-clk "pcie_ref" 0
qemu-clk "topsw_main" 0
qemu-clk "topsw_lsbus" 0
qemu-clk "dp_audio_ref" 0
qemu-clk "sata_ref" 0
qemu-clk "dp_video_ref" 1428571
qemu-clk "vpll_clk" 50000000
qemu-clk "apll_to_lpd" 12500000
qemu-clk "dpll_clk" 50000000
qemu-clk "gpu_ref" 0
qemu-clk "aux_refclk" 0
qemu-clk "video_clk" 27000000
qemu-clk "gdma_ref" 0
qemu-clk "gt_crx_ref_clk" 0
qemu-clk "dbg_fdp" 0
qemu-clk "apll_clk" 50000000
qemu-clk "pss_alt_ref_clk" 0
qemu-clk "ddr" 0
qemu-clk "dbg_tstmp" 0
qemu-clk "pss_ref_clk" 50000000
qemu-clk "dpdma_ref" 0
qemu-clk "vpll_to_lpd" 12500000
mmio 00000000fd1a0000/000000000000010cThis series is based on the current master
(d992f2f1368ceb92e6bfd8efece174110f4236ff).Thanks,
FredV2 -> V3:
* Rebased on current master.
* Renamedqemu_clk/ QEMUClock as suggested by Cédric.
* Renamedin_ratetoref_rateandout_rateto rate.
* Renamedqemu_clk_bind_clocktoqemu_clk_bind.
* Example added to the documentation as suggested by Peter.V1 -> V2:
* Rebased on current master.
* Some function renamed and documentation fixed.RFC -> V1:
* Rebased on current master.
* The docs has been fixed.
*qemu_clk_init_devicehelper has been provided to ease the initialization of the devices.KONRAD Frederic (10):
qemu-clk: introduce qemu-clk qom object
qemu-clk: allow to add a clock to a device
qemu-clk: allow to bind two clocks together
qemu-clk: introduce an init array to help the device construction
qdev-monitor: print the device's clock with info qtree
docs: add qemu-clock documentation
introduce fixed-clock
introducezynqmp_crf
zynqmp: add thezynqmp_crfto the platform
zynqmp: add reference clockMakefile.objs | 1 + docs/clock.txt | 278 ++++++++++++ hw/arm/xlnx-zynqmp.c | 56 +++ hw/misc/Makefile.objs | 2 + hw/misc/fixed-clock.c | 88 ++++ hw/misc/xilinx_zynqmp_crf.c | 968 ++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 8 + include/hw/misc/fixed-clock.h | 30 ++ include/qemu/qemu-clock.h | 161 +++++++ qdev-monitor.c | 2 + qemu-clock.c | 176 ++++++++ 11 files changed, 1770 insertions(+) create mode 100644 docs/clock.txt create mode 100644 hw/misc/fixed-clock.c create mode 100644 hw/misc/xilinx_zynqmp_crf.c create mode 100644 include/hw/misc/fixed-clock.h create mode 100644 include/qemu/qemu-clock.h create mode 100644 qemu-clock.c
Quoted 8 lines · KONRAD Frederic
Quoted 7 lines · Le 28/02/2017 à 11:02, [email protected] a écrit :
This is the third version of the clock framework API it contains:
* The first 6 patches which introduce the framework.
* The 7th patch which introduces a fixed-clock model.
* The rest which gives an example how to model a PLL from the existing zynqmp-crf extracted from the qemu xilinx tree.
Quoted 6 lines
Quoted 6 lines
No specific behavior is expected yet when the CRF register set is accessed but
the user can see for example thedp_video_refandvpll_to_lpdrate changing in
the monitor with the "info qtree" command when thevpll_ctrlregister is modified.
Some top-level review:
* I like the documentation, this is very helpful
* consider tracepoints rather than DPRINTF macro
* qemu_clk_device_add_clock() does a g_strdup, but when is this freed? (consider devices which are hot-unpluggable)
* similarly, what if a device with a clock with a lot of child nodes is destroyed? how are the ClkList structs freed?
* interaction with migration -- how is the "this clock is at this rate" state intended to be migrated?
* I'll leave the review of the xilinx patches to the xilinx folk
* the 'introduce zynqmp_crf' patch is missing any signoffs (in particular if it's from the xilinx tree it will need signoff from them)
thanks
-- PMM
Quoted 31 lines · Peter Maydell
Quoted 8 lines · KONRAD Frederic
Quoted 7 lines · Le 28/02/2017 à 11:02, [email protected] a écrit :
This is the third version of the clock framework API it contains:
* The first 6 patches which introduce the framework.
* The 7th patch which introduces a fixed-clock model.
* The rest which gives an example how to model a PLL from the existing zynqmp-crf extracted from the qemu xilinx tree.Quoted 6 lines
Quoted 6 lines
No specific behavior is expected yet when the CRF register set is accessed but
the user can see for example thedp_video_refandvpll_to_lpdrate changing in
the monitor with the "info qtree" command when thevpll_ctrlregister is modified.Some top-level review:
* I like the documentation, this is very helpful
* consider tracepoints rather than DPRINTF macro
*qemu_clk_device_add_clock()does ag_strdup, but when is this freed? (consider devices which are hot-unpluggable)
* similarly, what if a device with a clock with a lot of child nodes is destroyed? how are the ClkList structs freed?
* interaction with migration -- how is the "this clock is at this rate" state intended to be migrated?
* I'll leave the review of the xilinx patches to the xilinx folk
* the 'introducezynqmp_crf' patch is missing any signoffs (in particular if it's from the xilinx tree it will need signoff from them)
Quoted 3 lines
thanks
-- PMM
Nice thanks for the feedback!
Actually the hot unpluggable is a good question what can we do for that? Is that reasonable for a device which produce a clock to be hot unpluggable?
For the migration maybe we can refresh the whole clock tree at the end of the migration. Is that a good idea?
Fred
Quoted 10 lines · KONRAD Frederic
Quoted 8 lines · Peter Maydell
Some top-level review:
*
qemu_clk_device_add_clock()does ag_strdup, but when is this freed? (consider devices which are hot-unpluggable)
* similarly, what if a device with a clock with a lot of child nodes is destroyed? how are the ClkList structs freed?
* interaction with migration -- how is the "this clock is at this rate" state intended to be migrated?
Quoted 5 lines
Nice thanks for the feedback!
Actually the hot unpluggable is a good question what can we do for that? Is that reasonable for a device which produce a clock to be hot unpluggable?
I don't know if it's very likely (but you might have a PCI device for instance which uses clocks internally). But I think for a bit of low-level infrastructure like clocktree it's worth getting the details of the lifecycle right from the start.
Quoted 2 lines
For the migration maybe we can refresh the whole clock tree at the end of the migration. Is that a good idea?
That seems kind of awkward -- where would this code that did a clock tree refresh be? Also you're then reliant on all the callback functions registered to not actually do anything that affects device state when the refresh happens. It would be cleaner if the qemu-clk objects managed their own internal state migration (but can we do this without having to make them be Device objects rather than just objects ?).
Cc'd Paolo who might have an opinion on these -- my opinion currently is mostly "this doesn't really look right" rather than knowing what the right approach is.
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 2 lines
For the migration maybe we can refresh the whole clock tree at the end of the migration. Is that a good idea?
That seems kind of awkward -- where would this code that did a clock tree refresh be? Also you're then reliant on all the callback functions registered to not actually do anything that affects device state when the refresh happens. It would be cleaner if the qemu-clk objects managed their own internal state migration (but can we do this without having to make them be Device objects rather than just objects ?).
Quoted 3 lines
Cc'd Paolo who might have an opinion on these -- my opinion currently is mostly "this doesn't really look right" rather than knowing what the right approach is.
Same here. :)
I think the various bindings and rates could be refreshed as devices are migrated. This assumes that the device migration order is okay according to the clock tree, that is if you have three devices X/Y/Z and five clocks a/b/c/d/e/f:
fixed-clock
| |
X:a X:b
| | \
Y:c Y:d Z:e
|
Z:fyou could do this:
- migrate X
- retrieve the PLL ratios for a and b's bound clocks (if the ratio is variable, otherwise no need for this)
- in the post_load callback, bind a and b to the fixed-clock (if the binding is variable, otherwise no need for this)
- migrate Y
- retrieve the PLL ratio for d's bound clocks (if the ratio is variable, otherwise no need for this)
- in the post_load callback, bind c and d to a and b respectively (if the binding is variable, otherwise no need for this)
- migrate Z
- in the post_load callback, bind e and f to b and d respectively (if the binding is variable, otherwise no need for this)
Paolo
Quoted 15 lines · Paolo Bonzini
Quoted 10 lines · Peter Maydell
Quoted 2 lines
For the migration maybe we can refresh the whole clock tree at the end of the migration. Is that a good idea?
That seems kind of awkward -- where would this code that did a clock tree refresh be? Also you're then reliant on all the callback functions registered to not actually do anything that affects device state when the refresh happens. It would be cleaner if the qemu-clk objects managed their own internal state migration (but can we do this without having to make them be Device objects rather than just objects ?).
Quoted 3 lines
Cc'd Paolo who might have an opinion on these -- my opinion currently is mostly "this doesn't really look right" rather than knowing what the right approach is.
Quoted 5 lines
Same here. :)
I think the various bindings and rates could be refreshed as devices are migrated.
"This assumes that the device migration order is okay"
I think it's the real problem here?
Quoted 13 lines
according to the clock tree, that is if you have three devices X/Y/Z and five clocks a/b/c/d/e/f:
fixed-clock | | X:a X:b | | \ Y:c Y:d Z:e | Z:fyou could do this:
Quoted 14 lines
- migrate X
- retrieve the PLL ratios for a and b's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind a and b to the fixed-clock (if the binding is variable, otherwise no need for this)
- migrate Y
- retrieve the PLL ratio for d's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind c and d to a and b respectively (if the binding is variable, otherwise no need for this)
- migrate Z
- in thepost_loadcallback, bind e and f to b and d respectively (if the binding is variable, otherwise no need for this)
So for you the migration of the clock tree will be done by the device? I think this is OK :).
Fred
Quoted 2 lines
Paolo
Quoted 15 lines · Paolo Bonzini
I think the various bindings and rates could be refreshed as devices are migrated. This assumes that the device migration order is okay according to the clock tree, that is if you have three devices X/Y/Z and five clocks a/b/c/d/e/f:
fixed-clock | | X:a X:b | | \ Y:c Y:d Z:e | Z:fyou could do this:
Quoted 13 lines
- migrate X
- retrieve the PLL ratios for a and b's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind a and b to the fixed-clock (if the binding is variable, otherwise no need for this)
- migrate Y
- retrieve the PLL ratio for d's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind c and d to a and b respectively (if the binding is variable, otherwise no need for this)
- migrate Z
- in thepost_loadcallback, bind e and f to b and d respectively (if the binding is variable, otherwise no need for this)
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
(There's also the possibility of an oddball bit of hardware which has a clocktree with loops in it.)
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 3 lines · Paolo Bonzini
I think the various bindings and rates could be refreshed as devices are migrated. This assumes that the device migration order is okay according to the clock tree
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
It's device realization order, so there are some guarantees. A board can realize devices in its preferred order (and realization will also bind clocks and set rates IIUC, just like migration), and a qdev bus's children will be visited after the bus owner.
Quoted 2 lines
(There's also the possibility of an oddball bit of hardware which has a clocktree with loops in it.)
For these cases there is post_load, I guess.
Paolo
Quoted 30 lines · Peter Maydell
Quoted 15 lines · Paolo Bonzini
I think the various bindings and rates could be refreshed as devices are migrated. This assumes that the device migration order is okay according to the clock tree, that is if you have three devices X/Y/Z and five clocks a/b/c/d/e/f:
fixed-clock | | X:a X:b | | \ Y:c Y:d Z:e | Z:fyou could do this:
Quoted 13 lines
- migrate X
- retrieve the PLL ratios for a and b's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind a and b to the fixed-clock (if the binding is variable, otherwise no need for this)
- migrate Y
- retrieve the PLL ratio for d's bound clocks (if the ratio is variable, otherwise no need for this)
- in thepost_loadcallback, bind c and d to a and b respectively (if the binding is variable, otherwise no need for this)
- migrate Z
- in thepost_loadcallback, bind e and f to b and d respectively (if the binding is variable, otherwise no need for this)
Quoted 2 lines
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
How does this work for interrupts/gpios?
Perhaps we would need a way to force all clock sources that don't depend on input clocks to re-notify their clocks after migration is complete but before we run the new guest?
That would propagate updates throughout the chain...
Cheers,
Edgar
Quoted 3 lines
(There's also the possibility of an oddball bit of hardware which has a clocktree with loops in it.)
Quoted 6 lines · Edgar E. Iglesias
Quoted 2 lines · Peter Maydell
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
How does this work for interrupts/gpios?
Interrupts/gpios (qemu_irqs) don't have any internal state, so all that is needed is for both devices to correctly migrate their idea of their internal state, and it doesn't matter which order that happens in. (Typically in QEMU devices track the state of their inbound interrupt lines even if in real hardware there's no flop doing that.)
The difference here is that the clock objects themselves have internal state. That's not necessarily a bad idea, but it does mean that something's got to migrate that state or otherwise regenerate it. (Anthony once proposed that we should change qemu_irq objects to have internal state, because that's effectively what real hardware is and it would save the need for each device to track its input line state and be notified if the line didn't actually change state. It would just have been an enormous upheaval and migration compat break...)
thanks
-- PMM
Quoted 15 lines · Peter Maydell
Quoted 6 lines · Edgar E. Iglesias
Quoted 2 lines · Peter Maydell
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
How does this work for interrupts/gpios?
Interrupts/gpios (
qemu_irqs) don't have any internal state, so all that is needed is for both devices to correctly migrate their idea of their internal state, and it doesn't matter which order that happens in. (Typically in QEMU devices track the state of their inbound interrupt lines even if in real hardware there's no flop doing that.)
Quoted 9 lines
The difference here is that the clock objects themselves have internal state. That's not necessarily a bad idea, but it does mean that something's got to migrate that state or otherwise regenerate it. (Anthony once proposed that we should change
qemu_irqobjects to have internal state, because that's effectively what real hardware is and it would save the need for each device to track its input line state and be notified if the line didn't actually change state. It would just have been an enormous upheaval and migration compat break...)
Thanks. I didn't realize that the internal clock state would be used in a way that is not deriveable from other device state & input clocks. I'm not sure this is a use-case we need to support, thoughts?
Maybe there's some value in keeping interrupt and clock handling alike, e.g removing the internal state from clocks.
I need to have another look at the series before I comment too much since I don't remember the details...
Best regards,
Edgar
Quoted 30 lines · Edgar E. Iglesias
Quoted 15 lines · Peter Maydell
Quoted 6 lines · Edgar E. Iglesias
Quoted 2 lines · Peter Maydell
Unfortunately we make no guarantees at all about migration order for devices as far as I'm aware, so devices have to cope regardless.
How does this work for interrupts/gpios?
Interrupts/gpios (
qemu_irqs) don't have any internal state, so all that is needed is for both devices to correctly migrate their idea of their internal state, and it doesn't matter which order that happens in. (Typically in QEMU devices track the state of their inbound interrupt lines even if in real hardware there's no flop doing that.)Quoted 9 lines
The difference here is that the clock objects themselves have internal state. That's not necessarily a bad idea, but it does mean that something's got to migrate that state or otherwise regenerate it. (Anthony once proposed that we should change
qemu_irqobjects to have internal state, because that's effectively what real hardware is and it would save the need for each device to track its input line state and be notified if the line didn't actually change state. It would just have been an enormous upheaval and migration compat break...)Thanks. I didn't realize that the internal clock state would be used in a way that is not deriveable from other device state & input clocks. I'm not sure this is a use-case we need to support, thoughts?
Quoted 6 lines
Maybe there's some value in keeping interrupt and clock handling alike, e.g removing the internal state from clocks.
I need to have another look at the series before I comment too much since I don't remember the details...
The use case for that is essentially knowing the rate value when needed:
* for example in the monitor.
* if don't want to refresh the whole tree.
For the rest.. yes we can just keep the value in the device state..
Fred
Quoted 3 lines
Best regards,
Edgar
Quoted 11 lines · Edgar E. Iglesias
Quoted 9 lines · Peter Maydell
The difference here is that the clock objects themselves have internal state. That's not necessarily a bad idea, but it does mean that something's got to migrate that state or otherwise regenerate it. (Anthony once proposed that we should change
qemu_irqobjects to have internal state, because that's effectively what real hardware is and it would save the need for each device to track its input line state and be notified if the line didn't actually change state. It would just have been an enormous upheaval and migration compat break...)
Quoted 6 lines
Thanks. I didn't realize that the internal clock state would be used in a way that is not deriveable from other device state & input clocks. I'm not sure this is a use-case we need to support, thoughts?
Maybe there's some value in keeping interrupt and clock handling alike, e.g removing the internal state from clocks.
It occurs to me that it might be possible to split the difference, ie the clock object still has internal state, but the device that owns it is responsible for that state's migration, so you would have
VMSTATE_CLOCK(myclock, MyDeviceState),
in the vmstate for every clock you owned. (Not sure whether that should be "every input clock" or "every output clock" or even both?)
As an aside, I still find it very odd that you get a clock object for both an input clock and an output clock. I feel like we should have one end owns the clock object and the other just has a reference to it of some kind.
thanks
-- PMM
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Edgar E. Iglesias
Quoted 9 lines · Peter Maydell
The difference here is that the clock objects themselves have internal state. That's not necessarily a bad idea, but it does mean that something's got to migrate that state or otherwise regenerate it. (Anthony once proposed that we should change
qemu_irqobjects to have internal state, because that's effectively what real hardware is and it would save the need for each device to track its input line state and be notified if the line didn't actually change state. It would just have been an enormous upheaval and migration compat break...)Thanks. I didn't realize that the internal clock state would be used in a way that is not deriveable from other device state & input clocks. I'm not sure this is a use-case we need to support, thoughts?
Quoted 8 lines
Quoted 2 lines
Maybe there's some value in keeping interrupt and clock handling alike, e.g removing the internal state from clocks.
It occurs to me that it might be possible to split the difference, ie the clock object still has internal state, but the device that owns it is responsible for that state's migration, so you would have
VMSTATE_CLOCK(myclock, MyDeviceState),
Yes I think that makes sense.
Quoted 9 lines
in the vmstate for every clock you owned. (Not sure whether that should be "every input clock" or "every output clock" or even both?)
As an aside, I still find it very odd that you get a clock object for both an input clock and an output clock. I feel like we should have one end owns the clock object and the other just has a reference to it of some kind.
The point is beeing able to bind/unbind clocks inside the device to model a clock selector for example. So you just bind/unbind the input and output clocks.
Secondly you can print the clock input rate in the mtree command so you can eg: debug it.
Thanks,
Fred
Quoted 4 lines
thanks
-- PMM
Quoted 10 lines · KONRAD Frederic
Quoted 4 lines · Peter Maydell
As an aside, I still find it very odd that you get a clock object for both an input clock and an output clock. I feel like we should have one end owns the clock object and the other just has a reference to it of some kind.
The point is beeing able to bind/unbind clocks inside the device to model a clock selector for example. So you just bind/unbind the input and output clocks.
I don't see why this needs both 'input clock' and 'output clock' to be separate objects. What I have in mind is:
Device A:
has-a clock C1
Device B:
has-a clock C2
Device C: (a clock selector)
clock inputs CI1, CI2
has-a clock C3
Each device "owns" its output clock objects, but input clocks are just pointers to the clock object owned by the device at the other end. In the board you wire up CI1 to C1, and CI2 to C2 (using link properties I guess). Then in device C you can implement the clock switching by some kind of bind(s->CI1, &s->C3) call because you have pointers to all the relevant clock objects.
As I understand it your current implementation makes not just the output clocks C1 C2 C2 be clock objects, but also the inputs CI1 CI2, so effectively each link from a clock source to a clock sink has two objects involved.
thanks
-- PMM
Quoted 33 lines · Peter Maydell
Quoted 10 lines · KONRAD Frederic
Quoted 4 lines · Peter Maydell
As an aside, I still find it very odd that you get a clock object for both an input clock and an output clock. I feel like we should have one end owns the clock object and the other just has a reference to it of some kind.
The point is beeing able to bind/unbind clocks inside the device to model a clock selector for example. So you just bind/unbind the input and output clocks.
I don't see why this needs both 'input clock' and 'output clock' to be separate objects. What I have in mind is:
Device A:
has-a clock C1Device B:
has-a clock C2Device C: (a clock selector)
clock inputs CI1, CI2
has-a clock C3Each device "owns" its output clock objects, but input clocks are just pointers to the clock object owned by the device at the other end. In the board you wire up CI1 to C1, and CI2 to C2 (using link properties I guess). Then in device C you can implement the clock switching by some kind of
bind(s->CI1, &s->C3)call because you have pointers to all the relevant clock objects.
Quoted 4 lines
As I understand it your current implementation makes not just the output clocks C1 C2 C2 be clock objects, but also the inputs CI1 CI2, so effectively each link from a clock source to a clock sink has two objects involved.
Yes that makes sense but you won't have the name.
And one other thing I wanted to have is beeing able to refresh the clock tree without refreshing everything. If you start a refresh from the "pointer" and it is bind to other things you will refresh the other devices as well. Maybe we don't care or we can workaround that but..
Fred
Quoted 4 lines
thanks
-- PMM
Quoted 9 lines · KONRAD Frederic
Quoted 8 lines · Peter Maydell
Each device "owns" its output clock objects, but input clocks are just pointers to the clock object owned by the device at the other end. In the board you wire up CI1 to C1, and CI2 to C2 (using link properties I guess). Then in device C you can implement the clock switching by some kind of
bind(s->CI1, &s->C3)call because you have pointers to all the relevant clock objects.
Quoted 6 lines
Quoted 4 lines
As I understand it your current implementation makes not just the output clocks C1 C2 C2 be clock objects, but also the inputs CI1 CI2, so effectively each link from a clock source to a clock sink has two objects involved.
Yes that makes sense but you won't have the name.
I don't think that's a big deal.
Quoted 5 lines
And one other thing I wanted to have is beeing able to refresh the clock tree without refreshing everything. If you start a refresh from the "pointer" and it is bind to other things you will refresh the other devices as well. Maybe we don't care or we can workaround that but..
The pointer is for your clock inputs -- when would you want to start a refresh from that? I would expect refreshes to only ever go downstream -- you update the config of your clock outputs and things downstream of them will update in turn.
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 9 lines · KONRAD Frederic
Quoted 8 lines · Peter Maydell
Each device "owns" its output clock objects, but input clocks are just pointers to the clock object owned by the device at the other end. In the board you wire up CI1 to C1, and CI2 to C2 (using link properties I guess). Then in device C you can implement the clock switching by some kind of
bind(s->CI1, &s->C3)call because you have pointers to all the relevant clock objects.Quoted 6 lines
Quoted 4 lines
As I understand it your current implementation makes not just the output clocks C1 C2 C2 be clock objects, but also the inputs CI1 CI2, so effectively each link from a clock source to a clock sink has two objects involved.
Yes that makes sense but you won't have the name.
I don't think that's a big deal.
Quoted 5 lines
And one other thing I wanted to have is beeing able to refresh the clock tree without refreshing everything. If you start a refresh from the "pointer" and it is bind to other things you will refresh the other devices as well. Maybe we don't care or we can workaround that but..
Quoted 5 lines
The pointer is for your clock inputs -- when would you want to start a refresh from that? I would expect refreshes to only ever go downstream -- you update the config of your clock outputs and things downstream of them will update in turn.
I started with the goal in mind that the binding + the callback can refresh themself without user intervention.
So actually the user only have to change the binding in case of a clock selector.. Everything else is done by the framework.
For example if we want to change a multiplier through a register:
void register_write(..)
{
/* Refresh related clock input. */
}
void clock_cb(..)
{
return register_value * rate_in;
}
If we drop the clock first possibility:
void register_write(..)
{
/* refresh all depending clock with
* rate_in * register value.
* Either this can be tricky as we need to know exactly which
* clock need to be refreshed or we need to refresh everybody.
* On the device example in the patch-set this can become a
* mess.
*/
}
void clock_cb(..)
{
return register_value * rate_in;
}
Second possibility:
void register_write(..)
{
/* refresh the clock which is referenced as input.
* This is easy BUT it will refresh all other devices bound to
* this clock.
*/
}
void clock_cb(..)
{
return register_value * rate_in;
}
Thanks,
Fred
Quoted 4 lines
thanks
-- PMM
Quoted 8 lines · KONRAD Frederic
Quoted 5 lines · Peter Maydell
The pointer is for your clock inputs -- when would you want to start a refresh from that? I would expect refreshes to only ever go downstream -- you update the config of your clock outputs and things downstream of them will update in turn.
Quoted 5 lines
I started with the goal in mind that the binding + the callback can refresh themself without user intervention.
So actually the user only have to change the binding in case of a clock selector.. Everything else is done by the framework.
I agree you only need to change the bindings for clock selectors, that should be true whatever approach we take.
Quoted 30 lines
For example if we want to change a multiplier through a register:
void
register_write(..)
{
/* Refresh related clock input. */
}void
clock_cb(..)
{
returnregister_value*rate_in;
}If we drop the clock first possibility:
void
register_write(..)
{
/* refresh all depending clock with
*rate_in* register value.
* Either this can be tricky as we need to know exactly which
* clock need to be refreshed or we need to refresh everybody.
* On the device example in the patch-set this can become a
* mess.
*/
}void
clock_cb(..)
{
returnregister_value*rate_in;
}
Quoted 8 lines
Second possibility:
void
register_write(..)
{
/* refresh the clock which is referenced as input.
* This is easy BUT it will refresh all other devices bound to
* this clock.
*/
If this device can change the multiplier for a clock then it must be changing the multiplier for one of its *output* clocks. The input clock is owned by whatever device controls that clock. (In hardware, a device can't change the frequency of a clock signal that is an input to it.)
Eg you might have a fixed clock (output) representing the system clock, and a PLL device which takes that clock as an input, and has one or more output clocks at various rates whose multipliers can be changed. Changing the multiplier value in a register in the PLL device should make it change and refresh the relevant output clock. (If a device has a builtin clock divider then you'd model that as it having an input clock, plus an "output" clock which it doesn't actually expose to the rest of the world but just consumes internally. The builtin divider would change the settings on the 'output' clock.)
thanks
-- PMM