blob: 7d2730d699ae8989491e18f85599230a3b3671cf [file] [log] [blame]
Masahisa Kojima099064b2020-06-11 21:46:44 +09001
Jens Wiklander52c798e2015-12-07 14:37:10 +01002/*
Masahisa Kojima099064b2020-06-11 21:46:44 +09003 * Copyright (c) 2015-2020, 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
Isla Mitchelle3631462017-07-14 10:46:32 +010014#include "qemu_private.h"
Jens Wiklander52c798e2015-12-07 14:37:10 +010015
16#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
17 DEVICE0_SIZE, \
18 MT_DEVICE | MT_RW | MT_SECURE)
19
20#ifdef DEVICE1_BASE
21#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
22 DEVICE1_SIZE, \
23 MT_DEVICE | MT_RW | MT_SECURE)
24#endif
25
26#ifdef DEVICE2_BASE
27#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
28 DEVICE2_SIZE, \
29 MT_DEVICE | MT_RO | MT_SECURE)
30#endif
31
32#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
33 SHARED_RAM_SIZE, \
34 MT_DEVICE | MT_RW | MT_SECURE)
35
36#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
37 MT_MEMORY | MT_RW | MT_SECURE)
38
39#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
40 MT_MEMORY | MT_RW | MT_NS)
41
42#define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
43 MT_MEMORY | MT_RO | MT_SECURE)
44
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020045#define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \
46 MT_MEMORY | MT_RO | MT_SECURE)
47
Jens Wiklander52c798e2015-12-07 14:37:10 +010048/*
49 * Table of regions for various BL stages to map using the MMU.
50 * This doesn't include TZRAM as the 'mem_layout' argument passed to
51 * arm_configure_mmu_elx() will give the available subset of that,
52 */
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090053#ifdef IMAGE_BL1
Jens Wiklander52c798e2015-12-07 14:37:10 +010054static const mmap_region_t plat_qemu_mmap[] = {
55 MAP_FLASH0,
Radoslaw Biernacki7ed5e122018-06-07 20:14:36 +020056 MAP_FLASH1,
Jens Wiklander52c798e2015-12-07 14:37:10 +010057 MAP_SHARED_RAM,
58 MAP_DEVICE0,
59#ifdef MAP_DEVICE1
60 MAP_DEVICE1,
61#endif
62#ifdef MAP_DEVICE2
63 MAP_DEVICE2,
64#endif
65 {0}
66};
67#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090068#ifdef IMAGE_BL2
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 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +090081#if SPM_MM
82 QEMU_SP_IMAGE_MMAP,
83#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010084 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +090085#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010086 {0}
87};
88#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090089#ifdef IMAGE_BL31
Jens Wiklander52c798e2015-12-07 14:37:10 +010090static const mmap_region_t plat_qemu_mmap[] = {
91 MAP_SHARED_RAM,
92 MAP_DEVICE0,
93#ifdef MAP_DEVICE1
94 MAP_DEVICE1,
95#endif
Masahisa Kojima099064b2020-06-11 21:46:44 +090096#if SPM_MM
Masahisa Kojima7e917dc2020-09-23 16:52:59 +090097 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +090098 QEMU_SPM_BUF_EL3_MMAP,
99#else
Jens Wiklander52c798e2015-12-07 14:37:10 +0100100 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900101#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100102 {0}
103};
104#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100105#ifdef IMAGE_BL32
106static const mmap_region_t plat_qemu_mmap[] = {
107 MAP_SHARED_RAM,
108 MAP_DEVICE0,
109#ifdef MAP_DEVICE1
110 MAP_DEVICE1,
111#endif
112 {0}
113};
114#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100115
116/*******************************************************************************
117 * Macro generating the code for the function setting up the pagetables as per
118 * the platform memory map & initialize the mmu, for the given exception level
119 ******************************************************************************/
120
121#define DEFINE_CONFIGURE_MMU_EL(_el) \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100122 void qemu_configure_mmu_##_el(unsigned long total_base, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100123 unsigned long total_size, \
Michalis Pappasba861122018-02-28 14:36:03 +0800124 unsigned long code_start, \
125 unsigned long code_limit, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100126 unsigned long ro_start, \
127 unsigned long ro_limit, \
128 unsigned long coh_start, \
129 unsigned long coh_limit) \
130 { \
131 mmap_add_region(total_base, total_base, \
132 total_size, \
133 MT_MEMORY | MT_RW | MT_SECURE); \
Michalis Pappasba861122018-02-28 14:36:03 +0800134 mmap_add_region(code_start, code_start, \
135 code_limit - code_start, \
136 MT_CODE | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100137 mmap_add_region(ro_start, ro_start, \
138 ro_limit - ro_start, \
Michalis Pappasba861122018-02-28 14:36:03 +0800139 MT_RO_DATA | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100140 mmap_add_region(coh_start, coh_start, \
141 coh_limit - coh_start, \
142 MT_DEVICE | MT_RW | MT_SECURE); \
143 mmap_add(plat_qemu_mmap); \
144 init_xlat_tables(); \
145 \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100146 enable_mmu_##_el(0); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100147 }
148
149/* Define EL1 and EL3 variants of the function initialising the MMU */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700150#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100151DEFINE_CONFIGURE_MMU_EL(el1)
152DEFINE_CONFIGURE_MMU_EL(el3)
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700153#else
154DEFINE_CONFIGURE_MMU_EL(svc_mon)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100155#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100156
157