xref: /rk3399_ARM-atf/include/common/bl_common.h (revision 7303319b3823e9e33748d963e9173f3678aba4da)
14ecca339SDan Handley /*
251997e3dSBoyan Karatotev  * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
34ecca339SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
54ecca339SDan Handley  */
64ecca339SDan Handley 
7c3cf06f1SAntonio Nino Diaz #ifndef BL_COMMON_H
8c3cf06f1SAntonio Nino Diaz #define BL_COMMON_H
94ecca339SDan Handley 
1009d40e0eSAntonio Nino Diaz #include <common/ep_info.h>
1109d40e0eSAntonio Nino Diaz #include <common/param_header.h>
1209d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
134ecca339SDan Handley 
14d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
1557bf6057SJulius Werner #include <stddef.h>
1657bf6057SJulius Werner #include <stdint.h>
1757bf6057SJulius Werner #include <lib/cassert.h>
18d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
1957bf6057SJulius Werner 
2057bf6057SJulius Werner #include <export/common/bl_common_exp.h>
2157bf6057SJulius Werner 
2281542c00SAntonio Nino Diaz #define UP	U(1)
2381542c00SAntonio Nino Diaz #define DOWN	U(0)
244ecca339SDan Handley 
254ecca339SDan Handley /*******************************************************************************
268f55dfb4SSandrine Bailleux  * Constants to identify the location of a memory region in a given memory
278f55dfb4SSandrine Bailleux  * layout.
284ecca339SDan Handley ******************************************************************************/
2981542c00SAntonio Nino Diaz #define TOP	U(0x1)
3081542c00SAntonio Nino Diaz #define BOTTOM	U(0x0)
314ecca339SDan Handley 
32bbf8f6f9SYatharth Kochar /*******************************************************************************
33bbf8f6f9SYatharth Kochar  * Constants to indicate type of exception to the common exception handler.
34bbf8f6f9SYatharth Kochar  ******************************************************************************/
3581542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_SP_EL0		U(0x0)
3681542c00SAntonio Nino Diaz #define IRQ_SP_EL0			U(0x1)
3781542c00SAntonio Nino Diaz #define FIQ_SP_EL0			U(0x2)
3881542c00SAntonio Nino Diaz #define SERROR_SP_EL0			U(0x3)
3981542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_SP_ELX		U(0x4)
4081542c00SAntonio Nino Diaz #define IRQ_SP_ELX			U(0x5)
4181542c00SAntonio Nino Diaz #define FIQ_SP_ELX			U(0x6)
4281542c00SAntonio Nino Diaz #define SERROR_SP_ELX			U(0x7)
4381542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_AARCH64		U(0x8)
4481542c00SAntonio Nino Diaz #define IRQ_AARCH64			U(0x9)
4581542c00SAntonio Nino Diaz #define FIQ_AARCH64			U(0xa)
4681542c00SAntonio Nino Diaz #define SERROR_AARCH64			U(0xb)
4781542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_AARCH32		U(0xc)
4881542c00SAntonio Nino Diaz #define IRQ_AARCH32			U(0xd)
4981542c00SAntonio Nino Diaz #define FIQ_AARCH32			U(0xe)
5081542c00SAntonio Nino Diaz #define SERROR_AARCH32			U(0xf)
51bbf8f6f9SYatharth Kochar 
52c2ad38ceSVarun Wadekar /*
53c2ad38ceSVarun Wadekar  * Mapping to connect linker symbols from .ld.S with their counterparts
54c2ad38ceSVarun Wadekar  * from .scat for the BL31 image
55c2ad38ceSVarun Wadekar  */
56c2ad38ceSVarun Wadekar #if defined(USE_ARM_LINK)
57c2ad38ceSVarun Wadekar #define __BL31_END__			Load$$LR$$LR_END$$Base
58c2ad38ceSVarun Wadekar #define __BSS_START__			Load$$LR$$LR_BSS$$Base
59c2ad38ceSVarun Wadekar #define __BSS_END__			Load$$LR$$LR_BSS$$Limit
60c2ad38ceSVarun Wadekar #define __BSS_SIZE__			Load$$LR$$LR_BSS$$Length
61c2ad38ceSVarun Wadekar #define __COHERENT_RAM_START__		Load$$LR$$LR_COHERENT_RAM$$Base
62c2ad38ceSVarun Wadekar #define __COHERENT_RAM_END_UNALIGNED__	Load$$__COHERENT_RAM_EPILOGUE_UNALIGNED__$$Base
63c2ad38ceSVarun Wadekar #define __COHERENT_RAM_END__		Load$$LR$$LR_COHERENT_RAM$$Limit
64c2ad38ceSVarun Wadekar #define __COHERENT_RAM_UNALIGNED_SIZE__	Load$$__COHERENT_RAM__$$Length
65c2ad38ceSVarun Wadekar #define __CPU_OPS_START__		Load$$__CPU_OPS__$$Base
66c2ad38ceSVarun Wadekar #define __CPU_OPS_END__			Load$$__CPU_OPS__$$Limit
67c2ad38ceSVarun Wadekar #define __DATA_START__			Load$$__DATA__$$Base
68c2ad38ceSVarun Wadekar #define __DATA_END__			Load$$__DATA__$$Limit
69c2ad38ceSVarun Wadekar #define __GOT_START__			Load$$__GOT__$$Base
70c2ad38ceSVarun Wadekar #define __GOT_END__			Load$$__GOT__$$Limit
71c2ad38ceSVarun Wadekar #define __PERCPU_BAKERY_LOCK_START__	Load$$__BAKERY_LOCKS__$$Base
72c2ad38ceSVarun Wadekar #define __PERCPU_BAKERY_LOCK_END__	Load$$__BAKERY_LOCKS_EPILOGUE__$$Base
73c2ad38ceSVarun Wadekar #define __PMF_SVC_DESCS_START__		Load$$__PMF_SVC_DESCS__$$Base
74c2ad38ceSVarun Wadekar #define __PMF_SVC_DESCS_END__		Load$$__PMF_SVC_DESCS__$$Limit
75c2ad38ceSVarun Wadekar #define __PMF_TIMESTAMP_START__		Load$$__PMF_TIMESTAMP__$$Base
76c2ad38ceSVarun Wadekar #define __PMF_TIMESTAMP_END__		Load$$__PER_CPU_TIMESTAMPS__$$Limit
77c2ad38ceSVarun Wadekar #define __PMF_PERCPU_TIMESTAMP_END__	Load$$__PMF_TIMESTAMP_EPILOGUE__$$Base
78c2ad38ceSVarun Wadekar #define __RELA_END__			Load$$__RELA__$$Limit
79c2ad38ceSVarun Wadekar #define __RELA_START__			Load$$__RELA__$$Base
80c2ad38ceSVarun Wadekar #define __RODATA_START__		Load$$__RODATA__$$Base
81c2ad38ceSVarun Wadekar #define __RODATA_END__			Load$$__RODATA_EPILOGUE__$$Base
82c2ad38ceSVarun Wadekar #define __RT_SVC_DESCS_START__		Load$$__RT_SVC_DESCS__$$Base
83c2ad38ceSVarun Wadekar #define __RT_SVC_DESCS_END__		Load$$__RT_SVC_DESCS__$$Limit
847affa25cSMarc Bonnici #if SPMC_AT_EL3
857affa25cSMarc Bonnici #define __EL3_LP_DESCS_START__		Load$$__EL3_LP_DESCS__$$Base
867affa25cSMarc Bonnici #define __EL3_LP_DESCS_END__		Load$$__EL3_LP_DESCS__$$Limit
877affa25cSMarc Bonnici #endif
88890b5088SRaghu Krishnamurthy #if ENABLE_SPMD_LP
89890b5088SRaghu Krishnamurthy #define __SPMD_LP_DESCS_START__	Load$$__SPMD_LP_DESCS__$$Base
90890b5088SRaghu Krishnamurthy #define __SPMD_LP_DESCS_END__		Load$$__SPMD_LP_DESCS__$$Limit
91890b5088SRaghu Krishnamurthy #endif
92c2ad38ceSVarun Wadekar #define __RW_START__			Load$$LR$$LR_RW_DATA$$Base
93c2ad38ceSVarun Wadekar #define __RW_END__			Load$$LR$$LR_END$$Base
94c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_START__	Load$$__SPM_SHIM_EXCEPTIONS__$$Base
95c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_END__	Load$$__SPM_SHIM_EXCEPTIONS_EPILOGUE__$$Base
96c2ad38ceSVarun Wadekar #define __STACKS_START__		Load$$__STACKS__$$Base
97c2ad38ceSVarun Wadekar #define __STACKS_END__			Load$$__STACKS__$$Limit
98c2ad38ceSVarun Wadekar #define __TEXT_START__			Load$$__TEXT__$$Base
99c2ad38ceSVarun Wadekar #define __TEXT_END__			Load$$__TEXT_EPILOGUE__$$Base
100c2ad38ceSVarun Wadekar #endif /* USE_ARM_LINK */
101c2ad38ceSVarun Wadekar 
102d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
10309d40e0eSAntonio Nino Diaz 
10490b3a6acSDan Handley /*
10590b3a6acSDan Handley  * Declarations of linker defined symbols to help determine memory layout of
10690b3a6acSDan Handley  * BL images
10790b3a6acSDan Handley  */
1085d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA
109f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_START__,		BL_CODE_BASE);
110f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_END__,		BL_CODE_END);
111f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_START__,		BL_RO_DATA_BASE);
112f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_END__,		BL_RO_DATA_END);
1135d1c104fSSandrine Bailleux #else
114f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_START__,		BL_CODE_BASE);
115f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_END__,		BL_CODE_END);
1165d1c104fSSandrine Bailleux #endif
1179aedca02SSamuel Holland #if SEPARATE_NOBITS_REGION
1189aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_START__,		BL_NOBITS_BASE);
1199aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_END__,		BL_NOBITS_END);
1209aedca02SSamuel Holland #endif
1212c74a29dSMasahiro Yamada IMPORT_SYM(uintptr_t, __RW_END__,		BL_END);
1225d1c104fSSandrine Bailleux 
123c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1)
124c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__,		BL1_ROM_END);
125c9f9d9eaSAntonio Nino Diaz 
126c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__,	BL1_RAM_BASE);
127c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__,		BL1_RAM_LIMIT);
128c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2)
129f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_END__,		BL2_END);
1303d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U)
131f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2U_END__,		BL2U_END);
1323d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31)
133f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_START__,		BL31_START);
134f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_END__,		BL31_END);
1353d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32)
136f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL32_END__,		BL32_END);
1375b18de09SZelalem Aweke #elif defined(IMAGE_RMM)
1385b18de09SZelalem Aweke IMPORT_SYM(uintptr_t, __RMM_END__,		RMM_END);
13990b3a6acSDan Handley #endif /* IMAGE_BLX */
14090b3a6acSDan Handley 
141c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */
142c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2)
143f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__,		BL2_ROM_END);
144c9f9d9eaSAntonio Nino Diaz 
145f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__,	BL2_RAM_BASE);
146f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__,		BL2_RAM_END);
147c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */
148c9f9d9eaSAntonio Nino Diaz 
149*962958d3SRohit Mathew #if defined (IMAGE_BL31) || defined(IMAGE_BL32)
150*962958d3SRohit Mathew IMPORT_SYM(uintptr_t, __PER_CPU_START__,	PER_CPU_START);
151*962958d3SRohit Mathew IMPORT_SYM(uintptr_t, __PER_CPU_END__,		PER_CPU_END);
152*962958d3SRohit Mathew IMPORT_SYM(uintptr_t, __PER_CPU_UNIT_END__,	PER_CPU_UNIT_END)
153*962958d3SRohit Mathew #endif /* IMAGE_BL31 && IMAGE_BL2*/
154*962958d3SRohit Mathew 
1559f85f9e3SJoel Hutton /*
1569f85f9e3SJoel Hutton  * The next 2 constants identify the extents of the coherent memory region.
1579f85f9e3SJoel Hutton  * These addresses are used by the MMU setup code and therefore they must be
1589f85f9e3SJoel Hutton  * page-aligned.  It is the responsibility of the linker script to ensure that
1599f85f9e3SJoel Hutton  * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
1609f85f9e3SJoel Hutton  * page-aligned addresses.
1619f85f9e3SJoel Hutton  */
16290b3a6acSDan Handley #if USE_COHERENT_MEM
163f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__,	BL_COHERENT_RAM_BASE);
164f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__,	BL_COHERENT_RAM_END);
16590b3a6acSDan Handley #endif
16690b3a6acSDan Handley 
1674ecca339SDan Handley /*******************************************************************************
1684ecca339SDan Handley  * Structure used for telling the next BL how much of a particular type of
1694ecca339SDan Handley  * memory is available for its use and how much is already used.
1704ecca339SDan Handley  ******************************************************************************/
171fb037bfbSDan Handley typedef struct meminfo {
1724c0d0390SSoby Mathew 	uintptr_t total_base;
1738f55dfb4SSandrine Bailleux 	size_t total_size;
174fb037bfbSDan Handley } meminfo_t;
1754ecca339SDan Handley 
1764ecca339SDan Handley /*******************************************************************************
17724da55eeSHarrison Mutai  * Structure used for conveying the location and size of the heap allocated for
17824da55eeSHarrison Mutai  * use by the cryptography library.
17924da55eeSHarrison Mutai  * *****************************************************************************/
18024da55eeSHarrison Mutai struct crypto_heap_info {
18124da55eeSHarrison Mutai 	void *addr;
18224da55eeSHarrison Mutai 	size_t size;
18324da55eeSHarrison Mutai };
18424da55eeSHarrison Mutai 
18524da55eeSHarrison Mutai /*******************************************************************************
1864ecca339SDan Handley  * Function & variable prototypes
1874ecca339SDan Handley  ******************************************************************************/
18872600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data);
18972600226SYatharth Kochar 
190209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
191209a60ccSSoby Mathew /*
192209a60ccSSoby Mathew  * API to dynamically disable authentication. Only meant for development
193209a60ccSSoby Mathew  * systems.
194209a60ccSSoby Mathew  */
195209a60ccSSoby Mathew void dyn_disable_auth(void);
196209a60ccSSoby Mathew #endif
197209a60ccSSoby Mathew 
198dddf4283Slaurenw-arm const char *get_version(void);
19972600226SYatharth Kochar 
20068a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info);
2011af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir);
20268a68c92SSandrine Bailleux 
2030916c38dSRoberto Vargas struct mmap_region;
2040916c38dSRoberto Vargas 
2050916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions,
2060916c38dSRoberto Vargas 			   const struct mmap_region *plat_regions);
2070916c38dSRoberto Vargas 
208d5dfdeb6SJulius Werner #endif /*__ASSEMBLER__*/
2094ecca339SDan Handley 
210c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */
211