1 /* 2 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef __BL_COMMON_H__ 8 #define __BL_COMMON_H__ 9 10 #include <ep_info.h> 11 #include <param_header.h> 12 #include <utils_def.h> 13 14 #define UP 1 15 #define DOWN 0 16 17 /******************************************************************************* 18 * Constants to identify the location of a memory region in a given memory 19 * layout. 20 ******************************************************************************/ 21 #define TOP 0x1 22 #define BOTTOM !TOP 23 24 /* 25 * The following are used for image state attributes. 26 * Image can only be in one of the following state. 27 */ 28 #define IMAGE_STATE_RESET 0 29 #define IMAGE_STATE_COPIED 1 30 #define IMAGE_STATE_COPYING 2 31 #define IMAGE_STATE_AUTHENTICATED 3 32 #define IMAGE_STATE_EXECUTED 4 33 #define IMAGE_STATE_INTERRUPTED 5 34 35 #define IMAGE_ATTRIB_SKIP_LOADING U(0x02) 36 #define IMAGE_ATTRIB_PLAT_SETUP U(0x04) 37 38 #define INVALID_IMAGE_ID U(0xFFFFFFFF) 39 40 /******************************************************************************* 41 * Constants to indicate type of exception to the common exception handler. 42 ******************************************************************************/ 43 #define SYNC_EXCEPTION_SP_EL0 0x0 44 #define IRQ_SP_EL0 0x1 45 #define FIQ_SP_EL0 0x2 46 #define SERROR_SP_EL0 0x3 47 #define SYNC_EXCEPTION_SP_ELX 0x4 48 #define IRQ_SP_ELX 0x5 49 #define FIQ_SP_ELX 0x6 50 #define SERROR_SP_ELX 0x7 51 #define SYNC_EXCEPTION_AARCH64 0x8 52 #define IRQ_AARCH64 0x9 53 #define FIQ_AARCH64 0xa 54 #define SERROR_AARCH64 0xb 55 #define SYNC_EXCEPTION_AARCH32 0xc 56 #define IRQ_AARCH32 0xd 57 #define FIQ_AARCH32 0xe 58 #define SERROR_AARCH32 0xf 59 60 #ifndef __ASSEMBLY__ 61 #include <cassert.h> 62 #include <stddef.h> 63 #include <stdint.h> 64 #include <types.h> 65 #include <utils_def.h> /* To retain compatibility */ 66 67 /* 68 * Declarations of linker defined symbols to help determine memory layout of 69 * BL images 70 */ 71 #if SEPARATE_CODE_AND_RODATA 72 extern uintptr_t __TEXT_START__; 73 extern uintptr_t __TEXT_END__; 74 extern uintptr_t __RODATA_START__; 75 extern uintptr_t __RODATA_END__; 76 #else 77 extern uintptr_t __RO_START__; 78 extern uintptr_t __RO_END__; 79 #endif 80 81 #if defined(IMAGE_BL2) 82 extern uintptr_t __BL2_END__; 83 #elif defined(IMAGE_BL2U) 84 extern uintptr_t __BL2U_END__; 85 #elif defined(IMAGE_BL31) 86 extern uintptr_t __BL31_END__; 87 #elif defined(IMAGE_BL32) 88 extern uintptr_t __BL32_END__; 89 #endif /* IMAGE_BLX */ 90 91 #if USE_COHERENT_MEM 92 extern uintptr_t __COHERENT_RAM_START__; 93 extern uintptr_t __COHERENT_RAM_END__; 94 #endif 95 96 /******************************************************************************* 97 * Structure used for telling the next BL how much of a particular type of 98 * memory is available for its use and how much is already used. 99 ******************************************************************************/ 100 typedef struct meminfo { 101 uintptr_t total_base; 102 size_t total_size; 103 #if !LOAD_IMAGE_V2 104 uintptr_t free_base; 105 size_t free_size; 106 #endif 107 } meminfo_t; 108 109 /***************************************************************************** 110 * Image info binary provides information from the image loader that 111 * can be used by the firmware to manage available trusted RAM. 112 * More advanced firmware image formats can provide additional 113 * information that enables optimization or greater flexibility in the 114 * common firmware code 115 *****************************************************************************/ 116 typedef struct image_info { 117 param_header_t h; 118 uintptr_t image_base; /* physical address of base of image */ 119 uint32_t image_size; /* bytes read from image file */ 120 #if LOAD_IMAGE_V2 121 uint32_t image_max_size; 122 #endif 123 } image_info_t; 124 125 /***************************************************************************** 126 * The image descriptor struct definition. 127 *****************************************************************************/ 128 typedef struct image_desc { 129 /* Contains unique image id for the image. */ 130 unsigned int image_id; 131 /* 132 * This member contains Image state information. 133 * Refer IMAGE_STATE_XXX defined above. 134 */ 135 unsigned int state; 136 uint32_t copied_size; /* image size copied in blocks */ 137 image_info_t image_info; 138 entry_point_info_t ep_info; 139 } image_desc_t; 140 141 #if LOAD_IMAGE_V2 142 /* BL image node in the BL image loading sequence */ 143 typedef struct bl_load_info_node { 144 unsigned int image_id; 145 image_info_t *image_info; 146 struct bl_load_info_node *next_load_info; 147 } bl_load_info_node_t; 148 149 /* BL image head node in the BL image loading sequence */ 150 typedef struct bl_load_info { 151 param_header_t h; 152 bl_load_info_node_t *head; 153 } bl_load_info_t; 154 155 /* BL image node in the BL image execution sequence */ 156 typedef struct bl_params_node { 157 unsigned int image_id; 158 image_info_t *image_info; 159 entry_point_info_t *ep_info; 160 struct bl_params_node *next_params_info; 161 } bl_params_node_t; 162 163 /* 164 * BL image head node in the BL image execution sequence 165 * It is also used to pass information to next BL image. 166 */ 167 typedef struct bl_params { 168 param_header_t h; 169 bl_params_node_t *head; 170 } bl_params_t; 171 172 #else /* LOAD_IMAGE_V2 */ 173 174 /******************************************************************************* 175 * This structure represents the superset of information that can be passed to 176 * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be 177 * populated only if BL2 detects its presence. A pointer to a structure of this 178 * type should be passed in X0 to BL31's cold boot entrypoint. 179 * 180 * Use of this structure and the X0 parameter is not mandatory: the BL31 181 * platform code can use other mechanisms to provide the necessary information 182 * about BL32 and BL33 to the common and SPD code. 183 * 184 * BL31 image information is mandatory if this structure is used. If either of 185 * the optional BL32 and BL33 image information is not provided, this is 186 * indicated by the respective image_info pointers being zero. 187 ******************************************************************************/ 188 typedef struct bl31_params { 189 param_header_t h; 190 image_info_t *bl31_image_info; 191 entry_point_info_t *bl32_ep_info; 192 image_info_t *bl32_image_info; 193 entry_point_info_t *bl33_ep_info; 194 image_info_t *bl33_image_info; 195 } bl31_params_t; 196 197 #endif /* LOAD_IMAGE_V2 */ 198 199 /******************************************************************************* 200 * Function & variable prototypes 201 ******************************************************************************/ 202 size_t image_size(unsigned int image_id); 203 204 int is_mem_free(uintptr_t free_base, size_t free_size, 205 uintptr_t addr, size_t size); 206 207 #if LOAD_IMAGE_V2 208 209 int load_auth_image(unsigned int image_id, image_info_t *image_data); 210 211 #else 212 213 int load_image(meminfo_t *mem_layout, 214 unsigned int image_id, 215 uintptr_t image_base, 216 image_info_t *image_data, 217 entry_point_info_t *entry_point_info); 218 int load_auth_image(meminfo_t *mem_layout, 219 unsigned int image_id, 220 uintptr_t image_base, 221 image_info_t *image_data, 222 entry_point_info_t *entry_point_info); 223 void reserve_mem(uintptr_t *free_base, size_t *free_size, 224 uintptr_t addr, size_t size); 225 226 #endif /* LOAD_IMAGE_V2 */ 227 228 extern const char build_message[]; 229 extern const char version_string[]; 230 231 void print_entry_point_info(const entry_point_info_t *ep_info); 232 uintptr_t page_align(uintptr_t value, unsigned dir); 233 234 #endif /*__ASSEMBLY__*/ 235 236 #endif /* __BL_COMMON_H__ */ 237