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