blob: 7ba1d34d0e453691255747e6417cc5e4855de08b [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
2 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch_helpers.h>
32#include <bl_common.h>
33#include <platform_def.h>
34#include "qemu_private.h"
35#include <xlat_tables.h>
36
37#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
38 DEVICE0_SIZE, \
39 MT_DEVICE | MT_RW | MT_SECURE)
40
41#ifdef DEVICE1_BASE
42#define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
43 DEVICE1_SIZE, \
44 MT_DEVICE | MT_RW | MT_SECURE)
45#endif
46
47#ifdef DEVICE2_BASE
48#define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
49 DEVICE2_SIZE, \
50 MT_DEVICE | MT_RO | MT_SECURE)
51#endif
52
53#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
54 SHARED_RAM_SIZE, \
55 MT_DEVICE | MT_RW | MT_SECURE)
56
57#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
58 MT_MEMORY | MT_RW | MT_SECURE)
59
60#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
61 MT_MEMORY | MT_RW | MT_NS)
62
63#define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
64 MT_MEMORY | MT_RO | MT_SECURE)
65
66/*
67 * Table of regions for various BL stages to map using the MMU.
68 * This doesn't include TZRAM as the 'mem_layout' argument passed to
69 * arm_configure_mmu_elx() will give the available subset of that,
70 */
71#if IMAGE_BL1
72static const mmap_region_t plat_qemu_mmap[] = {
73 MAP_FLASH0,
74 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 {0}
83};
84#endif
85#if IMAGE_BL2
86static const mmap_region_t plat_qemu_mmap[] = {
87 MAP_FLASH0,
88 MAP_SHARED_RAM,
89 MAP_DEVICE0,
90#ifdef MAP_DEVICE1
91 MAP_DEVICE1,
92#endif
93#ifdef MAP_DEVICE2
94 MAP_DEVICE2,
95#endif
96 MAP_NS_DRAM0,
97 MAP_BL32_MEM,
98 {0}
99};
100#endif
101#if IMAGE_BL31
102static const mmap_region_t plat_qemu_mmap[] = {
103 MAP_SHARED_RAM,
104 MAP_DEVICE0,
105#ifdef MAP_DEVICE1
106 MAP_DEVICE1,
107#endif
108 MAP_BL32_MEM,
109 {0}
110};
111#endif
112
113/*******************************************************************************
114 * Macro generating the code for the function setting up the pagetables as per
115 * the platform memory map & initialize the mmu, for the given exception level
116 ******************************************************************************/
117
118#define DEFINE_CONFIGURE_MMU_EL(_el) \
119 void qemu_configure_mmu_el##_el(unsigned long total_base, \
120 unsigned long total_size, \
121 unsigned long ro_start, \
122 unsigned long ro_limit, \
123 unsigned long coh_start, \
124 unsigned long coh_limit) \
125 { \
126 mmap_add_region(total_base, total_base, \
127 total_size, \
128 MT_MEMORY | MT_RW | MT_SECURE); \
129 mmap_add_region(ro_start, ro_start, \
130 ro_limit - ro_start, \
131 MT_MEMORY | MT_RO | MT_SECURE); \
132 mmap_add_region(coh_start, coh_start, \
133 coh_limit - coh_start, \
134 MT_DEVICE | MT_RW | MT_SECURE); \
135 mmap_add(plat_qemu_mmap); \
136 init_xlat_tables(); \
137 \
138 enable_mmu_el##_el(0); \
139 }
140
141/* Define EL1 and EL3 variants of the function initialising the MMU */
142DEFINE_CONFIGURE_MMU_EL(1)
143DEFINE_CONFIGURE_MMU_EL(3)
144
145