xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_common.c (revision 284c3d67090586b20c7eed2955c05094dccff2e1)
13e4b8fdcSSoby Mathew /*
23e4b8fdcSSoby Mathew  * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
33e4b8fdcSSoby Mathew  *
482cb2c1aSdp-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 
39*284c3d67SSandrine Bailleux /*
40*284c3d67SSandrine Bailleux  * Need to be mapped with write permissions in order to set a new non-volatile
41*284c3d67SSandrine Bailleux  * counter value.
42*284c3d67SSandrine Bailleux  */
433e4b8fdcSSoby Mathew #define MAP_DEVICE2	MAP_REGION_FLAT(DEVICE2_BASE,			\
443e4b8fdcSSoby Mathew 					DEVICE2_SIZE,			\
45fe7de035SAntonio Nino Diaz 					MT_DEVICE | MT_RW | MT_SECURE)
463e4b8fdcSSoby Mathew 
473e4b8fdcSSoby Mathew 
483e4b8fdcSSoby Mathew /*
49b5fa6563SSandrine Bailleux  * Table of memory regions for various BL stages to map using the MMU.
50b5fa6563SSandrine Bailleux  * This doesn't include Trusted SRAM as arm_setup_page_tables() already
51b5fa6563SSandrine Bailleux  * takes care of mapping it.
5291fad655SSandrine Bailleux  *
5391fad655SSandrine Bailleux  * The flash needs to be mapped as writable in order to erase the FIP's Table of
5491fad655SSandrine Bailleux  * Contents in case of unrecoverable error (see plat_error_handler()).
553e4b8fdcSSoby Mathew  */
563d8256b2SMasahiro Yamada #ifdef IMAGE_BL1
573e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
583e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
593e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
603e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
613e4b8fdcSSoby Mathew 	MAP_DEVICE0,
623e4b8fdcSSoby Mathew 	MAP_DEVICE1,
633e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT
64*284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
65*284c3d67SSandrine Bailleux 	MAP_DEVICE2,
66*284c3d67SSandrine Bailleux 	/* Map DRAM to authenticate NS_BL2U image. */
673e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
683e4b8fdcSSoby Mathew #endif
693e4b8fdcSSoby Mathew 	{0}
703e4b8fdcSSoby Mathew };
713e4b8fdcSSoby Mathew #endif
723d8256b2SMasahiro Yamada #ifdef IMAGE_BL2
733e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
743e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
753e4b8fdcSSoby Mathew 	V2M_MAP_FLASH0_RW,
763e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
773e4b8fdcSSoby Mathew 	MAP_DEVICE0,
783e4b8fdcSSoby Mathew 	MAP_DEVICE1,
793e4b8fdcSSoby Mathew 	ARM_MAP_NS_DRAM1,
803e4b8fdcSSoby Mathew 	ARM_MAP_TSP_SEC_MEM,
81*284c3d67SSandrine Bailleux #if TRUSTED_BOARD_BOOT
82*284c3d67SSandrine Bailleux 	/* To access the Root of Trust Public Key registers. */
83*284c3d67SSandrine Bailleux 	MAP_DEVICE2,
84*284c3d67SSandrine Bailleux #endif
853e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM
863e4b8fdcSSoby Mathew 	ARM_MAP_BL31_SEC_DRAM,
873e4b8fdcSSoby Mathew #endif
883e4b8fdcSSoby Mathew 	{0}
893e4b8fdcSSoby Mathew };
903e4b8fdcSSoby Mathew #endif
913d8256b2SMasahiro Yamada #ifdef IMAGE_BL2U
923e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
933e4b8fdcSSoby Mathew 	MAP_DEVICE0,
943e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
953e4b8fdcSSoby Mathew 	{0}
963e4b8fdcSSoby Mathew };
973e4b8fdcSSoby Mathew #endif
983d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
993e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
1003e4b8fdcSSoby Mathew 	ARM_MAP_SHARED_RAM,
1013e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1023e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1033e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1043e4b8fdcSSoby Mathew 	{0}
1053e4b8fdcSSoby Mathew };
1063e4b8fdcSSoby Mathew #endif
1073d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
1083e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = {
109877cf3ffSSoby Mathew #ifdef AARCH32
110877cf3ffSSoby Mathew 	ARM_MAP_SHARED_RAM,
111877cf3ffSSoby Mathew #endif
1123e4b8fdcSSoby Mathew 	V2M_MAP_IOFPGA,
1133e4b8fdcSSoby Mathew 	MAP_DEVICE0,
1143e4b8fdcSSoby Mathew 	MAP_DEVICE1,
1153e4b8fdcSSoby Mathew 	{0}
1163e4b8fdcSSoby Mathew };
1173e4b8fdcSSoby Mathew #endif
1183e4b8fdcSSoby Mathew 
1193e4b8fdcSSoby Mathew ARM_CASSERT_MMAP
1203e4b8fdcSSoby Mathew 
1213e4b8fdcSSoby Mathew 
1223e4b8fdcSSoby Mathew /*******************************************************************************
1233e4b8fdcSSoby Mathew  * A single boot loader stack is expected to work on both the Foundation FVP
1243e4b8fdcSSoby Mathew  * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The
1253e4b8fdcSSoby Mathew  * SYS_ID register provides a mechanism for detecting the differences between
1263e4b8fdcSSoby Mathew  * these platforms. This information is stored in a per-BL array to allow the
1273e4b8fdcSSoby Mathew  * code to take the correct path.Per BL platform configuration.
1283e4b8fdcSSoby Mathew  ******************************************************************************/
1293e4b8fdcSSoby Mathew void fvp_config_setup(void)
1303e4b8fdcSSoby Mathew {
1313e4b8fdcSSoby Mathew 	unsigned int rev, hbi, bld, arch, sys_id;
1323e4b8fdcSSoby Mathew 
1333e4b8fdcSSoby Mathew 	sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID);
1343e4b8fdcSSoby Mathew 	rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK;
1353e4b8fdcSSoby Mathew 	hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK;
1363e4b8fdcSSoby Mathew 	bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK;
1373e4b8fdcSSoby Mathew 	arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK;
1383e4b8fdcSSoby Mathew 
1393e4b8fdcSSoby Mathew 	if (arch != ARCH_MODEL) {
1403e4b8fdcSSoby Mathew 		ERROR("This firmware is for FVP models\n");
1413e4b8fdcSSoby Mathew 		panic();
1423e4b8fdcSSoby Mathew 	}
1433e4b8fdcSSoby Mathew 
1443e4b8fdcSSoby Mathew 	/*
1453e4b8fdcSSoby Mathew 	 * The build field in the SYS_ID tells which variant of the GIC
1463e4b8fdcSSoby Mathew 	 * memory is implemented by the model.
1473e4b8fdcSSoby Mathew 	 */
1483e4b8fdcSSoby Mathew 	switch (bld) {
1493e4b8fdcSSoby Mathew 	case BLD_GIC_VE_MMAP:
15021a3973dSSoby Mathew 		ERROR("Legacy Versatile Express memory map for GIC peripheral"
15121a3973dSSoby Mathew 				" is not supported\n");
1523e4b8fdcSSoby Mathew 		panic();
1533e4b8fdcSSoby Mathew 		break;
1543e4b8fdcSSoby Mathew 	case BLD_GIC_A53A57_MMAP:
1553e4b8fdcSSoby Mathew 		break;
1563e4b8fdcSSoby Mathew 	default:
1573e4b8fdcSSoby Mathew 		ERROR("Unsupported board build %x\n", bld);
1583e4b8fdcSSoby Mathew 		panic();
1593e4b8fdcSSoby Mathew 	}
1603e4b8fdcSSoby Mathew 
1613e4b8fdcSSoby Mathew 	/*
1623e4b8fdcSSoby Mathew 	 * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010
1633e4b8fdcSSoby Mathew 	 * for the Foundation FVP.
1643e4b8fdcSSoby Mathew 	 */
1653e4b8fdcSSoby Mathew 	switch (hbi) {
1663e4b8fdcSSoby Mathew 	case HBI_FOUNDATION_FVP:
1673e4b8fdcSSoby Mathew 		arm_config.flags = 0;
1683e4b8fdcSSoby Mathew 
1693e4b8fdcSSoby Mathew 		/*
1703e4b8fdcSSoby Mathew 		 * Check for supported revisions of Foundation FVP
1713e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
1723e4b8fdcSSoby Mathew 		 */
1733e4b8fdcSSoby Mathew 		switch (rev) {
1743e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_0:
1753e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_V2_1:
1763e4b8fdcSSoby Mathew 		case REV_FOUNDATION_FVP_v9_1:
1774faa4a1dSSandrine Bailleux 		case REV_FOUNDATION_FVP_v9_6:
1783e4b8fdcSSoby Mathew 			break;
1793e4b8fdcSSoby Mathew 		default:
1803e4b8fdcSSoby Mathew 			WARN("Unrecognized Foundation FVP revision %x\n", rev);
1813e4b8fdcSSoby Mathew 			break;
1823e4b8fdcSSoby Mathew 		}
1833e4b8fdcSSoby Mathew 		break;
1843e4b8fdcSSoby Mathew 	case HBI_BASE_FVP:
1853e4b8fdcSSoby Mathew 		arm_config.flags |= ARM_CONFIG_BASE_MMAP |
1863e4b8fdcSSoby Mathew 			ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC;
1873e4b8fdcSSoby Mathew 
1883e4b8fdcSSoby Mathew 		/*
1893e4b8fdcSSoby Mathew 		 * Check for supported revisions
1903e4b8fdcSSoby Mathew 		 * Allow future revisions to run but emit warning diagnostic
1913e4b8fdcSSoby Mathew 		 */
1923e4b8fdcSSoby Mathew 		switch (rev) {
1933e4b8fdcSSoby Mathew 		case REV_BASE_FVP_V0:
1943e4b8fdcSSoby Mathew 			break;
1953e4b8fdcSSoby Mathew 		default:
1963e4b8fdcSSoby Mathew 			WARN("Unrecognized Base FVP revision %x\n", rev);
1973e4b8fdcSSoby Mathew 			break;
1983e4b8fdcSSoby Mathew 		}
1993e4b8fdcSSoby Mathew 		break;
2003e4b8fdcSSoby Mathew 	default:
2013e4b8fdcSSoby Mathew 		ERROR("Unsupported board HBI number 0x%x\n", hbi);
2023e4b8fdcSSoby Mathew 		panic();
2033e4b8fdcSSoby Mathew 	}
2043e4b8fdcSSoby Mathew }
2053e4b8fdcSSoby Mathew 
2063e4b8fdcSSoby Mathew 
2073e4b8fdcSSoby Mathew void fvp_interconnect_init(void)
2083e4b8fdcSSoby Mathew {
20971237876SSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) {
21071237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN
21171237876SSoby Mathew 		if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) {
21271237876SSoby Mathew 			ERROR("Unrecognized CCN variant detected. Only CCN-502"
21371237876SSoby Mathew 					" is supported");
21471237876SSoby Mathew 			panic();
21571237876SSoby Mathew 		}
21671237876SSoby Mathew #endif
2173e4b8fdcSSoby Mathew 		plat_arm_interconnect_init();
2183e4b8fdcSSoby Mathew 	}
21971237876SSoby Mathew }
2203e4b8fdcSSoby Mathew 
2213e4b8fdcSSoby Mathew void fvp_interconnect_enable(void)
2223e4b8fdcSSoby Mathew {
2233e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
2243e4b8fdcSSoby Mathew 		plat_arm_interconnect_enter_coherency();
2253e4b8fdcSSoby Mathew }
2263e4b8fdcSSoby Mathew 
2273e4b8fdcSSoby Mathew void fvp_interconnect_disable(void)
2283e4b8fdcSSoby Mathew {
2293e4b8fdcSSoby Mathew 	if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT)
2303e4b8fdcSSoby Mathew 		plat_arm_interconnect_exit_coherency();
2313e4b8fdcSSoby Mathew }
232