blob: 8fe4c957dba81610c322596a53f9b10a950cb5c0 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleyab2d31e2013-12-02 19:25:12 +00002 * Copyright (c) 2013, 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
31#include <string.h>
32#include <assert.h>
33#include <arch_helpers.h>
34#include <platform.h>
35#include <bl1.h>
36#include <console.h>
Harry Liebel30affd52013-10-30 17:41:48 +000037#include <cci400.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010038
39/*******************************************************************************
40 * Declarations of linker defined symbols which will help us find the layout
41 * of trusted SRAM
42 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000043extern unsigned long __COHERENT_RAM_START__;
44extern unsigned long __COHERENT_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010045
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000046extern unsigned long __BL1_RAM_START__;
47extern unsigned long __BL1_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010048
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000049/*
50 * The next 2 constants identify the extents of the coherent memory region.
51 * These addresses are used by the MMU setup code and therefore they must be
52 * page-aligned. It is the responsibility of the linker script to ensure that
53 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
54 * page-aligned addresses.
55 */
56#define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
57#define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010058
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000059#define BL1_RAM_BASE (unsigned long)(&__BL1_RAM_START__)
60#define BL1_RAM_LIMIT (unsigned long)(&__BL1_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010061
Achin Gupta4f6ad662013-10-25 09:08:21 +010062
63/* Data structure which holds the extents of the trusted SRAM for BL1*/
Sandrine Bailleux204aa032013-10-28 15:14:00 +000064static meminfo bl1_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010065
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000066meminfo *bl1_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010067{
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000068 return &bl1_tzram_layout;
Achin Gupta4f6ad662013-10-25 09:08:21 +010069}
70
71/*******************************************************************************
72 * Perform any BL1 specific platform actions.
73 ******************************************************************************/
74void bl1_early_platform_setup(void)
75{
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000076 const unsigned long bl1_ram_base = BL1_RAM_BASE;
77 const unsigned long bl1_ram_limit = BL1_RAM_LIMIT;
78 const unsigned long tzram_limit = TZRAM_BASE + TZRAM_SIZE;
Achin Gupta4f6ad662013-10-25 09:08:21 +010079
80 /*
81 * Calculate how much ram is BL1 using & how much remains free.
82 * This also includes a rudimentary mechanism to detect whether
83 * the BL1 data is loaded at the top or bottom of memory.
84 * TODO: add support for discontigous chunks of free ram if
85 * needed. Might need dynamic memory allocation support
86 * et al.
Achin Gupta4f6ad662013-10-25 09:08:21 +010087 */
88 bl1_tzram_layout.total_base = TZRAM_BASE;
89 bl1_tzram_layout.total_size = TZRAM_SIZE;
90
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000091 if (bl1_ram_limit == tzram_limit) {
92 /* BL1 has been loaded at the top of memory. */
Achin Gupta4f6ad662013-10-25 09:08:21 +010093 bl1_tzram_layout.free_base = TZRAM_BASE;
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000094 bl1_tzram_layout.free_size = bl1_ram_base - TZRAM_BASE;
Achin Gupta4f6ad662013-10-25 09:08:21 +010095 } else {
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000096 /* BL1 has been loaded at the bottom of memory. */
97 bl1_tzram_layout.free_base = bl1_ram_limit;
Achin Gupta4f6ad662013-10-25 09:08:21 +010098 bl1_tzram_layout.free_size =
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000099 tzram_limit - bl1_ram_limit;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100100 }
Harry Liebel30affd52013-10-30 17:41:48 +0000101
102 /* Initialize the platform config for future decision making */
103 platform_config_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100104}
105
106/*******************************************************************************
107 * Function which will evaluate how much of the trusted ram has been gobbled
108 * up by BL1 and return the base and size of whats available for loading BL2.
109 * Its called after coherency and the MMU have been turned on.
110 ******************************************************************************/
111void bl1_platform_setup(void)
112{
Achin Gupta4f6ad662013-10-25 09:08:21 +0100113 /* Enable and initialize the System level generic timer */
114 mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_EN);
115
116 /* Initialize the console */
117 console_init();
118
119 return;
120}
121
122/*******************************************************************************
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
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141 configure_mmu(&bl1_tzram_layout,
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000142 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}