1e35d0edbSJorge Ramirez-Ortiz /* 29f85f9e3SJoel Hutton * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 3e35d0edbSJorge Ramirez-Ortiz * 4e35d0edbSJorge Ramirez-Ortiz * SPDX-License-Identifier: BSD-3-Clause 5e35d0edbSJorge Ramirez-Ortiz */ 6e35d0edbSJorge Ramirez-Ortiz 7e35d0edbSJorge Ramirez-Ortiz #include <assert.h> 8e35d0edbSJorge Ramirez-Ortiz #include <errno.h> 9e35d0edbSJorge Ramirez-Ortiz #include <string.h> 10*09d40e0eSAntonio Nino Diaz 11*09d40e0eSAntonio Nino Diaz #include <platform_def.h> 12*09d40e0eSAntonio Nino Diaz 13*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 14*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 15*09d40e0eSAntonio Nino Diaz #include <common/debug.h> 16*09d40e0eSAntonio Nino Diaz #include <common/tbbr/tbbr_img_def.h> 17*09d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h> 18*09d40e0eSAntonio Nino Diaz #include <drivers/arm/pl061_gpio.h> 19*09d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h> 20*09d40e0eSAntonio Nino Diaz #include <drivers/mmc.h> 21*09d40e0eSAntonio Nino Diaz #include <drivers/synopsys/dw_mmc.h> 22*09d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 23*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 24*09d40e0eSAntonio Nino Diaz 25*09d40e0eSAntonio Nino Diaz #include "../../../bl1/bl1_private.h" 26e35d0edbSJorge Ramirez-Ortiz #include "hi3798cv200.h" 27e35d0edbSJorge Ramirez-Ortiz #include "plat_private.h" 28e35d0edbSJorge Ramirez-Ortiz 29e35d0edbSJorge Ramirez-Ortiz /* Data structure which holds the extents of the trusted RAM for BL1 */ 30e35d0edbSJorge Ramirez-Ortiz static meminfo_t bl1_tzram_layout; 3182fbaa33SAntonio Nino Diaz static meminfo_t bl2_tzram_layout; 325c58c8b1SJerome Forissier static console_pl011_t console; 330d8052a4SVictor Chong 340d8052a4SVictor Chong /* 3582fbaa33SAntonio Nino Diaz * Cannot use default weak implementation in bl1_main.c because BL1 RW data is 3682fbaa33SAntonio Nino Diaz * not at the top of the secure memory. 370d8052a4SVictor Chong */ 3882fbaa33SAntonio Nino Diaz int bl1_plat_handle_post_image_load(unsigned int image_id) 3982fbaa33SAntonio Nino Diaz { 4082fbaa33SAntonio Nino Diaz image_desc_t *image_desc; 4182fbaa33SAntonio Nino Diaz entry_point_info_t *ep_info; 420d8052a4SVictor Chong 4382fbaa33SAntonio Nino Diaz if (image_id != BL2_IMAGE_ID) 4482fbaa33SAntonio Nino Diaz return 0; 4582fbaa33SAntonio Nino Diaz 4682fbaa33SAntonio Nino Diaz /* Get the image descriptor */ 4782fbaa33SAntonio Nino Diaz image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 4882fbaa33SAntonio Nino Diaz assert(image_desc != NULL); 4982fbaa33SAntonio Nino Diaz 5082fbaa33SAntonio Nino Diaz /* Get the entry point info */ 5182fbaa33SAntonio Nino Diaz ep_info = &image_desc->ep_info; 5282fbaa33SAntonio Nino Diaz 5382fbaa33SAntonio Nino Diaz bl2_tzram_layout.total_base = BL2_BASE; 5482fbaa33SAntonio Nino Diaz bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE; 5582fbaa33SAntonio Nino Diaz 5682fbaa33SAntonio Nino Diaz flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t)); 5782fbaa33SAntonio Nino Diaz 5882fbaa33SAntonio Nino Diaz ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout; 5982fbaa33SAntonio Nino Diaz 6082fbaa33SAntonio Nino Diaz VERBOSE("BL1: BL2 memory layout address = %p\n", 6182fbaa33SAntonio Nino Diaz (void *)&bl2_tzram_layout); 6282fbaa33SAntonio Nino Diaz 6382fbaa33SAntonio Nino Diaz return 0; 640d8052a4SVictor Chong } 650d8052a4SVictor Chong 66e35d0edbSJorge Ramirez-Ortiz void bl1_early_platform_setup(void) 67e35d0edbSJorge Ramirez-Ortiz { 68e35d0edbSJorge Ramirez-Ortiz /* Initialize the console to provide early debug support */ 695c58c8b1SJerome Forissier console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, 705c58c8b1SJerome Forissier PL011_BAUDRATE, &console); 71e35d0edbSJorge Ramirez-Ortiz 72e35d0edbSJorge Ramirez-Ortiz /* Allow BL1 to see the whole Trusted RAM */ 730d8052a4SVictor Chong bl1_tzram_layout.total_base = BL1_RW_BASE; 740d8052a4SVictor Chong bl1_tzram_layout.total_size = BL1_RW_SIZE; 75e35d0edbSJorge Ramirez-Ortiz 76e35d0edbSJorge Ramirez-Ortiz INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT, 77e35d0edbSJorge Ramirez-Ortiz BL1_RAM_LIMIT - BL1_RAM_BASE); 78e35d0edbSJorge Ramirez-Ortiz } 79e35d0edbSJorge Ramirez-Ortiz 80e35d0edbSJorge Ramirez-Ortiz void bl1_plat_arch_setup(void) 81e35d0edbSJorge Ramirez-Ortiz { 82e35d0edbSJorge Ramirez-Ortiz plat_configure_mmu_el3(bl1_tzram_layout.total_base, 83e35d0edbSJorge Ramirez-Ortiz bl1_tzram_layout.total_size, 840d8052a4SVictor Chong BL1_RO_BASE, /* l-loader and BL1 ROM */ 85e35d0edbSJorge Ramirez-Ortiz BL1_RO_LIMIT, 869f85f9e3SJoel Hutton BL_COHERENT_RAM_BASE, 879f85f9e3SJoel Hutton BL_COHERENT_RAM_END); 88e35d0edbSJorge Ramirez-Ortiz } 89e35d0edbSJorge Ramirez-Ortiz 90e35d0edbSJorge Ramirez-Ortiz void bl1_platform_setup(void) 91e35d0edbSJorge Ramirez-Ortiz { 92e35d0edbSJorge Ramirez-Ortiz int i; 9315b54e7bSVictor Chong #if !POPLAR_RECOVERY 94d5ed2946SShawn Guo struct mmc_device_info info; 9559149bbeSVictor Chong dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE); 9615b54e7bSVictor Chong #endif 97e35d0edbSJorge Ramirez-Ortiz 98e35d0edbSJorge Ramirez-Ortiz generic_delay_timer_init(); 99e35d0edbSJorge Ramirez-Ortiz 100e35d0edbSJorge Ramirez-Ortiz pl061_gpio_init(); 101e35d0edbSJorge Ramirez-Ortiz for (i = 0; i < GPIO_MAX; i++) 102e35d0edbSJorge Ramirez-Ortiz pl061_gpio_register(GPIO_BASE(i), i); 103e35d0edbSJorge Ramirez-Ortiz 10415b54e7bSVictor Chong #if !POPLAR_RECOVERY 10559149bbeSVictor Chong /* SoC-specific emmc register are initialized/configured by bootrom */ 10659149bbeSVictor Chong INFO("BL1: initializing emmc\n"); 107eba1b6b3SHaojian Zhuang info.mmc_dev_type = MMC_IS_EMMC; 108eba1b6b3SHaojian Zhuang dw_mmc_init(¶ms, &info); 10915b54e7bSVictor Chong #endif 11059149bbeSVictor Chong 111e35d0edbSJorge Ramirez-Ortiz plat_io_setup(); 112e35d0edbSJorge Ramirez-Ortiz } 113e35d0edbSJorge Ramirez-Ortiz 114e35d0edbSJorge Ramirez-Ortiz unsigned int bl1_plat_get_next_image_id(void) 115e35d0edbSJorge Ramirez-Ortiz { 116e35d0edbSJorge Ramirez-Ortiz return BL2_IMAGE_ID; 117e35d0edbSJorge Ramirez-Ortiz } 118