event: Support a simple spy record
The current event spy is always passed the event context and the event.
The context is always NULL for a static spy. The event is not often used.
Introduce a 'simple' spy which takes no arguments. This allows us to drop
the adaptation code that many of these spy records use.
Update the event script to find these in the image.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/common/event.c b/common/event.c
index 3224e28..7e2590e 100644
--- a/common/event.c
+++ b/common/event.c
@@ -71,7 +71,14 @@
log_debug("Sending event %x/%s to spy '%s'\n", ev->type,
event_type_name(ev->type), event_spy_id(spy));
- ret = spy->func(NULL, ev);
+ if (spy->flags & EVSPYF_SIMPLE) {
+ const struct evspy_info_simple *simple;
+
+ simple = (struct evspy_info_simple *)spy;
+ ret = simple->func();
+ } else {
+ ret = spy->func(NULL, ev);
+ }
/*
* TODO: Handle various return codes to
diff --git a/include/event.h b/include/event.h
index daf44bf..0e3222c 100644
--- a/include/event.h
+++ b/include/event.h
@@ -99,19 +99,48 @@
union event_data data;
};
+/* Flags for event spy */
+enum evspy_flags {
+ EVSPYF_SIMPLE = 1 << 0,
+};
+
/** Function type for event handlers */
typedef int (*event_handler_t)(void *ctx, struct event *event);
+/** Function type for simple event handlers */
+typedef int (*event_handler_simple_t)(void);
+
/**
* struct evspy_info - information about an event spy
*
* @func: Function to call when the event is activated (must be first)
* @type: Event type
+ * @flag: Flags for this spy
* @id: Event id string
*/
struct evspy_info {
event_handler_t func;
- enum event_t type;
+ u8 type;
+ u8 flags;
+#if CONFIG_IS_ENABLED(EVENT_DEBUG)
+ const char *id;
+#endif
+};
+
+/**
+ * struct evspy_info_simple - information about an event spy
+ *
+ * THis is the 'simple' record, the only difference being the handler function
+ *
+ * @func: Function to call when the event is activated (must be first)
+ * @type: Event type
+ * @flag: Flags for this spy
+ * @id: Event id string
+ */
+struct evspy_info_simple {
+ event_handler_simple_t func;
+ u8 type;
+ u8 flags;
#if CONFIG_IS_ENABLED(EVENT_DEBUG)
const char *id;
#endif
@@ -119,9 +148,11 @@
/* Declare a new event spy */
#if CONFIG_IS_ENABLED(EVENT_DEBUG)
-#define _ESPY_REC(_type, _func) { _func, _type, #_func, }
+#define _ESPY_REC(_type, _func) { _func, _type, 0, #_func, }
+#define _ESPY_REC_SIMPLE(_type, _func) { _func, _type, EVSPYF_SIMPLE, #_func, }
#else
#define _ESPY_REC(_type, _func) { _func, _type, }
+#define _ESPY_REC_SIMPLE(_type, _func) { _func, _type, EVSPYF_SIMPLE }
#endif
static inline const char *event_spy_id(struct evspy_info *spy)
@@ -168,6 +199,12 @@
__used ll_entry_declare(struct evspy_info, _type ## _3_ ## _func, \
evspy_info) = _ESPY_REC(_type, _func)
+/* Simple spy with no function arguemnts */
+#define EVENT_SPY_SIMPLE(_type, _func) \
+ __used ll_entry_declare(struct evspy_info_simple, \
+ _type ## _3_ ## _func, \
+ evspy_info) = _ESPY_REC_SIMPLE(_type, _func)
+
/**
* event_register - register a new spy
*
diff --git a/scripts/event_dump.py b/scripts/event_dump.py
index 0117457..24dfe2b 100755
--- a/scripts/event_dump.py
+++ b/scripts/event_dump.py
@@ -19,8 +19,10 @@
# A typical symbol looks like this:
# _u_boot_list_2_evspy_info_2_EVT_MISC_INIT_F_3_sandbox_misc_init_f
-PREFIX = '_u_boot_list_2_evspy_info_2_'
-RE_EVTYPE = re.compile('%s(.*)_3_.*' % PREFIX)
+PREFIX_FULL = '_u_boot_list_2_evspy_info_2_'
+PREFIX_SIMPLE = '_u_boot_list_2_evspy_info_simple_2_'
+RE_EVTYPE_FULL = re.compile('%s(.*)_3_.*' % PREFIX_FULL)
+RE_EVTYPE_SIMPLE = re.compile('%s(.*)_3_.*' % PREFIX_SIMPLE)
def show_sym(fname, data, endian, evtype, sym):
"""Show information about an evspy entry
@@ -88,12 +90,14 @@
fname (str): Filename of ELF file
endian (str): Endianness to use ('little', 'big', 'auto')
"""
- syms = elf.GetSymbolFileOffset(fname, [PREFIX])
+ syms = elf.GetSymbolFileOffset(fname, [PREFIX_FULL, PREFIX_SIMPLE])
data = tools.read_file(fname)
print('%-20s %-30s %s' % ('Event type', 'Id', 'Source location'))
print('%-20s %-30s %s' % ('-' * 20, '-' * 30, '-' * 30))
for name, sym in syms.items():
- m_evtype = RE_EVTYPE.search(name)
+ m_evtype = RE_EVTYPE_FULL.search(name)
+ if not m_evtype:
+ m_evtype = RE_EVTYPE_SIMPLE.search(name)
evtype = m_evtype .group(1)
show_sym(fname, data, endian, evtype, sym)
diff --git a/test/common/event.c b/test/common/event.c
index 6037ae2..c0912a3 100644
--- a/test/common/event.c
+++ b/test/common/event.c
@@ -18,6 +18,8 @@
int val;
};
+static bool called;
+
static int h_adder(void *ctx, struct event *event)
{
struct event_data_test *data = &event->data.test;
@@ -28,6 +30,14 @@
return 0;
}
+static int h_adder_simple(void)
+{
+ called = true;
+
+ return 0;
+}
+EVENT_SPY_SIMPLE(EVT_TEST, h_adder_simple);
+
static int test_event_base(struct unit_test_state *uts)
{
struct test_state state;
@@ -46,6 +56,18 @@
}
COMMON_TEST(test_event_base, 0);
+static int test_event_simple(struct unit_test_state *uts)
+{
+ called = false;
+
+ /* Check that the handler is called */
+ ut_assertok(event_notify_null(EVT_TEST));
+ ut_assert(called);
+
+ return 0;
+}
+COMMON_TEST(test_event_simple, 0);
+
static int h_probe(void *ctx, struct event *event)
{
struct test_state *test_state = ctx;
diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py
index da196df..041f8f9 100644
--- a/test/py/tests/test_event_dump.py
+++ b/test/py/tests/test_event_dump.py
@@ -18,5 +18,6 @@
-------------------- ------------------------------ ------------------------------
EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*boot/vbe_request.c:.*
EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*boot/vbe_simple_os.c:.*
-EVT_MISC_INIT_F sandbox_misc_init_f .*arch/sandbox/cpu/start.c:'''
+EVT_MISC_INIT_F sandbox_misc_init_f .*arch/sandbox/cpu/start.c:.*
+EVT_TEST h_adder_simple .*test/common/event.c:'''
assert re.match(expect, out, re.MULTILINE) is not None