blob: f344b3752b1569ec03aefc4c21c5ed0fbf2227a9 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include <arch.h>
9#include <arch_helpers.h>
10#include <bl_common.h>
11#include <debug.h>
12#include <gicv2.h>
13#include <gic_common.h>
14#include <interrupt_props.h>
15#include <mmio.h>
16#include <platform.h>
17#include <platform_def.h>
18#include <xlat_tables_v2.h>
19#include "rcar_def.h"
20#include "rcar_private.h"
21#include "rcar_version.h"
22
23#if (IMAGE_BL2)
24extern void rcar_read_certificate(uint64_t cert, uint32_t *len, uintptr_t *p);
25extern int32_t rcar_get_certificate(const int32_t name, uint32_t *cert);
26#endif
27
28const uint8_t version_of_renesas[VERSION_OF_RENESAS_MAXLEN]
29 __attribute__ ((__section__("ro"))) = VERSION_OF_RENESAS;
30
31#define MAP_SHARED_RAM MAP_REGION_FLAT(RCAR_SHARED_MEM_BASE, \
32 RCAR_SHARED_MEM_SIZE, \
33 MT_MEMORY | MT_RW | MT_SECURE)
34
35#define MAP_FLASH0 MAP_REGION_FLAT(FLASH0_BASE, \
36 FLASH0_SIZE, \
37 MT_MEMORY | MT_RO | MT_SECURE)
38
39#define MAP_DRAM1_NS MAP_REGION_FLAT(DRAM1_NS_BASE, \
40 DRAM1_NS_SIZE, \
41 MT_MEMORY | MT_RW | MT_NS)
42
43#define MAP_DEVICE_RCAR MAP_REGION_FLAT(DEVICE_RCAR_BASE, \
44 DEVICE_RCAR_SIZE, \
45 MT_DEVICE | MT_RW | MT_SECURE)
46
47#define MAP_DEVICE_RCAR2 MAP_REGION_FLAT(DEVICE_RCAR_BASE2, \
48 DEVICE_RCAR_SIZE2, \
49 MT_DEVICE | MT_RW | MT_SECURE)
50
51#define MAP_SRAM MAP_REGION_FLAT(DEVICE_SRAM_BASE, \
52 DEVICE_SRAM_SIZE, \
53 MT_MEMORY | MT_RO | MT_SECURE)
54
55#define MAP_SRAM_STACK MAP_REGION_FLAT(DEVICE_SRAM_STACK_BASE, \
56 DEVICE_SRAM_STACK_SIZE, \
57 MT_MEMORY | MT_RW | MT_SECURE)
58
59#define MAP_ATFW_CRASH MAP_REGION_FLAT(RCAR_BL31_CRASH_BASE, \
60 RCAR_BL31_CRASH_SIZE, \
61 MT_MEMORY | MT_RW | MT_SECURE)
62
63#define MAP_ATFW_LOG MAP_REGION_FLAT(RCAR_BL31_LOG_BASE, \
64 RCAR_BL31_LOG_SIZE, \
65 MT_DEVICE | MT_RW | MT_SECURE)
66#if IMAGE_BL2
67#define MAP_DRAM0 MAP_REGION_FLAT(DRAM1_BASE, \
68 DRAM1_SIZE, \
69 MT_MEMORY | MT_RW | MT_SECURE)
70
71#define MAP_REG0 MAP_REGION_FLAT(DEVICE_RCAR_BASE, \
72 DEVICE_RCAR_SIZE, \
73 MT_DEVICE | MT_RW | MT_SECURE)
74
75#define MAP_RAM0 MAP_REGION_FLAT(RCAR_SYSRAM_BASE, \
76 RCAR_SYSRAM_SIZE, \
77 MT_MEMORY | MT_RW | MT_SECURE)
78
79#define MAP_REG1 MAP_REGION_FLAT(REG1_BASE, \
80 REG1_SIZE, \
81 MT_DEVICE | MT_RW | MT_SECURE)
82
83#define MAP_ROM MAP_REGION_FLAT(ROM0_BASE, \
84 ROM0_SIZE, \
85 MT_MEMORY | MT_RO | MT_SECURE)
86
87#define MAP_REG2 MAP_REGION_FLAT(REG2_BASE, \
88 REG2_SIZE, \
89 MT_DEVICE | MT_RW | MT_SECURE)
90
91#define MAP_DRAM1 MAP_REGION_FLAT(DRAM_40BIT_BASE, \
92 DRAM_40BIT_SIZE, \
93 MT_MEMORY | MT_RW | MT_SECURE)
94#endif
95
96#ifdef BL32_BASE
97#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_BASE, \
98 BL32_LIMIT - BL32_BASE, \
99 MT_MEMORY | MT_RW | MT_SECURE)
100#endif
101
102#if IMAGE_BL2
103const mmap_region_t rcar_mmap[] = {
104 MAP_FLASH0, /* 0x08000000 - 0x0BFFFFFF RPC area */
105 MAP_DRAM0, /* 0x40000000 - 0xBFFFFFFF DRAM area(Legacy) */
106 MAP_REG0, /* 0xE6000000 - 0xE62FFFFF SoC register area */
107 MAP_RAM0, /* 0xE6300000 - 0xE6303FFF System RAM area */
108 MAP_REG1, /* 0xE6400000 - 0xEAFFFFFF SoC register area */
109 MAP_ROM, /* 0xEB100000 - 0xEB127FFF boot ROM area */
110 MAP_REG2, /* 0xEC000000 - 0xFFFFFFFF SoC register area */
111 MAP_DRAM1, /* 0x0400000000 - 0x07FFFFFFFF DRAM area(4GB over) */
112 {0}
113};
114#endif
115
116#if IMAGE_BL31
117const mmap_region_t rcar_mmap[] = {
118 MAP_SHARED_RAM,
119 MAP_ATFW_CRASH,
120 MAP_ATFW_LOG,
121 MAP_DEVICE_RCAR,
122 MAP_DEVICE_RCAR2,
123 MAP_SRAM,
124 MAP_SRAM_STACK,
125 {0}
126};
127#endif
128
129#if IMAGE_BL32
130const mmap_region_t rcar_mmap[] = {
131 MAP_DEVICE0,
132 MAP_DEVICE1,
133 {0}
134};
135#endif
136
137CASSERT(ARRAY_SIZE(rcar_mmap) + RCAR_BL_REGIONS
138 <= MAX_MMAP_REGIONS, assert_max_mmap_regions);
139
140/*
141 * Macro generating the code for the function setting up the pagetables as per
142 * the platform memory map & initialize the mmu, for the given exception level
143 */
144#if USE_COHERENT_MEM
145void rcar_configure_mmu_el3(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, total_size,
153 MT_MEMORY | MT_RW | MT_SECURE);
154 mmap_add_region(ro_start, ro_start, ro_limit - ro_start,
155 MT_MEMORY | MT_RO | MT_SECURE);
156 mmap_add_region(coh_start, coh_start, coh_limit - coh_start,
157 MT_DEVICE | MT_RW | MT_SECURE);
158 mmap_add(rcar_mmap);
159
160 init_xlat_tables();
161 enable_mmu_el3(0);
162}
163#else
164void rcar_configure_mmu_el3(unsigned long total_base,
165 unsigned long total_size,
166 unsigned long ro_start,
167 unsigned long ro_limit)
168{
169 mmap_add_region(total_base, total_base, total_size,
170 MT_MEMORY | MT_RW | MT_SECURE);
171 mmap_add_region(ro_start, ro_start, ro_limit - ro_start,
172 MT_MEMORY | MT_RO | MT_SECURE);
173 mmap_add(rcar_mmap);
174
175 init_xlat_tables();
176 enable_mmu_el3(0);
177}
178#endif
179
180uintptr_t plat_get_ns_image_entrypoint(void)
181{
182#if (IMAGE_BL2)
183 uint32_t cert, len;
184 uintptr_t dst;
185 int32_t ret;
186
187 ret = rcar_get_certificate(NON_TRUSTED_FW_CONTENT_CERT_ID, &cert);
188 if (ret) {
189 ERROR("%s : cert file load error", __func__);
190 return NS_IMAGE_OFFSET;
191 }
192
193 rcar_read_certificate((uint64_t) cert, &len, &dst);
194
195 return dst;
196#else
197 return NS_IMAGE_OFFSET;
198#endif
199}
200
201unsigned int plat_get_syscnt_freq2(void)
202{
203 unsigned int freq;
204
205 freq = mmio_read_32(ARM_SYS_CNTCTL_BASE + CNTFID_OFF);
206 if (freq == 0)
207 panic();
208
209 return freq;
210}
211
212void plat_rcar_gic_init(void)
213{
214 gicv2_distif_init();
215 gicv2_pcpu_distif_init();
216 gicv2_cpuif_enable();
217}
218
219static const interrupt_prop_t interrupt_props[] = {
220#if IMAGE_BL2
221 INTR_PROP_DESC(ARM_IRQ_SEC_WDT, GIC_HIGHEST_SEC_PRIORITY,
222 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
223#else
224 INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
225 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
226 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
227 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
228 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY,
229 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
230 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY,
231 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
232 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY,
233 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
234 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY,
235 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
236 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY,
237 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
238 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY,
239 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
240 INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY,
241 GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
242 INTR_PROP_DESC(ARM_IRQ_SEC_RPC, GIC_HIGHEST_SEC_PRIORITY,
243 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
244 INTR_PROP_DESC(ARM_IRQ_SEC_TIMER, GIC_HIGHEST_SEC_PRIORITY,
245 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
246 INTR_PROP_DESC(ARM_IRQ_SEC_TIMER_UP, GIC_HIGHEST_SEC_PRIORITY,
247 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
248 INTR_PROP_DESC(ARM_IRQ_SEC_WDT, GIC_HIGHEST_SEC_PRIORITY,
249 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
250 INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT, GIC_HIGHEST_SEC_PRIORITY,
251 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
252 INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT_SecPKA, GIC_HIGHEST_SEC_PRIORITY,
253 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
254 INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT_PubPKA, GIC_HIGHEST_SEC_PRIORITY,
255 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
256#endif
257};
258
259static const gicv2_driver_data_t plat_gicv2_driver_data = {
260 .interrupt_props = interrupt_props,
261 .interrupt_props_num = (uint32_t) ARRAY_SIZE(interrupt_props),
262 .gicd_base = RCAR_GICD_BASE,
263 .gicc_base = RCAR_GICC_BASE,
264};
265
266void plat_rcar_gic_driver_init(void)
267{
268 gicv2_driver_init(&plat_gicv2_driver_data);
269}