Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <bl_common.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 9 | #include <platform.h> |
| 10 | #include <platform_def.h> |
| 11 | #include <xlat_mmu_helpers.h> |
| 12 | #include <xlat_tables_defs.h> |
| 13 | |
| 14 | #include "rpi3_private.h" |
| 15 | |
| 16 | #define BL31_END (uintptr_t)(&__BL31_END__) |
| 17 | |
| 18 | /* |
| 19 | * Placeholder variables for copying the arguments that have been passed to |
| 20 | * BL31 from BL2. |
| 21 | */ |
| 22 | static entry_point_info_t bl32_image_ep_info; |
| 23 | static entry_point_info_t bl33_image_ep_info; |
| 24 | |
| 25 | /******************************************************************************* |
| 26 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 27 | * the security state specified. BL33 corresponds to the non-secure image type |
| 28 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 29 | * if the image does not exist. |
| 30 | ******************************************************************************/ |
| 31 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 32 | { |
| 33 | entry_point_info_t *next_image_info; |
| 34 | |
| 35 | assert(sec_state_is_valid(type) != 0); |
| 36 | |
| 37 | next_image_info = (type == NON_SECURE) |
| 38 | ? &bl33_image_ep_info : &bl32_image_ep_info; |
| 39 | |
| 40 | /* None of the images can have 0x0 as the entrypoint. */ |
| 41 | if (next_image_info->pc) { |
| 42 | return next_image_info; |
| 43 | } else { |
| 44 | return NULL; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /******************************************************************************* |
| 49 | * Perform any BL31 early platform setup. Here is an opportunity to copy |
| 50 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before |
| 51 | * they are lost (potentially). This needs to be done before the MMU is |
| 52 | * initialized so that the memory layout can be used while creating page |
| 53 | * tables. BL2 has flushed this information to memory, so we are guaranteed |
| 54 | * to pick up good data. |
| 55 | ******************************************************************************/ |
| 56 | void bl31_early_platform_setup(void *from_bl2, |
| 57 | void *plat_params_from_bl2) |
| 58 | { |
| 59 | /* Initialize the console to provide early debug support */ |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 60 | rpi3_console_init(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 61 | |
| 62 | #if RESET_TO_BL31 |
| 63 | |
| 64 | /* There are no parameters from BL2 if BL31 is a reset vector */ |
| 65 | assert(from_bl2 == NULL); |
| 66 | assert(plat_params_from_bl2 == NULL); |
| 67 | |
| 68 | #ifdef BL32_BASE |
| 69 | /* Populate entry point information for BL32 */ |
| 70 | SET_PARAM_HEAD(&bl32_image_ep_info, |
| 71 | PARAM_EP, |
| 72 | VERSION_1, |
| 73 | 0); |
| 74 | SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE); |
| 75 | bl32_image_ep_info.pc = BL32_BASE; |
| 76 | bl32_image_ep_info.spsr = rpi3_get_spsr_for_bl32_entry(); |
| 77 | #endif /* BL32_BASE */ |
| 78 | |
| 79 | /* Populate entry point information for BL33 */ |
| 80 | SET_PARAM_HEAD(&bl33_image_ep_info, |
| 81 | PARAM_EP, |
| 82 | VERSION_1, |
| 83 | 0); |
| 84 | /* |
| 85 | * Tell BL31 where the non-trusted software image |
| 86 | * is located and the entry state information |
| 87 | */ |
| 88 | bl33_image_ep_info.pc = plat_get_ns_image_entrypoint(); |
| 89 | |
| 90 | bl33_image_ep_info.spsr = rpi3_get_spsr_for_bl33_entry(); |
| 91 | SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); |
| 92 | |
| 93 | #else /* RESET_TO_BL31 */ |
| 94 | |
| 95 | /* |
| 96 | * In debug builds, we pass a special value in 'plat_params_from_bl2' |
| 97 | * to verify platform parameters from BL2 to BL31. |
| 98 | * In release builds, it's not used. |
| 99 | */ |
| 100 | assert(((uintptr_t)plat_params_from_bl2) == RPI3_BL31_PLAT_PARAM_VAL); |
| 101 | |
| 102 | /* |
| 103 | * Check params passed from BL2 should not be NULL, |
| 104 | */ |
| 105 | bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; |
| 106 | |
| 107 | assert(params_from_bl2 != NULL); |
| 108 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 109 | assert(params_from_bl2->h.version >= VERSION_2); |
| 110 | |
| 111 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 112 | |
| 113 | /* |
| 114 | * Copy BL33 and BL32 (if present), entry point information. |
| 115 | * They are stored in Secure RAM, in BL2's address space. |
| 116 | */ |
| 117 | while (bl_params) { |
| 118 | if (bl_params->image_id == BL32_IMAGE_ID) { |
| 119 | bl32_image_ep_info = *bl_params->ep_info; |
| 120 | } |
| 121 | |
| 122 | if (bl_params->image_id == BL33_IMAGE_ID) { |
| 123 | bl33_image_ep_info = *bl_params->ep_info; |
| 124 | } |
| 125 | |
| 126 | bl_params = bl_params->next_params_info; |
| 127 | } |
| 128 | |
| 129 | if (bl33_image_ep_info.pc == 0) { |
| 130 | panic(); |
| 131 | } |
| 132 | |
| 133 | #endif /* RESET_TO_BL31 */ |
| 134 | } |
| 135 | |
| 136 | void bl31_plat_arch_setup(void) |
| 137 | { |
| 138 | rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE, |
| 139 | BL_CODE_BASE, BL_CODE_END, |
| 140 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 141 | #if USE_COHERENT_MEM |
| 142 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 143 | #endif |
| 144 | ); |
| 145 | |
| 146 | enable_mmu_el3(0); |
| 147 | } |
| 148 | |
| 149 | void bl31_platform_setup(void) |
| 150 | { |
| 151 | #if RESET_TO_BL31 |
| 152 | /* |
| 153 | * Do initial security configuration to allow DRAM/device access |
| 154 | * (if earlier BL has not already done so). |
| 155 | */ |
| 156 | #endif /* RESET_TO_BL31 */ |
| 157 | |
| 158 | return; |
| 159 | } |