1*b4315306SDan Handley /* 2*b4315306SDan Handley * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 3*b4315306SDan Handley * 4*b4315306SDan Handley * Redistribution and use in source and binary forms, with or without 5*b4315306SDan Handley * modification, are permitted provided that the following conditions are met: 6*b4315306SDan Handley * 7*b4315306SDan Handley * Redistributions of source code must retain the above copyright notice, this 8*b4315306SDan Handley * list of conditions and the following disclaimer. 9*b4315306SDan Handley * 10*b4315306SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 11*b4315306SDan Handley * this list of conditions and the following disclaimer in the documentation 12*b4315306SDan Handley * and/or other materials provided with the distribution. 13*b4315306SDan Handley * 14*b4315306SDan Handley * Neither the name of ARM nor the names of its contributors may be used 15*b4315306SDan Handley * to endorse or promote products derived from this software without specific 16*b4315306SDan Handley * prior written permission. 17*b4315306SDan Handley * 18*b4315306SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*b4315306SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*b4315306SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*b4315306SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*b4315306SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*b4315306SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*b4315306SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*b4315306SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*b4315306SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*b4315306SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*b4315306SDan Handley * POSSIBILITY OF SUCH DAMAGE. 29*b4315306SDan Handley */ 30*b4315306SDan Handley 31*b4315306SDan Handley #include <arch.h> 32*b4315306SDan Handley #include <arm_def.h> 33*b4315306SDan Handley #include <bl_common.h> 34*b4315306SDan Handley #include <cci.h> 35*b4315306SDan Handley #include <console.h> 36*b4315306SDan Handley #include <platform_def.h> 37*b4315306SDan Handley #include <plat_arm.h> 38*b4315306SDan Handley #include "../../bl1/bl1_private.h" 39*b4315306SDan Handley 40*b4315306SDan Handley 41*b4315306SDan Handley #if USE_COHERENT_MEM 42*b4315306SDan Handley /* 43*b4315306SDan Handley * The next 2 constants identify the extents of the coherent memory region. 44*b4315306SDan Handley * These addresses are used by the MMU setup code and therefore they must be 45*b4315306SDan Handley * page-aligned. It is the responsibility of the linker script to ensure that 46*b4315306SDan Handley * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to 47*b4315306SDan Handley * page-aligned addresses. 48*b4315306SDan Handley */ 49*b4315306SDan Handley #define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 50*b4315306SDan Handley #define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 51*b4315306SDan Handley #endif 52*b4315306SDan Handley 53*b4315306SDan Handley 54*b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */ 55*b4315306SDan Handley #pragma weak bl1_early_platform_setup 56*b4315306SDan Handley #pragma weak bl1_plat_arch_setup 57*b4315306SDan Handley #pragma weak bl1_platform_setup 58*b4315306SDan Handley #pragma weak bl1_plat_sec_mem_layout 59*b4315306SDan Handley #pragma weak bl1_plat_set_bl2_ep_info 60*b4315306SDan Handley 61*b4315306SDan Handley 62*b4315306SDan Handley /* Data structure which holds the extents of the trusted SRAM for BL1*/ 63*b4315306SDan Handley static meminfo_t bl1_tzram_layout; 64*b4315306SDan Handley 65*b4315306SDan Handley meminfo_t *bl1_plat_sec_mem_layout(void) 66*b4315306SDan Handley { 67*b4315306SDan Handley return &bl1_tzram_layout; 68*b4315306SDan Handley } 69*b4315306SDan Handley 70*b4315306SDan Handley /******************************************************************************* 71*b4315306SDan Handley * BL1 specific platform actions shared between ARM standard platforms. 72*b4315306SDan Handley ******************************************************************************/ 73*b4315306SDan Handley void arm_bl1_early_platform_setup(void) 74*b4315306SDan Handley { 75*b4315306SDan Handley const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; 76*b4315306SDan Handley 77*b4315306SDan Handley /* Initialize the console to provide early debug support */ 78*b4315306SDan Handley console_init(PLAT_ARM_BOOT_UART_BASE, PLAT_ARM_BOOT_UART_CLK_IN_HZ, 79*b4315306SDan Handley ARM_CONSOLE_BAUDRATE); 80*b4315306SDan Handley 81*b4315306SDan Handley /* Allow BL1 to see the whole Trusted RAM */ 82*b4315306SDan Handley bl1_tzram_layout.total_base = ARM_BL_RAM_BASE; 83*b4315306SDan Handley bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE; 84*b4315306SDan Handley 85*b4315306SDan Handley /* Calculate how much RAM BL1 is using and how much remains free */ 86*b4315306SDan Handley bl1_tzram_layout.free_base = ARM_BL_RAM_BASE; 87*b4315306SDan Handley bl1_tzram_layout.free_size = ARM_BL_RAM_SIZE; 88*b4315306SDan Handley reserve_mem(&bl1_tzram_layout.free_base, 89*b4315306SDan Handley &bl1_tzram_layout.free_size, 90*b4315306SDan Handley BL1_RAM_BASE, 91*b4315306SDan Handley bl1_size); 92*b4315306SDan Handley } 93*b4315306SDan Handley 94*b4315306SDan Handley void bl1_early_platform_setup(void) 95*b4315306SDan Handley { 96*b4315306SDan Handley arm_bl1_early_platform_setup(); 97*b4315306SDan Handley 98*b4315306SDan Handley /* 99*b4315306SDan Handley * Initialize CCI for this cluster during cold boot. 100*b4315306SDan Handley * No need for locks as no other CPU is active. 101*b4315306SDan Handley */ 102*b4315306SDan Handley arm_cci_init(); 103*b4315306SDan Handley /* 104*b4315306SDan Handley * Enable CCI coherency for the primary CPU's cluster. 105*b4315306SDan Handley */ 106*b4315306SDan Handley cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr())); 107*b4315306SDan Handley } 108*b4315306SDan Handley 109*b4315306SDan Handley /****************************************************************************** 110*b4315306SDan Handley * Perform the very early platform specific architecture setup shared between 111*b4315306SDan Handley * ARM standard platforms. This only does basic initialization. Later 112*b4315306SDan Handley * architectural setup (bl1_arch_setup()) does not do anything platform 113*b4315306SDan Handley * specific. 114*b4315306SDan Handley *****************************************************************************/ 115*b4315306SDan Handley void arm_bl1_plat_arch_setup(void) 116*b4315306SDan Handley { 117*b4315306SDan Handley arm_configure_mmu_el3(bl1_tzram_layout.total_base, 118*b4315306SDan Handley bl1_tzram_layout.total_size, 119*b4315306SDan Handley BL1_RO_BASE, 120*b4315306SDan Handley BL1_RO_LIMIT 121*b4315306SDan Handley #if USE_COHERENT_MEM 122*b4315306SDan Handley , BL1_COHERENT_RAM_BASE, 123*b4315306SDan Handley BL1_COHERENT_RAM_LIMIT 124*b4315306SDan Handley #endif 125*b4315306SDan Handley ); 126*b4315306SDan Handley } 127*b4315306SDan Handley 128*b4315306SDan Handley void bl1_plat_arch_setup(void) 129*b4315306SDan Handley { 130*b4315306SDan Handley arm_bl1_plat_arch_setup(); 131*b4315306SDan Handley } 132*b4315306SDan Handley 133*b4315306SDan Handley /* 134*b4315306SDan Handley * Perform the platform specific architecture setup shared between 135*b4315306SDan Handley * ARM standard platforms. 136*b4315306SDan Handley */ 137*b4315306SDan Handley void arm_bl1_platform_setup(void) 138*b4315306SDan Handley { 139*b4315306SDan Handley /* Initialise the IO layer and register platform IO devices */ 140*b4315306SDan Handley plat_arm_io_setup(); 141*b4315306SDan Handley } 142*b4315306SDan Handley 143*b4315306SDan Handley void bl1_platform_setup(void) 144*b4315306SDan Handley { 145*b4315306SDan Handley arm_bl1_platform_setup(); 146*b4315306SDan Handley } 147*b4315306SDan Handley 148*b4315306SDan Handley /******************************************************************************* 149*b4315306SDan Handley * Before calling this function BL2 is loaded in memory and its entrypoint 150*b4315306SDan Handley * is set by load_image. This is a placeholder for the platform to change 151*b4315306SDan Handley * the entrypoint of BL2 and set SPSR and security state. 152*b4315306SDan Handley * On ARM standard platforms we only set the security state of the entrypoint 153*b4315306SDan Handley ******************************************************************************/ 154*b4315306SDan Handley void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image, 155*b4315306SDan Handley entry_point_info_t *bl2_ep) 156*b4315306SDan Handley { 157*b4315306SDan Handley SET_SECURITY_STATE(bl2_ep->h.attr, SECURE); 158*b4315306SDan Handley bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); 159*b4315306SDan Handley } 160