1 /* 2 * Copyright (c) 2013 The Chromium OS Authors. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <initcall.h> 9 #include <efi.h> 10 11 DECLARE_GLOBAL_DATA_PTR; 12 13 #define SYS_TICKS_TO_US(ticks) ((ticks) / (COUNTER_FREQUENCY / 1000000)) 14 15 #ifdef DEBUG 16 static inline void call_get_ticks(ulong *ticks) { *ticks = get_ticks(); } 17 #else 18 static inline void call_get_ticks(ulong *ticks) { } 19 #endif 20 21 int initcall_run_list(const init_fnc_t init_sequence[]) 22 { 23 const init_fnc_t *init_fnc_ptr; 24 __maybe_unused ulong start = 0, end = 0; 25 26 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { 27 unsigned long reloc_ofs = 0; 28 int ret; 29 30 if (gd->flags & GD_FLG_RELOC) 31 reloc_ofs = gd->reloc_off; 32 #ifdef CONFIG_EFI_APP 33 reloc_ofs = (unsigned long)image_base; 34 #endif 35 debug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs); 36 if (gd->flags & GD_FLG_RELOC) 37 debug(" (relocated to %p)\n", (char *)*init_fnc_ptr); 38 else 39 debug("\n"); 40 call_get_ticks(&start); 41 ret = (*init_fnc_ptr)(); 42 call_get_ticks(&end); 43 if (start != end) 44 debug("\t\t\t\t\t\t\t\t#%6ld us\n", SYS_TICKS_TO_US(end - start)); 45 if (ret) { 46 printf("initcall sequence %p failed at call %p (err=%d)\n", 47 init_sequence, 48 (char *)*init_fnc_ptr - reloc_ofs, ret); 49 return -1; 50 } 51 } 52 return 0; 53 } 54