blob: 7ad40d0da9f64be3b38436a04802a4d25e14097f [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>
35#include <debug.h>
36#include <mmio.h>
37#include <platform.h>
38#include <platform_def.h>
39#include <xlat_tables.h>
40#include "../juno_def.h"
41
Soby Mathewb08bc042014-09-03 17:48:44 +010042#define MAP_MHU_SECURE MAP_REGION_FLAT(MHU_SECURE_BASE, \
43 MHU_SECURE_SIZE, \
44 (MHU_PAYLOAD_CACHED ? \
45 MT_MEMORY : MT_DEVICE) \
46 | MT_RW | MT_SECURE)
47
48#define MAP_FLASH MAP_REGION_FLAT(FLASH_BASE, \
49 FLASH_SIZE, \
50 MT_MEMORY | MT_RO | MT_SECURE)
51
52#define MAP_IOFPGA MAP_REGION_FLAT(IOFPGA_BASE, \
53 IOFPGA_SIZE, \
54 MT_DEVICE | MT_RW | MT_SECURE)
55
56#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
57 DEVICE0_SIZE, \
58 MT_DEVICE | MT_RW | MT_SECURE)
59
60#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
61 DEVICE1_SIZE, \
62 MT_DEVICE | MT_RW | MT_SECURE)
63
Juan Castillo921b8772014-09-05 17:29:38 +010064#define MAP_NS_DRAM MAP_REGION_FLAT(DRAM_NS_BASE, \
65 DRAM_NS_SIZE, \
Soby Mathewb08bc042014-09-03 17:48:44 +010066 MT_MEMORY | MT_RW | MT_NS)
Juan Castillo921b8772014-09-05 17:29:38 +010067
68#define MAP_TSP_MEM MAP_REGION_FLAT(TSP_SEC_MEM_BASE, \
69 TSP_SEC_MEM_SIZE, \
70 MT_MEMORY | MT_RW | MT_SECURE)
71
Sandrine Bailleux798140d2014-07-17 16:06:39 +010072/*
Soby Mathewb08bc042014-09-03 17:48:44 +010073 * Table of regions for different BL stages to map using the MMU.
Sandrine Bailleux798140d2014-07-17 16:06:39 +010074 * This doesn't include Trusted RAM as the 'mem_layout' argument passed to
75 * configure_mmu_elx() will give the available subset of that,
76 */
Soby Mathewb08bc042014-09-03 17:48:44 +010077#if IMAGE_BL1
Sandrine Bailleux798140d2014-07-17 16:06:39 +010078static const mmap_region_t juno_mmap[] = {
Soby Mathewb08bc042014-09-03 17:48:44 +010079 MAP_MHU_SECURE,
80 MAP_FLASH,
81 MAP_IOFPGA,
82 MAP_DEVICE0,
83 MAP_DEVICE1,
Sandrine Bailleux798140d2014-07-17 16:06:39 +010084 {0}
85};
Soby Mathewb08bc042014-09-03 17:48:44 +010086#endif
87#if IMAGE_BL2
88static const mmap_region_t juno_mmap[] = {
89 MAP_MHU_SECURE,
90 MAP_FLASH,
91 MAP_IOFPGA,
92 MAP_DEVICE0,
93 MAP_DEVICE1,
Juan Castillo921b8772014-09-05 17:29:38 +010094 MAP_NS_DRAM,
95 MAP_TSP_MEM,
Soby Mathewb08bc042014-09-03 17:48:44 +010096 {0}
97};
98#endif
99#if IMAGE_BL31
100static const mmap_region_t juno_mmap[] = {
101 MAP_MHU_SECURE,
102 MAP_IOFPGA,
103 MAP_DEVICE0,
104 MAP_DEVICE1,
105 {0}
106};
107#endif
108#if IMAGE_BL32
109static const mmap_region_t juno_mmap[] = {
110 MAP_IOFPGA,
111 MAP_DEVICE0,
112 MAP_DEVICE1,
113 {0}
114};
115#endif
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100116
Juan Castillob3286c02014-10-20 12:29:58 +0100117/* Array of secure interrupts to be configured by the gic driver */
118const unsigned int irq_sec_array[] = {
119 IRQ_MHU,
120 IRQ_GPU_SMMU_0,
121 IRQ_GPU_SMMU_1,
122 IRQ_ETR_SMMU,
123 IRQ_TZC400,
124 IRQ_TZ_WDOG,
125 IRQ_SEC_PHY_TIMER,
126 IRQ_SEC_SGI_0,
127 IRQ_SEC_SGI_1,
128 IRQ_SEC_SGI_2,
129 IRQ_SEC_SGI_3,
130 IRQ_SEC_SGI_4,
131 IRQ_SEC_SGI_5,
132 IRQ_SEC_SGI_6,
133 IRQ_SEC_SGI_7
134};
135
136const unsigned int num_sec_irqs = sizeof(irq_sec_array) /
137 sizeof(irq_sec_array[0]);
138
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100139/*******************************************************************************
140 * Macro generating the code for the function setting up the pagetables as per
141 * the platform memory map & initialize the mmu, for the given exception level
142 ******************************************************************************/
Soby Mathew2ae20432015-01-08 18:02:44 +0000143#if USE_COHERENT_MEM
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100144#define DEFINE_CONFIGURE_MMU_EL(_el) \
145 void configure_mmu_el##_el(unsigned long total_base, \
146 unsigned long total_size, \
147 unsigned long ro_start, \
148 unsigned long ro_limit, \
149 unsigned long coh_start, \
150 unsigned long coh_limit) \
151 { \
152 mmap_add_region(total_base, total_base, \
153 total_size, \
154 MT_MEMORY | MT_RW | MT_SECURE); \
155 mmap_add_region(ro_start, ro_start, \
156 ro_limit - ro_start, \
157 MT_MEMORY | MT_RO | MT_SECURE); \
158 mmap_add_region(coh_start, coh_start, \
159 coh_limit - coh_start, \
160 MT_DEVICE | MT_RW | MT_SECURE); \
161 mmap_add(juno_mmap); \
162 init_xlat_tables(); \
163 \
164 enable_mmu_el##_el(0); \
165 }
Soby Mathew2ae20432015-01-08 18:02:44 +0000166#else
167#define DEFINE_CONFIGURE_MMU_EL(_el) \
168 void configure_mmu_el##_el(unsigned long total_base, \
169 unsigned long total_size, \
170 unsigned long ro_start, \
171 unsigned long ro_limit) \
172 { \
173 mmap_add_region(total_base, total_base, \
174 total_size, \
175 MT_MEMORY | MT_RW | MT_SECURE); \
176 mmap_add_region(ro_start, ro_start, \
177 ro_limit - ro_start, \
178 MT_MEMORY | MT_RO | MT_SECURE); \
179 mmap_add(juno_mmap); \
180 init_xlat_tables(); \
181 \
182 enable_mmu_el##_el(0); \
183 }
184#endif
Sandrine Bailleux798140d2014-07-17 16:06:39 +0100185/* Define EL1 and EL3 variants of the function initialising the MMU */
186DEFINE_CONFIGURE_MMU_EL(1)
187DEFINE_CONFIGURE_MMU_EL(3)
188
189
190unsigned long plat_get_ns_image_entrypoint(void)
191{
192 return NS_IMAGE_OFFSET;
193}
194
195uint64_t plat_get_syscnt_freq(void)
196{
197 uint64_t counter_base_frequency;
198
199 /* Read the frequency from Frequency modes table */
200 counter_base_frequency = mmio_read_32(SYS_CNTCTL_BASE + CNTFID_OFF);
201
202 /* The first entry of the frequency modes table must not be 0 */
203 if (counter_base_frequency == 0)
204 panic();
205
206 return counter_base_frequency;
207}
Juan Castillob3286c02014-10-20 12:29:58 +0100208
209void plat_gic_init(void)
210{
211 arm_gic_init(GICC_BASE, GICD_BASE, 0, irq_sec_array, num_sec_irqs);
212}