#ifndef __INITCALL_H
#define __INITCALL_H
+#include <asm/types.h>
+#include <event.h>
+
+_Static_assert(EVT_COUNT < 256, "Can only support 256 event types with 8 bits");
+
+/**
+ * init_fnc_t - Init function
+ *
+ * Return: 0 if OK -ve on error
+ */
typedef int (*init_fnc_t)(void);
+/* Top bit indicates that the initcall is an event */
+#define INITCALL_IS_EVENT GENMASK(BITS_PER_LONG - 1, 8)
+#define INITCALL_EVENT_TYPE GENMASK(7, 0)
+
+#define INITCALL_EVENT(_type) (void *)((_type) | INITCALL_IS_EVENT)
+
+/**
+ * initcall_run_list() - Run through a list of function calls
+ *
+ * This calls functions one after the other, stopping at the first error, or
+ * when NULL is obtained.
+ *
+ * @init_sequence: NULL-terminated init sequence to run
+ * Return: 0 if OK, or -ve error code from the first failure
+ */
int initcall_run_list(const init_fnc_t init_sequence[]);
#endif
#include <efi.h>
#include <initcall.h>
#include <log.h>
+#include <relocate.h>
#include <asm/global_data.h>
DECLARE_GLOBAL_DATA_PTR;
return 0;
}
+
+/**
+ * initcall_is_event() - Get the event number for an initcall
+ *
+ * func: Function pointer to check
+ * Return: Event number, if this is an event, else 0
+ */
+static int initcall_is_event(init_fnc_t func)
+{
+ ulong val = (ulong)func;
+
+ if ((val & INITCALL_IS_EVENT) == INITCALL_IS_EVENT)
+ return val & INITCALL_EVENT_TYPE;
+
+ return 0;
+}
+
/*
* To enable debugging. add #define DEBUG at the top of the including file.
*
{
ulong reloc_ofs = calc_reloc_ofs();
const init_fnc_t *ptr;
+ enum event_t type;
init_fnc_t func;
int ret = 0;
for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) {
- if (reloc_ofs) {
+ type = initcall_is_event(func);
+
+ if (type) {
+ if (!CONFIG_IS_ENABLED(EVENT))
+ continue;
+ debug("initcall: event %d/%s\n", type,
+ event_type_name(type));
+ } else if (reloc_ofs) {
debug("initcall: %p (relocated to %p)\n",
- (char *)func - reloc_ofs, func);
+ (char *)func - reloc_ofs, (char *)func);
} else {
debug("initcall: %p\n", (char *)func - reloc_ofs);
}
- ret = func();
+ ret = type ? event_notify_null(type) : func();
}
if (ret) {
- printf("initcall failed at call %p (err=%dE)\n",
- (char *)func - reloc_ofs, ret);
+ if (CONFIG_IS_ENABLED(EVENT)) {
+ char buf[60];
+
+ /* don't worry about buf size as we are dying here */
+ if (type) {
+ sprintf(buf, "event %d/%s", type,
+ event_type_name(type));
+ } else {
+ sprintf(buf, "call %p", func);
+ }
+
+ printf("initcall failed at %s (err=%dE)\n", buf, ret);
+ } else {
+ printf("initcall failed at call %p (err=%d)\n",
+ (char *)func - reloc_ofs, ret);
+ }
return ret;
}
# Then look for this:
# u-boot-1 [000] 282.101375: funcgraph_exit: 0.006 us | }
# Then check for this:
- # u-boot-1 [000] 282.101375: funcgraph_entry: 0.000 us | event_init();
+ # u-boot-1 [000] 282.101375: funcgraph_entry: 0.000 us | initcall_is_event();
expected_indent = None
found_start = False
elif found_start and indent == expected_indent and brace == '}':
found_end = True
- # The next function after initf_bootstage() exits should be event_init()
- assert upto == 'event_init()'
+ # The next function after initf_bootstage() exits should be
+ # initcall_is_event()
+ assert upto == 'initcall_is_event()'
# Now look for initf_dm() and dm_timer_init() so we can check the bootstage
# time
# We expect dm_timer_init() to be called twice: once before relocation and
# once after
look1 = 'initf_dm;dm_timer_init 1'
- look2 = 'board_init_r;initr_dm_devices;dm_timer_init 1'
+ look2 = 'board_init_r;initcall_run_list;initr_dm_devices;dm_timer_init 1'
found = 0
with open(trace_fg, 'r') as fd:
for line in fd:
total += count
return total
-
+check_flamegraph
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('trace')