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 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 62 | /* |
| 63 | * In debug builds, we pass a special value in 'plat_params_from_bl2' |
| 64 | * to verify platform parameters from BL2 to BL31. |
| 65 | * In release builds, it's not used. |
| 66 | */ |
| 67 | assert(((uintptr_t)plat_params_from_bl2) == RPI3_BL31_PLAT_PARAM_VAL); |
| 68 | |
| 69 | /* |
| 70 | * Check params passed from BL2 should not be NULL, |
| 71 | */ |
| 72 | bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; |
| 73 | |
| 74 | assert(params_from_bl2 != NULL); |
| 75 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 76 | assert(params_from_bl2->h.version >= VERSION_2); |
| 77 | |
| 78 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 79 | |
| 80 | /* |
| 81 | * Copy BL33 and BL32 (if present), entry point information. |
| 82 | * They are stored in Secure RAM, in BL2's address space. |
| 83 | */ |
| 84 | while (bl_params) { |
| 85 | if (bl_params->image_id == BL32_IMAGE_ID) { |
| 86 | bl32_image_ep_info = *bl_params->ep_info; |
| 87 | } |
| 88 | |
| 89 | if (bl_params->image_id == BL33_IMAGE_ID) { |
| 90 | bl33_image_ep_info = *bl_params->ep_info; |
| 91 | } |
| 92 | |
| 93 | bl_params = bl_params->next_params_info; |
| 94 | } |
| 95 | |
| 96 | if (bl33_image_ep_info.pc == 0) { |
| 97 | panic(); |
| 98 | } |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void bl31_plat_arch_setup(void) |
| 102 | { |
| 103 | rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE, |
| 104 | BL_CODE_BASE, BL_CODE_END, |
| 105 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 106 | #if USE_COHERENT_MEM |
| 107 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 108 | #endif |
| 109 | ); |
| 110 | |
| 111 | enable_mmu_el3(0); |
| 112 | } |
| 113 | |
| 114 | void bl31_platform_setup(void) |
| 115 | { |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 116 | /* |
| 117 | * Do initial security configuration to allow DRAM/device access |
| 118 | * (if earlier BL has not already done so). |
| 119 | */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 120 | |
| 121 | return; |
| 122 | } |