xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
13e4b8fdcSSoby Mathew /*
23e4b8fdcSSoby Mathew  * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
33e4b8fdcSSoby Mathew  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
53e4b8fdcSSoby Mathew  */
63e4b8fdcSSoby Mathew 
73e4b8fdcSSoby Mathew #include <arm_config.h>
83e4b8fdcSSoby Mathew #include <arm_def.h>
971237876SSoby Mathew #include <ccn.h>
103e4b8fdcSSoby Mathew #include <debug.h>
113e4b8fdcSSoby Mathew #include <gicv2.h>
123e4b8fdcSSoby Mathew #include <mmio.h>
133e4b8fdcSSoby Mathew #include <plat_arm.h>
143e4b8fdcSSoby Mathew #include <v2m_def.h>
153e4b8fdcSSoby Mathew #include "../fvp_def.h"
163e4b8fdcSSoby Mathew 
173e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */
183e4b8fdcSSoby Mathew #define FVP_GICV2		1
193e4b8fdcSSoby Mathew #define FVP_GICV3		2
203e4b8fdcSSoby Mathew #define FVP_GICV3_LEGACY	3
213e4b8fdcSSoby Mathew 
223e4b8fdcSSoby Mathew /*******************************************************************************
233e4b8fdcSSoby Mathew  * arm_config holds the characteristics of the differences between the three FVP
243e4b8fdcSSoby Mathew  * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot
253e4b8fdcSSoby Mathew  * at each boot stage by the primary before enabling the MMU (to allow
263e4b8fdcSSoby Mathew  * interconnect configuration) & used thereafter. Each BL will have its own copy
273e4b8fdcSSoby Mathew  * to allow independent operation.
283e4b8fdcSSoby Mathew  ******************************************************************************/
293e4b8fdcSSoby Mathew arm_config_t arm_config;
303e4b8fdcSSoby Mathew 
313e4b8fdcSSoby Mathew #define MAP_DEVICE0	MAP_REGION_FLAT(DEVICE0_BASE,			\
323e4b8fdcSSoby Mathew 					DEVICE0_SIZE,			\
333e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
343e4b8fdcSSoby Mathew 
353e4b8fdcSSoby Mathew #define MAP_DEVICE1	MAP_REGION_FLAT(DEVICE1_BASE,			\
363e4b8fdcSSoby Mathew 					DEVICE1_SIZE,			\
373e4b8fdcSSoby Mathew 					MT_DEVICE | MT_RW | MT_SECURE)
383e4b8fdcSSoby Mathew 
393e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
403e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
41fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
423e4b8fdcSSoby Mathew 
433e4b8fdcSSoby Mathew 
443e4b8fdcSSoby Mathew /*
45b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
46b5fa6563SSandrine Bailleux  * This doesn't include Trusted SRAM as arm_setup_page_tables() already
47b5fa6563SSandrine Bailleux  * takes care of mapping it.
4891fad655SSandrine Bailleux  *
4991fad655SSandrine Bailleux  * The flash needs to be mapped as writable in order to erase the FIP's Table of
5091fad655SSandrine Bailleux  * Contents in case of unrecoverable error (see plat_error_handler()).
513e4b8fdcSSoby Mathew  */
523d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
533e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
543e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
553e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
563e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
573e4b8fdcSSoby Mathew 	MAP_DEVICE0,
583e4b8fdcSSoby Mathew 	MAP_DEVICE1,
593e4b8fdcSSoby Mathew 	MAP_DEVICE2,
603e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
613e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
623e4b8fdcSSoby Mathew #endif
633e4b8fdcSSoby Mathew 	{0}
643e4b8fdcSSoby Mathew };
653e4b8fdcSSoby Mathew #endif
663d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
673e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
683e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
693e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
703e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
713e4b8fdcSSoby Mathew 	MAP_DEVICE0,
723e4b8fdcSSoby Mathew 	MAP_DEVICE1,
733e4b8fdcSSoby Mathew 	MAP_DEVICE2,
743e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
753e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
763e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
773e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
783e4b8fdcSSoby Mathew #endif
793e4b8fdcSSoby Mathew 	{0}
803e4b8fdcSSoby Mathew };
813e4b8fdcSSoby Mathew #endif
823d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
833e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
843e4b8fdcSSoby Mathew 	MAP_DEVICE0,
853e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
863e4b8fdcSSoby Mathew 	{0}
873e4b8fdcSSoby Mathew };
883e4b8fdcSSoby Mathew #endif
893d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
903e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
913e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
923e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
933e4b8fdcSSoby Mathew 	MAP_DEVICE0,
943e4b8fdcSSoby Mathew 	MAP_DEVICE1,
953e4b8fdcSSoby Mathew 	{0}
963e4b8fdcSSoby Mathew };
973e4b8fdcSSoby Mathew #endif
983d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
993e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
100877cf3ffSSoby Mathew #ifdef AARCH32
101877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
102877cf3ffSSoby Mathew #endif
1033e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1043e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1053e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1063e4b8fdcSSoby Mathew 	{0}
1073e4b8fdcSSoby Mathew };
1083e4b8fdcSSoby Mathew #endif
1093e4b8fdcSSoby Mathew 
1103e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
1113e4b8fdcSSoby Mathew 
1123e4b8fdcSSoby Mathew 
1133e4b8fdcSSoby Mathew /*******************************************************************************
1143e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
1153e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
1163e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
1173e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
1183e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
1193e4b8fdcSSoby Mathew  ******************************************************************************/
1203e4b8fdcSSoby Mathew void fvp_config_setup(void)
1213e4b8fdcSSoby Mathew {
1223e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
1233e4b8fdcSSoby Mathew 
1243e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
1253e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
1263e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
1273e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
1283e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
1293e4b8fdcSSoby Mathew 
1303e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
1313e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
1323e4b8fdcSSoby Mathew 		panic();
1333e4b8fdcSSoby Mathew 	}
1343e4b8fdcSSoby Mathew 
1353e4b8fdcSSoby Mathew 	/*
1363e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
1373e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
1383e4b8fdcSSoby Mathew 	 */
1393e4b8fdcSSoby Mathew 	switch (bld) {
1403e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
14121a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
14221a3973dSSoby Mathew 				" is not supported\n");
1433e4b8fdcSSoby Mathew 		panic();
1443e4b8fdcSSoby Mathew 		break;
1453e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
1463e4b8fdcSSoby Mathew 		break;
1473e4b8fdcSSoby Mathew 	default:
1483e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
1493e4b8fdcSSoby Mathew 		panic();
1503e4b8fdcSSoby Mathew 	}
1513e4b8fdcSSoby Mathew 
1523e4b8fdcSSoby Mathew 	/*
1533e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
1543e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
1553e4b8fdcSSoby Mathew 	 */
1563e4b8fdcSSoby Mathew 	switch (hbi) {
1573e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
1583e4b8fdcSSoby Mathew 		arm_config.flags = 0;
1593e4b8fdcSSoby Mathew 
1603e4b8fdcSSoby Mathew 		/*
1613e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
1623e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
1633e4b8fdcSSoby Mathew 		 */
1643e4b8fdcSSoby Mathew 		switch (rev) {
1653e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
1663e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
1673e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
1684faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
1693e4b8fdcSSoby Mathew 			break;
1703e4b8fdcSSoby Mathew 		default:
1713e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
1723e4b8fdcSSoby Mathew 			break;
1733e4b8fdcSSoby Mathew 		}
1743e4b8fdcSSoby Mathew 		break;
1753e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
1763e4b8fdcSSoby Mathew 		arm_config.flags |= ARM_CONFIG_BASE_MMAP |
1773e4b8fdcSSoby Mathew 			ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC;
1783e4b8fdcSSoby Mathew 
1793e4b8fdcSSoby Mathew 		/*
1803e4b8fdcSSoby Mathew 		 * Check for supported revisions
1813e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
1823e4b8fdcSSoby Mathew 		 */
1833e4b8fdcSSoby Mathew 		switch (rev) {
1843e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
1853e4b8fdcSSoby Mathew 			break;
1863e4b8fdcSSoby Mathew 		default:
1873e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
1883e4b8fdcSSoby Mathew 			break;
1893e4b8fdcSSoby Mathew 		}
1903e4b8fdcSSoby Mathew 		break;
1913e4b8fdcSSoby Mathew 	default:
1923e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
1933e4b8fdcSSoby Mathew 		panic();
1943e4b8fdcSSoby Mathew 	}
1953e4b8fdcSSoby Mathew }
1963e4b8fdcSSoby Mathew 
1973e4b8fdcSSoby Mathew 
1983e4b8fdcSSoby Mathew void fvp_interconnect_init(void)
1993e4b8fdcSSoby Mathew {
20071237876SSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) {
20171237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
20271237876SSoby Mathew 		if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
20371237876SSoby Mathew 			ERROR("Unrecognized CCN variant detected. Only CCN-502"
20471237876SSoby Mathew 					" is supported");
20571237876SSoby Mathew 			panic();
20671237876SSoby Mathew 		}
20771237876SSoby Mathew #endif
2083e4b8fdcSSoby Mathew 		plat_arm_interconnect_init();
2093e4b8fdcSSoby Mathew 	}
21071237876SSoby Mathew }
2113e4b8fdcSSoby Mathew 
2123e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
2133e4b8fdcSSoby Mathew {
2143e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
2153e4b8fdcSSoby Mathew 		plat_arm_interconnect_enter_coherency();
2163e4b8fdcSSoby Mathew }
2173e4b8fdcSSoby Mathew 
2183e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
2193e4b8fdcSSoby Mathew {
2203e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
2213e4b8fdcSSoby Mathew 		plat_arm_interconnect_exit_coherency();
2223e4b8fdcSSoby Mathew }
223