blob: ac3b69a993505428ce8e0ccd7bbd1eccc89a2b54 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
Achin Gupta4f6ad662013-10-25 09:08:21 +010031#include <arch_helpers.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010032#include <assert.h>
33#include <bl_common.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010034#include <bl1.h>
35#include <console.h>
Harry Liebel30affd52013-10-30 17:41:48 +000036#include <cci400.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010037#include <mmio.h>
38#include <platform.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010039
40/*******************************************************************************
41 * Declarations of linker defined symbols which will help us find the layout
42 * of trusted SRAM
43 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000044extern unsigned long __COHERENT_RAM_START__;
45extern unsigned long __COHERENT_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010046
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000047extern unsigned long __BL1_RAM_START__;
48extern unsigned long __BL1_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010049
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000050/*
51 * The next 2 constants identify the extents of the coherent memory region.
52 * These addresses are used by the MMU setup code and therefore they must be
53 * page-aligned. It is the responsibility of the linker script to ensure that
54 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
55 * page-aligned addresses.
56 */
57#define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
58#define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010059
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000060#define BL1_RAM_BASE (unsigned long)(&__BL1_RAM_START__)
61#define BL1_RAM_LIMIT (unsigned long)(&__BL1_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010062
Achin Gupta4f6ad662013-10-25 09:08:21 +010063
64/* Data structure which holds the extents of the trusted SRAM for BL1*/
Dan Handleye2712bc2014-04-10 15:37:22 +010065static meminfo_t bl1_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010066
Dan Handleye2712bc2014-04-10 15:37:22 +010067meminfo_t *bl1_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010068{
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000069 return &bl1_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010070}
71
72/*******************************************************************************
73 * Perform any BL1 specific platform actions.
74 ******************************************************************************/
75void bl1_early_platform_setup(void)
76{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000077 const unsigned long bl1_ram_base = BL1_RAM_BASE;
78 const unsigned long bl1_ram_limit = BL1_RAM_LIMIT;
79 const unsigned long tzram_limit = TZRAM_BASE + TZRAM_SIZE;
Achin Gupta4f6ad662013-10-25 09:08:21 +010080
Vikram Kanigiri3684abf2014-03-27 14:33:15 +000081 /* Initialize the console to provide early debug support */
82 console_init(PL011_UART0_BASE);
83
Achin Gupta4f6ad662013-10-25 09:08:21 +010084 /*
85 * Calculate how much ram is BL1 using & how much remains free.
86 * This also includes a rudimentary mechanism to detect whether
87 * the BL1 data is loaded at the top or bottom of memory.
88 * TODO: add support for discontigous chunks of free ram if
89 * needed. Might need dynamic memory allocation support
90 * et al.
Achin Gupta4f6ad662013-10-25 09:08:21 +010091 */
92 bl1_tzram_layout.total_base = TZRAM_BASE;
93 bl1_tzram_layout.total_size = TZRAM_SIZE;
94
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000095 if (bl1_ram_limit == tzram_limit) {
96 /* BL1 has been loaded at the top of memory. */
Achin Gupta4f6ad662013-10-25 09:08:21 +010097 bl1_tzram_layout.free_base = TZRAM_BASE;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000098 bl1_tzram_layout.free_size = bl1_ram_base - TZRAM_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +010099 } else {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000100 /* BL1 has been loaded at the bottom of memory. */
101 bl1_tzram_layout.free_base = bl1_ram_limit;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100102 bl1_tzram_layout.free_size =
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000103 tzram_limit - bl1_ram_limit;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100104 }
Harry Liebel30affd52013-10-30 17:41:48 +0000105
106 /* Initialize the platform config for future decision making */
107 platform_config_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108}
109
110/*******************************************************************************
111 * Function which will evaluate how much of the trusted ram has been gobbled
112 * up by BL1 and return the base and size of whats available for loading BL2.
113 * Its called after coherency and the MMU have been turned on.
114 ******************************************************************************/
115void bl1_platform_setup(void)
116{
James Morrissey9d72b4e2014-02-10 17:04:32 +0000117 /* Initialise the IO layer and register platform IO devices */
118 io_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119}
120
James Morrissey9d72b4e2014-02-10 17:04:32 +0000121
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122/*******************************************************************************
123 * Perform the very early platform specific architecture setup here. At the
Harry Liebel30affd52013-10-30 17:41:48 +0000124 * moment this only does basic initialization. Later architectural setup
125 * (bl1_arch_setup()) does not do anything platform specific.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100126 ******************************************************************************/
127void bl1_plat_arch_setup(void)
128{
Harry Liebel30affd52013-10-30 17:41:48 +0000129 unsigned long cci_setup;
130
131 /*
132 * Enable CCI-400 for this cluster. No need
133 * for locks as no other cpu is active at the
134 * moment
135 */
136 cci_setup = platform_get_cfgvar(CONFIG_HAS_CCI);
137 if (cci_setup) {
138 cci_enable_coherency(read_mpidr());
139 }
140
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100141 configure_mmu_el3(&bl1_tzram_layout,
142 TZROM_BASE,
143 TZROM_BASE + TZROM_SIZE,
144 BL1_COHERENT_RAM_BASE,
145 BL1_COHERENT_RAM_LIMIT);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100146}
Vikram Kanigirida567432014-04-15 18:08:08 +0100147
148
149/*******************************************************************************
150 * Before calling this function BL2 is loaded in memory and its entrypoint
151 * is set by load_image. This is a placeholder for the platform to change
152 * the entrypoint of BL2 and set SPSR and security state.
153 * On FVP we are only setting the security state, entrypoint
154 ******************************************************************************/
155void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image,
156 entry_point_info_t *bl2_ep)
157{
158 SET_SECURITY_STATE(bl2_ep->h.attr, SECURE);
159 bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
160}