1*6fba6e04STony Xie /* 2*6fba6e04STony Xie * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3*6fba6e04STony Xie * 4*6fba6e04STony Xie * Redistribution and use in source and binary forms, with or without 5*6fba6e04STony Xie * modification, are permitted provided that the following conditions are met: 6*6fba6e04STony Xie * 7*6fba6e04STony Xie * Redistributions of source code must retain the above copyright notice, this 8*6fba6e04STony Xie * list of conditions and the following disclaimer. 9*6fba6e04STony Xie * 10*6fba6e04STony Xie * Redistributions in binary form must reproduce the above copyright notice, 11*6fba6e04STony Xie * this list of conditions and the following disclaimer in the documentation 12*6fba6e04STony Xie * and/or other materials provided with the distribution. 13*6fba6e04STony Xie * 14*6fba6e04STony Xie * Neither the name of ARM nor the names of its contributors may be used 15*6fba6e04STony Xie * to endorse or promote products derived from this software without specific 16*6fba6e04STony Xie * prior written permission. 17*6fba6e04STony Xie * 18*6fba6e04STony Xie * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*6fba6e04STony Xie * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*6fba6e04STony Xie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*6fba6e04STony Xie * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*6fba6e04STony Xie * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*6fba6e04STony Xie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*6fba6e04STony Xie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*6fba6e04STony Xie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*6fba6e04STony Xie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*6fba6e04STony Xie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*6fba6e04STony Xie * POSSIBILITY OF SUCH DAMAGE. 29*6fba6e04STony Xie */ 30*6fba6e04STony Xie 31*6fba6e04STony Xie #include <arm_gic.h> 32*6fba6e04STony Xie #include <assert.h> 33*6fba6e04STony Xie #include <bl_common.h> 34*6fba6e04STony Xie #include <console.h> 35*6fba6e04STony Xie #include <debug.h> 36*6fba6e04STony Xie #include <mmio.h> 37*6fba6e04STony Xie #include <platform.h> 38*6fba6e04STony Xie #include <plat_private.h> 39*6fba6e04STony Xie #include <platform_def.h> 40*6fba6e04STony Xie 41*6fba6e04STony Xie /******************************************************************************* 42*6fba6e04STony Xie * Declarations of linker defined symbols which will help us find the layout 43*6fba6e04STony Xie * of trusted SRAM 44*6fba6e04STony Xie ******************************************************************************/ 45*6fba6e04STony Xie unsigned long __RO_START__; 46*6fba6e04STony Xie unsigned long __RO_END__; 47*6fba6e04STony Xie 48*6fba6e04STony Xie unsigned long __COHERENT_RAM_START__; 49*6fba6e04STony Xie unsigned long __COHERENT_RAM_END__; 50*6fba6e04STony Xie 51*6fba6e04STony Xie /* 52*6fba6e04STony Xie * The next 2 constants identify the extents of the code & RO data region. 53*6fba6e04STony Xie * These addresses are used by the MMU setup code and therefore they must be 54*6fba6e04STony Xie * page-aligned. It is the responsibility of the linker script to ensure that 55*6fba6e04STony Xie * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. 56*6fba6e04STony Xie */ 57*6fba6e04STony Xie #define BL31_RO_BASE (unsigned long)(&__RO_START__) 58*6fba6e04STony Xie #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) 59*6fba6e04STony Xie 60*6fba6e04STony Xie /* 61*6fba6e04STony Xie * The next 2 constants identify the extents of the coherent memory region. 62*6fba6e04STony Xie * These addresses are used by the MMU setup code and therefore they must be 63*6fba6e04STony Xie * page-aligned. It is the responsibility of the linker script to ensure that 64*6fba6e04STony Xie * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols 65*6fba6e04STony Xie * refer to page-aligned addresses. 66*6fba6e04STony Xie */ 67*6fba6e04STony Xie #define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) 68*6fba6e04STony Xie #define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) 69*6fba6e04STony Xie 70*6fba6e04STony Xie static entry_point_info_t bl32_ep_info; 71*6fba6e04STony Xie static entry_point_info_t bl33_ep_info; 72*6fba6e04STony Xie 73*6fba6e04STony Xie /******************************************************************************* 74*6fba6e04STony Xie * Return a pointer to the 'entry_point_info' structure of the next image for 75*6fba6e04STony Xie * the security state specified. BL33 corresponds to the non-secure image type 76*6fba6e04STony Xie * while BL32 corresponds to the secure image type. A NULL pointer is returned 77*6fba6e04STony Xie * if the image does not exist. 78*6fba6e04STony Xie ******************************************************************************/ 79*6fba6e04STony Xie entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 80*6fba6e04STony Xie { 81*6fba6e04STony Xie entry_point_info_t *next_image_info; 82*6fba6e04STony Xie 83*6fba6e04STony Xie next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; 84*6fba6e04STony Xie 85*6fba6e04STony Xie /* None of the images on this platform can have 0x0 as the entrypoint */ 86*6fba6e04STony Xie if (next_image_info->pc) 87*6fba6e04STony Xie return next_image_info; 88*6fba6e04STony Xie else 89*6fba6e04STony Xie return NULL; 90*6fba6e04STony Xie } 91*6fba6e04STony Xie 92*6fba6e04STony Xie /******************************************************************************* 93*6fba6e04STony Xie * Perform any BL3-1 early platform setup. Here is an opportunity to copy 94*6fba6e04STony Xie * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 95*6fba6e04STony Xie * are lost (potentially). This needs to be done before the MMU is initialized 96*6fba6e04STony Xie * so that the memory layout can be used while creating page tables. 97*6fba6e04STony Xie * BL2 has flushed this information to memory, so we are guaranteed to pick up 98*6fba6e04STony Xie * good data. 99*6fba6e04STony Xie ******************************************************************************/ 100*6fba6e04STony Xie void bl31_early_platform_setup(bl31_params_t *from_bl2, 101*6fba6e04STony Xie void *plat_params_from_bl2) 102*6fba6e04STony Xie { 103*6fba6e04STony Xie console_init(PLAT_RK_UART_BASE, PLAT_RK_UART_CLOCK, 104*6fba6e04STony Xie PLAT_RK_UART_BAUDRATE); 105*6fba6e04STony Xie 106*6fba6e04STony Xie VERBOSE("bl31_setup\n"); 107*6fba6e04STony Xie 108*6fba6e04STony Xie /* Passing a NULL context is a critical programming error */ 109*6fba6e04STony Xie assert(from_bl2); 110*6fba6e04STony Xie 111*6fba6e04STony Xie assert(from_bl2->h.type == PARAM_BL31); 112*6fba6e04STony Xie assert(from_bl2->h.version >= VERSION_1); 113*6fba6e04STony Xie 114*6fba6e04STony Xie bl32_ep_info = *from_bl2->bl32_ep_info; 115*6fba6e04STony Xie bl33_ep_info = *from_bl2->bl33_ep_info; 116*6fba6e04STony Xie 117*6fba6e04STony Xie /* 118*6fba6e04STony Xie * The code for resuming cpu from suspend must be excuted in pmusram. 119*6fba6e04STony Xie * Copy the code into pmusram. 120*6fba6e04STony Xie */ 121*6fba6e04STony Xie plat_rockchip_pmusram_prepare(); 122*6fba6e04STony Xie } 123*6fba6e04STony Xie 124*6fba6e04STony Xie /******************************************************************************* 125*6fba6e04STony Xie * Perform any BL3-1 platform setup code 126*6fba6e04STony Xie ******************************************************************************/ 127*6fba6e04STony Xie void bl31_platform_setup(void) 128*6fba6e04STony Xie { 129*6fba6e04STony Xie plat_delay_timer_init(); 130*6fba6e04STony Xie plat_rockchip_soc_init(); 131*6fba6e04STony Xie 132*6fba6e04STony Xie /* Initialize the gic cpu and distributor interfaces */ 133*6fba6e04STony Xie plat_rockchip_gic_driver_init(); 134*6fba6e04STony Xie plat_rockchip_gic_init(); 135*6fba6e04STony Xie plat_rockchip_pmu_init(); 136*6fba6e04STony Xie } 137*6fba6e04STony Xie 138*6fba6e04STony Xie /******************************************************************************* 139*6fba6e04STony Xie * Perform the very early platform specific architectural setup here. At the 140*6fba6e04STony Xie * moment this is only intializes the mmu in a quick and dirty way. 141*6fba6e04STony Xie ******************************************************************************/ 142*6fba6e04STony Xie void bl31_plat_arch_setup(void) 143*6fba6e04STony Xie { 144*6fba6e04STony Xie plat_cci_init(); 145*6fba6e04STony Xie plat_cci_enable(); 146*6fba6e04STony Xie plat_configure_mmu_el3(BL31_RO_BASE, 147*6fba6e04STony Xie (BL31_COHERENT_RAM_LIMIT - BL31_RO_BASE), 148*6fba6e04STony Xie BL31_RO_BASE, 149*6fba6e04STony Xie BL31_RO_LIMIT, 150*6fba6e04STony Xie BL31_COHERENT_RAM_BASE, 151*6fba6e04STony Xie BL31_COHERENT_RAM_LIMIT); 152*6fba6e04STony Xie } 153