Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __BL_COMMON_H__ |
| 32 | #define __BL_COMMON_H__ |
| 33 | |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 34 | #include <ep_info.h> |
| 35 | #include <param_header.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 36 | |
| 37 | #define UP 1 |
| 38 | #define DOWN 0 |
| 39 | |
| 40 | /******************************************************************************* |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 41 | * Constants to identify the location of a memory region in a given memory |
| 42 | * layout. |
| 43 | ******************************************************************************/ |
| 44 | #define TOP 0x1 |
| 45 | #define BOTTOM !TOP |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 46 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 47 | /* |
| 48 | * The following are used for image state attributes. |
| 49 | * Image can only be in one of the following state. |
| 50 | */ |
| 51 | #define IMAGE_STATE_RESET 0 |
| 52 | #define IMAGE_STATE_COPIED 1 |
| 53 | #define IMAGE_STATE_COPYING 2 |
| 54 | #define IMAGE_STATE_AUTHENTICATED 3 |
| 55 | #define IMAGE_STATE_EXECUTED 4 |
| 56 | #define IMAGE_STATE_INTERRUPTED 5 |
| 57 | |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 58 | #define IMAGE_ATTRIB_SKIP_LOADING 0x02 |
| 59 | #define IMAGE_ATTRIB_PLAT_SETUP 0x04 |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 60 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 61 | #define INVALID_IMAGE_ID (0xFFFFFFFF) |
| 62 | |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 63 | /******************************************************************************* |
| 64 | * Constants to indicate type of exception to the common exception handler. |
| 65 | ******************************************************************************/ |
| 66 | #define SYNC_EXCEPTION_SP_EL0 0x0 |
| 67 | #define IRQ_SP_EL0 0x1 |
| 68 | #define FIQ_SP_EL0 0x2 |
| 69 | #define SERROR_SP_EL0 0x3 |
| 70 | #define SYNC_EXCEPTION_SP_ELX 0x4 |
| 71 | #define IRQ_SP_ELX 0x5 |
| 72 | #define FIQ_SP_ELX 0x6 |
| 73 | #define SERROR_SP_ELX 0x7 |
| 74 | #define SYNC_EXCEPTION_AARCH64 0x8 |
| 75 | #define IRQ_AARCH64 0x9 |
| 76 | #define FIQ_AARCH64 0xa |
| 77 | #define SERROR_AARCH64 0xb |
| 78 | #define SYNC_EXCEPTION_AARCH32 0xc |
| 79 | #define IRQ_AARCH32 0xd |
| 80 | #define FIQ_AARCH32 0xe |
| 81 | #define SERROR_AARCH32 0xf |
| 82 | |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 83 | #ifndef __ASSEMBLY__ |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 84 | #include <cassert.h> |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 85 | #include <stddef.h> |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 86 | #include <stdint.h> |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 87 | #include <types.h> |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 88 | #include <utils.h> /* To retain compatibility */ |
Vikram Kanigiri | 725b133 | 2015-03-04 10:34:27 +0000 | [diff] [blame] | 89 | |
Dan Handley | f05c1b5 | 2015-04-27 11:49:22 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Declarations of linker defined symbols to help determine memory layout of |
| 92 | * BL images |
| 93 | */ |
Sandrine Bailleux | f91f144 | 2016-07-08 14:37:40 +0100 | [diff] [blame] | 94 | #if SEPARATE_CODE_AND_RODATA |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 95 | extern uintptr_t __TEXT_START__; |
| 96 | extern uintptr_t __TEXT_END__; |
| 97 | extern uintptr_t __RODATA_START__; |
| 98 | extern uintptr_t __RODATA_END__; |
Sandrine Bailleux | f91f144 | 2016-07-08 14:37:40 +0100 | [diff] [blame] | 99 | #else |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 100 | extern uintptr_t __RO_START__; |
| 101 | extern uintptr_t __RO_END__; |
Sandrine Bailleux | f91f144 | 2016-07-08 14:37:40 +0100 | [diff] [blame] | 102 | #endif |
| 103 | |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 104 | #if defined(IMAGE_BL2) |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 105 | extern uintptr_t __BL2_END__; |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 106 | #elif defined(IMAGE_BL2U) |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 107 | extern uintptr_t __BL2U_END__; |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 108 | #elif defined(IMAGE_BL31) |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 109 | extern uintptr_t __BL31_END__; |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 110 | #elif defined(IMAGE_BL32) |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 111 | extern uintptr_t __BL32_END__; |
Dan Handley | f05c1b5 | 2015-04-27 11:49:22 +0100 | [diff] [blame] | 112 | #endif /* IMAGE_BLX */ |
| 113 | |
| 114 | #if USE_COHERENT_MEM |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 115 | extern uintptr_t __COHERENT_RAM_START__; |
| 116 | extern uintptr_t __COHERENT_RAM_END__; |
Dan Handley | f05c1b5 | 2015-04-27 11:49:22 +0100 | [diff] [blame] | 117 | #endif |
| 118 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 119 | /******************************************************************************* |
| 120 | * Structure used for telling the next BL how much of a particular type of |
| 121 | * memory is available for its use and how much is already used. |
| 122 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 123 | typedef struct meminfo { |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 124 | uintptr_t total_base; |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 125 | size_t total_size; |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 126 | #if !LOAD_IMAGE_V2 |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 127 | uintptr_t free_base; |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 128 | size_t free_size; |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 129 | #endif |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 130 | } meminfo_t; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 131 | |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 132 | /***************************************************************************** |
| 133 | * Image info binary provides information from the image loader that |
| 134 | * can be used by the firmware to manage available trusted RAM. |
| 135 | * More advanced firmware image formats can provide additional |
| 136 | * information that enables optimization or greater flexibility in the |
| 137 | * common firmware code |
| 138 | *****************************************************************************/ |
| 139 | typedef struct image_info { |
| 140 | param_header_t h; |
| 141 | uintptr_t image_base; /* physical address of base of image */ |
| 142 | uint32_t image_size; /* bytes read from image file */ |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 143 | #if LOAD_IMAGE_V2 |
| 144 | uint32_t image_max_size; |
| 145 | #endif |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 146 | } image_info_t; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 147 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 148 | /***************************************************************************** |
| 149 | * The image descriptor struct definition. |
| 150 | *****************************************************************************/ |
| 151 | typedef struct image_desc { |
| 152 | /* Contains unique image id for the image. */ |
| 153 | unsigned int image_id; |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 154 | /* |
| 155 | * This member contains Image state information. |
| 156 | * Refer IMAGE_STATE_XXX defined above. |
| 157 | */ |
| 158 | unsigned int state; |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 159 | uint32_t copied_size; /* image size copied in blocks */ |
Soby Mathew | 6d4f262 | 2016-01-12 10:30:59 +0000 | [diff] [blame] | 160 | image_info_t image_info; |
| 161 | entry_point_info_t ep_info; |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 162 | } image_desc_t; |
| 163 | |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 164 | #if LOAD_IMAGE_V2 |
| 165 | /* BL image node in the BL image loading sequence */ |
| 166 | typedef struct bl_load_info_node { |
| 167 | unsigned int image_id; |
| 168 | image_info_t *image_info; |
| 169 | struct bl_load_info_node *next_load_info; |
| 170 | } bl_load_info_node_t; |
| 171 | |
| 172 | /* BL image head node in the BL image loading sequence */ |
| 173 | typedef struct bl_load_info { |
| 174 | param_header_t h; |
| 175 | bl_load_info_node_t *head; |
| 176 | } bl_load_info_t; |
| 177 | |
| 178 | /* BL image node in the BL image execution sequence */ |
| 179 | typedef struct bl_params_node { |
| 180 | unsigned int image_id; |
| 181 | image_info_t *image_info; |
| 182 | entry_point_info_t *ep_info; |
| 183 | struct bl_params_node *next_params_info; |
| 184 | } bl_params_node_t; |
| 185 | |
| 186 | /* |
| 187 | * BL image head node in the BL image execution sequence |
| 188 | * It is also used to pass information to next BL image. |
| 189 | */ |
| 190 | typedef struct bl_params { |
| 191 | param_header_t h; |
| 192 | bl_params_node_t *head; |
| 193 | } bl_params_t; |
| 194 | |
| 195 | #else /* LOAD_IMAGE_V2 */ |
| 196 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 197 | /******************************************************************************* |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 198 | * This structure represents the superset of information that can be passed to |
| 199 | * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 200 | * populated only if BL2 detects its presence. A pointer to a structure of this |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 201 | * type should be passed in X0 to BL31's cold boot entrypoint. |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 202 | * |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 203 | * Use of this structure and the X0 parameter is not mandatory: the BL31 |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 204 | * platform code can use other mechanisms to provide the necessary information |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 205 | * about BL32 and BL33 to the common and SPD code. |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 206 | * |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 207 | * BL31 image information is mandatory if this structure is used. If either of |
| 208 | * the optional BL32 and BL33 image information is not provided, this is |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 209 | * indicated by the respective image_info pointers being zero. |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 210 | ******************************************************************************/ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 211 | typedef struct bl31_params { |
| 212 | param_header_t h; |
| 213 | image_info_t *bl31_image_info; |
| 214 | entry_point_info_t *bl32_ep_info; |
| 215 | image_info_t *bl32_image_info; |
| 216 | entry_point_info_t *bl33_ep_info; |
| 217 | image_info_t *bl33_image_info; |
| 218 | } bl31_params_t; |
| 219 | |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 220 | #endif /* LOAD_IMAGE_V2 */ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 221 | |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 222 | /******************************************************************************* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 223 | * Function & variable prototypes |
| 224 | ******************************************************************************/ |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 225 | size_t image_size(unsigned int image_id); |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 226 | |
Sandrine Bailleux | b0e529b | 2016-11-08 14:27:10 +0000 | [diff] [blame] | 227 | int is_mem_free(uintptr_t free_base, size_t free_size, |
| 228 | uintptr_t addr, size_t size); |
| 229 | |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 230 | #if LOAD_IMAGE_V2 |
| 231 | |
| 232 | int load_image(unsigned int image_id, image_info_t *image_data); |
| 233 | int load_auth_image(unsigned int image_id, image_info_t *image_data); |
| 234 | |
| 235 | #else |
| 236 | |
| 237 | uintptr_t page_align(uintptr_t, unsigned); |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 238 | int load_image(meminfo_t *mem_layout, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 239 | unsigned int image_id, |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 240 | uintptr_t image_base, |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 241 | image_info_t *image_data, |
| 242 | entry_point_info_t *entry_point_info); |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 243 | int load_auth_image(meminfo_t *mem_layout, |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 244 | unsigned int image_id, |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 245 | uintptr_t image_base, |
| 246 | image_info_t *image_data, |
| 247 | entry_point_info_t *entry_point_info); |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 248 | void reserve_mem(uintptr_t *free_base, size_t *free_size, |
| 249 | uintptr_t addr, size_t size); |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 250 | |
Yatharth Kochar | 3345a8d | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 251 | #endif /* LOAD_IMAGE_V2 */ |
| 252 | |
| 253 | extern const char build_message[]; |
| 254 | extern const char version_string[]; |
| 255 | |
Sandrine Bailleux | b2e224c | 2015-09-28 17:03:06 +0100 | [diff] [blame] | 256 | void print_entry_point_info(const entry_point_info_t *ep_info); |
| 257 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 258 | #endif /*__ASSEMBLY__*/ |
| 259 | |
| 260 | #endif /* __BL_COMMON_H__ */ |