blob: 7f8e4c49403ec879b5e4b5a640fc27454c4a5880 [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
97 QEMU_SPM_BUF_EL3_MMAP,
98#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010099 MAP_BL32_MEM,
Masahisa Kojima099064b2020-06-11 21:46:44 +0900100#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100101 {0}
102};
103#endif
Etienne Carriere911de8c2018-02-02 13:23:22 +0100104#ifdef IMAGE_BL32
105static const mmap_region_t plat_qemu_mmap[] = {
106 MAP_SHARED_RAM,
107 MAP_DEVICE0,
108#ifdef MAP_DEVICE1
109 MAP_DEVICE1,
110#endif
111 {0}
112};
113#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100114
115/*******************************************************************************
116 * Macro generating the code for the function setting up the pagetables as per
117 * the platform memory map & initialize the mmu, for the given exception level
118 ******************************************************************************/
119
120#define DEFINE_CONFIGURE_MMU_EL(_el) \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100121 void qemu_configure_mmu_##_el(unsigned long total_base, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100122 unsigned long total_size, \
Michalis Pappasba861122018-02-28 14:36:03 +0800123 unsigned long code_start, \
124 unsigned long code_limit, \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100125 unsigned long ro_start, \
126 unsigned long ro_limit, \
127 unsigned long coh_start, \
128 unsigned long coh_limit) \
129 { \
130 mmap_add_region(total_base, total_base, \
131 total_size, \
132 MT_MEMORY | MT_RW | MT_SECURE); \
Michalis Pappasba861122018-02-28 14:36:03 +0800133 mmap_add_region(code_start, code_start, \
134 code_limit - code_start, \
135 MT_CODE | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100136 mmap_add_region(ro_start, ro_start, \
137 ro_limit - ro_start, \
Michalis Pappasba861122018-02-28 14:36:03 +0800138 MT_RO_DATA | MT_SECURE); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100139 mmap_add_region(coh_start, coh_start, \
140 coh_limit - coh_start, \
141 MT_DEVICE | MT_RW | MT_SECURE); \
142 mmap_add(plat_qemu_mmap); \
143 init_xlat_tables(); \
144 \
Etienne Carriere911de8c2018-02-02 13:23:22 +0100145 enable_mmu_##_el(0); \
Jens Wiklander52c798e2015-12-07 14:37:10 +0100146 }
147
148/* Define EL1 and EL3 variants of the function initialising the MMU */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700149#ifdef __aarch64__
Etienne Carriere911de8c2018-02-02 13:23:22 +0100150DEFINE_CONFIGURE_MMU_EL(el1)
151DEFINE_CONFIGURE_MMU_EL(el3)
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700152#else
153DEFINE_CONFIGURE_MMU_EL(svc_mon)
Etienne Carriere911de8c2018-02-02 13:23:22 +0100154#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +0100155
156