mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 07:04:28 +00:00
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>
This commit is contained in:
parent
b81a024e4a
commit
ba5e3e1ed0
5 changed files with 79 additions and 8 deletions
|
@ -71,7 +71,14 @@ static int notify_static(struct event *ev)
|
|||
|
||||
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
|
||||
|
|
|
@ -99,19 +99,48 @@ struct event {
|
|||
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 @@ struct evspy_info {
|
|||
|
||||
/* 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 @@ static inline const char *event_spy_id(struct evspy_info *spy)
|
|||
__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
|
||||
*
|
||||
|
|
|
@ -19,8 +19,10 @@ from u_boot_pylib import tools
|
|||
|
||||
# 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 @@ def show_event_spy_list(fname, endian):
|
|||
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)
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ struct test_state {
|
|||
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 @@ static int h_adder(void *ctx, struct event *event)
|
|||
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 @@ static int test_event_base(struct unit_test_state *uts)
|
|||
}
|
||||
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;
|
||||
|
|
|
@ -18,5 +18,6 @@ def test_event_dump(u_boot_console):
|
|||
-------------------- ------------------------------ ------------------------------
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue