14ecca339SDan Handley /* 2b86048c4SAntonio Nino Diaz * Copyright (c) 2013-2019, 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 14*d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 1557bf6057SJulius Werner #include <stddef.h> 1657bf6057SJulius Werner #include <stdint.h> 1757bf6057SJulius Werner #include <lib/cassert.h> 18*d5dfdeb6SJulius 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 94*d5dfdeb6SJulius 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 1095d1c104fSSandrine Bailleux 110c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1) 111c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__, BL1_ROM_END); 112c9f9d9eaSAntonio Nino Diaz 113c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__, BL1_RAM_BASE); 114c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__, BL1_RAM_LIMIT); 115c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2) 116f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_END__, BL2_END); 1173d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U) 118f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2U_END__, BL2U_END); 1193d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31) 120f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_START__, BL31_START); 121f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_END__, BL31_END); 1223d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32) 123f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL32_END__, BL32_END); 12490b3a6acSDan Handley #endif /* IMAGE_BLX */ 12590b3a6acSDan Handley 126c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */ 127c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2) 128f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__, BL2_ROM_END); 129c9f9d9eaSAntonio Nino Diaz 130f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__, BL2_RAM_BASE); 131f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__, BL2_RAM_END); 132c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */ 133c9f9d9eaSAntonio Nino Diaz 1349f85f9e3SJoel Hutton /* 1359f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1369f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1379f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1389f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1399f85f9e3SJoel Hutton * page-aligned addresses. 1409f85f9e3SJoel Hutton */ 14190b3a6acSDan Handley #if USE_COHERENT_MEM 142f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 143f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 14490b3a6acSDan Handley #endif 14590b3a6acSDan Handley 1464ecca339SDan Handley /******************************************************************************* 1474ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1484ecca339SDan Handley * memory is available for its use and how much is already used. 1494ecca339SDan Handley ******************************************************************************/ 150fb037bfbSDan Handley typedef struct meminfo { 1514c0d0390SSoby Mathew uintptr_t total_base; 1528f55dfb4SSandrine Bailleux size_t total_size; 153fb037bfbSDan Handley } meminfo_t; 1544ecca339SDan Handley 1554ecca339SDan Handley /******************************************************************************* 1564ecca339SDan Handley * Function & variable prototypes 1574ecca339SDan Handley ******************************************************************************/ 15872600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 15972600226SYatharth Kochar 160209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 161209a60ccSSoby Mathew /* 162209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 163209a60ccSSoby Mathew * systems. 164209a60ccSSoby Mathew */ 165209a60ccSSoby Mathew void dyn_disable_auth(void); 166209a60ccSSoby Mathew #endif 167209a60ccSSoby Mathew 16872600226SYatharth Kochar extern const char build_message[]; 16972600226SYatharth Kochar extern const char version_string[]; 17072600226SYatharth Kochar 17168a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 1721af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 17368a68c92SSandrine Bailleux 1740916c38dSRoberto Vargas struct mmap_region; 1750916c38dSRoberto Vargas 1760916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 1770916c38dSRoberto Vargas const struct mmap_region *plat_regions); 1780916c38dSRoberto Vargas 179b86048c4SAntonio Nino Diaz void bl_handle_pauth(void); 180b86048c4SAntonio Nino Diaz 181*d5dfdeb6SJulius Werner #endif /*__ASSEMBLER__*/ 1824ecca339SDan Handley 183c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 184