[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/44] clock: Add ClockPreUpdate callback event type
From: |
Peter Maydell |
Subject: |
[PATCH 02/44] clock: Add ClockPreUpdate callback event type |
Date: |
Fri, 19 Feb 2021 14:45:35 +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>
---
docs/devel/clocks.rst | 9 ++++++++-
include/hw/clock.h | 1 +
hw/core/clock.c | 3 +++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst
index cd344e3fe5d..f0391e76b4f 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/include/hw/clock.h b/include/hw/clock.h
index 282a37f7c5a..2ba44e14424 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);
diff --git a/hw/core/clock.c b/hw/core/clock.c
index 4479eff145b..fc5a99683f8 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),
--
2.20.1
- [PATCH 00/44] hw/arm: New board model mps3-an547, Peter Maydell, 2021/02/19
- [PATCH 02/44] clock: Add ClockPreUpdate callback event type,
Peter Maydell <=
- [PATCH 01/44] clock: Add ClockEvent parameter to callbacks, Peter Maydell, 2021/02/19
- [PATCH 03/44] clock: Add clock_ns_to_ticks() function, Peter Maydell, 2021/02/19
- [PATCH 04/44] hw/timer/npcm7xx_timer: Use new clock_ns_to_ticks(), Peter Maydell, 2021/02/19
- [PATCH 06/44] hw/misc/iotkit-sysctl: Remove is_sse200 flag, Peter Maydell, 2021/02/19
- [PATCH 07/44] hw/misc/iotkit-secctl.c: Implement SSE-300 PID register values, Peter Maydell, 2021/02/19
- [PATCH 10/44] hw/misc/iotkit-sysinfo.c: Implement SYS_CONFIG1 and IIDR, Peter Maydell, 2021/02/19
- [PATCH 11/44] hw/timer/sse-counter: Model the SSE Subsystem System Counter, Peter Maydell, 2021/02/19
- [PATCH 13/44] hw/misc/iotkit-sysctl: Add SSE-300 cases which match SSE-200 behaviour, Peter Maydell, 2021/02/19
- [PATCH 05/44] hw/arm/armsse: Introduce SSE subsystem version property, Peter Maydell, 2021/02/19
- [PATCH 12/44] hw/timer/sse-timer: Model the SSE Subsystem System Timer, Peter Maydell, 2021/02/19