bl1_fvp_setup.c revision 97043ac98e13a726dbf8b3b41654dca759e3da2c
14f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/* 2e83b0cadc67882c1ba7f430d16dab80c9b3a0228Dan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 34f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 44f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Redistribution and use in source and binary forms, with or without 54f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * modification, are permitted provided that the following conditions are met: 64f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 74f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Redistributions of source code must retain the above copyright notice, this 84f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * list of conditions and the following disclaimer. 94f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 104f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Redistributions in binary form must reproduce the above copyright notice, 114f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * this list of conditions and the following disclaimer in the documentation 124f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * and/or other materials provided with the distribution. 134f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 144f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Neither the name of ARM nor the names of its contributors may be used 154f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * to endorse or promote products derived from this software without specific 164f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * prior written permission. 174f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * 184f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * POSSIBILITY OF SUCH DAMAGE. 294f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 304f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 314f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#include <arch_helpers.h> 3297043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <assert.h> 3397043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <bl_common.h> 344f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#include <bl1.h> 354f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#include <console.h> 3630affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel#include <cci400.h> 3797043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <mmio.h> 3897043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <platform.h> 394f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 404f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 414f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Declarations of linker defined symbols which will help us find the layout 424f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * of trusted SRAM 434f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 448d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __COHERENT_RAM_START__; 458d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __COHERENT_RAM_END__; 468d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux 478d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __BL1_RAM_START__; 488d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __BL1_RAM_END__; 498d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux 508d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux/* 518d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * The next 2 constants identify the extents of the coherent memory region. 528d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * These addresses are used by the MMU setup code and therefore they must be 538d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * page-aligned. It is the responsibility of the linker script to ensure that 548d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 558d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * page-aligned addresses. 568d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux */ 578d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 588d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 598d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux 608d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_RAM_BASE (unsigned long)(&__BL1_RAM_START__) 618d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_RAM_LIMIT (unsigned long)(&__BL1_RAM_END__) 624f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 634f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 644f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/* Data structure which holds the extents of the trusted SRAM for BL1*/ 65fb037bfb7cbf7b404c069b4ebac5a10059d948b1Dan Handleystatic meminfo_t bl1_tzram_layout; 664f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 67fb037bfb7cbf7b404c069b4ebac5a10059d948b1Dan Handleymeminfo_t *bl1_plat_sec_mem_layout(void) 684f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 69ee12f6f7497882fdcc8acc7774c516739296799eSandrine Bailleux return &bl1_tzram_layout; 704f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 714f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 724f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 734f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Perform any BL1 specific platform actions. 744f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 754f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_early_platform_setup(void) 764f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 778d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux const unsigned long bl1_ram_base = BL1_RAM_BASE; 788d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux const unsigned long bl1_ram_limit = BL1_RAM_LIMIT; 798d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux const unsigned long tzram_limit = TZRAM_BASE + TZRAM_SIZE; 804f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 814f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta /* 824f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Calculate how much ram is BL1 using & how much remains free. 834f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * This also includes a rudimentary mechanism to detect whether 844f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * the BL1 data is loaded at the top or bottom of memory. 854f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * TODO: add support for discontigous chunks of free ram if 864f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * needed. Might need dynamic memory allocation support 874f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * et al. 884f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta */ 894f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta bl1_tzram_layout.total_base = TZRAM_BASE; 904f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta bl1_tzram_layout.total_size = TZRAM_SIZE; 914f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 928d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux if (bl1_ram_limit == tzram_limit) { 938d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux /* BL1 has been loaded at the top of memory. */ 944f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta bl1_tzram_layout.free_base = TZRAM_BASE; 958d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux bl1_tzram_layout.free_size = bl1_ram_base - TZRAM_BASE; 964f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta } else { 978d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux /* BL1 has been loaded at the bottom of memory. */ 988d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux bl1_tzram_layout.free_base = bl1_ram_limit; 994f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta bl1_tzram_layout.free_size = 1008d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux tzram_limit - bl1_ram_limit; 1014f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta } 10230affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel 10330affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel /* Initialize the platform config for future decision making */ 10430affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel platform_config_setup(); 10520d284c08d81c288c821ba6878d005dd89c6cfaaSandrine Bailleux 10620d284c08d81c288c821ba6878d005dd89c6cfaaSandrine Bailleux /* Initialize the console */ 10720d284c08d81c288c821ba6878d005dd89c6cfaaSandrine Bailleux console_init(PL011_UART0_BASE); 1084f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 1094f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 1104f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 1114f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Function which will evaluate how much of the trusted ram has been gobbled 1124f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * up by BL1 and return the base and size of whats available for loading BL2. 1134f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Its called after coherency and the MMU have been turned on. 1144f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 1154f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_platform_setup(void) 1164f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 1179d72b4ea9c7d9cac386f70d8a6581d4b1a45d7b0James Morrissey /* Initialise the IO layer and register platform IO devices */ 1189d72b4ea9c7d9cac386f70d8a6581d4b1a45d7b0James Morrissey io_setup(); 1194f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 1204f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 1219d72b4ea9c7d9cac386f70d8a6581d4b1a45d7b0James Morrissey 1224f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 1234f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Perform the very early platform specific architecture setup here. At the 12430affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * moment this only does basic initialization. Later architectural setup 12530affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * (bl1_arch_setup()) does not do anything platform specific. 1264f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 1274f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_plat_arch_setup(void) 1284f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 12930affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel unsigned long cci_setup; 13030affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel 13130affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel /* 13230affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * Enable CCI-400 for this cluster. No need 13330affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * for locks as no other cpu is active at the 13430affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * moment 13530affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel */ 13630affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel cci_setup = platform_get_cfgvar(CONFIG_HAS_CCI); 13730affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel if (cci_setup) { 13830affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel cci_enable_coherency(read_mpidr()); 13930affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel } 14030affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel 1414f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta configure_mmu(&bl1_tzram_layout, 1428468739c5f19928240934f80c6582e45985bf975Ian Spray TZROM_BASE, 1438468739c5f19928240934f80c6582e45985bf975Ian Spray TZROM_BASE + TZROM_SIZE, 1448468739c5f19928240934f80c6582e45985bf975Ian Spray BL1_COHERENT_RAM_BASE, 1458468739c5f19928240934f80c6582e45985bf975Ian Spray BL1_COHERENT_RAM_LIMIT); 1464f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 147