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 74ecca339SDan Handley #ifndef __BL_COMMON_H__ 84ecca339SDan Handley #define __BL_COMMON_H__ 94ecca339SDan Handley 105dffb46cSSoby Mathew #include <ep_info.h> 115dffb46cSSoby Mathew #include <param_header.h> 12da5f2745SSoby Mathew #include <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 604ecca339SDan Handley #ifndef __ASSEMBLY__ 6129fb905dSVikram Kanigiri #include <cassert.h> 628f55dfb4SSandrine Bailleux #include <stddef.h> 635dffb46cSSoby Mathew #include <stdint.h> 6453d9c9c8SScott Branden #include <utils_def.h> /* To retain compatibility */ 65a7e98ad5SVikram Kanigiri 669f85f9e3SJoel Hutton 6790b3a6acSDan Handley /* 6890b3a6acSDan Handley * Declarations of linker defined symbols to help determine memory layout of 6990b3a6acSDan Handley * BL images 7090b3a6acSDan Handley */ 715d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA 729f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __TEXT_START__, BL_CODE_BASE); 739f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __TEXT_END__, BL_CODE_END); 749f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RODATA_START__, BL_RO_DATA_BASE); 759f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RODATA_END__, BL_RO_DATA_END); 765d1c104fSSandrine Bailleux #else 779f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RO_START__, BL_CODE_BASE); 789f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RO_END__, BL_CODE_END); 795d1c104fSSandrine Bailleux #endif 805d1c104fSSandrine Bailleux 813d8256b2SMasahiro Yamada #if defined(IMAGE_BL2) 829f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2_END__, BL2_END); 833d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U) 849f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2U_END__, BL2U_END); 853d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31) 869f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL31_END__, BL31_END); 873d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32) 889f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL32_END__, BL32_END); 8990b3a6acSDan Handley #endif /* IMAGE_BLX */ 9090b3a6acSDan Handley 919f85f9e3SJoel Hutton /* 929f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 939f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 949f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 959f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 969f85f9e3SJoel Hutton * page-aligned addresses. 979f85f9e3SJoel Hutton */ 9890b3a6acSDan Handley #if USE_COHERENT_MEM 999f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 1009f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 10190b3a6acSDan Handley #endif 10290b3a6acSDan Handley 1034ecca339SDan Handley /******************************************************************************* 1044ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1054ecca339SDan Handley * memory is available for its use and how much is already used. 1064ecca339SDan Handley ******************************************************************************/ 107fb037bfbSDan Handley typedef struct meminfo { 1084c0d0390SSoby Mathew uintptr_t total_base; 1098f55dfb4SSandrine Bailleux size_t total_size; 110fb037bfbSDan Handley } meminfo_t; 1114ecca339SDan Handley 1124112bfa0SVikram Kanigiri /***************************************************************************** 1134112bfa0SVikram Kanigiri * Image info binary provides information from the image loader that 1144112bfa0SVikram Kanigiri * can be used by the firmware to manage available trusted RAM. 1154112bfa0SVikram Kanigiri * More advanced firmware image formats can provide additional 1164112bfa0SVikram Kanigiri * information that enables optimization or greater flexibility in the 1174112bfa0SVikram Kanigiri * common firmware code 1184112bfa0SVikram Kanigiri *****************************************************************************/ 1194112bfa0SVikram Kanigiri typedef struct image_info { 1204112bfa0SVikram Kanigiri param_header_t h; 1214112bfa0SVikram Kanigiri uintptr_t image_base; /* physical address of base of image */ 1224112bfa0SVikram Kanigiri uint32_t image_size; /* bytes read from image file */ 12372600226SYatharth Kochar uint32_t image_max_size; 1244112bfa0SVikram Kanigiri } image_info_t; 1254ecca339SDan Handley 1267baff11fSYatharth Kochar /***************************************************************************** 1277baff11fSYatharth Kochar * The image descriptor struct definition. 1287baff11fSYatharth Kochar *****************************************************************************/ 1297baff11fSYatharth Kochar typedef struct image_desc { 1307baff11fSYatharth Kochar /* Contains unique image id for the image. */ 1317baff11fSYatharth Kochar unsigned int image_id; 1327baff11fSYatharth Kochar /* 1337baff11fSYatharth Kochar * This member contains Image state information. 1347baff11fSYatharth Kochar * Refer IMAGE_STATE_XXX defined above. 1357baff11fSYatharth Kochar */ 1367baff11fSYatharth Kochar unsigned int state; 137843ddee4SYatharth Kochar uint32_t copied_size; /* image size copied in blocks */ 138b313d755SSoby Mathew image_info_t image_info; 139b313d755SSoby Mathew entry_point_info_t ep_info; 1407baff11fSYatharth Kochar } image_desc_t; 1417baff11fSYatharth Kochar 14272600226SYatharth Kochar /* BL image node in the BL image loading sequence */ 14372600226SYatharth Kochar typedef struct bl_load_info_node { 14472600226SYatharth Kochar unsigned int image_id; 14572600226SYatharth Kochar image_info_t *image_info; 14672600226SYatharth Kochar struct bl_load_info_node *next_load_info; 14772600226SYatharth Kochar } bl_load_info_node_t; 14872600226SYatharth Kochar 14972600226SYatharth Kochar /* BL image head node in the BL image loading sequence */ 15072600226SYatharth Kochar typedef struct bl_load_info { 15172600226SYatharth Kochar param_header_t h; 15272600226SYatharth Kochar bl_load_info_node_t *head; 15372600226SYatharth Kochar } bl_load_info_t; 15472600226SYatharth Kochar 15572600226SYatharth Kochar /* BL image node in the BL image execution sequence */ 15672600226SYatharth Kochar typedef struct bl_params_node { 15772600226SYatharth Kochar unsigned int image_id; 15872600226SYatharth Kochar image_info_t *image_info; 15972600226SYatharth Kochar entry_point_info_t *ep_info; 16072600226SYatharth Kochar struct bl_params_node *next_params_info; 16172600226SYatharth Kochar } bl_params_node_t; 16272600226SYatharth Kochar 16372600226SYatharth Kochar /* 16472600226SYatharth Kochar * BL image head node in the BL image execution sequence 16572600226SYatharth Kochar * It is also used to pass information to next BL image. 16672600226SYatharth Kochar */ 16772600226SYatharth Kochar typedef struct bl_params { 16872600226SYatharth Kochar param_header_t h; 16972600226SYatharth Kochar bl_params_node_t *head; 17072600226SYatharth Kochar } bl_params_t; 17172600226SYatharth Kochar 1724ecca339SDan Handley /******************************************************************************* 1734ecca339SDan Handley * Function & variable prototypes 1744ecca339SDan Handley ******************************************************************************/ 175d3775d46SDaniel Boulby size_t get_image_size(unsigned int image_id); 17672600226SYatharth Kochar 17799c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size, 17899c5ebafSSandrine Bailleux uintptr_t addr, size_t size); 17999c5ebafSSandrine Bailleux 18072600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 18172600226SYatharth Kochar 182209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 183209a60ccSSoby Mathew /* 184209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 185209a60ccSSoby Mathew * systems. 186209a60ccSSoby Mathew */ 187209a60ccSSoby Mathew void dyn_disable_auth(void); 188209a60ccSSoby Mathew #endif 189209a60ccSSoby Mathew 19072600226SYatharth Kochar extern const char build_message[]; 19172600226SYatharth Kochar extern const char version_string[]; 19272600226SYatharth Kochar 19368a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 1941af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 19568a68c92SSandrine Bailleux 196*0916c38dSRoberto Vargas struct mmap_region; 197*0916c38dSRoberto Vargas 198*0916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 199*0916c38dSRoberto Vargas const struct mmap_region *plat_regions); 200*0916c38dSRoberto Vargas 2014ecca339SDan Handley #endif /*__ASSEMBLY__*/ 2024ecca339SDan Handley 2034ecca339SDan Handley #endif /* __BL_COMMON_H__ */ 204