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 | /* |
Ruchika Gupta | 5c17253 | 2022-04-08 13:14:44 +0530 | [diff] [blame] | 3 | * Copyright (c) 2015-2022, 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 | |
Ruchika Gupta | 5c17253 | 2022-04-08 13:14:44 +0530 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 15 | #include "qemu_private.h" |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 16 | |
| 17 | #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \ |
| 18 | DEVICE0_SIZE, \ |
| 19 | MT_DEVICE | MT_RW | MT_SECURE) |
| 20 | |
| 21 | #ifdef DEVICE1_BASE |
| 22 | #define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \ |
| 23 | DEVICE1_SIZE, \ |
| 24 | MT_DEVICE | MT_RW | MT_SECURE) |
| 25 | #endif |
| 26 | |
| 27 | #ifdef DEVICE2_BASE |
| 28 | #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \ |
| 29 | DEVICE2_SIZE, \ |
Graeme Gregory | 6260ddd | 2020-12-16 12:11:06 +0000 | [diff] [blame] | 30 | MT_DEVICE | MT_RW | MT_SECURE) |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \ |
| 34 | SHARED_RAM_SIZE, \ |
| 35 | MT_DEVICE | MT_RW | MT_SECURE) |
| 36 | |
| 37 | #define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \ |
| 38 | MT_MEMORY | MT_RW | MT_SECURE) |
| 39 | |
| 40 | #define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \ |
| 41 | MT_MEMORY | MT_RW | MT_NS) |
| 42 | |
| 43 | #define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \ |
| 44 | MT_MEMORY | MT_RO | MT_SECURE) |
| 45 | |
Radoslaw Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 46 | #define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \ |
| 47 | MT_MEMORY | MT_RO | MT_SECURE) |
| 48 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 49 | /* |
| 50 | * Table of regions for various BL stages to map using the MMU. |
| 51 | * This doesn't include TZRAM as the 'mem_layout' argument passed to |
| 52 | * arm_configure_mmu_elx() will give the available subset of that, |
| 53 | */ |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 54 | #ifdef IMAGE_BL1 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 55 | static const mmap_region_t plat_qemu_mmap[] = { |
| 56 | MAP_FLASH0, |
Radoslaw Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 57 | MAP_FLASH1, |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 58 | MAP_SHARED_RAM, |
| 59 | MAP_DEVICE0, |
| 60 | #ifdef MAP_DEVICE1 |
| 61 | MAP_DEVICE1, |
| 62 | #endif |
| 63 | #ifdef MAP_DEVICE2 |
| 64 | MAP_DEVICE2, |
| 65 | #endif |
| 66 | {0} |
| 67 | }; |
| 68 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 69 | #ifdef IMAGE_BL2 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 70 | static const mmap_region_t plat_qemu_mmap[] = { |
| 71 | MAP_FLASH0, |
Radoslaw Biernacki | 7ed5e12 | 2018-06-07 20:14:36 +0200 | [diff] [blame] | 72 | MAP_FLASH1, |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 73 | MAP_SHARED_RAM, |
| 74 | MAP_DEVICE0, |
| 75 | #ifdef MAP_DEVICE1 |
| 76 | MAP_DEVICE1, |
| 77 | #endif |
| 78 | #ifdef MAP_DEVICE2 |
| 79 | MAP_DEVICE2, |
| 80 | #endif |
| 81 | MAP_NS_DRAM0, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 82 | #if SPM_MM |
| 83 | QEMU_SP_IMAGE_MMAP, |
| 84 | #else |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 85 | MAP_BL32_MEM, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 86 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 87 | {0} |
| 88 | }; |
| 89 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 90 | #ifdef IMAGE_BL31 |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 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 |
Graeme Gregory | 6260ddd | 2020-12-16 12:11:06 +0000 | [diff] [blame] | 97 | #ifdef MAP_DEVICE2 |
| 98 | MAP_DEVICE2, |
| 99 | #endif |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 100 | #if SPM_MM |
Masahisa Kojima | 7e917dc | 2020-09-23 16:52:59 +0900 | [diff] [blame] | 101 | MAP_NS_DRAM0, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 102 | QEMU_SPM_BUF_EL3_MMAP, |
| 103 | #else |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 104 | MAP_BL32_MEM, |
Masahisa Kojima | 099064b | 2020-06-11 21:46:44 +0900 | [diff] [blame] | 105 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 106 | {0} |
| 107 | }; |
| 108 | #endif |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 109 | #ifdef IMAGE_BL32 |
| 110 | static const mmap_region_t plat_qemu_mmap[] = { |
| 111 | MAP_SHARED_RAM, |
| 112 | MAP_DEVICE0, |
| 113 | #ifdef MAP_DEVICE1 |
| 114 | MAP_DEVICE1, |
| 115 | #endif |
Graeme Gregory | 6260ddd | 2020-12-16 12:11:06 +0000 | [diff] [blame] | 116 | #ifdef MAP_DEVICE2 |
| 117 | MAP_DEVICE2, |
| 118 | #endif |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 119 | {0} |
| 120 | }; |
| 121 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 122 | |
| 123 | /******************************************************************************* |
| 124 | * Macro generating the code for the function setting up the pagetables as per |
| 125 | * the platform memory map & initialize the mmu, for the given exception level |
| 126 | ******************************************************************************/ |
| 127 | |
| 128 | #define DEFINE_CONFIGURE_MMU_EL(_el) \ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 129 | void qemu_configure_mmu_##_el(unsigned long total_base, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 130 | unsigned long total_size, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 131 | unsigned long code_start, \ |
| 132 | unsigned long code_limit, \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 133 | unsigned long ro_start, \ |
| 134 | unsigned long ro_limit, \ |
| 135 | unsigned long coh_start, \ |
| 136 | unsigned long coh_limit) \ |
| 137 | { \ |
| 138 | mmap_add_region(total_base, total_base, \ |
| 139 | total_size, \ |
| 140 | MT_MEMORY | MT_RW | MT_SECURE); \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 141 | mmap_add_region(code_start, code_start, \ |
| 142 | code_limit - code_start, \ |
| 143 | MT_CODE | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 144 | mmap_add_region(ro_start, ro_start, \ |
| 145 | ro_limit - ro_start, \ |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 146 | MT_RO_DATA | MT_SECURE); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 147 | mmap_add_region(coh_start, coh_start, \ |
| 148 | coh_limit - coh_start, \ |
| 149 | MT_DEVICE | MT_RW | MT_SECURE); \ |
| 150 | mmap_add(plat_qemu_mmap); \ |
| 151 | init_xlat_tables(); \ |
| 152 | \ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 153 | enable_mmu_##_el(0); \ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* Define EL1 and EL3 variants of the function initialising the MMU */ |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 157 | #ifdef __aarch64__ |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 158 | DEFINE_CONFIGURE_MMU_EL(el1) |
| 159 | DEFINE_CONFIGURE_MMU_EL(el3) |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 160 | #else |
| 161 | DEFINE_CONFIGURE_MMU_EL(svc_mon) |
Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 162 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 163 | |
Ruchika Gupta | 5c17253 | 2022-04-08 13:14:44 +0530 | [diff] [blame] | 164 | #if MEASURED_BOOT || TRUSTED_BOARD_BOOT |
| 165 | int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size) |
| 166 | { |
| 167 | return get_mbedtls_heap_helper(heap_addr, heap_size); |
| 168 | } |
| 169 | #endif |