| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <assert.h> |
| 8 |
|
| 9 |
#include <libfdt.h> |
| 10 |
|
| 11 |
#include <platform_def.h> |
| 12 |
|
| 13 |
#include <common/bl_common.h> |
| 14 |
#include <lib/xlat_tables/xlat_mmu_helpers.h> |
| 15 |
#include <lib/xlat_tables/xlat_tables_defs.h> |
| 16 |
#include <plat/common/platform.h> |
| 17 |
|
| 18 |
#include <rpi_shared.h> |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
static entry_point_info_t bl32_image_ep_info; |
| 25 |
static entry_point_info_t bl33_image_ep_info; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 34 |
{ |
| 35 |
entry_point_info_t *next_image_info; |
| 36 |
|
| 37 |
assert(sec_state_is_valid(type) != 0); |
| 38 |
|
| 39 |
next_image_info = (type == NON_SECURE) |
| 40 |
? &bl33_image_ep_info : &bl32_image_ep_info; |
| 41 |
|
| 42 |
|
| 43 |
if (next_image_info->pc) { |
| 44 |
return next_image_info; |
| 45 |
} else { |
| 46 |
return NULL; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
uintptr_t plat_get_ns_image_entrypoint(void) |
| 54 |
{ |
| 55 |
#ifdef PRELOADED_BL33_BASE |
| 56 |
return PRELOADED_BL33_BASE; |
| 57 |
#else |
| 58 |
return PLAT_RPI3_NS_IMAGE_OFFSET; |
| 59 |
#endif |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 71 |
u_register_t arg2, u_register_t arg3) |
| 72 |
|
| 73 |
{ |
| 74 |
|
| 75 |
rpi3_console_init(); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
assert(arg1 == RPI3_BL31_PLAT_PARAM_VAL); |
| 82 |
|
| 83 |
|
| 84 |
bl_params_t *params_from_bl2 = (bl_params_t *) arg0; |
| 85 |
|
| 86 |
assert(params_from_bl2 != NULL); |
| 87 |
assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 88 |
assert(params_from_bl2->h.version >= VERSION_2); |
| 89 |
|
| 90 |
bl_params_node_t *bl_params = params_from_bl2->head; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
while (bl_params) { |
| 97 |
if (bl_params->image_id == BL32_IMAGE_ID) { |
| 98 |
bl32_image_ep_info = *bl_params->ep_info; |
| 99 |
} |
| 100 |
|
| 101 |
if (bl_params->image_id == BL33_IMAGE_ID) { |
| 102 |
bl33_image_ep_info = *bl_params->ep_info; |
| 103 |
} |
| 104 |
|
| 105 |
bl_params = bl_params->next_params_info; |
| 106 |
} |
| 107 |
|
| 108 |
if (bl33_image_ep_info.pc == 0) { |
| 109 |
panic(); |
| 110 |
} |
| 111 |
|
| 112 |
#if RPI3_DIRECT_LINUX_BOOT |
| 113 |
# if RPI3_BL33_IN_AARCH32 |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
VERBOSE("rpi3: Preparing to boot 32-bit Linux kernel\n"); |
| 122 |
bl33_image_ep_info.args.arg0 = 0U; |
| 123 |
bl33_image_ep_info.args.arg1 = ~0U; |
| 124 |
bl33_image_ep_info.args.arg2 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 125 |
# else |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
VERBOSE("rpi3: Preparing to boot 64-bit Linux kernel\n"); |
| 133 |
bl33_image_ep_info.args.arg0 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 134 |
bl33_image_ep_info.args.arg1 = 0ULL; |
| 135 |
bl33_image_ep_info.args.arg2 = 0ULL; |
| 136 |
bl33_image_ep_info.args.arg3 = 0ULL; |
| 137 |
# endif |
| 138 |
#endif |
| 139 |
} |
| 140 |
|
| 141 |
void bl31_plat_arch_setup(void) |
| 142 |
{ |
| 143 |
rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE, |
| 144 |
BL_CODE_BASE, BL_CODE_END, |
| 145 |
BL_RO_DATA_BASE, BL_RO_DATA_END |
| 146 |
#if USE_COHERENT_MEM |
| 147 |
, BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 148 |
#endif |
| 149 |
); |
| 150 |
|
| 151 |
enable_mmu_el3(0); |
| 152 |
} |
| 153 |
|
| 154 |
#ifdef RPI3_PRELOADED_DTB_BASE |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
static void rpi3_dtb_add_mem_rsv(void) |
| 160 |
{ |
| 161 |
int i, regions, rc; |
| 162 |
uint64_t addr, size; |
| 163 |
void *dtb = (void *)RPI3_PRELOADED_DTB_BASE; |
| 164 |
|
| 165 |
INFO("rpi3: Checking DTB...\n"); |
| 166 |
|
| 167 |
|
| 168 |
if (fdt_check_header(dtb) != 0) |
| 169 |
return; |
| 170 |
|
| 171 |
regions = fdt_num_mem_rsv(dtb); |
| 172 |
|
| 173 |
VERBOSE("rpi3: Found %d mem reserve region(s)\n", regions); |
| 174 |
|
| 175 |
|
| 176 |
if (regions < 1) |
| 177 |
return; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
for (i = 0; i < regions; i++) { |
| 185 |
if (fdt_get_mem_rsv(dtb, i, &addr, &size) != 0) |
| 186 |
continue; |
| 187 |
|
| 188 |
if (addr != 0x0) |
| 189 |
continue; |
| 190 |
|
| 191 |
VERBOSE("rpi3: Firmware mem reserve region found\n"); |
| 192 |
|
| 193 |
rc = fdt_del_mem_rsv(dtb, i); |
| 194 |
if (rc != 0) { |
| 195 |
INFO("rpi3: Can't remove mem reserve region (%d)\n", rc); |
| 196 |
} |
| 197 |
|
| 198 |
break; |
| 199 |
} |
| 200 |
|
| 201 |
if (i == regions) { |
| 202 |
VERBOSE("rpi3: Firmware mem reserve region not found\n"); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
rc = fdt_add_mem_rsv(dtb, SEC_SRAM_BASE, SEC_SRAM_SIZE); |
| 211 |
if (rc != 0) { |
| 212 |
WARN("rpi3: Can't add mem reserve region (%d)\n", rc); |
| 213 |
} |
| 214 |
|
| 215 |
INFO("rpi3: Reserved 0x%llx - 0x%llx in DTB\n", SEC_SRAM_BASE, |
| 216 |
SEC_SRAM_BASE + SEC_SRAM_SIZE); |
| 217 |
} |
| 218 |
#endif |
| 219 |
|
| 220 |
void bl31_platform_setup(void) |
| 221 |
{ |
| 222 |
#ifdef RPI3_PRELOADED_DTB_BASE |
| 223 |
|
| 224 |
rpi3_dtb_add_mem_rsv(); |
| 225 |
#endif |
| 226 |
} |