13e4b8fdcSSoby Mathew /* 23e4b8fdcSSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 33e4b8fdcSSoby Mathew * 43e4b8fdcSSoby Mathew * Redistribution and use in source and binary forms, with or without 53e4b8fdcSSoby Mathew * modification, are permitted provided that the following conditions are met: 63e4b8fdcSSoby Mathew * 73e4b8fdcSSoby Mathew * Redistributions of source code must retain the above copyright notice, this 83e4b8fdcSSoby Mathew * list of conditions and the following disclaimer. 93e4b8fdcSSoby Mathew * 103e4b8fdcSSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 113e4b8fdcSSoby Mathew * this list of conditions and the following disclaimer in the documentation 123e4b8fdcSSoby Mathew * and/or other materials provided with the distribution. 133e4b8fdcSSoby Mathew * 143e4b8fdcSSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 153e4b8fdcSSoby Mathew * to endorse or promote products derived from this software without specific 163e4b8fdcSSoby Mathew * prior written permission. 173e4b8fdcSSoby Mathew * 183e4b8fdcSSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 193e4b8fdcSSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203e4b8fdcSSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 213e4b8fdcSSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 223e4b8fdcSSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 233e4b8fdcSSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 243e4b8fdcSSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 253e4b8fdcSSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 263e4b8fdcSSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 273e4b8fdcSSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283e4b8fdcSSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 293e4b8fdcSSoby Mathew */ 303e4b8fdcSSoby Mathew 313e4b8fdcSSoby Mathew #include <arm_config.h> 323e4b8fdcSSoby Mathew #include <arm_def.h> 333e4b8fdcSSoby Mathew #include <debug.h> 343e4b8fdcSSoby Mathew #include <gicv2.h> 353e4b8fdcSSoby Mathew #include <mmio.h> 363e4b8fdcSSoby Mathew #include <plat_arm.h> 373e4b8fdcSSoby Mathew #include <v2m_def.h> 383e4b8fdcSSoby Mathew #include "../fvp_def.h" 393e4b8fdcSSoby Mathew 403e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */ 413e4b8fdcSSoby Mathew #define FVP_GICV2 1 423e4b8fdcSSoby Mathew #define FVP_GICV3 2 433e4b8fdcSSoby Mathew #define FVP_GICV3_LEGACY 3 443e4b8fdcSSoby Mathew 453e4b8fdcSSoby Mathew /******************************************************************************* 463e4b8fdcSSoby Mathew * arm_config holds the characteristics of the differences between the three FVP 473e4b8fdcSSoby Mathew * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot 483e4b8fdcSSoby Mathew * at each boot stage by the primary before enabling the MMU (to allow 493e4b8fdcSSoby Mathew * interconnect configuration) & used thereafter. Each BL will have its own copy 503e4b8fdcSSoby Mathew * to allow independent operation. 513e4b8fdcSSoby Mathew ******************************************************************************/ 523e4b8fdcSSoby Mathew arm_config_t arm_config; 533e4b8fdcSSoby Mathew 543e4b8fdcSSoby Mathew #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \ 553e4b8fdcSSoby Mathew DEVICE0_SIZE, \ 563e4b8fdcSSoby Mathew MT_DEVICE | MT_RW | MT_SECURE) 573e4b8fdcSSoby Mathew 583e4b8fdcSSoby Mathew #define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \ 593e4b8fdcSSoby Mathew DEVICE1_SIZE, \ 603e4b8fdcSSoby Mathew MT_DEVICE | MT_RW | MT_SECURE) 613e4b8fdcSSoby Mathew 623e4b8fdcSSoby Mathew #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ 633e4b8fdcSSoby Mathew DEVICE2_SIZE, \ 643e4b8fdcSSoby Mathew MT_DEVICE | MT_RO | MT_SECURE) 653e4b8fdcSSoby Mathew 663e4b8fdcSSoby Mathew 673e4b8fdcSSoby Mathew /* 683e4b8fdcSSoby Mathew * Table of regions for various BL stages to map using the MMU. 693e4b8fdcSSoby Mathew * This doesn't include TZRAM as the 'mem_layout' argument passed to 703e4b8fdcSSoby Mathew * arm_configure_mmu_elx() will give the available subset of that, 713e4b8fdcSSoby Mathew */ 723e4b8fdcSSoby Mathew #if IMAGE_BL1 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 MAP_DEVICE2, 803e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT 813e4b8fdcSSoby Mathew ARM_MAP_NS_DRAM1, 823e4b8fdcSSoby Mathew #endif 833e4b8fdcSSoby Mathew {0} 843e4b8fdcSSoby Mathew }; 853e4b8fdcSSoby Mathew #endif 863e4b8fdcSSoby Mathew #if IMAGE_BL2 873e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 883e4b8fdcSSoby Mathew ARM_MAP_SHARED_RAM, 893e4b8fdcSSoby Mathew V2M_MAP_FLASH0_RW, 903e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 913e4b8fdcSSoby Mathew MAP_DEVICE0, 923e4b8fdcSSoby Mathew MAP_DEVICE1, 933e4b8fdcSSoby Mathew MAP_DEVICE2, 943e4b8fdcSSoby Mathew ARM_MAP_NS_DRAM1, 953e4b8fdcSSoby Mathew ARM_MAP_TSP_SEC_MEM, 963e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM 973e4b8fdcSSoby Mathew ARM_MAP_BL31_SEC_DRAM, 983e4b8fdcSSoby Mathew #endif 993e4b8fdcSSoby Mathew {0} 1003e4b8fdcSSoby Mathew }; 1013e4b8fdcSSoby Mathew #endif 1023e4b8fdcSSoby Mathew #if IMAGE_BL2U 1033e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 1043e4b8fdcSSoby Mathew MAP_DEVICE0, 1053e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1063e4b8fdcSSoby Mathew {0} 1073e4b8fdcSSoby Mathew }; 1083e4b8fdcSSoby Mathew #endif 1093e4b8fdcSSoby Mathew #if IMAGE_BL31 1103e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 1113e4b8fdcSSoby Mathew ARM_MAP_SHARED_RAM, 1123e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1133e4b8fdcSSoby Mathew MAP_DEVICE0, 1143e4b8fdcSSoby Mathew MAP_DEVICE1, 1153e4b8fdcSSoby Mathew {0} 1163e4b8fdcSSoby Mathew }; 1173e4b8fdcSSoby Mathew #endif 1183e4b8fdcSSoby Mathew #if IMAGE_BL32 1193e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 1203e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1213e4b8fdcSSoby Mathew MAP_DEVICE0, 1223e4b8fdcSSoby Mathew MAP_DEVICE1, 1233e4b8fdcSSoby Mathew {0} 1243e4b8fdcSSoby Mathew }; 1253e4b8fdcSSoby Mathew #endif 1263e4b8fdcSSoby Mathew 1273e4b8fdcSSoby Mathew ARM_CASSERT_MMAP 1283e4b8fdcSSoby Mathew 1293e4b8fdcSSoby Mathew 1303e4b8fdcSSoby Mathew /******************************************************************************* 1313e4b8fdcSSoby Mathew * A single boot loader stack is expected to work on both the Foundation FVP 1323e4b8fdcSSoby Mathew * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The 1333e4b8fdcSSoby Mathew * SYS_ID register provides a mechanism for detecting the differences between 1343e4b8fdcSSoby Mathew * these platforms. This information is stored in a per-BL array to allow the 1353e4b8fdcSSoby Mathew * code to take the correct path.Per BL platform configuration. 1363e4b8fdcSSoby Mathew ******************************************************************************/ 1373e4b8fdcSSoby Mathew void fvp_config_setup(void) 1383e4b8fdcSSoby Mathew { 1393e4b8fdcSSoby Mathew unsigned int rev, hbi, bld, arch, sys_id; 1403e4b8fdcSSoby Mathew 1413e4b8fdcSSoby Mathew sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID); 1423e4b8fdcSSoby Mathew rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK; 1433e4b8fdcSSoby Mathew hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK; 1443e4b8fdcSSoby Mathew bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK; 1453e4b8fdcSSoby Mathew arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK; 1463e4b8fdcSSoby Mathew 1473e4b8fdcSSoby Mathew if (arch != ARCH_MODEL) { 1483e4b8fdcSSoby Mathew ERROR("This firmware is for FVP models\n"); 1493e4b8fdcSSoby Mathew panic(); 1503e4b8fdcSSoby Mathew } 1513e4b8fdcSSoby Mathew 1523e4b8fdcSSoby Mathew /* 1533e4b8fdcSSoby Mathew * The build field in the SYS_ID tells which variant of the GIC 1543e4b8fdcSSoby Mathew * memory is implemented by the model. 1553e4b8fdcSSoby Mathew */ 1563e4b8fdcSSoby Mathew switch (bld) { 1573e4b8fdcSSoby Mathew case BLD_GIC_VE_MMAP: 158*21a3973dSSoby Mathew ERROR("Legacy Versatile Express memory map for GIC peripheral" 159*21a3973dSSoby Mathew " is not supported\n"); 1603e4b8fdcSSoby Mathew panic(); 1613e4b8fdcSSoby Mathew break; 1623e4b8fdcSSoby Mathew case BLD_GIC_A53A57_MMAP: 1633e4b8fdcSSoby Mathew break; 1643e4b8fdcSSoby Mathew default: 1653e4b8fdcSSoby Mathew ERROR("Unsupported board build %x\n", bld); 1663e4b8fdcSSoby Mathew panic(); 1673e4b8fdcSSoby Mathew } 1683e4b8fdcSSoby Mathew 1693e4b8fdcSSoby Mathew /* 1703e4b8fdcSSoby Mathew * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010 1713e4b8fdcSSoby Mathew * for the Foundation FVP. 1723e4b8fdcSSoby Mathew */ 1733e4b8fdcSSoby Mathew switch (hbi) { 1743e4b8fdcSSoby Mathew case HBI_FOUNDATION_FVP: 1753e4b8fdcSSoby Mathew arm_config.flags = 0; 1763e4b8fdcSSoby Mathew 1773e4b8fdcSSoby Mathew /* 1783e4b8fdcSSoby Mathew * Check for supported revisions of Foundation FVP 1793e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 1803e4b8fdcSSoby Mathew */ 1813e4b8fdcSSoby Mathew switch (rev) { 1823e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_0: 1833e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_1: 1843e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_v9_1: 1853e4b8fdcSSoby Mathew break; 1863e4b8fdcSSoby Mathew default: 1873e4b8fdcSSoby Mathew WARN("Unrecognized Foundation FVP revision %x\n", rev); 1883e4b8fdcSSoby Mathew break; 1893e4b8fdcSSoby Mathew } 1903e4b8fdcSSoby Mathew break; 1913e4b8fdcSSoby Mathew case HBI_BASE_FVP: 1923e4b8fdcSSoby Mathew arm_config.flags |= ARM_CONFIG_BASE_MMAP | 1933e4b8fdcSSoby Mathew ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC; 1943e4b8fdcSSoby Mathew 1953e4b8fdcSSoby Mathew /* 1963e4b8fdcSSoby Mathew * Check for supported revisions 1973e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 1983e4b8fdcSSoby Mathew */ 1993e4b8fdcSSoby Mathew switch (rev) { 2003e4b8fdcSSoby Mathew case REV_BASE_FVP_V0: 2013e4b8fdcSSoby Mathew break; 2023e4b8fdcSSoby Mathew default: 2033e4b8fdcSSoby Mathew WARN("Unrecognized Base FVP revision %x\n", rev); 2043e4b8fdcSSoby Mathew break; 2053e4b8fdcSSoby Mathew } 2063e4b8fdcSSoby Mathew break; 2073e4b8fdcSSoby Mathew default: 2083e4b8fdcSSoby Mathew ERROR("Unsupported board HBI number 0x%x\n", hbi); 2093e4b8fdcSSoby Mathew panic(); 2103e4b8fdcSSoby Mathew } 2113e4b8fdcSSoby Mathew } 2123e4b8fdcSSoby Mathew 2133e4b8fdcSSoby Mathew 2143e4b8fdcSSoby Mathew void fvp_interconnect_init(void) 2153e4b8fdcSSoby Mathew { 2163e4b8fdcSSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) 2173e4b8fdcSSoby Mathew plat_arm_interconnect_init(); 2183e4b8fdcSSoby Mathew } 2193e4b8fdcSSoby Mathew 2203e4b8fdcSSoby Mathew void fvp_interconnect_enable(void) 2213e4b8fdcSSoby Mathew { 2223e4b8fdcSSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) 2233e4b8fdcSSoby Mathew plat_arm_interconnect_enter_coherency(); 2243e4b8fdcSSoby Mathew } 2253e4b8fdcSSoby Mathew 2263e4b8fdcSSoby Mathew void fvp_interconnect_disable(void) 2273e4b8fdcSSoby Mathew { 2283e4b8fdcSSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) 2293e4b8fdcSSoby Mathew plat_arm_interconnect_exit_coherency(); 2303e4b8fdcSSoby Mathew } 231