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> 346063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux#include <debug.h> 354f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta#include <console.h> 3697043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <mmio.h> 3797043ac98e13a726dbf8b3b41654dca759e3da2cDan Handley#include <platform.h> 385f0cdb059d7d5c3a8a834074a7f236b85d014ddeDan Handley#include <platform_def.h> 398f55dfb4ba1a7c2cb5af355ff614923b6000864dSandrine Bailleux#include "../../bl1/bl1_private.h" 405f0cdb059d7d5c3a8a834074a7f236b85d014ddeDan Handley#include "fvp_def.h" 415f0cdb059d7d5c3a8a834074a7f236b85d014ddeDan Handley#include "fvp_private.h" 424f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 43ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew#if USE_COHERENT_MEM 444f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 454f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Declarations of linker defined symbols which will help us find the layout 464f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * of trusted SRAM 474f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 488d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __COHERENT_RAM_START__; 498d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleuxextern unsigned long __COHERENT_RAM_END__; 508d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux 518d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux/* 528d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * The next 2 constants identify the extents of the coherent memory region. 538d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * These addresses are used by the MMU setup code and therefore they must be 548d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * page-aligned. It is the responsibility of the linker script to ensure that 558d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 568d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux * page-aligned addresses. 578d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux */ 588d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 598d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux#define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 60ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew#endif 618d69a03f6a7db3c437b7cfdd15402627277d8cb4Sandrine Bailleux 624f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/* Data structure which holds the extents of the trusted SRAM for BL1*/ 63fb037bfb7cbf7b404c069b4ebac5a10059d948b1Dan Handleystatic meminfo_t bl1_tzram_layout; 644f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 65fb037bfb7cbf7b404c069b4ebac5a10059d948b1Dan Handleymeminfo_t *bl1_plat_sec_mem_layout(void) 664f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 67ee12f6f7497882fdcc8acc7774c516739296799eSandrine Bailleux return &bl1_tzram_layout; 684f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 694f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 704f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 714f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Perform any BL1 specific platform actions. 724f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 734f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_early_platform_setup(void) 744f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 756063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; 764f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 77770de65f9dc31f1c8045572bc48dc3bca12145c8Vikram Kanigiri /* Initialize the console to provide early debug support */ 78462c8350f6ed6b950609de1f72f00098440d3354Soby Mathew console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE); 79770de65f9dc31f1c8045572bc48dc3bca12145c8Vikram Kanigiri 806063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux /* Allow BL1 to see the whole Trusted RAM */ 81637ebd2eb9a40847fcd93a0ae3643aba6462c561Juan Castillo bl1_tzram_layout.total_base = FVP_TRUSTED_SRAM_BASE; 82637ebd2eb9a40847fcd93a0ae3643aba6462c561Juan Castillo bl1_tzram_layout.total_size = FVP_TRUSTED_SRAM_SIZE; 834f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 846063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux /* Calculate how much RAM BL1 is using and how much remains free */ 85637ebd2eb9a40847fcd93a0ae3643aba6462c561Juan Castillo bl1_tzram_layout.free_base = FVP_TRUSTED_SRAM_BASE; 86637ebd2eb9a40847fcd93a0ae3643aba6462c561Juan Castillo bl1_tzram_layout.free_size = FVP_TRUSTED_SRAM_SIZE; 876063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux reserve_mem(&bl1_tzram_layout.free_base, 886063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux &bl1_tzram_layout.free_size, 896063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux BL1_RAM_BASE, 906063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux bl1_size); 916063379902302dfcdfa9b8978b8a0dce44bd78f7Sandrine Bailleux 9230affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel /* Initialize the platform config for future decision making */ 9317a387ad5af5beacd8406f3f35cbf697e4ac3698Dan Handley fvp_config_setup(); 944f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 954f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 964f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 974f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Function which will evaluate how much of the trusted ram has been gobbled 984f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * up by BL1 and return the base and size of whats available for loading BL2. 994f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Its called after coherency and the MMU have been turned on. 1004f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 1014f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_platform_setup(void) 1024f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 1039d72b4ea9c7d9cac386f70d8a6581d4b1a45d7b0James Morrissey /* Initialise the IO layer and register platform IO devices */ 10417a387ad5af5beacd8406f3f35cbf697e4ac3698Dan Handley fvp_io_setup(); 1054f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 1064f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta 1079d72b4ea9c7d9cac386f70d8a6581d4b1a45d7b0James Morrissey 1084f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta/******************************************************************************* 1094f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta * Perform the very early platform specific architecture setup here. At the 11030affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * moment this only does basic initialization. Later architectural setup 11130affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel * (bl1_arch_setup()) does not do anything platform specific. 1124f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta ******************************************************************************/ 1134f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Guptavoid bl1_plat_arch_setup(void) 1144f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta{ 115cae3ef992e24b9ceb2ba1cd7d2ef0c6faaf29e0aDan Handley fvp_cci_init(); 116cae3ef992e24b9ceb2ba1cd7d2ef0c6faaf29e0aDan Handley fvp_cci_enable(); 11730affd563a98441155d3188f705c7b8be9e3ebefHarry Liebel 11817a387ad5af5beacd8406f3f35cbf697e4ac3698Dan Handley fvp_configure_mmu_el3(bl1_tzram_layout.total_base, 11917a387ad5af5beacd8406f3f35cbf697e4ac3698Dan Handley bl1_tzram_layout.total_size, 120637ebd2eb9a40847fcd93a0ae3643aba6462c561Juan Castillo BL1_RO_BASE, 121ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew BL1_RO_LIMIT 122ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew#if USE_COHERENT_MEM 123ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew , BL1_COHERENT_RAM_BASE, 124ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew BL1_COHERENT_RAM_LIMIT 125ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew#endif 126ab8707e6875a9fe447ff04fad9053d7d719f89e6Soby Mathew ); 1274f6ad66ae9fcc8bcb3b0fcee10b7ab1ffcaf1a5Achin Gupta} 1284112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri 1294112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri 1304112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri/******************************************************************************* 1314112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri * Before calling this function BL2 is loaded in memory and its entrypoint 1324112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri * is set by load_image. This is a placeholder for the platform to change 1334112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri * the entrypoint of BL2 and set SPSR and security state. 1344112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri * On FVP we are only setting the security state, entrypoint 1354112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri ******************************************************************************/ 1364112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigirivoid bl1_plat_set_bl2_ep_info(image_info_t *bl2_image, 1374112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri entry_point_info_t *bl2_ep) 1384112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri{ 1394112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri SET_SECURITY_STATE(bl2_ep->h.attr, SECURE); 1404112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); 1414112bfa0c223eda73af1cfe57ca7dc926f767dd8Vikram Kanigiri} 142