blob: 556aae593a27cb77ed9a965336e2890c93c0e141 [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>
Jens Wiklander52c798e2015-12-07 14:37:10 +010011#include <platform_def.h>
12#include "qemu_private.h"
13
Jens Wiklander52c798e2015-12-07 14:37:10 +010014/* Data structure which holds the extents of the trusted SRAM for BL1*/
15static meminfo_t bl1_tzram_layout;
16
17
18meminfo_t *bl1_plat_sec_mem_layout(void)
19{
20 return &bl1_tzram_layout;
21}
22
23/*******************************************************************************
24 * Perform any BL1 specific platform actions.
25 ******************************************************************************/
26void bl1_early_platform_setup(void)
27{
Jens Wiklander52c798e2015-12-07 14:37:10 +010028 /* Initialize the console to provide early debug support */
Michalis Pappascca6cb72018-03-04 15:43:38 +080029 qemu_console_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010030
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 Weic2f78442017-05-27 21:21:42 +080035#if !LOAD_IMAGE_V2
Jens Wiklander52c798e2015-12-07 14:37:10 +010036 /* 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 Weic2f78442017-05-27 21:21:42 +080040 BL1_RAM_BASE, BL1_RAM_LIMIT - BL1_RAM_BASE);
41#endif /* !LOAD_IMAGE_V2 */
Jens Wiklander52c798e2015-12-07 14:37:10 +010042}
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 Carriere911de8c2018-02-02 13:23:22 +010049#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 Wiklander52c798e2015-12-07 14:37:10 +010055void bl1_plat_arch_setup(void)
56{
Etienne Carriere911de8c2018-02-02 13:23:22 +010057 QEMU_CONFIGURE_BL1_MMU(bl1_tzram_layout.total_base,
Jens Wiklander52c798e2015-12-07 14:37:10 +010058 bl1_tzram_layout.total_size,
Michalis Pappasba861122018-02-28 14:36:03 +080059 BL_CODE_BASE, BL1_CODE_END,
60 BL1_RO_DATA_BASE, BL1_RO_DATA_END,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +090061 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +010062}
63
64void bl1_platform_setup(void)
65{
66 plat_qemu_io_setup();
67}
68
Fu Weic2f78442017-05-27 21:21:42 +080069#if !LOAD_IMAGE_V2
Jens Wiklander52c798e2015-12-07 14:37:10 +010070/*******************************************************************************
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 ******************************************************************************/
75void 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 ******************************************************************************/
104void 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 Weic2f78442017-05-27 21:21:42 +0800110#endif /* !LOAD_IMAGE_V2 */