1 /* 2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch.h> 8 #include <arch_helpers.h> 9 #include <platform_def.h> 10 #include <assert.h> 11 #include <bl_common.h> 12 #include <pl011.h> 13 #include <debug.h> 14 15 static console_pl011_t console; 16 static entry_point_info_t bl32_image_ep_info; 17 static entry_point_info_t bl33_image_ep_info; 18 19 entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 20 { 21 assert(sec_state_is_valid(type)); 22 return type == NON_SECURE ? &bl33_image_ep_info : &bl32_image_ep_info; 23 } 24 25 /******************************************************************************* 26 * Gets SPSR for BL32 entry 27 ******************************************************************************/ 28 uint32_t sq_get_spsr_for_bl32_entry(void) 29 { 30 /* 31 * The Secure Payload Dispatcher service is responsible for 32 * setting the SPSR prior to entry into the BL32 image. 33 */ 34 return 0; 35 } 36 37 /******************************************************************************* 38 * Gets SPSR for BL33 entry 39 ******************************************************************************/ 40 uint32_t sq_get_spsr_for_bl33_entry(void) 41 { 42 unsigned long el_status; 43 unsigned int mode; 44 uint32_t spsr; 45 46 /* Figure out what mode we enter the non-secure world in */ 47 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT; 48 el_status &= ID_AA64PFR0_ELX_MASK; 49 50 mode = (el_status) ? MODE_EL2 : MODE_EL1; 51 52 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); 53 return spsr; 54 } 55 56 void bl31_early_platform_setup(bl31_params_t *from_bl2, 57 void *plat_params_from_bl2) 58 { 59 /* Initialize the console to provide early debug support */ 60 (void)console_pl011_register(PLAT_SQ_BOOT_UART_BASE, 61 PLAT_SQ_BOOT_UART_CLK_IN_HZ, 62 SQ_CONSOLE_BAUDRATE, &console); 63 64 console_set_scope(&console.console, CONSOLE_FLAG_BOOT | 65 CONSOLE_FLAG_RUNTIME); 66 67 /* There are no parameters from BL2 if BL31 is a reset vector */ 68 assert(from_bl2 == NULL); 69 assert(plat_params_from_bl2 == NULL); 70 71 #ifdef BL32_BASE 72 /* Populate entry point information for BL32 */ 73 SET_PARAM_HEAD(&bl32_image_ep_info, 74 PARAM_EP, 75 VERSION_1, 76 0); 77 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); 78 bl32_image_ep_info.pc = BL32_BASE; 79 bl32_image_ep_info.spsr = sq_get_spsr_for_bl32_entry(); 80 #endif /* BL32_BASE */ 81 82 /* Populate entry point information for BL33 */ 83 SET_PARAM_HEAD(&bl33_image_ep_info, 84 PARAM_EP, 85 VERSION_1, 86 0); 87 /* 88 * Tell BL31 where the non-trusted software image 89 * is located and the entry state information 90 */ 91 bl33_image_ep_info.pc = PRELOADED_BL33_BASE; 92 bl33_image_ep_info.spsr = sq_get_spsr_for_bl33_entry(); 93 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); 94 } 95 96 void bl31_platform_setup(void) 97 { 98 } 99 100 void bl31_plat_runtime_setup(void) 101 { 102 } 103 104 void bl31_plat_arch_setup(void) 105 { 106 } 107