1e35d0edbSJorge Ramirez-Ortiz /* 20818e9e8SAntonio Nino Diaz * 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 <stddef.h> 10e35d0edbSJorge Ramirez-Ortiz #include <string.h> 1109d40e0eSAntonio Nino Diaz 1209d40e0eSAntonio Nino Diaz #include <platform_def.h> 1309d40e0eSAntonio Nino Diaz 1409d40e0eSAntonio Nino Diaz #include <arch.h> 1509d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 1609d40e0eSAntonio Nino Diaz #include <bl31/bl31.h> 1709d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1809d40e0eSAntonio Nino Diaz #include <common/debug.h> 1909d40e0eSAntonio Nino Diaz #include <cortex_a53.h> 2009d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h> 2109d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h> 2209d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 2309d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 2409d40e0eSAntonio Nino Diaz 25e35d0edbSJorge Ramirez-Ortiz #include "hi3798cv200.h" 26e35d0edbSJorge Ramirez-Ortiz #include "plat_private.h" 27e35d0edbSJorge Ramirez-Ortiz 28d45a1c30SJiancheng Xue #define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45) 29d45a1c30SJiancheng Xue 30f336774bSVictor Chong static entry_point_info_t bl32_image_ep_info; 31e35d0edbSJorge Ramirez-Ortiz static entry_point_info_t bl33_image_ep_info; 325c58c8b1SJerome Forissier static console_pl011_t console; 33e35d0edbSJorge Ramirez-Ortiz 34d45a1c30SJiancheng Xue static void hisi_tzpc_sec_init(void) 35d45a1c30SJiancheng Xue { 36d45a1c30SJiancheng Xue mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE); 37d45a1c30SJiancheng Xue } 38d45a1c30SJiancheng Xue 39e35d0edbSJorge Ramirez-Ortiz entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 40e35d0edbSJorge Ramirez-Ortiz { 41f336774bSVictor Chong entry_point_info_t *next_image_info; 42f336774bSVictor Chong 43f336774bSVictor Chong assert(sec_state_is_valid(type)); 44f336774bSVictor Chong next_image_info = (type == NON_SECURE) 45f336774bSVictor Chong ? &bl33_image_ep_info : &bl32_image_ep_info; 46f336774bSVictor Chong /* 47f336774bSVictor Chong * None of the images on the ARM development platforms can have 0x0 48f336774bSVictor Chong * as the entrypoint 49f336774bSVictor Chong */ 50f336774bSVictor Chong if (next_image_info->pc) 51f336774bSVictor Chong return next_image_info; 52f336774bSVictor Chong else 53f336774bSVictor Chong return NULL; 54e35d0edbSJorge Ramirez-Ortiz } 55e35d0edbSJorge Ramirez-Ortiz 560d8052a4SVictor Chong /******************************************************************************* 570d8052a4SVictor Chong * Perform any BL31 early platform setup common to ARM standard platforms. 580d8052a4SVictor Chong * Here is an opportunity to copy parameters passed by the calling EL (S-EL1 59a6238326SJohn Tsichritzis * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be 600d8052a4SVictor Chong * done before the MMU is initialized so that the memory layout can be used 610d8052a4SVictor Chong * while creating page tables. BL2 has flushed this information to memory, so 620d8052a4SVictor Chong * we are guaranteed to pick up good data. 630d8052a4SVictor Chong ******************************************************************************/ 6482fbaa33SAntonio Nino Diaz void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 6582fbaa33SAntonio Nino Diaz u_register_t arg2, u_register_t arg3) 66e35d0edbSJorge Ramirez-Ortiz { 6782fbaa33SAntonio Nino Diaz void *from_bl2; 6882fbaa33SAntonio Nino Diaz 6982fbaa33SAntonio Nino Diaz from_bl2 = (void *) arg0; 7082fbaa33SAntonio Nino Diaz 715c58c8b1SJerome Forissier console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, 725c58c8b1SJerome Forissier PL011_BAUDRATE, &console); 73e35d0edbSJorge Ramirez-Ortiz 74e35d0edbSJorge Ramirez-Ortiz /* Init console for crash report */ 75e35d0edbSJorge Ramirez-Ortiz plat_crash_console_init(); 76e35d0edbSJorge Ramirez-Ortiz 770d8052a4SVictor Chong /* 780d8052a4SVictor Chong * Check params passed from BL2 should not be NULL, 790d8052a4SVictor Chong */ 800d8052a4SVictor Chong bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; 810d8052a4SVictor Chong 820d8052a4SVictor Chong assert(params_from_bl2 != NULL); 830d8052a4SVictor Chong assert(params_from_bl2->h.type == PARAM_BL_PARAMS); 840d8052a4SVictor Chong assert(params_from_bl2->h.version >= VERSION_2); 850d8052a4SVictor Chong 860d8052a4SVictor Chong bl_params_node_t *bl_params = params_from_bl2->head; 870d8052a4SVictor Chong 880d8052a4SVictor Chong /* 890d8052a4SVictor Chong * Copy BL33 and BL32 (if present), entry point information. 900d8052a4SVictor Chong * They are stored in Secure RAM, in BL2's address space. 910d8052a4SVictor Chong */ 920d8052a4SVictor Chong while (bl_params) { 930d8052a4SVictor Chong if (bl_params->image_id == BL32_IMAGE_ID) 940d8052a4SVictor Chong bl32_image_ep_info = *bl_params->ep_info; 950d8052a4SVictor Chong 960d8052a4SVictor Chong if (bl_params->image_id == BL33_IMAGE_ID) 970d8052a4SVictor Chong bl33_image_ep_info = *bl_params->ep_info; 980d8052a4SVictor Chong 990d8052a4SVictor Chong bl_params = bl_params->next_params_info; 1000d8052a4SVictor Chong } 1010d8052a4SVictor Chong 1020d8052a4SVictor Chong if (bl33_image_ep_info.pc == 0) 1030d8052a4SVictor Chong panic(); 104e35d0edbSJorge Ramirez-Ortiz } 105e35d0edbSJorge Ramirez-Ortiz 106e35d0edbSJorge Ramirez-Ortiz void bl31_platform_setup(void) 107e35d0edbSJorge Ramirez-Ortiz { 108e35d0edbSJorge Ramirez-Ortiz /* Init arch timer */ 109e35d0edbSJorge Ramirez-Ortiz generic_delay_timer_init(); 110e35d0edbSJorge Ramirez-Ortiz 111e35d0edbSJorge Ramirez-Ortiz /* Init GIC distributor and CPU interface */ 1120818e9e8SAntonio Nino Diaz poplar_gic_driver_init(); 1130818e9e8SAntonio Nino Diaz poplar_gic_init(); 114d45a1c30SJiancheng Xue 115d45a1c30SJiancheng Xue /* Init security properties of IP blocks */ 116d45a1c30SJiancheng Xue hisi_tzpc_sec_init(); 117e35d0edbSJorge Ramirez-Ortiz } 118e35d0edbSJorge Ramirez-Ortiz 119e35d0edbSJorge Ramirez-Ortiz void bl31_plat_runtime_setup(void) 120e35d0edbSJorge Ramirez-Ortiz { 121e35d0edbSJorge Ramirez-Ortiz /* do nothing */ 122e35d0edbSJorge Ramirez-Ortiz } 123e35d0edbSJorge Ramirez-Ortiz 124e35d0edbSJorge Ramirez-Ortiz void bl31_plat_arch_setup(void) 125e35d0edbSJorge Ramirez-Ortiz { 1260d8052a4SVictor Chong plat_configure_mmu_el3(BL31_BASE, 1270d8052a4SVictor Chong (BL31_LIMIT - BL31_BASE), 128*f6605337SAntonio Nino Diaz BL_CODE_BASE, 129*f6605337SAntonio Nino Diaz BL_CODE_END, 130*f6605337SAntonio Nino Diaz BL_COHERENT_RAM_BASE, 131*f6605337SAntonio Nino Diaz BL_COHERENT_RAM_END); 132e35d0edbSJorge Ramirez-Ortiz 133e35d0edbSJorge Ramirez-Ortiz INFO("Boot BL33 from 0x%lx for %lu Bytes\n", 134e35d0edbSJorge Ramirez-Ortiz bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2); 135e35d0edbSJorge Ramirez-Ortiz } 136