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__ 614ecca339SDan Handley #include <stdio.h> 624ecca339SDan Handley 634ecca339SDan Handley /******************************************************************************* 644ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 654ecca339SDan Handley * memory is available for its use and how much is already used. 664ecca339SDan Handley ******************************************************************************/ 67*fb037bfbSDan Handley typedef struct meminfo { 684ecca339SDan Handley unsigned long total_base; 694ecca339SDan Handley long total_size; 704ecca339SDan Handley unsigned long free_base; 714ecca339SDan Handley long free_size; 724ecca339SDan Handley unsigned long attr; 734ecca339SDan Handley unsigned long next; 74*fb037bfbSDan Handley } meminfo_t; 754ecca339SDan Handley 76*fb037bfbSDan Handley typedef struct aapcs64_params { 774ecca339SDan Handley unsigned long arg0; 784ecca339SDan Handley unsigned long arg1; 794ecca339SDan Handley unsigned long arg2; 804ecca339SDan Handley unsigned long arg3; 814ecca339SDan Handley unsigned long arg4; 824ecca339SDan Handley unsigned long arg5; 834ecca339SDan Handley unsigned long arg6; 844ecca339SDan Handley unsigned long arg7; 85*fb037bfbSDan Handley } aapcs64_params_t; 864ecca339SDan Handley 874ecca339SDan Handley /******************************************************************************* 884ecca339SDan Handley * This structure represents the superset of information needed while switching 894ecca339SDan Handley * exception levels. The only two mechanisms to do so are ERET & SMC. In case of 904ecca339SDan Handley * SMC all members apart from 'aapcs64_params' will be ignored. 914ecca339SDan Handley ******************************************************************************/ 92*fb037bfbSDan Handley typedef struct el_change_info { 934ecca339SDan Handley unsigned long entrypoint; 944ecca339SDan Handley unsigned long spsr; 954ecca339SDan Handley unsigned long security_state; 96*fb037bfbSDan Handley aapcs64_params_t args; 97*fb037bfbSDan Handley } el_change_info_t; 984ecca339SDan Handley 994ecca339SDan Handley /******************************************************************************* 1004ecca339SDan Handley * This structure represents the superset of information that can be passed to 1014ecca339SDan Handley * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be 1024ecca339SDan Handley * populated only if BL2 detects its presence. 1034ecca339SDan Handley ******************************************************************************/ 104*fb037bfbSDan Handley typedef struct bl31_args { 105*fb037bfbSDan Handley meminfo_t bl31_meminfo; 106*fb037bfbSDan Handley el_change_info_t bl32_image_info; 107*fb037bfbSDan Handley meminfo_t bl32_meminfo; 108*fb037bfbSDan Handley el_change_info_t bl33_image_info; 109*fb037bfbSDan Handley meminfo_t bl33_meminfo; 110*fb037bfbSDan Handley } bl31_args_t; 1114ecca339SDan Handley 1124ecca339SDan Handley /******************************************************************************* 1134ecca339SDan Handley * Function & variable prototypes 1144ecca339SDan Handley ******************************************************************************/ 1154ecca339SDan Handley extern unsigned long page_align(unsigned long, unsigned); 1164ecca339SDan Handley extern void change_security_state(unsigned int); 117*fb037bfbSDan Handley extern void __dead2 drop_el(aapcs64_params_t *, unsigned long, unsigned long); 118*fb037bfbSDan Handley extern void __dead2 raise_el(aapcs64_params_t *); 119*fb037bfbSDan Handley extern void __dead2 change_el(el_change_info_t *); 1204ecca339SDan Handley extern unsigned long make_spsr(unsigned long, unsigned long, unsigned long); 121*fb037bfbSDan Handley extern void init_bl2_mem_layout(meminfo_t *, 122*fb037bfbSDan Handley meminfo_t *, 1234ecca339SDan Handley unsigned int, 1244ecca339SDan Handley unsigned long) __attribute__((weak)); 125*fb037bfbSDan Handley extern void init_bl31_mem_layout(const meminfo_t *, 126*fb037bfbSDan Handley meminfo_t *, 1274ecca339SDan Handley unsigned int) __attribute__((weak)); 1284ecca339SDan Handley extern unsigned long image_size(const char *); 129*fb037bfbSDan Handley extern unsigned long load_image(meminfo_t *, 1304ecca339SDan Handley const char *, 1314ecca339SDan Handley unsigned int, 1324ecca339SDan Handley unsigned long); 1334ecca339SDan Handley extern void __dead2 run_image(unsigned long entrypoint, 1344ecca339SDan Handley unsigned long spsr, 1354ecca339SDan Handley unsigned long security_state, 1364ecca339SDan Handley void *first_arg, 1374ecca339SDan Handley void *second_arg); 1384ecca339SDan Handley extern unsigned long *get_el_change_mem_ptr(void); 1394ecca339SDan Handley extern const char build_message[]; 1404ecca339SDan Handley 1414ecca339SDan Handley #endif /*__ASSEMBLY__*/ 1424ecca339SDan Handley 1434ecca339SDan Handley #endif /* __BL_COMMON_H__ */ 144