clock: Add ClockEvent parameter to callbacks

The Clock framework allows users to specify a callback which is
called after the clock's period has been updated.  Some users need to
also have a callback which is called before the clock period is
updated.

As the first step in adding support for notifying Clock users on
pre-update events, add an argument to the ClockCallback to specify
what event is being notified, and add an argument to the various
functions for registering a callback to specify which events are
of interest to that callback.

Note that the documentation update renders correct the previously
incorrect claim in 'Adding a new clock' that callbacks "will be
explained in a following section".

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Luc Michel <luc@lmichel.fr>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20210219144617.4782-2-peter.maydell@linaro.org
This commit is contained in:
Peter Maydell 2021-02-19 14:45:34 +00:00
parent 0436c55edf
commit 5ee0abed51
20 changed files with 161 additions and 58 deletions

View file

@ -22,7 +22,17 @@
#define TYPE_CLOCK "clock"
OBJECT_DECLARE_SIMPLE_TYPE(Clock, CLOCK)
typedef void ClockCallback(void *opaque);
/*
* Argument to ClockCallback functions indicating why the callback
* has been called. A mask of these values logically ORed together
* is used to specify which events are interesting when the callback
* is registered, so these values must all be different bit values.
*/
typedef enum ClockEvent {
ClockUpdate = 1, /* Clock period has just updated */
} ClockEvent;
typedef void ClockCallback(void *opaque, ClockEvent event);
/*
* clock store a value representing the clock's period in 2^-32ns unit.
@ -50,6 +60,7 @@ typedef void ClockCallback(void *opaque);
* @canonical_path: clock path string cache (used for trace purpose)
* @callback: called when clock changes
* @callback_opaque: argument for @callback
* @callback_events: mask of events when callback should be called
* @source: source (or parent in clock tree) of the clock
* @children: list of clocks connected to this one (it is their source)
* @sibling: structure used to form a clock list
@ -67,6 +78,7 @@ struct Clock {
char *canonical_path;
ClockCallback *callback;
void *callback_opaque;
unsigned int callback_events;
/* Clocks are organized in a clock tree */
Clock *source;
@ -114,10 +126,15 @@ Clock *clock_new(Object *parent, const char *name);
* @clk: the clock to register the callback into
* @cb: the callback function
* @opaque: the argument to the callback
* @events: the events the callback should be called for
* (logical OR of ClockEvent enum values)
*
* Register a callback called on every clock update.
* Note that a clock has only one callback: you cannot register
* different callback functions for different events.
*/
void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque);
void clock_set_callback(Clock *clk, ClockCallback *cb,
void *opaque, unsigned int events);
/**
* clock_clear_callback: