14ecca339SDan Handley /* 29fb8af33SRoberto Vargas * Copyright (c) 2013-2018, 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 1481542c00SAntonio Nino Diaz #define UP U(1) 1581542c00SAntonio Nino Diaz #define DOWN U(0) 164ecca339SDan Handley 174ecca339SDan Handley /******************************************************************************* 188f55dfb4SSandrine Bailleux * Constants to identify the location of a memory region in a given memory 198f55dfb4SSandrine Bailleux * layout. 204ecca339SDan Handley ******************************************************************************/ 2181542c00SAntonio Nino Diaz #define TOP U(0x1) 2281542c00SAntonio Nino Diaz #define BOTTOM U(0x0) 234ecca339SDan Handley 247baff11fSYatharth Kochar /* 257baff11fSYatharth Kochar * The following are used for image state attributes. 267baff11fSYatharth Kochar * Image can only be in one of the following state. 277baff11fSYatharth Kochar */ 2881542c00SAntonio Nino Diaz #define IMAGE_STATE_RESET U(0) 2981542c00SAntonio Nino Diaz #define IMAGE_STATE_COPIED U(1) 3081542c00SAntonio Nino Diaz #define IMAGE_STATE_COPYING U(2) 3181542c00SAntonio Nino Diaz #define IMAGE_STATE_AUTHENTICATED U(3) 3281542c00SAntonio Nino Diaz #define IMAGE_STATE_EXECUTED U(4) 3381542c00SAntonio Nino Diaz #define IMAGE_STATE_INTERRUPTED U(5) 347baff11fSYatharth Kochar 35da5f2745SSoby Mathew #define IMAGE_ATTRIB_SKIP_LOADING U(0x02) 36da5f2745SSoby Mathew #define IMAGE_ATTRIB_PLAT_SETUP U(0x04) 374112bfa0SVikram Kanigiri 38da5f2745SSoby Mathew #define INVALID_IMAGE_ID U(0xFFFFFFFF) 397baff11fSYatharth Kochar 40bbf8f6f9SYatharth Kochar /******************************************************************************* 41bbf8f6f9SYatharth Kochar * Constants to indicate type of exception to the common exception handler. 42bbf8f6f9SYatharth Kochar ******************************************************************************/ 4381542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_SP_EL0 U(0x0) 4481542c00SAntonio Nino Diaz #define IRQ_SP_EL0 U(0x1) 4581542c00SAntonio Nino Diaz #define FIQ_SP_EL0 U(0x2) 4681542c00SAntonio Nino Diaz #define SERROR_SP_EL0 U(0x3) 4781542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_SP_ELX U(0x4) 4881542c00SAntonio Nino Diaz #define IRQ_SP_ELX U(0x5) 4981542c00SAntonio Nino Diaz #define FIQ_SP_ELX U(0x6) 5081542c00SAntonio Nino Diaz #define SERROR_SP_ELX U(0x7) 5181542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_AARCH64 U(0x8) 5281542c00SAntonio Nino Diaz #define IRQ_AARCH64 U(0x9) 5381542c00SAntonio Nino Diaz #define FIQ_AARCH64 U(0xa) 5481542c00SAntonio Nino Diaz #define SERROR_AARCH64 U(0xb) 5581542c00SAntonio Nino Diaz #define SYNC_EXCEPTION_AARCH32 U(0xc) 5681542c00SAntonio Nino Diaz #define IRQ_AARCH32 U(0xd) 5781542c00SAntonio Nino Diaz #define FIQ_AARCH32 U(0xe) 5881542c00SAntonio Nino Diaz #define SERROR_AARCH32 U(0xf) 59bbf8f6f9SYatharth Kochar 60*c2ad38ceSVarun Wadekar /* 61*c2ad38ceSVarun Wadekar * Mapping to connect linker symbols from .ld.S with their counterparts 62*c2ad38ceSVarun Wadekar * from .scat for the BL31 image 63*c2ad38ceSVarun Wadekar */ 64*c2ad38ceSVarun Wadekar #if defined(USE_ARM_LINK) 65*c2ad38ceSVarun Wadekar #define __BL31_END__ Load$$LR$$LR_END$$Base 66*c2ad38ceSVarun Wadekar #define __BSS_START__ Load$$LR$$LR_BSS$$Base 67*c2ad38ceSVarun Wadekar #define __BSS_END__ Load$$LR$$LR_BSS$$Limit 68*c2ad38ceSVarun Wadekar #define __BSS_SIZE__ Load$$LR$$LR_BSS$$Length 69*c2ad38ceSVarun Wadekar #define __COHERENT_RAM_START__ Load$$LR$$LR_COHERENT_RAM$$Base 70*c2ad38ceSVarun Wadekar #define __COHERENT_RAM_END_UNALIGNED__ Load$$__COHERENT_RAM_EPILOGUE_UNALIGNED__$$Base 71*c2ad38ceSVarun Wadekar #define __COHERENT_RAM_END__ Load$$LR$$LR_COHERENT_RAM$$Limit 72*c2ad38ceSVarun Wadekar #define __COHERENT_RAM_UNALIGNED_SIZE__ Load$$__COHERENT_RAM__$$Length 73*c2ad38ceSVarun Wadekar #define __CPU_OPS_START__ Load$$__CPU_OPS__$$Base 74*c2ad38ceSVarun Wadekar #define __CPU_OPS_END__ Load$$__CPU_OPS__$$Limit 75*c2ad38ceSVarun Wadekar #define __DATA_START__ Load$$__DATA__$$Base 76*c2ad38ceSVarun Wadekar #define __DATA_END__ Load$$__DATA__$$Limit 77*c2ad38ceSVarun Wadekar #define __GOT_START__ Load$$__GOT__$$Base 78*c2ad38ceSVarun Wadekar #define __GOT_END__ Load$$__GOT__$$Limit 79*c2ad38ceSVarun Wadekar #define __PERCPU_BAKERY_LOCK_START__ Load$$__BAKERY_LOCKS__$$Base 80*c2ad38ceSVarun Wadekar #define __PERCPU_BAKERY_LOCK_END__ Load$$__BAKERY_LOCKS_EPILOGUE__$$Base 81*c2ad38ceSVarun Wadekar #define __PMF_SVC_DESCS_START__ Load$$__PMF_SVC_DESCS__$$Base 82*c2ad38ceSVarun Wadekar #define __PMF_SVC_DESCS_END__ Load$$__PMF_SVC_DESCS__$$Limit 83*c2ad38ceSVarun Wadekar #define __PMF_TIMESTAMP_START__ Load$$__PMF_TIMESTAMP__$$Base 84*c2ad38ceSVarun Wadekar #define __PMF_TIMESTAMP_END__ Load$$__PER_CPU_TIMESTAMPS__$$Limit 85*c2ad38ceSVarun Wadekar #define __PMF_PERCPU_TIMESTAMP_END__ Load$$__PMF_TIMESTAMP_EPILOGUE__$$Base 86*c2ad38ceSVarun Wadekar #define __RELA_END__ Load$$__RELA__$$Limit 87*c2ad38ceSVarun Wadekar #define __RELA_START__ Load$$__RELA__$$Base 88*c2ad38ceSVarun Wadekar #define __RODATA_START__ Load$$__RODATA__$$Base 89*c2ad38ceSVarun Wadekar #define __RODATA_END__ Load$$__RODATA_EPILOGUE__$$Base 90*c2ad38ceSVarun Wadekar #define __RT_SVC_DESCS_START__ Load$$__RT_SVC_DESCS__$$Base 91*c2ad38ceSVarun Wadekar #define __RT_SVC_DESCS_END__ Load$$__RT_SVC_DESCS__$$Limit 92*c2ad38ceSVarun Wadekar #define __RW_START__ Load$$LR$$LR_RW_DATA$$Base 93*c2ad38ceSVarun Wadekar #define __RW_END__ Load$$LR$$LR_END$$Base 94*c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_START__ Load$$__SPM_SHIM_EXCEPTIONS__$$Base 95*c2ad38ceSVarun Wadekar #define __SPM_SHIM_EXCEPTIONS_END__ Load$$__SPM_SHIM_EXCEPTIONS_EPILOGUE__$$Base 96*c2ad38ceSVarun Wadekar #define __STACKS_START__ Load$$__STACKS__$$Base 97*c2ad38ceSVarun Wadekar #define __STACKS_END__ Load$$__STACKS__$$Limit 98*c2ad38ceSVarun Wadekar #define __TEXT_START__ Load$$__TEXT__$$Base 99*c2ad38ceSVarun Wadekar #define __TEXT_END__ Load$$__TEXT_EPILOGUE__$$Base 100*c2ad38ceSVarun Wadekar #endif /* USE_ARM_LINK */ 101*c2ad38ceSVarun Wadekar 1024ecca339SDan Handley #ifndef __ASSEMBLY__ 10309d40e0eSAntonio Nino Diaz 1048f55dfb4SSandrine Bailleux #include <stddef.h> 1055dffb46cSSoby Mathew #include <stdint.h> 106a7e98ad5SVikram Kanigiri 10709d40e0eSAntonio Nino Diaz #include <lib/cassert.h> 1089f85f9e3SJoel Hutton 10990b3a6acSDan Handley /* 11090b3a6acSDan Handley * Declarations of linker defined symbols to help determine memory layout of 11190b3a6acSDan Handley * BL images 11290b3a6acSDan Handley */ 1135d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA 114f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_START__, BL_CODE_BASE); 115f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_END__, BL_CODE_END); 116f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_START__, BL_RO_DATA_BASE); 117f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_END__, BL_RO_DATA_END); 1185d1c104fSSandrine Bailleux #else 119f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_START__, BL_CODE_BASE); 120f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_END__, BL_CODE_END); 1215d1c104fSSandrine Bailleux #endif 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); 13790b3a6acSDan Handley #endif /* IMAGE_BLX */ 13890b3a6acSDan Handley 139c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */ 140c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2) 141f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__, BL2_ROM_END); 142c9f9d9eaSAntonio Nino Diaz 143f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__, BL2_RAM_BASE); 144f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__, BL2_RAM_END); 145c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */ 146c9f9d9eaSAntonio Nino Diaz 1479f85f9e3SJoel Hutton /* 1489f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1499f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1509f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1519f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1529f85f9e3SJoel Hutton * page-aligned addresses. 1539f85f9e3SJoel Hutton */ 15490b3a6acSDan Handley #if USE_COHERENT_MEM 155f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 156f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 15790b3a6acSDan Handley #endif 15890b3a6acSDan Handley 1594ecca339SDan Handley /******************************************************************************* 1604ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1614ecca339SDan Handley * memory is available for its use and how much is already used. 1624ecca339SDan Handley ******************************************************************************/ 163fb037bfbSDan Handley typedef struct meminfo { 1644c0d0390SSoby Mathew uintptr_t total_base; 1658f55dfb4SSandrine Bailleux size_t total_size; 166fb037bfbSDan Handley } meminfo_t; 1674ecca339SDan Handley 1684112bfa0SVikram Kanigiri /***************************************************************************** 1694112bfa0SVikram Kanigiri * Image info binary provides information from the image loader that 1704112bfa0SVikram Kanigiri * can be used by the firmware to manage available trusted RAM. 1714112bfa0SVikram Kanigiri * More advanced firmware image formats can provide additional 1724112bfa0SVikram Kanigiri * information that enables optimization or greater flexibility in the 1734112bfa0SVikram Kanigiri * common firmware code 1744112bfa0SVikram Kanigiri *****************************************************************************/ 1754112bfa0SVikram Kanigiri typedef struct image_info { 1764112bfa0SVikram Kanigiri param_header_t h; 1774112bfa0SVikram Kanigiri uintptr_t image_base; /* physical address of base of image */ 1784112bfa0SVikram Kanigiri uint32_t image_size; /* bytes read from image file */ 17972600226SYatharth Kochar uint32_t image_max_size; 1804112bfa0SVikram Kanigiri } image_info_t; 1814ecca339SDan Handley 1827baff11fSYatharth Kochar /***************************************************************************** 1837baff11fSYatharth Kochar * The image descriptor struct definition. 1847baff11fSYatharth Kochar *****************************************************************************/ 1857baff11fSYatharth Kochar typedef struct image_desc { 1867baff11fSYatharth Kochar /* Contains unique image id for the image. */ 1877baff11fSYatharth Kochar unsigned int image_id; 1887baff11fSYatharth Kochar /* 1897baff11fSYatharth Kochar * This member contains Image state information. 1907baff11fSYatharth Kochar * Refer IMAGE_STATE_XXX defined above. 1917baff11fSYatharth Kochar */ 1927baff11fSYatharth Kochar unsigned int state; 193843ddee4SYatharth Kochar uint32_t copied_size; /* image size copied in blocks */ 194b313d755SSoby Mathew image_info_t image_info; 195b313d755SSoby Mathew entry_point_info_t ep_info; 1967baff11fSYatharth Kochar } image_desc_t; 1977baff11fSYatharth Kochar 19872600226SYatharth Kochar /* BL image node in the BL image loading sequence */ 19972600226SYatharth Kochar typedef struct bl_load_info_node { 20072600226SYatharth Kochar unsigned int image_id; 20172600226SYatharth Kochar image_info_t *image_info; 20272600226SYatharth Kochar struct bl_load_info_node *next_load_info; 20372600226SYatharth Kochar } bl_load_info_node_t; 20472600226SYatharth Kochar 20572600226SYatharth Kochar /* BL image head node in the BL image loading sequence */ 20672600226SYatharth Kochar typedef struct bl_load_info { 20772600226SYatharth Kochar param_header_t h; 20872600226SYatharth Kochar bl_load_info_node_t *head; 20972600226SYatharth Kochar } bl_load_info_t; 21072600226SYatharth Kochar 21172600226SYatharth Kochar /* BL image node in the BL image execution sequence */ 21272600226SYatharth Kochar typedef struct bl_params_node { 21372600226SYatharth Kochar unsigned int image_id; 21472600226SYatharth Kochar image_info_t *image_info; 21572600226SYatharth Kochar entry_point_info_t *ep_info; 21672600226SYatharth Kochar struct bl_params_node *next_params_info; 21772600226SYatharth Kochar } bl_params_node_t; 21872600226SYatharth Kochar 21972600226SYatharth Kochar /* 22072600226SYatharth Kochar * BL image head node in the BL image execution sequence 22172600226SYatharth Kochar * It is also used to pass information to next BL image. 22272600226SYatharth Kochar */ 22372600226SYatharth Kochar typedef struct bl_params { 22472600226SYatharth Kochar param_header_t h; 22572600226SYatharth Kochar bl_params_node_t *head; 22672600226SYatharth Kochar } bl_params_t; 22772600226SYatharth Kochar 2284ecca339SDan Handley /******************************************************************************* 2294ecca339SDan Handley * Function & variable prototypes 2304ecca339SDan Handley ******************************************************************************/ 23172600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 23272600226SYatharth Kochar 233209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 234209a60ccSSoby Mathew /* 235209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 236209a60ccSSoby Mathew * systems. 237209a60ccSSoby Mathew */ 238209a60ccSSoby Mathew void dyn_disable_auth(void); 239209a60ccSSoby Mathew #endif 240209a60ccSSoby Mathew 24172600226SYatharth Kochar extern const char build_message[]; 24272600226SYatharth Kochar extern const char version_string[]; 24372600226SYatharth Kochar 24468a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 2451af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 24668a68c92SSandrine Bailleux 2470916c38dSRoberto Vargas struct mmap_region; 2480916c38dSRoberto Vargas 2490916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 2500916c38dSRoberto Vargas const struct mmap_region *plat_regions); 2510916c38dSRoberto Vargas 2524ecca339SDan Handley #endif /*__ASSEMBLY__*/ 2534ecca339SDan Handley 254c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 255