blob: 23ac5813ea32bf09bd083ca4d79dda2e9b2d9cf4 [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>
Jens Wiklanderf9198382022-01-17 09:48:28 +010013#include <services/el3_spmc_ffa_memory.h>
Antonio Nino Diaz61aff002018-10-19 16:52:22 +010014
Ruchika Gupta5c172532022-04-08 13:14:44 +053015#include <plat/common/platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010016#include "qemu_private.h"
Jens Wiklander52c798e2015-12-07 14:37:10 +010017
18#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
19 DEVICE0_SIZE, \
20 MT_DEVICE | MT_RW | MT_SECURE)
21
22#ifdef DEVICE1_BASE
23#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
24 DEVICE1_SIZE, \
25 MT_DEVICE | MT_RW | MT_SECURE)
26#endif
27
28#ifdef DEVICE2_BASE
29#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
30 DEVICE2_SIZE, \
Graeme Gregory6260ddd2020-12-16 12:11:06 +000031 MT_DEVICE | MT_RW | MT_SECURE)
Jens Wiklander52c798e2015-12-07 14:37:10 +010032#endif
33
34#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
35 SHARED_RAM_SIZE, \
36 MT_DEVICE | MT_RW | MT_SECURE)
37
38#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
39 MT_MEMORY | MT_RW | MT_SECURE)
40
41#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
42 MT_MEMORY | MT_RW | MT_NS)
43
44#define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
45 MT_MEMORY | MT_RO | MT_SECURE)
46
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020047#define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \
48 MT_MEMORY | MT_RO | MT_SECURE)
49
Jens Wiklander52c798e2015-12-07 14:37:10 +010050/*
51 * Table of regions for various BL stages to map using the MMU.
52 * This doesn't include TZRAM as the 'mem_layout' argument passed to
53 * arm_configure_mmu_elx() will give the available subset of that,
54 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090055#ifdef IMAGE_BL1
Jens Wiklander52c798e2015-12-07 14:37:10 +010056static const mmap_region_t plat_qemu_mmap[] = {
57 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020058 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010059 MAP_SHARED_RAM,
60 MAP_DEVICE0,
61#ifdef MAP_DEVICE1
62 MAP_DEVICE1,
63#endif
64#ifdef MAP_DEVICE2
65 MAP_DEVICE2,
66#endif
67 {0}
68};
69#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090070#ifdef IMAGE_BL2
Jens Wiklander52c798e2015-12-07 14:37:10 +010071static const mmap_region_t plat_qemu_mmap[] = {
72 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020073 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010074 MAP_SHARED_RAM,
75 MAP_DEVICE0,
76#ifdef MAP_DEVICE1
77 MAP_DEVICE1,
78#endif
79#ifdef MAP_DEVICE2
80 MAP_DEVICE2,
81#endif
82 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +090083#if SPM_MM
84 QEMU_SP_IMAGE_MMAP,
85#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010086 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +090087#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010088 {0}
89};
90#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090091#ifdef IMAGE_BL31
Jens Wiklander52c798e2015-12-07 14:37:10 +010092static const mmap_region_t plat_qemu_mmap[] = {
93 MAP_SHARED_RAM,
94 MAP_DEVICE0,
95#ifdef MAP_DEVICE1
96 MAP_DEVICE1,
97#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +000098#ifdef MAP_DEVICE2
99 MAP_DEVICE2,
100#endif
Masahisa Kojima099064b2020-06-11 21:46:44 +0900101#if SPM_MM
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900102 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900103 QEMU_SPM_BUF_EL3_MMAP,
Jens Wiklanderf9198382022-01-17 09:48:28 +0100104#elif !SPMC_AT_EL3
Jens Wiklander52c798e2015-12-07 14:37:10 +0100105 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900106#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100107 {0}
108};
109#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100110#ifdef IMAGE_BL32
111static const mmap_region_t plat_qemu_mmap[] = {
112 MAP_SHARED_RAM,
113 MAP_DEVICE0,
114#ifdef MAP_DEVICE1
115 MAP_DEVICE1,
116#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +0000117#ifdef MAP_DEVICE2
118 MAP_DEVICE2,
119#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100120 {0}
121};
122#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100123
124/*******************************************************************************
125 * Macro generating the code for the function setting up the pagetables as per
126 * the platform memory map & initialize the mmu, for the given exception level
127 ******************************************************************************/
128
129#define DEFINE_CONFIGURE_MMU_EL(_el) \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100130 void qemu_configure_mmu_##_el(unsigned long total_base, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100131 unsigned long total_size, \
Michalis Pappasba861122018-02-28 14:36:03 +0800132 unsigned long code_start, \
133 unsigned long code_limit, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100134 unsigned long ro_start, \
135 unsigned long ro_limit, \
136 unsigned long coh_start, \
137 unsigned long coh_limit) \
138 { \
139 mmap_add_region(total_base, total_base, \
140 total_size, \
141 MT_MEMORY | MT_RW | MT_SECURE); \
Michalis Pappasba861122018-02-28 14:36:03 +0800142 mmap_add_region(code_start, code_start, \
143 code_limit - code_start, \
144 MT_CODE | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100145 mmap_add_region(ro_start, ro_start, \
146 ro_limit - ro_start, \
Michalis Pappasba861122018-02-28 14:36:03 +0800147 MT_RO_DATA | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100148 mmap_add_region(coh_start, coh_start, \
149 coh_limit - coh_start, \
150 MT_DEVICE | MT_RW | MT_SECURE); \
151 mmap_add(plat_qemu_mmap); \
152 init_xlat_tables(); \
153 \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100154 enable_mmu_##_el(0); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100155 }
156
157/* Define EL1 and EL3 variants of the function initialising the MMU */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700158#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100159DEFINE_CONFIGURE_MMU_EL(el1)
160DEFINE_CONFIGURE_MMU_EL(el3)
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700161#else
162DEFINE_CONFIGURE_MMU_EL(svc_mon)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100163#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100164
Ruchika Gupta5c172532022-04-08 13:14:44 +0530165#if MEASURED_BOOT || TRUSTED_BOARD_BOOT
166int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
167{
168 return get_mbedtls_heap_helper(heap_addr, heap_size);
169}
170#endif
Jens Wiklanderf9198382022-01-17 09:48:28 +0100171
172#if SPMC_AT_EL3
173/*
174 * When using the EL3 SPMC implementation allocate the datastore
175 * for tracking shared memory descriptors in normal memory.
176 */
177#define PLAT_SPMC_SHMEM_DATASTORE_SIZE 64 * 1024
178
179uint8_t plat_spmc_shmem_datastore[PLAT_SPMC_SHMEM_DATASTORE_SIZE];
180
181int plat_spmc_shmem_datastore_get(uint8_t **datastore, size_t *size)
182{
183 *datastore = plat_spmc_shmem_datastore;
184 *size = PLAT_SPMC_SHMEM_DATASTORE_SIZE;
185 return 0;
186}
187
188int plat_spmc_shmem_begin(struct ffa_mtd *desc)
189{
190 return 0;
191}
192
193int plat_spmc_shmem_reclaim(struct ffa_mtd *desc)
194{
195 return 0;
196}
197#endif