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 |
John Tsichritzis | d653d33 | 2018-09-14 10:34:57 +0100 | [diff] [blame] | 50 | * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 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 | ******************************************************************************/ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 56 | void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 57 | u_register_t arg2, u_register_t arg3) |
| 58 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 59 | { |
| 60 | /* Initialize the console to provide early debug support */ |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 61 | rpi3_console_init(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 62 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 63 | /* |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 64 | * In debug builds, a special value is passed in 'arg1' to verify |
| 65 | * platform parameters from BL2 to BL31. Not used in release builds. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 66 | */ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 67 | assert(arg1 == RPI3_BL31_PLAT_PARAM_VAL); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 68 | |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 69 | /* Check that params passed from BL2 are not NULL. */ |
| 70 | bl_params_t *params_from_bl2 = (bl_params_t *) arg0; |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 71 | |
| 72 | assert(params_from_bl2 != NULL); |
| 73 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 74 | assert(params_from_bl2->h.version >= VERSION_2); |
| 75 | |
| 76 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 77 | |
| 78 | /* |
| 79 | * Copy BL33 and BL32 (if present), entry point information. |
| 80 | * They are stored in Secure RAM, in BL2's address space. |
| 81 | */ |
| 82 | while (bl_params) { |
| 83 | if (bl_params->image_id == BL32_IMAGE_ID) { |
| 84 | bl32_image_ep_info = *bl_params->ep_info; |
| 85 | } |
| 86 | |
| 87 | if (bl_params->image_id == BL33_IMAGE_ID) { |
| 88 | bl33_image_ep_info = *bl_params->ep_info; |
| 89 | } |
| 90 | |
| 91 | bl_params = bl_params->next_params_info; |
| 92 | } |
| 93 | |
| 94 | if (bl33_image_ep_info.pc == 0) { |
| 95 | panic(); |
| 96 | } |
Antonio Nino Diaz | f8b36cc | 2018-07-15 12:32:32 +0100 | [diff] [blame] | 97 | |
| 98 | #if RPI3_DIRECT_LINUX_BOOT |
| 99 | # if RPI3_BL33_IN_AARCH32 |
| 100 | /* |
| 101 | * According to the file ``Documentation/arm/Booting`` of the Linux |
| 102 | * kernel tree, Linux expects: |
| 103 | * r0 = 0 |
| 104 | * r1 = machine type number, optional in DT-only platforms (~0 if so) |
| 105 | * r2 = Physical address of the device tree blob |
| 106 | */ |
| 107 | VERBOSE("rpi3: Preparing to boot 32-bit Linux kernel\n"); |
| 108 | bl33_image_ep_info.args.arg0 = 0U; |
| 109 | bl33_image_ep_info.args.arg1 = ~0U; |
| 110 | bl33_image_ep_info.args.arg2 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 111 | # else |
| 112 | /* |
| 113 | * According to the file ``Documentation/arm64/booting.txt`` of the |
| 114 | * Linux kernel tree, Linux expects the physical address of the device |
| 115 | * tree blob (DTB) in x0, while x1-x3 are reserved for future use and |
| 116 | * must be 0. |
| 117 | */ |
| 118 | VERBOSE("rpi3: Preparing to boot 64-bit Linux kernel\n"); |
| 119 | bl33_image_ep_info.args.arg0 = (u_register_t) RPI3_PRELOADED_DTB_BASE; |
| 120 | bl33_image_ep_info.args.arg1 = 0ULL; |
| 121 | bl33_image_ep_info.args.arg2 = 0ULL; |
| 122 | bl33_image_ep_info.args.arg3 = 0ULL; |
| 123 | # endif /* RPI3_BL33_IN_AARCH32 */ |
| 124 | #endif /* RPI3_DIRECT_LINUX_BOOT */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void bl31_plat_arch_setup(void) |
| 128 | { |
| 129 | rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE, |
| 130 | BL_CODE_BASE, BL_CODE_END, |
| 131 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 132 | #if USE_COHERENT_MEM |
| 133 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 134 | #endif |
| 135 | ); |
| 136 | |
| 137 | enable_mmu_el3(0); |
| 138 | } |
| 139 | |
| 140 | void bl31_platform_setup(void) |
| 141 | { |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 142 | /* |
| 143 | * Do initial security configuration to allow DRAM/device access |
| 144 | * (if earlier BL has not already done so). |
| 145 | */ |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 146 | |
| 147 | return; |
| 148 | } |