xref: /rk3399_ARM-atf/include/common/bl_common.h (revision d3775d46a43a47c521193229cfcb1c0d6cb4878b)
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 
74ecca339SDan Handley #ifndef __BL_COMMON_H__
84ecca339SDan Handley #define __BL_COMMON_H__
94ecca339SDan Handley 
105dffb46cSSoby Mathew #include <ep_info.h>
115dffb46cSSoby Mathew #include <param_header.h>
12da5f2745SSoby Mathew #include <utils_def.h>
134ecca339SDan Handley 
144ecca339SDan Handley #define UP	1
154ecca339SDan Handley #define DOWN	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 ******************************************************************************/
218f55dfb4SSandrine Bailleux #define TOP	0x1
228f55dfb4SSandrine Bailleux #define BOTTOM	!TOP
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  */
287baff11fSYatharth Kochar #define IMAGE_STATE_RESET			0
297baff11fSYatharth Kochar #define IMAGE_STATE_COPIED			1
307baff11fSYatharth Kochar #define IMAGE_STATE_COPYING			2
317baff11fSYatharth Kochar #define IMAGE_STATE_AUTHENTICATED		3
327baff11fSYatharth Kochar #define IMAGE_STATE_EXECUTED			4
337baff11fSYatharth Kochar #define IMAGE_STATE_INTERRUPTED			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  ******************************************************************************/
43bbf8f6f9SYatharth Kochar #define SYNC_EXCEPTION_SP_EL0		0x0
44bbf8f6f9SYatharth Kochar #define IRQ_SP_EL0			0x1
45bbf8f6f9SYatharth Kochar #define FIQ_SP_EL0			0x2
46bbf8f6f9SYatharth Kochar #define SERROR_SP_EL0			0x3
47bbf8f6f9SYatharth Kochar #define SYNC_EXCEPTION_SP_ELX		0x4
48bbf8f6f9SYatharth Kochar #define IRQ_SP_ELX			0x5
49bbf8f6f9SYatharth Kochar #define FIQ_SP_ELX			0x6
50bbf8f6f9SYatharth Kochar #define SERROR_SP_ELX			0x7
51bbf8f6f9SYatharth Kochar #define SYNC_EXCEPTION_AARCH64		0x8
52bbf8f6f9SYatharth Kochar #define IRQ_AARCH64			0x9
53bbf8f6f9SYatharth Kochar #define FIQ_AARCH64			0xa
54bbf8f6f9SYatharth Kochar #define SERROR_AARCH64			0xb
55bbf8f6f9SYatharth Kochar #define SYNC_EXCEPTION_AARCH32		0xc
56bbf8f6f9SYatharth Kochar #define IRQ_AARCH32			0xd
57bbf8f6f9SYatharth Kochar #define FIQ_AARCH32			0xe
58bbf8f6f9SYatharth Kochar #define SERROR_AARCH32			0xf
59bbf8f6f9SYatharth Kochar 
604ecca339SDan Handley #ifndef __ASSEMBLY__
6129fb905dSVikram Kanigiri #include <cassert.h>
628f55dfb4SSandrine Bailleux #include <stddef.h>
635dffb46cSSoby Mathew #include <stdint.h>
644c0d0390SSoby Mathew #include <types.h>
6553d9c9c8SScott Branden #include <utils_def.h> /* To retain compatibility */
66a7e98ad5SVikram Kanigiri 
679f85f9e3SJoel Hutton 
6890b3a6acSDan Handley /*
6990b3a6acSDan Handley  * Declarations of linker defined symbols to help determine memory layout of
7090b3a6acSDan Handley  * BL images
7190b3a6acSDan Handley  */
725d1c104fSSandrine Bailleux #if SEPARATE_CODE_AND_RODATA
739f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __TEXT_START__,	BL_CODE_BASE);
749f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __TEXT_END__,		BL_CODE_END);
759f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RODATA_START__,	BL_RO_DATA_BASE);
769f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RODATA_END__,	BL_RO_DATA_END);
775d1c104fSSandrine Bailleux #else
789f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RO_START__,		BL_CODE_BASE);
799f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __RO_END__,		BL_CODE_END);
805d1c104fSSandrine Bailleux #endif
815d1c104fSSandrine Bailleux 
823d8256b2SMasahiro Yamada #if defined(IMAGE_BL2)
839f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2_END__,		BL2_END);
843d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U)
859f85f9e3SJoel Hutton IMPORT_SYM(unsigned long, __BL2U_END__,		BL2U_END);
863d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31)
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;
11172600226SYatharth Kochar #if !LOAD_IMAGE_V2
1124c0d0390SSoby Mathew 	uintptr_t free_base;
1138f55dfb4SSandrine Bailleux 	size_t free_size;
11472600226SYatharth Kochar #endif
115fb037bfbSDan Handley } meminfo_t;
1164ecca339SDan Handley 
1174112bfa0SVikram Kanigiri /*****************************************************************************
1184112bfa0SVikram Kanigiri  * Image info binary provides information from the image loader that
1194112bfa0SVikram Kanigiri  * can be used by the firmware to manage available trusted RAM.
1204112bfa0SVikram Kanigiri  * More advanced firmware image formats can provide additional
1214112bfa0SVikram Kanigiri  * information that enables optimization or greater flexibility in the
1224112bfa0SVikram Kanigiri  * common firmware code
1234112bfa0SVikram Kanigiri  *****************************************************************************/
1244112bfa0SVikram Kanigiri typedef struct image_info {
1254112bfa0SVikram Kanigiri 	param_header_t h;
1264112bfa0SVikram Kanigiri 	uintptr_t image_base;   /* physical address of base of image */
1274112bfa0SVikram Kanigiri 	uint32_t image_size;    /* bytes read from image file */
12872600226SYatharth Kochar #if LOAD_IMAGE_V2
12972600226SYatharth Kochar 	uint32_t image_max_size;
13072600226SYatharth Kochar #endif
1314112bfa0SVikram Kanigiri } image_info_t;
1324ecca339SDan Handley 
1337baff11fSYatharth Kochar /*****************************************************************************
1347baff11fSYatharth Kochar  * The image descriptor struct definition.
1357baff11fSYatharth Kochar  *****************************************************************************/
1367baff11fSYatharth Kochar typedef struct image_desc {
1377baff11fSYatharth Kochar 	/* Contains unique image id for the image. */
1387baff11fSYatharth Kochar 	unsigned int image_id;
1397baff11fSYatharth Kochar 	/*
1407baff11fSYatharth Kochar 	 * This member contains Image state information.
1417baff11fSYatharth Kochar 	 * Refer IMAGE_STATE_XXX defined above.
1427baff11fSYatharth Kochar 	 */
1437baff11fSYatharth Kochar 	unsigned int state;
144843ddee4SYatharth Kochar 	uint32_t copied_size;	/* image size copied in blocks */
145b313d755SSoby Mathew 	image_info_t image_info;
146b313d755SSoby Mathew 	entry_point_info_t ep_info;
1477baff11fSYatharth Kochar } image_desc_t;
1487baff11fSYatharth Kochar 
14972600226SYatharth Kochar #if LOAD_IMAGE_V2
15072600226SYatharth Kochar /* BL image node in the BL image loading sequence */
15172600226SYatharth Kochar typedef struct bl_load_info_node {
15272600226SYatharth Kochar 	unsigned int image_id;
15372600226SYatharth Kochar 	image_info_t *image_info;
15472600226SYatharth Kochar 	struct bl_load_info_node *next_load_info;
15572600226SYatharth Kochar } bl_load_info_node_t;
15672600226SYatharth Kochar 
15772600226SYatharth Kochar /* BL image head node in the BL image loading sequence */
15872600226SYatharth Kochar typedef struct bl_load_info {
15972600226SYatharth Kochar 	param_header_t h;
16072600226SYatharth Kochar 	bl_load_info_node_t *head;
16172600226SYatharth Kochar } bl_load_info_t;
16272600226SYatharth Kochar 
16372600226SYatharth Kochar /* BL image node in the BL image execution sequence */
16472600226SYatharth Kochar typedef struct bl_params_node {
16572600226SYatharth Kochar 	unsigned int image_id;
16672600226SYatharth Kochar 	image_info_t *image_info;
16772600226SYatharth Kochar 	entry_point_info_t *ep_info;
16872600226SYatharth Kochar 	struct bl_params_node *next_params_info;
16972600226SYatharth Kochar } bl_params_node_t;
17072600226SYatharth Kochar 
17172600226SYatharth Kochar /*
17272600226SYatharth Kochar  * BL image head node in the BL image execution sequence
17372600226SYatharth Kochar  * It is also used to pass information to next BL image.
17472600226SYatharth Kochar  */
17572600226SYatharth Kochar typedef struct bl_params {
17672600226SYatharth Kochar 	param_header_t h;
17772600226SYatharth Kochar 	bl_params_node_t *head;
17872600226SYatharth Kochar } bl_params_t;
17972600226SYatharth Kochar 
18072600226SYatharth Kochar #else /* LOAD_IMAGE_V2 */
18172600226SYatharth Kochar 
1824ecca339SDan Handley /*******************************************************************************
1834ecca339SDan Handley  * This structure represents the superset of information that can be passed to
1844ecca339SDan Handley  * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be
1854112bfa0SVikram Kanigiri  * populated only if BL2 detects its presence. A pointer to a structure of this
186d178637dSJuan Castillo  * type should be passed in X0 to BL31's cold boot entrypoint.
1874112bfa0SVikram Kanigiri  *
188d178637dSJuan Castillo  * Use of this structure and the X0 parameter is not mandatory: the BL31
1894112bfa0SVikram Kanigiri  * platform code can use other mechanisms to provide the necessary information
190d178637dSJuan Castillo  * about BL32 and BL33 to the common and SPD code.
1914112bfa0SVikram Kanigiri  *
192d178637dSJuan Castillo  * BL31 image information is mandatory if this structure is used. If either of
193d178637dSJuan Castillo  * the optional BL32 and BL33 image information is not provided, this is
1944112bfa0SVikram Kanigiri  * indicated by the respective image_info pointers being zero.
1954ecca339SDan Handley  ******************************************************************************/
1964112bfa0SVikram Kanigiri typedef struct bl31_params {
1974112bfa0SVikram Kanigiri 	param_header_t h;
1984112bfa0SVikram Kanigiri 	image_info_t *bl31_image_info;
1994112bfa0SVikram Kanigiri 	entry_point_info_t *bl32_ep_info;
2004112bfa0SVikram Kanigiri 	image_info_t *bl32_image_info;
2014112bfa0SVikram Kanigiri 	entry_point_info_t *bl33_ep_info;
2024112bfa0SVikram Kanigiri 	image_info_t *bl33_image_info;
2034112bfa0SVikram Kanigiri } bl31_params_t;
2044112bfa0SVikram Kanigiri 
20572600226SYatharth Kochar #endif /* LOAD_IMAGE_V2 */
2064112bfa0SVikram Kanigiri 
2074ecca339SDan Handley /*******************************************************************************
2084ecca339SDan Handley  * Function & variable prototypes
2094ecca339SDan Handley  ******************************************************************************/
210*d3775d46SDaniel Boulby size_t get_image_size(unsigned int image_id);
21172600226SYatharth Kochar 
21299c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size,
21399c5ebafSSandrine Bailleux 		uintptr_t addr, size_t size);
21499c5ebafSSandrine Bailleux 
21572600226SYatharth Kochar #if LOAD_IMAGE_V2
21672600226SYatharth Kochar 
21772600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data);
21872600226SYatharth Kochar 
21972600226SYatharth Kochar #else
22072600226SYatharth Kochar 
2218f55dfb4SSandrine Bailleux int load_image(meminfo_t *mem_layout,
22216948ae1SJuan Castillo 	       unsigned int image_id,
2231779ba6bSJuan Castillo 	       uintptr_t image_base,
2241779ba6bSJuan Castillo 	       image_info_t *image_data,
2251779ba6bSJuan Castillo 	       entry_point_info_t *entry_point_info);
2261779ba6bSJuan Castillo int load_auth_image(meminfo_t *mem_layout,
22772600226SYatharth Kochar 		    unsigned int image_id,
2281779ba6bSJuan Castillo 		    uintptr_t image_base,
2298f55dfb4SSandrine Bailleux 		    image_info_t *image_data,
2308f55dfb4SSandrine Bailleux 		    entry_point_info_t *entry_point_info);
2314c0d0390SSoby Mathew void reserve_mem(uintptr_t *free_base, size_t *free_size,
2324c0d0390SSoby Mathew 		uintptr_t addr, size_t size);
2338f55dfb4SSandrine Bailleux 
23472600226SYatharth Kochar #endif /* LOAD_IMAGE_V2 */
23572600226SYatharth Kochar 
236209a60ccSSoby Mathew #if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
237209a60ccSSoby Mathew /*
238209a60ccSSoby Mathew  * API to dynamically disable authentication. Only meant for development
239209a60ccSSoby Mathew  * systems.
240209a60ccSSoby Mathew  */
241209a60ccSSoby Mathew void dyn_disable_auth(void);
242209a60ccSSoby Mathew #endif
243209a60ccSSoby Mathew 
24472600226SYatharth Kochar extern const char build_message[];
24572600226SYatharth Kochar extern const char version_string[];
24672600226SYatharth Kochar 
24768a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info);
2481af540efSRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir);
24968a68c92SSandrine Bailleux 
2504ecca339SDan Handley #endif /*__ASSEMBLY__*/
2514ecca339SDan Handley 
2524ecca339SDan Handley #endif /* __BL_COMMON_H__ */
253