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> 3371237876SSoby Mathew #include <ccn.h> 343e4b8fdcSSoby Mathew #include <debug.h> 353e4b8fdcSSoby Mathew #include <gicv2.h> 363e4b8fdcSSoby Mathew #include <mmio.h> 373e4b8fdcSSoby Mathew #include <plat_arm.h> 383e4b8fdcSSoby Mathew #include <v2m_def.h> 393e4b8fdcSSoby Mathew #include "../fvp_def.h" 403e4b8fdcSSoby Mathew 413e4b8fdcSSoby Mathew /* Defines for GIC Driver build time selection */ 423e4b8fdcSSoby Mathew #define FVP_GICV2 1 433e4b8fdcSSoby Mathew #define FVP_GICV3 2 443e4b8fdcSSoby Mathew #define FVP_GICV3_LEGACY 3 453e4b8fdcSSoby Mathew 463e4b8fdcSSoby Mathew /******************************************************************************* 473e4b8fdcSSoby Mathew * arm_config holds the characteristics of the differences between the three FVP 483e4b8fdcSSoby Mathew * platforms (Base, A53_A57 & Foundation). It will be populated during cold boot 493e4b8fdcSSoby Mathew * at each boot stage by the primary before enabling the MMU (to allow 503e4b8fdcSSoby Mathew * interconnect configuration) & used thereafter. Each BL will have its own copy 513e4b8fdcSSoby Mathew * to allow independent operation. 523e4b8fdcSSoby Mathew ******************************************************************************/ 533e4b8fdcSSoby Mathew arm_config_t arm_config; 543e4b8fdcSSoby Mathew 553e4b8fdcSSoby Mathew #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \ 563e4b8fdcSSoby Mathew DEVICE0_SIZE, \ 573e4b8fdcSSoby Mathew MT_DEVICE | MT_RW | MT_SECURE) 583e4b8fdcSSoby Mathew 593e4b8fdcSSoby Mathew #define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \ 603e4b8fdcSSoby Mathew DEVICE1_SIZE, \ 613e4b8fdcSSoby Mathew MT_DEVICE | MT_RW | MT_SECURE) 623e4b8fdcSSoby Mathew 633e4b8fdcSSoby Mathew #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ 643e4b8fdcSSoby Mathew DEVICE2_SIZE, \ 65fe7de035SAntonio Nino Diaz MT_DEVICE | MT_RW | MT_SECURE) 663e4b8fdcSSoby Mathew 673e4b8fdcSSoby Mathew 683e4b8fdcSSoby Mathew /* 69b5fa6563SSandrine Bailleux * Table of memory regions for various BL stages to map using the MMU. 70b5fa6563SSandrine Bailleux * This doesn't include Trusted SRAM as arm_setup_page_tables() already 71b5fa6563SSandrine Bailleux * takes care of mapping it. 7291fad655SSandrine Bailleux * 7391fad655SSandrine Bailleux * The flash needs to be mapped as writable in order to erase the FIP's Table of 7491fad655SSandrine Bailleux * Contents in case of unrecoverable error (see plat_error_handler()). 753e4b8fdcSSoby Mathew */ 763e4b8fdcSSoby Mathew #if IMAGE_BL1 773e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 783e4b8fdcSSoby Mathew ARM_MAP_SHARED_RAM, 793e4b8fdcSSoby Mathew V2M_MAP_FLASH0_RW, 803e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 813e4b8fdcSSoby Mathew MAP_DEVICE0, 823e4b8fdcSSoby Mathew MAP_DEVICE1, 833e4b8fdcSSoby Mathew MAP_DEVICE2, 843e4b8fdcSSoby Mathew #if TRUSTED_BOARD_BOOT 853e4b8fdcSSoby Mathew ARM_MAP_NS_DRAM1, 863e4b8fdcSSoby Mathew #endif 873e4b8fdcSSoby Mathew {0} 883e4b8fdcSSoby Mathew }; 893e4b8fdcSSoby Mathew #endif 903e4b8fdcSSoby Mathew #if IMAGE_BL2 913e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 923e4b8fdcSSoby Mathew ARM_MAP_SHARED_RAM, 933e4b8fdcSSoby Mathew V2M_MAP_FLASH0_RW, 943e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 953e4b8fdcSSoby Mathew MAP_DEVICE0, 963e4b8fdcSSoby Mathew MAP_DEVICE1, 973e4b8fdcSSoby Mathew MAP_DEVICE2, 983e4b8fdcSSoby Mathew ARM_MAP_NS_DRAM1, 993e4b8fdcSSoby Mathew ARM_MAP_TSP_SEC_MEM, 1003e4b8fdcSSoby Mathew #if ARM_BL31_IN_DRAM 1013e4b8fdcSSoby Mathew ARM_MAP_BL31_SEC_DRAM, 1023e4b8fdcSSoby Mathew #endif 1033e4b8fdcSSoby Mathew {0} 1043e4b8fdcSSoby Mathew }; 1053e4b8fdcSSoby Mathew #endif 1063e4b8fdcSSoby Mathew #if IMAGE_BL2U 1073e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 1083e4b8fdcSSoby Mathew MAP_DEVICE0, 1093e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1103e4b8fdcSSoby Mathew {0} 1113e4b8fdcSSoby Mathew }; 1123e4b8fdcSSoby Mathew #endif 1133e4b8fdcSSoby Mathew #if IMAGE_BL31 1143e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 1153e4b8fdcSSoby Mathew ARM_MAP_SHARED_RAM, 1163e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1173e4b8fdcSSoby Mathew MAP_DEVICE0, 1183e4b8fdcSSoby Mathew MAP_DEVICE1, 1193e4b8fdcSSoby Mathew {0} 1203e4b8fdcSSoby Mathew }; 1213e4b8fdcSSoby Mathew #endif 1223e4b8fdcSSoby Mathew #if IMAGE_BL32 1233e4b8fdcSSoby Mathew const mmap_region_t plat_arm_mmap[] = { 124*877cf3ffSSoby Mathew #ifdef AARCH32 125*877cf3ffSSoby Mathew ARM_MAP_SHARED_RAM, 126*877cf3ffSSoby Mathew #endif 1273e4b8fdcSSoby Mathew V2M_MAP_IOFPGA, 1283e4b8fdcSSoby Mathew MAP_DEVICE0, 1293e4b8fdcSSoby Mathew MAP_DEVICE1, 1303e4b8fdcSSoby Mathew {0} 1313e4b8fdcSSoby Mathew }; 1323e4b8fdcSSoby Mathew #endif 1333e4b8fdcSSoby Mathew 1343e4b8fdcSSoby Mathew ARM_CASSERT_MMAP 1353e4b8fdcSSoby Mathew 1363e4b8fdcSSoby Mathew 1373e4b8fdcSSoby Mathew /******************************************************************************* 1383e4b8fdcSSoby Mathew * A single boot loader stack is expected to work on both the Foundation FVP 1393e4b8fdcSSoby Mathew * models and the two flavours of the Base FVP models (AEMv8 & Cortex). The 1403e4b8fdcSSoby Mathew * SYS_ID register provides a mechanism for detecting the differences between 1413e4b8fdcSSoby Mathew * these platforms. This information is stored in a per-BL array to allow the 1423e4b8fdcSSoby Mathew * code to take the correct path.Per BL platform configuration. 1433e4b8fdcSSoby Mathew ******************************************************************************/ 1443e4b8fdcSSoby Mathew void fvp_config_setup(void) 1453e4b8fdcSSoby Mathew { 1463e4b8fdcSSoby Mathew unsigned int rev, hbi, bld, arch, sys_id; 1473e4b8fdcSSoby Mathew 1483e4b8fdcSSoby Mathew sys_id = mmio_read_32(V2M_SYSREGS_BASE + V2M_SYS_ID); 1493e4b8fdcSSoby Mathew rev = (sys_id >> V2M_SYS_ID_REV_SHIFT) & V2M_SYS_ID_REV_MASK; 1503e4b8fdcSSoby Mathew hbi = (sys_id >> V2M_SYS_ID_HBI_SHIFT) & V2M_SYS_ID_HBI_MASK; 1513e4b8fdcSSoby Mathew bld = (sys_id >> V2M_SYS_ID_BLD_SHIFT) & V2M_SYS_ID_BLD_MASK; 1523e4b8fdcSSoby Mathew arch = (sys_id >> V2M_SYS_ID_ARCH_SHIFT) & V2M_SYS_ID_ARCH_MASK; 1533e4b8fdcSSoby Mathew 1543e4b8fdcSSoby Mathew if (arch != ARCH_MODEL) { 1553e4b8fdcSSoby Mathew ERROR("This firmware is for FVP models\n"); 1563e4b8fdcSSoby Mathew panic(); 1573e4b8fdcSSoby Mathew } 1583e4b8fdcSSoby Mathew 1593e4b8fdcSSoby Mathew /* 1603e4b8fdcSSoby Mathew * The build field in the SYS_ID tells which variant of the GIC 1613e4b8fdcSSoby Mathew * memory is implemented by the model. 1623e4b8fdcSSoby Mathew */ 1633e4b8fdcSSoby Mathew switch (bld) { 1643e4b8fdcSSoby Mathew case BLD_GIC_VE_MMAP: 16521a3973dSSoby Mathew ERROR("Legacy Versatile Express memory map for GIC peripheral" 16621a3973dSSoby Mathew " is not supported\n"); 1673e4b8fdcSSoby Mathew panic(); 1683e4b8fdcSSoby Mathew break; 1693e4b8fdcSSoby Mathew case BLD_GIC_A53A57_MMAP: 1703e4b8fdcSSoby Mathew break; 1713e4b8fdcSSoby Mathew default: 1723e4b8fdcSSoby Mathew ERROR("Unsupported board build %x\n", bld); 1733e4b8fdcSSoby Mathew panic(); 1743e4b8fdcSSoby Mathew } 1753e4b8fdcSSoby Mathew 1763e4b8fdcSSoby Mathew /* 1773e4b8fdcSSoby Mathew * The hbi field in the SYS_ID is 0x020 for the Base FVP & 0x010 1783e4b8fdcSSoby Mathew * for the Foundation FVP. 1793e4b8fdcSSoby Mathew */ 1803e4b8fdcSSoby Mathew switch (hbi) { 1813e4b8fdcSSoby Mathew case HBI_FOUNDATION_FVP: 1823e4b8fdcSSoby Mathew arm_config.flags = 0; 1833e4b8fdcSSoby Mathew 1843e4b8fdcSSoby Mathew /* 1853e4b8fdcSSoby Mathew * Check for supported revisions of Foundation FVP 1863e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 1873e4b8fdcSSoby Mathew */ 1883e4b8fdcSSoby Mathew switch (rev) { 1893e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_0: 1903e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_V2_1: 1913e4b8fdcSSoby Mathew case REV_FOUNDATION_FVP_v9_1: 1923e4b8fdcSSoby Mathew break; 1933e4b8fdcSSoby Mathew default: 1943e4b8fdcSSoby Mathew WARN("Unrecognized Foundation FVP revision %x\n", rev); 1953e4b8fdcSSoby Mathew break; 1963e4b8fdcSSoby Mathew } 1973e4b8fdcSSoby Mathew break; 1983e4b8fdcSSoby Mathew case HBI_BASE_FVP: 1993e4b8fdcSSoby Mathew arm_config.flags |= ARM_CONFIG_BASE_MMAP | 2003e4b8fdcSSoby Mathew ARM_CONFIG_HAS_INTERCONNECT | ARM_CONFIG_HAS_TZC; 2013e4b8fdcSSoby Mathew 2023e4b8fdcSSoby Mathew /* 2033e4b8fdcSSoby Mathew * Check for supported revisions 2043e4b8fdcSSoby Mathew * Allow future revisions to run but emit warning diagnostic 2053e4b8fdcSSoby Mathew */ 2063e4b8fdcSSoby Mathew switch (rev) { 2073e4b8fdcSSoby Mathew case REV_BASE_FVP_V0: 2083e4b8fdcSSoby Mathew break; 2093e4b8fdcSSoby Mathew default: 2103e4b8fdcSSoby Mathew WARN("Unrecognized Base FVP revision %x\n", rev); 2113e4b8fdcSSoby Mathew break; 2123e4b8fdcSSoby Mathew } 2133e4b8fdcSSoby Mathew break; 2143e4b8fdcSSoby Mathew default: 2153e4b8fdcSSoby Mathew ERROR("Unsupported board HBI number 0x%x\n", hbi); 2163e4b8fdcSSoby Mathew panic(); 2173e4b8fdcSSoby Mathew } 2183e4b8fdcSSoby Mathew } 2193e4b8fdcSSoby Mathew 2203e4b8fdcSSoby Mathew 2213e4b8fdcSSoby Mathew void fvp_interconnect_init(void) 2223e4b8fdcSSoby Mathew { 22371237876SSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) { 22471237876SSoby Mathew #if FVP_INTERCONNECT_DRIVER == FVP_CCN 22571237876SSoby Mathew if (ccn_get_part0_id(PLAT_ARM_CCN_BASE) != CCN_502_PART0_ID) { 22671237876SSoby Mathew ERROR("Unrecognized CCN variant detected. Only CCN-502" 22771237876SSoby Mathew " is supported"); 22871237876SSoby Mathew panic(); 22971237876SSoby Mathew } 23071237876SSoby Mathew #endif 2313e4b8fdcSSoby Mathew plat_arm_interconnect_init(); 2323e4b8fdcSSoby Mathew } 23371237876SSoby Mathew } 2343e4b8fdcSSoby Mathew 2353e4b8fdcSSoby Mathew void fvp_interconnect_enable(void) 2363e4b8fdcSSoby Mathew { 2373e4b8fdcSSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) 2383e4b8fdcSSoby Mathew plat_arm_interconnect_enter_coherency(); 2393e4b8fdcSSoby Mathew } 2403e4b8fdcSSoby Mathew 2413e4b8fdcSSoby Mathew void fvp_interconnect_disable(void) 2423e4b8fdcSSoby Mathew { 2433e4b8fdcSSoby Mathew if (arm_config.flags & ARM_CONFIG_HAS_INTERCONNECT) 2443e4b8fdcSSoby Mathew plat_arm_interconnect_exit_coherency(); 2453e4b8fdcSSoby Mathew } 246