blob: 019b8e1c332634ad8c19d30b32935cb380f47edb [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 <platform.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010032#include <fvp_pwrc.h>
Achin Guptae4d084e2014-02-19 17:18:23 +000033#include <bl_common.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010034
35/*******************************************************************************
36 * Declarations of linker defined symbols which will help us find the layout
37 * of trusted SRAM
38 ******************************************************************************/
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000039extern unsigned long __RO_START__;
40extern unsigned long __RO_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000042extern unsigned long __COHERENT_RAM_START__;
43extern unsigned long __COHERENT_RAM_END__;
Achin Gupta4f6ad662013-10-25 09:08:21 +010044
Sandrine Bailleux8d69a032013-11-27 09:38:52 +000045/*
46 * The next 2 constants identify the extents of the code & RO data region.
47 * These addresses are used by the MMU setup code and therefore they must be
48 * page-aligned. It is the responsibility of the linker script to ensure that
49 * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses.
50 */
51#define BL31_RO_BASE (unsigned long)(&__RO_START__)
52#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
53
54/*
55 * The next 2 constants identify the extents of the coherent memory region.
56 * These addresses are used by the MMU setup code and therefore they must be
57 * page-aligned. It is the responsibility of the linker script to ensure that
58 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols
59 * refer to page-aligned addresses.
60 */
61#define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
62#define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
Achin Gupta4f6ad662013-10-25 09:08:21 +010063
64/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +000065 * Reference to structure which holds the arguments that have been passed to
66 * BL31 from BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +010067 ******************************************************************************/
Achin Guptae4d084e2014-02-19 17:18:23 +000068static bl31_args *bl2_to_bl31_args;
Achin Gupta4f6ad662013-10-25 09:08:21 +010069
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +000070meminfo *bl31_plat_sec_mem_layout(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010071{
Achin Guptae4d084e2014-02-19 17:18:23 +000072 return &bl2_to_bl31_args->bl31_meminfo;
Achin Gupta4f6ad662013-10-25 09:08:21 +010073}
74
75/*******************************************************************************
76 * Return information about passing control to the non-trusted software images
77 * to common code.TODO: In the initial architecture, the image after BL31 will
78 * always run in the non-secure state. In the final architecture there
79 * will be a series of images. This function will need enhancement then
80 ******************************************************************************/
Sandrine Bailleux93ca2212013-12-02 15:57:09 +000081el_change_info *bl31_get_next_image_info(void)
Achin Gupta4f6ad662013-10-25 09:08:21 +010082{
Achin Guptae4d084e2014-02-19 17:18:23 +000083 return &bl2_to_bl31_args->bl33_image_info;
Achin Gupta4f6ad662013-10-25 09:08:21 +010084}
85
86/*******************************************************************************
Achin Guptae4d084e2014-02-19 17:18:23 +000087 * Perform any BL31 specific platform actions. Here is an opportunity to copy
88 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
89 * are lost (potentially). This needs to be done before the MMU is initialized
90 * so that the memory layout can be used while creating page tables. On the FVP
91 * we know that BL2 has populated the parameters in secure DRAM. So we just use
92 * the reference passed in 'from_bl2' instead of copying. The 'data' parameter
93 * is not used since all the information is contained in 'from_bl2'. Also, BL2
94 * has flushed this information to memory, so we are guaranteed to pick up good
95 * data
Achin Gupta4f6ad662013-10-25 09:08:21 +010096 ******************************************************************************/
Achin Guptae4d084e2014-02-19 17:18:23 +000097void bl31_early_platform_setup(bl31_args *from_bl2,
Sandrine Bailleux93ca2212013-12-02 15:57:09 +000098 void *data)
Achin Gupta4f6ad662013-10-25 09:08:21 +010099{
Achin Guptae4d084e2014-02-19 17:18:23 +0000100 bl2_to_bl31_args = from_bl2;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100101
102 /* Initialize the platform config for future decision making */
103 platform_config_setup();
104}
105
106/*******************************************************************************
107 * Initialize the gic, configure the CLCD and zero out variables needed by the
108 * secondaries to boot up correctly.
109 ******************************************************************************/
110void bl31_platform_setup()
111{
112 unsigned int reg_val;
113
Ian Spray84687392014-01-02 16:57:12 +0000114 /* Initialize the gic cpu and distributor interfaces */
115 gic_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +0100116
117 /*
118 * TODO: Configure the CLCD before handing control to
119 * linux. Need to see if a separate driver is needed
120 * instead.
121 */
122 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGDATA, 0);
123 mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL,
124 (1ull << 31) | (1 << 30) | (7 << 20) | (0 << 16));
125
126 /* Allow access to the System counter timer module */
127 reg_val = (1 << CNTACR_RPCT_SHIFT) | (1 << CNTACR_RVCT_SHIFT);
128 reg_val |= (1 << CNTACR_RFRQ_SHIFT) | (1 << CNTACR_RVOFF_SHIFT);
129 reg_val |= (1 << CNTACR_RWVT_SHIFT) | (1 << CNTACR_RWPT_SHIFT);
130 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(0), reg_val);
131 mmio_write_32(SYS_TIMCTL_BASE + CNTACR_BASE(1), reg_val);
132
133 reg_val = (1 << CNTNSAR_NS_SHIFT(0)) | (1 << CNTNSAR_NS_SHIFT(1));
134 mmio_write_32(SYS_TIMCTL_BASE + CNTNSAR, reg_val);
135
136 /* Intialize the power controller */
137 fvp_pwrc_setup();
138
Ian Spray84687392014-01-02 16:57:12 +0000139 /* Topologies are best known to the platform. */
Achin Gupta4f6ad662013-10-25 09:08:21 +0100140 plat_setup_topology();
141}
142
143/*******************************************************************************
144 * Perform the very early platform specific architectural setup here. At the
145 * moment this is only intializes the mmu in a quick and dirty way.
146 ******************************************************************************/
147void bl31_plat_arch_setup()
148{
Achin Guptae4d084e2014-02-19 17:18:23 +0000149 configure_mmu(&bl2_to_bl31_args->bl31_meminfo,
Sandrine Bailleux8d69a032013-11-27 09:38:52 +0000150 BL31_RO_BASE,
151 BL31_RO_LIMIT,
152 BL31_COHERENT_RAM_BASE,
153 BL31_COHERENT_RAM_LIMIT);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100154}