blob: 47ec79114e8b44a3dcfcd15db837adaa13fef1e9 [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, \
Graeme Gregory6260ddd2020-12-16 12:11:06 +000029 MT_DEVICE | MT_RW | MT_SECURE)
Jens Wiklander52c798e2015-12-07 14:37:10 +010030#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
Graeme Gregory6260ddd2020-12-16 12:11:06 +000096#ifdef MAP_DEVICE2
97 MAP_DEVICE2,
98#endif
Masahisa Kojima099064b2020-06-11 21:46:44 +090099#if SPM_MM
Masahisa Kojima7e917dc2020-09-23 16:52:59 +0900100 MAP_NS_DRAM0,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900101 QEMU_SPM_BUF_EL3_MMAP,
102#else
Jens Wiklander52c798e2015-12-07 14:37:10 +0100103 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900104#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100105 {0}
106};
107#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100108#ifdef IMAGE_BL32
109static const mmap_region_t plat_qemu_mmap[] = {
110 MAP_SHARED_RAM,
111 MAP_DEVICE0,
112#ifdef MAP_DEVICE1
113 MAP_DEVICE1,
114#endif
Graeme Gregory6260ddd2020-12-16 12:11:06 +0000115#ifdef MAP_DEVICE2
116 MAP_DEVICE2,
117#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100118 {0}
119};
120#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100121
122/*******************************************************************************
123 * Macro generating the code for the function setting up the pagetables as per
124 * the platform memory map & initialize the mmu, for the given exception level
125 ******************************************************************************/
126
127#define DEFINE_CONFIGURE_MMU_EL(_el) \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100128 void qemu_configure_mmu_##_el(unsigned long total_base, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100129 unsigned long total_size, \
Michalis Pappasba861122018-02-28 14:36:03 +0800130 unsigned long code_start, \
131 unsigned long code_limit, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100132 unsigned long ro_start, \
133 unsigned long ro_limit, \
134 unsigned long coh_start, \
135 unsigned long coh_limit) \
136 { \
137 mmap_add_region(total_base, total_base, \
138 total_size, \
139 MT_MEMORY | MT_RW | MT_SECURE); \
Michalis Pappasba861122018-02-28 14:36:03 +0800140 mmap_add_region(code_start, code_start, \
141 code_limit - code_start, \
142 MT_CODE | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100143 mmap_add_region(ro_start, ro_start, \
144 ro_limit - ro_start, \
Michalis Pappasba861122018-02-28 14:36:03 +0800145 MT_RO_DATA | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100146 mmap_add_region(coh_start, coh_start, \
147 coh_limit - coh_start, \
148 MT_DEVICE | MT_RW | MT_SECURE); \
149 mmap_add(plat_qemu_mmap); \
150 init_xlat_tables(); \
151 \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100152 enable_mmu_##_el(0); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100153 }
154
155/* Define EL1 and EL3 variants of the function initialising the MMU */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700156#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100157DEFINE_CONFIGURE_MMU_EL(el1)
158DEFINE_CONFIGURE_MMU_EL(el3)
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700159#else
160DEFINE_CONFIGURE_MMU_EL(svc_mon)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100161#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100162
163