blob: 6b6e185178e12da8fc44766ed4d4d505999ba7f3 [file] [log] [blame]
Sandrine Bailleux798140d2014-07-17 16:06:39 +01001/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 *
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 <arch_helpers.h>
Juan Castillob3286c02014-10-20 12:29:58 +010032#include <arm_gic.h>
Sandrine Bailleux798140d2014-07-17 16:06:39 +010033#include <assert.h>
34#include <bl_common.h>
Vikram Kanigiri4e97e542015-02-26 15:25:58 +000035#include <cci.h>
Sandrine Bailleux798140d2014-07-17 16:06:39 +010036#include <debug.h>
37#include <mmio.h>
38#include <platform.h>
39#include <platform_def.h>
40#include <xlat_tables.h>
41#include "../juno_def.h"
42
Soby Mathewb08bc042014-09-03 17:48:44 +010043#define MAP_MHU_SECURE MAP_REGION_FLAT(MHU_SECURE_BASE, \
44 MHU_SECURE_SIZE, \
45 (MHU_PAYLOAD_CACHED ? \
46 MT_MEMORY : MT_DEVICE) \
47 | MT_RW | MT_SECURE)
48
49#define MAP_FLASH MAP_REGION_FLAT(FLASH_BASE, \
50 FLASH_SIZE, \
51 MT_MEMORY | MT_RO | MT_SECURE)
52
53#define MAP_IOFPGA MAP_REGION_FLAT(IOFPGA_BASE, \
54 IOFPGA_SIZE, \
55 MT_DEVICE | MT_RW | MT_SECURE)
56
57#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
58 DEVICE0_SIZE, \
59 MT_DEVICE | MT_RW | MT_SECURE)
60
61#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
62 DEVICE1_SIZE, \
63 MT_DEVICE | MT_RW | MT_SECURE)
64
Juan Castillo921b8772014-09-05 17:29:38 +010065#define MAP_NS_DRAM MAP_REGION_FLAT(DRAM_NS_BASE, \
66 DRAM_NS_SIZE, \
Soby Mathewb08bc042014-09-03 17:48:44 +010067 MT_MEMORY | MT_RW | MT_NS)
Juan Castillo921b8772014-09-05 17:29:38 +010068
69#define MAP_TSP_MEM MAP_REGION_FLAT(TSP_SEC_MEM_BASE, \
70 TSP_SEC_MEM_SIZE, \
71 MT_MEMORY | MT_RW | MT_SECURE)
72
Sandrine Bailleux798140d2014-07-17 16:06:39 +010073/*
Soby Mathewb08bc042014-09-03 17:48:44 +010074 * Table of regions for different BL stages to map using the MMU.
Sandrine Bailleux798140d2014-07-17 16:06:39 +010075 * This doesn't include Trusted RAM as the 'mem_layout' argument passed to
76 * configure_mmu_elx() will give the available subset of that,
77 */
Soby Mathewb08bc042014-09-03 17:48:44 +010078#if IMAGE_BL1
Sandrine Bailleux798140d2014-07-17 16:06:39 +010079static const mmap_region_t juno_mmap[] = {
Soby Mathewb08bc042014-09-03 17:48:44 +010080 MAP_MHU_SECURE,
81 MAP_FLASH,
82 MAP_IOFPGA,
83 MAP_DEVICE0,
84 MAP_DEVICE1,
Sandrine Bailleux798140d2014-07-17 16:06:39 +010085 {0}
86};
Soby Mathewb08bc042014-09-03 17:48:44 +010087#endif
88#if IMAGE_BL2
89static const mmap_region_t juno_mmap[] = {
90 MAP_MHU_SECURE,
91 MAP_FLASH,
92 MAP_IOFPGA,
93 MAP_DEVICE0,
94 MAP_DEVICE1,
Juan Castillo921b8772014-09-05 17:29:38 +010095 MAP_NS_DRAM,
96 MAP_TSP_MEM,
Soby Mathewb08bc042014-09-03 17:48:44 +010097 {0}
98};
99#endif
100#if IMAGE_BL31
101static const mmap_region_t juno_mmap[] = {
102 MAP_MHU_SECURE,
103 MAP_IOFPGA,
104 MAP_DEVICE0,
105 MAP_DEVICE1,
106 {0}
107};
108#endif
109#if IMAGE_BL32
110static const mmap_region_t juno_mmap[] = {
111 MAP_IOFPGA,
112 MAP_DEVICE0,
113 MAP_DEVICE1,
114 {0}
115};
116#endif
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100117
Vikram Kanigiri725b1332015-03-04 10:34:27 +0000118CASSERT(ARRAY_SIZE(juno_mmap) + JUNO_BL_REGIONS \
Soby Mathew13ee9682015-01-22 11:22:22 +0000119 <= MAX_MMAP_REGIONS, assert_max_mmap_regions);
120
Juan Castillob3286c02014-10-20 12:29:58 +0100121/* Array of secure interrupts to be configured by the gic driver */
122const unsigned int irq_sec_array[] = {
123 IRQ_MHU,
124 IRQ_GPU_SMMU_0,
125 IRQ_GPU_SMMU_1,
126 IRQ_ETR_SMMU,
127 IRQ_TZC400,
128 IRQ_TZ_WDOG,
129 IRQ_SEC_PHY_TIMER,
130 IRQ_SEC_SGI_0,
131 IRQ_SEC_SGI_1,
132 IRQ_SEC_SGI_2,
133 IRQ_SEC_SGI_3,
134 IRQ_SEC_SGI_4,
135 IRQ_SEC_SGI_5,
136 IRQ_SEC_SGI_6,
137 IRQ_SEC_SGI_7
138};
139
Vikram Kanigiri4e97e542015-02-26 15:25:58 +0000140static const int cci_map[] = {
141 CCI400_CLUSTER0_SL_IFACE_IX,
142 CCI400_CLUSTER1_SL_IFACE_IX
143};
144
145void plat_cci_init(void)
146{
147 cci_init(CCI400_BASE,
148 cci_map,
149 ARRAY_SIZE(cci_map));
150}
151
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100152/*******************************************************************************
153 * Macro generating the code for the function setting up the pagetables as per
154 * the platform memory map & initialize the mmu, for the given exception level
155 ******************************************************************************/
Soby Mathew2ae20432015-01-08 18:02:44 +0000156#if USE_COHERENT_MEM
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100157#define DEFINE_CONFIGURE_MMU_EL(_el) \
158 void configure_mmu_el##_el(unsigned long total_base, \
159 unsigned long total_size, \
160 unsigned long ro_start, \
161 unsigned long ro_limit, \
162 unsigned long coh_start, \
163 unsigned long coh_limit) \
164 { \
165 mmap_add_region(total_base, total_base, \
166 total_size, \
167 MT_MEMORY | MT_RW | MT_SECURE); \
168 mmap_add_region(ro_start, ro_start, \
169 ro_limit - ro_start, \
170 MT_MEMORY | MT_RO | MT_SECURE); \
171 mmap_add_region(coh_start, coh_start, \
172 coh_limit - coh_start, \
173 MT_DEVICE | MT_RW | MT_SECURE); \
174 mmap_add(juno_mmap); \
175 init_xlat_tables(); \
176 \
177 enable_mmu_el##_el(0); \
178 }
Soby Mathew2ae20432015-01-08 18:02:44 +0000179#else
180#define DEFINE_CONFIGURE_MMU_EL(_el) \
181 void configure_mmu_el##_el(unsigned long total_base, \
182 unsigned long total_size, \
183 unsigned long ro_start, \
184 unsigned long ro_limit) \
185 { \
186 mmap_add_region(total_base, total_base, \
187 total_size, \
188 MT_MEMORY | MT_RW | MT_SECURE); \
189 mmap_add_region(ro_start, ro_start, \
190 ro_limit - ro_start, \
191 MT_MEMORY | MT_RO | MT_SECURE); \
192 mmap_add(juno_mmap); \
193 init_xlat_tables(); \
194 \
195 enable_mmu_el##_el(0); \
196 }
197#endif
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100198/* Define EL1 and EL3 variants of the function initialising the MMU */
199DEFINE_CONFIGURE_MMU_EL(1)
200DEFINE_CONFIGURE_MMU_EL(3)
201
202
203unsigned long plat_get_ns_image_entrypoint(void)
204{
205 return NS_IMAGE_OFFSET;
206}
207
208uint64_t plat_get_syscnt_freq(void)
209{
210 uint64_t counter_base_frequency;
211
212 /* Read the frequency from Frequency modes table */
213 counter_base_frequency = mmio_read_32(SYS_CNTCTL_BASE + CNTFID_OFF);
214
215 /* The first entry of the frequency modes table must not be 0 */
216 if (counter_base_frequency == 0)
217 panic();
218
219 return counter_base_frequency;
220}
Juan Castillob3286c02014-10-20 12:29:58 +0100221
222void plat_gic_init(void)
223{
Vikram Kanigiri725b1332015-03-04 10:34:27 +0000224 arm_gic_init(GICC_BASE,
225 GICD_BASE,
226 0,
227 irq_sec_array,
228 ARRAY_SIZE(irq_sec_array));
Juan Castillob3286c02014-10-20 12:29:58 +0100229}