[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V1 04/10] qemu-clk: introduce an init array to help
From: |
fred . konrad |
Subject: |
[Qemu-devel] [PATCH V1 04/10] qemu-clk: introduce an init array to help the device construction |
Date: |
Thu, 6 Oct 2016 00:10:58 +0200 |
From: KONRAD Frederic <address@hidden>
This introduces a clock init array to ease the clock tree construction.
Signed-off-by: KONRAD Frederic <address@hidden>
---
include/qemu/qemu-clock.h | 23 +++++++++++++++++++++++
qemu-clock.c | 17 +++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/include/qemu/qemu-clock.h b/include/qemu/qemu-clock.h
index d575566..72062de 100644
--- a/include/qemu/qemu-clock.h
+++ b/include/qemu/qemu-clock.h
@@ -50,6 +50,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. */
+ qemu_clk_on_rate_update_cb 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_attach_to_device:
* @dev: the device on which the clock need to be attached.
diff --git a/qemu-clock.c b/qemu-clock.c
index 541f615..5c799bc 100644
--- a/qemu-clock.c
+++ b/qemu-clock.c
@@ -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_attach_to_device(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);
--
2.5.5
- [Qemu-devel] [PATCH V1 00/10] Clock framework API., fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 01/10] qemu-clk: introduce qemu-clk qom object, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 02/10] qemu-clk: allow to attach a clock to a device, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 03/10] qemu-clk: allow to bind two clocks together, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 04/10] qemu-clk: introduce an init array to help the device construction,
fred . konrad <=
- [Qemu-devel] [PATCH V1 05/10] qdev-monitor: print the device's clock with info qtree, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 06/10] docs: add qemu-clock documentation, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 07/10] introduce fixed-clock, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 09/10] zynqmp: add the zynqmp_crf to the platform, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 10/10] zynqmp: add reference clock, fred . konrad, 2016/10/05
- [Qemu-devel] [PATCH V1 08/10] introduce zynqmp_crf, fred . konrad, 2016/10/05