developer | 6d8e8f8 | 2022-06-20 10:25:35 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022, MediaTek Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef MTK_INIT_H |
| 8 | #define MTK_INIT_H |
| 9 | |
| 10 | #include <cdefs.h> |
| 11 | #include <lib/mtk_init/mtk_init_def.h> |
| 12 | |
| 13 | #define INIT_CALL_EXPAND_AS_ENUMERATION(_section_enum, _section_name, _level) \ |
| 14 | _section_enum = _level, |
| 15 | |
| 16 | #define EXPAND_AS_LINK_SECTION(_section_enum, _section_name, _level) \ |
| 17 | __##_section_enum##_START__ = .; \ |
| 18 | KEEP(*(_section_name##_level)); |
| 19 | |
| 20 | #define EXPAND_AS_EXTERN(_section_enum, _section_name, _level) \ |
| 21 | extern struct initcall __##_section_enum##_START__[]; |
| 22 | |
| 23 | #define EXPAND_AS_SYMBOL_ARR(_section_enum, _section_name, _level) \ |
| 24 | __##_section_enum##_START__, |
| 25 | |
| 26 | #define DECLARE_MTK_INITCALL(_fn, _level) \ |
| 27 | const struct initcall _mtk_initcall_##_fn \ |
| 28 | __used \ |
| 29 | __aligned(sizeof(void *)) \ |
| 30 | __section(".mtk_plat_initcall_"#_level) \ |
| 31 | = { \ |
| 32 | .name = #_fn, \ |
| 33 | .fn = _fn \ |
| 34 | } |
| 35 | |
| 36 | /* initcall helpers */ |
| 37 | #define MTK_EARLY_PLAT_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 0) |
| 38 | #define MTK_ARCH_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 1) |
| 39 | #define MTK_PLAT_SETUP_0_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 2) |
| 40 | #define MTK_PLAT_SETUP_1_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 3) |
| 41 | #define MTK_PLAT_RUNTIME_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 4) |
| 42 | #define MTK_PLAT_BL33_DEFER_INIT(_fn) DECLARE_MTK_INITCALL(_fn, 5) |
| 43 | |
| 44 | #ifndef __ASSEMBLER__ |
| 45 | struct initcall { |
| 46 | const char *name; |
| 47 | int (*fn)(void); |
| 48 | }; |
| 49 | |
| 50 | enum { |
| 51 | INIT_CALL_TABLE(INIT_CALL_EXPAND_AS_ENUMERATION) |
| 52 | MTK_INIT_LVL_MAX |
| 53 | }; |
| 54 | |
| 55 | void mtk_init_one_level(unsigned int level); |
| 56 | #endif |
| 57 | |
| 58 | #endif /* MTK_INIT_H */ |