xref: /rk3399_ARM-atf/include/common/bl_common.h (revision f66053372952f9f30ffc4da28080c36a38e17ce5)
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
72*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_START__,		BL_CODE_BASE);
73*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __TEXT_END__,		BL_CODE_END);
74*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_START__,		BL_RO_DATA_BASE);
75*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RODATA_END__,		BL_RO_DATA_END);
765d1c104fSSandrine Bailleux #else
77*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_START__,		BL_CODE_BASE);
78*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __RO_END__,		BL_CODE_END);
795d1c104fSSandrine Bailleux #endif
805d1c104fSSandrine Bailleux 
81c9f9d9eaSAntonio Nino Diaz #if defined(IMAGE_BL1)
82c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_ROM_END__,		BL1_ROM_END);
83c9f9d9eaSAntonio Nino Diaz 
84c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_START__,	BL1_RAM_BASE);
85c9f9d9eaSAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL1_RAM_END__,		BL1_RAM_LIMIT);
86c9f9d9eaSAntonio Nino Diaz #elif defined(IMAGE_BL2)
87*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_END__,		BL2_END);
883d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U)
89*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2U_END__,		BL2U_END);
903d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31)
91*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_START__,		BL31_START);
92*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL31_END__,		BL31_END);
933d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32)
94*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL32_END__,		BL32_END);
9590b3a6acSDan Handley #endif /* IMAGE_BLX */
9690b3a6acSDan Handley 
97c9f9d9eaSAntonio Nino Diaz /* The following symbols are only exported from the BL2 at EL3 linker script. */
98c9f9d9eaSAntonio Nino Diaz #if BL2_IN_XIP_MEM && defined(IMAGE_BL2)
99*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_ROM_END__,		BL2_ROM_END);
100c9f9d9eaSAntonio Nino Diaz 
101*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_START__,	BL2_RAM_BASE);
102*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __BL2_RAM_END__,		BL2_RAM_END);
103c9f9d9eaSAntonio Nino Diaz #endif /* BL2_IN_XIP_MEM */
104c9f9d9eaSAntonio Nino Diaz 
1059f85f9e3SJoel Hutton /*
1069f85f9e3SJoel Hutton  * The next 2 constants identify the extents of the coherent memory region.
1079f85f9e3SJoel Hutton  * These addresses are used by the MMU setup code and therefore they must be
1089f85f9e3SJoel Hutton  * page-aligned.  It is the responsibility of the linker script to ensure that
1099f85f9e3SJoel Hutton  * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
1109f85f9e3SJoel Hutton  * page-aligned addresses.
1119f85f9e3SJoel Hutton  */
11290b3a6acSDan Handley #if USE_COHERENT_MEM
113*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__,	BL_COHERENT_RAM_BASE);
114*f6605337SAntonio Nino Diaz IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__,	BL_COHERENT_RAM_END);
11590b3a6acSDan Handley #endif
11690b3a6acSDan Handley 
1174ecca339SDan Handley /*******************************************************************************
1184ecca339SDan Handley  * Structure used for telling the next BL how much of a particular type of
1194ecca339SDan Handley  * memory is available for its use and how much is already used.
1204ecca339SDan Handley  ******************************************************************************/
121fb037bfbSDan Handley typedef struct meminfo {
1224c0d0390SSoby Mathew 	uintptr_t total_base;
1238f55dfb4SSandrine Bailleux 	size_t total_size;
124fb037bfbSDan Handley } meminfo_t;
1254ecca339SDan Handley 
1264112bfa0SVikram Kanigiri /*****************************************************************************
1274112bfa0SVikram Kanigiri  * Image info binary provides information from the image loader that
1284112bfa0SVikram Kanigiri  * can be used by the firmware to manage available trusted RAM.
1294112bfa0SVikram Kanigiri  * More advanced firmware image formats can provide additional
1304112bfa0SVikram Kanigiri  * information that enables optimization or greater flexibility in the
1314112bfa0SVikram Kanigiri  * common firmware code
1324112bfa0SVikram Kanigiri  *****************************************************************************/
1334112bfa0SVikram Kanigiri typedef struct image_info {
1344112bfa0SVikram Kanigiri 	param_header_t h;
1354112bfa0SVikram Kanigiri 	uintptr_t image_base;   /* physical address of base of image */
1364112bfa0SVikram Kanigiri 	uint32_t image_size;    /* bytes read from image file */
13772600226SYatharth Kochar 	uint32_t image_max_size;
1384112bfa0SVikram Kanigiri } image_info_t;
1394ecca339SDan Handley 
1407baff11fSYatharth Kochar /*****************************************************************************
1417baff11fSYatharth Kochar  * The image descriptor struct definition.
1427baff11fSYatharth Kochar  *****************************************************************************/
1437baff11fSYatharth Kochar typedef struct image_desc {
1447baff11fSYatharth Kochar 	/* Contains unique image id for the image. */
1457baff11fSYatharth Kochar 	unsigned int image_id;
1467baff11fSYatharth Kochar 	/*
1477baff11fSYatharth Kochar 	 * This member contains Image state information.
1487baff11fSYatharth Kochar 	 * Refer IMAGE_STATE_XXX defined above.
1497baff11fSYatharth Kochar 	 */
1507baff11fSYatharth Kochar 	unsigned int state;
151843ddee4SYatharth Kochar 	uint32_t copied_size;	/* image size copied in blocks */
152b313d755SSoby Mathew 	image_info_t image_info;
153b313d755SSoby Mathew 	entry_point_info_t ep_info;
1547baff11fSYatharth Kochar } image_desc_t;
1557baff11fSYatharth Kochar 
15672600226SYatharth Kochar /* BL image node in the BL image loading sequence */
15772600226SYatharth Kochar typedef struct bl_load_info_node {
15872600226SYatharth Kochar 	unsigned int image_id;
15972600226SYatharth Kochar 	image_info_t *image_info;
16072600226SYatharth Kochar 	struct bl_load_info_node *next_load_info;
16172600226SYatharth Kochar } bl_load_info_node_t;
16272600226SYatharth Kochar 
16372600226SYatharth Kochar /* BL image head node in the BL image loading sequence */
16472600226SYatharth Kochar typedef struct bl_load_info {
16572600226SYatharth Kochar 	param_header_t h;
16672600226SYatharth Kochar 	bl_load_info_node_t *head;
16772600226SYatharth Kochar } bl_load_info_t;
16872600226SYatharth Kochar 
16972600226SYatharth Kochar /* BL image node in the BL image execution sequence */
17072600226SYatharth Kochar typedef struct bl_params_node {
17172600226SYatharth Kochar 	unsigned int image_id;
17272600226SYatharth Kochar 	image_info_t *image_info;
17372600226SYatharth Kochar 	entry_point_info_t *ep_info;
17472600226SYatharth Kochar 	struct bl_params_node *next_params_info;
17572600226SYatharth Kochar } bl_params_node_t;
17672600226SYatharth Kochar 
17772600226SYatharth Kochar /*
17872600226SYatharth Kochar  * BL image head node in the BL image execution sequence
17972600226SYatharth Kochar  * It is also used to pass information to next BL image.
18072600226SYatharth Kochar  */
18172600226SYatharth Kochar typedef struct bl_params {
18272600226SYatharth Kochar 	param_header_t h;
18372600226SYatharth Kochar 	bl_params_node_t *head;
18472600226SYatharth Kochar } bl_params_t;
18572600226SYatharth Kochar 
1864ecca339SDan Handley /*******************************************************************************
1874ecca339SDan Handley  * Function & variable prototypes
1884ecca339SDan Handley  ******************************************************************************/
189d3775d46SDaniel Boulby size_t get_image_size(unsigned int image_id);
19072600226SYatharth Kochar 
19199c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size,
19299c5ebafSSandrine Bailleux 		uintptr_t addr, size_t size);
19399c5ebafSSandrine Bailleux 
19472600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data);
19572600226SYatharth Kochar 
196209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
197209a60ccSSoby Mathew /*
198209a60ccSSoby Mathew  * API to dynamically disable authentication. Only meant for development
199209a60ccSSoby Mathew  * systems.
200209a60ccSSoby Mathew  */
201209a60ccSSoby Mathew void dyn_disable_auth(void);
202209a60ccSSoby Mathew #endif
203209a60ccSSoby Mathew 
20472600226SYatharth Kochar extern const char build_message[];
20572600226SYatharth Kochar extern const char version_string[];
20672600226SYatharth Kochar 
20768a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info);
2081af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir);
20968a68c92SSandrine Bailleux 
2100916c38dSRoberto Vargas struct mmap_region;
2110916c38dSRoberto Vargas 
2120916c38dSRoberto Vargas void setup_page_tables(const struct mmap_region *bl_regions,
2130916c38dSRoberto Vargas 			   const struct mmap_region *plat_regions);
2140916c38dSRoberto Vargas 
2154ecca339SDan Handley #endif /*__ASSEMBLY__*/
2164ecca339SDan Handley 
217c3cf06f1SAntonio Nino Diaz #endif /* BL_COMMON_H */
218