blob: 4438aaccc5ffac9cb9dd3a3f8813f4a73870ac70 [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
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
39
40/*
41 * The next 2 constants identify the extents of the coherent memory region.
42 * These addresses are used by the MMU setup code and therefore they must be
43 * page-aligned. It is the responsibility of the linker script to ensure that
44 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
45 * page-aligned addresses.
46 */
47#define BL1_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
48#define BL1_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
49
50
51/*******************************************************************************
52 * Declarations of linker defined symbols which will tell us where BL1 lives
53 * in Trusted RAM
54 ******************************************************************************/
55extern uint64_t __BL1_RAM_START__;
56extern uint64_t __BL1_RAM_END__;
57#define BL1_RAM_BASE (uint64_t)(&__BL1_RAM_START__)
58#define BL1_RAM_LIMIT (uint64_t)(&__BL1_RAM_END__)
59
60/* Data structure which holds the extents of the trusted SRAM for BL1*/
61static meminfo_t bl1_tzram_layout;
62
63
64meminfo_t *bl1_plat_sec_mem_layout(void)
65{
66 return &bl1_tzram_layout;
67}
68
69/*******************************************************************************
70 * Perform any BL1 specific platform actions.
71 ******************************************************************************/
72void bl1_early_platform_setup(void)
73{
74 const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE;
75
76 /* Initialize the console to provide early debug support */
77 console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ,
78 PLAT_QEMU_CONSOLE_BAUDRATE);
79
80 /* Allow BL1 to see the whole Trusted RAM */
81 bl1_tzram_layout.total_base = BL_RAM_BASE;
82 bl1_tzram_layout.total_size = BL_RAM_SIZE;
83
84 /* Calculate how much RAM BL1 is using and how much remains free */
85 bl1_tzram_layout.free_base = BL_RAM_BASE;
86 bl1_tzram_layout.free_size = BL_RAM_SIZE;
87 reserve_mem(&bl1_tzram_layout.free_base, &bl1_tzram_layout.free_size,
88 BL1_RAM_BASE, bl1_size);
89}
90
91/******************************************************************************
92 * Perform the very early platform specific architecture setup. This only
93 * does basic initialization. Later architectural setup (bl1_arch_setup())
94 * does not do anything platform specific.
95 *****************************************************************************/
96void bl1_plat_arch_setup(void)
97{
98 qemu_configure_mmu_el3(bl1_tzram_layout.total_base,
99 bl1_tzram_layout.total_size,
100 BL1_RO_BASE, BL1_RO_LIMIT,
101 BL1_COHERENT_RAM_BASE, BL1_COHERENT_RAM_LIMIT);
102}
103
104void bl1_platform_setup(void)
105{
106 plat_qemu_io_setup();
107}
108
109/*******************************************************************************
110 * Function that takes a memory layout into which BL2 has been loaded and
111 * populates a new memory layout for BL2 that ensures that BL1's data sections
112 * resident in secure RAM are not visible to BL2.
113 ******************************************************************************/
114void bl1_init_bl2_mem_layout(const meminfo_t *bl1_mem_layout,
115 meminfo_t *bl2_mem_layout)
116{
117 const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE;
118
119 assert(bl1_mem_layout != NULL);
120 assert(bl2_mem_layout != NULL);
121
122 /* Check that BL1's memory is lying outside of the free memory */
123 assert((BL1_RAM_LIMIT <= bl1_mem_layout->free_base) ||
124 (BL1_RAM_BASE >= (bl1_mem_layout->free_base +
125 bl1_mem_layout->free_size)));
126
127 /* Remove BL1 RW data from the scope of memory visible to BL2 */
128 *bl2_mem_layout = *bl1_mem_layout;
129 reserve_mem(&bl2_mem_layout->total_base,
130 &bl2_mem_layout->total_size,
131 BL1_RAM_BASE,
132 bl1_size);
133
134 flush_dcache_range((unsigned long)bl2_mem_layout, sizeof(meminfo_t));
135}
136
137/*******************************************************************************
138 * Before calling this function BL2 is loaded in memory and its entrypoint
139 * is set by load_image. This is a placeholder for the platform to change
140 * the entrypoint of BL2 and set SPSR and security state.
141 * On ARM standard platforms we only set the security state of the entrypoint
142 ******************************************************************************/
143void bl1_plat_set_bl2_ep_info(image_info_t *bl2_image,
144 entry_point_info_t *bl2_ep)
145{
146 SET_SECURITY_STATE(bl2_ep->h.attr, SECURE);
147 bl2_ep->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
148}