Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 61aff00 | 2018-10-19 16:52:22 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <bl_common.h> |
| 9 | #include <platform_def.h> |
Antonio Nino Diaz | 61aff00 | 2018-10-19 16:52:22 +0100 | [diff] [blame] | 10 | #include <xlat_tables_v2.h> |
| 11 | |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 12 | #include "qemu_private.h" |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 13 | |
| 14 | #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \ |
| 15 | DEVICE0_SIZE, \ |
| 16 | MT_DEVICE | MT_RW | MT_SECURE) |
| 17 | |
| 18 | #ifdef DEVICE1_BASE |
| 19 | #define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \ |
| 20 | DEVICE1_SIZE, \ |
| 21 | MT_DEVICE | MT_RW | MT_SECURE) |
| 22 | #endif |
| 23 | |
| 24 | #ifdef DEVICE2_BASE |
| 25 | #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ |
| 26 | DEVICE2_SIZE, \ |
| 27 | MT_DEVICE | MT_RO | MT_SECURE) |
| 28 | #endif |
| 29 | |
| 30 | #define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \ |
| 31 | SHARED_RAM_SIZE, \ |
| 32 | MT_DEVICE | MT_RW | MT_SECURE) |
| 33 | |
| 34 | #define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \ |
| 35 | MT_MEMORY | MT_RW | MT_SECURE) |
| 36 | |
| 37 | #define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \ |
| 38 | MT_MEMORY | MT_RW | MT_NS) |
| 39 | |
| 40 | #define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \ |
| 41 | MT_MEMORY | MT_RO | MT_SECURE) |
| 42 | |
| 43 | /* |
| 44 | * Table of regions for various BL stages to map using the MMU. |
| 45 | * This doesn't include TZRAM as the 'mem_layout' argument passed to |
| 46 | * arm_configure_mmu_elx() will give the available subset of that, |
| 47 | */ |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 48 | #ifdef IMAGE_BL1 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 49 | static const mmap_region_t plat_qemu_mmap[] = { |
| 50 | MAP_FLASH0, |
| 51 | MAP_SHARED_RAM, |
| 52 | MAP_DEVICE0, |
| 53 | #ifdef MAP_DEVICE1 |
| 54 | MAP_DEVICE1, |
| 55 | #endif |
| 56 | #ifdef MAP_DEVICE2 |
| 57 | MAP_DEVICE2, |
| 58 | #endif |
| 59 | {0} |
| 60 | }; |
| 61 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 62 | #ifdef IMAGE_BL2 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 63 | static const mmap_region_t plat_qemu_mmap[] = { |
| 64 | MAP_FLASH0, |
| 65 | MAP_SHARED_RAM, |
| 66 | MAP_DEVICE0, |
| 67 | #ifdef MAP_DEVICE1 |
| 68 | MAP_DEVICE1, |
| 69 | #endif |
| 70 | #ifdef MAP_DEVICE2 |
| 71 | MAP_DEVICE2, |
| 72 | #endif |
| 73 | MAP_NS_DRAM0, |
| 74 | MAP_BL32_MEM, |
| 75 | {0} |
| 76 | }; |
| 77 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 78 | #ifdef IMAGE_BL31 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 79 | static const mmap_region_t plat_qemu_mmap[] = { |
| 80 | MAP_SHARED_RAM, |
| 81 | MAP_DEVICE0, |
| 82 | #ifdef MAP_DEVICE1 |
| 83 | MAP_DEVICE1, |
| 84 | #endif |
| 85 | MAP_BL32_MEM, |
| 86 | {0} |
| 87 | }; |
| 88 | #endif |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 89 | #ifdef IMAGE_BL32 |
| 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 |
| 96 | {0} |
| 97 | }; |
| 98 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 99 | |
| 100 | /******************************************************************************* |
| 101 | * Macro generating the code for the function setting up the pagetables as per |
| 102 | * the platform memory map & initialize the mmu, for the given exception level |
| 103 | ******************************************************************************/ |
| 104 | |
| 105 | #define DEFINE_CONFIGURE_MMU_EL(_el) \ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 106 | void qemu_configure_mmu_##_el(unsigned long total_base, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 107 | unsigned long total_size, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 108 | unsigned long code_start, \ |
| 109 | unsigned long code_limit, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 110 | unsigned long ro_start, \ |
| 111 | unsigned long ro_limit, \ |
| 112 | unsigned long coh_start, \ |
| 113 | unsigned long coh_limit) \ |
| 114 | { \ |
| 115 | mmap_add_region(total_base, total_base, \ |
| 116 | total_size, \ |
| 117 | MT_MEMORY | MT_RW | MT_SECURE); \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 118 | mmap_add_region(code_start, code_start, \ |
| 119 | code_limit - code_start, \ |
| 120 | MT_CODE | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 121 | mmap_add_region(ro_start, ro_start, \ |
| 122 | ro_limit - ro_start, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 123 | MT_RO_DATA | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 124 | mmap_add_region(coh_start, coh_start, \ |
| 125 | coh_limit - coh_start, \ |
| 126 | MT_DEVICE | MT_RW | MT_SECURE); \ |
| 127 | mmap_add(plat_qemu_mmap); \ |
| 128 | init_xlat_tables(); \ |
| 129 | \ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 130 | enable_mmu_##_el(0); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* Define EL1 and EL3 variants of the function initialising the MMU */ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 134 | #ifdef AARCH32 |
Antonio Nino Diaz | 099b0b1 | 2018-09-26 09:29:45 +0100 | [diff] [blame] | 135 | DEFINE_CONFIGURE_MMU_EL(svc_mon) |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 136 | #else |
| 137 | DEFINE_CONFIGURE_MMU_EL(el1) |
| 138 | DEFINE_CONFIGURE_MMU_EL(el3) |
| 139 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 140 | |
| 141 | |