xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 3e4b8fdcd3794ca07135521a5fd4c3141624f17c)
1*3e4b8fdcSSoby Mathew /*
2*3e4b8fdcSSoby Mathew  * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3*3e4b8fdcSSoby Mathew  *
4*3e4b8fdcSSoby Mathew  * Redistribution and use in source and binary forms, with or without
5*3e4b8fdcSSoby Mathew  * modification, are permitted provided that the following conditions are met:
6*3e4b8fdcSSoby Mathew  *
7*3e4b8fdcSSoby Mathew  * Redistributions of source code must retain the above copyright notice, this
8*3e4b8fdcSSoby Mathew  * list of conditions and the following disclaimer.
9*3e4b8fdcSSoby Mathew  *
10*3e4b8fdcSSoby Mathew  * Redistributions in binary form must reproduce the above copyright notice,
11*3e4b8fdcSSoby Mathew  * this list of conditions and the following disclaimer in the documentation
12*3e4b8fdcSSoby Mathew  * and/or other materials provided with the distribution.
13*3e4b8fdcSSoby Mathew  *
14*3e4b8fdcSSoby Mathew  * Neither the name of ARM nor the names of its contributors may be used
15*3e4b8fdcSSoby Mathew  * to endorse or promote products derived from this software without specific
16*3e4b8fdcSSoby Mathew  * prior written permission.
17*3e4b8fdcSSoby Mathew  *
18*3e4b8fdcSSoby Mathew  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*3e4b8fdcSSoby Mathew  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*3e4b8fdcSSoby Mathew  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*3e4b8fdcSSoby Mathew  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*3e4b8fdcSSoby Mathew  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*3e4b8fdcSSoby Mathew  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*3e4b8fdcSSoby Mathew  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*3e4b8fdcSSoby Mathew  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*3e4b8fdcSSoby Mathew  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*3e4b8fdcSSoby Mathew  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*3e4b8fdcSSoby Mathew  * POSSIBILITY OF SUCH DAMAGE.
29*3e4b8fdcSSoby Mathew  */
30*3e4b8fdcSSoby Mathew 
31*3e4b8fdcSSoby Mathew #include <arm_config.h>
32*3e4b8fdcSSoby Mathew #include <arm_def.h>
33*3e4b8fdcSSoby Mathew #include <debug.h>
34*3e4b8fdcSSoby Mathew #include <gicv2.h>
35*3e4b8fdcSSoby Mathew #include <mmio.h>
36*3e4b8fdcSSoby Mathew #include <plat_arm.h>
37*3e4b8fdcSSoby Mathew #include <v2m_def.h>
38*3e4b8fdcSSoby Mathew #include "../fvp_def.h"
39*3e4b8fdcSSoby Mathew 
40*3e4b8fdcSSoby Mathew #if (FVP_USE_GIC_DRIVER == FVP_GICV2)
41*3e4b8fdcSSoby Mathew extern gicv2_driver_data_t arm_gic_data;
42*3e4b8fdcSSoby Mathew #endif
43*3e4b8fdcSSoby Mathew 
44*3e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
45*3e4b8fdcSSoby Mathew #define FVP_GICV2		1
46*3e4b8fdcSSoby Mathew #define FVP_GICV3		2
47*3e4b8fdcSSoby Mathew #define FVP_GICV3_LEGACY	3
48*3e4b8fdcSSoby Mathew 
49*3e4b8fdcSSoby Mathew /*******************************************************************************
50*3e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
51*3e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
52*3e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
53*3e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
54*3e4b8fdcSSoby Mathew  * to allow independent operation.
55*3e4b8fdcSSoby Mathew  ******************************************************************************/
56*3e4b8fdcSSoby Mathew arm_config_t arm_config;
57*3e4b8fdcSSoby Mathew 
58*3e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
59*3e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
60*3e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
61*3e4b8fdcSSoby Mathew 
62*3e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
63*3e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
64*3e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
65*3e4b8fdcSSoby Mathew 
66*3e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
67*3e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
68*3e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RO | MT_SECURE)
69*3e4b8fdcSSoby Mathew 
70*3e4b8fdcSSoby Mathew 
71*3e4b8fdcSSoby Mathew /*
72*3e4b8fdcSSoby Mathew  * Table of regions for various BL stages to map using the MMU.
73*3e4b8fdcSSoby Mathew  * This doesn't include TZRAM as the 'mem_layout' argument passed to
74*3e4b8fdcSSoby Mathew  * arm_configure_mmu_elx() will give the available subset of that,
75*3e4b8fdcSSoby Mathew  */
76*3e4b8fdcSSoby Mathew #if IMAGE_BL1
77*3e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
78*3e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
79*3e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
80*3e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
81*3e4b8fdcSSoby Mathew 	MAP_DEVICE0,
82*3e4b8fdcSSoby Mathew 	MAP_DEVICE1,
83*3e4b8fdcSSoby Mathew 	MAP_DEVICE2,
84*3e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
85*3e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
86*3e4b8fdcSSoby Mathew #endif
87*3e4b8fdcSSoby Mathew 	{0}
88*3e4b8fdcSSoby Mathew };
89*3e4b8fdcSSoby Mathew #endif
90*3e4b8fdcSSoby Mathew #if IMAGE_BL2
91*3e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
92*3e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
93*3e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
94*3e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
95*3e4b8fdcSSoby Mathew 	MAP_DEVICE0,
96*3e4b8fdcSSoby Mathew 	MAP_DEVICE1,
97*3e4b8fdcSSoby Mathew 	MAP_DEVICE2,
98*3e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
99*3e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
100*3e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
101*3e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
102*3e4b8fdcSSoby Mathew #endif
103*3e4b8fdcSSoby Mathew 	{0}
104*3e4b8fdcSSoby Mathew };
105*3e4b8fdcSSoby Mathew #endif
106*3e4b8fdcSSoby Mathew #if IMAGE_BL2U
107*3e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
108*3e4b8fdcSSoby Mathew 	MAP_DEVICE0,
109*3e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
110*3e4b8fdcSSoby Mathew 	{0}
111*3e4b8fdcSSoby Mathew };
112*3e4b8fdcSSoby Mathew #endif
113*3e4b8fdcSSoby Mathew #if IMAGE_BL31
114*3e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
115*3e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
116*3e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
117*3e4b8fdcSSoby Mathew 	MAP_DEVICE0,
118*3e4b8fdcSSoby Mathew 	MAP_DEVICE1,
119*3e4b8fdcSSoby Mathew 	{0}
120*3e4b8fdcSSoby Mathew };
121*3e4b8fdcSSoby Mathew #endif
122*3e4b8fdcSSoby Mathew #if IMAGE_BL32
123*3e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
124*3e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
125*3e4b8fdcSSoby Mathew 	MAP_DEVICE0,
126*3e4b8fdcSSoby Mathew 	MAP_DEVICE1,
127*3e4b8fdcSSoby Mathew 	{0}
128*3e4b8fdcSSoby Mathew };
129*3e4b8fdcSSoby Mathew #endif
130*3e4b8fdcSSoby Mathew 
131*3e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
132*3e4b8fdcSSoby Mathew 
133*3e4b8fdcSSoby Mathew 
134*3e4b8fdcSSoby Mathew /*******************************************************************************
135*3e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
136*3e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
137*3e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
138*3e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
139*3e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
140*3e4b8fdcSSoby Mathew  ******************************************************************************/
141*3e4b8fdcSSoby Mathew void fvp_config_setup(void)
142*3e4b8fdcSSoby Mathew {
143*3e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
144*3e4b8fdcSSoby Mathew 
145*3e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
146*3e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
147*3e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
148*3e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
149*3e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
150*3e4b8fdcSSoby Mathew 
151*3e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
152*3e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
153*3e4b8fdcSSoby Mathew 		panic();
154*3e4b8fdcSSoby Mathew 	}
155*3e4b8fdcSSoby Mathew 
156*3e4b8fdcSSoby Mathew 	/*
157*3e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
158*3e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
159*3e4b8fdcSSoby Mathew 	 */
160*3e4b8fdcSSoby Mathew 	switch (bld) {
161*3e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
162*3e4b8fdcSSoby Mathew #if IMAGE_BL31 || IMAGE_BL32
163*3e4b8fdcSSoby Mathew #if FVP_USE_GIC_DRIVER == FVP_GICV2
164*3e4b8fdcSSoby Mathew 		/*
165*3e4b8fdcSSoby Mathew 		 * If the FVP implements the VE compatible memory map, then the
166*3e4b8fdcSSoby Mathew 		 * GICv2 driver must be included in the build. Update the platform
167*3e4b8fdcSSoby Mathew 		 * data with the correct GICv2 base addresses before it is used
168*3e4b8fdcSSoby Mathew 		 * to initialise the driver.
169*3e4b8fdcSSoby Mathew 		 *
170*3e4b8fdcSSoby Mathew 		 * This update of platform data is temporary and will be removed
171*3e4b8fdcSSoby Mathew 		 * once VE memory map for FVP is no longer supported by Trusted
172*3e4b8fdcSSoby Mathew 		 * Firmware.
173*3e4b8fdcSSoby Mathew 		 */
174*3e4b8fdcSSoby Mathew 		arm_gic_data.gicd_base = VE_GICD_BASE;
175*3e4b8fdcSSoby Mathew 		arm_gic_data.gicc_base = VE_GICC_BASE;
176*3e4b8fdcSSoby Mathew 
177*3e4b8fdcSSoby Mathew #else
178*3e4b8fdcSSoby Mathew 		ERROR("Only GICv2 driver supported for VE memory map\n");
179*3e4b8fdcSSoby Mathew 		panic();
180*3e4b8fdcSSoby Mathew #endif /* __FVP_USE_GIC_DRIVER == FVP_GICV2__ */
181*3e4b8fdcSSoby Mathew #endif /* __IMAGE_BL31 || IMAGE_BL32__ */
182*3e4b8fdcSSoby Mathew 		break;
183*3e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
184*3e4b8fdcSSoby Mathew 		break;
185*3e4b8fdcSSoby Mathew 	default:
186*3e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
187*3e4b8fdcSSoby Mathew 		panic();
188*3e4b8fdcSSoby Mathew 	}
189*3e4b8fdcSSoby Mathew 
190*3e4b8fdcSSoby Mathew 	/*
191*3e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
192*3e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
193*3e4b8fdcSSoby Mathew 	 */
194*3e4b8fdcSSoby Mathew 	switch (hbi) {
195*3e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
196*3e4b8fdcSSoby Mathew 		arm_config.flags = 0;
197*3e4b8fdcSSoby Mathew 
198*3e4b8fdcSSoby Mathew 		/*
199*3e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
200*3e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
201*3e4b8fdcSSoby Mathew 		 */
202*3e4b8fdcSSoby Mathew 		switch (rev) {
203*3e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
204*3e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
205*3e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
206*3e4b8fdcSSoby Mathew 			break;
207*3e4b8fdcSSoby Mathew 		default:
208*3e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
209*3e4b8fdcSSoby Mathew 			break;
210*3e4b8fdcSSoby Mathew 		}
211*3e4b8fdcSSoby Mathew 		break;
212*3e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
213*3e4b8fdcSSoby Mathew 		arm_config.flags |= ARM_CONFIG_BASE_MMAP |
214*3e4b8fdcSSoby Mathew 			ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC;
215*3e4b8fdcSSoby Mathew 
216*3e4b8fdcSSoby Mathew 		/*
217*3e4b8fdcSSoby Mathew 		 * Check for supported revisions
218*3e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
219*3e4b8fdcSSoby Mathew 		 */
220*3e4b8fdcSSoby Mathew 		switch (rev) {
221*3e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
222*3e4b8fdcSSoby Mathew 			break;
223*3e4b8fdcSSoby Mathew 		default:
224*3e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
225*3e4b8fdcSSoby Mathew 			break;
226*3e4b8fdcSSoby Mathew 		}
227*3e4b8fdcSSoby Mathew 		break;
228*3e4b8fdcSSoby Mathew 	default:
229*3e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
230*3e4b8fdcSSoby Mathew 		panic();
231*3e4b8fdcSSoby Mathew 	}
232*3e4b8fdcSSoby Mathew }
233*3e4b8fdcSSoby Mathew 
234*3e4b8fdcSSoby Mathew 
235*3e4b8fdcSSoby Mathew void fvp_interconnect_init(void)
236*3e4b8fdcSSoby Mathew {
237*3e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
238*3e4b8fdcSSoby Mathew 		plat_arm_interconnect_init();
239*3e4b8fdcSSoby Mathew }
240*3e4b8fdcSSoby Mathew 
241*3e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
242*3e4b8fdcSSoby Mathew {
243*3e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
244*3e4b8fdcSSoby Mathew 		plat_arm_interconnect_enter_coherency();
245*3e4b8fdcSSoby Mathew }
246*3e4b8fdcSSoby Mathew 
247*3e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
248*3e4b8fdcSSoby Mathew {
249*3e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
250*3e4b8fdcSSoby Mathew 		plat_arm_interconnect_exit_coherency();
251*3e4b8fdcSSoby Mathew }
252