blob: 068c69c0d54b4819486e58e26009aff4e2a2f6d2 [file] [log] [blame]
Masahisa Kojima099064b2020-06-11 21:46:44 +09001
Jens Wiklander52c798e2015-12-07 14:37:10 +01002/*
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +01003 * Copyright (c) 2015-2024, 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
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +01008#include <string.h>
9
Jens Wiklander52c798e2015-12-07 14:37:10 +010010#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <arch_helpers.h>
13#include <common/bl_common.h>
14#include <lib/xlat_tables/xlat_tables_v2.h>
Jens Wiklanderf9198382022-01-17 09:48:28 +010015#include <services/el3_spmc_ffa_memory.h>
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +010016#if ENABLE_RME
17#include <services/rmm_core_manifest.h>
18#endif
Antonio Nino Diaz61aff002018-10-19 16:52:22 +010019
Ruchika Gupta5c172532022-04-08 13:14:44 +053020#include <plat/common/platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010021#include "qemu_private.h"
Jens Wiklander52c798e2015-12-07 14:37:10 +010022
23#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
24 DEVICE0_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010025 MT_DEVICE | MT_RW | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010026
27#ifdef DEVICE1_BASE
28#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
29 DEVICE1_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010030 MT_DEVICE | MT_RW | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010031#endif
32
33#ifdef DEVICE2_BASE
34#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
35 DEVICE2_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010036 MT_DEVICE | MT_RW | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010037#endif
38
39#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
40 SHARED_RAM_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010041 MT_DEVICE | MT_RW | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010042
43#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010044 MT_MEMORY | MT_RW | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010045
46#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
47 MT_MEMORY | MT_RW | MT_NS)
48
49#define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010050 MT_MEMORY | MT_RO | EL3_PAS)
Jens Wiklander52c798e2015-12-07 14:37:10 +010051
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020052#define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010053 MT_MEMORY | MT_RO | EL3_PAS)
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020054
Raymond Mao032ba022023-06-28 15:07:15 -070055#ifdef FW_HANDOFF_BASE
56#define MAP_FW_HANDOFF MAP_REGION_FLAT(FW_HANDOFF_BASE, FW_HANDOFF_SIZE, \
Jean-Philippe Bruckerb54f6c92023-09-07 17:46:12 +010057 MT_MEMORY | MT_RW | EL3_PAS)
Raymond Mao032ba022023-06-28 15:07:15 -070058#endif
59#ifdef FW_NS_HANDOFF_BASE
60#define MAP_FW_NS_HANDOFF MAP_REGION_FLAT(FW_NS_HANDOFF_BASE, FW_HANDOFF_SIZE, \
61 MT_MEMORY | MT_RW | MT_NS)
62#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010063/*
64 * Table of regions for various BL stages to map using the MMU.
65 * This doesn't include TZRAM as the 'mem_layout' argument passed to
66 * arm_configure_mmu_elx() will give the available subset of that,
67 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090068#ifdef IMAGE_BL1
Jens Wiklander52c798e2015-12-07 14:37:10 +010069static const mmap_region_t plat_qemu_mmap[] = {
70 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020071 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010072 MAP_SHARED_RAM,
73 MAP_DEVICE0,
74#ifdef MAP_DEVICE1
75 MAP_DEVICE1,
76#endif
77#ifdef MAP_DEVICE2
78 MAP_DEVICE2,
79#endif
80 {0}
81};
82#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090083#ifdef IMAGE_BL2
Jens Wiklander52c798e2015-12-07 14:37:10 +010084static const mmap_region_t plat_qemu_mmap[] = {
85 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020086 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010087 MAP_SHARED_RAM,
88 MAP_DEVICE0,
89#ifdef MAP_DEVICE1
90 MAP_DEVICE1,
91#endif
92#ifdef MAP_DEVICE2
93 MAP_DEVICE2,
94#endif
95 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +090096#if SPM_MM
97 QEMU_SP_IMAGE_MMAP,
98#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010099 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900100#endif
Raymond Mao032ba022023-06-28 15:07:15 -0700101#ifdef MAP_FW_HANDOFF
102 MAP_FW_HANDOFF,
103#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100104 {0}
105};
106#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900107#ifdef IMAGE_BL31
Jens Wiklander52c798e2015-12-07 14:37:10 +0100108static const mmap_region_t plat_qemu_mmap[] = {
109 MAP_SHARED_RAM,
110 MAP_DEVICE0,
111#ifdef MAP_DEVICE1
112 MAP_DEVICE1,
113#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +0000114#ifdef MAP_DEVICE2
115 MAP_DEVICE2,
116#endif
Raymond Mao032ba022023-06-28 15:07:15 -0700117#ifdef MAP_FW_HANDOFF
118 MAP_FW_HANDOFF,
119#endif
120#ifdef MAP_FW_NS_HANDOFF
121 MAP_FW_NS_HANDOFF,
122#endif
Masahisa Kojima099064b2020-06-11 21:46:44 +0900123#if SPM_MM
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900124 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900125 QEMU_SPM_BUF_EL3_MMAP,
Jens Wiklanderf9198382022-01-17 09:48:28 +0100126#elif !SPMC_AT_EL3
Jens Wiklander52c798e2015-12-07 14:37:10 +0100127 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900128#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100129 {0}
130};
131#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100132#ifdef IMAGE_BL32
133static const mmap_region_t plat_qemu_mmap[] = {
134 MAP_SHARED_RAM,
135 MAP_DEVICE0,
136#ifdef MAP_DEVICE1
137 MAP_DEVICE1,
138#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +0000139#ifdef MAP_DEVICE2
140 MAP_DEVICE2,
141#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100142 {0}
143};
144#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100145
Jean-Philippe Brucker3e807552023-09-07 19:06:44 +0100146#ifdef IMAGE_RMM
147const mmap_region_t plat_qemu_mmap[] = {
148 MAP_DEVICE0,
149#ifdef MAP_DEVICE1
150 MAP_DEVICE1,
151#endif
152#ifdef MAP_DEVICE2
153 MAP_DEVICE2,
154#endif
155 {0}
156};
157#endif
158
Jens Wiklander52c798e2015-12-07 14:37:10 +0100159/*******************************************************************************
Chen Baozif7d9aa82023-02-20 10:50:15 +0000160 * Returns QEMU platform specific memory map regions.
Jens Wiklander52c798e2015-12-07 14:37:10 +0100161 ******************************************************************************/
Chen Baozif7d9aa82023-02-20 10:50:15 +0000162const mmap_region_t *plat_qemu_get_mmap(void)
163{
164 return plat_qemu_mmap;
165}
Jens Wiklander52c798e2015-12-07 14:37:10 +0100166
Ruchika Gupta5c172532022-04-08 13:14:44 +0530167#if MEASURED_BOOT || TRUSTED_BOARD_BOOT
168int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
169{
170 return get_mbedtls_heap_helper(heap_addr, heap_size);
171}
172#endif
Jens Wiklanderf9198382022-01-17 09:48:28 +0100173
174#if SPMC_AT_EL3
175/*
176 * When using the EL3 SPMC implementation allocate the datastore
177 * for tracking shared memory descriptors in normal memory.
178 */
179#define PLAT_SPMC_SHMEM_DATASTORE_SIZE 64 * 1024
180
181uint8_t plat_spmc_shmem_datastore[PLAT_SPMC_SHMEM_DATASTORE_SIZE];
182
183int plat_spmc_shmem_datastore_get(uint8_t **datastore, size_t *size)
184{
185 *datastore = plat_spmc_shmem_datastore;
186 *size = PLAT_SPMC_SHMEM_DATASTORE_SIZE;
187 return 0;
188}
189
190int plat_spmc_shmem_begin(struct ffa_mtd *desc)
191{
192 return 0;
193}
194
195int plat_spmc_shmem_reclaim(struct ffa_mtd *desc)
196{
197 return 0;
198}
199#endif
Madhukar Pappireddy042043b2023-03-02 16:33:25 -0600200
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500201#if defined(SPD_spmd) && (SPMC_AT_EL3 == 0)
Madhukar Pappireddy042043b2023-03-02 16:33:25 -0600202/*
203 * A dummy implementation of the platform handler for Group0 secure interrupt.
204 */
205int plat_spmd_handle_group0_interrupt(uint32_t intid)
206{
207 (void)intid;
208 return -1;
209}
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500210#endif /*defined(SPD_spmd) && (SPMC_AT_EL3 == 0)*/
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100211
212#if ENABLE_RME
213/*
214 * Get a pointer to the RMM-EL3 Shared buffer and return it
215 * through the pointer passed as parameter.
216 *
217 * This function returns the size of the shared buffer.
218 */
219size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
220{
221 *shared = (uintptr_t)RMM_SHARED_BASE;
222
223 return (size_t)RMM_SHARED_SIZE;
224}
225
226int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
227{
228 uint64_t checksum;
229 uintptr_t base;
230 uint64_t size;
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100231 size_t num_banks = 1;
232 size_t num_consoles = 1;
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100233 struct ns_dram_bank *bank_ptr;
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100234 struct console_info *console_ptr;
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100235
236 assert(manifest != NULL);
237
238 manifest->version = RMMD_MANIFEST_VERSION;
239 manifest->padding = 0U; /* RES0 */
240 manifest->plat_data = (uintptr_t)NULL;
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100241 manifest->plat_dram.num_banks = num_banks;
242 manifest->plat_console.num_consoles = num_consoles;
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100243
244 /*
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100245 * Boot manifest structure illustration:
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100246 *
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100247 * +----------------------------------------+
248 * | offset | field | comment |
249 * +----------+--------------+--------------+
250 * | 0 | version | 0x00000003 |
251 * +----------+--------------+--------------+
252 * | 4 | padding | 0x00000000 |
253 * +----------+--------------+--------------+
254 * | 8 | plat_data | NULL |
255 * +----------+--------------+--------------+
256 * | 16 | num_banks | |
257 * +----------+--------------+ |
258 * | 24 | banks | plat_dram |
259 * +----------+--------------+ |
260 * | 32 | checksum | |
261 * +----------+--------------+--------------+
262 * | 40 | num_consoles | |
263 * +----------+--------------+ |
264 * | 48 | consoles | plat_console |
265 * +----------+--------------+ |
266 * | 56 | checksum | |
267 * +----------+--------------+--------------+
268 * | 64 | base 0 | |
269 * +----------+--------------+ bank[0] |
270 * | 72 | size 0 | |
271 * +----------+--------------+--------------+
272 * | 80 | base | |
273 * +----------+--------------+ |
274 * | 88 | map_pages | |
275 * +----------+--------------+ |
276 * | 96 | name | |
277 * +----------+--------------+ consoles[0] |
278 * | 104 | clk_in_hz | |
279 * +----------+--------------+ |
280 * | 112 | baud_rate | |
281 * +----------+--------------+ |
282 * | 120 | flags | |
283 * +----------+--------------+--------------+
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100284 */
285 bank_ptr = (struct ns_dram_bank *)
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100286 (((uintptr_t)manifest) + sizeof(*manifest));
287
288 console_ptr = (struct console_info *)
289 ((uintptr_t)bank_ptr + (num_banks * sizeof(*bank_ptr)));
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100290
291 manifest->plat_dram.banks = bank_ptr;
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100292 manifest->plat_console.consoles = console_ptr;
293
294 /* Ensure the manifest is not larger than the shared buffer */
295 assert((sizeof(struct rmm_manifest) +
296 (sizeof(struct console_info) * num_consoles) +
297 (sizeof(struct ns_dram_bank) * num_banks)) <= RMM_SHARED_SIZE);
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100298
299 /* Calculate checksum of plat_dram structure */
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100300 checksum = num_banks + (uint64_t)bank_ptr;
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100301
302 base = NS_DRAM0_BASE;
303 size = NS_DRAM0_SIZE;
304 bank_ptr[0].base = base;
305 bank_ptr[0].size = size;
306 checksum += base + size;
307
308 /* Checksum must be 0 */
309 manifest->plat_dram.checksum = ~checksum + 1UL;
310
Jean-Philippe Brucker2c7b22d2024-04-04 09:41:57 +0100311 /* Calculate the checksum of the plat_consoles structure */
312 checksum = num_consoles + (uint64_t)console_ptr;
313
314 /* Zero out the console info struct */
315 memset((void *)console_ptr, 0, sizeof(struct console_info) * num_consoles);
316
317 console_ptr[0].map_pages = 1;
318 console_ptr[0].base = PLAT_QEMU_BOOT_UART_BASE;
319 console_ptr[0].clk_in_hz = PLAT_QEMU_BOOT_UART_CLK_IN_HZ;
320 console_ptr[0].baud_rate = PLAT_QEMU_CONSOLE_BAUDRATE;
321
322 strlcpy(console_ptr[0].name, "pl011", sizeof(console_ptr[0].name));
323
324 /* Update checksum */
325 checksum += console_ptr[0].base + console_ptr[0].map_pages +
326 console_ptr[0].clk_in_hz + console_ptr[0].baud_rate;
327
328 /* Checksum must be 0 */
329 manifest->plat_console.checksum = ~checksum + 1UL;
330
Jean-Philippe Bruckerf304bd62023-09-07 17:33:22 +0100331 return 0;
332}
333#endif /* ENABLE_RME */