1 /* 2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <errno.h> 9 10 #include <bl31/bl31.h> 11 #include <common/bl_common.h> 12 #include <common/debug.h> 13 #include <drivers/arm/pl011.h> 14 #include <drivers/console.h> 15 #include <lib/xlat_tables/xlat_tables.h> 16 #include <plat/common/platform.h> 17 18 #include "versal_private.h" 19 20 static entry_point_info_t bl32_image_ep_info; 21 static entry_point_info_t bl33_image_ep_info; 22 static console_pl011_t versal_runtime_console; 23 24 /* 25 * Return a pointer to the 'entry_point_info' structure of the next image for 26 * the security state specified. BL33 corresponds to the non-secure image type 27 * while BL32 corresponds to the secure image type. A NULL pointer is returned 28 * if the image does not exist. 29 */ 30 entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 31 { 32 assert(sec_state_is_valid(type)); 33 34 if (type == NON_SECURE) 35 return &bl33_image_ep_info; 36 37 return &bl32_image_ep_info; 38 } 39 40 /* 41 * Perform any BL31 specific platform actions. Here is an opportunity to copy 42 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they 43 * are lost (potentially). This needs to be done before the MMU is initialized 44 * so that the memory layout can be used while creating page tables. 45 */ 46 void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 47 u_register_t arg2, u_register_t arg3) 48 { 49 50 /* Initialize the console to provide early debug support */ 51 int rc = console_pl011_register(VERSAL_UART_BASE, 52 VERSAL_UART_CLOCK, 53 VERSAL_UART_BAUDRATE, 54 &versal_runtime_console); 55 if (rc == 0) 56 panic(); 57 58 console_set_scope(&versal_runtime_console.console, CONSOLE_FLAG_BOOT | 59 CONSOLE_FLAG_RUNTIME); 60 61 /* Initialize the platform config for future decision making */ 62 versal_config_setup(); 63 /* There are no parameters from BL2 if BL31 is a reset vector */ 64 assert(arg0 == 0U); 65 assert(arg1 == 0U); 66 67 /* 68 * Do initial security configuration to allow DRAM/device access. On 69 * Base VERSAL only DRAM security is programmable (via TrustZone), but 70 * other platforms might have more programmable security devices 71 * present. 72 */ 73 74 /* Populate common information for BL32 and BL33 */ 75 SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0); 76 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); 77 SET_PARAM_HEAD(&bl33_image_ep_info, PARAM_EP, VERSION_1, 0); 78 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); 79 80 /* use build time defaults in JTAG boot mode */ 81 bl32_image_ep_info.pc = BL32_BASE; 82 bl32_image_ep_info.spsr = 0; 83 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint(); 84 bl33_image_ep_info.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX, 85 DISABLE_ALL_EXCEPTIONS); 86 87 NOTICE("BL31: Secure code at 0x%lx\n", bl32_image_ep_info.pc); 88 NOTICE("BL31: Non secure code at 0x%lx\n", bl33_image_ep_info.pc); 89 } 90 91 void bl31_platform_setup(void) 92 { 93 /* Initialize the gic cpu and distributor interfaces */ 94 plat_versal_gic_driver_init(); 95 plat_versal_gic_init(); 96 } 97 98 void bl31_plat_runtime_setup(void) 99 { 100 } 101 102 /* 103 * Perform the very early platform specific architectural setup here. 104 */ 105 void bl31_plat_arch_setup(void) 106 { 107 const mmap_region_t bl_regions[] = { 108 MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE, 109 MT_MEMORY | MT_RW | MT_SECURE), 110 MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE, 111 MT_CODE | MT_SECURE), 112 MAP_REGION_FLAT(BL_RO_DATA_BASE, BL_RO_DATA_END - BL_RO_DATA_BASE, 113 MT_RO_DATA | MT_SECURE), 114 MAP_REGION_FLAT(BL_COHERENT_RAM_BASE, 115 BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE, 116 MT_DEVICE | MT_RW | MT_SECURE), 117 {0} 118 }; 119 120 setup_page_tables(bl_regions, plat_versal_get_mmap()); 121 enable_mmu_el3(0); 122 } 123