xref: /rk3399_ARM-atf/plat/arm/common/arm_bl2_el3_setup.c (revision 402b3cf8766fe2cb4ae462f7ee7761d08a1ba56c)
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  */
609d40e0eSAntonio Nino Diaz 
7d323af9eSDaniel Boulby #include <assert.h>
809d40e0eSAntonio Nino Diaz 
909d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h>
10bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h>
1109d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
12234bc7f8SAntonio Nino Diaz #include <platform_def.h>
1309d40e0eSAntonio Nino Diaz 
1481528dbcSRoberto Vargas #pragma weak bl2_el3_early_platform_setup
1581528dbcSRoberto Vargas #pragma weak bl2_el3_plat_arch_setup
1681528dbcSRoberto Vargas #pragma weak bl2_el3_plat_prepare_exit
1781528dbcSRoberto Vargas 
18d323af9eSDaniel Boulby #define MAP_BL2_EL3_TOTAL	MAP_REGION_FLAT(				\
19d323af9eSDaniel Boulby 					bl2_el3_tzram_layout.total_base,	\
20d323af9eSDaniel Boulby 					bl2_el3_tzram_layout.total_size,	\
21d323af9eSDaniel Boulby 					MT_MEMORY | MT_RW | MT_SECURE)
22d323af9eSDaniel Boulby 
2381528dbcSRoberto Vargas static meminfo_t bl2_el3_tzram_layout;
2481528dbcSRoberto Vargas 
2581528dbcSRoberto Vargas /*
2681528dbcSRoberto Vargas  * Perform arm specific early platform setup. At this moment we only initialize
2781528dbcSRoberto Vargas  * the console and the memory layout.
2881528dbcSRoberto Vargas  */
2981528dbcSRoberto Vargas void arm_bl2_el3_early_platform_setup(void)
3081528dbcSRoberto Vargas {
3181528dbcSRoberto Vargas 	/* Initialize the console to provide early debug support */
3288a0523eSAntonio Nino Diaz 	arm_console_boot_init();
3381528dbcSRoberto Vargas 
3481528dbcSRoberto Vargas 	/*
3581528dbcSRoberto Vargas 	 * Allow BL2 to see the whole Trusted RAM. This is determined
3681528dbcSRoberto Vargas 	 * statically since we cannot rely on BL1 passing this information
3781528dbcSRoberto Vargas 	 * in the BL2_AT_EL3 case.
3881528dbcSRoberto Vargas 	 */
3981528dbcSRoberto Vargas 	bl2_el3_tzram_layout.total_base = ARM_BL_RAM_BASE;
4081528dbcSRoberto Vargas 	bl2_el3_tzram_layout.total_size = ARM_BL_RAM_SIZE;
4181528dbcSRoberto Vargas 
4281528dbcSRoberto Vargas 	/* Initialise the IO layer and register platform IO devices */
4381528dbcSRoberto Vargas 	plat_arm_io_setup();
4481528dbcSRoberto Vargas }
4581528dbcSRoberto Vargas 
4681528dbcSRoberto Vargas void bl2_el3_early_platform_setup(u_register_t arg0 __unused,
4781528dbcSRoberto Vargas 				  u_register_t arg1 __unused,
4881528dbcSRoberto Vargas 				  u_register_t arg2 __unused,
4981528dbcSRoberto Vargas 				  u_register_t arg3 __unused)
5081528dbcSRoberto Vargas {
5181528dbcSRoberto Vargas 	arm_bl2_el3_early_platform_setup();
5281528dbcSRoberto Vargas 
5381528dbcSRoberto Vargas 	/*
5481528dbcSRoberto Vargas 	 * Initialize Interconnect for this cluster during cold boot.
5581528dbcSRoberto Vargas 	 * No need for locks as no other CPU is active.
5681528dbcSRoberto Vargas 	 */
5781528dbcSRoberto Vargas 	plat_arm_interconnect_init();
5881528dbcSRoberto Vargas 	/*
5981528dbcSRoberto Vargas 	 * Enable Interconnect coherency for the primary CPU's cluster.
6081528dbcSRoberto Vargas 	 */
6181528dbcSRoberto Vargas 	plat_arm_interconnect_enter_coherency();
6281528dbcSRoberto Vargas 
6381528dbcSRoberto Vargas 	generic_delay_timer_init();
6481528dbcSRoberto Vargas }
6581528dbcSRoberto Vargas 
6681528dbcSRoberto Vargas /*******************************************************************************
6781528dbcSRoberto Vargas  * Perform the very early platform specific architectural setup here. At the
6881528dbcSRoberto Vargas  * moment this is only initializes the mmu in a quick and dirty way.
6981528dbcSRoberto Vargas  ******************************************************************************/
7081528dbcSRoberto Vargas void arm_bl2_el3_plat_arch_setup(void)
7181528dbcSRoberto Vargas {
72d323af9eSDaniel Boulby 
7381528dbcSRoberto Vargas #if USE_COHERENT_MEM
74d323af9eSDaniel Boulby 	/* Ensure ARM platforms dont use coherent memory in BL2_AT_EL3 */
75d323af9eSDaniel Boulby 	assert(BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE == 0U);
7681528dbcSRoberto Vargas #endif
77d323af9eSDaniel Boulby 
78d323af9eSDaniel Boulby 	const mmap_region_t bl_regions[] = {
79d323af9eSDaniel Boulby 		MAP_BL2_EL3_TOTAL,
802ecaafd2SDaniel Boulby 		ARM_MAP_BL_RO,
81d323af9eSDaniel Boulby 		{0}
82d323af9eSDaniel Boulby 	};
83d323af9eSDaniel Boulby 
840916c38dSRoberto Vargas 	setup_page_tables(bl_regions, plat_arm_get_mmap());
8581528dbcSRoberto Vargas 
86*402b3cf8SJulius Werner #ifdef __aarch64__
8781528dbcSRoberto Vargas 	enable_mmu_el3(0);
88*402b3cf8SJulius Werner #else
89*402b3cf8SJulius Werner 	enable_mmu_svc_mon(0);
9081528dbcSRoberto Vargas #endif
9181528dbcSRoberto Vargas }
9281528dbcSRoberto Vargas 
9381528dbcSRoberto Vargas void bl2_el3_plat_arch_setup(void)
9481528dbcSRoberto Vargas {
9581528dbcSRoberto Vargas 	arm_bl2_el3_plat_arch_setup();
9681528dbcSRoberto Vargas }
9781528dbcSRoberto Vargas 
9881528dbcSRoberto Vargas void bl2_el3_plat_prepare_exit(void)
9981528dbcSRoberto Vargas {
10081528dbcSRoberto Vargas }
101