blob: f0d6e448447e2a937a985841450bbcc36a66ddaf [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 <assert.h>
32#include <arch_helpers.h>
33#include <platform.h>
34#include <bl2.h>
35#include <bl_common.h>
36
37/*******************************************************************************
38 * Declarations of linker defined symbols which will help us find the layout
39 * of trusted SRAM
40 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000041extern unsigned long __RO_START__;
42extern unsigned long __RO_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010043
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 +000047/*
48 * The next 2 constants identify the extents of the code & RO data region.
49 * These addresses are used by the MMU setup code and therefore they must be
50 * page-aligned. It is the responsibility of the linker script to ensure that
51 * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses.
52 */
53#define BL2_RO_BASE (unsigned long)(&__RO_START__)
54#define BL2_RO_LIMIT (unsigned long)(&__RO_END__)
55
56/*
57 * The next 2 constants identify the extents of the coherent memory region.
58 * These addresses are used by the MMU setup code and therefore they must be
59 * page-aligned. It is the responsibility of the linker script to ensure that
60 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
61 * page-aligned addresses.
62 */
63#define BL2_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
64#define BL2_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010065
66/* Pointer to memory visible to both BL2 and BL31 for passing data */
67extern unsigned char **bl2_el_change_mem_ptr;
68
69/* Data structure which holds the extents of the trusted SRAM for BL2 */
70static meminfo bl2_tzram_layout
71__attribute__ ((aligned(PLATFORM_CACHE_LINE_SIZE),
Sandrine Bailleux204aa032013-10-28 15:14:00 +000072 section("tzfw_coherent_mem")));
Achin Guptae4d084e2014-02-19 17:18:23 +000073
74/*******************************************************************************
75 * Reference to structure which holds the arguments which need to be passed
76 * to BL31
77 ******************************************************************************/
78static bl31_args *bl2_to_bl31_args;
Achin Gupta4f6ad662013-10-25 09:08:21 +010079
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000080meminfo *bl2_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010081{
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000082 return &bl2_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010083}
84
Achin Guptae4d084e2014-02-19 17:18:23 +000085/*******************************************************************************
86 * This function returns a pointer to the memory that the platform has kept
87 * aside to pass all the information that BL31 could need.
88 ******************************************************************************/
89bl31_args *bl2_get_bl31_args_ptr(void)
Harry Liebel561cd332014-02-14 14:42:48 +000090{
Achin Guptae4d084e2014-02-19 17:18:23 +000091 return bl2_to_bl31_args;
Harry Liebel561cd332014-02-14 14:42:48 +000092}
93
Achin Gupta4f6ad662013-10-25 09:08:21 +010094/*******************************************************************************
95 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
96 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
97 * Copy it to a safe loaction before its reclaimed by later BL2 functionality.
98 ******************************************************************************/
99void bl2_early_platform_setup(meminfo *mem_layout,
100 void *data)
101{
102 /* Setup the BL2 memory layout */
103 bl2_tzram_layout.total_base = mem_layout->total_base;
104 bl2_tzram_layout.total_size = mem_layout->total_size;
105 bl2_tzram_layout.free_base = mem_layout->free_base;
106 bl2_tzram_layout.free_size = mem_layout->free_size;
107 bl2_tzram_layout.attr = mem_layout->attr;
108 bl2_tzram_layout.next = 0;
109
110 /* Initialize the platform config for future decision making */
111 platform_config_setup();
112
113 return;
114}
115
116/*******************************************************************************
Sandrine Bailleux942f4052013-11-19 17:14:22 +0000117 * Perform platform specific setup. For now just initialize the memory location
118 * to use for passing arguments to BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119 ******************************************************************************/
120void bl2_platform_setup()
121{
James Morrissey9d72b4e2014-02-10 17:04:32 +0000122 /* Initialise the IO layer and register platform IO devices */
123 io_setup();
124
Achin Guptaa3050ed2014-02-19 17:52:35 +0000125 /*
126 * Ensure that the secure DRAM memory used for passing BL31 arguments
127 * does not overlap with the BL32_BASE.
128 */
129 assert (BL32_BASE > TZDRAM_BASE + sizeof(bl31_args));
130
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131 /* Use the Trusted DRAM for passing args to BL31 */
Achin Guptae4d084e2014-02-19 17:18:23 +0000132 bl2_to_bl31_args = (bl31_args *) TZDRAM_BASE;
133
134 /* Populate the extents of memory available for loading BL33 */
135 bl2_to_bl31_args->bl33_meminfo.total_base = DRAM_BASE;
136 bl2_to_bl31_args->bl33_meminfo.total_size = DRAM_SIZE;
137 bl2_to_bl31_args->bl33_meminfo.free_base = DRAM_BASE;
138 bl2_to_bl31_args->bl33_meminfo.free_size = DRAM_SIZE;
139 bl2_to_bl31_args->bl33_meminfo.attr = 0;
140 bl2_to_bl31_args->bl33_meminfo.next = 0;
Achin Guptaa3050ed2014-02-19 17:52:35 +0000141
142 /*
143 * Populate the extents of memory available for loading BL32.
144 * TODO: We are temporarily executing BL2 from TZDRAM; will eventually
145 * move to Trusted SRAM
146 */
147 bl2_to_bl31_args->bl32_meminfo.total_base = BL32_BASE;
148 bl2_to_bl31_args->bl32_meminfo.free_base = BL32_BASE;
149
150 bl2_to_bl31_args->bl32_meminfo.total_size =
151 (TZDRAM_BASE + TZDRAM_SIZE) - BL32_BASE;
152 bl2_to_bl31_args->bl32_meminfo.free_size =
153 (TZDRAM_BASE + TZDRAM_SIZE) - BL32_BASE;
154
155 bl2_to_bl31_args->bl32_meminfo.attr = BOT_LOAD;
156 bl2_to_bl31_args->bl32_meminfo.next = 0;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100157}
158
159/*******************************************************************************
160 * Perform the very early platform specific architectural setup here. At the
161 * moment this is only intializes the mmu in a quick and dirty way.
162 ******************************************************************************/
163void bl2_plat_arch_setup()
164{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100165 configure_mmu(&bl2_tzram_layout,
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000166 BL2_RO_BASE,
167 BL2_RO_LIMIT,
168 BL2_COHERENT_RAM_BASE,
169 BL2_COHERENT_RAM_LIMIT);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100170}