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