blob: ed5f681326aa705257ba6d19d56e340c16a264ed [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassc8a311d2013-03-05 14:39:40 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassc8a311d2013-03-05 14:39:40 +00004 */
5
Simon Glass2d986c02017-03-28 10:27:17 -06006#ifndef __INITCALL_H
7#define __INITCALL_H
8
Simon Glassc8a311d2013-03-05 14:39:40 +00009typedef int (*init_fnc_t)(void);
10
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060012#ifdef CONFIG_EFI_APP
13#include <efi.h>
14#endif
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060016
benlong.zhouf0969fb2023-10-26 16:42:01 +080017#ifdef CONFIG_AMLOGIC_MODIFY
18#ifdef CONFIG_AMLOGIC_TIME_PROFILE
19void record_init_call_time(void *func, unsigned int time);
20void dump_initcall_time(void);
21unsigned int get_time(void);
22#endif
23#endif
24
Simon Glass315f60d2019-04-08 13:20:47 -060025/*
26 * To enable debugging. add #define DEBUG at the top of the including file.
27 *
28 * To find a symbol, use grep on u-boot.map
29 */
Alexander Graf47870af2019-01-31 16:06:23 +010030static inline int initcall_run_list(const init_fnc_t init_sequence[])
31{
32 const init_fnc_t *init_fnc_ptr;
benlong.zhouf0969fb2023-10-26 16:42:01 +080033#ifdef CONFIG_AMLOGIC_MODIFY
34#ifdef CONFIG_AMLOGIC_TIME_PROFILE
35 int time;
36#endif
37#endif
Alexander Graf47870af2019-01-31 16:06:23 +010038
39 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
40 unsigned long reloc_ofs = 0;
41 int ret;
42
Simon Glass001d1882019-04-08 13:20:41 -060043 /*
44 * Sandbox is relocated by the OS, so symbols always appear at
45 * the relocated address.
46 */
47 if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
Alexander Graf47870af2019-01-31 16:06:23 +010048 reloc_ofs = gd->reloc_off;
49#ifdef CONFIG_EFI_APP
50 reloc_ofs = (unsigned long)image_base;
51#endif
Simon Glass001d1882019-04-08 13:20:41 -060052 if (reloc_ofs)
Ovidiu Panaitfa840f12019-09-25 14:10:54 +030053 debug("initcall: %p (relocated to %p)\n",
54 (char *)*init_fnc_ptr - reloc_ofs,
55 (char *)*init_fnc_ptr);
Alexander Graf47870af2019-01-31 16:06:23 +010056 else
Ovidiu Panaitfa840f12019-09-25 14:10:54 +030057 debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
58
benlong.zhouf0969fb2023-10-26 16:42:01 +080059#ifdef CONFIG_AMLOGIC_MODIFY
60 #ifdef CONFIG_AMLOGIC_TIME_PROFILE
61 time = get_time();
62 #endif
63#endif
Alexander Graf47870af2019-01-31 16:06:23 +010064 ret = (*init_fnc_ptr)();
benlong.zhouf0969fb2023-10-26 16:42:01 +080065#ifdef CONFIG_AMLOGIC_MODIFY
66 #ifdef CONFIG_AMLOGIC_TIME_PROFILE
67 time = get_time() - time;
68 record_init_call_time((char *)*init_fnc_ptr - reloc_ofs, time);
69 #endif
70#endif
Alexander Graf47870af2019-01-31 16:06:23 +010071 if (ret) {
72 printf("initcall sequence %p failed at call %p (err=%d)\n",
73 init_sequence,
74 (char *)*init_fnc_ptr - reloc_ofs, ret);
75 return -1;
76 }
77 }
78 return 0;
79}
Simon Glass2d986c02017-03-28 10:27:17 -060080
81#endif