14ecca339SDan Handley /* 2*7affa25cSMarc Bonnici * Copyright (c) 2013-2022, 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 84*7affa25cSMarc Bonnici #if SPMC_AT_EL3 85*7affa25cSMarc Bonnici #define __EL3_LP_DESCS_START__ Load$$__EL3_LP_DESCS__$$Base 86*7affa25cSMarc Bonnici #define __EL3_LP_DESCS_END__ Load$$__EL3_LP_DESCS__$$Limit 87*7affa25cSMarc Bonnici #endif 88c2ad38ceSVarun Wadekar #define __RW_START__ Load$$LR$$LR_RW_DATA$$Base 89c2ad38ceSVarun Wadekar #define __RW_END__ Load$$LR$$LR_END$$Base 90c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_START__ Load$$__SPM_SHIM_EXCEPTIONS__$$Base 91c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_END__ Load$$__SPM_SHIM_EXCEPTIONS_EPILOGUE__$$Base 92c2ad38ceSVarun Wadekar #define __STACKS_START__ Load$$__STACKS__$$Base 93c2ad38ceSVarun Wadekar #define __STACKS_END__ Load$$__STACKS__$$Limit 94c2ad38ceSVarun Wadekar #define __TEXT_START__ Load$$__TEXT__$$Base 95c2ad38ceSVarun Wadekar #define __TEXT_END__ Load$$__TEXT_EPILOGUE__$$Base 96c2ad38ceSVarun Wadekar #endif /* USE_ARM_LINK */ 97c2ad38ceSVarun Wadekar 98d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 9909d40e0eSAntonio Nino Diaz 10090b3a6acSDan Handley /* 10190b3a6acSDan Handley * Declarations of linker defined symbols to help determine memory layout of 10290b3a6acSDan Handley * BL images 10390b3a6acSDan Handley */ 1045d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA 105f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_START__, BL_CODE_BASE); 106f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_END__, BL_CODE_END); 107f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_START__, BL_RO_DATA_BASE); 108f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_END__, BL_RO_DATA_END); 1095d1c104fSSandrine Bailleux #else 110f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_START__, BL_CODE_BASE); 111f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_END__, BL_CODE_END); 1125d1c104fSSandrine Bailleux #endif 1139aedca02SSamuel Holland #if SEPARATE_NOBITS_REGION 1149aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_START__, BL_NOBITS_BASE); 1159aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_END__, BL_NOBITS_END); 1169aedca02SSamuel Holland #endif 1172c74a29dSMasahiro Yamada IMPORT_SYM(uintptr_t, __RW_END__, BL_END); 1185d1c104fSSandrine Bailleux 119c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1) 120c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__, BL1_ROM_END); 121c9f9d9eaSAntonio Nino Diaz 122c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__, BL1_RAM_BASE); 123c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__, BL1_RAM_LIMIT); 124c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2) 125f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_END__, BL2_END); 1263d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U) 127f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2U_END__, BL2U_END); 1283d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31) 129f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_START__, BL31_START); 130f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_END__, BL31_END); 1313d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32) 132f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL32_END__, BL32_END); 1335b18de09SZelalem Aweke #elif defined(IMAGE_RMM) 1345b18de09SZelalem Aweke IMPORT_SYM(uintptr_t, __RMM_END__, RMM_END); 13590b3a6acSDan Handley #endif /* IMAGE_BLX */ 13690b3a6acSDan Handley 137c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */ 138c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2) 139f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__, BL2_ROM_END); 140c9f9d9eaSAntonio Nino Diaz 141f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__, BL2_RAM_BASE); 142f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__, BL2_RAM_END); 143c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */ 144c9f9d9eaSAntonio Nino Diaz 1459f85f9e3SJoel Hutton /* 1469f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1479f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1489f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1499f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1509f85f9e3SJoel Hutton * page-aligned addresses. 1519f85f9e3SJoel Hutton */ 15290b3a6acSDan Handley #if USE_COHERENT_MEM 153f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 154f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 15590b3a6acSDan Handley #endif 15690b3a6acSDan Handley 1574ecca339SDan Handley /******************************************************************************* 1584ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1594ecca339SDan Handley * memory is available for its use and how much is already used. 1604ecca339SDan Handley ******************************************************************************/ 161fb037bfbSDan Handley typedef struct meminfo { 1624c0d0390SSoby Mathew uintptr_t total_base; 1638f55dfb4SSandrine Bailleux size_t total_size; 164fb037bfbSDan Handley } meminfo_t; 1654ecca339SDan Handley 1664ecca339SDan Handley /******************************************************************************* 1674ecca339SDan Handley * Function & variable prototypes 1684ecca339SDan Handley ******************************************************************************/ 16972600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 17072600226SYatharth Kochar 171209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 172209a60ccSSoby Mathew /* 173209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 174209a60ccSSoby Mathew * systems. 175209a60ccSSoby Mathew */ 176209a60ccSSoby Mathew void dyn_disable_auth(void); 177209a60ccSSoby Mathew #endif 178209a60ccSSoby Mathew 17972600226SYatharth Kochar extern const char build_message[]; 18072600226SYatharth Kochar extern const char version_string[]; 18172600226SYatharth Kochar 18268a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 1831af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 18468a68c92SSandrine Bailleux 1850916c38dSRoberto Vargas struct mmap_region; 1860916c38dSRoberto Vargas 1870916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 1880916c38dSRoberto Vargas const struct mmap_region *plat_regions); 1890916c38dSRoberto Vargas 190b86048c4SAntonio Nino Diaz void bl_handle_pauth(void); 191b86048c4SAntonio Nino Diaz 192d5dfdeb6SJulius Werner #endif /*__ASSEMBLER__*/ 1934ecca339SDan Handley 194c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 195