14ecca339SDan Handley /* 2758ccb80SChris Kay * Copyright (c) 2013-2024, 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 1499f85f9e3SJoel Hutton /* 1509f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1519f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1529f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1539f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1549f85f9e3SJoel Hutton * page-aligned addresses. 1559f85f9e3SJoel Hutton */ 15690b3a6acSDan Handley #if USE_COHERENT_MEM 157f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 158f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 15990b3a6acSDan Handley #endif 16090b3a6acSDan Handley 1614ecca339SDan Handley /******************************************************************************* 1624ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1634ecca339SDan Handley * memory is available for its use and how much is already used. 1644ecca339SDan Handley ******************************************************************************/ 165fb037bfbSDan Handley typedef struct meminfo { 1664c0d0390SSoby Mathew uintptr_t total_base; 1678f55dfb4SSandrine Bailleux size_t total_size; 168fb037bfbSDan Handley } meminfo_t; 1694ecca339SDan Handley 1704ecca339SDan Handley /******************************************************************************* 171*24da55eeSHarrison Mutai * Structure used for conveying the location and size of the heap allocated for 172*24da55eeSHarrison Mutai * use by the cryptography library. 173*24da55eeSHarrison Mutai * *****************************************************************************/ 174*24da55eeSHarrison Mutai struct crypto_heap_info { 175*24da55eeSHarrison Mutai void *addr; 176*24da55eeSHarrison Mutai size_t size; 177*24da55eeSHarrison Mutai }; 178*24da55eeSHarrison Mutai 179*24da55eeSHarrison Mutai /******************************************************************************* 1804ecca339SDan Handley * Function & variable prototypes 1814ecca339SDan Handley ******************************************************************************/ 18272600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 18372600226SYatharth Kochar 184209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 185209a60ccSSoby Mathew /* 186209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 187209a60ccSSoby Mathew * systems. 188209a60ccSSoby Mathew */ 189209a60ccSSoby Mathew void dyn_disable_auth(void); 190209a60ccSSoby Mathew #endif 191209a60ccSSoby Mathew 192dddf4283Slaurenw-arm const char *get_version(void); 19372600226SYatharth Kochar 19468a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 1951af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 19668a68c92SSandrine Bailleux 1970916c38dSRoberto Vargas struct mmap_region; 1980916c38dSRoberto Vargas 1990916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 2000916c38dSRoberto Vargas const struct mmap_region *plat_regions); 2010916c38dSRoberto Vargas 202b86048c4SAntonio Nino Diaz void bl_handle_pauth(void); 203b86048c4SAntonio Nino Diaz 204d5dfdeb6SJulius Werner #endif /*__ASSEMBLER__*/ 2054ecca339SDan Handley 206c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 207