blob: 38be6283575ee53a970baf316ea3596eb60c2aa5 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Soby Mathewb911cc72017-02-13 12:46:28 +00002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
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 Mathewb911cc72017-02-13 12:46:28 +000034#include <ep_info.h>
35#include <param_header.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010036
37#define UP 1
38#define DOWN 0
39
40/*******************************************************************************
Sandrine Bailleux467d0572014-06-24 14:02:34 +010041 * 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 Gupta4f6ad662013-10-25 09:08:21 +010046
Yatharth Kochara65be2f2015-10-09 18:06:13 +010047/*
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 Kochar3345a8d2016-09-12 16:08:41 +010058#define IMAGE_ATTRIB_SKIP_LOADING 0x02
59#define IMAGE_ATTRIB_PLAT_SETUP 0x04
Dan Handley2bd4ef22014-04-09 13:14:54 +010060
Yatharth Kochara65be2f2015-10-09 18:06:13 +010061#define INVALID_IMAGE_ID (0xFFFFFFFF)
62
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010063/*******************************************************************************
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 Kanigirida567432014-04-15 18:08:08 +010083#ifndef __ASSEMBLY__
Vikram Kanigiria3a5e4a2014-05-15 18:27:15 +010084#include <cassert.h>
Sandrine Bailleux467d0572014-06-24 14:02:34 +010085#include <stddef.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000086#include <stdint.h>
Soby Mathewa0fedc42016-06-16 14:52:04 +010087#include <types.h>
Sandrine Bailleux7659a262016-07-05 09:55:03 +010088#include <utils.h> /* To retain compatibility */
Vikram Kanigiri725b1332015-03-04 10:34:27 +000089
Dan Handleyf05c1b52015-04-27 11:49:22 +010090/*
91 * Declarations of linker defined symbols to help determine memory layout of
92 * BL images
93 */
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010094#if SEPARATE_CODE_AND_RODATA
Soby Mathewa0fedc42016-06-16 14:52:04 +010095extern uintptr_t __TEXT_START__;
96extern uintptr_t __TEXT_END__;
97extern uintptr_t __RODATA_START__;
98extern uintptr_t __RODATA_END__;
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +010099#else
Soby Mathewa0fedc42016-06-16 14:52:04 +0100100extern uintptr_t __RO_START__;
101extern uintptr_t __RO_END__;
Sandrine Bailleuxf91f1442016-07-08 14:37:40 +0100102#endif
103
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900104#if defined(IMAGE_BL2)
Soby Mathewa0fedc42016-06-16 14:52:04 +0100105extern uintptr_t __BL2_END__;
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900106#elif defined(IMAGE_BL2U)
Soby Mathewa0fedc42016-06-16 14:52:04 +0100107extern uintptr_t __BL2U_END__;
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900108#elif defined(IMAGE_BL31)
Soby Mathewa0fedc42016-06-16 14:52:04 +0100109extern uintptr_t __BL31_END__;
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900110#elif defined(IMAGE_BL32)
Soby Mathewa0fedc42016-06-16 14:52:04 +0100111extern uintptr_t __BL32_END__;
Dan Handleyf05c1b52015-04-27 11:49:22 +0100112#endif /* IMAGE_BLX */
113
114#if USE_COHERENT_MEM
Soby Mathewa0fedc42016-06-16 14:52:04 +0100115extern uintptr_t __COHERENT_RAM_START__;
116extern uintptr_t __COHERENT_RAM_END__;
Dan Handleyf05c1b52015-04-27 11:49:22 +0100117#endif
118
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119/*******************************************************************************
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 Handleye2712bc2014-04-10 15:37:22 +0100123typedef struct meminfo {
Soby Mathewa0fedc42016-06-16 14:52:04 +0100124 uintptr_t total_base;
Sandrine Bailleux467d0572014-06-24 14:02:34 +0100125 size_t total_size;
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100126#if !LOAD_IMAGE_V2
Soby Mathewa0fedc42016-06-16 14:52:04 +0100127 uintptr_t free_base;
Sandrine Bailleux467d0572014-06-24 14:02:34 +0100128 size_t free_size;
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100129#endif
Dan Handleye2712bc2014-04-10 15:37:22 +0100130} meminfo_t;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131
Vikram Kanigirida567432014-04-15 18:08:08 +0100132/*****************************************************************************
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 *****************************************************************************/
139typedef 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 Kochar3345a8d2016-09-12 16:08:41 +0100143#if LOAD_IMAGE_V2
144 uint32_t image_max_size;
145#endif
Vikram Kanigirida567432014-04-15 18:08:08 +0100146} image_info_t;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100147
Yatharth Kochara65be2f2015-10-09 18:06:13 +0100148/*****************************************************************************
149 * The image descriptor struct definition.
150 *****************************************************************************/
151typedef struct image_desc {
152 /* Contains unique image id for the image. */
153 unsigned int image_id;
Yatharth Kochara65be2f2015-10-09 18:06:13 +0100154 /*
155 * This member contains Image state information.
156 * Refer IMAGE_STATE_XXX defined above.
157 */
158 unsigned int state;
Yatharth Kocharf11b29a2016-02-01 11:04:46 +0000159 uint32_t copied_size; /* image size copied in blocks */
Soby Mathew6d4f2622016-01-12 10:30:59 +0000160 image_info_t image_info;
161 entry_point_info_t ep_info;
Yatharth Kochara65be2f2015-10-09 18:06:13 +0100162} image_desc_t;
163
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100164#if LOAD_IMAGE_V2
165/* BL image node in the BL image loading sequence */
166typedef 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 */
173typedef 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 */
179typedef 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 */
190typedef 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 Gupta4f6ad662013-10-25 09:08:21 +0100197/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +0000198 * 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 Kanigirida567432014-04-15 18:08:08 +0100200 * populated only if BL2 detects its presence. A pointer to a structure of this
Juan Castillo7d199412015-12-14 09:35:25 +0000201 * type should be passed in X0 to BL31's cold boot entrypoint.
Vikram Kanigirida567432014-04-15 18:08:08 +0100202 *
Juan Castillo7d199412015-12-14 09:35:25 +0000203 * Use of this structure and the X0 parameter is not mandatory: the BL31
Vikram Kanigirida567432014-04-15 18:08:08 +0100204 * platform code can use other mechanisms to provide the necessary information
Juan Castillo7d199412015-12-14 09:35:25 +0000205 * about BL32 and BL33 to the common and SPD code.
Vikram Kanigirida567432014-04-15 18:08:08 +0100206 *
Juan Castillo7d199412015-12-14 09:35:25 +0000207 * 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 Kanigirida567432014-04-15 18:08:08 +0100209 * indicated by the respective image_info pointers being zero.
Achin Guptae4d084e2014-02-19 17:18:23 +0000210 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +0100211typedef 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 Kochar3345a8d2016-09-12 16:08:41 +0100220#endif /* LOAD_IMAGE_V2 */
Vikram Kanigirida567432014-04-15 18:08:08 +0100221
Achin Guptae4d084e2014-02-19 17:18:23 +0000222/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100223 * Function & variable prototypes
224 ******************************************************************************/
Soby Mathewa0fedc42016-06-16 14:52:04 +0100225size_t image_size(unsigned int image_id);
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100226
Sandrine Bailleuxb0e529b2016-11-08 14:27:10 +0000227int is_mem_free(uintptr_t free_base, size_t free_size,
228 uintptr_t addr, size_t size);
229
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100230#if LOAD_IMAGE_V2
231
232int load_image(unsigned int image_id, image_info_t *image_data);
233int load_auth_image(unsigned int image_id, image_info_t *image_data);
234
235#else
236
237uintptr_t page_align(uintptr_t, unsigned);
Sandrine Bailleux467d0572014-06-24 14:02:34 +0100238int load_image(meminfo_t *mem_layout,
Juan Castillo3a66aca2015-04-13 17:36:19 +0100239 unsigned int image_id,
Juan Castilloa08a5e72015-05-19 11:54:12 +0100240 uintptr_t image_base,
Sandrine Bailleux467d0572014-06-24 14:02:34 +0100241 image_info_t *image_data,
242 entry_point_info_t *entry_point_info);
Juan Castilloa08a5e72015-05-19 11:54:12 +0100243int load_auth_image(meminfo_t *mem_layout,
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100244 unsigned int image_id,
Juan Castilloa08a5e72015-05-19 11:54:12 +0100245 uintptr_t image_base,
246 image_info_t *image_data,
247 entry_point_info_t *entry_point_info);
Soby Mathewa0fedc42016-06-16 14:52:04 +0100248void reserve_mem(uintptr_t *free_base, size_t *free_size,
249 uintptr_t addr, size_t size);
Sandrine Bailleux467d0572014-06-24 14:02:34 +0100250
Yatharth Kochar3345a8d2016-09-12 16:08:41 +0100251#endif /* LOAD_IMAGE_V2 */
252
253extern const char build_message[];
254extern const char version_string[];
255
Sandrine Bailleuxb2e224c2015-09-28 17:03:06 +0100256void print_entry_point_info(const entry_point_info_t *ep_info);
257
Achin Gupta4f6ad662013-10-25 09:08:21 +0100258#endif /*__ASSEMBLY__*/
259
260#endif /* __BL_COMMON_H__ */