blob: 3874413f009ab0a7e8e05185dc17ae0e230d8660 [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 Kanigiri96377452014-04-24 11:02:16 +010032#include <arch_helpers.h>
Dan Handleyfb42b122014-06-20 09:43:15 +010033#include <arm_gic.h>
Vikram Kanigirida567432014-04-15 18:08:08 +010034#include <assert.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010035#include <bl_common.h>
36#include <bl31.h>
Vikram Kanigiri3ff77de2014-03-25 17:35:26 +000037#include <console.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010038#include <mmio.h>
39#include <platform.h>
40#include <stddef.h>
Dan Handley4d2e49d2014-04-11 11:52:12 +010041#include "drivers/pwrc/fvp_pwrc.h"
Dan Handleyed6ff952014-05-14 17:44:19 +010042#include "fvp_def.h"
43#include "fvp_private.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010044
45/*******************************************************************************
46 * Declarations of linker defined symbols which will help us find the layout
47 * of trusted SRAM
48 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000049extern unsigned long __RO_START__;
50extern unsigned long __RO_END__;
Soby Mathew2ae20432015-01-08 18:02:44 +000051extern unsigned long __BL31_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010052
Soby Mathew2ae20432015-01-08 18:02:44 +000053#if USE_COHERENT_MEM
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000054extern unsigned long __COHERENT_RAM_START__;
55extern unsigned long __COHERENT_RAM_END__;
Soby Mathew2ae20432015-01-08 18:02:44 +000056#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010057
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000058/*
Soby Mathew2ae20432015-01-08 18:02:44 +000059 * The next 3 constants identify the extents of the code, RO data region and the
60 * limit of the BL3-1 image. These addresses are used by the MMU setup code and
61 * therefore they must be page-aligned. It is the responsibility of the linker
62 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
63 * refer to page-aligned addresses.
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000064 */
65#define BL31_RO_BASE (unsigned long)(&__RO_START__)
66#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
Soby Mathew2ae20432015-01-08 18:02:44 +000067#define BL31_END (unsigned long)(&__BL31_END__)
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000068
Soby Mathew2ae20432015-01-08 18:02:44 +000069#if USE_COHERENT_MEM
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000070/*
71 * The next 2 constants identify the extents of the coherent memory region.
72 * These addresses are used by the MMU setup code and therefore they must be
73 * page-aligned. It is the responsibility of the linker script to ensure that
74 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols
75 * refer to page-aligned addresses.
76 */
77#define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
78#define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Soby Mathew2ae20432015-01-08 18:02:44 +000079#endif
Vikram Kanigiri96377452014-04-24 11:02:16 +010080
81#if RESET_TO_BL31
Vikram Kanigiri9d70f0f2014-07-15 16:46:43 +010082static entry_point_info_t bl32_image_ep_info;
83static entry_point_info_t bl33_image_ep_info;
Vikram Kanigiri96377452014-04-24 11:02:16 +010084#else
Achin Gupta4f6ad662013-10-25 09:08:21 +010085/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +000086 * Reference to structure which holds the arguments that have been passed to
87 * BL31 from BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +010088 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +010089static bl31_params_t *bl2_to_bl31_params;
Vikram Kanigiri96377452014-04-24 11:02:16 +010090#endif
Achin Gupta35ca3512014-02-19 17:58:33 +000091
Achin Gupta4f6ad662013-10-25 09:08:21 +010092/*******************************************************************************
Vikram Kanigirida567432014-04-15 18:08:08 +010093 * Return a pointer to the 'entry_point_info' structure of the next image for the
Achin Gupta35ca3512014-02-19 17:58:33 +000094 * security state specified. BL33 corresponds to the non-secure image type
95 * while BL32 corresponds to the secure image type. A NULL pointer is returned
96 * if the image does not exist.
Achin Gupta4f6ad662013-10-25 09:08:21 +010097 ******************************************************************************/
Dan Handley701fea72014-05-27 16:17:21 +010098entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
Achin Gupta4f6ad662013-10-25 09:08:21 +010099{
Vikram Kanigiri96377452014-04-24 11:02:16 +0100100#if RESET_TO_BL31
Juan Castillof558cac2014-06-05 09:45:36 +0100101 assert(sec_state_is_valid(type));
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100102
Vikram Kanigiri9d70f0f2014-07-15 16:46:43 +0100103 if (type == NON_SECURE)
104 return &bl33_image_ep_info;
105 else
106 return &bl32_image_ep_info;
Vikram Kanigiri96377452014-04-24 11:02:16 +0100107#else
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100108 entry_point_info_t *next_image_info;
109
Juan Castillof558cac2014-06-05 09:45:36 +0100110 assert(sec_state_is_valid(type));
111
Vikram Kanigiri96377452014-04-24 11:02:16 +0100112 next_image_info = (type == NON_SECURE) ?
Vikram Kanigirida567432014-04-15 18:08:08 +0100113 bl2_to_bl31_params->bl33_ep_info :
114 bl2_to_bl31_params->bl32_ep_info;
Achin Gupta35ca3512014-02-19 17:58:33 +0000115
116 /* None of the images on this platform can have 0x0 as the entrypoint */
Vikram Kanigirida567432014-04-15 18:08:08 +0100117 if (next_image_info->pc)
Achin Gupta35ca3512014-02-19 17:58:33 +0000118 return next_image_info;
119 else
120 return NULL;
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100121#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122}
123
124/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +0000125 * Perform any BL31 specific platform actions. Here is an opportunity to copy
126 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
127 * are lost (potentially). This needs to be done before the MMU is initialized
128 * so that the memory layout can be used while creating page tables. On the FVP
129 * we know that BL2 has populated the parameters in secure DRAM. So we just use
130 * the reference passed in 'from_bl2' instead of copying. The 'data' parameter
131 * is not used since all the information is contained in 'from_bl2'. Also, BL2
132 * has flushed this information to memory, so we are guaranteed to pick up good
133 * data
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134 ******************************************************************************/
Vikram Kanigirida567432014-04-15 18:08:08 +0100135void bl31_early_platform_setup(bl31_params_t *from_bl2,
Vikram Kanigirid8c9d262014-05-16 18:48:12 +0100136 void *plat_params_from_bl2)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100137{
Vikram Kanigiri3684abf2014-03-27 14:33:15 +0000138 /* Initialize the console to provide early debug support */
Soby Mathew69817f72014-07-14 15:43:21 +0100139 console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE);
Vikram Kanigiri3684abf2014-03-27 14:33:15 +0000140
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141 /* Initialize the platform config for future decision making */
Dan Handleyea451572014-05-15 14:53:30 +0100142 fvp_config_setup();
Vikram Kanigiri96377452014-04-24 11:02:16 +0100143
144#if RESET_TO_BL31
145 /* There are no parameters from BL2 if BL31 is a reset vector */
146 assert(from_bl2 == NULL);
147 assert(plat_params_from_bl2 == NULL);
148
Vikram Kanigiri96377452014-04-24 11:02:16 +0100149 /*
150 * Do initial security configuration to allow DRAM/device access. On
151 * Base FVP only DRAM security is programmable (via TrustZone), but
152 * other platforms might have more programmable security devices
153 * present.
154 */
Dan Handleyea451572014-05-15 14:53:30 +0100155 fvp_security_setup();
Vikram Kanigiri9d70f0f2014-07-15 16:46:43 +0100156
157 /* Populate entry point information for BL3-2 and BL3-3 */
158 SET_PARAM_HEAD(&bl32_image_ep_info,
159 PARAM_EP,
160 VERSION_1,
161 0);
162 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
163 bl32_image_ep_info.pc = BL32_BASE;
164 bl32_image_ep_info.spsr = fvp_get_spsr_for_bl32_entry();
165
166 SET_PARAM_HEAD(&bl33_image_ep_info,
167 PARAM_EP,
168 VERSION_1,
169 0);
170 /*
171 * Tell BL31 where the non-trusted software image
172 * is located and the entry state information
173 */
174 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
175 bl33_image_ep_info.spsr = fvp_get_spsr_for_bl33_entry();
176 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
177
Vikram Kanigiri96377452014-04-24 11:02:16 +0100178#else
179 /* Check params passed from BL2 should not be NULL,
180 * We are not checking plat_params_from_bl2 as NULL as we are not
181 * using it on FVP
182 */
183 assert(from_bl2 != NULL);
184 assert(from_bl2->h.type == PARAM_BL31);
185 assert(from_bl2->h.version >= VERSION_1);
186
187 bl2_to_bl31_params = from_bl2;
Andrew Thoelkea55566d2014-05-28 22:22:55 +0100188 assert(((unsigned long)plat_params_from_bl2) == FVP_BL31_PLAT_PARAM_VAL);
Vikram Kanigiri96377452014-04-24 11:02:16 +0100189#endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100190}
191
192/*******************************************************************************
193 * Initialize the gic, configure the CLCD and zero out variables needed by the
194 * secondaries to boot up correctly.
195 ******************************************************************************/
Juan Castillo2d552402014-06-13 17:05:10 +0100196void bl31_platform_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100197{
198 unsigned int reg_val;
199
Ian Spray84687392014-01-02 16:57:12 +0000200 /* Initialize the gic cpu and distributor interfaces */
Dan Handleyfb42b122014-06-20 09:43:15 +0100201 fvp_gic_init();
202 arm_gic_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100203
204 /*
205 * TODO: Configure the CLCD before handing control to
206 * linux. Need to see if a separate driver is needed
207 * instead.
208 */
209 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGDATA, 0);
210 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
211 (1ull << 31) | (1 << 30) | (7 << 20) | (0 << 16));
212
Sandrine Bailleux3fa98472014-03-31 11:25:18 +0100213 /* Enable and initialize the System level generic timer */
214 mmio_write_32(SYS_CNTCTL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN);
215
Achin Gupta4f6ad662013-10-25 09:08:21 +0100216 /* Allow access to the System counter timer module */
217 reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT);
218 reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT);
219 reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT);
220 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(0), reg_val);
221 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val);
222
223 reg_val = (1 << CNTNSAR_NS_SHIFT(0)) | (1 << CNTNSAR_NS_SHIFT(1));
224 mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val);
225
226 /* Intialize the power controller */
227 fvp_pwrc_setup();
228
Ian Spray84687392014-01-02 16:57:12 +0000229 /* Topologies are best known to the platform. */
Dan Handleyea451572014-05-15 14:53:30 +0100230 fvp_setup_topology();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100231}
232
233/*******************************************************************************
234 * Perform the very early platform specific architectural setup here. At the
235 * moment this is only intializes the mmu in a quick and dirty way.
236 ******************************************************************************/
Juan Castillo2d552402014-06-13 17:05:10 +0100237void bl31_plat_arch_setup(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100238{
Dan Handleybe234f92014-08-04 16:11:15 +0100239 fvp_cci_init();
Vikram Kanigiri96377452014-04-24 11:02:16 +0100240#if RESET_TO_BL31
Dan Handleybe234f92014-08-04 16:11:15 +0100241 fvp_cci_enable();
Dan Handleyea451572014-05-15 14:53:30 +0100242#endif
243 fvp_configure_mmu_el3(BL31_RO_BASE,
Soby Mathew2ae20432015-01-08 18:02:44 +0000244 (BL31_END - BL31_RO_BASE),
Dan Handleyea451572014-05-15 14:53:30 +0100245 BL31_RO_BASE,
Soby Mathew2ae20432015-01-08 18:02:44 +0000246 BL31_RO_LIMIT
247#if USE_COHERENT_MEM
248 , BL31_COHERENT_RAM_BASE,
249 BL31_COHERENT_RAM_LIMIT
250#endif
251 );
Achin Gupta4f6ad662013-10-25 09:08:21 +0100252}