blob: f8c922e6a2c0744cff857010c22602a0a3ae4718 [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")));
Harry Liebel561cd332014-02-14 14:42:48 +000073/* Data structure which holds the extents of the Non-Secure DRAM for BL33 */
74static meminfo bl33_dram_layout
75__attribute__ ((aligned(PLATFORM_CACHE_LINE_SIZE),
76 section("tzfw_coherent_mem")));
Achin Gupta4f6ad662013-10-25 09:08:21 +010077
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000078meminfo *bl2_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010079{
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000080 return &bl2_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010081}
82
Harry Liebel561cd332014-02-14 14:42:48 +000083meminfo *bl2_get_ns_mem_layout(void)
84{
85 return &bl33_dram_layout;
86}
87
Achin Gupta4f6ad662013-10-25 09:08:21 +010088/*******************************************************************************
89 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
90 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
91 * Copy it to a safe loaction before its reclaimed by later BL2 functionality.
92 ******************************************************************************/
93void bl2_early_platform_setup(meminfo *mem_layout,
94 void *data)
95{
96 /* Setup the BL2 memory layout */
97 bl2_tzram_layout.total_base = mem_layout->total_base;
98 bl2_tzram_layout.total_size = mem_layout->total_size;
99 bl2_tzram_layout.free_base = mem_layout->free_base;
100 bl2_tzram_layout.free_size = mem_layout->free_size;
101 bl2_tzram_layout.attr = mem_layout->attr;
102 bl2_tzram_layout.next = 0;
103
Harry Liebel561cd332014-02-14 14:42:48 +0000104 /* Setup the BL3-3 memory layout.
105 * Normal World Firmware loaded into main DRAM.
106 */
107 bl33_dram_layout.total_base = DRAM_BASE;
108 bl33_dram_layout.total_size = DRAM_SIZE;
109 bl33_dram_layout.free_base = DRAM_BASE;
110 bl33_dram_layout.free_size = DRAM_SIZE;
111 bl33_dram_layout.attr = 0;
112 bl33_dram_layout.next = 0;
113
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114 /* Initialize the platform config for future decision making */
115 platform_config_setup();
116
117 return;
118}
119
120/*******************************************************************************
Sandrine Bailleux942f4052013-11-19 17:14:22 +0000121 * Perform platform specific setup. For now just initialize the memory location
122 * to use for passing arguments to BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100123 ******************************************************************************/
124void bl2_platform_setup()
125{
James Morrissey9d72b4e2014-02-10 17:04:32 +0000126 /* Initialise the IO layer and register platform IO devices */
127 io_setup();
128
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129 /* Use the Trusted DRAM for passing args to BL31 */
130 bl2_el_change_mem_ptr = (unsigned char **) TZDRAM_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131}
132
133/*******************************************************************************
134 * Perform the very early platform specific architectural setup here. At the
135 * moment this is only intializes the mmu in a quick and dirty way.
136 ******************************************************************************/
137void bl2_plat_arch_setup()
138{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139 configure_mmu(&bl2_tzram_layout,
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000140 BL2_RO_BASE,
141 BL2_RO_LIMIT,
142 BL2_COHERENT_RAM_BASE,
143 BL2_COHERENT_RAM_LIMIT);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144}