xref: /rk3399_ARM-atf/plat/hisilicon/poplar/bl31_plat_setup.c (revision 72ac9810449b32ac321b85f495e3753ac955ca4d)
1e35d0edbSJorge Ramirez-Ortiz /*
2*d51a6326SSalman Nabi  * Copyright (c) 2017-2024, 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>
94ce3e99aSScott Branden #include <inttypes.h>
10e35d0edbSJorge Ramirez-Ortiz #include <stddef.h>
114ce3e99aSScott Branden #include <stdint.h>
12e35d0edbSJorge Ramirez-Ortiz #include <string.h>
1309d40e0eSAntonio Nino Diaz 
1409d40e0eSAntonio Nino Diaz #include <platform_def.h>
1509d40e0eSAntonio Nino Diaz 
1609d40e0eSAntonio Nino Diaz #include <arch.h>
1709d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1809d40e0eSAntonio Nino Diaz #include <bl31/bl31.h>
1909d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
2009d40e0eSAntonio Nino Diaz #include <common/debug.h>
2109d40e0eSAntonio Nino Diaz #include <cortex_a53.h>
2209d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h>
2309d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h>
2409d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
2509d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
2609d40e0eSAntonio Nino Diaz 
27e35d0edbSJorge Ramirez-Ortiz #include "hi3798cv200.h"
28e35d0edbSJorge Ramirez-Ortiz #include "plat_private.h"
29e35d0edbSJorge Ramirez-Ortiz 
30d45a1c30SJiancheng Xue #define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45)
31d45a1c30SJiancheng Xue 
32f336774bSVictor Chong static entry_point_info_t bl32_image_ep_info;
33e35d0edbSJorge Ramirez-Ortiz static entry_point_info_t bl33_image_ep_info;
34f695e1e0SAndre Przywara static console_t console;
35e35d0edbSJorge Ramirez-Ortiz 
hisi_tzpc_sec_init(void)36d45a1c30SJiancheng Xue static void hisi_tzpc_sec_init(void)
37d45a1c30SJiancheng Xue {
38d45a1c30SJiancheng Xue 	mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE);
39d45a1c30SJiancheng Xue }
40d45a1c30SJiancheng Xue 
bl31_plat_get_next_image_ep_info(uint32_t type)41e35d0edbSJorge Ramirez-Ortiz entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
42e35d0edbSJorge Ramirez-Ortiz {
43f336774bSVictor Chong 	entry_point_info_t *next_image_info;
44f336774bSVictor Chong 
45f336774bSVictor Chong 	assert(sec_state_is_valid(type));
46f336774bSVictor Chong 	next_image_info = (type == NON_SECURE)
47f336774bSVictor Chong 			? &bl33_image_ep_info : &bl32_image_ep_info;
48f336774bSVictor Chong 	/*
49f336774bSVictor Chong 	 * None of the images on the ARM development platforms can have 0x0
50f336774bSVictor Chong 	 * as the entrypoint
51f336774bSVictor Chong 	 */
52f336774bSVictor Chong 	if (next_image_info->pc)
53f336774bSVictor Chong 		return next_image_info;
54f336774bSVictor Chong 	else
55f336774bSVictor Chong 		return NULL;
56e35d0edbSJorge Ramirez-Ortiz }
57e35d0edbSJorge Ramirez-Ortiz 
580d8052a4SVictor Chong /*******************************************************************************
590d8052a4SVictor Chong  * Perform any BL31 early platform setup common to ARM standard platforms.
600d8052a4SVictor Chong  * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
61a6238326SJohn Tsichritzis  * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
620d8052a4SVictor Chong  * done before the MMU is initialized so that the memory layout can be used
630d8052a4SVictor Chong  * while creating page tables. BL2 has flushed this information to memory, so
640d8052a4SVictor Chong  * we are guaranteed to pick up good data.
650d8052a4SVictor Chong  ******************************************************************************/
bl31_early_platform_setup2(u_register_t arg0,u_register_t arg1,u_register_t arg2,u_register_t arg3)6682fbaa33SAntonio Nino Diaz void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
6782fbaa33SAntonio Nino Diaz 				u_register_t arg2, u_register_t arg3)
68e35d0edbSJorge Ramirez-Ortiz {
6982fbaa33SAntonio Nino Diaz 	void *from_bl2;
7082fbaa33SAntonio Nino Diaz 
7182fbaa33SAntonio Nino Diaz 	from_bl2 = (void *) arg0;
7282fbaa33SAntonio Nino Diaz 
735c58c8b1SJerome Forissier 	console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
745c58c8b1SJerome Forissier 			       PL011_BAUDRATE, &console);
75e35d0edbSJorge Ramirez-Ortiz 
76e35d0edbSJorge Ramirez-Ortiz 	/* Init console for crash report */
77e35d0edbSJorge Ramirez-Ortiz 	plat_crash_console_init();
78e35d0edbSJorge Ramirez-Ortiz 
790d8052a4SVictor Chong 	/*
800d8052a4SVictor Chong 	 * Check params passed from BL2 should not be NULL,
810d8052a4SVictor Chong 	 */
820d8052a4SVictor Chong 	bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
830d8052a4SVictor Chong 
840d8052a4SVictor Chong 	assert(params_from_bl2 != NULL);
850d8052a4SVictor Chong 	assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
860d8052a4SVictor Chong 	assert(params_from_bl2->h.version >= VERSION_2);
870d8052a4SVictor Chong 
880d8052a4SVictor Chong 	bl_params_node_t *bl_params = params_from_bl2->head;
890d8052a4SVictor Chong 
900d8052a4SVictor Chong 	/*
910d8052a4SVictor Chong 	 * Copy BL33 and BL32 (if present), entry point information.
920d8052a4SVictor Chong 	 * They are stored in Secure RAM, in BL2's address space.
930d8052a4SVictor Chong 	 */
940d8052a4SVictor Chong 	while (bl_params) {
950d8052a4SVictor Chong 		if (bl_params->image_id == BL32_IMAGE_ID)
960d8052a4SVictor Chong 			bl32_image_ep_info = *bl_params->ep_info;
970d8052a4SVictor Chong 
980d8052a4SVictor Chong 		if (bl_params->image_id == BL33_IMAGE_ID)
990d8052a4SVictor Chong 			bl33_image_ep_info = *bl_params->ep_info;
1000d8052a4SVictor Chong 
1010d8052a4SVictor Chong 		bl_params = bl_params->next_params_info;
1020d8052a4SVictor Chong 	}
1030d8052a4SVictor Chong 
1040d8052a4SVictor Chong 	if (bl33_image_ep_info.pc == 0)
1050d8052a4SVictor Chong 		panic();
106e35d0edbSJorge Ramirez-Ortiz }
107e35d0edbSJorge Ramirez-Ortiz 
bl31_platform_setup(void)108e35d0edbSJorge Ramirez-Ortiz void bl31_platform_setup(void)
109e35d0edbSJorge Ramirez-Ortiz {
110e35d0edbSJorge Ramirez-Ortiz 	/* Init arch timer */
111e35d0edbSJorge Ramirez-Ortiz 	generic_delay_timer_init();
112e35d0edbSJorge Ramirez-Ortiz 
113e35d0edbSJorge Ramirez-Ortiz 	/* Init GIC distributor and CPU interface */
1140818e9e8SAntonio Nino Diaz 	poplar_gic_driver_init();
1150818e9e8SAntonio Nino Diaz 	poplar_gic_init();
116d45a1c30SJiancheng Xue 
117d45a1c30SJiancheng Xue 	/* Init security properties of IP blocks */
118d45a1c30SJiancheng Xue 	hisi_tzpc_sec_init();
119e35d0edbSJorge Ramirez-Ortiz }
120e35d0edbSJorge Ramirez-Ortiz 
bl31_plat_arch_setup(void)121e35d0edbSJorge Ramirez-Ortiz void bl31_plat_arch_setup(void)
122e35d0edbSJorge Ramirez-Ortiz {
1230d8052a4SVictor Chong 	plat_configure_mmu_el3(BL31_BASE,
1240d8052a4SVictor Chong 			       (BL31_LIMIT - BL31_BASE),
125f6605337SAntonio Nino Diaz 			       BL_CODE_BASE,
126f6605337SAntonio Nino Diaz 			       BL_CODE_END,
127f6605337SAntonio Nino Diaz 			       BL_COHERENT_RAM_BASE,
128f6605337SAntonio Nino Diaz 			       BL_COHERENT_RAM_END);
129e35d0edbSJorge Ramirez-Ortiz 
1304ce3e99aSScott Branden 	INFO("Boot BL33 from 0x%lx for %" PRIu64 " Bytes\n",
131e35d0edbSJorge Ramirez-Ortiz 	     bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2);
132e35d0edbSJorge Ramirez-Ortiz }
133