xref: /rk3399_ARM-atf/include/common/bl_common.h (revision 9fb8af33c40f21becde99fc15db73b1f4d82059c)
14ecca339SDan Handley /*
2*9fb8af33SRoberto 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 
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
724c0d0390SSoby Mathew extern uintptr_t __TEXT_START__;
734c0d0390SSoby Mathew extern uintptr_t __TEXT_END__;
744c0d0390SSoby Mathew extern uintptr_t __RODATA_START__;
754c0d0390SSoby Mathew extern uintptr_t __RODATA_END__;
765d1c104fSSandrine Bailleux #else
774c0d0390SSoby Mathew extern uintptr_t __RO_START__;
784c0d0390SSoby Mathew extern uintptr_t __RO_END__;
795d1c104fSSandrine Bailleux #endif
805d1c104fSSandrine Bailleux 
813d8256b2SMasahiro Yamada #if defined(IMAGE_BL2)
824c0d0390SSoby Mathew extern uintptr_t __BL2_END__;
833d8256b2SMasahiro Yamada #elif defined(IMAGE_BL2U)
844c0d0390SSoby Mathew extern uintptr_t __BL2U_END__;
853d8256b2SMasahiro Yamada #elif defined(IMAGE_BL31)
864c0d0390SSoby Mathew extern uintptr_t __BL31_END__;
873d8256b2SMasahiro Yamada #elif defined(IMAGE_BL32)
884c0d0390SSoby Mathew extern uintptr_t __BL32_END__;
8990b3a6acSDan Handley #endif /* IMAGE_BLX */
9090b3a6acSDan Handley 
9190b3a6acSDan Handley #if USE_COHERENT_MEM
924c0d0390SSoby Mathew extern uintptr_t __COHERENT_RAM_START__;
934c0d0390SSoby Mathew extern uintptr_t __COHERENT_RAM_END__;
9490b3a6acSDan Handley #endif
9590b3a6acSDan Handley 
964ecca339SDan Handley /*******************************************************************************
974ecca339SDan Handley  * Structure used for telling the next BL how much of a particular type of
984ecca339SDan Handley  * memory is available for its use and how much is already used.
994ecca339SDan Handley  ******************************************************************************/
100fb037bfbSDan Handley typedef struct meminfo {
1014c0d0390SSoby Mathew 	uintptr_t total_base;
1028f55dfb4SSandrine Bailleux 	size_t total_size;
10372600226SYatharth Kochar #if !LOAD_IMAGE_V2
1044c0d0390SSoby Mathew 	uintptr_t free_base;
1058f55dfb4SSandrine Bailleux 	size_t free_size;
10672600226SYatharth Kochar #endif
107fb037bfbSDan Handley } meminfo_t;
1084ecca339SDan Handley 
1094112bfa0SVikram Kanigiri /*****************************************************************************
1104112bfa0SVikram Kanigiri  * Image info binary provides information from the image loader that
1114112bfa0SVikram Kanigiri  * can be used by the firmware to manage available trusted RAM.
1124112bfa0SVikram Kanigiri  * More advanced firmware image formats can provide additional
1134112bfa0SVikram Kanigiri  * information that enables optimization or greater flexibility in the
1144112bfa0SVikram Kanigiri  * common firmware code
1154112bfa0SVikram Kanigiri  *****************************************************************************/
1164112bfa0SVikram Kanigiri typedef struct image_info {
1174112bfa0SVikram Kanigiri 	param_header_t h;
1184112bfa0SVikram Kanigiri 	uintptr_t image_base;   /* physical address of base of image */
1194112bfa0SVikram Kanigiri 	uint32_t image_size;    /* bytes read from image file */
12072600226SYatharth Kochar #if LOAD_IMAGE_V2
12172600226SYatharth Kochar 	uint32_t image_max_size;
12272600226SYatharth Kochar #endif
1234112bfa0SVikram Kanigiri } image_info_t;
1244ecca339SDan Handley 
1257baff11fSYatharth Kochar /*****************************************************************************
1267baff11fSYatharth Kochar  * The image descriptor struct definition.
1277baff11fSYatharth Kochar  *****************************************************************************/
1287baff11fSYatharth Kochar typedef struct image_desc {
1297baff11fSYatharth Kochar 	/* Contains unique image id for the image. */
1307baff11fSYatharth Kochar 	unsigned int image_id;
1317baff11fSYatharth Kochar 	/*
1327baff11fSYatharth Kochar 	 * This member contains Image state information.
1337baff11fSYatharth Kochar 	 * Refer IMAGE_STATE_XXX defined above.
1347baff11fSYatharth Kochar 	 */
1357baff11fSYatharth Kochar 	unsigned int state;
136843ddee4SYatharth Kochar 	uint32_t copied_size;	/* image size copied in blocks */
137b313d755SSoby Mathew 	image_info_t image_info;
138b313d755SSoby Mathew 	entry_point_info_t ep_info;
1397baff11fSYatharth Kochar } image_desc_t;
1407baff11fSYatharth Kochar 
14172600226SYatharth Kochar #if LOAD_IMAGE_V2
14272600226SYatharth Kochar /* BL image node in the BL image loading sequence */
14372600226SYatharth Kochar typedef struct bl_load_info_node {
14472600226SYatharth Kochar 	unsigned int image_id;
14572600226SYatharth Kochar 	image_info_t *image_info;
14672600226SYatharth Kochar 	struct bl_load_info_node *next_load_info;
14772600226SYatharth Kochar } bl_load_info_node_t;
14872600226SYatharth Kochar 
14972600226SYatharth Kochar /* BL image head node in the BL image loading sequence */
15072600226SYatharth Kochar typedef struct bl_load_info {
15172600226SYatharth Kochar 	param_header_t h;
15272600226SYatharth Kochar 	bl_load_info_node_t *head;
15372600226SYatharth Kochar } bl_load_info_t;
15472600226SYatharth Kochar 
15572600226SYatharth Kochar /* BL image node in the BL image execution sequence */
15672600226SYatharth Kochar typedef struct bl_params_node {
15772600226SYatharth Kochar 	unsigned int image_id;
15872600226SYatharth Kochar 	image_info_t *image_info;
15972600226SYatharth Kochar 	entry_point_info_t *ep_info;
16072600226SYatharth Kochar 	struct bl_params_node *next_params_info;
16172600226SYatharth Kochar } bl_params_node_t;
16272600226SYatharth Kochar 
16372600226SYatharth Kochar /*
16472600226SYatharth Kochar  * BL image head node in the BL image execution sequence
16572600226SYatharth Kochar  * It is also used to pass information to next BL image.
16672600226SYatharth Kochar  */
16772600226SYatharth Kochar typedef struct bl_params {
16872600226SYatharth Kochar 	param_header_t h;
16972600226SYatharth Kochar 	bl_params_node_t *head;
17072600226SYatharth Kochar } bl_params_t;
17172600226SYatharth Kochar 
17272600226SYatharth Kochar #else /* LOAD_IMAGE_V2 */
17372600226SYatharth Kochar 
1744ecca339SDan Handley /*******************************************************************************
1754ecca339SDan Handley  * This structure represents the superset of information that can be passed to
1764ecca339SDan Handley  * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be
1774112bfa0SVikram Kanigiri  * populated only if BL2 detects its presence. A pointer to a structure of this
178d178637dSJuan Castillo  * type should be passed in X0 to BL31's cold boot entrypoint.
1794112bfa0SVikram Kanigiri  *
180d178637dSJuan Castillo  * Use of this structure and the X0 parameter is not mandatory: the BL31
1814112bfa0SVikram Kanigiri  * platform code can use other mechanisms to provide the necessary information
182d178637dSJuan Castillo  * about BL32 and BL33 to the common and SPD code.
1834112bfa0SVikram Kanigiri  *
184d178637dSJuan Castillo  * BL31 image information is mandatory if this structure is used. If either of
185d178637dSJuan Castillo  * the optional BL32 and BL33 image information is not provided, this is
1864112bfa0SVikram Kanigiri  * indicated by the respective image_info pointers being zero.
1874ecca339SDan Handley  ******************************************************************************/
1884112bfa0SVikram Kanigiri typedef struct bl31_params {
1894112bfa0SVikram Kanigiri 	param_header_t h;
1904112bfa0SVikram Kanigiri 	image_info_t *bl31_image_info;
1914112bfa0SVikram Kanigiri 	entry_point_info_t *bl32_ep_info;
1924112bfa0SVikram Kanigiri 	image_info_t *bl32_image_info;
1934112bfa0SVikram Kanigiri 	entry_point_info_t *bl33_ep_info;
1944112bfa0SVikram Kanigiri 	image_info_t *bl33_image_info;
1954112bfa0SVikram Kanigiri } bl31_params_t;
1964112bfa0SVikram Kanigiri 
19772600226SYatharth Kochar #endif /* LOAD_IMAGE_V2 */
1984112bfa0SVikram Kanigiri 
1994ecca339SDan Handley /*******************************************************************************
2004ecca339SDan Handley  * Function & variable prototypes
2014ecca339SDan Handley  ******************************************************************************/
2024c0d0390SSoby Mathew size_t image_size(unsigned int image_id);
20372600226SYatharth Kochar 
20499c5ebafSSandrine Bailleux int is_mem_free(uintptr_t free_base, size_t free_size,
20599c5ebafSSandrine Bailleux 		uintptr_t addr, size_t size);
20699c5ebafSSandrine Bailleux 
20772600226SYatharth Kochar #if LOAD_IMAGE_V2
20872600226SYatharth Kochar 
20972600226SYatharth Kochar int load_auth_image(unsigned int image_id, image_info_t *image_data);
21072600226SYatharth Kochar 
21172600226SYatharth Kochar #else
21272600226SYatharth Kochar 
213*9fb8af33SRoberto Vargas uintptr_t page_align(uintptr_t value, unsigned dir);
2148f55dfb4SSandrine Bailleux int load_image(meminfo_t *mem_layout,
21516948ae1SJuan Castillo 	       unsigned int image_id,
2161779ba6bSJuan Castillo 	       uintptr_t image_base,
2171779ba6bSJuan Castillo 	       image_info_t *image_data,
2181779ba6bSJuan Castillo 	       entry_point_info_t *entry_point_info);
2191779ba6bSJuan Castillo int load_auth_image(meminfo_t *mem_layout,
22072600226SYatharth Kochar 		    unsigned int image_id,
2211779ba6bSJuan Castillo 		    uintptr_t image_base,
2228f55dfb4SSandrine Bailleux 		    image_info_t *image_data,
2238f55dfb4SSandrine Bailleux 		    entry_point_info_t *entry_point_info);
2244c0d0390SSoby Mathew void reserve_mem(uintptr_t *free_base, size_t *free_size,
2254c0d0390SSoby Mathew 		uintptr_t addr, size_t size);
2268f55dfb4SSandrine Bailleux 
22772600226SYatharth Kochar #endif /* LOAD_IMAGE_V2 */
22872600226SYatharth Kochar 
22972600226SYatharth Kochar extern const char build_message[];
23072600226SYatharth Kochar extern const char version_string[];
23172600226SYatharth Kochar 
23268a68c92SSandrine Bailleux void print_entry_point_info(const entry_point_info_t *ep_info);
23368a68c92SSandrine Bailleux 
2344ecca339SDan Handley #endif /*__ASSEMBLY__*/
2354ecca339SDan Handley 
2364ecca339SDan Handley #endif /* __BL_COMMON_H__ */
237