xref: /rk3399_ARM-atf/include/common/bl_common.h (revision 97043ac98e13a726dbf8b3b41654dca759e3da2c)
14ecca339SDan Handley /*
24ecca339SDan Handley  * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
34ecca339SDan Handley  *
44ecca339SDan Handley  * Redistribution and use in source and binary forms, with or without
54ecca339SDan Handley  * modification, are permitted provided that the following conditions are met:
64ecca339SDan Handley  *
74ecca339SDan Handley  * Redistributions of source code must retain the above copyright notice, this
84ecca339SDan Handley  * list of conditions and the following disclaimer.
94ecca339SDan Handley  *
104ecca339SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
114ecca339SDan Handley  * this list of conditions and the following disclaimer in the documentation
124ecca339SDan Handley  * and/or other materials provided with the distribution.
134ecca339SDan Handley  *
144ecca339SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
154ecca339SDan Handley  * to endorse or promote products derived from this software without specific
164ecca339SDan Handley  * prior written permission.
174ecca339SDan Handley  *
184ecca339SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
194ecca339SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204ecca339SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214ecca339SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
224ecca339SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
234ecca339SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
244ecca339SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
254ecca339SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
264ecca339SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
274ecca339SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284ecca339SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
294ecca339SDan Handley  */
304ecca339SDan Handley 
314ecca339SDan Handley #ifndef __BL_COMMON_H__
324ecca339SDan Handley #define __BL_COMMON_H__
334ecca339SDan Handley 
344ecca339SDan Handley #define SECURE		0
354ecca339SDan Handley #define NON_SECURE	1
364ecca339SDan Handley 
374ecca339SDan Handley #define UP	1
384ecca339SDan Handley #define DOWN	0
394ecca339SDan Handley 
404ecca339SDan Handley /*******************************************************************************
414ecca339SDan Handley  * Constants for loading images. When BLx wants to load BLy, it looks at a
424ecca339SDan Handley  * meminfo structure to find the extents of free memory. Then depending upon
434ecca339SDan Handley  * how it has been configured, it can either load BLy at the top or bottom of
444ecca339SDan Handley  * the free memory. These constants indicate the choice.
454ecca339SDan Handley  * TODO: Make this configurable while building the trusted firmware.
464ecca339SDan Handley  ******************************************************************************/
474ecca339SDan Handley #define TOP_LOAD	0x1
484ecca339SDan Handley #define BOT_LOAD	!TOP_LOAD
494ecca339SDan Handley #define LOAD_MASK	(1 << 0)
504ecca339SDan Handley 
514ecca339SDan Handley /******************************************************************************
524ecca339SDan Handley  * Opcode passed in x0 to tell next EL that we want to run an image.
534ecca339SDan Handley  * Corresponds to the function ID of the only SMC that the BL1 exception
544ecca339SDan Handley  * handlers service. That's why the chosen value is the first function ID of
554ecca339SDan Handley  * the ARM SMC64 range.
564ecca339SDan Handley  *****************************************************************************/
574ecca339SDan Handley #define RUN_IMAGE	0xC0000000
584ecca339SDan Handley 
594ecca339SDan Handley 
604ecca339SDan Handley #ifndef __ASSEMBLY__
61*97043ac9SDan Handley 
62*97043ac9SDan Handley #include <cdefs.h> /* For __dead2 */
634ecca339SDan Handley 
644ecca339SDan Handley /*******************************************************************************
654ecca339SDan Handley  * Structure used for telling the next BL how much of a particular type of
664ecca339SDan Handley  * memory is available for its use and how much is already used.
674ecca339SDan Handley  ******************************************************************************/
68fb037bfbSDan Handley typedef struct meminfo {
694ecca339SDan Handley 	unsigned long total_base;
704ecca339SDan Handley 	long total_size;
714ecca339SDan Handley 	unsigned long free_base;
724ecca339SDan Handley 	long free_size;
734ecca339SDan Handley 	unsigned long attr;
744ecca339SDan Handley 	unsigned long next;
75fb037bfbSDan Handley } meminfo_t;
764ecca339SDan Handley 
77fb037bfbSDan Handley typedef struct aapcs64_params {
784ecca339SDan Handley 	unsigned long arg0;
794ecca339SDan Handley 	unsigned long arg1;
804ecca339SDan Handley 	unsigned long arg2;
814ecca339SDan Handley 	unsigned long arg3;
824ecca339SDan Handley 	unsigned long arg4;
834ecca339SDan Handley 	unsigned long arg5;
844ecca339SDan Handley 	unsigned long arg6;
854ecca339SDan Handley 	unsigned long arg7;
86fb037bfbSDan Handley } aapcs64_params_t;
874ecca339SDan Handley 
884ecca339SDan Handley /*******************************************************************************
894ecca339SDan Handley  * This structure represents the superset of information needed while switching
904ecca339SDan Handley  * exception levels. The only two mechanisms to do so are ERET & SMC. In case of
914ecca339SDan Handley  * SMC all members apart from 'aapcs64_params' will be ignored.
924ecca339SDan Handley  ******************************************************************************/
93fb037bfbSDan Handley typedef struct el_change_info {
944ecca339SDan Handley 	unsigned long entrypoint;
954ecca339SDan Handley 	unsigned long spsr;
964ecca339SDan Handley 	unsigned long security_state;
97fb037bfbSDan Handley 	aapcs64_params_t args;
98fb037bfbSDan Handley } el_change_info_t;
994ecca339SDan Handley 
1004ecca339SDan Handley /*******************************************************************************
1014ecca339SDan Handley  * This structure represents the superset of information that can be passed to
1024ecca339SDan Handley  * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be
1034ecca339SDan Handley  * populated only if BL2 detects its presence.
1044ecca339SDan Handley  ******************************************************************************/
105fb037bfbSDan Handley typedef struct bl31_args {
106fb037bfbSDan Handley 	meminfo_t bl31_meminfo;
107fb037bfbSDan Handley 	el_change_info_t bl32_image_info;
108fb037bfbSDan Handley 	meminfo_t bl32_meminfo;
109fb037bfbSDan Handley 	el_change_info_t bl33_image_info;
110fb037bfbSDan Handley 	meminfo_t bl33_meminfo;
111fb037bfbSDan Handley } bl31_args_t;
1124ecca339SDan Handley 
1134ecca339SDan Handley /*******************************************************************************
1144ecca339SDan Handley  * Function & variable prototypes
1154ecca339SDan Handley  ******************************************************************************/
1164ecca339SDan Handley extern unsigned long page_align(unsigned long, unsigned);
1174ecca339SDan Handley extern void change_security_state(unsigned int);
118fb037bfbSDan Handley extern void __dead2 drop_el(aapcs64_params_t *, unsigned long, unsigned long);
119fb037bfbSDan Handley extern void __dead2 raise_el(aapcs64_params_t *);
120fb037bfbSDan Handley extern void __dead2 change_el(el_change_info_t *);
1214ecca339SDan Handley extern unsigned long make_spsr(unsigned long, unsigned long, unsigned long);
122fb037bfbSDan Handley extern void init_bl2_mem_layout(meminfo_t *,
123fb037bfbSDan Handley 				meminfo_t *,
1244ecca339SDan Handley 				unsigned int,
1254ecca339SDan Handley 				unsigned long) __attribute__((weak));
126fb037bfbSDan Handley extern void init_bl31_mem_layout(const meminfo_t *,
127fb037bfbSDan Handley 				meminfo_t *,
1284ecca339SDan Handley 				unsigned int) __attribute__((weak));
1294ecca339SDan Handley extern unsigned long image_size(const char *);
130fb037bfbSDan Handley extern unsigned long load_image(meminfo_t *,
1314ecca339SDan Handley 				const char *,
1324ecca339SDan Handley 				unsigned int,
1334ecca339SDan Handley 				unsigned long);
1344ecca339SDan Handley extern void __dead2 run_image(unsigned long entrypoint,
1354ecca339SDan Handley 				unsigned long spsr,
1364ecca339SDan Handley 				unsigned long security_state,
1374ecca339SDan Handley 				void *first_arg,
1384ecca339SDan Handley 				void *second_arg);
1394ecca339SDan Handley extern unsigned long *get_el_change_mem_ptr(void);
1404ecca339SDan Handley extern const char build_message[];
1414ecca339SDan Handley 
1424ecca339SDan Handley #endif /*__ASSEMBLY__*/
1434ecca339SDan Handley 
1444ecca339SDan Handley #endif /* __BL_COMMON_H__ */
145