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 604ecca339SDan Handley #ifndef __ASSEMBLY__ 6109d40e0eSAntonio Nino Diaz 628f55dfb4SSandrine Bailleux #include <stddef.h> 635dffb46cSSoby Mathew #include <stdint.h> 64a7e98ad5SVikram Kanigiri 6509d40e0eSAntonio Nino Diaz #include <lib/cassert.h> 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 81*c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1) 82*c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__, BL1_ROM_END); 83*c9f9d9eaSAntonio Nino Diaz 84*c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__, BL1_RAM_BASE); 85*c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__, BL1_RAM_LIMIT); 86*c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2) 879f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2_END__, BL2_END); 883d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U) 899f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2U_END__, BL2U_END); 903d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31) 91931f7c61SSoby Mathew IMPORT_SYM(unsigned long, __BL31_START__, BL31_START); 929f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL31_END__, BL31_END); 933d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32) 949f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL32_END__, BL32_END); 9590b3a6acSDan Handley #endif /* IMAGE_BLX */ 9690b3a6acSDan Handley 97*c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */ 98*c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2) 99*c9f9d9eaSAntonio Nino Diaz extern uintptr_t __BL2_ROM_END__; 100*c9f9d9eaSAntonio Nino Diaz #define BL2_ROM_END (uintptr_t)(&__BL2_ROM_END__) 101*c9f9d9eaSAntonio Nino Diaz 102*c9f9d9eaSAntonio Nino Diaz extern uintptr_t __BL2_RAM_START__; 103*c9f9d9eaSAntonio Nino Diaz extern uintptr_t __BL2_RAM_END__; 104*c9f9d9eaSAntonio Nino Diaz #define BL2_RAM_BASE (uintptr_t)(&__BL2_RAM_START__) 105*c9f9d9eaSAntonio Nino Diaz #define BL2_RAM_LIMIT (uintptr_t)(&__BL2_RAM_END__) 106*c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */ 107*c9f9d9eaSAntonio Nino Diaz 1089f85f9e3SJoel Hutton /* 1099f85f9e3SJoel Hutton * The next 2 constants identify the extents of the coherent memory region. 1109f85f9e3SJoel Hutton * These addresses are used by the MMU setup code and therefore they must be 1119f85f9e3SJoel Hutton * page-aligned. It is the responsibility of the linker script to ensure that 1129f85f9e3SJoel Hutton * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 1139f85f9e3SJoel Hutton * page-aligned addresses. 1149f85f9e3SJoel Hutton */ 11590b3a6acSDan Handley #if USE_COHERENT_MEM 1169f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_START__, BL_COHERENT_RAM_BASE); 1179f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_END__, BL_COHERENT_RAM_END); 11890b3a6acSDan Handley #endif 11990b3a6acSDan Handley 1204ecca339SDan Handley /******************************************************************************* 1214ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1224ecca339SDan Handley * memory is available for its use and how much is already used. 1234ecca339SDan Handley ******************************************************************************/ 124fb037bfbSDan Handley typedef struct meminfo { 1254c0d0390SSoby Mathew uintptr_t total_base; 1268f55dfb4SSandrine Bailleux size_t total_size; 127fb037bfbSDan Handley } meminfo_t; 1284ecca339SDan Handley 1294112bfa0SVikram Kanigiri /***************************************************************************** 1304112bfa0SVikram Kanigiri * Image info binary provides information from the image loader that 1314112bfa0SVikram Kanigiri * can be used by the firmware to manage available trusted RAM. 1324112bfa0SVikram Kanigiri * More advanced firmware image formats can provide additional 1334112bfa0SVikram Kanigiri * information that enables optimization or greater flexibility in the 1344112bfa0SVikram Kanigiri * common firmware code 1354112bfa0SVikram Kanigiri *****************************************************************************/ 1364112bfa0SVikram Kanigiri typedef struct image_info { 1374112bfa0SVikram Kanigiri param_header_t h; 1384112bfa0SVikram Kanigiri uintptr_t image_base; /* physical address of base of image */ 1394112bfa0SVikram Kanigiri uint32_t image_size; /* bytes read from image file */ 14072600226SYatharth Kochar uint32_t image_max_size; 1414112bfa0SVikram Kanigiri } image_info_t; 1424ecca339SDan Handley 1437baff11fSYatharth Kochar /***************************************************************************** 1447baff11fSYatharth Kochar * The image descriptor struct definition. 1457baff11fSYatharth Kochar *****************************************************************************/ 1467baff11fSYatharth Kochar typedef struct image_desc { 1477baff11fSYatharth Kochar /* Contains unique image id for the image. */ 1487baff11fSYatharth Kochar unsigned int image_id; 1497baff11fSYatharth Kochar /* 1507baff11fSYatharth Kochar * This member contains Image state information. 1517baff11fSYatharth Kochar * Refer IMAGE_STATE_XXX defined above. 1527baff11fSYatharth Kochar */ 1537baff11fSYatharth Kochar unsigned int state; 154843ddee4SYatharth Kochar uint32_t copied_size; /* image size copied in blocks */ 155b313d755SSoby Mathew image_info_t image_info; 156b313d755SSoby Mathew entry_point_info_t ep_info; 1577baff11fSYatharth Kochar } image_desc_t; 1587baff11fSYatharth Kochar 15972600226SYatharth Kochar /* BL image node in the BL image loading sequence */ 16072600226SYatharth Kochar typedef struct bl_load_info_node { 16172600226SYatharth Kochar unsigned int image_id; 16272600226SYatharth Kochar image_info_t *image_info; 16372600226SYatharth Kochar struct bl_load_info_node *next_load_info; 16472600226SYatharth Kochar } bl_load_info_node_t; 16572600226SYatharth Kochar 16672600226SYatharth Kochar /* BL image head node in the BL image loading sequence */ 16772600226SYatharth Kochar typedef struct bl_load_info { 16872600226SYatharth Kochar param_header_t h; 16972600226SYatharth Kochar bl_load_info_node_t *head; 17072600226SYatharth Kochar } bl_load_info_t; 17172600226SYatharth Kochar 17272600226SYatharth Kochar /* BL image node in the BL image execution sequence */ 17372600226SYatharth Kochar typedef struct bl_params_node { 17472600226SYatharth Kochar unsigned int image_id; 17572600226SYatharth Kochar image_info_t *image_info; 17672600226SYatharth Kochar entry_point_info_t *ep_info; 17772600226SYatharth Kochar struct bl_params_node *next_params_info; 17872600226SYatharth Kochar } bl_params_node_t; 17972600226SYatharth Kochar 18072600226SYatharth Kochar /* 18172600226SYatharth Kochar * BL image head node in the BL image execution sequence 18272600226SYatharth Kochar * It is also used to pass information to next BL image. 18372600226SYatharth Kochar */ 18472600226SYatharth Kochar typedef struct bl_params { 18572600226SYatharth Kochar param_header_t h; 18672600226SYatharth Kochar bl_params_node_t *head; 18772600226SYatharth Kochar } bl_params_t; 18872600226SYatharth Kochar 1894ecca339SDan Handley /******************************************************************************* 1904ecca339SDan Handley * Function & variable prototypes 1914ecca339SDan Handley ******************************************************************************/ 192d3775d46SDaniel Boulby size_t get_image_size(unsigned int image_id); 19372600226SYatharth Kochar 19499c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size, 19599c5ebafSSandrine Bailleux uintptr_t addr, size_t size); 19699c5ebafSSandrine Bailleux 19772600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data); 19872600226SYatharth Kochar 199209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH) 200209a60ccSSoby Mathew /* 201209a60ccSSoby Mathew * API to dynamically disable authentication. Only meant for development 202209a60ccSSoby Mathew * systems. 203209a60ccSSoby Mathew */ 204209a60ccSSoby Mathew void dyn_disable_auth(void); 205209a60ccSSoby Mathew #endif 206209a60ccSSoby Mathew 20772600226SYatharth Kochar extern const char build_message[]; 20872600226SYatharth Kochar extern const char version_string[]; 20972600226SYatharth Kochar 21068a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info); 2111af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir); 21268a68c92SSandrine Bailleux 2130916c38dSRoberto Vargas struct mmap_region; 2140916c38dSRoberto Vargas 2150916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions, 2160916c38dSRoberto Vargas const struct mmap_region *plat_regions); 2170916c38dSRoberto Vargas 2184ecca339SDan Handley #endif /*__ASSEMBLY__*/ 2194ecca339SDan Handley 220c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */ 221