Clock framework API.
Subsystems (2)
v2 cover Clock framework API.
From: KONRAD Frederic <[email protected]>
Hi,
This is the second 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
(a9e404600a9bd1e6a26431fc89e5069092e67f14).
Thanks,
Fred
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 | 108 +++++ 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 | 174 ++++++++ 11 files changed, 1598 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 v2 1/10 qemu-clk: introduce qemu-clk qom object
From: KONRAD Frederic <[email protected]>
This introduces qemu-clk qom object.
--- 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
@@ -78,6 +78,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(struct qemu_clk, (obj), TYPE_CLOCK) + +typedef struct qemu_clk { +/*< private >*/ +Object parent_obj; +} *qemu_clk ; + +#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
Re: [Qemu-devel] [PATCH V2 01/10] qemu-clk: introduce qemu-clk qom object
ello Frederic,
Quoted 41 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This introduces qemu-clk qom object.
Signed-off-by KONRAD Frederic <[email protected]>--- 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.cMakefile.objs +1
-0@@ -78,6 +78,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 ###################################################################### # qapiinclude/qemu/qemu-clock.h new file +10
-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
include/qemu/qemu-clock.h line 20
Quoted 10 lines
include/qemu/qemu-clock.h new file +10
-0+* 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/>.
May be we could shorten the GPL v2 statement to something like :
* This code is licensed under the GPL version 2 or later. See the
* COPYING file in the top-level directory.
I haven't been very good at that my self, but we could save quite a few lines in qemu if files were not repeating the License statement.
Quoted 7 lines
include/qemu/qemu-clock.h new file +6
-0+* +*/ + +#ifndef QEMU_CLOCK_H +#define QEMU_CLOCK_H +
include/qemu/qemu-clock.h line 36
Quoted 10 lines
include/qemu/qemu-clock.h new file +10
-0+#include "qemu/osdep.h" +#include "qom/object.h" + +#define TYPE_CLOCK "qemu-clk" +#define QEMU_CLOCK (obj) OBJECT_CHECK(struct qemu_clk, (obj), TYPE_CLOCK) + +typedef struct qemu_clk { +/*< private >*/ +Object parent_obj; +} *qemu_clk ;
CODING_STYLE says that we should use CamelCase for typedef. Also, I don't think the '*' is required. What's the idea ?
Quoted 36 lines
include/qemu/qemu-clock.h new file +3
-0+#endif /* QEMU_CLOCK_H */ + +qemu-clock.c new file +27
-0@@ -0,0 +1,50 @@ +/* +* 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/>. +* +*/ + +#include "qemu/osdep.h" +#include "qemu/qemu-clock.h" +#include "hw/hw.h" +#include "qemu/log.h"
qemu-clock.c line 37
Quoted 10 lines
qemu-clock.c new file +10
-0+ +#ifndef DEBUG_QEMU_CLOCK +#define DEBUG_QEMU_CLOCK 0 +#endif + +#define DPRINTF(fmt, args...) do { \ + if (DEBUG_QEMU_CLOCK) { \ + qemu_log("%s: " fmt, __func__, ## args); \ + } \ +} while (0);
I think the trace framework should be used instead.
Thanks
C.
Quoted 13 lines
qemu-clock.c new file +12
-0+static const TypeInfo qemu_clk_info = { + .name =TYPE_CLOCK , + .parent =TYPE_OBJECT , + .instance_size =sizeof (struct qemu_clk ), +}; + +static void qemu_clk_register_types (void ) +{ +type_register_static (&qemu_clk_info); +} + +type_init (qemu_clk_register_types);
Re: [Qemu-devel] [PATCH V2 01/10] qemu-clk: introduce qemu-clk qom object
Quoted 1 line · Cédric Le Goater
ello Frederic,
Hi Cédric,
Thanks for taking a look at this!
Quoted 56 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
Quoted 41 lines
From: KONRAD Frederic <[email protected]>
This introduces qemu-clk qom object.
Signed-off-by KONRAD Frederic <[email protected]>--- 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.cMakefile.objs +1
-0@@ -78,6 +78,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 ###################################################################### # qapiinclude/qemu/qemu-clock.h new file +10
-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 include/qemu/qemu-clock.h line 20
Quoted 10 lines
include/qemu/qemu-clock.h new file +10
-0+* 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/>. May be we could shorten the GPL v2 statement to something like :
Quoted 6 lines
* This code is licensed under the GPL version 2 or later. See the
* COPYING file in the top-level directory.I haven't been very good at that my self, but we could save quite a few lines in qemu if files were not repeating the License statement.
Well if it is really needed I can get rid of this few lines :).
Quoted 14 lines
Quoted 14 lines
include/qemu/qemu-clock.h new file +12
-0+* +*/ + +#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(struct qemu_clk, (obj), TYPE_CLOCK) +
Quoted 8 lines
include/qemu/qemu-clock.h line 36
Quoted 5 lines
include/qemu/qemu-clock.h new file +4
-0+typedef struct qemu_clk { +/*< private >*/ +Object parent_obj; +} *qemu_clk ;
CODING_STYLEsays that we should use CamelCase for typedef. Also, I don't think the '*' is required. What's the idea ?
Your right, I tried to follow the gpio "style".. But maybe it's old and we better go for the camelcase and without the pointer.
Quoted 41 lines
Quoted 41 lines
include/qemu/qemu-clock.h new file +3
-0+#endif /* QEMU_CLOCK_H */ + +qemu-clock.c new file +31
-0@@ -0,0 +1,50 @@ +/* +* 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/>. +* +*/ + +#include "qemu/osdep.h" +#include "qemu/qemu-clock.h" +#include "hw/hw.h" +#include "qemu/log.h" + +#ifndef DEBUG_QEMU_CLOCK +#define DEBUG_QEMU_CLOCK 0 +#endif
Quoted 8 lines
qemu-clock.c line 37
Quoted 6 lines
qemu-clock.c new file +6
-0+ +#define DPRINTF(fmt, args...) do { \ + if (DEBUG_QEMU_CLOCK) { \ + qemu_log("%s: " fmt, __func__, ## args); \ + } \ +} while (0);I think the trace framework should be used instead.
Seems not really standard AFAIK.
Some files use printf, some other qemu_log etc..
Thanks,
Fred
Quoted 20 lines
Thanks
C.
Quoted 13 lines
qemu-clock.c new file +12
-0+static const TypeInfo qemu_clk_info = { + .name =TYPE_CLOCK , + .parent =TYPE_OBJECT , + .instance_size =sizeof (struct qemu_clk ), +}; + +static void qemu_clk_register_types (void ) +{ +type_register_static (&qemu_clk_info); +} + +type_init (qemu_clk_register_types);
PATCH v2 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.
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 qemu_clk {/*< private >*/ Object parent_obj; +char *name;/* name of this clock in the device. */ } *qemu_clk ; -#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,qemu_clk 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. +*/ +qemu_clk 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,qemu_clk 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); +} + +qemu_clk 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
Re: [Qemu-devel] [PATCH V2 02/10] qemu-clk: allow to add a clock to a device
Quoted 78 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
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.Signed-off-by KONRAD Frederic <[email protected]>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 qemu_clk {/*< private >*/ Object parent_obj; +char *name;/* name of this clock in the device. */ } *qemu_clk ; -#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,qemu_clk 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. +*/ +qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name); +#endif /* QEMU_CLOCK_H */ qemu-clock.c +12
-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,qemu_clk 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); +} + +qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name) +{
qemu-clock.c line 60
Quoted 10 lines
qemu-clock.c +10
-0+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); +}
I see how these routines are used in patch 10/10. But if we were open coding device CRF_APB, I don't think we would need them at all and it would make the code a little simple IMHO.
Thanks,
C.
Quoted 4 lines
qemu-clock.c +0
-0static const TypeInfo qemu_clk_info = { .name =TYPE_CLOCK , .parent =TYPE_OBJECT ,
Re: [Qemu-devel] [PATCH V2 02/10] qemu-clk: allow to add a clock to a device
Quoted 86 lines · Cédric Le Goater
Quoted 85 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
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.Signed-off-by KONRAD Frederic <[email protected]>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 qemu_clk {/*< private >*/ Object parent_obj; +char *name;/* name of this clock in the device. */ } *qemu_clk ; -#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,qemu_clk 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. +*/ +qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name); +#endif /* QEMU_CLOCK_H */ qemu-clock.c +19
-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,qemu_clk 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); +} + +qemu_clk 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);
Quoted 8 lines
qemu-clock.c line 60
Quoted 3 lines
qemu-clock.c +3
-0+g_free (path); +return QEMU_CLOCK (clk); +}I see how these routines are used in patch 10/10. But if we were open coding device
CRF_APB, I don't think we would need them at all and it would make the code a little simple IMHO.
What do you mean by open coding?
Fred
Quoted 11 lines
Thanks,
C.
Quoted 4 lines
qemu-clock.c +0
-0static const TypeInfo qemu_clk_info = { .name =TYPE_CLOCK , .parent =TYPE_OBJECT ,
Re: [Qemu-devel] [PATCH V2 02/10] qemu-clk: allow to add a clock to a device
Quoted 4 lines · Frederic Konrad
Quoted 3 lines
I see how these routines are used in patch 10/10. But if we were open coding device
CRF_APB, I don't think we would need them at all and it would make the code a little simple IMHO.What do you mean by open coding?
I mean to externalize the definition of the objects in a header file.
Then you can replace the type 'Object *' of the attribute holding a reference to an instance by a non pointer type.
Anyhow, I think we need to replace object_new() by object_initialize() for QOM, and so we need to expose a little more the object internals.
Thanks,
C.
Re: [Qemu-devel] [PATCH V2 02/10] qemu-clk: allow to add a clock to a device
Quoted 9 lines · Cédric Le Goater
Quoted 4 lines · Frederic Konrad
Quoted 3 lines
I see how these routines are used in patch 10/10. But if we were open coding device
CRF_APB, I don't think we would need them at all and it would make the code a little simple IMHO.What do you mean by open coding?
I mean to externalize the definition of the objects in a header file.
Quoted 6 lines
Then you can replace the type 'Object *' of the attribute holding a reference to an instance by a non pointer type.
Anyhow, I think we need to replace
object_new()byobject_initialize()for QOM, and so we need to expose a little more the object internals.
Ok got you.
I'll take a look.
Thanks,
Fred
Quoted 6 lines
Thanks,
C.
PATCH v2 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.
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 | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+)
include/qemu/qemu-clock.h +67 -0
@@ -30,12 +30,25 @@#define TYPE_CLOCK "qemu-clk"#define QEMU_CLOCK (obj) OBJECT_CHECK(struct qemu_clk, (obj), TYPE_CLOCK) +typedef struct ClkList ClkList ; +typedef uint64_t QEMUClkRateUpdateCallback (void *opaque,uint64_t rate); +typedef struct qemu_clk {/*< private >*/ Object parent_obj;char *name;/* name of this clock in the device. */ +uint64_t in_rate;/* rate of the clock which drive this pin. */ +uint64_t out_rate;/* rate of this clock pin. */ +void *opaque; +QEMUClkRateUpdateCallback *cb; + QLIST_HEAD(, ClkList) bound; } *qemu_clk ; +struct ClkList { +qemu_clk 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, qemu_clk clk,*/ qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name); +/** +* qemu_clk_bind_clock: +* @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_clock (qemu_clk out,qemu_clk in); + +/** +* qemu_clk_unbind: +* @out: the clock output. +* @in: the clock input. +* +* Disconnect the clocks if they were bound together. +* +*/ +void qemu_clk_unbind (qemu_clk out,qemu_clk 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 (qemu_clk 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 (qemu_clk 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 (qemu_clk clk, +QEMUClkRateUpdateCallback *cb, +void *opaque); +#endif /* QEMU_CLOCK_H */
qemu-clock.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH V2 03/10] qemu-clk: allow to bind two clocks together
Hello,
Quoted 24 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This introduces the clock binding and the update part.
When theqemu_clk_rate_update(qemu_clk, int)function is called:
* The clock callback is called on theqemu_clkso it can change the rate.
* Theqemu_clk_rate_updatefunction is called on all the driven clock.Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Renameqemu_clk_on_rate_update_cbto 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 | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+)include/qemu/qemu-clock.h +0
-0@@ -30,12 +30,25 @@#define TYPE_CLOCK "qemu-clk"
include/qemu/qemu-clock.h line 40
Quoted 10 lines
include/qemu/qemu-clock.h +4
-0#define QEMU_CLOCK (obj) OBJECT_CHECK(struct qemu_clk, (obj), TYPE_CLOCK) +typedef struct ClkList ClkList ; +typedef uint64_t QEMUClkRateUpdateCallback (void *opaque,uint64_t rate); + typedef struct qemu_clk { /*< private >*/ Object parent_obj; char *name; /* name of this clock in the device. */ + uint64_t in_rate; /* rate of the clock which drive this pin. */
So if this is the reference clock rate, which can be divided by settings in control registers, I would call the attribute 'ref_rate' or 'rate_reference'
include/qemu/qemu-clock.h line 41
Quoted 1 line
include/qemu/qemu-clock.h +1
-0+uint64_t out_rate;/* rate of this clock pin. */
and this attribute could just be 'rate' and may be if we make a property out of it, we could get rid of FixedClock in patch 7/10.
include/qemu/qemu-clock.h line 43
Quoted 2 lines
include/qemu/qemu-clock.h +2
-0+void *opaque; +QEMUClkRateUpdateCallback *cb;
If I understand correctly, the need is to be able to refresh the rate of a clock object depending on some settings in a controller. I think we should be using a derived class and an operation for it. it would look better from a QOM point of view.
Here is a possibility,
We could make 'rate' a property and use a set property handler to call the derived class specific operation. This is very similar to the callback but we would remove the need of qemu_clk_update_rate() and use the std mechanisms already in place :
object_property_set_int()
qemu_clk_refresh() would still be needed to propagate the changes in the settings of a controller to the target clocks.
The 'opaque' attribute, which holds the pointer to a controller object, would have to be passed to the derived clock object with
object_property_add_const_link()
and then grabbed with
object_property_get_link()
in the realize function of the derived clock object, or whenever it's needed, in the operation for instance.
This clearly means more code than the actual solution, but that is QOM way I think.
include/qemu/qemu-clock.h line 51
Quoted 8 lines
include/qemu/qemu-clock.h +6
-0+ QLIST_HEAD(, ClkList) bound; } *qemu_clk; +struct ClkList { +qemu_clk clk; +QLIST_ENTRY (ClkList) node; +}; +
Do we really need this intermediate object ? Can't we just put the list_entry attribute under qemu_clk ? I haven't tried, may be I am wrong but that would simplify the code.
Quoted 7 lines
include/qemu/qemu-clock.h +0
-0/** * 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, qemu_clk clk,*/ qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name);
include/qemu/qemu-clock.h void qemu_clk_device_add_clock(DeviceState *dev, qemu_clk clk, · line 84
Quoted 10 lines
include/qemu/qemu-clock.h +10
-0+/** +* qemu_clk_bind_clock: +* @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_clock (qemu_clk out,qemu_clk in);
maybe remove the _clock suffix. It feels redundant.
Thanks,
C.
Quoted 114 lines
include/qemu/qemu-clock.h +44
-0+ +/** +* qemu_clk_unbind: +* @out: the clock output. +* @in: the clock input. +* +* Disconnect the clocks if they were bound together. +* +*/ +void qemu_clk_unbind (qemu_clk out,qemu_clk 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 (qemu_clk 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 (qemu_clk 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 (qemu_clk clk, +QEMUClkRateUpdateCallback *cb, +void *opaque); +#endif /*
QEMU_CLOCK_H*/qemu-clock.c +56
-0@@ -37,6 +37,62 @@ } \ }while (0 ); +void qemu_clk_refresh (qemu_clk clk) +{ +qemu_clk_update_rate (clk, clk->in_rate); +} + +void qemu_clk_update_rate (qemu_clk clk,uint64_t rate) +{ +ClkList *child; + + clk->in_rate = rate; + clk->out_rate = rate; + +if (clk->cb) { + clk->out_rate = clk->cb (clk->opaque, rate); + } + +DPRINTF ("%s output rate updated to %" PRIu64"\n" , +object_get_canonical_path (OBJECT (clk)), + clk->out_rate); + + QLIST_FOREACH(child, &clk->bound, node) { +qemu_clk_update_rate (child->clk, clk->out_rate); + } +} + +void qemu_clk_bind_clock (qemu_clk out,qemu_clk in) +{ +ClkList *child; + + child =g_malloc (sizeof (child)); +assert (child); + child->clk = in; +QLIST_INSERT_HEAD (&out->bound, child, node); +qemu_clk_update_rate (in, out->out_rate); +} + +void qemu_clk_unbind (qemu_clk out,qemu_clk in) +{ +ClkList *child, *next; + + QLIST_FOREACH_SAFE(child, &out->bound, node, next) { +if (child->clk == in) { +QLIST_REMOVE (child, node); +g_free (child); + } + } +} + +void qemu_clk_set_callback (qemu_clk clk, +QEMUClkRateUpdateCallback *cb, +void *opaque) +{ + clk->cb = cb; + clk->opaque = opaque; +} +void qemu_clk_device_add_clock (DeviceState *dev,qemu_clk clk,const char *name) {
Re: [Qemu-devel] [PATCH V2 03/10] qemu-clk: allow to bind two clocks together
Quoted 79 lines · Cédric Le Goater
Hello,
Quoted 24 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This introduces the clock binding and the update part.
When theqemu_clk_rate_update(qemu_clk, int)function is called:
* The clock callback is called on theqemu_clkso it can change the rate.
* Theqemu_clk_rate_updatefunction is called on all the driven clock.Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Renameqemu_clk_on_rate_update_cbto 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 | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+)include/qemu/qemu-clock.h +0
-0@@ -30,12 +30,25 @@#define TYPE_CLOCK "qemu-clk"include/qemu/qemu-clock.h line 40
Quoted 10 lines
include/qemu/qemu-clock.h +4
-0#define QEMU_CLOCK (obj) OBJECT_CHECK(struct qemu_clk, (obj), TYPE_CLOCK) +typedef struct ClkList ClkList ; +typedef uint64_t QEMUClkRateUpdateCallback (void *opaque,uint64_t rate); + typedef struct qemu_clk { /*< private >*/ Object parent_obj; char *name; /* name of this clock in the device. */ + uint64_t in_rate; /* rate of the clock which drive this pin. */So if this is the reference clock rate, which can be divided by settings in control registers, I would call the attribute '
ref_rate' or 'rate_reference'include/qemu/qemu-clock.h line 41
Quoted 1 line
include/qemu/qemu-clock.h +1
-0+uint64_t out_rate;/* rate of this clock pin. */ and this attribute could just be 'rate' and may be if we make a property out of it, we could get rid of FixedClock in patch 7/10.
include/qemu/qemu-clock.h line 43
Quoted 2 lines
include/qemu/qemu-clock.h +2
-0+void *opaque; +QEMUClkRateUpdateCallback *cb;If I understand correctly, the need is to be able to refresh the rate of a clock object depending on some settings in a controller. I think we should be using a derived class and an operation for it. it would look better from a QOM point of view.
Here is a possibility,
We could make 'rate' a property and use a set property handler to call the derived class specific operation. This is very similar to the callback but we would remove the need of
qemu_clk_update_rate()and use the std mechanisms already in place :
object_property_set_int()
qemu_clk_refresh()would still be needed to propagate the changes in the settings of a controller to the target clocks.The 'opaque' attribute, which holds the pointer to a controller object, would have to be passed to the derived clock object with
object_property_add_const_link()and then grabbed with
Quoted 7 lines
object_property_get_link()in the realize function of the derived clock object, or whenever it's needed, in the operation for instance.
This clearly means more code than the actual solution, but that is QOM way I think.
Yes, the big issue here is that there are several clock inputs and clock outputs. We need to be able to bind / unbind them if there is a selector or some such.
So a device will have more than one clock object internally in it which are "chained" to form a clock tree.
It seems overkill to me to implement one derived object per clock "block" in the device to get the callback.
Quoted 4 lines
Quoted 4 lines
include/qemu/qemu-clock.h +1
-0+ QLIST_HEAD(, ClkList) bound; } *qemu_clk;
Quoted 9 lines
include/qemu/qemu-clock.h line 51
Quoted 5 lines
include/qemu/qemu-clock.h +5
-0+struct ClkList { +qemu_clk clk; +QLIST_ENTRY (ClkList) node; +}; +Do we really need this intermediate object ? Can't we just put the
list_entryattribute underqemu_clk? I haven't tried, may be I am wrong but that would simplify the code.
Yes I think it is needed. Actually I didn't find anything which does this differently.
Quoted 8 lines
Quoted 8 lines
include/qemu/qemu-clock.h +0
-0/** * 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, qemu_clk clk,*/ qemu_clk qemu_clk_device_get_clock (DeviceState *dev,const char *name);
Quoted 12 lines
include/qemu/qemu-clock.h void qemu_clk_device_add_clock(DeviceState *dev, qemu_clk clk, · line 84
Quoted 10 lines
include/qemu/qemu-clock.h +10
-0+/** +* qemu_clk_bind_clock: +* @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_clock (qemu_clk out,qemu_clk in);maybe remove the
_clocksuffix. It feels redundant.
Ok.
Thanks,
Fred
Quoted 121 lines
Thanks,
C.
Quoted 114 lines
include/qemu/qemu-clock.h +44
-0+ +/** +* qemu_clk_unbind: +* @out: the clock output. +* @in: the clock input. +* +* Disconnect the clocks if they were bound together. +* +*/ +void qemu_clk_unbind (qemu_clk out,qemu_clk 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 (qemu_clk 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 (qemu_clk 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 (qemu_clk clk, +QEMUClkRateUpdateCallback *cb, +void *opaque); +#endif /*
QEMU_CLOCK_H*/qemu-clock.c +56
-0@@ -37,6 +37,62 @@ } \ }while (0 ); +void qemu_clk_refresh (qemu_clk clk) +{ +qemu_clk_update_rate (clk, clk->in_rate); +} + +void qemu_clk_update_rate (qemu_clk clk,uint64_t rate) +{ +ClkList *child; + + clk->in_rate = rate; + clk->out_rate = rate; + +if (clk->cb) { + clk->out_rate = clk->cb (clk->opaque, rate); + } + +DPRINTF ("%s output rate updated to %" PRIu64"\n" , +object_get_canonical_path (OBJECT (clk)), + clk->out_rate); + + QLIST_FOREACH(child, &clk->bound, node) { +qemu_clk_update_rate (child->clk, clk->out_rate); + } +} + +void qemu_clk_bind_clock (qemu_clk out,qemu_clk in) +{ +ClkList *child; + + child =g_malloc (sizeof (child)); +assert (child); + child->clk = in; +QLIST_INSERT_HEAD (&out->bound, child, node); +qemu_clk_update_rate (in, out->out_rate); +} + +void qemu_clk_unbind (qemu_clk out,qemu_clk in) +{ +ClkList *child, *next; + + QLIST_FOREACH_SAFE(child, &out->bound, node, next) { +if (child->clk == in) { +QLIST_REMOVE (child, node); +g_free (child); + } + } +} + +void qemu_clk_set_callback (qemu_clk clk, +QEMUClkRateUpdateCallback *cb, +void *opaque) +{ + clk->cb = cb; + clk->opaque = opaque; +} +void qemu_clk_device_add_clock (DeviceState *dev,qemu_clk clk,const char *name) {
PATCH v2 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.
--- 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) +{ +qemu_clk *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 (qemu_clk clk) {qemu_clk_update_rate (clk, clk->in_rate);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH V2 04/10] qemu-clk: introduce an init array to help the device construction
Quoted 3 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This introduces a clock init array to ease the clock tree construction.
I think this belongs to the zynqmp-crf model.
Thanks,
C.
Quoted 77 lines
Signed-off-by KONRAD Frederic <[email protected]>--- 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) +{ +qemu_clk *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 (qemu_clk clk) {qemu_clk_update_rate (clk, clk->in_rate);
PATCH v2 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(qemu_clk 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
@@ -29,6 +29,7 @@#include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" +#include "qemu/qemu-clock.h" /* * Aliases were a bad idea from the start. Let's keep them
@@ -689,6 +690,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
@@ -132,6 +133,33 @@ qemu_clk 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) +{ +qemu_clk clk = (qemu_clk)(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->out_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
Re: [Qemu-devel] [PATCH V2 05/10] qdev-monitor: print the device's clock with info qtree
Quoted 4 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This prints the clock attached to a DeviceState when using "info qtree" monitor command.
It would be nice to print the bound clocks also.
And so, may be, we could handle this binding between clocks simply by using object_property_add_child() on the objects and build a QOM clock hierarchy.
I would certainly make sense from a physical POV but would that be possible ?
Thanks,
C.
Quoted 127 lines
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/000000000000010cSigned-off-by KONRAD Frederic <[email protected]>--- 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(qemu_clk 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@@ -29,6 +29,7 @@#include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" +#include "qemu/qemu-clock.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -689,6 +690,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@@ -132,6 +133,33 @@ qemu_clk 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) +{ +qemu_clk clk = (qemu_clk)(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->out_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 ,
PATCH v2 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 | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 docs/clock.txt
docs/clock.txt new file +108 -0
@@ -0,0 +1,108 @@ + +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 +with the unmodified rate. + +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.
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH V2 06/10] docs: add qemu-clock documentation
Quoted 4 lines · On 26 January 2017 at 09:47, <[email protected]> wrote:
From: KONRAD Frederic <[email protected]>
This adds the qemu-clock documentation.
Quoted 8 lines
Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Fixed in accordance with the changes in the previous patches.--- docs/clock.txt | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 docs/clock.txt
Could we have a simple example of what you need to do if you are:
* a device providing a clock source of some kind
* a device that takes a clock input and has one or more clock outputs which are configured by that device (for frequency, on/off, etc)
* a device that consumes a clock
please? I think that would help make it more concrete how you need to use these things.
thanks
-- PMM
Re: [Qemu-devel] [PATCH V2 06/10] docs: add qemu-clock documentation
Quoted 14 lines · Peter Maydell
Quoted 4 lines · On 26 January 2017 at 09:47, <[email protected]> wrote:
From: KONRAD Frederic <[email protected]>
This adds the qemu-clock documentation.
Quoted 8 lines
Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Fixed in accordance with the changes in the previous patches.--- docs/clock.txt | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 docs/clock.txt
Quoted 2 lines
Could we have a simple example of what you need to do if you are:
* a device providing a clock source of some kind
The fixed clock in patch 7 might be helpful for that. Maybe I can just point to it in the documentation?
Quoted 4 lines
* a device that takes a clock input and has one or more clock outputs which are configured by that device (for frequency, on/off, etc)
* a device that consumes a clock
The CRF is doing that. Maybe I can add a simpler testcase device to build a make check for that?
Fred
Quoted 7 lines
please? I think that would help make it more concrete how you need to use these things.
thanks
-- PMM
Re: [Qemu-devel] [PATCH V2 06/10] docs: add qemu-clock documentation
Quoted 21 lines · Frederic Konrad
Quoted 14 lines · Peter Maydell
Quoted 4 lines · On 26 January 2017 at 09:47, <[email protected]> wrote:
From: KONRAD Frederic <[email protected]>
This adds the qemu-clock documentation.
Quoted 8 lines
Signed-off-by KONRAD Frederic <[email protected]>V1 -> V2:
* Fixed in accordance with the changes in the previous patches.--- docs/clock.txt | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 docs/clock.txtQuoted 2 lines
Could we have a simple example of what you need to do if you are:
* a device providing a clock source of some kindThe fixed clock in patch 7 might be helpful for that. Maybe I can just point to it in the documentation?
Quoted 7 lines
Quoted 4 lines
* a device that takes a clock input and has one or more clock outputs which are configured by that device (for frequency, on/off, etc)
* a device that consumes a clockThe CRF is doing that. Maybe I can add a simpler testcase device to build a make check for that?
I don't really want a whole test case device (which is a lot of extra boilerplate and detail obscuring the necessities), I'd just like a sketch of what these devices need to do in the documentation.
thanks
-- PMM
PATCH v2 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
@@ -53,3 +53,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
Re: [Qemu-devel] [PATCH V2 07/10] introduce fixed-clock
Quoted 63 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This is a fixed clock device.
It justs behave as an empty device with a parametrable output rate.Signed-off-by KONRAD Frederic <[email protected]>--- 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.hhw/misc/Makefile.objs +1
-0@@ -53,3 +53,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.ohw/misc/fixed-clock.c new file +34
-0@@ -0,0 +1,88 @@ +/* +* 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/>. +* +*/ + +#include "qemu/osdep.h" +#include "hw/qdev.h" +#include "hw/misc/fixed-clock.h" +#include "qemu/qemu-clock.h" +#include "qapi/error.h" + +#ifndef DEBUG_FIXED_CLOCK +#define DEBUG_FIXED_CLOCK 0 +#endif + +#define DPRINTF (fmt, ...) do { \
hw/misc/fixed-clock.c line 44
Quoted 10 lines
hw/misc/fixed-clock.c new file +10
-0+if (DEBUG_FIXED_CLOCK ) { \ + qemu_log(__FILE__": " fmt , ## __VA_ARGS__); \ + } \ +}while (0 ); + +typedef struct { + DeviceState parent_obj; + + uint32_t rate; + struct qemu_clk out;
This really feels redundant. See my previous suggestion.
Thanks,
C.
Quoted 81 lines
hw/misc/fixed-clock.c new file +44
-0+} FixedClock; + +static Property fixed_clock_properties[] = { +DEFINE_PROP_UINT32 ("rate" , FixedClock, rate,0 ), +DEFINE_PROP_END_OF_LIST () +}; + +static void fixed_clock_realizefn (DeviceState *dev,Error **errp) +{ +FixedClock *s =FIXED_CLOCK (dev); + +qemu_clk_update_rate (&s->out, s->rate); +} + +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" ); +} + +static void fixed_clock_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = fixed_clock_realizefn; + dc->props = fixed_clock_properties; +} + +static const TypeInfo fixed_clock_info = { + .name =TYPE_FIXED_CLOCK , + .parent =TYPE_DEVICE , + .instance_size =sizeof (FixedClock), + .instance_init = fixed_clock_instance_init, + .class_init = fixed_clock_class_init, +}; + +static void fixed_clock_register_types (void ) +{ +type_register_static (&fixed_clock_info); +} + +type_init (fixed_clock_register_types);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 */
PATCH v2 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
@@ -43,6 +43,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 v2 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 v2 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_clock (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_clock (qemu_clk_device_get_clock (DEVICE (s->video_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf),"video_clk" )); + +qemu_clk_bind_clock (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_clock (qemu_clk_device_get_clock (DEVICE (s->aux_refclk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"aux_refclk" )); + +qemu_clk_bind_clock (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
Re: [Qemu-devel] [PATCH V2 10/10] zynqmp: add reference clock
Quoted 24 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
This adds some fixed reference clock to the zynqmp platform. They will feed the
zynqmp_crfblock.Signed-off-by KONRAD Frederic <[email protected]>--- hw/arm/xlnx-zynqmp.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 6 ++++++ 2 files changed, 55 insertions(+)hw/arm/xlnx-zynqmp.c +1
-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
hw/arm/xlnx-zynqmp.c static void xlnx_zynqmp_init(Object *obj) · line 190
Quoted 8 lines
hw/arm/xlnx-zynqmp.c +5
-0@@ -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);
object_initialize() should be preferred to object_new().
The exact reason is not very clear to me but a maintainer answered to some code of mine saying that object_new() can break QOM lifetime rules it seems. May be others can chime in on that topic
Thanks,
C.
Quoted 78 lines
hw/arm/xlnx-zynqmp.c +43
-0+ 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_clock (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_clock (qemu_clk_device_get_clock (DEVICE (s->video_clk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf),"video_clk" )); + +qemu_clk_bind_clock (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_clock (qemu_clk_device_get_clock (DEVICE (s->aux_refclk), +"clk_out" ), +qemu_clk_device_get_clock (DEVICE (s->crf), +"aux_refclk" )); + +qemu_clk_bind_clock (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;
Ping!
Thanks,
Fred
Quoted 95 lines · On 01/26/2017 10:47 AM, [email protected] wrote:
From: KONRAD Frederic <[email protected]>
Hi,
This is the second 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
(a9e404600a9bd1e6a26431fc89e5069092e67f14).Thanks,
FredV1 -> 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 | 108 +++++ 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 | 174 ++++++++ 11 files changed, 1598 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