All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Tyrone Ting" <kfting@nuvoton.com>, "Luc Michel" <luc@lmichel.fr>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Havard Skinnemoen" <hskinnemoen@google.com>
Subject: [PATCH v2 2/4] clock: Add ClockPreUpdate callback event type
Date: Tue,  9 Feb 2021 13:20:38 +0000	[thread overview]
Message-ID: <20210209132040.5091-3-peter.maydell@linaro.org> (raw)
In-Reply-To: <20210209132040.5091-1-peter.maydell@linaro.org>

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>
---
 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 5c73b4e7ae9..d7a6673c29e 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 71dc1f4de65..2c86091d8a3 100644
--- a/hw/core/clock.c
+++ b/hw/core/clock.c
@@ -80,6 +80,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



  parent reply	other threads:[~2021-02-09 13:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 13:20 [PATCH v2 0/4] New APIs for the Clock framework Peter Maydell
2021-02-09 13:20 ` [PATCH v2 1/4] clock: Add ClockEvent parameter to callbacks Peter Maydell
2021-02-10 20:53   ` Hao Wu
2021-02-10 22:19     ` Peter Maydell
2021-02-11 10:14   ` Luc Michel
2021-02-11 15:29   ` Philippe Mathieu-Daudé
2021-02-09 13:20 ` Peter Maydell [this message]
2021-02-10 20:55   ` [PATCH v2 2/4] clock: Add ClockPreUpdate callback event type Hao Wu
2021-02-10 22:55   ` Philippe Mathieu-Daudé
2021-02-11 10:11   ` Luc Michel
2021-02-09 13:20 ` [PATCH v2 3/4] clock: Add clock_ns_to_ticks() function Peter Maydell
2021-02-10 21:00   ` Hao Wu
2021-02-10 23:44   ` Philippe Mathieu-Daudé
2021-02-11 10:13   ` Luc Michel
2021-02-09 13:20 ` [PATCH v2 4/4] hw/timer/npcm7xx_timer: Use new clock_ns_to_ticks() Peter Maydell
2021-02-10 21:01   ` Hao Wu
2021-02-10 23:44   ` Philippe Mathieu-Daudé
2021-02-11 10:13   ` Luc Michel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210209132040.5091-3-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=hskinnemoen@google.com \
    --cc=kfting@nuvoton.com \
    --cc=luc@lmichel.fr \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.