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 344112bfa0SVikram Kanigiri #define SECURE 0x0 354112bfa0SVikram Kanigiri #define NON_SECURE 0x1 364ecca339SDan Handley 374ecca339SDan Handley #define UP 1 384ecca339SDan Handley #define DOWN 0 394ecca339SDan Handley 404ecca339SDan Handley /******************************************************************************* 41*8f55dfb4SSandrine Bailleux * Constants to identify the location of a memory region in a given memory 42*8f55dfb4SSandrine Bailleux * layout. 434ecca339SDan Handley ******************************************************************************/ 44*8f55dfb4SSandrine Bailleux #define TOP 0x1 45*8f55dfb4SSandrine Bailleux #define BOTTOM !TOP 464ecca339SDan Handley 474ecca339SDan Handley /****************************************************************************** 484ecca339SDan Handley * Opcode passed in x0 to tell next EL that we want to run an image. 494ecca339SDan Handley * Corresponds to the function ID of the only SMC that the BL1 exception 504ecca339SDan Handley * handlers service. That's why the chosen value is the first function ID of 514ecca339SDan Handley * the ARM SMC64 range. 524ecca339SDan Handley *****************************************************************************/ 534ecca339SDan Handley #define RUN_IMAGE 0xC0000000 544ecca339SDan Handley 5529fb905dSVikram Kanigiri /******************************************************************************* 5629fb905dSVikram Kanigiri * Constants that allow assembler code to access members of and the 574112bfa0SVikram Kanigiri * 'entry_point_info' structure at their correct offsets. 5829fb905dSVikram Kanigiri ******************************************************************************/ 594112bfa0SVikram Kanigiri #define ENTRY_POINT_INFO_PC_OFFSET 0x08 604112bfa0SVikram Kanigiri #define ENTRY_POINT_INFO_ARGS_OFFSET 0x18 614112bfa0SVikram Kanigiri 62167a9357SAndrew Thoelke #define PARAM_EP_SECURITY_MASK 0x1 634112bfa0SVikram Kanigiri #define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK) 644112bfa0SVikram Kanigiri #define SET_SECURITY_STATE(x, security) \ 654112bfa0SVikram Kanigiri ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) 664112bfa0SVikram Kanigiri 67167a9357SAndrew Thoelke #define EP_EE_MASK 0x2 68167a9357SAndrew Thoelke #define EP_EE_LITTLE 0x0 69167a9357SAndrew Thoelke #define EP_EE_BIG 0x2 70167a9357SAndrew Thoelke #define EP_GET_EE(x) (x & EP_EE_MASK) 71167a9357SAndrew Thoelke #define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee)) 72167a9357SAndrew Thoelke 73167a9357SAndrew Thoelke #define EP_ST_MASK 0x4 74167a9357SAndrew Thoelke #define EP_ST_DISABLE 0x0 75167a9357SAndrew Thoelke #define EP_ST_ENABLE 0x4 76167a9357SAndrew Thoelke #define EP_GET_ST(x) (x & EP_ST_MASK) 77167a9357SAndrew Thoelke #define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee)) 78167a9357SAndrew Thoelke 794112bfa0SVikram Kanigiri #define PARAM_EP 0x01 804112bfa0SVikram Kanigiri #define PARAM_IMAGE_BINARY 0x02 814112bfa0SVikram Kanigiri #define PARAM_BL31 0x03 824112bfa0SVikram Kanigiri 834112bfa0SVikram Kanigiri #define VERSION_1 0x01 844112bfa0SVikram Kanigiri 854112bfa0SVikram Kanigiri #define SET_PARAM_HEAD(_p, _type, _ver, _attr) do { \ 864112bfa0SVikram Kanigiri (_p)->h.type = (uint8_t)(_type); \ 874112bfa0SVikram Kanigiri (_p)->h.version = (uint8_t)(_ver); \ 884112bfa0SVikram Kanigiri (_p)->h.size = (uint16_t)sizeof(*_p); \ 894112bfa0SVikram Kanigiri (_p)->h.attr = (uint32_t)(_attr) ; \ 904112bfa0SVikram Kanigiri } while (0) 914ecca339SDan Handley 924ecca339SDan Handley #ifndef __ASSEMBLY__ 9397043ac9SDan Handley #include <cdefs.h> /* For __dead2 */ 9429fb905dSVikram Kanigiri #include <cassert.h> 954112bfa0SVikram Kanigiri #include <stdint.h> 96*8f55dfb4SSandrine Bailleux #include <stddef.h> 974ecca339SDan Handley 984ecca339SDan Handley /******************************************************************************* 994ecca339SDan Handley * Structure used for telling the next BL how much of a particular type of 1004ecca339SDan Handley * memory is available for its use and how much is already used. 1014ecca339SDan Handley ******************************************************************************/ 102fb037bfbSDan Handley typedef struct meminfo { 103*8f55dfb4SSandrine Bailleux uint64_t total_base; 104*8f55dfb4SSandrine Bailleux size_t total_size; 105*8f55dfb4SSandrine Bailleux uint64_t free_base; 106*8f55dfb4SSandrine Bailleux size_t free_size; 107fb037bfbSDan Handley } meminfo_t; 1084ecca339SDan Handley 109fb037bfbSDan Handley typedef struct aapcs64_params { 1104ecca339SDan Handley unsigned long arg0; 1114ecca339SDan Handley unsigned long arg1; 1124ecca339SDan Handley unsigned long arg2; 1134ecca339SDan Handley unsigned long arg3; 1144ecca339SDan Handley unsigned long arg4; 1154ecca339SDan Handley unsigned long arg5; 1164ecca339SDan Handley unsigned long arg6; 1174ecca339SDan Handley unsigned long arg7; 118fb037bfbSDan Handley } aapcs64_params_t; 1194ecca339SDan Handley 1204112bfa0SVikram Kanigiri /*************************************************************************** 1214112bfa0SVikram Kanigiri * This structure provides version information and the size of the 1224112bfa0SVikram Kanigiri * structure, attributes for the structure it represents 1234112bfa0SVikram Kanigiri ***************************************************************************/ 1244112bfa0SVikram Kanigiri typedef struct param_header { 1254112bfa0SVikram Kanigiri uint8_t type; /* type of the structure */ 1264112bfa0SVikram Kanigiri uint8_t version; /* version of this structure */ 1274112bfa0SVikram Kanigiri uint16_t size; /* size of this structure in bytes */ 1284112bfa0SVikram Kanigiri uint32_t attr; /* attributes: unused bits SBZ */ 1294112bfa0SVikram Kanigiri } param_header_t; 1304112bfa0SVikram Kanigiri 1314112bfa0SVikram Kanigiri /***************************************************************************** 1324112bfa0SVikram Kanigiri * This structure represents the superset of information needed while 1334112bfa0SVikram Kanigiri * switching exception levels. The only two mechanisms to do so are 1344112bfa0SVikram Kanigiri * ERET & SMC. Security state is indicated using bit zero of header 1354112bfa0SVikram Kanigiri * attribute 1364112bfa0SVikram Kanigiri * NOTE: BL1 expects entrypoint followed by spsr while processing 1374112bfa0SVikram Kanigiri * SMC to jump to BL31 from the start of entry_point_info 1384112bfa0SVikram Kanigiri *****************************************************************************/ 1394112bfa0SVikram Kanigiri typedef struct entry_point_info { 1404112bfa0SVikram Kanigiri param_header_t h; 1414112bfa0SVikram Kanigiri uintptr_t pc; 1424112bfa0SVikram Kanigiri uint32_t spsr; 143fb037bfbSDan Handley aapcs64_params_t args; 1444112bfa0SVikram Kanigiri } entry_point_info_t; 1454112bfa0SVikram Kanigiri 1464112bfa0SVikram Kanigiri /***************************************************************************** 1474112bfa0SVikram Kanigiri * Image info binary provides information from the image loader that 1484112bfa0SVikram Kanigiri * can be used by the firmware to manage available trusted RAM. 1494112bfa0SVikram Kanigiri * More advanced firmware image formats can provide additional 1504112bfa0SVikram Kanigiri * information that enables optimization or greater flexibility in the 1514112bfa0SVikram Kanigiri * common firmware code 1524112bfa0SVikram Kanigiri *****************************************************************************/ 1534112bfa0SVikram Kanigiri typedef struct image_info { 1544112bfa0SVikram Kanigiri param_header_t h; 1554112bfa0SVikram Kanigiri uintptr_t image_base; /* physical address of base of image */ 1564112bfa0SVikram Kanigiri uint32_t image_size; /* bytes read from image file */ 1574112bfa0SVikram Kanigiri } image_info_t; 1584ecca339SDan Handley 1594ecca339SDan Handley /******************************************************************************* 1604ecca339SDan Handley * This structure represents the superset of information that can be passed to 1614ecca339SDan Handley * BL31 e.g. while passing control to it from BL2. The BL32 parameters will be 1624112bfa0SVikram Kanigiri * populated only if BL2 detects its presence. A pointer to a structure of this 1634112bfa0SVikram Kanigiri * type should be passed in X3 to BL31's cold boot entrypoint 1644112bfa0SVikram Kanigiri * 1654112bfa0SVikram Kanigiri * Use of this structure and the X3 parameter is not mandatory: the BL3-1 1664112bfa0SVikram Kanigiri * platform code can use other mechanisms to provide the necessary information 1674112bfa0SVikram Kanigiri * about BL3-2 and BL3-3 to the common and SPD code. 1684112bfa0SVikram Kanigiri * 1694112bfa0SVikram Kanigiri * BL3-1 image information is mandatory if this structure is used. If either of 1704112bfa0SVikram Kanigiri * the optional BL3-2 and BL3-3 image information is not provided, this is 1714112bfa0SVikram Kanigiri * indicated by the respective image_info pointers being zero. 1724ecca339SDan Handley ******************************************************************************/ 1734112bfa0SVikram Kanigiri typedef struct bl31_params { 1744112bfa0SVikram Kanigiri param_header_t h; 1754112bfa0SVikram Kanigiri image_info_t *bl31_image_info; 1764112bfa0SVikram Kanigiri entry_point_info_t *bl32_ep_info; 1774112bfa0SVikram Kanigiri image_info_t *bl32_image_info; 1784112bfa0SVikram Kanigiri entry_point_info_t *bl33_ep_info; 1794112bfa0SVikram Kanigiri image_info_t *bl33_image_info; 1804112bfa0SVikram Kanigiri } bl31_params_t; 1814112bfa0SVikram Kanigiri 1824112bfa0SVikram Kanigiri 18329fb905dSVikram Kanigiri /* 1844112bfa0SVikram Kanigiri * Compile time assertions related to the 'entry_point_info' structure to 18529fb905dSVikram Kanigiri * ensure that the assembler and the compiler view of the offsets of 18629fb905dSVikram Kanigiri * the structure members is the same. 18729fb905dSVikram Kanigiri */ 1884112bfa0SVikram Kanigiri CASSERT(ENTRY_POINT_INFO_PC_OFFSET == 1894112bfa0SVikram Kanigiri __builtin_offsetof(entry_point_info_t, pc), \ 19029fb905dSVikram Kanigiri assert_BL31_pc_offset_mismatch); 19129fb905dSVikram Kanigiri 1924112bfa0SVikram Kanigiri CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \ 1934112bfa0SVikram Kanigiri __builtin_offsetof(entry_point_info_t, args), \ 19429fb905dSVikram Kanigiri assert_BL31_args_offset_mismatch); 19529fb905dSVikram Kanigiri 1964112bfa0SVikram Kanigiri CASSERT(sizeof(unsigned long) == 1974112bfa0SVikram Kanigiri __builtin_offsetof(entry_point_info_t, spsr) - \ 1984112bfa0SVikram Kanigiri __builtin_offsetof(entry_point_info_t, pc), \ 19929fb905dSVikram Kanigiri assert_entrypoint_and_spsr_should_be_adjacent); 20029fb905dSVikram Kanigiri 2014ecca339SDan Handley /******************************************************************************* 2024ecca339SDan Handley * Function & variable prototypes 2034ecca339SDan Handley ******************************************************************************/ 204c6bc0710SDan Handley unsigned long page_align(unsigned long, unsigned); 205c6bc0710SDan Handley void change_security_state(unsigned int); 206c6bc0710SDan Handley unsigned long image_size(const char *); 207*8f55dfb4SSandrine Bailleux int load_image(meminfo_t *mem_layout, 208*8f55dfb4SSandrine Bailleux const char *image_name, 209*8f55dfb4SSandrine Bailleux uint64_t image_base, 210*8f55dfb4SSandrine Bailleux image_info_t *image_data, 211*8f55dfb4SSandrine Bailleux entry_point_info_t *entry_point_info); 2124ecca339SDan Handley extern const char build_message[]; 2134ecca339SDan Handley 214*8f55dfb4SSandrine Bailleux void reserve_mem(uint64_t *free_base, size_t *free_size, 215*8f55dfb4SSandrine Bailleux uint64_t addr, size_t size); 216*8f55dfb4SSandrine Bailleux 2174ecca339SDan Handley #endif /*__ASSEMBLY__*/ 2184ecca339SDan Handley 2194ecca339SDan Handley #endif /* __BL_COMMON_H__ */ 220