]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
clock: Add ClockPreUpdate callback event type
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 19 Feb 2021 14:45:35 +0000 (14:45 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 8 Mar 2021 17:20:01 +0000 (17:20 +0000)
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>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20210219144617.4782-3-peter.maydell@linaro.org

docs/devel/clocks.rst
hw/core/clock.c
include/hw/clock.h

index cd344e3fe5d8f2795173985ef8825fa0c0ac8e7f..f0391e76b4f821ad55ab085310b1c3d1fc73fab9 100644 (file)
@@ -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
index 4479eff145b0cff9157f2479916349f4fbe9629e..fc5a99683f895a3166b25add22de849f7adbedcb 100644 (file)
@@ -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),
index 282a37f7c5ac36c1f0fe1fc0ddfa5230d4e04f0a..2ba44e144242221bf16990c97908dc9ad36fa9a9 100644 (file)
@@ -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);