181528dbcSRoberto Vargas /* 242d4d3baSArvind Ram Prakash * Copyright (c) 2017-2023, 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> 10*6ed98c45SHarsimran Singh Tungal #include <drivers/partition/partition.h> 11bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h> 1209d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 13234bc7f8SAntonio Nino Diaz #include <platform_def.h> 1409d40e0eSAntonio Nino Diaz 1581528dbcSRoberto Vargas #pragma weak bl2_el3_early_platform_setup 1681528dbcSRoberto Vargas #pragma weak bl2_el3_plat_arch_setup 1781528dbcSRoberto Vargas #pragma weak bl2_el3_plat_prepare_exit 1881528dbcSRoberto Vargas 19d323af9eSDaniel Boulby #define MAP_BL2_EL3_TOTAL MAP_REGION_FLAT( \ 20d323af9eSDaniel Boulby bl2_el3_tzram_layout.total_base, \ 21d323af9eSDaniel Boulby bl2_el3_tzram_layout.total_size, \ 22d323af9eSDaniel Boulby MT_MEMORY | MT_RW | MT_SECURE) 23d323af9eSDaniel Boulby 2481528dbcSRoberto Vargas static meminfo_t bl2_el3_tzram_layout; 2581528dbcSRoberto Vargas 2681528dbcSRoberto Vargas /* 2781528dbcSRoberto Vargas * Perform arm specific early platform setup. At this moment we only initialize 2881528dbcSRoberto Vargas * the console and the memory layout. 2981528dbcSRoberto Vargas */ 3081528dbcSRoberto Vargas void arm_bl2_el3_early_platform_setup(void) 3181528dbcSRoberto Vargas { 3281528dbcSRoberto Vargas /* Initialize the console to provide early debug support */ 3388a0523eSAntonio Nino Diaz arm_console_boot_init(); 3481528dbcSRoberto Vargas 3581528dbcSRoberto Vargas /* 3681528dbcSRoberto Vargas * Allow BL2 to see the whole Trusted RAM. This is determined 3781528dbcSRoberto Vargas * statically since we cannot rely on BL1 passing this information 3842d4d3baSArvind Ram Prakash * in the RESET_TO_BL2 case. 3981528dbcSRoberto Vargas */ 4081528dbcSRoberto Vargas bl2_el3_tzram_layout.total_base = ARM_BL_RAM_BASE; 4181528dbcSRoberto Vargas bl2_el3_tzram_layout.total_size = ARM_BL_RAM_SIZE; 4281528dbcSRoberto Vargas 4381528dbcSRoberto Vargas /* Initialise the IO layer and register platform IO devices */ 4481528dbcSRoberto Vargas plat_arm_io_setup(); 4581528dbcSRoberto Vargas } 4681528dbcSRoberto Vargas 4781528dbcSRoberto Vargas void bl2_el3_early_platform_setup(u_register_t arg0 __unused, 4881528dbcSRoberto Vargas u_register_t arg1 __unused, 4981528dbcSRoberto Vargas u_register_t arg2 __unused, 5081528dbcSRoberto Vargas u_register_t arg3 __unused) 5181528dbcSRoberto Vargas { 5281528dbcSRoberto Vargas arm_bl2_el3_early_platform_setup(); 5381528dbcSRoberto Vargas 5481528dbcSRoberto Vargas /* 5581528dbcSRoberto Vargas * Initialize Interconnect for this cluster during cold boot. 5681528dbcSRoberto Vargas * No need for locks as no other CPU is active. 5781528dbcSRoberto Vargas */ 5881528dbcSRoberto Vargas plat_arm_interconnect_init(); 5981528dbcSRoberto Vargas /* 6081528dbcSRoberto Vargas * Enable Interconnect coherency for the primary CPU's cluster. 6181528dbcSRoberto Vargas */ 6281528dbcSRoberto Vargas plat_arm_interconnect_enter_coherency(); 6381528dbcSRoberto Vargas 6481528dbcSRoberto Vargas generic_delay_timer_init(); 6581528dbcSRoberto Vargas } 6681528dbcSRoberto Vargas 6781528dbcSRoberto Vargas /******************************************************************************* 6881528dbcSRoberto Vargas * Perform the very early platform specific architectural setup here. At the 6981528dbcSRoberto Vargas * moment this is only initializes the mmu in a quick and dirty way. 7081528dbcSRoberto Vargas ******************************************************************************/ 7181528dbcSRoberto Vargas void arm_bl2_el3_plat_arch_setup(void) 7281528dbcSRoberto Vargas { 73d323af9eSDaniel Boulby 7481528dbcSRoberto Vargas #if USE_COHERENT_MEM 7542d4d3baSArvind Ram Prakash /* Ensure ARM platforms dont use coherent memory 7642d4d3baSArvind Ram Prakash * in RESET_TO_BL2 7742d4d3baSArvind Ram Prakash */ 78d323af9eSDaniel Boulby assert(BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE == 0U); 7981528dbcSRoberto Vargas #endif 80d323af9eSDaniel Boulby 81d323af9eSDaniel Boulby const mmap_region_t bl_regions[] = { 82d323af9eSDaniel Boulby MAP_BL2_EL3_TOTAL, 832ecaafd2SDaniel Boulby ARM_MAP_BL_RO, 84d323af9eSDaniel Boulby {0} 85d323af9eSDaniel Boulby }; 86d323af9eSDaniel Boulby 870916c38dSRoberto Vargas setup_page_tables(bl_regions, plat_arm_get_mmap()); 8881528dbcSRoberto Vargas 89402b3cf8SJulius Werner #ifdef __aarch64__ 9081528dbcSRoberto Vargas enable_mmu_el3(0); 91402b3cf8SJulius Werner #else 92402b3cf8SJulius Werner enable_mmu_svc_mon(0); 9381528dbcSRoberto Vargas #endif 9481528dbcSRoberto Vargas } 9581528dbcSRoberto Vargas 9681528dbcSRoberto Vargas void bl2_el3_plat_arch_setup(void) 9781528dbcSRoberto Vargas { 98*6ed98c45SHarsimran Singh Tungal int __maybe_unused ret; 9981528dbcSRoberto Vargas arm_bl2_el3_plat_arch_setup(); 100*6ed98c45SHarsimran Singh Tungal #if ARM_GPT_SUPPORT 101*6ed98c45SHarsimran Singh Tungal ret = gpt_partition_init(); 102*6ed98c45SHarsimran Singh Tungal if (ret != 0) { 103*6ed98c45SHarsimran Singh Tungal ERROR("GPT partition initialisation failed!\n"); 104*6ed98c45SHarsimran Singh Tungal panic(); 105*6ed98c45SHarsimran Singh Tungal } 106*6ed98c45SHarsimran Singh Tungal #endif /* ARM_GPT_SUPPORT */ 10781528dbcSRoberto Vargas } 10881528dbcSRoberto Vargas 10981528dbcSRoberto Vargas void bl2_el3_plat_prepare_exit(void) 11081528dbcSRoberto Vargas { 11181528dbcSRoberto Vargas } 112