aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-01-29 15:40:09 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-02-15 13:16:12 +0000
commit168ebc00e72c686aea046ec3b993610ff678e9dc (patch)
tree05aae25b6b6568ce30550449ef116b53aba44f45
parentb7878f38a00806c221c51001509329105f48af1f (diff)
downloadqemu-arm-168ebc00e72c686aea046ec3b993610ff678e9dc.tar.gz
clock: Add ClockPreUpdate callback event type
Add a new callback event type ClockPreUpdate, which is called on period changes before the period is updated. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Luc Michel <luc@lmichel.fr> Reviewed-by: Hao Wu <wuhaotsh@google.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
-rw-r--r--docs/devel/clocks.rst9
-rw-r--r--hw/core/clock.c3
-rw-r--r--include/hw/clock.h1
3 files changed, 12 insertions, 1 deletions
diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index cd344e3fe5..f0391e76b4 100644
--- a/docs/devel/clocks.rst
+++ b/docs/devel/clocks.rst
@@ -181,7 +181,14 @@ events.
The events currently supported are:
- * ``ClockUpdate`` : called after the input clock's period has changed
+ * ``ClockPreUpdate`` : called when the input clock's period is about to
+ update. This is useful if the device needs to do some action for
+ which it needs to know the old value of the clock period. During
+ this callback, Clock API functions like ``clock_get()`` or
+ ``clock_ticks_to_ns()`` will use the old period.
+ * ``ClockUpdate`` : called after the input clock's period has changed.
+ During this callback, Clock API functions like ``clock_ticks_to_ns()``
+ will use the new period.
Note that a clock only has one callback: it is not possible to register
different functions for different events. You must register a single
diff --git a/hw/core/clock.c b/hw/core/clock.c
index 4479eff145..fc5a99683f 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -81,6 +81,9 @@ static void clock_propagate_period(Clock *clk, bool call_callbacks)
QLIST_FOREACH(child, &clk->children, sibling) {
if (child->period != clk->period) {
+ if (call_callbacks) {
+ clock_call_callback(child, ClockPreUpdate);
+ }
child->period = clk->period;
trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk),
CLOCK_PERIOD_TO_HZ(clk->period),
diff --git a/include/hw/clock.h b/include/hw/clock.h
index 282a37f7c5..2ba44e1442 100644
--- a/include/hw/clock.h
+++ b/include/hw/clock.h
@@ -30,6 +30,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(Clock, CLOCK)
*/
typedef enum ClockEvent {
ClockUpdate = 1, /* Clock period has just updated */
+ ClockPreUpdate = 2, /* Clock period is about to update */
} ClockEvent;
typedef void ClockCallback(void *opaque, ClockEvent event);