14ecca339SDan Handley /* 22c74a29dSMasahiro Yamada * Copyright (c) 2013-2020, 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 84c2ad38ceSVarun Wadekar #define __RW_START__ Load$$LR$$LR_RW_DATA$$Base 85c2ad38ceSVarun Wadekar #define __RW_END__ Load$$LR$$LR_END$$Base 86c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_START__ Load$$__SPM_SHIM_EXCEPTIONS__$$Base 87c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_END__ Load$$__SPM_SHIM_EXCEPTIONS_EPILOGUE__$$Base 88c2ad38ceSVarun Wadekar #define __STACKS_START__ Load$$__STACKS__$$Base 89c2ad38ceSVarun Wadekar #define __STACKS_END__ Load$$__STACKS__$$Limit 90c2ad38ceSVarun Wadekar #define __TEXT_START__ Load$$__TEXT__$$Base 91c2ad38ceSVarun Wadekar #define __TEXT_END__ Load$$__TEXT_EPILOGUE__$$Base 92c2ad38ceSVarun Wadekar #endif /* USE_ARM_LINK */ 93c2ad38ceSVarun Wadekar 94d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 9509d40e0eSAntonio Nino Diaz 9690b3a6acSDan Handley /* 9790b3a6acSDan Handley * Declarations of linker defined symbols to help determine memory layout of 9890b3a6acSDan Handley * BL images 9990b3a6acSDan Handley */ 1005d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA 101f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_START__, BL_CODE_BASE); 102f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_END__, BL_CODE_END); 103f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_START__, BL_RO_DATA_BASE); 104f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_END__, BL_RO_DATA_END); 1055d1c104fSSandrine Bailleux #else 106f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_START__, BL_CODE_BASE); 107f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_END__, BL_CODE_END); 1085d1c104fSSandrine Bailleux #endif 109*9aedca02SSamuel Holland #if SEPARATE_NOBITS_REGION 110*9aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_START__, BL_NOBITS_BASE); 111*9aedca02SSamuel Holland IMPORT_SYM(uintptr_t, __NOBITS_END__, BL_NOBITS_END); 112*9aedca02SSamuel Holland #endif 1132c74a29dSMasahiro Yamada IMPORT_SYM(uintptr_t, __RW_END__, BL_END); 1145d1c104fSSandrine Bailleux 115c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1) 116c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__, BL1_ROM_END); 117c9f9d9eaSAntonio Nino Diaz 118c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__, BL1_RAM_BASE); 119c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__, BL1_RAM_LIMIT); 120c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2) 121f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_END__, BL2_END); 1223d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U) 123f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2U_END__, BL2U_END); 1243d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31) 125f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_START__, BL31_START); 126f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_END__, BL31_END); 1273d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32) 128f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL32_END__, BL32_END); 12990b3a6acSDan Handley #endif /* IMAGE_BLX */ 13090b3a6acSDan Handley 131c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */ 132c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2) 133f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__, BL2_ROM_END); 134c9f9d9eaSAntonio Nino Diaz 135f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__, BL2_RAM_BASE); 136f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__, BL2_RAM_END); 137c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */ 138c9f9d9eaSAntonio Nino Diaz 1399f85f9e3SJoel Hutton /* 1409f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1419f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1429f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1439f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1449f85f9e3SJoel Hutton * page-aligned addresses. 1459f85f9e3SJoel Hutton */ 14690b3a6acSDan Handley #if USE_COHERENT_MEM 147f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 148f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 14990b3a6acSDan Handley #endif 15090b3a6acSDan Handley 1514ecca339SDan Handley /******************************************************************************* 1524ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1534ecca339SDan Handley * memory is available for its use and how much is already used. 1544ecca339SDan Handley ******************************************************************************/ 155fb037bfbSDan Handley typedef struct meminfo { 1564c0d0390SSoby Mathew uintptr_t total_base; 1578f55dfb4SSandrine Bailleux size_t total_size; 158fb037bfbSDan Handley } meminfo_t; 1594ecca339SDan Handley 1604ecca339SDan Handley /******************************************************************************* 1614ecca339SDan Handley * Function & variable prototypes 1624ecca339SDan Handley ******************************************************************************/ 16372600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 16472600226SYatharth Kochar 165209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 166209a60ccSSoby Mathew /* 167209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 168209a60ccSSoby Mathew * systems. 169209a60ccSSoby Mathew */ 170209a60ccSSoby Mathew void dyn_disable_auth(void); 171209a60ccSSoby Mathew #endif 172209a60ccSSoby Mathew 17372600226SYatharth Kochar extern const char build_message[]; 17472600226SYatharth Kochar extern const char version_string[]; 17572600226SYatharth Kochar 17668a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 1771af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 17868a68c92SSandrine Bailleux 1790916c38dSRoberto Vargas struct mmap_region; 1800916c38dSRoberto Vargas 1810916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 1820916c38dSRoberto Vargas const struct mmap_region *plat_regions); 1830916c38dSRoberto Vargas 184b86048c4SAntonio Nino Diaz void bl_handle_pauth(void); 185b86048c4SAntonio Nino Diaz 186d5dfdeb6SJulius Werner #endif /*__ASSEMBLER__*/ 1874ecca339SDan Handley 188c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 189