xref: /rk3399_ARM-atf/include/common/bl_common.h (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
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 
10*09d40e0eSAntonio Nino Diaz #include <common/ep_info.h>
11*09d40e0eSAntonio Nino Diaz #include <common/param_header.h>
12*09d40e0eSAntonio 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__
61*09d40e0eSAntonio Nino Diaz 
628f55dfb4SSandrine Bailleux #include <stddef.h>
635dffb46cSSoby Mathew #include <stdint.h>
64a7e98ad5SVikram Kanigiri 
65*09d40e0eSAntonio 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 
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)
86931f7c61SSoby Mathew IMPORT_SYM(unsigned long, __BL31_START__,	BL31_START);
879f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL31_END__,		BL31_END);
883d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32)
899f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL32_END__,		BL32_END);
9090b3a6acSDan Handley #endif /* IMAGE_BLX */
9190b3a6acSDan Handley 
929f85f9e3SJoel Hutton /*
939f85f9e3SJoel Hutton  * The next 2 constants identify the extents of the coherent memory region.
949f85f9e3SJoel Hutton  * These addresses are used by the MMU setup code and therefore they must be
959f85f9e3SJoel Hutton  * page-aligned.  It is the responsibility of the linker script to ensure that
969f85f9e3SJoel Hutton  * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
979f85f9e3SJoel Hutton  * page-aligned addresses.
989f85f9e3SJoel Hutton  */
9990b3a6acSDan Handley #if USE_COHERENT_MEM
1009f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_START__,	BL_COHERENT_RAM_BASE);
1019f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __COHERENT_RAM_END__,		BL_COHERENT_RAM_END);
10290b3a6acSDan Handley #endif
10390b3a6acSDan Handley 
1044ecca339SDan Handley /*******************************************************************************
1054ecca339SDan Handley  * Structure used for telling the next BL how much of a particular type of
1064ecca339SDan Handley  * memory is available for its use and how much is already used.
1074ecca339SDan Handley  ******************************************************************************/
108fb037bfbSDan Handley typedef struct meminfo {
1094c0d0390SSoby Mathew 	uintptr_t total_base;
1108f55dfb4SSandrine Bailleux 	size_t total_size;
111fb037bfbSDan Handley } meminfo_t;
1124ecca339SDan Handley 
1134112bfa0SVikram Kanigiri /*****************************************************************************
1144112bfa0SVikram Kanigiri  * Image info binary provides information from the image loader that
1154112bfa0SVikram Kanigiri  * can be used by the firmware to manage available trusted RAM.
1164112bfa0SVikram Kanigiri  * More advanced firmware image formats can provide additional
1174112bfa0SVikram Kanigiri  * information that enables optimization or greater flexibility in the
1184112bfa0SVikram Kanigiri  * common firmware code
1194112bfa0SVikram Kanigiri  *****************************************************************************/
1204112bfa0SVikram Kanigiri typedef struct image_info {
1214112bfa0SVikram Kanigiri 	param_header_t h;
1224112bfa0SVikram Kanigiri 	uintptr_t image_base;   /* physical address of base of image */
1234112bfa0SVikram Kanigiri 	uint32_t image_size;    /* bytes read from image file */
12472600226SYatharth Kochar 	uint32_t image_max_size;
1254112bfa0SVikram Kanigiri } image_info_t;
1264ecca339SDan Handley 
1277baff11fSYatharth Kochar /*****************************************************************************
1287baff11fSYatharth Kochar  * The image descriptor struct definition.
1297baff11fSYatharth Kochar  *****************************************************************************/
1307baff11fSYatharth Kochar typedef struct image_desc {
1317baff11fSYatharth Kochar 	/* Contains unique image id for the image. */
1327baff11fSYatharth Kochar 	unsigned int image_id;
1337baff11fSYatharth Kochar 	/*
1347baff11fSYatharth Kochar 	 * This member contains Image state information.
1357baff11fSYatharth Kochar 	 * Refer IMAGE_STATE_XXX defined above.
1367baff11fSYatharth Kochar 	 */
1377baff11fSYatharth Kochar 	unsigned int state;
138843ddee4SYatharth Kochar 	uint32_t copied_size;	/* image size copied in blocks */
139b313d755SSoby Mathew 	image_info_t image_info;
140b313d755SSoby Mathew 	entry_point_info_t ep_info;
1417baff11fSYatharth Kochar } image_desc_t;
1427baff11fSYatharth Kochar 
14372600226SYatharth Kochar /* BL image node in the BL image loading sequence */
14472600226SYatharth Kochar typedef struct bl_load_info_node {
14572600226SYatharth Kochar 	unsigned int image_id;
14672600226SYatharth Kochar 	image_info_t *image_info;
14772600226SYatharth Kochar 	struct bl_load_info_node *next_load_info;
14872600226SYatharth Kochar } bl_load_info_node_t;
14972600226SYatharth Kochar 
15072600226SYatharth Kochar /* BL image head node in the BL image loading sequence */
15172600226SYatharth Kochar typedef struct bl_load_info {
15272600226SYatharth Kochar 	param_header_t h;
15372600226SYatharth Kochar 	bl_load_info_node_t *head;
15472600226SYatharth Kochar } bl_load_info_t;
15572600226SYatharth Kochar 
15672600226SYatharth Kochar /* BL image node in the BL image execution sequence */
15772600226SYatharth Kochar typedef struct bl_params_node {
15872600226SYatharth Kochar 	unsigned int image_id;
15972600226SYatharth Kochar 	image_info_t *image_info;
16072600226SYatharth Kochar 	entry_point_info_t *ep_info;
16172600226SYatharth Kochar 	struct bl_params_node *next_params_info;
16272600226SYatharth Kochar } bl_params_node_t;
16372600226SYatharth Kochar 
16472600226SYatharth Kochar /*
16572600226SYatharth Kochar  * BL image head node in the BL image execution sequence
16672600226SYatharth Kochar  * It is also used to pass information to next BL image.
16772600226SYatharth Kochar  */
16872600226SYatharth Kochar typedef struct bl_params {
16972600226SYatharth Kochar 	param_header_t h;
17072600226SYatharth Kochar 	bl_params_node_t *head;
17172600226SYatharth Kochar } bl_params_t;
17272600226SYatharth Kochar 
1734ecca339SDan Handley /*******************************************************************************
1744ecca339SDan Handley  * Function & variable prototypes
1754ecca339SDan Handley  ******************************************************************************/
176d3775d46SDaniel Boulby size_t get_image_size(unsigned int image_id);
17772600226SYatharth Kochar 
17899c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size,
17999c5ebafSSandrine Bailleux 		uintptr_t addr, size_t size);
18099c5ebafSSandrine Bailleux 
18172600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data);
18272600226SYatharth Kochar 
183209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
184209a60ccSSoby Mathew /*
185209a60ccSSoby Mathew  * API to dynamically disable authentication. Only meant for development
186209a60ccSSoby Mathew  * systems.
187209a60ccSSoby Mathew  */
188209a60ccSSoby Mathew void dyn_disable_auth(void);
189209a60ccSSoby Mathew #endif
190209a60ccSSoby Mathew 
19172600226SYatharth Kochar extern const char build_message[];
19272600226SYatharth Kochar extern const char version_string[];
19372600226SYatharth Kochar 
19468a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info);
1951af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir);
19668a68c92SSandrine Bailleux 
1970916c38dSRoberto Vargas struct mmap_region;
1980916c38dSRoberto Vargas 
1990916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions,
2000916c38dSRoberto Vargas 			   const struct mmap_region *plat_regions);
2010916c38dSRoberto Vargas 
2024ecca339SDan Handley #endif /*__ASSEMBLY__*/
2034ecca339SDan Handley 
204c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */
205