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 | f8b36cc | 2018-07-15 12:32:32 +0100 | [diff] [blame] | 99 | |
| 100 | #if RPI3_DIRECT_LINUX_BOOT |
| 101 | # if RPI3_BL33_IN_AARCH32 |
| 102 | /* |
| 103 | * According to the file ``Documentation/arm/Booting`` of the Linux |
| 104 | * kernel tree, Linux expects: |
| 105 | * r0 = 0 |
| 106 | * r1 = machine type number, optional in DT-only platforms (~0 if so) |
| 107 | * r2 = Physical address of the device tree blob |
| 108 | */ |
| 109 | VERBOSE("rpi3: Preparing to boot 32-bit Linux kernel\n"); |
| 110 | bl33_image_ep_info.args.arg0 = 0U; |
| 111 | bl33_image_ep_info.args.arg1 = ~0U; |
| 112 | bl33_image_ep_info.args.arg2 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 113 | # else |
| 114 | /* |
| 115 | * According to the file ``Documentation/arm64/booting.txt`` of the |
| 116 | * Linux kernel tree, Linux expects the physical address of the device |
| 117 | * tree blob (DTB) in x0, while x1-x3 are reserved for future use and |
| 118 | * must be 0. |
| 119 | */ |
| 120 | VERBOSE("rpi3: Preparing to boot 64-bit Linux kernel\n"); |
| 121 | bl33_image_ep_info.args.arg0 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 122 | bl33_image_ep_info.args.arg1 = 0ULL; |
| 123 | bl33_image_ep_info.args.arg2 = 0ULL; |
| 124 | bl33_image_ep_info.args.arg3 = 0ULL; |
| 125 | # endif /* RPI3_BL33_IN_AARCH32 */ |
| 126 | #endif /* RPI3_DIRECT_LINUX_BOOT */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void bl31_plat_arch_setup(void) |
| 130 | { |
| 131 | rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE, |
| 132 | BL_CODE_BASE, BL_CODE_END, |
| 133 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 134 | #if USE_COHERENT_MEM |
| 135 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 136 | #endif |
| 137 | ); |
| 138 | |
| 139 | enable_mmu_el3(0); |
| 140 | } |
| 141 | |
| 142 | void bl31_platform_setup(void) |
| 143 | { |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 144 | /* |
| 145 | * Do initial security configuration to allow DRAM/device access |
| 146 | * (if earlier BL has not already done so). |
| 147 | */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 148 | |
| 149 | return; |
| 150 | } |