u-boot/include/initcall.h
Jerome Forissier 6c171f7a18 common: board: make initcalls static
Change board_init_f(), board_init_f_r() and board_init_r() to make
static calls instead of iterating over the init_sequence_f,
init_sequence_f_r and init_sequence_r arrays, respectively. This makes
the code a simpler (and even more so when initcall_run_list() is
later removed) and it reduces the binary size as well. Tested with
xilinx_zynqmp_kria_defconfig; bloat-o-meter results:

- With LTO
add/remove: 106/196 grow/shrink: 10/28 up/down: 31548/-33829 (-2281)
Total: Before=1070471, After=1068190, chg -0.21%
- Without LTO
add/remove: 0/54 grow/shrink: 3/0 up/down: 2322/-2832 (-510)
Total: Before=1121723, After=1121213, chg -0.05%

Execution time does not change in a noticeable way.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
2025-04-14 08:59:39 -06:00

65 lines
1.5 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2011 The Chromium OS Authors.
*/
#ifndef __INITCALL_H
#define __INITCALL_H
#include <asm/types.h>
#include <event.h>
#include <hang.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[]);
#define INITCALL(_call) \
do { \
if (_call()) { \
printf("%s(): initcall %s() failed\n", __func__, \
#_call); \
hang(); \
} \
} while (0)
#define INITCALL_EVT(_evt) \
do { \
if (event_notify_null(_evt)) { \
printf("%s(): event %d/%s failed\n", __func__, _evt, \
event_type_name(_evt)) ; \
hang(); \
} \
} while (0)
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
#define WATCHDOG_INIT() INITCALL(init_func_watchdog_init)
#define WATCHDOG_RESET() INITCALL(init_func_watchdog_reset)
#else
#define WATCHDOG_INIT()
#define WATCHDOG_RESET()
#endif
#endif