Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 1 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 2 | /* |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 3 | * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 8 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/bl_common.h> |
| 12 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Antonio Nino Diaz | 61aff00 | 2018-10-19 16:52:22 +0100 | [diff] [blame] | 13 | |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 14 | #include "qemu_private.h" |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 15 | |
| 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 Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 45 | #define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \ |
| 46 | MT_MEMORY | MT_RO | MT_SECURE) |
| 47 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 48 | /* |
| 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 Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 53 | #ifdef IMAGE_BL1 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 54 | static const mmap_region_t plat_qemu_mmap[] = { |
| 55 | MAP_FLASH0, |
Radoslaw Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 56 | MAP_FLASH1, |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 57 | 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 Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 68 | #ifdef IMAGE_BL2 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 69 | static const mmap_region_t plat_qemu_mmap[] = { |
| 70 | MAP_FLASH0, |
Radoslaw Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 71 | MAP_FLASH1, |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 72 | 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 Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 81 | #if SPM_MM |
| 82 | QEMU_SP_IMAGE_MMAP, |
| 83 | #else |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 84 | MAP_BL32_MEM, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 85 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 86 | {0} |
| 87 | }; |
| 88 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 89 | #ifdef IMAGE_BL31 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 90 | static const mmap_region_t plat_qemu_mmap[] = { |
| 91 | MAP_SHARED_RAM, |
| 92 | MAP_DEVICE0, |
| 93 | #ifdef MAP_DEVICE1 |
| 94 | MAP_DEVICE1, |
| 95 | #endif |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 96 | #if SPM_MM |
Masahisa Kojima | 7e917dc | 2020-09-23 16:52:59 +0900 | [diff] [blame] | 97 | MAP_NS_DRAM0, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 98 | QEMU_SPM_BUF_EL3_MMAP, |
| 99 | #else |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 100 | MAP_BL32_MEM, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 101 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 102 | {0} |
| 103 | }; |
| 104 | #endif |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 105 | #ifdef IMAGE_BL32 |
| 106 | static 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 Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 115 | |
| 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 Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 122 | void qemu_configure_mmu_##_el(unsigned long total_base, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 123 | unsigned long total_size, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 124 | unsigned long code_start, \ |
| 125 | unsigned long code_limit, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 126 | 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 Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 134 | mmap_add_region(code_start, code_start, \ |
| 135 | code_limit - code_start, \ |
| 136 | MT_CODE | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 137 | mmap_add_region(ro_start, ro_start, \ |
| 138 | ro_limit - ro_start, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 139 | MT_RO_DATA | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 140 | 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 Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 146 | enable_mmu_##_el(0); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* Define EL1 and EL3 variants of the function initialising the MMU */ |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 150 | #ifdef __aarch64__ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 151 | DEFINE_CONFIGURE_MMU_EL(el1) |
| 152 | DEFINE_CONFIGURE_MMU_EL(el3) |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 153 | #else |
| 154 | DEFINE_CONFIGURE_MMU_EL(svc_mon) |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 155 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 156 | |
| 157 | |