blob: 83072e457c2ffe4a755f2a0bcc3da2b664913ced [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
Sandrine Bailleux3fa98472014-03-31 11:25:18 +010031#include <arch.h>
Vikram Kanigirida567432014-04-15 18:08:08 +010032#include <assert.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <bl_common.h>
34#include <bl31.h>
Vikram Kanigiri3ff77de2014-03-25 17:35:26 +000035#include <console.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010036#include <mmio.h>
37#include <platform.h>
38#include <stddef.h>
Dan Handley4d2e49d2014-04-11 11:52:12 +010039#include "drivers/pwrc/fvp_pwrc.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010040
41/*******************************************************************************
42 * Declarations of linker defined symbols which will help us find the layout
43 * of trusted SRAM
44 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000045extern unsigned long __RO_START__;
46extern unsigned long __RO_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010047
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000048extern unsigned long __COHERENT_RAM_START__;
49extern unsigned long __COHERENT_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010050
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000051/*
52 * The next 2 constants identify the extents of the code & RO data region.
53 * These addresses are used by the MMU setup code and therefore they must be
54 * page-aligned. It is the responsibility of the linker script to ensure that
55 * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses.
56 */
57#define BL31_RO_BASE (unsigned long)(&__RO_START__)
58#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
59
60/*
61 * The next 2 constants identify the extents of the coherent memory region.
62 * These addresses are used by the MMU setup code and therefore they must be
63 * page-aligned. It is the responsibility of the linker script to ensure that
64 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols
65 * refer to page-aligned addresses.
66 */
67#define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
68#define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010069
70/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +000071 * Reference to structure which holds the arguments that have been passed to
72 * BL31 from BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +010073 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +010074static bl31_params_t *bl2_to_bl31_params;
75static bl31_plat_params_t *bl2_to_bl31_plat_params;
Achin Gupta4f6ad662013-10-25 09:08:21 +010076
Dan Handleye2712bc2014-04-10 15:37:22 +010077meminfo_t *bl31_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010078{
Vikram Kanigirida567432014-04-15 18:08:08 +010079 return &bl2_to_bl31_plat_params->bl31_meminfo;
Achin Gupta4f6ad662013-10-25 09:08:21 +010080}
81
Dan Handleye2712bc2014-04-10 15:37:22 +010082meminfo_t *bl31_plat_get_bl32_mem_layout(void)
Achin Gupta35ca3512014-02-19 17:58:33 +000083{
Vikram Kanigirida567432014-04-15 18:08:08 +010084 return &bl2_to_bl31_plat_params->bl32_meminfo;
Achin Gupta35ca3512014-02-19 17:58:33 +000085}
86
Achin Gupta4f6ad662013-10-25 09:08:21 +010087/*******************************************************************************
Vikram Kanigirida567432014-04-15 18:08:08 +010088 * Return a pointer to the 'entry_point_info' structure of the next image for the
Achin Gupta35ca3512014-02-19 17:58:33 +000089 * security state specified. BL33 corresponds to the non-secure image type
90 * while BL32 corresponds to the secure image type. A NULL pointer is returned
91 * if the image does not exist.
Achin Gupta4f6ad662013-10-25 09:08:21 +010092 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +010093entry_point_info_t *bl31_get_next_image_info(uint32_t type)
Achin Gupta4f6ad662013-10-25 09:08:21 +010094{
Vikram Kanigirida567432014-04-15 18:08:08 +010095 entry_point_info_t *next_image_info;
Achin Gupta35ca3512014-02-19 17:58:33 +000096
97 next_image_info = (type == NON_SECURE) ?
Vikram Kanigirida567432014-04-15 18:08:08 +010098 bl2_to_bl31_params->bl33_ep_info :
99 bl2_to_bl31_params->bl32_ep_info;
Achin Gupta35ca3512014-02-19 17:58:33 +0000100
101 /* None of the images on this platform can have 0x0 as the entrypoint */
Vikram Kanigirida567432014-04-15 18:08:08 +0100102 if (next_image_info->pc)
Achin Gupta35ca3512014-02-19 17:58:33 +0000103 return next_image_info;
104 else
105 return NULL;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100106}
107
108/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +0000109 * Perform any BL31 specific platform actions. Here is an opportunity to copy
110 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
111 * are lost (potentially). This needs to be done before the MMU is initialized
112 * so that the memory layout can be used while creating page tables. On the FVP
113 * we know that BL2 has populated the parameters in secure DRAM. So we just use
114 * the reference passed in 'from_bl2' instead of copying. The 'data' parameter
115 * is not used since all the information is contained in 'from_bl2'. Also, BL2
116 * has flushed this information to memory, so we are guaranteed to pick up good
117 * data
Achin Gupta4f6ad662013-10-25 09:08:21 +0100118 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +0100119void bl31_early_platform_setup(bl31_params_t *from_bl2,
120 bl31_plat_params_t *plat_info_from_bl2)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100121{
Vikram Kanigirida567432014-04-15 18:08:08 +0100122 assert(from_bl2->h.type == PARAM_BL31);
123 assert(from_bl2->h.version >= VERSION_1);
124
125 bl2_to_bl31_params = from_bl2;
126 bl2_to_bl31_plat_params = plat_info_from_bl2;
127
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128
Vikram Kanigiri3684abf2014-03-27 14:33:15 +0000129 /* Initialize the console to provide early debug support */
130 console_init(PL011_UART0_BASE);
131
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132 /* Initialize the platform config for future decision making */
133 platform_config_setup();
134}
135
136/*******************************************************************************
137 * Initialize the gic, configure the CLCD and zero out variables needed by the
138 * secondaries to boot up correctly.
139 ******************************************************************************/
140void bl31_platform_setup()
141{
142 unsigned int reg_val;
143
Ian Spray84687392014-01-02 16:57:12 +0000144 /* Initialize the gic cpu and distributor interfaces */
145 gic_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100146
147 /*
148 * TODO: Configure the CLCD before handing control to
149 * linux. Need to see if a separate driver is needed
150 * instead.
151 */
152 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGDATA, 0);
153 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
154 (1ull << 31) | (1 << 30) | (7 << 20) | (0 << 16));
155
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100156 /* Enable and initialize the System level generic timer */
157 mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN);
158
Achin Gupta4f6ad662013-10-25 09:08:21 +0100159 /* Allow access to the System counter timer module */
160 reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT);
161 reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT);
162 reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT);
163 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(0), reg_val);
164 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val);
165
166 reg_val = (1 << CNTNSAR_NS_SHIFT(0)) | (1 << CNTNSAR_NS_SHIFT(1));
167 mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val);
168
169 /* Intialize the power controller */
170 fvp_pwrc_setup();
171
Ian Spray84687392014-01-02 16:57:12 +0000172 /* Topologies are best known to the platform. */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100173 plat_setup_topology();
174}
175
176/*******************************************************************************
177 * Perform the very early platform specific architectural setup here. At the
178 * moment this is only intializes the mmu in a quick and dirty way.
179 ******************************************************************************/
180void bl31_plat_arch_setup()
181{
Vikram Kanigirida567432014-04-15 18:08:08 +0100182 configure_mmu_el3(&bl2_to_bl31_plat_params->bl31_meminfo,
Sandrine Bailleux74a62b32014-05-09 11:35:36 +0100183 BL31_RO_BASE,
184 BL31_RO_LIMIT,
185 BL31_COHERENT_RAM_BASE,
186 BL31_COHERENT_RAM_LIMIT);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100187}