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 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch.h> |
| 32 | #include <arch_helpers.h> |
| 33 | #include <assert.h> |
| 34 | #include <bl_common.h> |
| 35 | #include <console.h> |
| 36 | #include <platform_def.h> |
| 37 | #include "qemu_private.h" |
| 38 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 39 | /******************************************************************************* |
| 40 | * Declarations of linker defined symbols which will tell us where BL1 lives |
| 41 | * in Trusted RAM |
| 42 | ******************************************************************************/ |
| 43 | extern uint64_t __BL1_RAM_START__; |
| 44 | extern uint64_t __BL1_RAM_END__; |
| 45 | #define BL1_RAM_BASE (uint64_t)(&__BL1_RAM_START__) |
| 46 | #define BL1_RAM_LIMIT (uint64_t)(&__BL1_RAM_END__) |
| 47 | |
| 48 | /* Data structure which holds the extents of the trusted SRAM for BL1*/ |
| 49 | static meminfo_t bl1_tzram_layout; |
| 50 | |
| 51 | |
| 52 | meminfo_t *bl1_plat_sec_mem_layout(void) |
| 53 | { |
| 54 | return &bl1_tzram_layout; |
| 55 | } |
| 56 | |
| 57 | /******************************************************************************* |
| 58 | * Perform any BL1 specific platform actions. |
| 59 | ******************************************************************************/ |
| 60 | void bl1_early_platform_setup(void) |
| 61 | { |
| 62 | const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; |
| 63 | |
| 64 | /* Initialize the console to provide early debug support */ |
| 65 | console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ, |
| 66 | PLAT_QEMU_CONSOLE_BAUDRATE); |
| 67 | |
| 68 | /* Allow BL1 to see the whole Trusted RAM */ |
| 69 | bl1_tzram_layout.total_base = BL_RAM_BASE; |
| 70 | bl1_tzram_layout.total_size = BL_RAM_SIZE; |
| 71 | |
| 72 | /* Calculate how much RAM BL1 is using and how much remains free */ |
| 73 | bl1_tzram_layout.free_base = BL_RAM_BASE; |
| 74 | bl1_tzram_layout.free_size = BL_RAM_SIZE; |
| 75 | reserve_mem(&bl1_tzram_layout.free_base, &bl1_tzram_layout.free_size, |
| 76 | BL1_RAM_BASE, bl1_size); |
| 77 | } |
| 78 | |
| 79 | /****************************************************************************** |
| 80 | * Perform the very early platform specific architecture setup. This only |
| 81 | * does basic initialization. Later architectural setup (bl1_arch_setup()) |
| 82 | * does not do anything platform specific. |
| 83 | *****************************************************************************/ |
| 84 | void bl1_plat_arch_setup(void) |
| 85 | { |
| 86 | qemu_configure_mmu_el3(bl1_tzram_layout.total_base, |
| 87 | bl1_tzram_layout.total_size, |
| 88 | BL1_RO_BASE, BL1_RO_LIMIT, |
Masahiro Yamada | 0fac5af | 2016-12-28 16:11:41 +0900 | [diff] [blame] | 89 | BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END); |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void bl1_platform_setup(void) |
| 93 | { |
| 94 | plat_qemu_io_setup(); |
| 95 | } |
| 96 | |
| 97 | /******************************************************************************* |
| 98 | * Function that takes a memory layout into which BL2 has been loaded and |
| 99 | * populates a new memory layout for BL2 that ensures that BL1's data sections |
| 100 | * resident in secure RAM are not visible to BL2. |
| 101 | ******************************************************************************/ |
| 102 | void bl1_init_bl2_mem_layout(const meminfo_t *bl1_mem_layout, |
| 103 | meminfo_t *bl2_mem_layout) |
| 104 | { |
| 105 | const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE; |
| 106 | |
| 107 | assert(bl1_mem_layout != NULL); |
| 108 | assert(bl2_mem_layout != NULL); |
| 109 | |
| 110 | /* Check that BL1's memory is lying outside of the free memory */ |
| 111 | assert((BL1_RAM_LIMIT <= bl1_mem_layout->free_base) || |
| 112 | (BL1_RAM_BASE >= (bl1_mem_layout->free_base + |
| 113 | bl1_mem_layout->free_size))); |
| 114 | |
| 115 | /* Remove BL1 RW data from the scope of memory visible to BL2 */ |
| 116 | *bl2_mem_layout = *bl1_mem_layout; |
| 117 | reserve_mem(&bl2_mem_layout->total_base, |
| 118 | &bl2_mem_layout->total_size, |
| 119 | BL1_RAM_BASE, |
| 120 | bl1_size); |
| 121 | |
| 122 | flush_dcache_range((unsigned long)bl2_mem_layout, sizeof(meminfo_t)); |
| 123 | } |
| 124 | |
| 125 | /******************************************************************************* |
| 126 | * Before calling this function BL2 is loaded in memory and its entrypoint |
| 127 | * is set by load_image. This is a placeholder for the platform to change |
| 128 | * the entrypoint of BL2 and set SPSR and security state. |
| 129 | * On ARM standard platforms we only set the security state of the entrypoint |
| 130 | ******************************************************************************/ |
| 131 | void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image, |
| 132 | entry_point_info_t *bl2_ep) |
| 133 | { |
| 134 | SET_SECURITY_STATE(bl2_ep->h.attr, SECURE); |
| 135 | bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); |
| 136 | } |