Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <arch_helpers.h> |
| 9 | #include <assert.h> |
| 10 | #include <bl_common.h> |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 11 | #include <platform_def.h> |
| 12 | #include "qemu_private.h" |
| 13 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 14 | /* Data structure which holds the extents of the trusted SRAM for BL1*/ |
| 15 | static meminfo_t bl1_tzram_layout; |
| 16 | |
| 17 | |
| 18 | meminfo_t *bl1_plat_sec_mem_layout(void) |
| 19 | { |
| 20 | return &bl1_tzram_layout; |
| 21 | } |
| 22 | |
| 23 | /******************************************************************************* |
| 24 | * Perform any BL1 specific platform actions. |
| 25 | ******************************************************************************/ |
| 26 | void bl1_early_platform_setup(void) |
| 27 | { |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 28 | /* Initialize the console to provide early debug support */ |
Michalis Pappas | cca6cb7 | 2018-03-04 15:43:38 +0800 | [diff] [blame] | 29 | qemu_console_init(); |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 30 | |
| 31 | /* Allow BL1 to see the whole Trusted RAM */ |
| 32 | bl1_tzram_layout.total_base = BL_RAM_BASE; |
| 33 | bl1_tzram_layout.total_size = BL_RAM_SIZE; |
| 34 | |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 35 | #if !LOAD_IMAGE_V2 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 36 | /* Calculate how much RAM BL1 is using and how much remains free */ |
| 37 | bl1_tzram_layout.free_base = BL_RAM_BASE; |
| 38 | bl1_tzram_layout.free_size = BL_RAM_SIZE; |
| 39 | reserve_mem(&bl1_tzram_layout.free_base, &bl1_tzram_layout.free_size, |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 40 | BL1_RAM_BASE, BL1_RAM_LIMIT - BL1_RAM_BASE); |
| 41 | #endif /* !LOAD_IMAGE_V2 */ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /****************************************************************************** |
| 45 | * Perform the very early platform specific architecture setup. This only |
| 46 | * does basic initialization. Later architectural setup (bl1_arch_setup()) |
| 47 | * does not do anything platform specific. |
| 48 | *****************************************************************************/ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 49 | #ifdef AARCH32 |
| 50 | #define QEMU_CONFIGURE_BL1_MMU(...) qemu_configure_mmu_secure(__VA_ARGS__) |
| 51 | #else |
| 52 | #define QEMU_CONFIGURE_BL1_MMU(...) qemu_configure_mmu_el3(__VA_ARGS__) |
| 53 | #endif |
| 54 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 55 | void bl1_plat_arch_setup(void) |
| 56 | { |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 57 | QEMU_CONFIGURE_BL1_MMU(bl1_tzram_layout.total_base, |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 58 | bl1_tzram_layout.total_size, |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 59 | BL_CODE_BASE, BL1_CODE_END, |
| 60 | BL1_RO_DATA_BASE, BL1_RO_DATA_END, |
Masahiro Yamada | 0fac5af | 2016-12-28 16:11:41 +0900 | [diff] [blame] | 61 | BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END); |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void bl1_platform_setup(void) |
| 65 | { |
| 66 | plat_qemu_io_setup(); |
| 67 | } |
| 68 | |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 69 | #if !LOAD_IMAGE_V2 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 70 | /******************************************************************************* |
| 71 | * Function that takes a memory layout into which BL2 has been loaded and |
| 72 | * populates a new memory layout for BL2 that ensures that BL1's data sections |
| 73 | * resident in secure RAM are not visible to BL2. |
| 74 | ******************************************************************************/ |
| 75 | void bl1_init_bl2_mem_layout(const meminfo_t *bl1_mem_layout, |
| 76 | meminfo_t *bl2_mem_layout) |
| 77 | { |
| 78 | const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; |
| 79 | |
| 80 | assert(bl1_mem_layout != NULL); |
| 81 | assert(bl2_mem_layout != NULL); |
| 82 | |
| 83 | /* Check that BL1's memory is lying outside of the free memory */ |
| 84 | assert((BL1_RAM_LIMIT <= bl1_mem_layout->free_base) || |
| 85 | (BL1_RAM_BASE >= (bl1_mem_layout->free_base + |
| 86 | bl1_mem_layout->free_size))); |
| 87 | |
| 88 | /* Remove BL1 RW data from the scope of memory visible to BL2 */ |
| 89 | *bl2_mem_layout = *bl1_mem_layout; |
| 90 | reserve_mem(&bl2_mem_layout->total_base, |
| 91 | &bl2_mem_layout->total_size, |
| 92 | BL1_RAM_BASE, |
| 93 | bl1_size); |
| 94 | |
| 95 | flush_dcache_range((unsigned long)bl2_mem_layout, sizeof(meminfo_t)); |
| 96 | } |
| 97 | |
| 98 | /******************************************************************************* |
| 99 | * Before calling this function BL2 is loaded in memory and its entrypoint |
| 100 | * is set by load_image. This is a placeholder for the platform to change |
| 101 | * the entrypoint of BL2 and set SPSR and security state. |
| 102 | * On ARM standard platforms we only set the security state of the entrypoint |
| 103 | ******************************************************************************/ |
| 104 | void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image, |
| 105 | entry_point_info_t *bl2_ep) |
| 106 | { |
| 107 | SET_SECURITY_STATE(bl2_ep->h.attr, SECURE); |
| 108 | bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); |
| 109 | } |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 110 | #endif /* !LOAD_IMAGE_V2 */ |