blob: 0c184f49bb7bb7933617039a6a65d265a1a8c3db [file] [log] [blame]
Masahisa Kojima099064b2020-06-11 21:46:44 +09001
Jens Wiklander52c798e2015-12-07 14:37:10 +01002/*
Ruchika Gupta5c172532022-04-08 13:14:44 +05303 * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
Jens Wiklander52c798e2015-12-07 14:37:10 +01004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Jens Wiklander52c798e2015-12-07 14:37:10 +01006 */
7
Jens Wiklander52c798e2015-12-07 14:37:10 +01008#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/bl_common.h>
12#include <lib/xlat_tables/xlat_tables_v2.h>
Antonio Nino Diaz61aff002018-10-19 16:52:22 +010013
Ruchika Gupta5c172532022-04-08 13:14:44 +053014#include <plat/common/platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010015#include "qemu_private.h"
Jens Wiklander52c798e2015-12-07 14:37:10 +010016
17#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
18 DEVICE0_SIZE, \
19 MT_DEVICE | MT_RW | MT_SECURE)
20
21#ifdef DEVICE1_BASE
22#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
23 DEVICE1_SIZE, \
24 MT_DEVICE | MT_RW | MT_SECURE)
25#endif
26
27#ifdef DEVICE2_BASE
28#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
29 DEVICE2_SIZE, \
Graeme Gregory6260ddd2020-12-16 12:11:06 +000030 MT_DEVICE | MT_RW | MT_SECURE)
Jens Wiklander52c798e2015-12-07 14:37:10 +010031#endif
32
33#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
34 SHARED_RAM_SIZE, \
35 MT_DEVICE | MT_RW | MT_SECURE)
36
37#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
38 MT_MEMORY | MT_RW | MT_SECURE)
39
40#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
41 MT_MEMORY | MT_RW | MT_NS)
42
43#define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
44 MT_MEMORY | MT_RO | MT_SECURE)
45
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020046#define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \
47 MT_MEMORY | MT_RO | MT_SECURE)
48
Jens Wiklander52c798e2015-12-07 14:37:10 +010049/*
50 * Table of regions for various BL stages to map using the MMU.
51 * This doesn't include TZRAM as the 'mem_layout' argument passed to
52 * arm_configure_mmu_elx() will give the available subset of that,
53 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090054#ifdef IMAGE_BL1
Jens Wiklander52c798e2015-12-07 14:37:10 +010055static const mmap_region_t plat_qemu_mmap[] = {
56 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020057 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010058 MAP_SHARED_RAM,
59 MAP_DEVICE0,
60#ifdef MAP_DEVICE1
61 MAP_DEVICE1,
62#endif
63#ifdef MAP_DEVICE2
64 MAP_DEVICE2,
65#endif
66 {0}
67};
68#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090069#ifdef IMAGE_BL2
Jens Wiklander52c798e2015-12-07 14:37:10 +010070static const mmap_region_t plat_qemu_mmap[] = {
71 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020072 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010073 MAP_SHARED_RAM,
74 MAP_DEVICE0,
75#ifdef MAP_DEVICE1
76 MAP_DEVICE1,
77#endif
78#ifdef MAP_DEVICE2
79 MAP_DEVICE2,
80#endif
81 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +090082#if SPM_MM
83 QEMU_SP_IMAGE_MMAP,
84#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010085 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +090086#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010087 {0}
88};
89#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090090#ifdef IMAGE_BL31
Jens Wiklander52c798e2015-12-07 14:37:10 +010091static const mmap_region_t plat_qemu_mmap[] = {
92 MAP_SHARED_RAM,
93 MAP_DEVICE0,
94#ifdef MAP_DEVICE1
95 MAP_DEVICE1,
96#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +000097#ifdef MAP_DEVICE2
98 MAP_DEVICE2,
99#endif
Masahisa Kojima099064b2020-06-11 21:46:44 +0900100#if SPM_MM
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900101 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900102 QEMU_SPM_BUF_EL3_MMAP,
103#else
Jens Wiklander52c798e2015-12-07 14:37:10 +0100104 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900105#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100106 {0}
107};
108#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100109#ifdef IMAGE_BL32
110static const mmap_region_t plat_qemu_mmap[] = {
111 MAP_SHARED_RAM,
112 MAP_DEVICE0,
113#ifdef MAP_DEVICE1
114 MAP_DEVICE1,
115#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +0000116#ifdef MAP_DEVICE2
117 MAP_DEVICE2,
118#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100119 {0}
120};
121#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100122
123/*******************************************************************************
124 * Macro generating the code for the function setting up the pagetables as per
125 * the platform memory map & initialize the mmu, for the given exception level
126 ******************************************************************************/
127
128#define DEFINE_CONFIGURE_MMU_EL(_el) \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100129 void qemu_configure_mmu_##_el(unsigned long total_base, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100130 unsigned long total_size, \
Michalis Pappasba861122018-02-28 14:36:03 +0800131 unsigned long code_start, \
132 unsigned long code_limit, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100133 unsigned long ro_start, \
134 unsigned long ro_limit, \
135 unsigned long coh_start, \
136 unsigned long coh_limit) \
137 { \
138 mmap_add_region(total_base, total_base, \
139 total_size, \
140 MT_MEMORY | MT_RW | MT_SECURE); \
Michalis Pappasba861122018-02-28 14:36:03 +0800141 mmap_add_region(code_start, code_start, \
142 code_limit - code_start, \
143 MT_CODE | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100144 mmap_add_region(ro_start, ro_start, \
145 ro_limit - ro_start, \
Michalis Pappasba861122018-02-28 14:36:03 +0800146 MT_RO_DATA | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100147 mmap_add_region(coh_start, coh_start, \
148 coh_limit - coh_start, \
149 MT_DEVICE | MT_RW | MT_SECURE); \
150 mmap_add(plat_qemu_mmap); \
151 init_xlat_tables(); \
152 \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100153 enable_mmu_##_el(0); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100154 }
155
156/* Define EL1 and EL3 variants of the function initialising the MMU */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700157#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100158DEFINE_CONFIGURE_MMU_EL(el1)
159DEFINE_CONFIGURE_MMU_EL(el3)
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700160#else
161DEFINE_CONFIGURE_MMU_EL(svc_mon)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100162#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100163
Ruchika Gupta5c172532022-04-08 13:14:44 +0530164#if MEASURED_BOOT || TRUSTED_BOARD_BOOT
165int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
166{
167 return get_mbedtls_heap_helper(heap_addr, heap_size);
168}
169#endif