xref: /rk3399_ARM-atf/plat/arm/common/arm_bl2_el3_setup.c (revision d323af9e3d903d981b42f954844a95a6bfef91ab)
181528dbcSRoberto Vargas /*
288a0523eSAntonio Nino Diaz  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
381528dbcSRoberto Vargas  *
481528dbcSRoberto Vargas  * SPDX-License-Identifier: BSD-3-Clause
581528dbcSRoberto Vargas  */
6*d323af9eSDaniel Boulby #include <arm_def.h>
7*d323af9eSDaniel Boulby #include <assert.h>
881528dbcSRoberto Vargas #include <generic_delay_timer.h>
981528dbcSRoberto Vargas #include <plat_arm.h>
1081528dbcSRoberto Vargas #include <platform.h>
1181528dbcSRoberto Vargas 
1281528dbcSRoberto Vargas #pragma weak bl2_el3_early_platform_setup
1381528dbcSRoberto Vargas #pragma weak bl2_el3_plat_arch_setup
1481528dbcSRoberto Vargas #pragma weak bl2_el3_plat_prepare_exit
1581528dbcSRoberto Vargas 
16*d323af9eSDaniel Boulby #define MAP_BL2_EL3_TOTAL	MAP_REGION_FLAT(				\
17*d323af9eSDaniel Boulby 					bl2_el3_tzram_layout.total_base,	\
18*d323af9eSDaniel Boulby 					bl2_el3_tzram_layout.total_size,	\
19*d323af9eSDaniel Boulby 					MT_MEMORY | MT_RW | MT_SECURE)
20*d323af9eSDaniel Boulby 
2181528dbcSRoberto Vargas static meminfo_t bl2_el3_tzram_layout;
2281528dbcSRoberto Vargas 
2381528dbcSRoberto Vargas /*
2481528dbcSRoberto Vargas  * Perform arm specific early platform setup. At this moment we only initialize
2581528dbcSRoberto Vargas  * the console and the memory layout.
2681528dbcSRoberto Vargas  */
2781528dbcSRoberto Vargas void arm_bl2_el3_early_platform_setup(void)
2881528dbcSRoberto Vargas {
2981528dbcSRoberto Vargas 	/* Initialize the console to provide early debug support */
3088a0523eSAntonio Nino Diaz 	arm_console_boot_init();
3181528dbcSRoberto Vargas 
3281528dbcSRoberto Vargas 	/*
3381528dbcSRoberto Vargas 	 * Allow BL2 to see the whole Trusted RAM. This is determined
3481528dbcSRoberto Vargas 	 * statically since we cannot rely on BL1 passing this information
3581528dbcSRoberto Vargas 	 * in the BL2_AT_EL3 case.
3681528dbcSRoberto Vargas 	 */
3781528dbcSRoberto Vargas 	bl2_el3_tzram_layout.total_base = ARM_BL_RAM_BASE;
3881528dbcSRoberto Vargas 	bl2_el3_tzram_layout.total_size = ARM_BL_RAM_SIZE;
3981528dbcSRoberto Vargas 
4081528dbcSRoberto Vargas 	/* Initialise the IO layer and register platform IO devices */
4181528dbcSRoberto Vargas 	plat_arm_io_setup();
4281528dbcSRoberto Vargas }
4381528dbcSRoberto Vargas 
4481528dbcSRoberto Vargas void bl2_el3_early_platform_setup(u_register_t arg0 __unused,
4581528dbcSRoberto Vargas 				  u_register_t arg1 __unused,
4681528dbcSRoberto Vargas 				  u_register_t arg2 __unused,
4781528dbcSRoberto Vargas 				  u_register_t arg3 __unused)
4881528dbcSRoberto Vargas {
4981528dbcSRoberto Vargas 	arm_bl2_el3_early_platform_setup();
5081528dbcSRoberto Vargas 
5181528dbcSRoberto Vargas 	/*
5281528dbcSRoberto Vargas 	 * Initialize Interconnect for this cluster during cold boot.
5381528dbcSRoberto Vargas 	 * No need for locks as no other CPU is active.
5481528dbcSRoberto Vargas 	 */
5581528dbcSRoberto Vargas 	plat_arm_interconnect_init();
5681528dbcSRoberto Vargas 	/*
5781528dbcSRoberto Vargas 	 * Enable Interconnect coherency for the primary CPU's cluster.
5881528dbcSRoberto Vargas 	 */
5981528dbcSRoberto Vargas 	plat_arm_interconnect_enter_coherency();
6081528dbcSRoberto Vargas 
6181528dbcSRoberto Vargas 	generic_delay_timer_init();
6281528dbcSRoberto Vargas }
6381528dbcSRoberto Vargas 
6481528dbcSRoberto Vargas /*******************************************************************************
6581528dbcSRoberto Vargas  * Perform the very early platform specific architectural setup here. At the
6681528dbcSRoberto Vargas  * moment this is only initializes the mmu in a quick and dirty way.
6781528dbcSRoberto Vargas  ******************************************************************************/
6881528dbcSRoberto Vargas void arm_bl2_el3_plat_arch_setup(void)
6981528dbcSRoberto Vargas {
70*d323af9eSDaniel Boulby 
7181528dbcSRoberto Vargas #if USE_COHERENT_MEM
72*d323af9eSDaniel Boulby 	/* Ensure ARM platforms dont use coherent memory in BL2_AT_EL3 */
73*d323af9eSDaniel Boulby 	assert(BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE == 0U);
7481528dbcSRoberto Vargas #endif
75*d323af9eSDaniel Boulby 
76*d323af9eSDaniel Boulby 	const mmap_region_t bl_regions[] = {
77*d323af9eSDaniel Boulby 		MAP_BL2_EL3_TOTAL,
78*d323af9eSDaniel Boulby 		ARM_MAP_BL_CODE,
79*d323af9eSDaniel Boulby 		ARM_MAP_BL_RO_DATA,
80*d323af9eSDaniel Boulby 		{0}
81*d323af9eSDaniel Boulby 	};
82*d323af9eSDaniel Boulby 
83*d323af9eSDaniel Boulby 	arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
8481528dbcSRoberto Vargas 
8581528dbcSRoberto Vargas #ifdef AARCH32
8681528dbcSRoberto Vargas 	enable_mmu_secure(0);
8781528dbcSRoberto Vargas #else
8881528dbcSRoberto Vargas 	enable_mmu_el3(0);
8981528dbcSRoberto Vargas #endif
9081528dbcSRoberto Vargas }
9181528dbcSRoberto Vargas 
9281528dbcSRoberto Vargas void bl2_el3_plat_arch_setup(void)
9381528dbcSRoberto Vargas {
9481528dbcSRoberto Vargas 	arm_bl2_el3_plat_arch_setup();
9581528dbcSRoberto Vargas }
9681528dbcSRoberto Vargas 
9781528dbcSRoberto Vargas void bl2_el3_plat_prepare_exit(void)
9881528dbcSRoberto Vargas {
9981528dbcSRoberto Vargas }
100